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

Commit 3150436c authored by Caitlin Shkuratov's avatar Caitlin Shkuratov Committed by Android (Google) Code Review
Browse files

Merge changes from topic "caitlinshk-chip-bounds" into main

* changes:
  [SB] Remove flag status_bar_auto_start_screen_record_chip
  [SB][Notif] Only show 1 status bar notification chip per app.
  [SB][Chips] Keep track of each chip's current on-screens bounds.
parents 1856c05c a45d8065
Loading
Loading
Loading
Loading
+10 −12
Original line number Diff line number Diff line
@@ -425,18 +425,6 @@ flag {
    }
}

flag {
    name: "status_bar_auto_start_screen_record_chip"
    namespace: "systemui"
    description: "When screen recording, use the specified start time to update the screen record "
        "chip state instead of waiting for an official 'recording started' signal"
    bug: "366448907"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}


flag {
    name: "status_bar_chips_modernization"
    namespace: "systemui"
@@ -524,6 +512,16 @@ flag {
  is_fixed_read_only: true
}

flag {
    name: "status_bar_chip_to_hun_animation"
    namespace: "systemui"
    description: "Implement a bespoke tap-chip-to-show-HUN animation for SB notification chips"
    bug: "393369891"
    metadata {
      purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "status_bar_window_no_custom_touch"
    namespace: "systemui"
+185 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import com.android.systemui.statusbar.notification.data.model.activeNotification
import com.android.systemui.statusbar.notification.data.repository.ActiveNotificationsStore
import com.android.systemui.statusbar.notification.data.repository.UnconfinedFakeHeadsUpRowRepository
import com.android.systemui.statusbar.notification.data.repository.activeNotificationListRepository
import com.android.systemui.statusbar.notification.data.repository.addNotif
import com.android.systemui.statusbar.notification.headsup.PinnedStatus
import com.android.systemui.statusbar.notification.promoted.PromotedNotificationUi
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentBuilder
@@ -232,16 +233,19 @@ class NotifChipsViewModelTest : SysuiTestCase() {
                listOf(
                    activeNotificationModel(
                        key = "notif1",
                        packageName = "notif1",
                        statusBarChipIcon = firstIcon,
                        promotedContent = PromotedNotificationContentBuilder("notif1").build(),
                    ),
                    activeNotificationModel(
                        key = "notif2",
                        packageName = "notif2",
                        statusBarChipIcon = secondIcon,
                        promotedContent = PromotedNotificationContentBuilder("notif2").build(),
                    ),
                    activeNotificationModel(
                        key = "notif3",
                        packageName = "notif3",
                        statusBarChipIcon = createStatusBarIconViewOrNull(),
                        promotedContent = null,
                    ),
@@ -267,16 +271,19 @@ class NotifChipsViewModelTest : SysuiTestCase() {
                listOf(
                    activeNotificationModel(
                        key = firstKey,
                        packageName = firstKey,
                        statusBarChipIcon = null,
                        promotedContent = PromotedNotificationContentBuilder(firstKey).build(),
                    ),
                    activeNotificationModel(
                        key = secondKey,
                        packageName = secondKey,
                        statusBarChipIcon = null,
                        promotedContent = PromotedNotificationContentBuilder(secondKey).build(),
                    ),
                    activeNotificationModel(
                        key = thirdKey,
                        packageName = thirdKey,
                        statusBarChipIcon = null,
                        promotedContent = null,
                    ),
@@ -288,6 +295,184 @@ class NotifChipsViewModelTest : SysuiTestCase() {
            assertIsNotifKey(latest!![1], secondKey)
        }

    @Test
    fun chips_twoChips_samePackage_differentUids_bothIncluded() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)

            fakeSystemClock.setCurrentTimeMillis(1000)
            activeNotificationListRepository.addNotif(
                activeNotificationModel(
                    key = "notif1",
                    packageName = "samePackage",
                    uid = 10,
                    statusBarChipIcon = createStatusBarIconViewOrNull(),
                    promotedContent = PromotedNotificationContentBuilder("notif1").build(),
                )
            )

            fakeSystemClock.advanceTime(1000)
            activeNotificationListRepository.addNotif(
                activeNotificationModel(
                    key = "notif2",
                    packageName = "samePackage",
                    uid = 20,
                    statusBarChipIcon = createStatusBarIconViewOrNull(),
                    promotedContent = PromotedNotificationContentBuilder("notif2").build(),
                )
            )

            // Notif added later takes priority
            assertThat(latest!!.map { it.key }).containsExactly("notif2", "notif1").inOrder()
        }

    @Test
    fun chips_twoChips_sameUid_differentPackages_bothIncluded() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)

            fakeSystemClock.setCurrentTimeMillis(1000)
            activeNotificationListRepository.addNotif(
                activeNotificationModel(
                    key = "notif1",
                    packageName = "onePackage",
                    uid = 10,
                    statusBarChipIcon = createStatusBarIconViewOrNull(),
                    promotedContent = PromotedNotificationContentBuilder("notif1").build(),
                )
            )

            fakeSystemClock.advanceTime(1000)
            activeNotificationListRepository.addNotif(
                activeNotificationModel(
                    key = "notif2",
                    packageName = "anotherPackage",
                    uid = 10,
                    statusBarChipIcon = createStatusBarIconViewOrNull(),
                    promotedContent = PromotedNotificationContentBuilder("notif2").build(),
                )
            )

            // Notif added later takes priority
            assertThat(latest!!.map { it.key }).containsExactly("notif2", "notif1").inOrder()
        }

    @Test
    fun chips_twoChips_samePackage_andSameUid_onlyLaterOneIncluded() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)

            val uid = 3
            fakeSystemClock.setCurrentTimeMillis(1000)
            activeNotificationListRepository.addNotif(
                activeNotificationModel(
                    key = "notif1",
                    packageName = "samePackage",
                    uid = 3,
                    statusBarChipIcon = createStatusBarIconViewOrNull(),
                    promotedContent = PromotedNotificationContentBuilder("notif1").build(),
                )
            )

            fakeSystemClock.advanceTime(1000)
            activeNotificationListRepository.addNotif(
                activeNotificationModel(
                    key = "notif2",
                    packageName = "samePackage",
                    uid = 3,
                    statusBarChipIcon = createStatusBarIconViewOrNull(),
                    promotedContent = PromotedNotificationContentBuilder("notif2").build(),
                )
            )

            // Notif added later takes priority
            assertThat(latest!!.map { it.key }).containsExactly("notif2").inOrder()
        }

    @Test
    fun chips_multipleChipsFromMultiplePackagesAndUids_higherPriorityOfEachIncluded() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)

            // Two notifs from "firstPackage"
            fakeSystemClock.setCurrentTimeMillis(1000)
            activeNotificationListRepository.addNotif(
                activeNotificationModel(
                    key = "firstPackage.1",
                    packageName = "firstPackage",
                    uid = 1,
                    statusBarChipIcon = createStatusBarIconViewOrNull(),
                    promotedContent = PromotedNotificationContentBuilder("firstPackage.1").build(),
                )
            )

            fakeSystemClock.advanceTime(1000)
            activeNotificationListRepository.addNotif(
                activeNotificationModel(
                    key = "firstPackage.2",
                    packageName = "firstPackage",
                    uid = 1,
                    statusBarChipIcon = createStatusBarIconViewOrNull(),
                    promotedContent = PromotedNotificationContentBuilder("firstPackage.2").build(),
                )
            )

            // Three notifs from "secondPackage"
            fakeSystemClock.advanceTime(1000)
            activeNotificationListRepository.addNotif(
                activeNotificationModel(
                    key = "secondPackage.1",
                    packageName = "secondPackage",
                    uid = 2,
                    statusBarChipIcon = createStatusBarIconViewOrNull(),
                    promotedContent = PromotedNotificationContentBuilder("secondPackage.1").build(),
                )
            )

            fakeSystemClock.advanceTime(1000)
            activeNotificationListRepository.addNotif(
                activeNotificationModel(
                    key = "secondPackage.2",
                    packageName = "secondPackage",
                    uid = 2,
                    statusBarChipIcon = createStatusBarIconViewOrNull(),
                    promotedContent = PromotedNotificationContentBuilder("secondPackage.2").build(),
                )
            )

            fakeSystemClock.advanceTime(1000)
            activeNotificationListRepository.addNotif(
                activeNotificationModel(
                    key = "secondPackage.3",
                    packageName = "secondPackage",
                    uid = 2,
                    statusBarChipIcon = createStatusBarIconViewOrNull(),
                    promotedContent = PromotedNotificationContentBuilder("secondPackage.3").build(),
                )
            )

            fakeSystemClock.advanceTime(1000)
            activeNotificationListRepository.addNotif(
                activeNotificationModel(
                    key = "secondPackage.andDifferentUid",
                    packageName = "secondPackage",
                    uid = 200,
                    statusBarChipIcon = createStatusBarIconViewOrNull(),
                    promotedContent =
                        PromotedNotificationContentBuilder("secondPackage.andDifferentUid").build(),
                )
            )

            // Notifs added later take priority
            assertThat(latest!!.map { it.key })
                .containsExactly(
                    "secondPackage.andDifferentUid",
                    "secondPackage.3",
                    "firstPackage.2",
                )
                .inOrder()
        }

    @Test
    fun chips_notifTimeAndSystemTimeBothUpdated_modelNotRecreated() =
        kosmos.runTest {
+1 −26
Original line number Diff line number Diff line
@@ -16,11 +16,8 @@

package com.android.systemui.statusbar.chips.screenrecord.domain.interactor

import android.platform.test.annotations.DisableFlags
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_AUTO_START_SCREEN_RECORD_CHIP
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
@@ -161,25 +158,7 @@ class ScreenRecordChipInteractorTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_STATUS_BAR_AUTO_START_SCREEN_RECORD_CHIP)
    fun screenRecordState_flagOff_doesNotAutomaticallySwitchToRecordingBasedOnTime() =
        testScope.runTest {
            val latest by collectLastValue(underTest.screenRecordState)

            // WHEN screen record should start in 900ms
            screenRecordRepo.screenRecordState.value = ScreenRecordModel.Starting(900)
            assertThat(latest).isEqualTo(ScreenRecordChipModel.Starting(900))

            // WHEN 900ms has elapsed
            advanceTimeBy(901)

            // THEN we don't automatically update to the recording state if the flag is off
            assertThat(latest).isEqualTo(ScreenRecordChipModel.Starting(900))
        }

    @Test
    @EnableFlags(FLAG_STATUS_BAR_AUTO_START_SCREEN_RECORD_CHIP)
    fun screenRecordState_flagOn_automaticallySwitchesToRecordingBasedOnTime() =
    fun screenRecordState_automaticallySwitchesToRecordingBasedOnTime() =
        testScope.runTest {
            val latest by collectLastValue(underTest.screenRecordState)

@@ -195,7 +174,6 @@ class ScreenRecordChipInteractorTest : SysuiTestCase() {
        }

    @Test
    @EnableFlags(FLAG_STATUS_BAR_AUTO_START_SCREEN_RECORD_CHIP)
    fun screenRecordState_recordingBeginsEarly_switchesToRecording() =
        testScope.runTest {
            val latest by collectLastValue(underTest.screenRecordState)
@@ -227,7 +205,6 @@ class ScreenRecordChipInteractorTest : SysuiTestCase() {
        }

    @Test
    @EnableFlags(FLAG_STATUS_BAR_AUTO_START_SCREEN_RECORD_CHIP)
    fun screenRecordState_secondRecording_doesNotAutomaticallyStart() =
        testScope.runTest {
            val latest by collectLastValue(underTest.screenRecordState)
@@ -250,7 +227,6 @@ class ScreenRecordChipInteractorTest : SysuiTestCase() {
        }

    @Test
    @EnableFlags(FLAG_STATUS_BAR_AUTO_START_SCREEN_RECORD_CHIP)
    fun screenRecordState_startingButThenDoingNothing_doesNotAutomaticallyStart() =
        testScope.runTest {
            val latest by collectLastValue(underTest.screenRecordState)
@@ -269,7 +245,6 @@ class ScreenRecordChipInteractorTest : SysuiTestCase() {
        }

    @Test
    @EnableFlags(FLAG_STATUS_BAR_AUTO_START_SCREEN_RECORD_CHIP)
    fun screenRecordState_multipleStartingValues_autoStartResets() =
        testScope.runTest {
            val latest by collectLastValue(underTest.screenRecordState)
+213 −17

File changed.

Preview size limit exceeded, changes collapsed.

+3 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.statusbar.pipeline.shared.ui.viewmodel

import android.graphics.Color
import android.graphics.Rect
import android.graphics.RectF
import android.view.View
import androidx.compose.runtime.getValue
import com.android.systemui.lifecycle.ExclusiveActivatable
@@ -57,6 +58,8 @@ class FakeHomeStatusBarViewModel(
    override val ongoingActivityChips =
        ChipsVisibilityModel(MultipleOngoingActivityChipsModel(), areChipsAllowed = false)

    override fun onChipBoundsChanged(key: String, bounds: RectF) {}

    override val ongoingActivityChipsLegacy =
        MutableStateFlow(MultipleOngoingActivityChipsModelLegacy())

Loading