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

Commit a76d8cca authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB][RON] Add custom text to RON demo command.

Bug: 361346412
Flag: com.android.systemui.status_bar_ron_chips
Test: `adb shell cmd statusbar demo-ron -p com.android.systemui -t 10min` ->
verify status bar chip shows with provided text
Test: verify call chips and screen share chips still work as expected
Test: atest DemoRonChipViewModelTest

Change-Id: I34a39c73f78bfe852df8b440bedd223d87e02f75
parent 60cf8199
Loading
Loading
Loading
Loading
+51 −18
Original line number Original line Diff line number Diff line
@@ -41,8 +41,16 @@ import kotlinx.coroutines.flow.asStateFlow
 * adb commands sent by the user.
 * adb commands sent by the user.
 *
 *
 * Example adb commands:
 * Example adb commands:
 * - To show a chip with the SysUI icon: adb shell cmd statusbar demo-ron -p com.android.systemui
 *
 * - To hide the chip: adb shell cmd statusbar demo-ron --hide
 * To show a chip with the SysUI icon and custom text:
 * ```
 * adb shell cmd statusbar demo-ron -p com.android.systemui -t 10min
 * ```
 *
 * To hide the chip:
 * ```
 * adb shell cmd statusbar demo-ron --hide
 * ```
 *
 *
 * See [DemoRonCommand] for more information on the adb command spec.
 * See [DemoRonCommand] for more information on the adb command spec.
 */
 */
@@ -71,6 +79,14 @@ constructor(
                valueParser = Type.String,
                valueParser = Type.String,
            )
            )


        private val text: String? by
            param(
                longName = "text",
                shortName = "t",
                description = "Text to display in the chip",
                valueParser = Type.String,
            )

        private val hide by
        private val hide by
            flag(
            flag(
                longName = "hide",
                longName = "hide",
@@ -97,24 +113,25 @@ constructor(
                return
                return
            }
            }


            lateinit var iconDrawable: Drawable
            val appIcon = getAppIcon(currentPackageName)
            try {
            if (appIcon == null) {
                // Note: For the real implementation, we should check if applicationInfo exists
                // before fetching the icon, so that we either don't show the chip or show a good
                // backup icon in case the app info can't be found for some reason.
                iconDrawable = packageManager.getApplicationIcon(currentPackageName)
            } catch (e: NameNotFoundException) {
                pw.println("Package $currentPackageName could not be found")
                pw.println("Package $currentPackageName could not be found")
                return
                return
            }
            }


            val currentText = text
            if (currentText != null) {
                _chip.value =
                    OngoingActivityChipModel.Shown.Text(
                        icon = appIcon,
                        // TODO(b/361346412): Include a demo with a custom color theme.
                        colors = ColorsModel.Themed,
                        text = currentText,
                    )
            } else {
                _chip.value =
                _chip.value =
                // TODO(b/361346412): Include a demo for text like "10min".
                    OngoingActivityChipModel.Shown.Timer(
                    OngoingActivityChipModel.Shown.Timer(
                    icon =
                        icon = appIcon,
                        OngoingActivityChipModel.ChipIcon.FullColorAppIcon(
                            Icon.Loaded(drawable = iconDrawable, contentDescription = null),
                        ),
                        // TODO(b/361346412): Include a demo with a custom color theme.
                        // TODO(b/361346412): Include a demo with a custom color theme.
                        colors = ColorsModel.Themed,
                        colors = ColorsModel.Themed,
                        startTimeMs = systemClock.elapsedRealtime(),
                        startTimeMs = systemClock.elapsedRealtime(),
@@ -122,4 +139,20 @@ constructor(
                    )
                    )
            }
            }
        }
        }

        private fun getAppIcon(packageName: String): OngoingActivityChipModel.ChipIcon? {
            lateinit var iconDrawable: Drawable
            try {
                // Note: For the real implementation, we should check if applicationInfo exists
                // before fetching the icon, so that we either don't show the chip or show a good
                // backup icon in case the app info can't be found for some reason.
                iconDrawable = packageManager.getApplicationIcon(packageName)
            } catch (e: NameNotFoundException) {
                return null
            }
            return OngoingActivityChipModel.ChipIcon.FullColorAppIcon(
                Icon.Loaded(drawable = iconDrawable, contentDescription = null),
            )
        }
    }
}
}
+10 −0
Original line number Original line Diff line number Diff line
@@ -89,6 +89,16 @@ sealed class OngoingActivityChipModel {
        ) : Shown(icon = null, colors, onClickListener = null) {
        ) : Shown(icon = null, colors, onClickListener = null) {
            override val logName = "Shown.Countdown"
            override val logName = "Shown.Countdown"
        }
        }

        /** This chip shows the specified [text] in the chip. */
        data class Text(
            override val icon: ChipIcon,
            override val colors: ColorsModel,
            // TODO(b/361346412): Enforce a max length requirement?
            val text: String,
        ) : Shown(icon, colors, onClickListener = null) {
            override val logName = "Shown.Text"
        }
    }
    }


    /** Represents an icon to show on the chip. */
    /** Represents an icon to show on the chip. */
