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

Commit 39f039cc authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Misc] Convert CastDevice to a Kotlin data class." into main

parents dfb1523f e093a979
Loading
Loading
Loading
Loading
+31 −11
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.systemui.qs.pipeline.domain.model.AutoAddSignal
import com.android.systemui.qs.pipeline.shared.TileSpec
import com.android.systemui.qs.tiles.CastTile
import com.android.systemui.statusbar.policy.CastController
import com.android.systemui.statusbar.policy.CastDevice
import com.android.systemui.util.mockito.capture
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
@@ -73,9 +74,12 @@ class CastAutoAddableTest : SysuiTestCase() {
    @Test
    fun onCastDevicesChanged_deviceNotConnectedOrConnecting_noSignal() = runTest {
        val device =
            CastController.CastDevice().apply {
                state = CastController.CastDevice.STATE_DISCONNECTED
            }
            CastDevice(
                id = "id",
                name = null,
                state = CastDevice.CastState.Disconnected,
                origin = CastDevice.CastOrigin.MediaProjection,
            )
        whenever(castController.castDevices).thenReturn(listOf(device))

        val signal by collectLastValue(underTest.autoAddSignal(0))
@@ -91,11 +95,19 @@ class CastAutoAddableTest : SysuiTestCase() {
    @Test
    fun onCastDevicesChanged_someDeviceConnecting_addSignal() = runTest {
        val disconnectedDevice =
            CastController.CastDevice().apply {
                state = CastController.CastDevice.STATE_DISCONNECTED
            }
            CastDevice(
                id = "id",
                name = null,
                state = CastDevice.CastState.Disconnected,
                origin = CastDevice.CastOrigin.MediaProjection,
            )
        val connectingDevice =
            CastController.CastDevice().apply { state = CastController.CastDevice.STATE_CONNECTING }
            CastDevice(
                id = "id",
                name = null,
                state = CastDevice.CastState.Connecting,
                origin = CastDevice.CastOrigin.MediaProjection,
            )
        whenever(castController.castDevices)
            .thenReturn(listOf(disconnectedDevice, connectingDevice))

@@ -112,11 +124,19 @@ class CastAutoAddableTest : SysuiTestCase() {
    @Test
    fun onCastDevicesChanged_someDeviceConnected_addSignal() = runTest {
        val disconnectedDevice =
            CastController.CastDevice().apply {
                state = CastController.CastDevice.STATE_DISCONNECTED
            }
            CastDevice(
                id = "id",
                name = null,
                state = CastDevice.CastState.Disconnected,
                origin = CastDevice.CastOrigin.MediaProjection,
            )
        val connectedDevice =
            CastController.CastDevice().apply { state = CastController.CastDevice.STATE_CONNECTED }
            CastDevice(
                id = "id",
                name = null,
                state = CastDevice.CastState.Connected,
                origin = CastDevice.CastOrigin.MediaProjection,
            )
        whenever(castController.castDevices).thenReturn(listOf(disconnectedDevice, connectedDevice))

        val signal by collectLastValue(underTest.autoAddSignal(0))
+1 −6
Original line number Diff line number Diff line
@@ -41,12 +41,7 @@ constructor(

    override fun ProducerScope<AutoAddSignal>.getCallback(): CastController.Callback {
        return CastController.Callback {
            val isCasting =
                controller.castDevices.any {
                    it.state == CastController.CastDevice.STATE_CONNECTED ||
                        it.state == CastController.CastDevice.STATE_CONNECTING
                }
            if (isCasting) {
            if (controller.castDevices.any { it.isCasting }) {
                sendAdd()
            }
        }
+6 −7
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ import com.android.systemui.statusbar.phone.SystemUIDialog;
import com.android.systemui.statusbar.pipeline.shared.data.model.DefaultConnectionModel;
import com.android.systemui.statusbar.pipeline.shared.data.repository.ConnectivityRepository;
import com.android.systemui.statusbar.policy.CastController;
import com.android.systemui.statusbar.policy.CastController.CastDevice;
import com.android.systemui.statusbar.policy.CastDevice;
import com.android.systemui.statusbar.policy.HotspotController;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.util.DialogKt;
@@ -193,14 +193,13 @@ public class CastTile extends QSTileImpl<BooleanState> {
    // case where multiple devices were active :-/.
    private boolean willPopDialog() {
        List<CastDevice> activeDevices = getActiveDevices();
        return activeDevices.isEmpty() || (activeDevices.get(0).tag instanceof RouteInfo);
        return activeDevices.isEmpty() || (activeDevices.get(0).getTag() instanceof RouteInfo);
    }

    private List<CastDevice> getActiveDevices() {
        ArrayList<CastDevice> activeDevices = new ArrayList<>();
        for (CastDevice device : mController.getCastDevices()) {
            if (device.state == CastDevice.STATE_CONNECTED
                    || device.state == CastDevice.STATE_CONNECTING) {
            if (device.isCasting()) {
                activeDevices.add(device);
            }
        }
@@ -276,7 +275,7 @@ public class CastTile extends QSTileImpl<BooleanState> {
        // We always choose the first device that's in the CONNECTED state in the case where
        // multiple devices are CONNECTED at the same time.
        for (CastDevice device : devices) {
            if (device.state == CastDevice.STATE_CONNECTED) {
            if (device.getState() == CastDevice.CastState.Connected) {
                state.value = true;
                state.secondaryLabel = getDeviceName(device);
                state.stateDescription = state.stateDescription + ","
@@ -284,7 +283,7 @@ public class CastTile extends QSTileImpl<BooleanState> {
                        R.string.accessibility_cast_name, state.label);
                connecting = false;
                break;
            } else if (device.state == CastDevice.STATE_CONNECTING) {
            } else if (device.getState() == CastDevice.CastState.Connecting) {
                connecting = true;
            }
        }
@@ -315,7 +314,7 @@ public class CastTile extends QSTileImpl<BooleanState> {
    }

    private String getDeviceName(CastDevice device) {
        return device.name != null ? device.name
        return device.getName() != null ? device.getName()
                : mContext.getString(R.string.quick_settings_cast_device_default_name);
    }

+2 −3
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ import com.android.systemui.qs.external.CustomTile;
import com.android.systemui.qs.pipeline.shared.QSPipelineFlagsRepository;
import com.android.systemui.res.R;
import com.android.systemui.statusbar.policy.CastController;
import com.android.systemui.statusbar.policy.CastController.CastDevice;
import com.android.systemui.statusbar.policy.CastDevice;
import com.android.systemui.statusbar.policy.DataSaverController;
import com.android.systemui.statusbar.policy.DataSaverController.Listener;
import com.android.systemui.statusbar.policy.DeviceControlsController;
@@ -430,8 +430,7 @@ public class AutoTileManager implements UserAwareController {

            boolean isCasting = false;
            for (CastDevice device : mCastController.getCastDevices()) {
                if (device.state == CastDevice.STATE_CONNECTED
                        || device.state == CastDevice.STATE_CONNECTING) {
                if (device.isCasting()) {
                    isCasting = true;
                    break;
                }
+2 −3
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.phone.ui.StatusBarIconController;
import com.android.systemui.statusbar.policy.BluetoothController;
import com.android.systemui.statusbar.policy.CastController;
import com.android.systemui.statusbar.policy.CastController.CastDevice;
import com.android.systemui.statusbar.policy.CastDevice;
import com.android.systemui.statusbar.policy.DataSaverController;
import com.android.systemui.statusbar.policy.DataSaverController.Listener;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
@@ -521,8 +521,7 @@ public class PhoneStatusBarPolicy
    private void updateCast() {
        boolean isCasting = false;
        for (CastDevice device : mCast.getCastDevices()) {
            if (device.state == CastDevice.STATE_CONNECTING
                    || device.state == CastDevice.STATE_CONNECTED) {
            if (device.isCasting()) {
                isCasting = true;
                break;
            }
Loading