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

Commit cd529893 authored by Yanting Yang's avatar Yanting Yang Committed by Android (Google) Code Review
Browse files

Merge "Fix BluetoothDevicesSlice doesn't appear issue."

parents 9b628203 cbbc008a
Loading
Loading
Loading
Loading
+21 −14
Original line number Diff line number Diff line
@@ -179,14 +179,9 @@ public class BluetoothDevicesSlice implements CustomSliceable {
        final Collection<CachedBluetoothDevice> cachedDevices =
                bluetoothManager.getCachedDeviceManager().getCachedDevicesCopy();

        /**
         * TODO(b/114807655): Contextual Home Page - Connected Device
         * It's under discussion for including available media devices and currently connected
         * devices from Bluetooth. Will update the devices list or remove TODO later.
         */
        // Get available media device list and sort them.
        // Get all connected devices and sort them.
        return cachedDevices.stream()
                .filter(device -> device.isConnected() && device.isConnectedA2dpDevice())
                .filter(device -> device.getDevice().isConnected())
                .sorted(COMPARATOR).collect(Collectors.toList());
    }

@@ -226,18 +221,29 @@ public class BluetoothDevicesSlice implements CustomSliceable {
        final List<ListBuilder.RowBuilder> bluetoothRows = new ArrayList<>();
        final List<CachedBluetoothDevice> bluetoothDevices = getConnectedBluetoothDevices();
        for (CachedBluetoothDevice bluetoothDevice : bluetoothDevices) {
            bluetoothRows.add(new ListBuilder.RowBuilder()
            final ListBuilder.RowBuilder rowBuilder = new ListBuilder.RowBuilder()
                    .setTitleItem(getBluetoothDeviceIcon(bluetoothDevice), ListBuilder.ICON_IMAGE)
                    .setTitle(bluetoothDevice.getName())
                    .setSubtitle(bluetoothDevice.getConnectionSummary())
                    .setPrimaryAction(buildBluetoothDeviceAction(bluetoothDevice))
                    .addEndItem(buildBluetoothDetailDeepLinkAction(bluetoothDevice)));
                    .setSubtitle(bluetoothDevice.getConnectionSummary());

            if (bluetoothDevice.isConnectedA2dpDevice()) {
                // For available media devices, the primary action is to active audio stream and
                // add setting icon to the end to link detail page.
                rowBuilder.setPrimaryAction(buildMediaBluetoothAction(bluetoothDevice));
                rowBuilder.addEndItem(buildBluetoothDetailDeepLinkAction(bluetoothDevice));
            } else {
                // For other devices, the primary action is to link detail page.
                rowBuilder.setPrimaryAction(buildBluetoothDetailDeepLinkAction(bluetoothDevice));
            }

            bluetoothRows.add(rowBuilder);
        }

        return bluetoothRows;
    }

    private SliceAction buildBluetoothDeviceAction(CachedBluetoothDevice bluetoothDevice) {
    @VisibleForTesting
    SliceAction buildMediaBluetoothAction(CachedBluetoothDevice bluetoothDevice) {
        // Send broadcast to activate available media device.
        final Intent intent = new Intent(getUri().toString())
                .setClass(mContext, SliceBroadcastReceiver.class)
@@ -250,7 +256,8 @@ public class BluetoothDevicesSlice implements CustomSliceable {
                bluetoothDevice.getName());
    }

    private SliceAction buildBluetoothDetailDeepLinkAction(CachedBluetoothDevice bluetoothDevice) {
    @VisibleForTesting
    SliceAction buildBluetoothDetailDeepLinkAction(CachedBluetoothDevice bluetoothDevice) {
        return SliceAction.createDeeplink(
                getBluetoothDetailIntent(bluetoothDevice),
                IconCompat.createWithResource(mContext, R.drawable.ic_settings_24dp),
+23 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -121,6 +122,27 @@ public class BluetoothDevicesSliceTest {
        SliceTester.assertAnySliceItemContainsTitle(sliceItems, BLUETOOTH_MOCK_TITLE);
    }

    @Test
    public void getSlice_hasMediaBluetoothDevice_shouldBuildMediaBluetoothAction() {
        mockBluetoothDeviceList(1 /* deviceCount */);
        doReturn(true).when(mBluetoothDeviceList.get(0)).isConnectedA2dpDevice();
        doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices();

        mBluetoothDevicesSlice.getSlice();

        verify(mBluetoothDevicesSlice).buildMediaBluetoothAction(any());
    }

    @Test
    public void getSlice_noMediaBluetoothDevice_shouldNotBuildMediaBluetoothAction() {
        mockBluetoothDeviceList(1 /* deviceCount */);
        doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices();

        mBluetoothDevicesSlice.getSlice();

        verify(mBluetoothDevicesSlice, never()).buildMediaBluetoothAction(any());
    }

    @Test
    public void getSlice_noBluetoothDevices_shouldHaveNoBluetoothDevicesTitle() {
        doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices();
@@ -175,7 +197,6 @@ public class BluetoothDevicesSliceTest {
        doReturn(BLUETOOTH_MOCK_TITLE).when(mCachedBluetoothDevice).getName();
        doReturn(BLUETOOTH_MOCK_SUMMARY).when(mCachedBluetoothDevice).getConnectionSummary();
        doReturn(BLUETOOTH_MOCK_ADDRESS).when(mCachedBluetoothDevice).getAddress();
        doReturn(true).when(mCachedBluetoothDevice).isConnectedA2dpDevice();
        for (int i = 0; i < deviceCount; i++) {
            mBluetoothDeviceList.add(mCachedBluetoothDevice);
        }