+16 −8
Original line number Original line Diff line number Diff line
@@ -252,10 +252,13 @@ class CollapsedStatusBarViewBinderImpl @Inject constructor() : CollapsedStatusBa
                chipTextView.text = chipModel.secondsUntilStarted.toString()
                chipTextView.text = chipModel.secondsUntilStarted.toString()
                chipTextView.visibility = View.VISIBLE
                chipTextView.visibility = View.VISIBLE


                // The Chronometer should be stopped to prevent leaks -- see b/192243808 and
                chipTimeView.hide()
                // [Chronometer.start].
            }
                chipTimeView.stop()
            is OngoingActivityChipModel.Shown.Text -> {
                chipTimeView.visibility = View.GONE
                chipTextView.text = chipModel.text
                chipTextView.visibility = View.VISIBLE

                chipTimeView.hide()
            }
            }
            is OngoingActivityChipModel.Shown.Timer -> {
            is OngoingActivityChipModel.Shown.Timer -> {
                ChipChronometerBinder.bind(chipModel.startTimeMs, chipTimeView)
                ChipChronometerBinder.bind(chipModel.startTimeMs, chipTimeView)
@@ -265,12 +268,16 @@ class CollapsedStatusBarViewBinderImpl @Inject constructor() : CollapsedStatusBa
            }
            }
            is OngoingActivityChipModel.Shown.IconOnly -> {
            is OngoingActivityChipModel.Shown.IconOnly -> {
                chipTextView.visibility = View.GONE
                chipTextView.visibility = View.GONE
                // The Chronometer should be stopped to prevent leaks -- see b/192243808 and
                chipTimeView.hide()
                // [Chronometer.start].
            }
                chipTimeView.stop()
                chipTimeView.visibility = View.GONE
        }
        }
    }
    }

    private fun ChipChronometer.hide() {
        // The Chronometer should be stopped to prevent leaks -- see b/192243808 and
        // [Chronometer.start].
        this.stop()
        this.visibility = View.GONE
    }
    }


    private fun updateChipPadding(
    private fun updateChipPadding(
@@ -371,6 +378,7 @@ class CollapsedStatusBarViewBinderImpl @Inject constructor() : CollapsedStatusBa
                chipView.accessibilityLiveRegion = View.ACCESSIBILITY_LIVE_REGION_ASSERTIVE
                chipView.accessibilityLiveRegion = View.ACCESSIBILITY_LIVE_REGION_ASSERTIVE
            }
            }
            is OngoingActivityChipModel.Shown.Timer,
            is OngoingActivityChipModel.Shown.Timer,
            is OngoingActivityChipModel.Shown.Text,
            is OngoingActivityChipModel.Shown.IconOnly -> {
            is OngoingActivityChipModel.Shown.IconOnly -> {
                chipView.accessibilityLiveRegion = View.ACCESSIBILITY_LIVE_REGION_NONE
                chipView.accessibilityLiveRegion = View.ACCESSIBILITY_LIVE_REGION_NONE
            }
            }
+14 −0
Original line number Original line Diff line number Diff line
@@ -87,6 +87,20 @@ class DemoRonChipViewModelTest : SysuiTestCase() {
            assertThat(latest).isInstanceOf(OngoingActivityChipModel.Shown::class.java)
            assertThat(latest).isInstanceOf(OngoingActivityChipModel.Shown::class.java)
        }
        }


    @Test
    @EnableFlags(FLAG_STATUS_BAR_RON_CHIPS)
    fun chip_hasText_shownWithText() =
        testScope.runTest {
            val latest by collectLastValue(underTest.chip)

            commandRegistry.onShellCommand(
                pw,
                arrayOf("demo-ron", "-p", "com.android.systemui", "-t", "test")
            )

            assertThat(latest).isInstanceOf(OngoingActivityChipModel.Shown.Text::class.java)
        }

    @Test
    @Test
    @EnableFlags(FLAG_STATUS_BAR_RON_CHIPS)
    @EnableFlags(FLAG_STATUS_BAR_RON_CHIPS)
    fun chip_hasHideArg_hidden() =
    fun chip_hasHideArg_hidden() =