Introduce a new user restriction for disallowing Bluetooth.
Only the device owner will be able to set the restriction and the restriction will prevent usage of Bluetooth on the entire device - i.e. in all the users. Test: cts-tradefed run cts -m CtsDevicePolicyManagerTestCases --test com.android.cts.devicepolicy.UserRestrictionsTest Test: cts-tradefed run cts -m CtsDevicePolicyManagerTestCases --test com.android.cts.devicepolicy.DeviceOwnerTest#testBluetoothRestriction Bug: 32895300 Merged-In: I2875cf178cb16eca1965d0ba965d1cd3d8db2ad5 Change-Id: I2875cf178cb16eca1965d0ba965d1cd3d8db2ad5
This commit is contained in:
@@ -29379,6 +29379,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_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_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_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_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_CELL_BROADCASTS = "no_config_cell_broadcasts";
|
||||||
field public static final java.lang.String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
|
field public static final java.lang.String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
|
||||||
|
|||||||
@@ -31956,6 +31956,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_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_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_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_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_CELL_BROADCASTS = "no_config_cell_broadcasts";
|
||||||
field public static final java.lang.String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
|
field public static final java.lang.String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
|
||||||
|
|||||||
@@ -29454,6 +29454,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_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_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_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_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_CELL_BROADCASTS = "no_config_cell_broadcasts";
|
||||||
field public static final java.lang.String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
|
field public static final java.lang.String DISALLOW_CONFIG_CREDENTIALS = "no_config_credentials";
|
||||||
|
|||||||
@@ -186,6 +186,8 @@ public class UserManager {
|
|||||||
* Specifies if a user is disallowed from configuring bluetooth.
|
* Specifies if a user is disallowed from configuring bluetooth.
|
||||||
* This does <em>not</em> restrict the user from turning bluetooth on or off.
|
* This does <em>not</em> restrict the user from turning bluetooth on or off.
|
||||||
* The default value is <code>false</code>.
|
* 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>This restriction has no effect in a managed profile.
|
||||||
*
|
*
|
||||||
* <p>Key for user restrictions.
|
* <p>Key for user restrictions.
|
||||||
@@ -196,6 +198,20 @@ public class UserManager {
|
|||||||
*/
|
*/
|
||||||
public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
|
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
|
* 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.
|
* USB. This can only be set by device owners and profile owners on the primary user.
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import android.content.pm.PackageManager;
|
|||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
@@ -49,6 +50,8 @@ import android.os.RemoteException;
|
|||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
import android.os.UserManagerInternal;
|
||||||
|
import android.os.UserManagerInternal.UserRestrictionsListener;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.provider.Settings.SettingNotFoundException;
|
import android.provider.Settings.SettingNotFoundException;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
@@ -172,6 +175,19 @@ 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) {
|
||||||
|
disable(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
@@ -621,6 +637,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
|
|
||||||
public boolean enableNoAutoConnect()
|
public boolean enableNoAutoConnect()
|
||||||
{
|
{
|
||||||
|
if (isBluetoothDisallowed()) {
|
||||||
|
if (DBG) {
|
||||||
|
Slog.d(TAG, "enableNoAutoConnect(): not enabling - bluetooth disallowed");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
|
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
|
||||||
"Need BLUETOOTH ADMIN permission");
|
"Need BLUETOOTH ADMIN permission");
|
||||||
|
|
||||||
@@ -643,6 +666,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean enable() {
|
public boolean enable() {
|
||||||
|
if (isBluetoothDisallowed()) {
|
||||||
|
if (DBG) {
|
||||||
|
Slog.d(TAG,"enable(): not enabling - bluetooth disallowed");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
|
if ((Binder.getCallingUid() != Process.SYSTEM_UID) &&
|
||||||
(!checkIfCallerIsForegroundUser())) {
|
(!checkIfCallerIsForegroundUser())) {
|
||||||
Slog.w(TAG,"enable(): not allowed for non-active and non system user");
|
Slog.w(TAG,"enable(): not allowed for non-active and non system user");
|
||||||
@@ -804,6 +834,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
*/
|
*/
|
||||||
public void handleOnBootPhase() {
|
public void handleOnBootPhase() {
|
||||||
if (DBG) Slog.d(TAG, "Bluetooth boot completed");
|
if (DBG) Slog.d(TAG, "Bluetooth boot completed");
|
||||||
|
UserManagerInternal userManagerInternal =
|
||||||
|
LocalServices.getService(UserManagerInternal.class);
|
||||||
|
userManagerInternal.addUserRestrictionsListener(mUserRestrictionsListener);
|
||||||
|
if (isBluetoothDisallowed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (mEnableExternal && isBluetoothPersistedStateOnBluetooth()) {
|
if (mEnableExternal && isBluetoothPersistedStateOnBluetooth()) {
|
||||||
if (DBG) Slog.d(TAG, "Auto-enabling Bluetooth.");
|
if (DBG) Slog.d(TAG, "Auto-enabling Bluetooth.");
|
||||||
sendEnableMsg(mQuietEnableExternal);
|
sendEnableMsg(mQuietEnableExternal);
|
||||||
@@ -1846,6 +1882,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
|
@Override
|
||||||
public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
|
public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
|
||||||
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
|
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ public class UserRestrictionsUtils {
|
|||||||
UserManager.DISALLOW_SHARE_LOCATION,
|
UserManager.DISALLOW_SHARE_LOCATION,
|
||||||
UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES,
|
UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES,
|
||||||
UserManager.DISALLOW_CONFIG_BLUETOOTH,
|
UserManager.DISALLOW_CONFIG_BLUETOOTH,
|
||||||
|
UserManager.DISALLOW_BLUETOOTH,
|
||||||
UserManager.DISALLOW_USB_FILE_TRANSFER,
|
UserManager.DISALLOW_USB_FILE_TRANSFER,
|
||||||
UserManager.DISALLOW_CONFIG_CREDENTIALS,
|
UserManager.DISALLOW_CONFIG_CREDENTIALS,
|
||||||
UserManager.DISALLOW_REMOVE_USER,
|
UserManager.DISALLOW_REMOVE_USER,
|
||||||
@@ -118,6 +119,7 @@ public class UserRestrictionsUtils {
|
|||||||
* User restrictions that can not be set by profile owners.
|
* User restrictions that can not be set by profile owners.
|
||||||
*/
|
*/
|
||||||
private static final Set<String> DEVICE_OWNER_ONLY_RESTRICTIONS = Sets.newArraySet(
|
private static final Set<String> DEVICE_OWNER_ONLY_RESTRICTIONS = Sets.newArraySet(
|
||||||
|
UserManager.DISALLOW_BLUETOOTH,
|
||||||
UserManager.DISALLOW_USB_FILE_TRANSFER,
|
UserManager.DISALLOW_USB_FILE_TRANSFER,
|
||||||
UserManager.DISALLOW_CONFIG_TETHERING,
|
UserManager.DISALLOW_CONFIG_TETHERING,
|
||||||
UserManager.DISALLOW_NETWORK_RESET,
|
UserManager.DISALLOW_NETWORK_RESET,
|
||||||
|
|||||||
Reference in New Issue
Block a user