summaryrefslogtreecommitdiff
path: root/service/java/com/android/server/bluetooth/BluetoothManagerService.java
diff options
context:
space:
mode:
authorRahul Sabnis <rahulsabnis@google.com>2022-03-31 19:39:06 -0700
committerZach Johnson <zachoverflow@google.com>2022-04-06 13:25:47 -0700
commit991914d3e41155b5f085163352b5b78a33992f73 (patch)
tree429bf50d0f2c886319372438248cec51d83f5298 /service/java/com/android/server/bluetooth/BluetoothManagerService.java
parentf91afd6e590dfbfce7690a264103592704b0398d (diff)
Replace logic to determine the foreground user id with the SystemService
callback Tag: #feature Bug: 226404651 Test: Manual Ignore-AOSP-First: Resolving merge conflict Change-Id: I78e6ead277785dff4cbbf8fc218dc68dccdc28a5
Diffstat (limited to 'service/java/com/android/server/bluetooth/BluetoothManagerService.java')
-rw-r--r--service/java/com/android/server/bluetooth/BluetoothManagerService.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/service/java/com/android/server/bluetooth/BluetoothManagerService.java b/service/java/com/android/server/bluetooth/BluetoothManagerService.java
index a1ea210609..a1efcf3c63 100644
--- a/service/java/com/android/server/bluetooth/BluetoothManagerService.java
+++ b/service/java/com/android/server/bluetooth/BluetoothManagerService.java
@@ -216,6 +216,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
private final ReentrantReadWriteLock mBluetoothLock = new ReentrantReadWriteLock();
private boolean mBinding;
private boolean mUnbinding;
+ private int mForegroundUserId;
private BluetoothModeChangeHelper mBluetoothModeChangeHelper;
@@ -543,6 +544,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
String value = SystemProperties.get(
"persist.sys.fflag.override.settings_bluetooth_hearing_aid");
+ mForegroundUserId = UserHandle.SYSTEM.getIdentifier();
+
if (!TextUtils.isEmpty(value)) {
boolean isHearingAidEnabled = Boolean.parseBoolean(value);
Log.v(TAG, "set feature flag HEARING_AID_SETTINGS to " + isHearingAidEnabled);
@@ -857,6 +860,25 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
}
+ /**
+ * Sends the current foreground user id to the Bluetooth process. This user id is used to
+ * determine if Binder calls are coming from the active user.
+ *
+ * @param userId is the foreground user id we are propagating to the Bluetooth process
+ */
+ private void propagateForegroundUserId(int userId) {
+ mBluetoothLock.readLock().lock();
+ try {
+ if (mBluetooth != null) {
+ mBluetooth.setForegroundUserId(userId, mContext.getAttributionSource());
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "Unable to set foreground user id", e);
+ } finally {
+ mBluetoothLock.readLock().unlock();
+ }
+ }
+
public int getState() {
if ((Binder.getCallingUid() != Process.SYSTEM_UID) && (!checkIfCallerIsForegroundUser())) {
Log.w(TAG, "getState(): report OFF for non-active and non system user");
@@ -2215,6 +2237,8 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
BluetoothAdapter.STATE_BLE_TURNING_ON,
BluetoothAdapter.STATE_BLE_ON,
BluetoothAdapter.STATE_BLE_TURNING_OFF));
+ } else {
+ propagateForegroundUserId(mForegroundUserId);
}
break;
}
@@ -2352,6 +2376,12 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
}
mHandler.removeMessages(MESSAGE_USER_SWITCHED);
+ // Save the foreground user id and propagate to BT process after it's restarted
+ int toUserId = msg.arg1;
+ if (mForegroundUserId != toUserId) {
+ mForegroundUserId = toUserId;
+ }
+
/* disable and enable BT when detect a user switch */
if (mBluetooth != null && isEnabled()) {
restartForReason(BluetoothProtoEnums.ENABLE_DISABLE_REASON_USER_SWITCH);