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

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

Merge changes I9174b973,I4b2dceb7 into main

* changes:
  [SB][Notifs] status_bar_ron_chips flag -> status_bar_notification_chips.
  [SB][Notifs] Initial scaffolding for notification status bar chips.
parents 4a87d601 0409fcd7
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"))
        }
    }
}
+121 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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.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.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
import com.android.systemui.statusbar.notification.data.repository.activeNotificationListRepository
import com.android.systemui.statusbar.notification.shared.ActiveNotificationModel
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlin.test.Test
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.runner.RunWith
import org.mockito.kotlin.mock

@SmallTest
@RunWith(AndroidJUnit4::class)
@OptIn(ExperimentalCoroutinesApi::class)
@EnableFlags(StatusBarNotifChips.FLAG_NAME)
class NotifChipsViewModelTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val activeNotificationListRepository = kosmos.activeNotificationListRepository

    private val underTest = kosmos.notifChipsViewModel

    @Test
    fun chips_noNotifs_empty() =
        testScope.runTest {
            val latest by collectLastValue(underTest.chips)

            setNotifs(emptyList())

            assertThat(latest).isEmpty()
        }

    @Test
    fun chips_notifMissingStatusBarChipIconView_empty() =
        testScope.runTest {
            val latest by collectLastValue(underTest.chips)

            setNotifs(listOf(activeNotificationModel(key = "notif", statusBarChipIcon = null)))

            assertThat(latest).isEmpty()
        }

    @Test
    fun chips_oneNotif_statusBarIconViewMatches() =
        testScope.runTest {
            val latest by collectLastValue(underTest.chips)

            val icon = mock<StatusBarIconView>()
            setNotifs(listOf(activeNotificationModel(key = "notif", statusBarChipIcon = icon)))

            assertThat(latest).hasSize(1)
            val chip = latest!![0]
            assertThat(chip).isInstanceOf(OngoingActivityChipModel.Shown.ShortTimeDelta::class.java)
            assertThat(chip.icon).isEqualTo(OngoingActivityChipModel.ChipIcon.StatusBarView(icon))
        }

    @Test
    fun chips_twoNotifs_twoChips() =
        testScope.runTest {
            val latest by collectLastValue(underTest.chips)

            val firstIcon = mock<StatusBarIconView>()
            val secondIcon = mock<StatusBarIconView>()
            setNotifs(
                listOf(
                    activeNotificationModel(key = "notif1", statusBarChipIcon = firstIcon),
                    activeNotificationModel(key = "notif2", statusBarChipIcon = secondIcon),
                )
            )

            assertThat(latest).hasSize(2)
            assertIsNotifChip(latest!![0], firstIcon)
            assertIsNotifChip(latest!![1], secondIcon)
        }

    private fun setNotifs(notifs: List<ActiveNotificationModel>) {
        activeNotificationListRepository.activeNotifications.value =
            ActiveNotificationsStore.Builder()
                .apply { notifs.forEach { addIndividualNotif(it) } }
                .build()
        testScope.runCurrent()
    }

    companion object {
        fun assertIsNotifChip(latest: OngoingActivityChipModel?, expectedIcon: StatusBarIconView) {
            assertThat(latest)
                .isInstanceOf(OngoingActivityChipModel.Shown.ShortTimeDelta::class.java)
            assertThat((latest as OngoingActivityChipModel.Shown).icon)
                .isEqualTo(OngoingActivityChipModel.ChipIcon.StatusBarView(expectedIcon))
        }
    }
}
+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
+132 −28

File changed and moved.

Preview size limit exceeded, changes collapsed.

Loading