Skip to content

Commit 2fe8fb2

Browse files
author
Dianne Hackborn
committed
Fix issue #6664140: Time to lock should work even Stay awake...
...in Developer options is on Don't respect stay awake while on as long as a time to lock limit is being enforced. When we start enforcing one, make sure the setting is off (since we won't be respecting it anyway). Bug: 6664140 Change-Id: Id07cb528afa0c64c7766341841c51771f507121d
1 parent 87959cd commit 2fe8fb2

File tree

2 files changed

+48
-34
lines changed

2 files changed

+48
-34
lines changed

services/java/com/android/server/DevicePolicyManagerService.java

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
112112
int mPasswordOwner = -1;
113113
Handler mHandler = new Handler();
114114

115+
long mLastMaximumTimeToLock = -1;
116+
115117
final HashMap<ComponentName, ActiveAdmin> mAdminMap
116118
= new HashMap<ComponentName, ActiveAdmin>();
117119
final ArrayList<ActiveAdmin> mAdminList
@@ -595,17 +597,18 @@ void removeActiveAdminLocked(final ComponentName adminReceiver) {
595597
new BroadcastReceiver() {
596598
@Override
597599
public void onReceive(Context context, Intent intent) {
598-
synchronized (this) {
600+
synchronized (DevicePolicyManagerService.this) {
599601
boolean doProxyCleanup = admin.info.usesPolicy(
600602
DeviceAdminInfo.USES_POLICY_SETS_GLOBAL_PROXY);
601603
mAdminList.remove(admin);
602604
mAdminMap.remove(adminReceiver);
603605
validatePasswordOwnerLocked();
604606
syncDeviceCapabilitiesLocked();
605607
if (doProxyCleanup) {
606-
resetGlobalProxy();
608+
resetGlobalProxyLocked();
607609
}
608610
saveSettingsLocked();
611+
updateMaximumTimeToLockLocked();
609612
}
610613
}
611614
});
@@ -826,16 +829,7 @@ private void loadSettingsLocked() {
826829

827830
validatePasswordOwnerLocked();
828831
syncDeviceCapabilitiesLocked();
829-
830-
long timeMs = getMaximumTimeToLock(null);
831-
if (timeMs <= 0) {
832-
timeMs = Integer.MAX_VALUE;
833-
}
834-
try {
835-
getIPowerManager().setMaximumScreenOffTimeount((int)timeMs);
836-
} catch (RemoteException e) {
837-
Slog.w(TAG, "Failure talking with power manager", e);
838-
}
832+
updateMaximumTimeToLockLocked();
839833
}
840834

841835
static void validateQualityConstant(int quality) {
@@ -1606,25 +1600,38 @@ public void setMaximumTimeToLock(ComponentName who, long timeMs) {
16061600
DeviceAdminInfo.USES_POLICY_FORCE_LOCK);
16071601
if (ap.maximumTimeToUnlock != timeMs) {
16081602
ap.maximumTimeToUnlock = timeMs;
1603+
saveSettingsLocked();
1604+
updateMaximumTimeToLockLocked();
1605+
}
1606+
}
1607+
}
16091608

1610-
long ident = Binder.clearCallingIdentity();
1611-
try {
1612-
saveSettingsLocked();
1609+
void updateMaximumTimeToLockLocked() {
1610+
long timeMs = getMaximumTimeToLock(null);
1611+
if (mLastMaximumTimeToLock == timeMs) {
1612+
return;
1613+
}
16131614

1614-
timeMs = getMaximumTimeToLock(null);
1615-
if (timeMs <= 0) {
1616-
timeMs = Integer.MAX_VALUE;
1617-
}
1615+
long ident = Binder.clearCallingIdentity();
1616+
try {
1617+
if (timeMs <= 0) {
1618+
timeMs = Integer.MAX_VALUE;
1619+
} else {
1620+
// Make sure KEEP_SCREEN_ON is disabled, since that
1621+
// would allow bypassing of the maximum time to lock.
1622+
Settings.System.putInt(mContext.getContentResolver(),
1623+
Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0);
1624+
}
16181625

1619-
try {
1620-
getIPowerManager().setMaximumScreenOffTimeount((int)timeMs);
1621-
} catch (RemoteException e) {
1622-
Slog.w(TAG, "Failure talking with power manager", e);
1623-
}
1624-
} finally {
1625-
Binder.restoreCallingIdentity(ident);
1626-
}
1626+
mLastMaximumTimeToLock = timeMs;
1627+
1628+
try {
1629+
getIPowerManager().setMaximumScreenOffTimeount((int)timeMs);
1630+
} catch (RemoteException e) {
1631+
Slog.w(TAG, "Failure talking with power manager", e);
16271632
}
1633+
} finally {
1634+
Binder.restoreCallingIdentity(ident);
16281635
}
16291636
}
16301637

