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

Commit 452a1f26 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[Notifs] Replace `isPinned` boolean with a 3-option enum instead.

Currently, notifications can only be shown heads up if we decide the
notification should be heads up when it's added or updated.

With the status bar notification chips, notifications will *also* be
shown heads up if the user taps on the notification chip.

The status bar needs to have different behavior based on whether the
notification is HUNing because it was added/updated or because the user
tapped on the chip:
 - If added/updated like normal: Hide the clock, show just the new
   notification icon, hide the chips
 - If user tapped on chip: Show clock, show the chip, hide the
   notification icons

This CL replaces the `isPinned` boolean with a 3-option enum so that we
know *why* a notification is being shown heads-up. A future CL will use
PinnedStatus.PinnedDueToChip when the user taps on a chip and update the
status bar behavior accordingly.

Bug: 364653005
Flag: EXEMPT refactor
Test: Key notification CUJs work:
 - Receive notif while unlocked -> notif HUNs
 - Swipe up on HUN -> notif snoozed
 - Swipe left/right on HUN -> notif dismissed
 - Tap on HUN -> launches activity
 - Receive notif while locked with bypass enabled -> notif HUNs
 - Receive notif while locked with bypass disabled -> notif becomes part
   of stack
 - Enable notification cooldown -> notifs cool down

