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

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

Merge "Tweak updateAZR so that supplying null ZenDeviceEffects behaves the...

Merge "Tweak updateAZR so that supplying null ZenDeviceEffects behaves the same as null ZenPolicy" into main
parents e936a492 352789ed
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -377,6 +377,9 @@ public final class AutomaticZenRule implements Parcelable {
     * Sets the {@link ZenDeviceEffects} associated to this rule. Device effects specify changes to
     * the device behavior that should apply while the rule is active, but are not directly related
     * to suppressing notifications (for example: disabling always-on display).
     *
     * <p>When updating an existing rule via {@link NotificationManager#updateAutomaticZenRule},
     * a {@code null} value here means the previous set of effects is retained.
     */
    @FlaggedApi(Flags.FLAG_MODES_API)
    public void setDeviceEffects(@Nullable ZenDeviceEffects deviceEffects) {
@@ -749,6 +752,9 @@ public final class AutomaticZenRule implements Parcelable {

        /**
         * Sets the zen policy.
         *
         * <p>When updating an existing rule via {@link NotificationManager#updateAutomaticZenRule},
         * a {@code null} value here means the previous policy is retained.
         */
        public @NonNull Builder setZenPolicy(@Nullable ZenPolicy policy) {
            mPolicy = policy;
@@ -759,6 +765,9 @@ public final class AutomaticZenRule implements Parcelable {
         * Sets the {@link ZenDeviceEffects} associated to this rule. Device effects specify changes
         * to the device behavior that should apply while the rule is active, but are not directly
         * related to suppressing notifications (for example: disabling always-on display).
         *
         * <p>When updating an existing rule via {@link NotificationManager#updateAutomaticZenRule},
         * a {@code null} value here means the previous set of effects is retained.
         */
        @NonNull
        public Builder setDeviceEffects(@Nullable ZenDeviceEffects deviceEffects) {
+1 −1
Original line number Diff line number Diff line
@@ -1285,8 +1285,8 @@ public class ZenModeHelper {
     */
    private static void updateZenDeviceEffects(ZenRule zenRule,
            @Nullable ZenDeviceEffects newEffects, boolean isFromApp, boolean updateBitmask) {
        // Same as with ZenPolicy, supplying null effects means keeping the previous ones.
        if (newEffects == null) {
            zenRule.zenDeviceEffects = null;
            return;
        }

+5 −5
Original line number Diff line number Diff line
@@ -4420,13 +4420,13 @@ public class ZenModeHelperTest extends UiServiceTestCase {
    @EnableFlags(Flags.FLAG_MODES_API)
    public void updateAutomaticZenRule_nullDeviceEffectsUpdate() {
        // Adds a starting rule with empty zen policies and device effects
        ZenDeviceEffects zde = new ZenDeviceEffects.Builder().setShouldUseNightMode(true).build();
        AutomaticZenRule azrBase = new AutomaticZenRule.Builder(NAME, CONDITION_ID)
                .setDeviceEffects(new ZenDeviceEffects.Builder().build())
                .setDeviceEffects(zde)
                .build();
        // Adds the rule using the app, to avoid having any user modified bits set.
        String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(),
                azrBase, UPDATE_ORIGIN_APP, "reason", Process.SYSTEM_UID);
        AutomaticZenRule rule = mZenModeHelper.getAutomaticZenRule(ruleId);

        AutomaticZenRule azr = new AutomaticZenRule.Builder(azrBase)
                // Sets Device Effects to null
@@ -4437,10 +4437,10 @@ public class ZenModeHelperTest extends UiServiceTestCase {
        // user modified, it can be updated.
        mZenModeHelper.updateAutomaticZenRule(ruleId, azr, UPDATE_ORIGIN_APP, "reason",
                Process.SYSTEM_UID);
        rule = mZenModeHelper.getAutomaticZenRule(ruleId);
        AutomaticZenRule rule = mZenModeHelper.getAutomaticZenRule(ruleId);

        // When AZR's ZenDeviceEffects is null, the updated rule's device effects will be null.
        assertThat(rule.getDeviceEffects()).isNull();
        // When AZR's ZenDeviceEffects is null, the updated rule's device effects are kept.
        assertThat(rule.getDeviceEffects()).isEqualTo(zde);
    }

    @Test