From 78b250599b6fcb68a0ad1afe795499cc79caddf5 Mon Sep 17 00:00:00 2001 From: Tim Peng Date: Sat, 11 Sep 2021 05:56:08 +0000 Subject: [PATCH] DO NOT MERGE: HA still appears in Media device list even though it has been unpaired. -Add mUnpairing to mark the device triggers removeBond() -For HA, once it calls removeBond(), two HA would be unpaired. It causes the incorrect state if we do main/sub devices switching. Bug: 198124571 Test: manual test Merged-In: I4ed5db2bd01f4b4e8f246ed3e8f74e24149571f9 Change-Id: I4ed5db2bd01f4b4e8f246ed3e8f74e24149571f9 (cherry picked from commit 5597cbd76befe3e19523aed70327d9d232d18476) --- .../settingslib/bluetooth/CachedBluetoothDevice.java | 7 ++++++- .../settingslib/bluetooth/HearingAidDeviceManager.java | 3 +++ 2 files changed, 9 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 021ba2247e67f..cac34aebc073c 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java @@ -21,7 +21,6 @@ import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothCsipSetCoordinator; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHearingAid; -import android.bluetooth.BluetoothLeAudio; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothUuid; import android.content.Context; @@ -116,6 +115,7 @@ public class CachedBluetoothDevice implements Comparable private boolean mIsHeadsetProfileConnectedFail = false; private boolean mIsHearingAidProfileConnectedFail = false; private boolean mIsLeAudioProfileConnectedFail = false; + private boolean mUnpairing = false; // Group second device for Hearing Aid private CachedBluetoothDevice mSubDevice; // Group member devices for the coordinated set @@ -457,6 +457,7 @@ public class CachedBluetoothDevice implements Comparable if (state != BluetoothDevice.BOND_NONE) { final BluetoothDevice dev = mDevice; if (dev != null) { + mUnpairing = true; final boolean successful = dev.removeBond(); if (successful) { releaseLruCache(); @@ -1387,4 +1388,8 @@ public class CachedBluetoothDevice implements Comparable void releaseLruCache() { mDrawableCache.evictAll(); } + + boolean getUnpairing() { + return mUnpairing; + } } diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidDeviceManager.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidDeviceManager.java index 20ece69d7281b..818f5ca33ebf6 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidDeviceManager.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidDeviceManager.java @@ -180,6 +180,9 @@ public class HearingAidDeviceManager { break; case BluetoothProfile.STATE_DISCONNECTED: mainDevice = findMainDevice(cachedDevice); + if (cachedDevice.getUnpairing()) { + return true; + } if (mainDevice != null) { // When main device exists, receiving sub device disconnection // To update main device UI