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

Commit 0409fcd7 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB][Notifs] status_bar_ron_chips flag -> status_bar_notification_chips.

Removes "RON" from the flag name and instead makes the flag name more
generic.

Also updates all the "demo RON" code to be "demo notification" instead.

Bug: 364653005
Flag: com.android.systemui.status_bar_notification_chips
Test: all tests under statusbar package
Change-Id: I9174b97369917c33b0dde35a4ff99fb12729df8a
parent 231d7dfd
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -395,9 +395,9 @@ flag {
}

flag {
    name: "status_bar_ron_chips"
    name: "status_bar_notification_chips"
    namespace: "systemui"
    description: "Show rich ongoing notifications as chips in the status bar"
    description: "Show promoted ongoing notifications as chips in the status bar"
    bug: "361346412"
}

+21 −21
Original line number Diff line number Diff line
@@ -14,17 +14,17 @@
 * limitations under the License.
 */

package com.android.systemui.statusbar.chips.ron.demo.ui.viewmodel
package com.android.systemui.statusbar.chips.notification.demo.ui.viewmodel

import android.content.packageManager
import android.graphics.drawable.BitmapDrawable
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import androidx.test.filters.SmallTest
import com.android.systemui.Flags.FLAG_STATUS_BAR_RON_CHIPS
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.statusbar.chips.notification.shared.StatusBarNotifChips
import com.android.systemui.statusbar.chips.ui.model.ColorsModel
import com.android.systemui.statusbar.chips.ui.model.OngoingActivityChipModel
import com.android.systemui.statusbar.commandline.CommandRegistry
@@ -40,13 +40,13 @@ import org.mockito.kotlin.any
import org.mockito.kotlin.whenever

@SmallTest
class DemoRonChipViewModelTest : SysuiTestCase() {
class DemoNotifChipViewModelTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val commandRegistry = kosmos.commandRegistry
    private val pw = PrintWriter(StringWriter())

    private val underTest = kosmos.demoRonChipViewModel
    private val underTest = kosmos.demoNotifChipViewModel

    @Before
    fun setUp() {
@@ -56,61 +56,61 @@ class DemoRonChipViewModelTest : SysuiTestCase() {
    }

    @Test
    @DisableFlags(FLAG_STATUS_BAR_RON_CHIPS)
    @DisableFlags(StatusBarNotifChips.FLAG_NAME)
    fun chip_flagOff_hidden() =
        testScope.runTest {
            val latest by collectLastValue(underTest.chip)

            addDemoRonChip()
            addDemoNotifChip()

            assertThat(latest).isInstanceOf(OngoingActivityChipModel.Hidden::class.java)
        }

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

            commandRegistry.onShellCommand(pw, arrayOf("demo-ron"))
            commandRegistry.onShellCommand(pw, arrayOf("demo-notif"))

            assertThat(latest).isInstanceOf(OngoingActivityChipModel.Hidden::class.java)
        }

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

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

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

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

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

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

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

            commandRegistry.onShellCommand(
                pw,
                arrayOf("demo-ron", "-p", "com.android.systemui", "-c", "#434343")
                arrayOf("demo-notif", "-p", "com.android.systemui", "-c", "#434343"),
            )

            assertThat(latest).isInstanceOf(OngoingActivityChipModel.Shown::class.java)
@@ -119,28 +119,28 @@ class DemoRonChipViewModelTest : SysuiTestCase() {
        }

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

            // First, show a chip
            addDemoRonChip()
            addDemoNotifChip()
            assertThat(latest).isInstanceOf(OngoingActivityChipModel.Shown::class.java)

            // Then, hide the chip
            commandRegistry.onShellCommand(pw, arrayOf("demo-ron", "--hide"))
            commandRegistry.onShellCommand(pw, arrayOf("demo-notif", "--hide"))