Test: atest BaseHeadsUpManagerTest HeadsUpManagerPhoneTest
Change-Id: Ic60a75e8651a02aa7d7b435f39a01c634332e0c0
parent 82dfcef4
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -2837,9 +2837,7 @@ class SceneContainerStartableTest : SysuiTestCase() {
        )

    private fun fakeHeadsUpRowRepository(key: String, isPinned: Boolean) =
        FakeHeadsUpRowRepository(key = key, elementKey = Any()).apply {
            this.isPinned.value = isPinned
        }
        FakeHeadsUpRowRepository(key = key, elementKey = Any(), isPinned = isPinned)

    private fun setFingerprintSensorType(fingerprintSensorType: FingerprintSensorType) {
        kosmos.fingerprintPropertyRepository.setProperties(
+4 −4
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.app.Notification
import android.app.NotificationManager.IMPORTANCE_DEFAULT
import android.app.NotificationManager.IMPORTANCE_LOW
import android.platform.test.annotations.EnableFlags
import android.provider.Settings
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
@@ -43,6 +42,7 @@ import com.android.systemui.statusbar.notification.collection.notifcollection.No
import com.android.systemui.statusbar.notification.data.repository.FakeHeadsUpRowRepository
import com.android.systemui.statusbar.notification.data.repository.activeNotificationListRepository
import com.android.systemui.statusbar.notification.domain.interactor.lockScreenNotificationMinimalismSetting
import com.android.systemui.statusbar.notification.headsup.PinnedStatus
import com.android.systemui.statusbar.notification.shared.NotificationMinimalism
import com.android.systemui.statusbar.notification.stack.data.repository.headsUpNotificationRepository
import com.android.systemui.testKosmos
@@ -394,7 +394,7 @@ class LockScreenMinimalismCoordinatorTest : SysuiTestCase() {
            assertThatTopUnseenKey().isEqualTo(solo1.key)

            // TEST: even being pinned doesn't take effect immediately
            hunRepo1.isPinned.value = true
            hunRepo1.pinnedStatus.value = PinnedStatus.PinnedBySystem
            testScheduler.advanceTimeBy(0.5.seconds)
            onBeforeTransformGroupsListener.onBeforeTransformGroups(listEntryList)
            assertThatTopUnseenKey().isEqualTo(solo1.key)
@@ -406,8 +406,8 @@ class LockScreenMinimalismCoordinatorTest : SysuiTestCase() {

            // TEST: repeat; being heads up and pinned for 1 second triggers seen
            kosmos.headsUpNotificationRepository.orderedHeadsUpRows.value = listOf(hunRepo2)
            hunRepo1.isPinned.value = false
            hunRepo2.isPinned.value = true
            hunRepo1.pinnedStatus.value = PinnedStatus.NotPinned
            hunRepo2.pinnedStatus.value = PinnedStatus.PinnedBySystem
            testScheduler.advanceTimeBy(1.seconds)
            onBeforeTransformGroupsListener.onBeforeTransformGroups(listEntryList)
            assertThatTopUnseenKey().isEqualTo(null)
+35 −14
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.systemui.kosmos.testScope
import com.android.systemui.shade.shadeTestUtil
import com.android.systemui.statusbar.notification.data.repository.FakeHeadsUpRowRepository
import com.android.systemui.statusbar.notification.data.repository.notificationsKeyguardViewStateRepository
import com.android.systemui.statusbar.notification.headsup.PinnedStatus
import com.android.systemui.statusbar.notification.stack.data.repository.headsUpNotificationRepository
import com.android.systemui.statusbar.notification.stack.domain.interactor.headsUpNotificationInteractor
import com.android.systemui.testKosmos
@@ -102,7 +103,7 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
        }

    @Test
    fun hasPinnedRows_rowGetsPinned_true() =
    fun hasPinnedRows_rowGetsPinnedNormally_true() =
        testScope.runTest {
            val hasPinnedRows by collectLastValue(underTest.hasPinnedRows)
            // GIVEN no rows are pinned
@@ -115,8 +116,30 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
            headsUpRepository.setNotifications(rows)
            runCurrent()

            // WHEN a row gets pinned
            rows[0].isPinned.value = true
            // WHEN a row gets pinned normally
            rows[0].pinnedStatus.value = PinnedStatus.PinnedBySystem
            runCurrent()

            // THEN hasPinnedRows updates to true
            assertThat(hasPinnedRows).isTrue()
        }

    @Test
    fun hasPinnedRows_rowGetsPinnedByUser_true() =
        testScope.runTest {
            val hasPinnedRows by collectLastValue(underTest.hasPinnedRows)
            // GIVEN no rows are pinned
            val rows =
                arrayListOf(
                    fakeHeadsUpRowRepository("key 0"),
                    fakeHeadsUpRowRepository("key 1"),
                    fakeHeadsUpRowRepository("key 2"),
                )
            headsUpRepository.setNotifications(rows)
            runCurrent()

            // WHEN a row gets pinned due to a chip tap
            rows[0].pinnedStatus.value = PinnedStatus.PinnedByUser
            runCurrent()

            // THEN hasPinnedRows updates to true
@@ -138,7 +161,7 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
            runCurrent()

            // THEN that row gets unpinned
            rows[0].isPinned.value = false
            rows[0].pinnedStatus.value = PinnedStatus.NotPinned
            runCurrent()

            // THEN hasPinnedRows updates to false
@@ -246,7 +269,7 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
            runCurrent()

            // WHEN all rows gets pinned
            rows[2].isPinned.value = true
            rows[2].pinnedStatus.value = PinnedStatus.PinnedBySystem
            runCurrent()

            // THEN no rows are filtered
@@ -271,7 +294,7 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
            assertThat(activeHeadsUpRows).containsExactly(rows[0], rows[1], rows[2])

            // WHEN all rows gets pinned
            rows[2].isPinned.value = true
            rows[2].pinnedStatus.value = PinnedStatus.PinnedBySystem
            runCurrent()

            // THEN no change
@@ -329,7 +352,7 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
            runCurrent()

            // WHEN a row gets unpinned
            rows[0].isPinned.value = false
            rows[0].pinnedStatus.value = PinnedStatus.NotPinned
            runCurrent()

            // THEN the unpinned row is filtered
@@ -351,7 +374,7 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
            runCurrent()

            // WHEN a row gets unpinned
            rows[0].isPinned.value = false
            rows[0].pinnedStatus.value = PinnedStatus.NotPinned
            runCurrent()

            // THEN all rows are still present
@@ -372,15 +395,15 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
            headsUpRepository.setNotifications(rows)
            runCurrent()

            rows[0].isPinned.value = true
            rows[0].pinnedStatus.value = PinnedStatus.PinnedBySystem
            runCurrent()
            assertThat(pinnedHeadsUpRows).containsExactly(rows[0])

            rows[0].isPinned.value = false
            rows[0].pinnedStatus.value = PinnedStatus.NotPinned
            runCurrent()
            assertThat(pinnedHeadsUpRows).isEmpty()

            rows[0].isPinned.value = true
            rows[0].pinnedStatus.value = PinnedStatus.PinnedBySystem
            runCurrent()
            assertThat(pinnedHeadsUpRows).containsExactly(rows[0])
        }
@@ -485,7 +508,5 @@ class HeadsUpNotificationInteractorTest : SysuiTestCase() {
        }

    private fun fakeHeadsUpRowRepository(key: String, isPinned: Boolean = false) =
        FakeHeadsUpRowRepository(key = key, elementKey = Any()).apply {
            this.isPinned.value = isPinned
        }
        FakeHeadsUpRowRepository(key = key, isPinned = isPinned)
}
+3 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

import kotlinx.coroutines.flow.StateFlowKt;
import platform.test.runner.parameterized.ParameterizedAndroidJunit4;
import platform.test.runner.parameterized.Parameters;

@@ -318,6 +319,8 @@ public class HeadsUpManagerImplTest extends SysuiTestCase {
                mContext);
        final HeadsUpManagerImpl.HeadsUpEntry headsUpEntry = mock(
                HeadsUpManagerImpl.HeadsUpEntry.class);
        when(headsUpEntry.getPinnedStatus())
                .thenReturn(StateFlowKt.MutableStateFlow(PinnedStatus.NotPinned));
        headsUpEntry.mEntry = notifEntry;

        hum.onEntryRemoved(headsUpEntry, "test");
+2 −1
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import androidx.test.filters.SmallTest;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.shade.ShadeController;
import com.android.systemui.statusbar.notification.headsup.PinnedStatus;
import com.android.systemui.statusbar.notification.logging.NotificationPanelLogger;
import com.android.systemui.statusbar.notification.headsup.HeadsUpManager;

@@ -91,7 +92,7 @@ public class ExpandableNotificationRowDragControllerTest extends SysuiTestCase {
        ExpandableNotificationRowDragController controller = createSpyController();
        mRow.setDragController(controller);
        mRow.setHeadsUp(true);
        mRow.setPinned(true);
        mRow.setPinnedStatus(PinnedStatus.PinnedBySystem);

        mRow.doLongClickCallback(0, 0);
        mRow.doDragCallback(0, 0);
Loading