From ec6e7c971a4b12aea0a33737aca4ebddb9212849 Mon Sep 17 00:00:00 2001 From: Angela Wang Date: Wed, 12 Jul 2023 07:27:10 +0000 Subject: [PATCH] Ignore ASHA hisyncId grouping if the device supports CSIP If a device is added as another device's sub device, it'll be removed from the cached device list. This makes the device can't be correctly grouped as a CSIP set when CSIP is connected. We should ignore ASHA hisyncId grouping and leave it to be handled as a member of CSIP set. Bug: 288284097 Test: atest CachedBluetoothDeviceTest Test: atest HearingAidDeviceManagerTest Change-Id: Ibf10198521d3186186e87f96b13475185e51e856 --- .../settingslib/bluetooth/CachedBluetoothDevice.java | 10 +++++++++- .../settingslib/bluetooth/HearingAidDeviceManager.java | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java index f522fd13c9f8e..1f5127ba6ae46 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java @@ -1522,10 +1522,15 @@ public class CachedBluetoothDevice implements Comparable * list. */ public void switchMemberDeviceContent(CachedBluetoothDevice newMainDevice) { - // Backup from main device + // Remove the sub device from mMemberDevices first to prevent hash mismatch problem due + // to mDevice switch + removeMemberDevice(newMainDevice); + + // Backup from current main device final BluetoothDevice tmpDevice = mDevice; final short tmpRssi = mRssi; final boolean tmpJustDiscovered = mJustDiscovered; + // Set main device from sub device release(); mDevice = newMainDevice.mDevice; @@ -1539,6 +1544,9 @@ public class CachedBluetoothDevice implements Comparable newMainDevice.mRssi = tmpRssi; newMainDevice.mJustDiscovered = tmpJustDiscovered; newMainDevice.fillData(); + + // Add the sub device back into mMemberDevices with correct hash + addMemberDevice(newMainDevice); } /** diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidDeviceManager.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidDeviceManager.java index e5e57824f6ef0..f59936119a5d8 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidDeviceManager.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidDeviceManager.java @@ -167,6 +167,14 @@ public class HearingAidDeviceManager { if (cachedDevice.getHiSyncId() != hiSyncId) { continue; } + + // The remote device supports CSIP, the other ear should be processed as a member + // device. Ignore hiSyncId grouping from ASHA here. + if (cachedDevice.getProfiles().stream().anyMatch( + profile -> profile instanceof CsipSetCoordinatorProfile)) { + continue; + } + if (firstMatchedIndex == -1) { // Found the first one firstMatchedIndex = i;