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

Commit 92fb2199 authored by Tim Peng's avatar Tim Peng Committed by tim peng
Browse files

No feedback when attempting to transfer to an unpowered BT device

-Set transfering state when trying to connect
-Reset to onTransferBluetoothDevice when failing connecting
-Add test cases

Bug: 152606143
Test: make -j50 RunSettingsLibRoboTests
Change-Id: Ifc4cb16a5d7d2b2c85b1171aa070651a5feaa4e2
parent bb5e6b49
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -146,6 +146,7 @@ public class LocalMediaManager implements BluetoothCallback {
                    ((BluetoothMediaDevice) device).getCachedDevice();
            if (!cachedDevice.isConnected() && !cachedDevice.isBusy()) {
                mOnTransferBluetoothDevice = connectDevice;
                device.setState(MediaDeviceState.STATE_CONNECTING);
                cachedDevice.connect();
                return;
            }
@@ -394,6 +395,7 @@ public class LocalMediaManager implements BluetoothCallback {
            dispatchDeviceListUpdate();
            if (mOnTransferBluetoothDevice != null && mOnTransferBluetoothDevice.isConnected()) {
                connectDevice(mOnTransferBluetoothDevice);
                mOnTransferBluetoothDevice.setState(MediaDeviceState.STATE_CONNECTED);
                mOnTransferBluetoothDevice = null;
            }
        }
@@ -539,6 +541,14 @@ public class LocalMediaManager implements BluetoothCallback {

        @Override
        public void onDeviceAttributesChanged() {
            if (mOnTransferBluetoothDevice != null
                    && !((BluetoothMediaDevice) mOnTransferBluetoothDevice).getCachedDevice()
                    .isBusy()
                    && !mOnTransferBluetoothDevice.isConnected()) {
                // Failed to connect
                mOnTransferBluetoothDevice.setState(MediaDeviceState.STATE_DISCONNECTED);
                mOnTransferBluetoothDevice = null;
            }
            dispatchDeviceAttributesChanged();
        }
    }
+20 −0
Original line number Diff line number Diff line
@@ -463,6 +463,26 @@ public class LocalMediaManagerTest {
        verify(mCallback).onDeviceAttributesChanged();
    }

    @Test
    public void onDeviceAttributesChanged_failingTransferring_shouldResetState() {
        final MediaDevice currentDevice = mock(MediaDevice.class);
        final MediaDevice device = mock(BluetoothMediaDevice.class);
        final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
        mLocalMediaManager.mMediaDevices.add(device);
        mLocalMediaManager.mMediaDevices.add(currentDevice);
        when(device.getId()).thenReturn(TEST_DEVICE_ID_1);
        when(currentDevice.getId()).thenReturn(TEST_CURRENT_DEVICE_ID);
        when(((BluetoothMediaDevice) device).getCachedDevice()).thenReturn(cachedDevice);
        when(cachedDevice.isConnected()).thenReturn(false);
        when(cachedDevice.isBusy()).thenReturn(false);

        mLocalMediaManager.registerCallback(mCallback);
        mLocalMediaManager.connectDevice(device);

        mLocalMediaManager.mDeviceAttributeChangeCallback.onDeviceAttributesChanged();
        verify(device).setState(LocalMediaManager.MediaDeviceState.STATE_DISCONNECTED);
    }

    @Test
    public void onRequestFailed_checkDevicesState() {
        mLocalMediaManager.mMediaDevices.add(mInfoMediaDevice1);