OSDN Git Service

Clear deprecated effects when saving zen policy
authorBeverly <beverlyt@google.com>
Thu, 10 May 2018 17:28:00 +0000 (13:28 -0400)
committerBeverly <beverlyt@google.com>
Thu, 10 May 2018 17:37:37 +0000 (13:37 -0400)
- Deprecated effects are set in NotificationManagerService,
so unset them before setting the NotificationPolicy
- When user clicks on Custom, they are brought to the custom vis effects
page instead of resetting custom values to presets

Fixes: 79383781
Test: manual
Test: NotificationManagerServiceTest testSetNotificationPolicy_preP_setOldNewFields
Change-Id: Id6db9ce2aaeed6321389f8dbfbea65eda30c74ad

src/com/android/settings/notification/ZenModeBackend.java
src/com/android/settings/notification/ZenModeRestrictNotificationsSettings.java
src/com/android/settings/notification/ZenModeVisEffectsCustomPreferenceController.java
tests/robotests/src/com/android/settings/notification/ZenModeVisEffectsCustomPreferenceControllerTest.java

index ece2a9e..cb8a048 100644 (file)
@@ -16,6 +16,9 @@
 
 package com.android.settings.notification;
 
+import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_OFF;
+import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_ON;
+
 import android.app.ActivityManager;
 import android.app.AutomaticZenRule;
 import android.app.NotificationManager;
@@ -146,19 +149,24 @@ public class ZenModeBackend {
     protected void savePolicy(int priorityCategories, int priorityCallSenders,
             int priorityMessageSenders, int suppressedVisualEffects) {
         mPolicy = new NotificationManager.Policy(priorityCategories, priorityCallSenders,
-                priorityMessageSenders,
-                suppressedVisualEffects);
+                priorityMessageSenders, suppressedVisualEffects);
         mNotificationManager.setNotificationPolicy(mPolicy);
     }
 
-    protected int getNewSuppressedEffects(boolean suppress, int effectType) {
+    private int getNewSuppressedEffects(boolean suppress, int effectType) {
         int effects = mPolicy.suppressedVisualEffects;
+
         if (suppress) {
             effects |= effectType;
         } else {
             effects &= ~effectType;
         }
-        return effects;
+
+        return clearDeprecatedEffects(effects);
+    }
+
+    private int clearDeprecatedEffects(int effects) {
+        return effects & ~(SUPPRESSED_EFFECT_SCREEN_ON | SUPPRESSED_EFFECT_SCREEN_OFF);
     }
 
     protected boolean isEffectAllowed(int effect) {
index 966e932..a2a0ba7 100644 (file)
@@ -70,7 +70,6 @@ public class ZenModeRestrictNotificationsSettings extends ZenModeSettingsBase im
             custom.displayPreference(getPreferenceScreen());
 
             if (mShowMenuSelected) {
-                custom.select();
                 metrics.action(mContext, ACTION_ZEN_SHOW_CUSTOM, true);
             } else {
                 metrics.action(mContext, ACTION_ZEN_SHOW_CUSTOM, false);
index 550fda4..5baf0fa 100644 (file)
@@ -18,6 +18,7 @@ package com.android.settings.notification;
 
 import android.app.NotificationManager.Policy;
 import android.content.Context;
+
 import androidx.preference.Preference;
 import androidx.preference.PreferenceScreen;
 
@@ -57,15 +58,12 @@ public class ZenModeVisEffectsCustomPreferenceController
         pref.setChecked(areCustomOptionsSelected());
 
         pref.setOnGearClickListener(p -> {
-            new SubSettingLauncher(mContext)
-                    .setDestination(ZenModeBlockedEffectsSettings.class.getName())
-                    .setTitleRes(R.string.zen_mode_what_to_block_title)
-                    .setSourceMetricsCategory(MetricsProto.MetricsEvent.SETTINGS_ZEN_NOTIFICATIONS)
-                    .launch();
+            launchCustomSettings();
+
         });
 
         pref.setOnRadioButtonClickListener(p -> {
-            select();
+            launchCustomSettings();
         });
     }
 
@@ -84,9 +82,14 @@ public class ZenModeVisEffectsCustomPreferenceController
     protected void select() {
         mMetricsFeatureProvider.action(mContext,
                 MetricsProto.MetricsEvent.ACTION_ZEN_CUSTOM, true);
-        mBackend.savePolicy(mBackend.mPolicy.priorityCategories,
-                mBackend.mPolicy.priorityCallSenders,
-                mBackend.mPolicy.priorityMessageSenders,
-                INTERRUPTIVE_EFFECTS);
+    }
+
+    private void launchCustomSettings() {
+        select();
+        new SubSettingLauncher(mContext)
+                .setDestination(ZenModeBlockedEffectsSettings.class.getName())
+                .setTitleRes(R.string.zen_mode_what_to_block_title)
+                .setSourceMetricsCategory(MetricsProto.MetricsEvent.SETTINGS_ZEN_NOTIFICATIONS)
+                .launch();
     }
 }
\ No newline at end of file
index 5de7697..f3d92d1 100644 (file)
@@ -150,18 +150,4 @@ public class ZenModeVisEffectsCustomPreferenceControllerTest {
         verify(mockPref).setOnGearClickListener(any());
         verify(mockPref).setOnRadioButtonClickListener(any());
     }
-
-    @Test
-    public void select() {
-        int interruptiveSuppressed = SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
-                | SUPPRESSED_EFFECT_AMBIENT
-                | SUPPRESSED_EFFECT_LIGHTS
-                | SUPPRESSED_EFFECT_PEEK;
-        mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 1);
-        mController.select();
-        verify(mBackend).savePolicy(anyInt(), anyInt(), anyInt(), eq(interruptiveSuppressed));
-        verify(mFeatureFactory.metricsFeatureProvider).action(eq(mContext),
-                eq(ACTION_ZEN_CUSTOM),
-                eq(true));
-    }
 }