@@ -1868,7 +1875,7 @@ public ComponentName setGlobalProxy(ComponentName who, String proxySpec,
18681875
// Reset the global proxy accordingly
18691876
// Do this using system permissions, as apps cannot write to secure settings
18701877
long origId = Binder.clearCallingIdentity();
1871-
resetGlobalProxy();
1878+
resetGlobalProxyLocked();
18721879
Binder.restoreCallingIdentity(origId);
18731880
return null;
18741881
}
@@ -1892,20 +1899,20 @@ public ComponentName getGlobalProxyAdmin() {
18921899
return null;
18931900
}
18941901

1895-
private void resetGlobalProxy() {
1902+
private void resetGlobalProxyLocked() {
18961903
final int N = mAdminList.size();
18971904
for (int i = 0; i < N; i++) {
18981905
ActiveAdmin ap = mAdminList.get(i);
18991906
if (ap.specifiesGlobalProxy) {
1900-
saveGlobalProxy(ap.globalProxySpec, ap.globalProxyExclusionList);
1907+
saveGlobalProxyLocked(ap.globalProxySpec, ap.globalProxyExclusionList);
19011908
return;
19021909
}
19031910
}
19041911
// No device admins defining global proxies - reset global proxy settings to none
1905-
saveGlobalProxy(null, null);
1912+
saveGlobalProxyLocked(null, null);
19061913
}
19071914

1908-
private void saveGlobalProxy(String proxySpec, String exclusionList) {
1915+
private void saveGlobalProxyLocked(String proxySpec, String exclusionList) {
19091916
if (exclusionList == null) {
19101917
exclusionList = "";
19111918
}

services/java/com/android/server/PowerManagerService.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,11 @@ public void setMaximumScreenOffTimeount(int timeMs) {
477477
}
478478
}
479479

480+
int getStayOnConditionsLocked() {
481+
return mMaximumScreenOffTimeout <= 0 || mMaximumScreenOffTimeout == Integer.MAX_VALUE
482+
? mStayOnConditions : 0;
483+
}
484+
480485
private class SettingsObserver implements Observer {
481486
private int getInt(String name, int defValue) {
482487
ContentValues values = mSettings.getValues(name);
@@ -760,7 +765,8 @@ public void binderDied() {
760765
}
761766

762767
private void updateWakeLockLocked() {
763-
if (mStayOnConditions != 0 && mBatteryService.isPowered(mStayOnConditions)) {
768+
final int stayOnConditions = getStayOnConditionsLocked();
769+
if (stayOnConditions != 0 && mBatteryService.isPowered(stayOnConditions)) {
764770
// keep the device on if we're plugged in and mStayOnWhilePluggedIn is set.
765771
mStayOnWhilePluggedInScreenDimLock.acquire();
766772
mStayOnWhilePluggedInPartialLock.acquire();
@@ -2097,7 +2103,8 @@ private void updateLightsLocked(int newState, int forceState) {
20972103
// was dim
20982104
steps = (int)(ANIM_STEPS*ratio);
20992105
}
2100-
if (mStayOnConditions != 0 && mBatteryService.isPowered(mStayOnConditions)) {
2106+
final int stayOnConditions = getStayOnConditionsLocked();
2107+
if (stayOnConditions != 0 && mBatteryService.isPowered(stayOnConditions)) {
21012108
// If the "stay on while plugged in" option is
21022109
// turned on, then the screen will often not
21032110
// automatically turn off while plugged in. To

0 commit comments

Comments
 (0)