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

Commit 064a8277 authored by tim peng's avatar tim peng Committed by Android (Google) Code Review
Browse files

Merge "No feedback when attempting to transfer to an unpowered BT device" into rvc-dev

parents 001fddc0 92fb2199
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
@@ -483,6 +483,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);