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

Commit e64dc557 authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

Make empty shade text react to Modes changes

Bug: 366003631
Flag: android.app.modes_ui_empty_shade
Test: EmptyShadeViewModelTest + ZenModeInteractorTest
Change-Id: I07d46bd955b34e57e4450935484a6adb57999db3
parent 2768fbe7
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -167,6 +167,13 @@ public class TestModeBuilder {
        return this;
    }

    public TestModeBuilder setVisualEffect(int effect, boolean allowed) {
        ZenPolicy newPolicy = new ZenPolicy.Builder(mRule.getZenPolicy())
                .showVisualEffect(effect, allowed).build();
        setZenPolicy(newPolicy);
        return this;
    }

    public TestModeBuilder setEnabled(boolean enabled) {
        return setEnabled(enabled, /* byUser= */ false);
    }
+54 −3
Original line number Diff line number Diff line
@@ -16,17 +16,20 @@

package com.android.systemui.statusbar.notification.emptyshade.ui.viewmodel

import android.app.Flags
import android.app.NotificationManager.Policy
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.FlagsParameterization
import android.provider.Settings
import android.service.notification.ZenPolicy.VISUAL_EFFECT_NOTIFICATION_LIST
import androidx.test.filters.SmallTest
import com.android.settingslib.notification.data.repository.updateNotificationPolicy
import com.android.settingslib.notification.modes.TestModeBuilder
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.flags.andSceneContainer
import com.android.systemui.kosmos.testScope
import com.android.systemui.res.R
import com.android.systemui.statusbar.notification.data.repository.activeNotificationListRepository
import com.android.systemui.statusbar.notification.emptyshade.shared.ModesEmptyShadeFix
import com.android.systemui.statusbar.notification.footer.shared.FooterViewRefactor
@@ -117,6 +120,7 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {

    @Test
    @EnableFlags(ModesEmptyShadeFix.FLAG_NAME)
    @DisableFlags(Flags.FLAG_MODES_UI, Flags.FLAG_MODES_API)
    fun text_changesWhenNotifsHiddenInShade() =
        testScope.runTest {
            val text by collectLastValue(underTest.text)
@@ -127,7 +131,7 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
            zenModeRepository.updateZenMode(Settings.Global.ZEN_MODE_OFF)
            runCurrent()

            assertThat(text).isEqualTo(R.string.empty_shade_text)
            assertThat(text).isEqualTo("No notifications")

            zenModeRepository.updateNotificationPolicy(
                suppressedVisualEffects = Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST
@@ -135,7 +139,54 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
            zenModeRepository.updateZenMode(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS)
            runCurrent()

            assertThat(text).isEqualTo(R.string.dnd_suppressing_shade_text)
            assertThat(text).isEqualTo("Notifications paused by Do Not Disturb")
        }

    @Test
    @EnableFlags(ModesEmptyShadeFix.FLAG_NAME, Flags.FLAG_MODES_UI, Flags.FLAG_MODES_API)
    fun text_reflectsModesHidingNotifications() =
        testScope.runTest {
            val text by collectLastValue(underTest.text)

            assertThat(text).isEqualTo("No notifications")

            zenModeRepository.addMode(
                TestModeBuilder()
                    .setId("Do not disturb")
                    .setName("Do not disturb")
                    .setActive(true)
                    .setVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, /* allowed= */ false)
                    .build()
            )
            runCurrent()
            assertThat(text).isEqualTo("Notifications paused by Do not disturb")

            zenModeRepository.addMode(
                TestModeBuilder()
                    .setId("Work")
                    .setName("Work")
                    .setActive(true)
                    .setVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, /* allowed= */ false)
                    .build()
            )
            runCurrent()
            assertThat(text).isEqualTo("Notifications paused by Do not disturb and one other mode")

            zenModeRepository.addMode(
                TestModeBuilder()
                    .setId("Gym")
                    .setName("Gym")
                    .setActive(true)
                    .setVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, /* allowed= */ false)
                    .build()
            )
            runCurrent()
            assertThat(text).isEqualTo("Notifications paused by Do not disturb and 2 other modes")

            zenModeRepository.deactivateMode("Do not disturb")
            zenModeRepository.deactivateMode("Work")
            runCurrent()
            assertThat(text).isEqualTo("Notifications paused by Gym")
        }

    @Test