            assertThat(latest).isInstanceOf(OngoingActivityChipModel.Hidden::class.java)
        }

    private fun addDemoRonChip() {
        Companion.addDemoRonChip(commandRegistry, pw)
    private fun addDemoNotifChip() {
        addDemoNotifChip(commandRegistry, pw)
    }

    companion object {
        fun addDemoRonChip(commandRegistry: CommandRegistry, pw: PrintWriter) {
            commandRegistry.onShellCommand(pw, arrayOf("demo-ron", "-p", "com.android.systemui"))
        fun addDemoNotifChip(commandRegistry: CommandRegistry, pw: PrintWriter) {
            commandRegistry.onShellCommand(pw, arrayOf("demo-notif", "-p", "com.android.systemui"))
        }
    }
}
+2 −3
Original line number Diff line number Diff line
@@ -19,12 +19,11 @@ package com.android.systemui.statusbar.chips.notification.ui.viewmodel
import android.platform.test.annotations.EnableFlags
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.Flags.FLAG_STATUS_BAR_RON_CHIPS
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.statusbar.StatusBarIconView
import com.android.systemui.statusbar.chips.ron.ui.viewmodel.notifChipsViewModel
import com.android.systemui.statusbar.chips.notification.shared.StatusBarNotifChips
import com.android.systemui.statusbar.chips.ui.model.OngoingActivityChipModel
import com.android.systemui.statusbar.notification.data.model.activeNotificationModel
import com.android.systemui.statusbar.notification.data.repository.ActiveNotificationsStore
@@ -42,7 +41,7 @@ import org.mockito.kotlin.mock
@SmallTest
@RunWith(AndroidJUnit4::class)
@OptIn(ExperimentalCoroutinesApi::class)
@EnableFlags(FLAG_STATUS_BAR_RON_CHIPS)
@EnableFlags(StatusBarNotifChips.FLAG_NAME)
class NotifChipsViewModelTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
+7 −9
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.platform.test.annotations.DisableFlags
import android.view.View
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.Flags.FLAG_STATUS_BAR_RON_CHIPS
import com.android.systemui.SysuiTestCase
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.coroutines.collectLastValue
@@ -40,7 +39,8 @@ import com.android.systemui.screenrecord.data.model.ScreenRecordModel
import com.android.systemui.screenrecord.data.repository.screenRecordRepository
import com.android.systemui.statusbar.chips.mediaprojection.domain.interactor.MediaProjectionChipInteractorTest.Companion.NORMAL_PACKAGE
import com.android.systemui.statusbar.chips.mediaprojection.domain.interactor.MediaProjectionChipInteractorTest.Companion.setUpPackageManagerForMediaProjection
import com.android.systemui.statusbar.chips.ron.demo.ui.viewmodel.demoRonChipViewModel
import com.android.systemui.statusbar.chips.notification.demo.ui.viewmodel.demoNotifChipViewModel
import com.android.systemui.statusbar.chips.notification.shared.StatusBarNotifChips
import com.android.systemui.statusbar.chips.ui.model.OngoingActivityChipModel
import com.android.systemui.statusbar.chips.ui.view.ChipBackgroundContainer
import com.android.systemui.statusbar.phone.SystemUIDialog
@@ -66,13 +66,11 @@ import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever

/**
 * Tests for [OngoingActivityChipsViewModel] when the [FLAG_STATUS_BAR_RON_CHIPS] flag is disabled.
 */
/** Tests for [OngoingActivityChipsViewModel] when the [StatusBarNotifChips] flag is disabled. */
@SmallTest
@RunWith(AndroidJUnit4::class)
@OptIn(ExperimentalCoroutinesApi::class)
@DisableFlags(FLAG_STATUS_BAR_RON_CHIPS)
@DisableFlags(StatusBarNotifChips.FLAG_NAME)
class OngoingActivityChipsViewModelTest : SysuiTestCase() {
    private val kosmos = Kosmos().also { it.testCase = this }
    private val testScope = kosmos.testScope
@@ -99,11 +97,11 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() {
    @Before
    fun setUp() {
        setUpPackageManagerForMediaProjection(kosmos)
        kosmos.demoRonChipViewModel.start()
        kosmos.demoNotifChipViewModel.start()
        val icon =
            BitmapDrawable(
                context.resources,
                Bitmap.createBitmap(/* width= */ 100, /* height= */ 100, Bitmap.Config.ARGB_8888)
                Bitmap.createBitmap(/* width= */ 100, /* height= */ 100, Bitmap.Config.ARGB_8888),
            )
        whenever(kosmos.packageManager.getApplicationIcon(any<String>())).thenReturn(icon)
    }
@@ -325,7 +323,7 @@ class OngoingActivityChipsViewModelTest : SysuiTestCase() {
            latest: OngoingActivityChipModel?,
            chipView: View,
            dialog: SystemUIDialog,
            kosmos: Kosmos
            kosmos: Kosmos,
        ): DialogInterface.OnClickListener {
            // Capture the action that would get invoked when the user clicks "Stop" on the dialog
            lateinit var dialogStopAction: DialogInterface.OnClickListener
+25 −27
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.platform.test.annotations.EnableFlags
import android.view.View
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.Flags.FLAG_STATUS_BAR_RON_CHIPS
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
@@ -37,9 +36,10 @@ import com.android.systemui.screenrecord.data.repository.screenRecordRepository
import com.android.systemui.statusbar.StatusBarIconView
import com.android.systemui.statusbar.chips.mediaprojection.domain.interactor.MediaProjectionChipInteractorTest.Companion.NORMAL_PACKAGE
import com.android.systemui.statusbar.chips.mediaprojection.domain.interactor.MediaProjectionChipInteractorTest.Companion.setUpPackageManagerForMediaProjection
import com.android.systemui.statusbar.chips.notification.demo.ui.viewmodel.DemoNotifChipViewModelTest.Companion.addDemoNotifChip
import com.android.systemui.statusbar.chips.notification.demo.ui.viewmodel.demoNotifChipViewModel
import com.android.systemui.statusbar.chips.notification.shared.StatusBarNotifChips
import com.android.systemui.statusbar.chips.notification.ui.viewmodel.NotifChipsViewModelTest.Companion.assertIsNotifChip
import com.android.systemui.statusbar.chips.ron.demo.ui.viewmodel.DemoRonChipViewModelTest.Companion.addDemoRonChip
import com.android.systemui.statusbar.chips.ron.demo.ui.viewmodel.demoRonChipViewModel
import com.android.systemui.statusbar.chips.ui.model.MultipleOngoingActivityChipsModel
import com.android.systemui.statusbar.chips.ui.model.OngoingActivityChipModel
import com.android.systemui.statusbar.chips.ui.view.ChipBackgroundContainer
@@ -73,14 +73,12 @@ import org.mockito.kotlin.any
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever

/**
 * Tests for [OngoingActivityChipsViewModel] when the [FLAG_STATUS_BAR_RON_CHIPS] flag is enabled.
 */
/** Tests for [OngoingActivityChipsViewModel] when the [StatusBarNotifChips] flag is enabled. */
@SmallTest
@RunWith(AndroidJUnit4::class)
@OptIn(ExperimentalCoroutinesApi::class)
@EnableFlags(FLAG_STATUS_BAR_RON_CHIPS)
class OngoingActivityChipsWithRonsViewModelTest : SysuiTestCase() {
@EnableFlags(StatusBarNotifChips.FLAG_NAME)
class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val systemClock = kosmos.fakeSystemClock
@@ -110,7 +108,7 @@ class OngoingActivityChipsWithRonsViewModelTest : SysuiTestCase() {
    @Before
    fun setUp() {
        setUpPackageManagerForMediaProjection(kosmos)
        kosmos.demoRonChipViewModel.start()
        kosmos.demoNotifChipViewModel.start()
        val icon =
            BitmapDrawable(
                context.resources,
@@ -119,7 +117,7 @@ class OngoingActivityChipsWithRonsViewModelTest : SysuiTestCase() {
        whenever(kosmos.packageManager.getApplicationIcon(any<String>())).thenReturn(icon)
    }

    // Even though the `primaryChip` flow isn't used when the RONs flag is on, still test that the
    // Even though the `primaryChip` flow isn't used when the notifs flag is on, still test that the
    // flow has the right behavior to verify that we don't break any existing functionality.

    @Test
@@ -256,13 +254,13 @@ class OngoingActivityChipsWithRonsViewModelTest : SysuiTestCase() {
        testScope.runTest {
            screenRecordState.value = ScreenRecordModel.Recording
            callRepo.setOngoingCallState(inCallModel(startTimeMs = 34))
            addDemoRonChip(commandRegistry, pw)
            addDemoNotifChip(commandRegistry, pw)

            val latest by collectLastValue(underTest.chips)

            assertIsScreenRecordChip(latest!!.primary)
            assertIsCallChip(latest!!.secondary)
            // Demo RON chip is dropped
            // Demo notif chip is dropped
        }

    @Test
@@ -389,7 +387,7 @@ class OngoingActivityChipsWithRonsViewModelTest : SysuiTestCase() {
    fun primaryChip_higherPriorityChipAdded_lowerPriorityChipReplaced() =
        testScope.runTest {
            // Start with just the lowest priority chip shown
            addDemoRonChip(commandRegistry, pw)
            addDemoNotifChip(commandRegistry, pw)
            // And everything else hidden
            callRepo.setOngoingCallState(OngoingCallModel.NoCall)
            mediaProjectionState.value = MediaProjectionState.NotProjecting
@@ -397,7 +395,7 @@ class OngoingActivityChipsWithRonsViewModelTest : SysuiTestCase() {

            val latest by collectLastValue(underTest.primaryChip)

            assertIsDemoRonChip(latest)
            assertIsDemoNotifChip(latest)

            // WHEN the higher priority call chip is added
            callRepo.setOngoingCallState(inCallModel(startTimeMs = 34))
@@ -431,7 +429,7 @@ class OngoingActivityChipsWithRonsViewModelTest : SysuiTestCase() {
            mediaProjectionState.value =
                MediaProjectionState.Projecting.EntireScreen(NORMAL_PACKAGE)
            callRepo.setOngoingCallState(inCallModel(startTimeMs = 34))
            addDemoRonChip(commandRegistry, pw)
            addDemoNotifChip(commandRegistry, pw)

            val latest by collectLastValue(underTest.primaryChip)

@@ -453,15 +451,15 @@ class OngoingActivityChipsWithRonsViewModelTest : SysuiTestCase() {
            // WHEN the higher priority call is removed
            callRepo.setOngoingCallState(OngoingCallModel.NoCall)

            // THEN the lower priority demo RON is used
            assertIsDemoRonChip(latest)
            // THEN the lower priority demo notif is used
            assertIsDemoNotifChip(latest)
        }

    @Test
    fun chips_movesChipsAroundAccordingToPriority() =
        testScope.runTest {
            // Start with just the lowest priority chip shown
            addDemoRonChip(commandRegistry, pw)
            addDemoNotifChip(commandRegistry, pw)
            // And everything else hidden
            callRepo.setOngoingCallState(OngoingCallModel.NoCall)
            mediaProjectionState.value = MediaProjectionState.NotProjecting
@@ -469,16 +467,16 @@ class OngoingActivityChipsWithRonsViewModelTest : SysuiTestCase() {

            val latest by collectLastValue(underTest.chips)

            assertIsDemoRonChip(latest!!.primary)
            assertIsDemoNotifChip(latest!!.primary)
            assertThat(latest!!.secondary).isInstanceOf(OngoingActivityChipModel.Hidden::class.java)

            // WHEN the higher priority call chip is added
            callRepo.setOngoingCallState(inCallModel(startTimeMs = 34))

            // THEN the higher priority call chip is used as primary and demo ron is demoted to
            // THEN the higher priority call chip is used as primary and demo notif is demoted to
            // secondary
            assertIsCallChip(latest!!.primary)
            assertIsDemoRonChip(latest!!.secondary)
            assertIsDemoNotifChip(latest!!.secondary)

            // WHEN the higher priority media projection chip is added
            mediaProjectionState.value =
@@ -489,7 +487,7 @@ class OngoingActivityChipsWithRonsViewModelTest : SysuiTestCase() {
                )

            // THEN the higher priority media projection chip is used as primary and call is demoted
            // to secondary (and demo RON is dropped altogether)
            // to secondary (and demo notif is dropped altogether)
            assertIsShareToAppChip(latest!!.primary)
            assertIsCallChip(latest!!.secondary)

@@ -503,15 +501,15 @@ class OngoingActivityChipsWithRonsViewModelTest : SysuiTestCase() {
            screenRecordState.value = ScreenRecordModel.DoingNothing
            callRepo.setOngoingCallState(OngoingCallModel.NoCall)

            // THEN media projection and demo RON remain
            // THEN media projection and demo notif remain
            assertIsShareToAppChip(latest!!.primary)
            assertIsDemoRonChip(latest!!.secondary)
            assertIsDemoNotifChip(latest!!.secondary)

            // WHEN media projection is dropped
            mediaProjectionState.value = MediaProjectionState.NotProjecting

            // THEN demo RON is promoted to primary
            assertIsDemoRonChip(latest!!.primary)
            // THEN demo notif is promoted to primary
            assertIsDemoNotifChip(latest!!.primary)
            assertThat(latest!!.secondary).isInstanceOf(OngoingActivityChipModel.Hidden::class.java)
        }

@@ -624,7 +622,7 @@ class OngoingActivityChipsWithRonsViewModelTest : SysuiTestCase() {
            assertThat(latest).isEqualTo(OngoingActivityChipModel.Hidden(shouldAnimate = false))
        }

    private fun assertIsDemoRonChip(latest: OngoingActivityChipModel?) {
    private fun assertIsDemoNotifChip(latest: OngoingActivityChipModel?) {
        assertThat(latest).isInstanceOf(OngoingActivityChipModel.Shown::class.java)
        assertThat((latest as OngoingActivityChipModel.Shown).icon)
            .isInstanceOf(OngoingActivityChipModel.ChipIcon.FullColorAppIcon::class.java)
Loading