summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author SongFerngWang <songferngwang@google.com> 2022-12-16 17:55:41 +0800
committer SongFerngWang <songferngwang@google.com> 2022-12-16 21:18:00 +0800
commit453c9ee2b7865977d0b39a9f7189b75a623cbe00 (patch)
tree6b030d899ad71234a72153b3fd8bcb3774137459
parenta668ed6134b275a0ca65483975293643ebdb956d (diff)
[Unicast] Won't show "active" when changing active from HS to LEHS
if the 'active device' is in the member device list, then the main device is active and then updating the main device's state. Bug: 259892289 Test: build pass. make RunSettingsLibRoboTests -j40 ROBOTEST_FILTER=BluetoothEventManagerTest Change-Id: I60d7cb40cc29ea12e5d4f12c10d44eda3e2cf4fe
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java15
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothEventManagerTest.java45
2 files changed, 59 insertions, 1 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java
index a9f4e9c74103..4d6dd4b538cc 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java
@@ -233,7 +233,22 @@ public class BluetoothEventManager {
@Nullable CachedBluetoothDevice activeDevice,
int bluetoothProfile) {
for (CachedBluetoothDevice cachedDevice : mDeviceManager.getCachedDevicesCopy()) {
+ Set<CachedBluetoothDevice> memberSet = cachedDevice.getMemberDevice();
boolean isActive = Objects.equals(cachedDevice, activeDevice);
+ if (!isActive && !memberSet.isEmpty()) {
+ for (CachedBluetoothDevice memberCachedDevice : memberSet) {
+ isActive = Objects.equals(memberCachedDevice, activeDevice);
+ if (isActive) {
+ Log.d(TAG,
+ "The active device is the member device "
+ + activeDevice.getDevice().getAnonymizedAddress()
+ + ". change activeDevice as main device "
+ + cachedDevice.getDevice().getAnonymizedAddress());
+ activeDevice = cachedDevice;
+ break;
+ }
+ }
+ }
cachedDevice.onActiveDeviceChanged(isActive, bluetoothProfile);
}
for (BluetoothCallback callback : mCallbacks) {
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothEventManagerTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothEventManagerTest.java
index 7b94492cef4f..3361a66e958d 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothEventManagerTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothEventManagerTest.java
@@ -70,10 +70,14 @@ public class BluetoothEventManagerTest {
@Mock
private HearingAidProfile mHearingAidProfile;
@Mock
+ private LeAudioProfile mLeAudioProfile;
+ @Mock
private BluetoothDevice mDevice1;
@Mock
private BluetoothDevice mDevice2;
@Mock
+ private BluetoothDevice mDevice3;
+ @Mock
private LocalBluetoothProfileManager mLocalProfileManager;
@Mock
private BluetoothUtils.ErrorListener mErrorListener;
@@ -83,6 +87,7 @@ public class BluetoothEventManagerTest {
private BluetoothEventManager mBluetoothEventManager;
private CachedBluetoothDevice mCachedDevice1;
private CachedBluetoothDevice mCachedDevice2;
+ private CachedBluetoothDevice mCachedDevice3;
@Before
public void setUp() {
@@ -95,9 +100,10 @@ public class BluetoothEventManagerTest {
when(mHfpProfile.isProfileReady()).thenReturn(true);
when(mA2dpProfile.isProfileReady()).thenReturn(true);
when(mHearingAidProfile.isProfileReady()).thenReturn(true);
-
+ when(mLeAudioProfile.isProfileReady()).thenReturn(true);
mCachedDevice1 = new CachedBluetoothDevice(mContext, mLocalProfileManager, mDevice1);
mCachedDevice2 = new CachedBluetoothDevice(mContext, mLocalProfileManager, mDevice2);
+ mCachedDevice3 = new CachedBluetoothDevice(mContext, mLocalProfileManager, mDevice3);
BluetoothUtils.setErrorListener(mErrorListener);
}
@@ -293,6 +299,43 @@ public class BluetoothEventManagerTest {
assertThat(mCachedDevice2.isActiveDevice(BluetoothProfile.HEADSET)).isFalse();
}
+ @Test
+ public void dispatchActiveDeviceChanged_connectedMemberDevices_activeDeviceChanged() {
+ final List<CachedBluetoothDevice> cachedDevices = new ArrayList<>();
+ cachedDevices.add(mCachedDevice1);
+ cachedDevices.add(mCachedDevice2);
+
+ int group1 = 1;
+ when(mDevice3.getAddress()).thenReturn("testAddress3");
+ mCachedDevice1.setGroupId(group1);
+ mCachedDevice3.setGroupId(group1);
+ mCachedDevice1.addMemberDevice(mCachedDevice3);
+
+ when(mDevice1.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
+ when(mDevice2.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
+ when(mDevice3.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
+ when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(cachedDevices);
+
+ // Connect device1 and device3 for LE and device2 for A2DP and HFP
+ mCachedDevice1.onProfileStateChanged(mLeAudioProfile, BluetoothProfile.STATE_CONNECTED);
+ mCachedDevice3.onProfileStateChanged(mLeAudioProfile, BluetoothProfile.STATE_CONNECTED);
+ mCachedDevice2.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_CONNECTED);
+ mCachedDevice2.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_CONNECTED);
+
+ // Verify that both devices are connected and none is Active
+ assertThat(mCachedDevice1.isActiveDevice(BluetoothProfile.LE_AUDIO)).isFalse();
+ assertThat(mCachedDevice2.isActiveDevice(BluetoothProfile.A2DP)).isFalse();
+ assertThat(mCachedDevice2.isActiveDevice(BluetoothProfile.HEADSET)).isFalse();
+ assertThat(mCachedDevice3.isActiveDevice(BluetoothProfile.LE_AUDIO)).isFalse();
+
+ // The member device is active.
+ mBluetoothEventManager.dispatchActiveDeviceChanged(mCachedDevice3,
+ BluetoothProfile.LE_AUDIO);
+
+ // The main device is active since the member is active.
+ assertThat(mCachedDevice1.isActiveDevice(BluetoothProfile.LE_AUDIO)).isTrue();
+ }
+
/**
* Test to verify onActiveDeviceChanged() with A2DP and Hearing Aid.
*/