summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Lenka Trochtova <ltrochtova@google.com> 2017-01-09 19:48:51 +0100
committer Lenka Trochtova <ltrochtova@google.com> 2017-01-10 10:54:14 +0100
commit77fe44ffb6b5d40daf3b127cb36d5111b7618cc1 (patch)
tree2c597f241f4fda5bbce318bd8dbc1b690407b71d
parent6a9ad14172619b7d61a5119d7f95e613d890f603 (diff)
Don't offer the BT sharing option to the user if BT is disallowed.
Disable BluetoothOppLauncherActivity component if the UserManager#BLUETOOTH_DISALLOWED user restriction is set. Test: cts-tradefed run cts -m CtsDevicePolicyManagerTestCases --test com.android.cts.devicepolicy.DeviceOwnerTest#testBluetoothRestriction Bug: 32895060 Change-Id: I4316843b2858aefa750f12a8a0e940424aa21a10
-rw-r--r--services/core/java/com/android/server/BluetoothManagerService.java28
1 files changed, 27 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java
index 4f43eac8b3ca..f2e1fb678189 100644
--- a/services/core/java/com/android/server/BluetoothManagerService.java
+++ b/services/core/java/com/android/server/BluetoothManagerService.java
@@ -217,6 +217,11 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
@Override
public void onUserRestrictionsChanged(int userId, Bundle newRestrictions,
Bundle prevRestrictions) {
+ if (!newRestrictions.containsKey(UserManager.DISALLOW_BLUETOOTH)
+ && !prevRestrictions.containsKey(UserManager.DISALLOW_BLUETOOTH)) {
+ // The relevant restriction has not changed - do nothing.
+ return;
+ }
final boolean bluetoothDisallowed =
newRestrictions.getBoolean(UserManager.DISALLOW_BLUETOOTH);
if ((mEnable || mEnableExternal) && bluetoothDisallowed) {
@@ -227,6 +232,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
// when from system.
}
}
+ updateOppLauncherComponentState(bluetoothDisallowed);
}
};
@@ -938,7 +944,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
UserManagerInternal userManagerInternal =
LocalServices.getService(UserManagerInternal.class);
userManagerInternal.addUserRestrictionsListener(mUserRestrictionsListener);
- if (isBluetoothDisallowed()) {
+ final boolean isBluetoothDisallowed = isBluetoothDisallowed();
+ updateOppLauncherComponentState(isBluetoothDisallowed);
+ if (isBluetoothDisallowed) {
return;
}
if (mEnableExternal && isBluetoothPersistedStateOnBluetooth()) {
@@ -1995,6 +2003,24 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
}
}
+ /**
+ * Disables BluetoothOppLauncherActivity component, so the Bluetooth sharing option is not
+ * offered to the user if Bluetooth is disallowed. Puts the component to its default state if
+ * Bluetooth is not disallowed.
+ *
+ * @param bluetoothDisallowed whether the {@link UserManager.DISALLOW_BLUETOOTH} user
+ * restriction was set.
+ */
+ private void updateOppLauncherComponentState(boolean bluetoothDisallowed) {
+ final ComponentName oppLauncherComponent = new ComponentName("com.android.bluetooth",
+ "com.android.bluetooth.opp.BluetoothOppLauncherActivity");
+ final int newState = bluetoothDisallowed
+ ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
+ : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
+ mContext.getPackageManager()
+ .setComponentEnabledSetting(oppLauncherComponent, newState, 0);
+ }
+
@Override
public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);