diff options
author | 2022-09-28 20:18:23 +0000 | |
---|---|---|
committer | 2022-09-28 20:18:23 +0000 | |
commit | 0dda857931b07ff871b8a045499f2920cb7da0e3 (patch) | |
tree | 1e289cdf5f95f39205090858d94406b7399b9ed4 | |
parent | 004ba6f57d74759c56814e545b6efeea20dfd491 (diff) | |
parent | c6cc319d411b07a08211de284597387d0832228b (diff) |
Merge "[LE unicast] The isBusy state should involve the state of sub device" into tm-qpr-dev am: 6e4c896775 am: c6cc319d41
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20059745
Change-Id: Ia1de4d623521c4cded71c2cc38c148a962af3a18
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2 files changed, 91 insertions, 8 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java index 7927c5d460a4..eb53ea1d44f7 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java @@ -758,16 +758,23 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> } public boolean isBusy() { - synchronized (mProfileLock) { - for (LocalBluetoothProfile profile : mProfiles) { - int status = getProfileConnectionState(profile); - if (status == BluetoothProfile.STATE_CONNECTING - || status == BluetoothProfile.STATE_DISCONNECTING) { - return true; - } + for (CachedBluetoothDevice memberDevice : getMemberDevice()) { + if (isBusyState(memberDevice)) { + return true; + } + } + 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 getBondState() == BluetoothDevice.BOND_BONDING; } + 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 79e99387b2fa..315ab0aac878 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,4 +1069,80 @@ 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(); + } } |