diff options
| author | 2024-03-13 01:45:46 +0800 | |
|---|---|---|
| committer | 2024-03-12 17:52:48 +0000 | |
| commit | 1f07e88880ee253818033e0c9da18c47537dc99e (patch) | |
| tree | 14d8e1add57c39d87122e8ef795f688f8f91d694 | |
| parent | 7b05e435f3b937110441eae861cb327cb4fa0d83 (diff) | |
[Audiosharing] Fix fallback device selection.
Use LE audio profile to get group id as fallback for non-CSIP device.
Test: manual
Fix: 328820792
Change-Id: Icc453844fad9c70bb259033e55212a337a2fbaf1
| -rw-r--r-- | packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java index bd27c896a3c4..1118efc3e953 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java @@ -81,11 +81,13 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile { public static final int BROADCAST_STATE_UNKNOWN = 0; public static final int BROADCAST_STATE_ON = 1; public static final int BROADCAST_STATE_OFF = 2; + @Retention(RetentionPolicy.SOURCE) @IntDef( prefix = {"BROADCAST_STATE_"}, value = {BROADCAST_STATE_UNKNOWN, BROADCAST_STATE_ON, BROADCAST_STATE_OFF}) public @interface BroadcastState {} + private static final String SETTINGS_PKG = "com.android.settings"; private static final String TAG = "LocalBluetoothLeBroadcast"; private static final boolean DEBUG = BluetoothUtils.D; @@ -1068,7 +1070,7 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile { return; } int fallbackActiveGroupId = getFallbackActiveGroupId(); - if (targetCachedDevice.getGroupId() == fallbackActiveGroupId) { + if (getGroupId(targetCachedDevice) == fallbackActiveGroupId) { Log.d( TAG, "Skip updateFallbackActiveDeviceIfNeeded, already is fallback: " @@ -1091,6 +1093,23 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile { BluetoothCsipSetCoordinator.GROUP_ID_INVALID); } + private int getGroupId(CachedBluetoothDevice cachedDevice) { + int groupId = cachedDevice.getGroupId(); + String anonymizedAddress = cachedDevice.getDevice().getAnonymizedAddress(); + if (groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID) { + Log.d(TAG, "getGroupId by CSIP profile for device: " + anonymizedAddress); + return groupId; + } + for (LocalBluetoothProfile profile : cachedDevice.getProfiles()) { + if (profile instanceof LeAudioProfile) { + Log.d(TAG, "getGroupId by LEA profile for device: " + anonymizedAddress); + return ((LeAudioProfile) profile).getGroupId(cachedDevice.getDevice()); + } + } + Log.d(TAG, "getGroupId return invalid id for device: " + anonymizedAddress); + return BluetoothCsipSetCoordinator.GROUP_ID_INVALID; + } + private void notifyBroadcastStateChange(@BroadcastState int state) { if (!mContext.getPackageName().equals(SETTINGS_PKG)) { Log.d(TAG, "Skip notifyBroadcastStateChange, not triggered by Settings."); |