From 68cc42009e656b785420c531e39c131bbe6729cf Mon Sep 17 00:00:00 2001 From: Benjamin Franz Date: Wed, 11 Mar 2015 15:43:06 +0000 Subject: [PATCH] Allow DO to set Settings.Global.STAY_ON_WHILE_PLUGGED_IN Bug: 19704419 Change-Id: I3fc970eae8ef947775b6b565916bb245dea1b43b --- core/java/android/app/admin/DevicePolicyManager.java | 3 +++ .../server/devicepolicy/DevicePolicyManagerService.java | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index e23ffe412d4a2..245db06d164f7 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -3562,6 +3562,9 @@ public class DevicePolicyManager { * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use * {@link android.net.wifi.WifiManager#setWifiEnabled(boolean)} instead. *
  • {@link Settings.Global#WIFI_SLEEP_POLICY}
  • + *
  • {@link Settings.Global#STAY_ON_WHILE_PLUGGED_IN} + * This setting is only available from {@link android.os.Build.VERSION_CODES#MNC} onwards + * and can only be set if {@link #setMaximumTimeToLock} is not used to set a timeout.
  • * * * @param admin Which {@link DeviceAdminReceiver} this request is associated with. diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 00d7971ce9591..365a67a87a745 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -211,6 +211,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { GLOBAL_SETTINGS_WHITELIST.add(Settings.Global.NETWORK_PREFERENCE); GLOBAL_SETTINGS_WHITELIST.add(Settings.Global.USB_MASS_STORAGE_ENABLED); GLOBAL_SETTINGS_WHITELIST.add(Settings.Global.WIFI_SLEEP_POLICY); + GLOBAL_SETTINGS_WHITELIST.add(Settings.Global.STAY_ON_WHILE_PLUGGED_IN); } final Context mContext; @@ -5437,6 +5438,14 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } } + if (Settings.Global.STAY_ON_WHILE_PLUGGED_IN.equals(setting)) { + // ignore if it contradicts an existing policy + long timeMs = getMaximumTimeToLock(who, UserHandle.getCallingUserId()); + if (timeMs > 0 && timeMs < Integer.MAX_VALUE) { + return; + } + } + long id = Binder.clearCallingIdentity(); try { Settings.Global.putString(contentResolver, setting, value);