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

Commit d7437c58 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "List 5 disconnected bt device" into rvc-dev

parents e0c2025f 11264e21
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
public class LocalMediaManager implements BluetoothCallback {
    private static final Comparator<MediaDevice> COMPARATOR = Comparator.naturalOrder();
    private static final String TAG = "LocalMediaManager";
    private static final int MAX_DISCONNECTED_DEVICE_NUM = 5;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({MediaDeviceState.STATE_CONNECTED,
@@ -404,13 +405,18 @@ public class LocalMediaManager implements BluetoothCallback {
                    mLocalBluetoothManager.getCachedDeviceManager();

            final List<CachedBluetoothDevice> cachedBluetoothDeviceList = new ArrayList<>();
            int deviceCount = 0;
            for (BluetoothDevice device : bluetoothDevices) {
                final CachedBluetoothDevice cachedDevice =
                        cachedDeviceManager.findDevice(device);
                if (cachedDevice != null) {
                    if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED
                            && !cachedDevice.isConnected()) {
                        deviceCount++;
                        cachedBluetoothDeviceList.add(cachedDevice);
                        if (deviceCount >= MAX_DISCONNECTED_DEVICE_NUM) {
                            break;
                        }
                    }
                }
            }
+52 −0
Original line number Diff line number Diff line
@@ -599,4 +599,56 @@ public class LocalMediaManagerTest {

        verify(mCallback).onRequestFailed(1);
    }

    @Test
    public void onDeviceListAdded_haveDisconnectedDevice_list5DisconnectedDevice() {
        final List<MediaDevice> devices = new ArrayList<>();
        final MediaDevice device1 = mock(MediaDevice.class);
        final MediaDevice device2 = mock(MediaDevice.class);
        final MediaDevice device3 = mock(MediaDevice.class);
        mLocalMediaManager.mPhoneDevice = mock(PhoneMediaDevice.class);
        devices.add(device1);
        devices.add(device2);
        mLocalMediaManager.mMediaDevices.add(device3);
        mLocalMediaManager.mMediaDevices.add(mLocalMediaManager.mPhoneDevice);

        final List<BluetoothDevice> bluetoothDevices = new ArrayList<>();
        final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class);
        final BluetoothDevice bluetoothDevice2 = mock(BluetoothDevice.class);
        final BluetoothDevice bluetoothDevice3 = mock(BluetoothDevice.class);
        final BluetoothDevice bluetoothDevice4 = mock(BluetoothDevice.class);
        final BluetoothDevice bluetoothDevice5 = mock(BluetoothDevice.class);
        final BluetoothDevice bluetoothDevice6 = mock(BluetoothDevice.class);
        final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
        final CachedBluetoothDeviceManager cachedManager = mock(CachedBluetoothDeviceManager.class);
        bluetoothDevices.add(bluetoothDevice);
        bluetoothDevices.add(bluetoothDevice2);
        bluetoothDevices.add(bluetoothDevice3);
        bluetoothDevices.add(bluetoothDevice4);
        bluetoothDevices.add(bluetoothDevice5);
        bluetoothDevices.add(bluetoothDevice6);
        mShadowBluetoothAdapter.setMostRecentlyConnectedDevices(bluetoothDevices);

        when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(cachedManager);
        when(cachedManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice);
        when(cachedManager.findDevice(bluetoothDevice2)).thenReturn(cachedDevice);
        when(cachedManager.findDevice(bluetoothDevice3)).thenReturn(cachedDevice);
        when(cachedManager.findDevice(bluetoothDevice4)).thenReturn(cachedDevice);
        when(cachedManager.findDevice(bluetoothDevice5)).thenReturn(cachedDevice);
        when(cachedManager.findDevice(bluetoothDevice6)).thenReturn(cachedDevice);
        when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
        when(cachedDevice.isConnected()).thenReturn(false);

        when(device1.getId()).thenReturn(TEST_DEVICE_ID_1);
        when(device2.getId()).thenReturn(TEST_DEVICE_ID_2);
        when(device3.getId()).thenReturn(TEST_DEVICE_ID_3);
        when(mLocalMediaManager.mPhoneDevice.getId()).thenReturn("test_phone_id");

        assertThat(mLocalMediaManager.mMediaDevices).hasSize(2);
        mLocalMediaManager.registerCallback(mCallback);
        mLocalMediaManager.mMediaDeviceCallback.onDeviceListAdded(devices);

        assertThat(mLocalMediaManager.mMediaDevices).hasSize(7);
        verify(mCallback).onDeviceListUpdate(any());
    }
}