Loading service/java/com/android/server/bluetooth/BluetoothManagerService.java +38 −38 Original line number Diff line number Diff line Loading @@ -42,11 +42,11 @@ import android.bluetooth.IBluetooth; import android.bluetooth.IBluetoothCallback; import android.bluetooth.IBluetoothGatt; import android.bluetooth.IBluetoothHeadset; import android.bluetooth.IBluetoothLeCallControl; import android.bluetooth.IBluetoothManager; import android.bluetooth.IBluetoothManagerCallback; import android.bluetooth.IBluetoothProfileServiceConnection; import android.bluetooth.IBluetoothStateChangeCallback; import android.bluetooth.IBluetoothLeCallControl; import android.content.ActivityNotFoundException; import android.content.AttributionSource; import android.content.BroadcastReceiver; Loading Loading @@ -89,9 +89,6 @@ import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.DumpUtils; import com.android.internal.util.FrameworkStatsLog; import com.android.server.pm.UserManagerInternal; import com.android.server.pm.UserManagerInternal.UserRestrictionsListener; import com.android.server.pm.UserRestrictionsUtils; import java.io.FileDescriptor; import java.io.PrintWriter; Loading Loading @@ -174,6 +171,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub { private final Context mContext; private final UserManager mUserManager; // Locks are not provided for mName and mAddress. // They are accessed in handler or broadcast receiver, same thread context. private String mAddress; Loading Loading @@ -270,34 +269,25 @@ class BluetoothManagerService extends IBluetoothManager.Stub { } }; private final UserRestrictionsListener mUserRestrictionsListener = new UserRestrictionsListener() { @Override public void onUserRestrictionsChanged(int userId, Bundle newRestrictions, Bundle prevRestrictions) { if (UserRestrictionsUtils.restrictionsChanged(prevRestrictions, newRestrictions, UserManager.DISALLOW_BLUETOOTH_SHARING)) { updateOppLauncherComponentState(userId, newRestrictions.getBoolean(UserManager.DISALLOW_BLUETOOTH_SHARING)); } public void onUserRestrictionsChanged(UserHandle userHandle) { final boolean newBluetoothDisallowed = mUserManager.hasUserRestrictionForUser( UserManager.DISALLOW_BLUETOOTH, userHandle); boolean newBluetoothSharingDisallowed = mUserManager.hasUserRestrictionForUser( UserManager.DISALLOW_BLUETOOTH_SHARING, userHandle); // DISALLOW_BLUETOOTH can only be set by DO or PO on the system user. if (userId == USER_SYSTEM && UserRestrictionsUtils.restrictionsChanged(prevRestrictions, newRestrictions, UserManager.DISALLOW_BLUETOOTH)) { if (userId == USER_SYSTEM && newRestrictions.getBoolean( UserManager.DISALLOW_BLUETOOTH)) { updateOppLauncherComponentState(userId, true); // Sharing disallowed if (userHandle == UserHandle.SYSTEM) { if (newBluetoothDisallowed) { updateOppLauncherComponentState(userHandle, true); // Sharing disallowed sendDisableMsg(BluetoothProtoEnums.ENABLE_DISABLE_REASON_DISALLOWED, mContext.getPackageName()); } else { updateOppLauncherComponentState(userId, newRestrictions.getBoolean( UserManager.DISALLOW_BLUETOOTH_SHARING)); updateOppLauncherComponentState(userHandle, newBluetoothSharingDisallowed); } } else { updateOppLauncherComponentState(userHandle, newBluetoothSharingDisallowed); } } }; @VisibleForTesting public void onInitFlagsChanged() { Loading Loading @@ -500,6 +490,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub { mCallbacks = new RemoteCallbackList<IBluetoothManagerCallback>(); mStateChangeCallbacks = new RemoteCallbackList<IBluetoothStateChangeCallback>(); mUserManager = mContext.getSystemService(UserManager.class); mIsHearingAidProfileSupported = context.getResources() .getBoolean(com.android.internal.R.bool.config_hearing_aid_profile_supported); Loading @@ -524,6 +516,16 @@ class BluetoothManagerService extends IBluetoothManager.Stub { filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); mContext.registerReceiver(mReceiver, filter); IntentFilter filterUser = new IntentFilter(); filterUser.addAction(UserManager.ACTION_USER_RESTRICTIONS_CHANGED); filterUser.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); mContext.registerReceiverForAllUsers(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { onUserRestrictionsChanged(getSendingUser()); } }, filterUser, null, null); loadStoredNameAndAddress(); if (isBluetoothPersistedStateOn()) { if (DBG) { Loading Loading @@ -1401,9 +1403,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub { Slog.d(TAG, "Bluetooth boot completed"); } mAppOps = mContext.getSystemService(AppOpsManager.class); UserManagerInternal userManagerInternal = LocalServices.getService(UserManagerInternal.class); userManagerInternal.addUserRestrictionsListener(mUserRestrictionsListener); final boolean isBluetoothDisallowed = isBluetoothDisallowed(); if (isBluetoothDisallowed) { return; Loading Loading @@ -2754,10 +2753,11 @@ class BluetoothManagerService extends IBluetoothManager.Stub { * offered to the user if Bluetooth or sharing is disallowed. Puts the component to its default * state if Bluetooth is not disallowed. * * @param userId user to disable bluetooth sharing for. * @param userHandle user to disable bluetooth sharing for * @param bluetoothSharingDisallowed whether bluetooth sharing is disallowed. */ private void updateOppLauncherComponentState(int userId, boolean bluetoothSharingDisallowed) { private void updateOppLauncherComponentState(UserHandle userHandle, boolean bluetoothSharingDisallowed) { final ComponentName oppLauncherComponent = new ComponentName("com.android.bluetooth", "com.android.bluetooth.opp.BluetoothOppLauncherActivity"); final int newState = Loading @@ -2766,7 +2766,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { try { final IPackageManager imp = AppGlobals.getPackageManager(); imp.setComponentEnabledSetting(oppLauncherComponent, newState, PackageManager.DONT_KILL_APP, userId); PackageManager.DONT_KILL_APP, userHandle.getIdentifier()); } catch (Exception e) { // The component was not found, do nothing. } Loading Loading
service/java/com/android/server/bluetooth/BluetoothManagerService.java +38 −38 Original line number Diff line number Diff line Loading @@ -42,11 +42,11 @@ import android.bluetooth.IBluetooth; import android.bluetooth.IBluetoothCallback; import android.bluetooth.IBluetoothGatt; import android.bluetooth.IBluetoothHeadset; import android.bluetooth.IBluetoothLeCallControl; import android.bluetooth.IBluetoothManager; import android.bluetooth.IBluetoothManagerCallback; import android.bluetooth.IBluetoothProfileServiceConnection; import android.bluetooth.IBluetoothStateChangeCallback; import android.bluetooth.IBluetoothLeCallControl; import android.content.ActivityNotFoundException; import android.content.AttributionSource; import android.content.BroadcastReceiver; Loading Loading @@ -89,9 +89,6 @@ import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.DumpUtils; import com.android.internal.util.FrameworkStatsLog; import com.android.server.pm.UserManagerInternal; import com.android.server.pm.UserManagerInternal.UserRestrictionsListener; import com.android.server.pm.UserRestrictionsUtils; import java.io.FileDescriptor; import java.io.PrintWriter; Loading Loading @@ -174,6 +171,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub { private final Context mContext; private final UserManager mUserManager; // Locks are not provided for mName and mAddress. // They are accessed in handler or broadcast receiver, same thread context. private String mAddress; Loading Loading @@ -270,34 +269,25 @@ class BluetoothManagerService extends IBluetoothManager.Stub { } }; private final UserRestrictionsListener mUserRestrictionsListener = new UserRestrictionsListener() { @Override public void onUserRestrictionsChanged(int userId, Bundle newRestrictions, Bundle prevRestrictions) { if (UserRestrictionsUtils.restrictionsChanged(prevRestrictions, newRestrictions, UserManager.DISALLOW_BLUETOOTH_SHARING)) { updateOppLauncherComponentState(userId, newRestrictions.getBoolean(UserManager.DISALLOW_BLUETOOTH_SHARING)); } public void onUserRestrictionsChanged(UserHandle userHandle) { final boolean newBluetoothDisallowed = mUserManager.hasUserRestrictionForUser( UserManager.DISALLOW_BLUETOOTH, userHandle); boolean newBluetoothSharingDisallowed = mUserManager.hasUserRestrictionForUser( UserManager.DISALLOW_BLUETOOTH_SHARING, userHandle); // DISALLOW_BLUETOOTH can only be set by DO or PO on the system user. if (userId == USER_SYSTEM && UserRestrictionsUtils.restrictionsChanged(prevRestrictions, newRestrictions, UserManager.DISALLOW_BLUETOOTH)) { if (userId == USER_SYSTEM && newRestrictions.getBoolean( UserManager.DISALLOW_BLUETOOTH)) { updateOppLauncherComponentState(userId, true); // Sharing disallowed if (userHandle == UserHandle.SYSTEM) { if (newBluetoothDisallowed) { updateOppLauncherComponentState(userHandle, true); // Sharing disallowed sendDisableMsg(BluetoothProtoEnums.ENABLE_DISABLE_REASON_DISALLOWED, mContext.getPackageName()); } else { updateOppLauncherComponentState(userId, newRestrictions.getBoolean( UserManager.DISALLOW_BLUETOOTH_SHARING)); updateOppLauncherComponentState(userHandle, newBluetoothSharingDisallowed); } } else { updateOppLauncherComponentState(userHandle, newBluetoothSharingDisallowed); } } }; @VisibleForTesting public void onInitFlagsChanged() { Loading Loading @@ -500,6 +490,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub { mCallbacks = new RemoteCallbackList<IBluetoothManagerCallback>(); mStateChangeCallbacks = new RemoteCallbackList<IBluetoothStateChangeCallback>(); mUserManager = mContext.getSystemService(UserManager.class); mIsHearingAidProfileSupported = context.getResources() .getBoolean(com.android.internal.R.bool.config_hearing_aid_profile_supported); Loading @@ -524,6 +516,16 @@ class BluetoothManagerService extends IBluetoothManager.Stub { filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); mContext.registerReceiver(mReceiver, filter); IntentFilter filterUser = new IntentFilter(); filterUser.addAction(UserManager.ACTION_USER_RESTRICTIONS_CHANGED); filterUser.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); mContext.registerReceiverForAllUsers(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { onUserRestrictionsChanged(getSendingUser()); } }, filterUser, null, null); loadStoredNameAndAddress(); if (isBluetoothPersistedStateOn()) { if (DBG) { Loading Loading @@ -1401,9 +1403,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub { Slog.d(TAG, "Bluetooth boot completed"); } mAppOps = mContext.getSystemService(AppOpsManager.class); UserManagerInternal userManagerInternal = LocalServices.getService(UserManagerInternal.class); userManagerInternal.addUserRestrictionsListener(mUserRestrictionsListener); final boolean isBluetoothDisallowed = isBluetoothDisallowed(); if (isBluetoothDisallowed) { return; Loading Loading @@ -2754,10 +2753,11 @@ class BluetoothManagerService extends IBluetoothManager.Stub { * offered to the user if Bluetooth or sharing is disallowed. Puts the component to its default * state if Bluetooth is not disallowed. * * @param userId user to disable bluetooth sharing for. * @param userHandle user to disable bluetooth sharing for * @param bluetoothSharingDisallowed whether bluetooth sharing is disallowed. */ private void updateOppLauncherComponentState(int userId, boolean bluetoothSharingDisallowed) { private void updateOppLauncherComponentState(UserHandle userHandle, boolean bluetoothSharingDisallowed) { final ComponentName oppLauncherComponent = new ComponentName("com.android.bluetooth", "com.android.bluetooth.opp.BluetoothOppLauncherActivity"); final int newState = Loading @@ -2766,7 +2766,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { try { final IPackageManager imp = AppGlobals.getPackageManager(); imp.setComponentEnabledSetting(oppLauncherComponent, newState, PackageManager.DONT_KILL_APP, userId); PackageManager.DONT_KILL_APP, userHandle.getIdentifier()); } catch (Exception e) { // The component was not found, do nothing. } Loading