summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2012-06-15 17:05:25 -0700
committerDianne Hackborn <hackbod@google.com>2012-06-15 17:23:16 -0700
commit2fe8fb276c28372edb60f5bb10e172c19ef2671b (patch)
tree600e22507e05e4250e071c4e287d9f7544fe598c /services
parent87959cdd8560e743956a71bb687799e94053e086 (diff)
downloadframeworks_base-2fe8fb276c28372edb60f5bb10e172c19ef2671b.zip
frameworks_base-2fe8fb276c28372edb60f5bb10e172c19ef2671b.tar.gz
frameworks_base-2fe8fb276c28372edb60f5bb10e172c19ef2671b.tar.bz2
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
Diffstat (limited to 'services')
-rw-r--r--services/java/com/android/server/DevicePolicyManagerService.java71
-rw-r--r--services/java/com/android/server/PowerManagerService.java11
2 files changed, 48 insertions, 34 deletions
diff --git a/services/java/com/android/server/DevicePolicyManagerService.java b/services/java/com/android/server/DevicePolicyManagerService.java
index eb33060..0f5ad66 100644
--- a/services/java/com/android/server/DevicePolicyManagerService.java
+++ b/services/java/com/android/server/DevicePolicyManagerService.java
@@ -112,6 +112,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
int mPasswordOwner = -1;
Handler mHandler = new Handler();
+ long mLastMaximumTimeToLock = -1;
+
final HashMap<ComponentName, ActiveAdmin> mAdminMap
= new HashMap<ComponentName, ActiveAdmin>();
final ArrayList<ActiveAdmin> mAdminList
@@ -595,7 +597,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- synchronized (this) {
+ synchronized (DevicePolicyManagerService.this) {
boolean doProxyCleanup = admin.info.usesPolicy(
DeviceAdminInfo.USES_POLICY_SETS_GLOBAL_PROXY);
mAdminList.remove(admin);
@@ -603,9 +605,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
validatePasswordOwnerLocked();
syncDeviceCapabilitiesLocked();
if (doProxyCleanup) {
- resetGlobalProxy();
+ resetGlobalProxyLocked();
}
saveSettingsLocked();
+ updateMaximumTimeToLockLocked();
}
}
});
@@ -826,16 +829,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
validatePasswordOwnerLocked();
syncDeviceCapabilitiesLocked();
-
- long timeMs = getMaximumTimeToLock(null);
- if (timeMs <= 0) {
- timeMs = Integer.MAX_VALUE;
- }
- try {
- getIPowerManager().setMaximumScreenOffTimeount((int)timeMs);
- } catch (RemoteException e) {
- Slog.w(TAG, "Failure talking with power manager", e);
- }
+ updateMaximumTimeToLockLocked();
}
static void validateQualityConstant(int quality) {
@@ -1606,25 +1600,38 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
DeviceAdminInfo.USES_POLICY_FORCE_LOCK);
if (ap.maximumTimeToUnlock != timeMs) {
ap.maximumTimeToUnlock = timeMs;
+ saveSettingsLocked();
+ updateMaximumTimeToLockLocked();
+ }
+ }
+ }
- long ident = Binder.clearCallingIdentity();
- try {
- saveSettingsLocked();
+ void updateMaximumTimeToLockLocked() {
+ long timeMs = getMaximumTimeToLock(null);
+ if (mLastMaximumTimeToLock == timeMs) {
+ return;
+ }
- timeMs = getMaximumTimeToLock(null);
- if (timeMs <= 0) {
- timeMs = Integer.MAX_VALUE;
- }
+ long ident = Binder.clearCallingIdentity();
+ try {
+ if (timeMs <= 0) {
+ timeMs = Integer.MAX_VALUE;
+ } else {
+ // Make sure KEEP_SCREEN_ON is disabled, since that
+ // would allow bypassing of the maximum time to lock.
+ Settings.System.putInt(mContext.getContentResolver(),
+ Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0);
+ }
- try {
- getIPowerManager().setMaximumScreenOffTimeount((int)timeMs);
- } catch (RemoteException e) {
- Slog.w(TAG, "Failure talking with power manager", e);
- }
- } finally {
- Binder.restoreCallingIdentity(ident);
- }
+ mLastMaximumTimeToLock = timeMs;
+
+ try {
+ getIPowerManager().setMaximumScreenOffTimeount((int)timeMs);
+ } catch (RemoteException e) {
+ Slog.w(TAG, "Failure talking with power manager", e);
}
+ } finally {
+ Binder.restoreCallingIdentity(ident);
}
}
@@ -1868,7 +1875,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
// Reset the global proxy accordingly
// Do this using system permissions, as apps cannot write to secure settings
long origId = Binder.clearCallingIdentity();
- resetGlobalProxy();
+ resetGlobalProxyLocked();
Binder.restoreCallingIdentity(origId);
return null;
}
@@ -1892,20 +1899,20 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
return null;
}
- private void resetGlobalProxy() {
+ private void resetGlobalProxyLocked() {
final int N = mAdminList.size();
for (int i = 0; i < N; i++) {
ActiveAdmin ap = mAdminList.get(i);
if (ap.specifiesGlobalProxy) {
- saveGlobalProxy(ap.globalProxySpec, ap.globalProxyExclusionList);
+ saveGlobalProxyLocked(ap.globalProxySpec, ap.globalProxyExclusionList);
return;
}
}
// No device admins defining global proxies - reset global proxy settings to none
- saveGlobalProxy(null, null);
+ saveGlobalProxyLocked(null, null);
}
- private void saveGlobalProxy(String proxySpec, String exclusionList) {
+ private void saveGlobalProxyLocked(String proxySpec, String exclusionList) {
if (exclusionList == null) {
exclusionList = "";
}
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java
index f46f8e6..fbdd7aa 100644
--- a/services/java/com/android/server/PowerManagerService.java
+++ b/services/java/com/android/server/PowerManagerService.java
@@ -477,6 +477,11 @@ public class PowerManagerService extends IPowerManager.Stub
}
}
+ int getStayOnConditionsLocked() {
+ return mMaximumScreenOffTimeout <= 0 || mMaximumScreenOffTimeout == Integer.MAX_VALUE
+ ? mStayOnConditions : 0;
+ }
+
private class SettingsObserver implements Observer {
private int getInt(String name, int defValue) {
ContentValues values = mSettings.getValues(name);
@@ -760,7 +765,8 @@ public class PowerManagerService extends IPowerManager.Stub
}
private void updateWakeLockLocked() {
- if (mStayOnConditions != 0 && mBatteryService.isPowered(mStayOnConditions)) {
+ final int stayOnConditions = getStayOnConditionsLocked();
+ if (stayOnConditions != 0 && mBatteryService.isPowered(stayOnConditions)) {
// keep the device on if we're plugged in and mStayOnWhilePluggedIn is set.
mStayOnWhilePluggedInScreenDimLock.acquire();
mStayOnWhilePluggedInPartialLock.acquire();
@@ -2097,7 +2103,8 @@ public class PowerManagerService extends IPowerManager.Stub
// was dim
steps = (int)(ANIM_STEPS*ratio);
}
- if (mStayOnConditions != 0 && mBatteryService.isPowered(mStayOnConditions)) {
+ final int stayOnConditions = getStayOnConditionsLocked();
+ if (stayOnConditions != 0 && mBatteryService.isPowered(stayOnConditions)) {
// If the "stay on while plugged in" option is
// turned on, then the screen will often not
// automatically turn off while plugged in. To