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

Commit 7f9b571d authored by Michael Mikhail's avatar Michael Mikhail
Browse files

[Media TTT] Use a default name if blank string is given

Adds a default device name if the given routeInfo name is blank. Name
routeInfo builder does not accept empty or null string. Checking if the
name is blank should be fair enough in order to provide a reasonable string.

Bug: 261491161
Test: atest MediaTttSenderCoordinatorTest
Change-Id: Ibf38af23990d6ccf8f81eb6bcebc2ef0cf3f5d48
parent c9e3c707
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -2364,6 +2364,8 @@
    <string name="media_transfer_failed">Something went wrong. Try again.</string>
    <!-- Text to indicate that a media transfer is currently in-progress, aka loading. [CHAR LIMIT=NONE] -->
    <string name="media_transfer_loading">Loading</string>
    <!-- Default name of the device. [CHAR LIMIT=30] -->
    <string name="media_ttt_default_device_type">tablet</string>

    <!-- Error message indicating that a control timed out while waiting for an update [CHAR_LIMIT=30] -->
    <string name="controls_error_timeout">Inactive, check app</string>
+6 −1
Original line number Diff line number Diff line
@@ -150,7 +150,12 @@ constructor(
        logger: MediaTttLogger<ChipbarInfo>,
    ): ChipbarInfo {
        val packageName = routeInfo.clientPackageName
        val otherDeviceName = routeInfo.name.toString()
        val otherDeviceName =
            if (routeInfo.name.isBlank()) {
                context.getString(R.string.media_ttt_default_device_type)
            } else {
                routeInfo.name.toString()
            }

        return ChipbarInfo(
            // Display the app's icon as the start icon
+37 −0
Original line number Diff line number Diff line
@@ -205,6 +205,21 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() {
        verify(vibratorHelper).vibrate(any<VibrationEffect>())
    }

    @Test
    fun commandQueueCallback_almostCloseToStartCast_deviceNameBlank_showsDefaultDeviceName() {
        commandQueueCallback.updateMediaTapToTransferSenderDisplay(
            StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_ALMOST_CLOSE_TO_START_CAST,
            routeInfoWithBlankDeviceName,
            null,
        )

        val chipbarView = getChipbarView()
        assertThat(chipbarView.getChipText())
            .contains(context.getString(R.string.media_ttt_default_device_type))
        assertThat(chipbarView.getChipText())
            .isNotEqualTo(ChipStateSender.ALMOST_CLOSE_TO_START_CAST.getExpectedStateText())
    }

    @Test
    fun commandQueueCallback_almostCloseToEndCast_triggersCorrectChip() {
        commandQueueCallback.updateMediaTapToTransferSenderDisplay(
@@ -247,6 +262,21 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() {
        verify(vibratorHelper).vibrate(any<VibrationEffect>())
    }

    @Test
    fun commandQueueCallback_transferToReceiverTriggered_deviceNameBlank_showsDefaultDeviceName() {
        commandQueueCallback.updateMediaTapToTransferSenderDisplay(
            StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_RECEIVER_TRIGGERED,
            routeInfoWithBlankDeviceName,
            null,
        )

        val chipbarView = getChipbarView()
        assertThat(chipbarView.getChipText())
            .contains(context.getString(R.string.media_ttt_default_device_type))
        assertThat(chipbarView.getChipText())
            .isNotEqualTo(ChipStateSender.TRANSFER_TO_RECEIVER_TRIGGERED.getExpectedStateText())
    }

    @Test
    fun commandQueueCallback_transferToThisDeviceTriggered_triggersCorrectChip() {
        commandQueueCallback.updateMediaTapToTransferSenderDisplay(
@@ -934,6 +964,7 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() {

private const val APP_NAME = "Fake app name"
private const val OTHER_DEVICE_NAME = "My Tablet"
private const val BLANK_DEVICE_NAME = " "
private const val PACKAGE_NAME = "com.android.systemui"
private const val TIMEOUT = 10000

@@ -942,3 +973,9 @@ private val routeInfo =
        .addFeature("feature")
        .setClientPackageName(PACKAGE_NAME)
        .build()

private val routeInfoWithBlankDeviceName =
    MediaRoute2Info.Builder("id", BLANK_DEVICE_NAME)
        .addFeature("feature")
        .setClientPackageName(PACKAGE_NAME)
        .build()