From 656fa7f5d1ce9299cb63043de80f2b4db9bff497 Mon Sep 17 00:00:00 2001 From: Esteban Talavera Date: Mon, 29 Jun 2015 17:41:39 +0100 Subject: [PATCH] Marking some globals from setGlobalSetting as not supported Those globals don't have the intended behaviour any more. Bug: 19967818 Change-Id: I8c7891e59280f9deb88b1f0ffead3de07f4eca56 --- .../android/app/admin/DevicePolicyManager.java | 27 ++++++++++++---------- .../devicepolicy/DevicePolicyManagerService.java | 27 ++++++++++++++-------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index 83e06d6c9805..9812e6153b3e 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -3956,24 +3956,27 @@ public class DevicePolicyManager { *
  • {@link Settings.Global#ADB_ENABLED}
  • *
  • {@link Settings.Global#AUTO_TIME}
  • *
  • {@link Settings.Global#AUTO_TIME_ZONE}
  • - *
  • {@link Settings.Global#BLUETOOTH_ON} - * Changing this setting has not effect as of {@link android.os.Build.VERSION_CODES#MNC}. Use - * {@link android.bluetooth.BluetoothAdapter#enable()} and - * {@link android.bluetooth.BluetoothAdapter#disable()} instead.
  • *
  • {@link Settings.Global#DATA_ROAMING}
  • - *
  • {@link Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}
  • - *
  • {@link Settings.Global#MODE_RINGER}
  • - *
  • {@link Settings.Global#NETWORK_PREFERENCE}
  • *
  • {@link Settings.Global#USB_MASS_STORAGE_ENABLED}
  • - *
  • {@link Settings.Global#WIFI_ON} - * 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.
  • + * 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. *
  • {@link Settings.Global#WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN}
  • * + *

    Changing the following settings has no effect as of + * {@link android.os.Build.VERSION_CODES#MNC}: + *

    * * @param admin Which {@link DeviceAdminReceiver} this request is associated with. * @param setting The name of the setting to update. diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 491b4120d544..cd6e41561e42 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -225,6 +225,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { private static final Set SECURE_SETTINGS_WHITELIST; private static final Set SECURE_SETTINGS_DEVICEOWNER_WHITELIST; private static final Set GLOBAL_SETTINGS_WHITELIST; + private static final Set GLOBAL_SETTINGS_DEPRECATED; static { SECURE_SETTINGS_WHITELIST = new HashSet(); SECURE_SETTINGS_WHITELIST.add(Settings.Secure.DEFAULT_INPUT_METHOD); @@ -240,13 +241,17 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { GLOBAL_SETTINGS_WHITELIST.add(Settings.Global.AUTO_TIME); GLOBAL_SETTINGS_WHITELIST.add(Settings.Global.AUTO_TIME_ZONE); GLOBAL_SETTINGS_WHITELIST.add(Settings.Global.DATA_ROAMING); - GLOBAL_SETTINGS_WHITELIST.add(Settings.Global.DEVELOPMENT_SETTINGS_ENABLED); - GLOBAL_SETTINGS_WHITELIST.add(Settings.Global.MODE_RINGER); - 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); GLOBAL_SETTINGS_WHITELIST.add(Settings.Global.WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN); + + GLOBAL_SETTINGS_DEPRECATED = new HashSet(); + GLOBAL_SETTINGS_DEPRECATED.add(Settings.Global.BLUETOOTH_ON); + GLOBAL_SETTINGS_DEPRECATED.add(Settings.Global.DEVELOPMENT_SETTINGS_ENABLED); + GLOBAL_SETTINGS_DEPRECATED.add(Settings.Global.MODE_RINGER); + GLOBAL_SETTINGS_DEPRECATED.add(Settings.Global.NETWORK_PREFERENCE); + GLOBAL_SETTINGS_DEPRECATED.add(Settings.Global.WIFI_ON); } // Keyguard features that when set of a profile will affect the profiles @@ -5964,14 +5969,16 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { synchronized (this) { getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER); + // Some settings are no supported any more. However we do not want to throw a + // SecurityException to avoid breaking apps. + if (GLOBAL_SETTINGS_DEPRECATED.contains(setting)) { + Log.i(LOG_TAG, "Global setting no longer supported: " + setting); + return; + } + if (!GLOBAL_SETTINGS_WHITELIST.contains(setting)) { - // BLUETOOTH_ON and WIFI_ON used to be supported but not any more. We do not want to - // throw a SecurityException not to break apps. - if (!Settings.Global.BLUETOOTH_ON.equals(setting) - && !Settings.Global.WIFI_ON.equals(setting)) { - throw new SecurityException(String.format( - "Permission denial: device owners cannot update %1$s", setting)); - } + throw new SecurityException(String.format( + "Permission denial: device owners cannot update %1$s", setting)); } if (Settings.Global.STAY_ON_WHILE_PLUGGED_IN.equals(setting)) { -- 2.11.0