Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit faeee1ba authored by SongFerng Wang's avatar SongFerng Wang Committed by Automerger Merge Worker
Browse files

Merge "Revert "[LE unicast] The isBusy state should involve the state of sub...

Merge "Revert "[LE unicast] The isBusy state should involve the state of sub device"" into tm-qpr-dev am: 8a283d04 am: 3e78c2ab

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20269876



Change-Id: I0c0b678e8c2dbe66509c820d319968d47afcd7bd
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 9261bd11 3e78c2ab
Loading
Loading
Loading
Loading
+8 −15
Original line number Diff line number Diff line
@@ -758,23 +758,16 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
    }

    public boolean isBusy() {
        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);
        synchronized (mProfileLock) {
            for (LocalBluetoothProfile profile : mProfiles) {
                int status = getProfileConnectionState(profile);
                if (status == BluetoothProfile.STATE_CONNECTING
                        || status == BluetoothProfile.STATE_DISCONNECTING) {
                    return true;
                }
            }
        return device.getBondState() == BluetoothDevice.BOND_BONDING;
            return getBondState() == BluetoothDevice.BOND_BONDING;
        }
    }

    private boolean updateProfiles() {
+0 −76
Original line number Diff line number Diff line
@@ -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();
    }
}