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

Commit 7bc734e4 authored by Matías Hernández's avatar Matías Hernández Committed by Android (Google) Code Review
Browse files

Merge "Track user update of rule icon" into main

parents ff4ec7ef 660b09a1
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ public final class AutomaticZenRule implements Parcelable {
    @IntDef(flag = true, prefix = { "FIELD_" }, value = {
            FIELD_NAME,
            FIELD_INTERRUPTION_FILTER,
            FIELD_ICON
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ModifiableField {}
@@ -133,6 +134,11 @@ public final class AutomaticZenRule implements Parcelable {
     */
    @FlaggedApi(Flags.FLAG_MODES_API)
    public static final int FIELD_INTERRUPTION_FILTER = 1 << 1;
    /**
     * @hide
     */
    @FlaggedApi(Flags.FLAG_MODES_API)
    public static final int FIELD_ICON = 1 << 2;

    private boolean enabled;
    private String name;
@@ -579,6 +585,9 @@ public final class AutomaticZenRule implements Parcelable {
        if ((bitmask & FIELD_INTERRUPTION_FILTER) != 0) {
            modified.add("FIELD_INTERRUPTION_FILTER");
        }
        if ((bitmask & FIELD_ICON) != 0) {
            modified.add("FIELD_ICON");
        }
        return "{" + String.join(",", modified) + "}";
    }

+17 −4
Original line number Diff line number Diff line
@@ -1154,11 +1154,13 @@ public class ZenModeHelper {
                rule.allowManualInvocation = azr.isManualInvocationAllowed();
                modified = true;
            }
            if (!Flags.modesUi()) {
                String iconResName = drawableResIdToResName(rule.pkg, azr.getIconResId());
                if (!Objects.equals(rule.iconResName, iconResName)) {
                    rule.iconResName = iconResName;
                    modified = true;
                }
            }
            if (!Objects.equals(rule.triggerDescription, azr.getTriggerDescription())) {
                rule.triggerDescription = azr.getTriggerDescription();
                modified = true;
@@ -1210,6 +1212,17 @@ public class ZenModeHelper {
                modified = true;
            }

            if (Flags.modesUi()) {
                String iconResName = drawableResIdToResName(rule.pkg, azr.getIconResId());
                if (!Objects.equals(rule.iconResName, iconResName)) {
                    rule.iconResName = iconResName;
                    if (updateBitmask) {
                        rule.userModifiedFields |= AutomaticZenRule.FIELD_ICON;
                    }
                    modified = true;
                }
            }

            // Updates the bitmask and values for all policy fields, based on the origin.
            modified |= updatePolicy(rule, azr.getZenPolicy(), updateBitmask, isNew);

+9 −3
Original line number Diff line number Diff line
@@ -4361,7 +4361,7 @@ public class ZenModeHelperTest extends UiServiceTestCase {
                azrBase, UPDATE_ORIGIN_APP, "reason", Process.SYSTEM_UID);
        AutomaticZenRule rule = mZenModeHelper.getAutomaticZenRule(ruleId);

        // Modifies the filter, zen policy, and device effects
        // Modifies the filter, icon, zen policy, and device effects
        ZenPolicy policy = new ZenPolicy.Builder(rule.getZenPolicy())
                .allowPriorityChannels(false)
                .build();
@@ -4371,6 +4371,7 @@ public class ZenModeHelperTest extends UiServiceTestCase {
                        .build();
        AutomaticZenRule azrUpdate = new AutomaticZenRule.Builder(rule)
                .setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
                .setIconResId(ICON_RES_ID)
                .setZenPolicy(policy)
                .setDeviceEffects(deviceEffects)
                .build();
@@ -4382,6 +4383,7 @@ public class ZenModeHelperTest extends UiServiceTestCase {

        // UPDATE_ORIGIN_USER should change the bitmask and change the values.
        assertThat(rule.getInterruptionFilter()).isEqualTo(INTERRUPTION_FILTER_PRIORITY);
        assertThat(rule.getIconResId()).isEqualTo(ICON_RES_ID);
        assertThat(rule.getZenPolicy().getPriorityChannelsAllowed()).isEqualTo(
                ZenPolicy.STATE_DISALLOW);

@@ -4389,7 +4391,9 @@ public class ZenModeHelperTest extends UiServiceTestCase {

        ZenRule storedRule = mZenModeHelper.mConfig.automaticRules.get(ruleId);
        assertThat(storedRule.userModifiedFields)
                .isEqualTo(AutomaticZenRule.FIELD_INTERRUPTION_FILTER);
                .isEqualTo(Flags.modesUi()
                        ? AutomaticZenRule.FIELD_INTERRUPTION_FILTER | AutomaticZenRule.FIELD_ICON
                        : AutomaticZenRule.FIELD_INTERRUPTION_FILTER);
        assertThat(storedRule.zenPolicyUserModifiedFields)
                .isEqualTo(ZenPolicy.FIELD_ALLOW_CHANNELS);
        assertThat(storedRule.zenDeviceEffectsUserModifiedFields)
@@ -4414,7 +4418,7 @@ public class ZenModeHelperTest extends UiServiceTestCase {
                azrBase, UPDATE_ORIGIN_APP, "reason", Process.SYSTEM_UID);
        AutomaticZenRule rule = mZenModeHelper.getAutomaticZenRule(ruleId);

        // Modifies the zen policy and device effects
        // Modifies the icon, zen policy and device effects
        ZenPolicy policy = new ZenPolicy.Builder(rule.getZenPolicy())
                .allowReminders(true)
                .build();
@@ -4424,6 +4428,7 @@ public class ZenModeHelperTest extends UiServiceTestCase {
                        .build();
        AutomaticZenRule azrUpdate = new AutomaticZenRule.Builder(rule)
                .setInterruptionFilter(INTERRUPTION_FILTER_PRIORITY)
                .setIconResId(ICON_RES_ID)
                .setZenPolicy(policy)
                .setDeviceEffects(deviceEffects)
                .build();
@@ -4434,6 +4439,7 @@ public class ZenModeHelperTest extends UiServiceTestCase {
        rule = mZenModeHelper.getAutomaticZenRule(ruleId);

        // UPDATE_ORIGIN_SYSTEM_OR_SYSTEMUI should change the value but NOT update the bitmask.
        assertThat(rule.getIconResId()).isEqualTo(ICON_RES_ID);
        assertThat(rule.getZenPolicy().getPriorityCategoryReminders())
                .isEqualTo(ZenPolicy.STATE_ALLOW);
        assertThat(rule.getDeviceEffects().shouldDisplayGrayscale()).isTrue();