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

Commit 7a095ee6 authored by Matías Hernández's avatar Matías Hernández
Browse files

Don't set the app launcher icon as the icon for implicit rules

And clear it from existing rules.

Many app icons don't have a monochrome variant, and even when they do they might not be appropriate for some surfaces where mode icons are displayed. Instead, use a default icon (which the user can customize, if they want).

Should be ok to change since it wasn't visible anywhere before MODES_UI.

Flag: android.app.modes_ui
Fixes: 361597532
Test: atest ZenModeHelperTest
Change-Id: I47d8b132287ffc50a74316898c2071fbb31e13ed
parent 28b2ac4c
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -241,10 +241,11 @@ public class ZenModeConfig implements Parcelable {
    // ZenModeConfig XML versions distinguishing key changes.
    public static final int XML_VERSION_ZEN_UPGRADE = 8;
    public static final int XML_VERSION_MODES_API = 11;
    public static final int XML_VERSION_MODES_UI = 12;

    // TODO: b/310620812 - Update XML_VERSION and update default_zen_config.xml accordingly when
    //       modes_api is inlined.
    private static final int XML_VERSION = 10;
    // TODO: b/310620812, b/344831624 - Update XML_VERSION and update default_zen_config.xml
    //  accordingly when modes_api / modes_ui are inlined.
    private static final int XML_VERSION_PRE_MODES = 10;
    public static final String ZEN_TAG = "zen";
    private static final String ZEN_ATT_VERSION = "version";
    private static final String ZEN_ATT_USER = "user";
@@ -952,7 +953,13 @@ public class ZenModeConfig implements Parcelable {
    }

    public static int getCurrentXmlVersion() {
        return Flags.modesApi() ? XML_VERSION_MODES_API : XML_VERSION;
        if (Flags.modesUi()) {
            return XML_VERSION_MODES_UI;
        } else if (Flags.modesApi()) {
            return XML_VERSION_MODES_API;
        } else {
            return XML_VERSION_PRE_MODES;
        }
    }

    public static ZenModeConfig readXml(TypedXmlPullParser parser)
@@ -2607,7 +2614,7 @@ public class ZenModeConfig implements Parcelable {
        @AutomaticZenRule.Type
        public int type = AutomaticZenRule.TYPE_UNKNOWN;
        public String triggerDescription;
        public String iconResName;
        @Nullable public String iconResName;
        public boolean allowManualInvocation;
        @AutomaticZenRule.ModifiableField public int userModifiedFields;
        @ZenPolicy.ModifiableField public int zenPolicyUserModifiedFields;
+1 −19
Original line number Diff line number Diff line
@@ -286,8 +286,7 @@ public class ZenMode implements Parcelable {

    /**
     * Returns the mode icon -- which can be either app-provided (via {@code addAutomaticZenRule}),
     * user-chosen (via the icon picker in Settings), the app's launcher icon for implicit rules
     * (in its monochrome variant, if available), or a default icon based on the mode type.
     * user-chosen (via the icon picker in Settings), or a default icon based on the mode type.
     */
    @NonNull
    public ListenableFuture<Drawable> getIcon(@NonNull Context context,
@@ -300,23 +299,6 @@ public class ZenMode implements Parcelable {
        return iconLoader.getIcon(context, mRule);
    }

    /**
     * Returns an alternative mode icon. The difference with {@link #getIcon} is that it's the
     * basic DND icon not only for Manual DND, but also for <em>implicit rules</em>. As such, it's
     * suitable for places where showing the launcher icon of an app could be confusing, such as
     * the status bar or lockscreen.
     */
    @NonNull
    public ListenableFuture<Drawable> getLockscreenIcon(@NonNull Context context,
            @NonNull ZenIconLoader iconLoader) {
        if (mKind == Kind.MANUAL_DND || mKind == Kind.IMPLICIT) {
            return Futures.immediateFuture(requireNonNull(
                    context.getDrawable(R.drawable.ic_do_not_disturb_on_24dp)));
        }

        return iconLoader.getIcon(context, mRule);
    }

    @NonNull
    public ZenPolicy getPolicy() {
        switch (mRule.getInterruptionFilter()) {
+0 −35
Original line number Diff line number Diff line
@@ -322,41 +322,6 @@ public class ZenModeTest {
        verify(iconLoader).getIcon(any(), eq(IMPLICIT_ZEN_RULE));
    }

    @Test
    public void getLockscreenIcon_normalMode_loadsIconNormally() {
        ZenIconLoader iconLoader = mock(ZenIconLoader.class);
        ZenMode mode = new ZenMode("id", ZEN_RULE, zenConfigRuleFor(ZEN_RULE, false));

        ListenableFuture<Drawable> unused = mode.getLockscreenIcon(
                RuntimeEnvironment.getApplication(), iconLoader);

        verify(iconLoader).getIcon(any(), eq(ZEN_RULE));
    }

    @Test
    public void getLockscreenIcon_manualDnd_returnsFixedIcon() {
        ZenIconLoader iconLoader = mock(ZenIconLoader.class);

        ListenableFuture<Drawable> future = TestModeBuilder.MANUAL_DND_INACTIVE.getLockscreenIcon(
                RuntimeEnvironment.getApplication(), iconLoader);

        assertThat(future.isDone()).isTrue();
        verify(iconLoader, never()).getIcon(any(), any());
    }

    @Test
    public void getLockscreenIcon_implicitMode_returnsFixedIcon() {
        ZenIconLoader iconLoader = mock(ZenIconLoader.class);
        ZenMode mode = new ZenMode(IMPLICIT_RULE_ID, IMPLICIT_ZEN_RULE,
                zenConfigRuleFor(IMPLICIT_ZEN_RULE, false));

        ListenableFuture<Drawable> future = mode.getLockscreenIcon(
                RuntimeEnvironment.getApplication(), iconLoader);

        assertThat(future.isDone()).isTrue();
        verify(iconLoader, never()).getIcon(any(), any());
    }

    private static void assertUnparceledIsEqualToOriginal(String type, ZenMode original) {
        Parcel parcel = Parcel.obtain();
        try {
+1 −1
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ constructor(
                    isActivated = modes.isNotEmpty(),
                    icon =
                        if (Flags.modesApi() && Flags.modesUi() && Flags.modesUiIcons())
                            zenModeInteractor.getActiveModeIcon(context, modes)
                            zenModeInteractor.getActiveModeIcon(modes)
                        else null,
                    activeModes = modes.map { it.name }
                )
+2 −6
Original line number Diff line number Diff line
@@ -95,10 +95,6 @@ constructor(
        return mode.getIcon(context, iconLoader).await().asIcon()
    }

    suspend fun getLockscreenModeIcon(mode: ZenMode): Icon {
        return mode.getLockscreenIcon(context, iconLoader).await().asIcon()
    }

    /**
     * Given the list of modes (which may include zero or more currently active modes), returns an
     * icon representing the active mode, if any (or, if multiple modes are active, to the most
@@ -106,8 +102,8 @@ constructor(
     * standard DND icon for implicit modes, instead of the launcher icon of the associated
     * package).
     */
    suspend fun getActiveModeIcon(context: Context, modes: List<ZenMode>): Icon? {
        return getMainActiveMode(modes)?.let { m -> getLockscreenModeIcon(m) }
    suspend fun getActiveModeIcon(modes: List<ZenMode>): Icon? {
        return getMainActiveMode(modes)?.let { m -> getModeIcon(m) }
    }

    fun activateMode(zenMode: ZenMode) {
Loading