+44 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.provider.Settings.Secure.ZEN_DURATION
import android.provider.Settings.Secure.ZEN_DURATION_FOREVER
import android.provider.Settings.Secure.ZEN_DURATION_PROMPT
import android.service.notification.SystemZenRules
import android.service.notification.ZenPolicy.VISUAL_EFFECT_NOTIFICATION_LIST
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.internal.R
@@ -34,6 +35,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.shared.settings.data.repository.secureSettingsRepository
import com.android.systemui.statusbar.notification.emptyshade.shared.ModesEmptyShadeFix
import com.android.systemui.statusbar.policy.data.repository.fakeDeviceProvisioningRepository
import com.android.systemui.statusbar.policy.data.repository.fakeZenModeRepository
import com.android.systemui.testKosmos
@@ -379,4 +381,46 @@ class ZenModeInteractorTest : SysuiTestCase() {

            assertThat(dndMode!!.isActive).isTrue()
        }

    @Test
    @EnableFlags(ModesEmptyShadeFix.FLAG_NAME, Flags.FLAG_MODES_UI, Flags.FLAG_MODES_API)
    fun modesHidingNotifications_onlyIncludesModesWithNotifListSuppression() =
        testScope.runTest {
            val modesHidingNotifications by collectLastValue(underTest.modesHidingNotifications)

            zenModeRepository.addModes(
                listOf(
                    TestModeBuilder()
                        .setName("Not active, no list suppression")
                        .setActive(false)
                        .setVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, /* allowed= */ true)
                        .build(),
                    TestModeBuilder()
                        .setName("Not active, has list suppression")
                        .setActive(false)
                        .setVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, /* allowed= */ false)
                        .build(),
                    TestModeBuilder()
                        .setName("No list suppression")
                        .setActive(true)
                        .setVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, /* allowed= */ true)
                        .build(),
                    TestModeBuilder()
                        .setName("Has list suppression 1")
                        .setActive(true)
                        .setVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, /* allowed= */ false)
                        .build(),
                    TestModeBuilder()
                        .setName("Has list suppression 2")
                        .setActive(true)
                        .setVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, /* allowed= */ false)
                        .build(),
                )
            )
            runCurrent()

            assertThat(modesHidingNotifications?.map { it.name })
                .containsExactly("Has list suppression 1", "Has list suppression 2")
                .inOrder()
        }
}
+10 −0
Original line number Diff line number Diff line
@@ -1473,6 +1473,16 @@
    <!-- The text to show in the notifications shade when dnd is suppressing notifications. [CHAR LIMIT=100] -->
    <string name="dnd_suppressing_shade_text">Notifications paused by Do Not Disturb</string>

    <!-- The text to show in the notifications shade when a mode is suppressing notifications. [CHAR LIMIT=100] -->
    <string name="modes_suppressing_shade_text">
        {count, plural, offset:1
            =0 {No notifications}
            =1 {Notifications paused by {mode}}
            =2 {Notifications paused by {mode} and one other mode}
            other {Notifications paused by {mode} and # other modes}
        }
    </string>

    <!-- Media projection permission dialog action text. [CHAR LIMIT=60] -->
    <string name="media_projection_action_text">Start now</string>

+24 −8
Original line number Diff line number Diff line
@@ -39,12 +39,15 @@ import com.android.systemui.statusbar.notification.stack.ExpandableViewState;

import kotlin.Unit;

import java.util.Objects;

public class EmptyShadeView extends StackScrollerDecorView implements LaunchableView {

    private TextView mEmptyText;
    private TextView mEmptyFooterText;

    private @StringRes int mText = R.string.empty_shade_text;
    private @StringRes int mTextId = R.string.empty_shade_text;
    private String mTextString;

    private @DrawableRes int mFooterIcon;
    private @StringRes int mFooterText;
@@ -62,7 +65,9 @@ public class EmptyShadeView extends StackScrollerDecorView implements Launchable
        super(context, attrs);
        mSize = getResources().getDimensionPixelSize(
                R.dimen.notifications_unseen_footer_icon_size);
        if (!ModesEmptyShadeFix.isEnabled()) {
        if (ModesEmptyShadeFix.isEnabled()) {
            mTextString = getContext().getString(R.string.empty_shade_text);
        } else {
            // These will be set by the binder when appropriate if ModesEmptyShadeFix is on.
            mFooterIcon = R.drawable.ic_friction_lock_closed;
            mFooterText = R.string.unlock_to_see_notif_text;
@@ -97,7 +102,11 @@ public class EmptyShadeView extends StackScrollerDecorView implements Launchable
        super.onConfigurationChanged(newConfig);
        mSize = getResources().getDimensionPixelSize(
                R.dimen.notifications_unseen_footer_icon_size);
        mEmptyText.setText(mText);
        if (ModesEmptyShadeFix.isEnabled()) {
            mEmptyText.setText(mTextString);
        } else {
            mEmptyText.setText(mTextId);
        }
        mEmptyFooterText.setVisibility(mFooterVisibility);
        setFooterText(mFooterText);
        setFooterIcon(mFooterIcon);
@@ -122,11 +131,18 @@ public class EmptyShadeView extends StackScrollerDecorView implements Launchable

    /** Set the resource ID for the main text shown by the view. */
    public void setText(@StringRes int text) {
        if (ModesEmptyShadeFix.isEnabled() && mText == text) {
            return; // nothing to change
        ModesEmptyShadeFix.assertInLegacyMode();
        mTextId = text;
        mEmptyText.setText(mTextId);
    }

    /** Set the string for the main text shown by the view. */
    public void setText(String text) {
        if (ModesEmptyShadeFix.isUnexpectedlyInLegacyMode() || Objects.equals(mTextString, text)) {
            return;
        }
        mText = text;
        mEmptyText.setText(mText);
        mTextString = text;
        mEmptyText.setText(text);
    }

    /** Visibility for the footer (the additional icon+text shown below the main text). */
@@ -173,7 +189,7 @@ public class EmptyShadeView extends StackScrollerDecorView implements Launchable
    @StringRes
    public int getTextResource() {
        ModesEmptyShadeFix.assertInLegacyMode();
        return mText;
        return mTextId;
    }

    /** Get resource ID for footer text. */
Loading