From 41916d492c38055928ae5ad1e0b815ff79dc4f5c Mon Sep 17 00:00:00 2001 From: Nicolas Prevot Date: Tue, 24 Feb 2015 18:41:50 +0000 Subject: Fail silently when changing BLUETOOTH_ON/WIFI_ON directly If the device owner tries to change BLUETOOTH_ON or WIFI_ON via DevicePolicyManager.setGlobalSetting, fail silently. There was not much point for the device owner to do it since it can also change bluetooth/wifi state via normal bluetooth and wifi apis. BUG:19311992 Change-Id: Ifba163800aa413865b8a2877cb21aacfa5cfc6c8 --- core/java/android/app/admin/DevicePolicyManager.java | 9 +++++++-- .../server/devicepolicy/DevicePolicyManagerService.java | 11 +++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index d0ebdbd..ca18b9c 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -3360,13 +3360,18 @@ public class DevicePolicyManager { *
  • {@link Settings.Global#ADB_ENABLED}
  • *
  • {@link Settings.Global#AUTO_TIME}
  • *
  • {@link Settings.Global#AUTO_TIME_ZONE}
  • - *
  • {@link Settings.Global#BLUETOOTH_ON}
  • + *
  • {@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}
  • + *
  • {@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}
  • * * diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 770da5b..8205fbd 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -196,13 +196,11 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { GLOBAL_SETTINGS_WHITELIST.add(Settings.Global.ADB_ENABLED); GLOBAL_SETTINGS_WHITELIST.add(Settings.Global.AUTO_TIME); GLOBAL_SETTINGS_WHITELIST.add(Settings.Global.AUTO_TIME_ZONE); - GLOBAL_SETTINGS_WHITELIST.add(Settings.Global.BLUETOOTH_ON); 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_ON); GLOBAL_SETTINGS_WHITELIST.add(Settings.Global.WIFI_SLEEP_POLICY); } @@ -5267,8 +5265,13 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER); if (!GLOBAL_SETTINGS_WHITELIST.contains(setting)) { - throw new SecurityException(String.format( - "Permission denial: device owners cannot update %1$s", 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)); + } } long id = Binder.clearCallingIdentity(); -- cgit v1.1