diff options
| -rw-r--r-- | api/current.txt | 1 | ||||
| -rw-r--r-- | api/system-current.txt | 1 | ||||
| -rw-r--r-- | api/test-current.txt | 1 | ||||
| -rw-r--r-- | core/java/android/os/UserManager.java | 16 | ||||
| -rw-r--r-- | services/core/java/com/android/server/BluetoothManagerService.java | 51 | ||||
| -rw-r--r-- | services/core/java/com/android/server/pm/UserRestrictionsUtils.java | 2 |
6 files changed, 72 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt index d22006d3c9e8..c1314ad05091 100644 --- a/api/current.txt +++ b/api/current.txt @@ -29277,6 +29277,7 @@ package android.os { field public static final java.lang.String DISALLOW_ADD_USER = "no_add_user"; field public static final java.lang.String DISALLOW_ADJUST_VOLUME = "no_adjust_volume"; field public static final java.lang.String DISALLOW_APPS_CONTROL = "no_control_apps"; + field public static final java.lang.String DISALLOW_BLUETOOTH = "no_bluetooth"; field public static final java.lang.String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth"; field public static final java.lang.String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts"; field public static final java.lang.String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials"; diff --git a/api/system-current.txt b/api/system-current.txt index 01d4f47bdf33..b6b7f8b3b2b9 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -31804,6 +31804,7 @@ package android.os { field public static final java.lang.String DISALLOW_ADD_USER = "no_add_user"; field public static final java.lang.String DISALLOW_ADJUST_VOLUME = "no_adjust_volume"; field public static final java.lang.String DISALLOW_APPS_CONTROL = "no_control_apps"; + field public static final java.lang.String DISALLOW_BLUETOOTH = "no_bluetooth"; field public static final java.lang.String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth"; field public static final java.lang.String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts"; field public static final java.lang.String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials"; diff --git a/api/test-current.txt b/api/test-current.txt index e21afe2a4c7c..2d7b29fe2d59 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -29347,6 +29347,7 @@ package android.os { field public static final java.lang.String DISALLOW_ADD_USER = "no_add_user"; field public static final java.lang.String DISALLOW_ADJUST_VOLUME = "no_adjust_volume"; field public static final java.lang.String DISALLOW_APPS_CONTROL = "no_control_apps"; + field public static final java.lang.String DISALLOW_BLUETOOTH = "no_bluetooth"; field public static final java.lang.String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth"; field public static final java.lang.String DISALLOW_CONFIG_CELL_BROADCASTS = "no_config_cell_broadcasts"; field public static final java.lang.String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials"; diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java index bcc8d463e51d..7543bdeedd4b 100644 --- a/core/java/android/os/UserManager.java +++ b/core/java/android/os/UserManager.java @@ -186,6 +186,8 @@ public class UserManager { * Specifies if a user is disallowed from configuring bluetooth. * This does <em>not</em> restrict the user from turning bluetooth on or off. * The default value is <code>false</code>. + * <p>This restriction doesn't prevent the user from using bluetooth. For disallowing usage of + * bluetooth completely on the device, use {@link #DISALLOW_BLUETOOTH}. * <p>This restriction has no effect in a managed profile. * * <p>Key for user restrictions. @@ -197,6 +199,20 @@ public class UserManager { public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth"; /** + * Specifies if bluetooth is disallowed on the device. + * + * <p> This restriction can only be set by the device owner and the profile owner on the + * primary user and it applies globally - i.e. it disables bluetooth on the entire device. + * <p>The default value is <code>false</code>. + * <p>Key for user restrictions. + * <p>Type: Boolean + * @see DevicePolicyManager#addUserRestriction(ComponentName, String) + * @see DevicePolicyManager#clearUserRestriction(ComponentName, String) + * @see #getUserRestrictions() + */ + public static final String DISALLOW_BLUETOOTH = "no_bluetooth"; + + /** * Specifies if a user is disallowed from transferring files over * USB. This can only be set by device owners and profile owners on the primary user. * The default value is <code>false</code>. diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java index 5b365983f07c..5b38ebfbcde3 100644 --- a/services/core/java/com/android/server/BluetoothManagerService.java +++ b/services/core/java/com/android/server/BluetoothManagerService.java @@ -41,6 +41,7 @@ import android.content.pm.UserInfo; import android.database.ContentObserver; import android.os.Binder; import android.os.Build; +import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Looper; @@ -51,6 +52,8 @@ import android.os.RemoteException; import android.os.SystemClock; import android.os.UserHandle; import android.os.UserManager; +import android.os.UserManagerInternal; +import android.os.UserManagerInternal.UserRestrictionsListener; import android.provider.Settings; import android.provider.Settings.SettingNotFoundException; import android.util.Slog; @@ -176,6 +179,24 @@ class BluetoothManagerService extends IBluetoothManager.Stub { } }; + private final UserRestrictionsListener mUserRestrictionsListener = + new UserRestrictionsListener() { + @Override + public void onUserRestrictionsChanged(int userId, Bundle newRestrictions, + Bundle prevRestrictions) { + final boolean bluetoothDisallowed = + newRestrictions.getBoolean(UserManager.DISALLOW_BLUETOOTH); + if ((mEnable || mEnableExternal) && bluetoothDisallowed) { + try { + disable(null, true); + } catch (RemoteException e) { + Slog.w(TAG, "Exception when disabling Bluetooth from UserRestrictionsListener", + e); + } + } + } + }; + private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -612,6 +633,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub { public boolean enableNoAutoConnect() { + if (isBluetoothDisallowed()) { + if (DBG) { + Slog.d(TAG, "enableNoAutoConnect(): not enabling - bluetooth disallowed"); + } + return false; + } + mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission"); @@ -637,6 +665,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub { final int callingUid = Binder.getCallingUid(); final boolean callerSystem = UserHandle.getAppId(callingUid) == Process.SYSTEM_UID; + if (isBluetoothDisallowed()) { + if (DBG) { + Slog.d(TAG,"enable(): not enabling - bluetooth disallowed"); + } + return false; + } + if (!callerSystem) { if (!checkIfCallerIsForegroundUser()) { Slog.w(TAG, "enable(): not allowed for non-active and non system user"); @@ -841,6 +876,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub { */ public void handleOnBootPhase() { if (DBG) Slog.d(TAG, "Bluetooth boot completed"); + UserManagerInternal userManagerInternal = + LocalServices.getService(UserManagerInternal.class); + userManagerInternal.addUserRestrictionsListener(mUserRestrictionsListener); + if (isBluetoothDisallowed()) { + return; + } if (mEnableExternal && isBluetoothPersistedStateOnBluetooth()) { if (DBG) Slog.d(TAG, "Auto-enabling Bluetooth."); sendEnableMsg(mQuietEnableExternal); @@ -1883,6 +1924,16 @@ class BluetoothManagerService extends IBluetoothManager.Stub { } } + private boolean isBluetoothDisallowed() { + long callingIdentity = Binder.clearCallingIdentity(); + try { + return mContext.getSystemService(UserManager.class) + .hasUserRestriction(UserManager.DISALLOW_BLUETOOTH, UserHandle.SYSTEM); + } finally { + Binder.restoreCallingIdentity(callingIdentity); + } + } + @Override public void dump(FileDescriptor fd, PrintWriter writer, String[] args) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG); diff --git a/services/core/java/com/android/server/pm/UserRestrictionsUtils.java b/services/core/java/com/android/server/pm/UserRestrictionsUtils.java index 38a3f421264f..f08f6bb9cf1a 100644 --- a/services/core/java/com/android/server/pm/UserRestrictionsUtils.java +++ b/services/core/java/com/android/server/pm/UserRestrictionsUtils.java @@ -73,6 +73,7 @@ public class UserRestrictionsUtils { UserManager.DISALLOW_SHARE_LOCATION, UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, UserManager.DISALLOW_CONFIG_BLUETOOTH, + UserManager.DISALLOW_BLUETOOTH, UserManager.DISALLOW_USB_FILE_TRANSFER, UserManager.DISALLOW_CONFIG_CREDENTIALS, UserManager.DISALLOW_REMOVE_USER, @@ -117,6 +118,7 @@ public class UserRestrictionsUtils { * User restrictions that can not be set by profile owners. */ private static final Set<String> DEVICE_OWNER_ONLY_RESTRICTIONS = Sets.newArraySet( + UserManager.DISALLOW_BLUETOOTH, UserManager.DISALLOW_USB_FILE_TRANSFER, UserManager.DISALLOW_CONFIG_TETHERING, UserManager.DISALLOW_NETWORK_RESET, |