Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +15 −8 Original line number Diff line number Diff line Loading @@ -758,16 +758,23 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> } public boolean isBusy() { synchronized (mProfileLock) { for (LocalBluetoothProfile profile : mProfiles) { int status = getProfileConnectionState(profile); 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() { Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +76 −0 Original line number Diff line number Diff line Loading @@ -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(); } } Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +15 −8 Original line number Diff line number Diff line Loading @@ -758,16 +758,23 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> } public boolean isBusy() { synchronized (mProfileLock) { for (LocalBluetoothProfile profile : mProfiles) { int status = getProfileConnectionState(profile); 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() { Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +76 −0 Original line number Diff line number Diff line Loading @@ -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(); } }