From a0dc7e0d5b83a54653971d2d8f0b0e7ddbb1f9a2 Mon Sep 17 00:00:00 2001 From: SongFerng Wang Date: Tue, 25 Oct 2022 10:12:46 +0000 Subject: [PATCH] Revert "[LE unicast] The isBusy state should involve the state of sub device" This reverts commit 4b2b34eef35a207906be2628bd57f03dfa310687. Reason for revert: According to b/253592180#comment6, we should hide the concept of member sets of a CSIP pairing or joining a group. The UI did not gray out device preference when the member is busy. Change-Id: Iae13955f34222854f7b1f6b767e9aed09cb3ba32 --- .../bluetooth/CachedBluetoothDevice.java | 23 ++---- .../bluetooth/CachedBluetoothDeviceTest.java | 76 ------------------- 2 files changed, 8 insertions(+), 91 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java index d899d8ba15af6..a5f3df9f628d3 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java @@ -756,23 +756,16 @@ public class CachedBluetoothDevice implements Comparable } public boolean isBusy() { - for (CachedBluetoothDevice memberDevice : getMemberDevice()) { - if (isBusyState(memberDevice)) { - return true; + synchronized (mProfileLock) { + for (LocalBluetoothProfile profile : mProfiles) { + int status = getProfileConnectionState(profile); + if (status == BluetoothProfile.STATE_CONNECTING + || status == BluetoothProfile.STATE_DISCONNECTING) { + return true; + } } + return getBondState() == BluetoothDevice.BOND_BONDING; } - return isBusyState(this); - } - - private boolean isBusyState(CachedBluetoothDevice device){ - for (LocalBluetoothProfile profile : device.getProfiles()) { - int status = device.getProfileConnectionState(profile); - if (status == BluetoothProfile.STATE_CONNECTING - || status == BluetoothProfile.STATE_DISCONNECTING) { - return true; - } - } - return device.getBondState() == BluetoothDevice.BOND_BONDING; } private boolean updateProfiles() { diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java index 315ab0aac878d..79e99387b2fa0 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java @@ -1069,80 +1069,4 @@ public class CachedBluetoothDeviceTest { assertThat(mSubCachedDevice.mDevice).isEqualTo(mDevice); assertThat(mCachedDevice.getMemberDevice().contains(mSubCachedDevice)).isTrue(); } - - @Test - public void isBusy_mainDeviceIsConnecting_returnsBusy() { - mCachedDevice.addMemberDevice(mSubCachedDevice); - updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); - updateSubDeviceProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); - when(mDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); - when(mSubDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); - - updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTING); - - assertThat(mCachedDevice.getMemberDevice().contains(mSubCachedDevice)).isTrue(); - assertThat(mCachedDevice.getProfiles().contains(mA2dpProfile)).isTrue(); - assertThat(mSubCachedDevice.getProfiles().contains(mA2dpProfile)).isTrue(); - assertThat(mCachedDevice.isBusy()).isTrue(); - } - - @Test - public void isBusy_mainDeviceIsBonding_returnsBusy() { - mCachedDevice.addMemberDevice(mSubCachedDevice); - updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); - updateSubDeviceProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); - when(mSubDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); - - when(mDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDING); - - assertThat(mCachedDevice.getMemberDevice().contains(mSubCachedDevice)).isTrue(); - assertThat(mCachedDevice.getProfiles().contains(mA2dpProfile)).isTrue(); - assertThat(mSubCachedDevice.getProfiles().contains(mA2dpProfile)).isTrue(); - assertThat(mCachedDevice.isBusy()).isTrue(); - } - - @Test - public void isBusy_memberDeviceIsConnecting_returnsBusy() { - mCachedDevice.addMemberDevice(mSubCachedDevice); - updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); - updateSubDeviceProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); - when(mDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); - when(mSubDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); - - updateSubDeviceProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTING); - - assertThat(mCachedDevice.getMemberDevice().contains(mSubCachedDevice)).isTrue(); - assertThat(mCachedDevice.getProfiles().contains(mA2dpProfile)).isTrue(); - assertThat(mSubCachedDevice.getProfiles().contains(mA2dpProfile)).isTrue(); - assertThat(mCachedDevice.isBusy()).isTrue(); - } - - @Test - public void isBusy_memberDeviceIsBonding_returnsBusy() { - mCachedDevice.addMemberDevice(mSubCachedDevice); - updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); - updateSubDeviceProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); - when(mDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); - - when(mSubDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDING); - - assertThat(mCachedDevice.getMemberDevice().contains(mSubCachedDevice)).isTrue(); - assertThat(mCachedDevice.getProfiles().contains(mA2dpProfile)).isTrue(); - assertThat(mSubCachedDevice.getProfiles().contains(mA2dpProfile)).isTrue(); - assertThat(mCachedDevice.isBusy()).isTrue(); - } - - @Test - public void isBusy_allDevicesAreNotBusy_returnsNotBusy() { - mCachedDevice.addMemberDevice(mSubCachedDevice); - updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); - updateSubDeviceProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); - when(mDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); - when(mSubDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); - - assertThat(mCachedDevice.getMemberDevice().contains(mSubCachedDevice)).isTrue(); - assertThat(mCachedDevice.getProfiles().contains(mA2dpProfile)).isTrue(); - assertThat(mSubCachedDevice.getProfiles().contains(mA2dpProfile)).isTrue(); - assertThat(mCachedDevice.isBusy()).isFalse(); - } }