OSDN Git Service

Show new visual effects options in dnd settings
authorJulia Reynolds <juliacr@google.com>
Fri, 2 Mar 2018 20:51:14 +0000 (15:51 -0500)
committerJulia Reynolds <juliacr@google.com>
Thu, 8 Mar 2018 21:42:35 +0000 (16:42 -0500)
Bug: 74075050
Test: make -j20 RunSettingsRoboTests
Change-Id: Ia629007d1c80b657aaf756d0f6d2edfd89a7f6b4

18 files changed:
AndroidManifest.xml
res/values/strings.xml
res/xml/zen_mode_behavior_settings.xml
res/xml/zen_mode_block_settings.xml [new file with mode: 0644]
res/xml/zen_mode_settings.xml
src/com/android/settings/Settings.java
src/com/android/settings/notification/ZenModeBackend.java
src/com/android/settings/notification/ZenModeBehaviorSettings.java
src/com/android/settings/notification/ZenModeBlockedEffectsPreferenceController.java [new file with mode: 0644]
src/com/android/settings/notification/ZenModeBlockedEffectsSettings.java [new file with mode: 0644]
src/com/android/settings/notification/ZenModeScreenOffPreferenceController.java [deleted file]
src/com/android/settings/notification/ZenModeScreenOnPreferenceController.java [deleted file]
src/com/android/settings/notification/ZenModeSettings.java
src/com/android/settings/notification/ZenModeVisEffectPreferenceController.java [new file with mode: 0644]
src/com/android/settings/search/SearchIndexableResourcesImpl.java
tests/robotests/src/com/android/settings/notification/ZenModeBlockedEffectsPreferenceControllerTest.java [moved from tests/robotests/src/com/android/settings/notification/ZenModeScreenOnPreferenceControllerTest.java with 57% similarity]
tests/robotests/src/com/android/settings/notification/ZenModeScreenOffPreferenceControllerTest.java [deleted file]
tests/robotests/src/com/android/settings/notification/ZenModeVisEffectPreferenceControllerTest.java [new file with mode: 0644]

index feb1b05..d0ed638 100644 (file)
         </activity>
 
         <activity
+            android:name="Settings$ZenModeBlockedEffectsSettingsActivity"
+            android:label="@string/zen_mode_what_to_block_title"
+            android:icon="@drawable/ic_settings_notifications"
+            android:exported="true"
+            android:taskAffinity="com.android.settings"
+            android:parentActivityName="Settings">
+            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+                       android:value="com.android.settings.notification.ZenModeBlockedEffectsSetting" />
+            <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+                       android:value="true" />
+        </activity>
+
+        <activity
             android:name="Settings$ZenModeBehaviorSettingsActivity"
             android:label="@string/zen_mode_behavior_settings_title"
             android:icon="@drawable/ic_settings_notifications"
index 39f641c..c64880e 100644 (file)
     <!-- Do not disturb: Title for the Do not Disturb dialog to turn on Do not disturb. [CHAR LIMIT=50]-->
     <string name="zen_mode_settings_turn_on_dialog_title">Turn on Do Not Disturb</string>
 
-    <!-- Do not disturb: Title for the behaviors option and associated settings page. [CHAR LIMIT=30] -->
-    <string name="zen_mode_behavior_settings_title">Behavior</string>
+    <!-- Do not disturb: Title for the page describing what can bypass DND. [CHAR LIMIT=30] -->
+    <string name="zen_mode_behavior_settings_title">Exceptions</string>
 
     <!-- Do not disturb: Instructions indicating what types of sounds can bypass DND. [CHAR LIMIT=52] -->
     <string name="zen_mode_behavior_allow_title">Allow sounds and vibrations from</string>
     <!--  Do not disturb: Subtitle for the Visual signals option to toggle on/off visual signals/alerts when the screen is on/when screen is off. [CHAR LIMIT=30] -->
     <string name="zen_mode_visual_signals_settings_subtitle">Allow visual signals</string>
 
+    <!-- Do not disturb: what to block title [CHAR LIMIT = 60] -->
+    <string name="zen_mode_what_to_block_title">What to block</string>
+    <!-- Do not disturb: what to block > effects title [CHAR LIMIT = 60] -->
+    <string name="zen_mode_block_effects_title">When notifications arrive</string>
+    <!-- Do not disturb: what to block option [CHAR LIMIT=NONE] -->
+    <string name="zen_mode_block_effect_sound">Mute sound and vibration</string>
+    <!-- Do not disturb: what to block option [CHAR LIMIT=NONE] -->
+    <string name="zen_mode_block_effect_intent">Don\'t turn on screen</string>
+    <!-- Do not disturb: what to block option [CHAR LIMIT=NONE] -->
+    <string name="zen_mode_block_effect_light">Don\'t blink light</string>
+    <!-- Do not disturb: what to block option [CHAR LIMIT=NONE] -->
+    <string name="zen_mode_block_effect_peek">Don\'t pop notifications on screen</string>
+    <!-- Do not disturb: what to block option [CHAR LIMIT=NONE] -->
+    <string name="zen_mode_block_effect_status">Hide status bar icons</string>
+    <!-- Do not disturb: what to block option [CHAR LIMIT=NONE] -->
+    <string name="zen_mode_block_effect_badge">Hide notification dots</string>
+    <!-- Do not disturb: what to block option [CHAR LIMIT=NONE] -->
+    <string name="zen_mode_block_effect_ambient">Hide from ambient display</string>
+    <!-- Do not disturb: what to block option [CHAR LIMIT=NONE] -->
+    <string name="zen_mode_block_effect_list">Hide from notification list</string>
+
+    <!-- Do not disturb: what to block summary, only sound and vibration -->
+    <string name="zen_mode_block_effect_summary_sound">Sound and vibration</string>
+    <!-- Do not disturb: what to block summary, sound vibration and some visual signals-->
+    <string name="zen_mode_block_effect_summary_some">Sound, vibration, and some visual signs of notifications</string>
+    <!-- Do not disturb: what to block summary, all effects -->
+    <string name="zen_mode_block_effect_summary_all">Sound, vibration, and visual signs of notifications</string>
+
     <!--  Do not disturb: Button to add new automatic rule to DND. [CHAR LIMIT=30] -->
     <string name="zen_mode_add">Add</string>
 
index 084b78d..8426d91 100644 (file)
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:settings="http://schemas.android.com/apk/res-auto"
     android:key="zen_mode_behavior_settings_page"
-    android:title="@string/zen_mode_behavior_settings_title"
-    settings:initialExpandedChildrenCount="8">
-
-   <PreferenceCategory
-       android:title="@string/zen_mode_behavior_allow_title"
-       android:key="zen_mode_behavior_allow_preferences">
-
-       <!-- Alarms -->
-       <SwitchPreference
-           android:key="zen_mode_alarms"
-           android:title="@string/zen_mode_alarms"/>
-
-       <!-- Media -->
-       <SwitchPreference
-           android:key="zen_mode_media"
-           android:title="@string/zen_mode_media"/>
-
-       <!-- System -->
-       <SwitchPreference
-           android:key="zen_mode_system"
-           android:title="@string/zen_mode_system"/>
-
-       <!-- Reminders -->
-       <SwitchPreference
-           android:key="zen_mode_reminders"
-           android:title="@string/zen_mode_reminders"/>
-
-       <!-- Events -->
-       <SwitchPreference
-           android:key="zen_mode_events"
-           android:title="@string/zen_mode_events"/>
-
-       <!-- Messages -->
-       <ListPreference
-           android:key="zen_mode_messages"
-           android:title="@string/zen_mode_messages"
-           android:entries="@array/zen_mode_contacts_entries"
-           android:entryValues="@array/zen_mode_contacts_values"/>
-
-       <!-- Calls -->
-       <ListPreference
-           android:key="zen_mode_calls"
-           android:title="@string/zen_mode_calls"
-           android:entries="@array/zen_mode_contacts_entries"
-           android:entryValues="@array/zen_mode_contacts_values"/>
-
-       <!-- Repeat callers -->
-       <SwitchPreference
-           android:key="zen_mode_repeat_callers"
-           android:title="@string/zen_mode_repeat_callers" />
-
-   </PreferenceCategory>
-
-    <PreferenceCategory
-        android:title="@string/zen_mode_visual_signals_settings_subtitle"
-        android:key="zen_mode_visual_signals_preferences">
-
-        <SwitchPreference android:key="zen_mode_screen_on"
-                          android:title="@string/zen_mode_screen_on"
-                          android:summary="@string/zen_mode_screen_on_summary" />
-
-        <SwitchPreference android:key="zen_mode_screen_off"
-                          android:title="@string/zen_mode_screen_off"
-                          android:summary="@string/zen_mode_screen_off_summary" />
-    </PreferenceCategory>
+    android:title="@string/zen_mode_behavior_settings_title" >
+
+   <!-- Alarms -->
+   <SwitchPreference
+       android:key="zen_mode_alarms"
+       android:title="@string/zen_mode_alarms"/>
+
+   <!-- Media -->
+   <SwitchPreference
+       android:key="zen_mode_media"
+       android:title="@string/zen_mode_media"/>
+
+   <!-- System -->
+   <SwitchPreference
+       android:key="zen_mode_system"
+       android:title="@string/zen_mode_system"/>
+
+   <!-- Reminders -->
+   <SwitchPreference
+       android:key="zen_mode_reminders"
+       android:title="@string/zen_mode_reminders"/>
+
+   <!-- Events -->
+   <SwitchPreference
+       android:key="zen_mode_events"
+       android:title="@string/zen_mode_events"/>
+
+   <!-- Messages -->
+   <ListPreference
+       android:key="zen_mode_messages"
+       android:title="@string/zen_mode_messages"
+       android:entries="@array/zen_mode_contacts_entries"
+       android:entryValues="@array/zen_mode_contacts_values"/>
+
+   <!-- Calls -->
+   <ListPreference
+       android:key="zen_mode_calls"
+       android:title="@string/zen_mode_calls"
+       android:entries="@array/zen_mode_contacts_entries"
+       android:entryValues="@array/zen_mode_contacts_values"/>
+
+   <!-- Repeat callers -->
+   <SwitchPreference
+       android:key="zen_mode_repeat_callers"
+       android:title="@string/zen_mode_repeat_callers" />
 
     <com.android.settingslib.widget.FooterPreference />
 
diff --git a/res/xml/zen_mode_block_settings.xml b/res/xml/zen_mode_block_settings.xml
new file mode 100644 (file)
index 0000000..ce33e97
--- /dev/null
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2018 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<PreferenceScreen
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:key="zen_mode_block_settings_page">
+
+    <!-- sound vibration -->
+    <CheckBoxPreference
+        android:key="zen_effect_sound"
+        android:title="@string/zen_mode_block_effect_sound"
+        android:enabled="false" />
+
+   <PreferenceCategory
+       android:title="@string/zen_mode_block_effects_title"
+       android:key="zen_mode_block_vis_effects">
+
+       <CheckBoxPreference
+           android:key="zen_effect_intent"
+           android:title="@string/zen_mode_block_effect_intent" />
+
+       <CheckBoxPreference
+           android:key="zen_effect_light"
+           android:title="@string/zen_mode_block_effect_light" />
+
+       <CheckBoxPreference
+           android:key="zen_effect_peek"
+           android:title="@string/zen_mode_block_effect_peek" />
+
+       <CheckBoxPreference
+           android:key="zen_effect_status"
+           android:title="@string/zen_mode_block_effect_status" />
+
+       <CheckBoxPreference
+           android:key="zen_effect_badge"
+           android:title="@string/zen_mode_block_effect_badge" />
+
+       <CheckBoxPreference
+           android:key="zen_effect_ambient"
+           android:title="@string/zen_mode_block_effect_ambient" />
+
+       <CheckBoxPreference
+           android:key="zen_effect_list"
+           android:title="@string/zen_mode_block_effect_list" />
+   </PreferenceCategory>
+
+</PreferenceScreen>
index ca8ad10..1f863c2 100644 (file)
     android:key="zen_mode_settings"
     android:title="@string/zen_mode_settings_title">
 
-    <!-- Priority behavior settings -->
+    <!-- What to block (effects) -->
+    <Preference
+        android:key="zen_mode_block_effects_settings"
+        android:title="@string/zen_mode_what_to_block_title"
+        android:fragment="com.android.settings.notification.ZenModeBlockedEffectsSettings" />
+
+    <!-- Behavior settings (exceptions) -->
     <Preference
             android:key="zen_mode_behavior_settings"
             android:title="@string/zen_mode_behavior_settings_title"
index 4baa77b..03853d1 100644 (file)
@@ -100,6 +100,7 @@ public class Settings extends SettingsActivity {
     public static class PrintJobSettingsActivity extends SettingsActivity { /* empty */ }
     public static class ZenModeSettingsActivity extends SettingsActivity { /* empty */ }
     public static class ZenModeBehaviorSettingsActivity extends SettingsActivity { /* empty */ }
+    public static class ZenModeBlockedEffectsSettingsActivity extends SettingsActivity { /* empty */ }
     public static class ZenModeAutomationSettingsActivity extends SettingsActivity { /* empty */ }
     public static class ZenModeScheduleRuleSettingsActivity extends SettingsActivity { /* empty */ }
     public static class ZenModeEventRuleSettingsActivity extends SettingsActivity { /* empty */ }
index e8f103e..8817417 100644 (file)
@@ -88,6 +88,10 @@ public class ZenModeBackend {
         return mZenMode;
     }
 
+    protected boolean isVisualEffectSuppressed(int visualEffect) {
+        return (mPolicy.suppressedVisualEffects & visualEffect) != 0;
+    }
+
     protected boolean isPriorityCategoryEnabled(int categoryType) {
         return (mPolicy.priorityCategories & categoryType) != 0;
     }
@@ -117,8 +121,8 @@ public class ZenModeBackend {
         return SOURCE_NONE;
     }
 
-    protected void saveVisualEffectsPolicy(int category, boolean canBypass) {
-        int suppressedEffects = getNewSuppressedEffects(!canBypass, category);
+    protected void saveVisualEffectsPolicy(int category, boolean suppress) {
+        int suppressedEffects = getNewSuppressedEffects(suppress, category);
         savePolicy(mPolicy.priorityCategories, mPolicy.priorityCallSenders,
                 mPolicy.priorityMessageSenders, suppressedEffects);
     }
index 7b5fa04..31542c3 100644 (file)
@@ -49,8 +49,6 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde
         controllers.add(new ZenModeRepeatCallersPreferenceController(context, lifecycle,
                 context.getResources().getInteger(com.android.internal.R.integer
                 .config_zen_repeat_callers_threshold)));
-        controllers.add(new ZenModeScreenOnPreferenceController(context, lifecycle));
-        controllers.add(new ZenModeScreenOffPreferenceController(context, lifecycle));
         controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle));
         return controllers;
     }
@@ -85,15 +83,6 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde
                 @Override
                 public List<String> getNonIndexableKeys(Context context) {
                     final List<String> keys = super.getNonIndexableKeys(context);
-                    keys.add(ZenModeAlarmsPreferenceController.KEY);
-                    keys.add(ZenModeMediaPreferenceController.KEY);
-                    keys.add(ZenModeEventsPreferenceController.KEY);
-                    keys.add(ZenModeRemindersPreferenceController.KEY);
-                    keys.add(ZenModeMessagesPreferenceController.KEY);
-                    keys.add(ZenModeCallsPreferenceController.KEY);
-                    keys.add(ZenModeRepeatCallersPreferenceController.KEY);
-                    keys.add(ZenModeScreenOnPreferenceController.KEY);
-                    keys.add(ZenModeScreenOffPreferenceController.KEY);
                     return keys;
                 }
 
diff --git a/src/com/android/settings/notification/ZenModeBlockedEffectsPreferenceController.java b/src/com/android/settings/notification/ZenModeBlockedEffectsPreferenceController.java
new file mode 100644 (file)
index 0000000..9500320
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.notification;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+public class ZenModeBlockedEffectsPreferenceController extends
+        AbstractZenModePreferenceController implements PreferenceControllerMixin {
+
+    protected static final String KEY = "zen_mode_block_effects_settings";
+    private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
+
+    public ZenModeBlockedEffectsPreferenceController(Context context, Lifecycle lifecycle) {
+        super(context, KEY, lifecycle);
+        mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return KEY;
+    }
+
+    @Override
+    public boolean isAvailable() {
+        return true;
+    }
+
+    @Override
+    public CharSequence getSummary() {
+        return mSummaryBuilder.getBlockedEffectsSummary(getPolicy());
+    }
+
+}
diff --git a/src/com/android/settings/notification/ZenModeBlockedEffectsSettings.java b/src/com/android/settings/notification/ZenModeBlockedEffectsSettings.java
new file mode 100644 (file)
index 0000000..0cac9cb
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.notification;
+
+import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT;
+import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_BADGE;
+import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT;
+import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS;
+import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST;
+import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK;
+import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BAR;
+
+import android.content.Context;
+import android.provider.SearchIndexableResource;
+import android.support.v7.preference.CheckBoxPreference;
+
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.R;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ZenModeBlockedEffectsSettings extends ZenModeSettingsBase implements Indexable {
+
+    @Override
+    public void onResume() {
+        super.onResume();
+        CheckBoxPreference soundPreference =
+                (CheckBoxPreference) getPreferenceScreen().findPreference("zen_effect_sound");
+        if (soundPreference != null) {
+            soundPreference.setChecked(true);
+        }
+    }
+
+    @Override
+    protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+        return buildPreferenceControllers(context, getLifecycle());
+    }
+
+    private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
+            Lifecycle lifecycle) {
+        List<AbstractPreferenceController> controllers = new ArrayList<>();
+        controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
+                "zen_effect_intent", SUPPRESSED_EFFECT_FULL_SCREEN_INTENT,
+                MetricsEvent.ACTION_ZEN_BLOCK_FULL_SCREEN_INTENTS, null));
+        controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
+                "zen_effect_light", SUPPRESSED_EFFECT_LIGHTS,
+                MetricsEvent.ACTION_ZEN_BLOCK_LIGHT, null));
+        controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
+                "zen_effect_peek", SUPPRESSED_EFFECT_PEEK,
+                MetricsEvent.ACTION_ZEN_BLOCK_PEEK, null));
+        controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
+                "zen_effect_status", SUPPRESSED_EFFECT_STATUS_BAR,
+                MetricsEvent.ACTION_ZEN_BLOCK_STATUS,
+                new int[] {SUPPRESSED_EFFECT_NOTIFICATION_LIST}));
+        controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
+                "zen_effect_badge", SUPPRESSED_EFFECT_BADGE,
+                MetricsEvent.ACTION_ZEN_BLOCK_BADGE, null));
+        controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
+                "zen_effect_ambient", SUPPRESSED_EFFECT_AMBIENT,
+                MetricsEvent.ACTION_ZEN_BLOCK_AMBIENT, null));
+        controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
+                "zen_effect_list", SUPPRESSED_EFFECT_NOTIFICATION_LIST,
+                MetricsEvent.ACTION_ZEN_BLOCK_NOTIFICATION_LIST, null));
+        return controllers;
+    }
+
+    @Override
+    protected int getPreferenceScreenResId() {
+        return R.xml.zen_mode_block_settings;
+    }
+
+    @Override
+    public int getMetricsCategory() {
+        return MetricsEvent.ZEN_WHAT_TO_BLOCK;
+    }
+
+    /**
+     * For Search.
+     */
+    public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+            new BaseSearchIndexProvider() {
+                @Override
+                public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
+                        boolean enabled) {
+                    final ArrayList<SearchIndexableResource> result = new ArrayList<>();
+
+                    final SearchIndexableResource sir = new SearchIndexableResource(context);
+                    sir.xmlResId = R.xml.zen_mode_block_settings;
+                    result.add(sir);
+                    return result;
+                }
+
+                @Override
+                public List<String> getNonIndexableKeys(Context context) {
+                    final List<String> keys = super.getNonIndexableKeys(context);
+                    return keys;
+                }
+
+            @Override
+            public List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+                return buildPreferenceControllers(context, null);
+            }
+        };
+}
diff --git a/src/com/android/settings/notification/ZenModeScreenOffPreferenceController.java b/src/com/android/settings/notification/ZenModeScreenOffPreferenceController.java
deleted file mode 100644 (file)
index 81c9b0d..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.notification;
-
-import android.app.NotificationManager.Policy;
-import android.content.Context;
-import android.support.v14.preference.SwitchPreference;
-import android.support.v7.preference.Preference;
-import android.util.Log;
-
-import com.android.internal.logging.nano.MetricsProto;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-
-public class ZenModeScreenOffPreferenceController extends
-        AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
-
-    protected static final String KEY = "zen_mode_screen_off";
-
-    public ZenModeScreenOffPreferenceController(Context context, Lifecycle lifecycle) {
-        super(context, KEY, lifecycle);
-    }
-
-    @Override
-    public String getPreferenceKey() {
-        return KEY;
-    }
-
-    @Override
-    public boolean isAvailable() {
-        return true;
-    }
-
-    @Override
-    public void updateState(Preference preference) {
-        super.updateState(preference);
-
-        SwitchPreference pref = (SwitchPreference) preference;
-        pref.setChecked(mBackend.isEffectAllowed(Policy.SUPPRESSED_EFFECT_SCREEN_OFF));
-    }
-
-    @Override
-    public boolean onPreferenceChange(Preference preference, Object newValue) {
-        final boolean bypass = (Boolean) newValue;
-        if (ZenModeSettingsBase.DEBUG) {
-            Log.d(TAG, "onPrefChange allowWhenScreenOff=" + bypass);
-        }
-        mMetricsFeatureProvider.action(mContext,
-                MetricsProto.MetricsEvent.ACTION_ZEN_ALLOW_WHEN_SCREEN_OFF, bypass);
-        mBackend.saveVisualEffectsPolicy(Policy.SUPPRESSED_EFFECT_SCREEN_OFF, bypass);
-        return true;
-    }
-}
diff --git a/src/com/android/settings/notification/ZenModeScreenOnPreferenceController.java b/src/com/android/settings/notification/ZenModeScreenOnPreferenceController.java
deleted file mode 100644 (file)
index bab4dd1..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.notification;
-
-import android.app.NotificationManager.Policy;
-import android.content.Context;
-import android.support.v14.preference.SwitchPreference;
-import android.support.v7.preference.Preference;
-import android.util.Log;
-
-import com.android.internal.logging.nano.MetricsProto;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-
-public class ZenModeScreenOnPreferenceController extends
-        AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
-
-    protected static final String KEY = "zen_mode_screen_on";
-
-    public ZenModeScreenOnPreferenceController(Context context, Lifecycle lifecycle) {
-        super(context, KEY, lifecycle);
-    }
-
-    @Override
-    public String getPreferenceKey() {
-        return KEY;
-    }
-
-    @Override
-    public boolean isAvailable() {
-        return true;
-    }
-
-    @Override
-    public void updateState(Preference preference) {
-        super.updateState(preference);
-
-        SwitchPreference pref = (SwitchPreference) preference;
-        pref.setChecked(mBackend.isEffectAllowed(Policy.SUPPRESSED_EFFECT_SCREEN_ON));
-    }
-
-    @Override
-    public boolean onPreferenceChange(Preference preference, Object newValue) {
-        final boolean bypass = (Boolean) newValue;
-        if (ZenModeSettingsBase.DEBUG) Log.d(TAG, "onPrefChange allowWhenScreenOn="
-                + bypass);
-        mMetricsFeatureProvider.action(mContext,
-                MetricsProto.MetricsEvent.ACTION_ZEN_ALLOW_WHEN_SCREEN_ON, bypass);
-        mBackend.saveVisualEffectsPolicy(Policy.SUPPRESSED_EFFECT_SCREEN_ON, bypass);
-        return true;
-    }
-}
index 4e8793b..fdb5cc6 100644 (file)
@@ -63,6 +63,7 @@ public class ZenModeSettings extends ZenModeSettingsBase {
             Lifecycle lifecycle, FragmentManager fragmentManager) {
         List<AbstractPreferenceController> controllers = new ArrayList<>();
         controllers.add(new ZenModeBehaviorPreferenceController(context, lifecycle));
+        controllers.add(new ZenModeBlockedEffectsPreferenceController(context, lifecycle));
         controllers.add(new ZenModeAutomationPreferenceController(context));
         controllers.add(new ZenModeButtonPreferenceController(context, lifecycle, fragmentManager));
         controllers.add(new ZenModeSettingsFooterPreferenceController(context, lifecycle));
@@ -137,6 +138,18 @@ public class ZenModeSettings extends ZenModeSettingsBase {
             }
         }
 
+        String getBlockedEffectsSummary(Policy policy) {
+            if (policy.suppressedVisualEffects == 0) {
+                return mContext.getResources().getString(
+                        R.string.zen_mode_block_effect_summary_sound);
+            } else if (Policy.areAllVisualEffectsSuppressed(policy.suppressedVisualEffects)) {
+                return mContext.getResources().getString(
+                        R.string.zen_mode_block_effect_summary_all);
+            }
+            return mContext.getResources().getString(
+                    R.string.zen_mode_block_effect_summary_some);
+        }
+
         String getAutomaticRulesSummary() {
             final int count = getEnabledAutomaticRulesCount();
             return count == 0 ? mContext.getString(R.string.zen_mode_settings_summary_off)
diff --git a/src/com/android/settings/notification/ZenModeVisEffectPreferenceController.java b/src/com/android/settings/notification/ZenModeVisEffectPreferenceController.java
new file mode 100644 (file)
index 0000000..89b953d
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.notification;
+
+import android.content.Context;
+import android.support.v7.preference.CheckBoxPreference;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+public class ZenModeVisEffectPreferenceController
+        extends AbstractZenModePreferenceController
+        implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
+
+    protected final String mKey;
+    protected final int mEffect;
+    protected final int mMetricsCategory;
+    // if any of these effects are suppressed, this effect must be too
+    protected final int[] mParentSuppressedEffects;
+    private PreferenceScreen mScreen;
+
+    public ZenModeVisEffectPreferenceController(Context context, Lifecycle lifecycle, String key,
+            int visualEffect, int metricsCategory, int[] parentSuppressedEffects) {
+        super(context, key, lifecycle);
+        mKey = key;
+        mEffect = visualEffect;
+        mMetricsCategory = metricsCategory;
+        mParentSuppressedEffects = parentSuppressedEffects;
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return mKey;
+    }
+
+    @Override
+    public boolean isAvailable() {
+        return true;
+    }
+
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        mScreen = screen;
+        super.displayPreference(screen);
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        super.updateState(preference);
+        boolean suppressed = mBackend.isVisualEffectSuppressed(mEffect);
+        boolean parentSuppressed = false;
+        if (mParentSuppressedEffects != null) {
+            for (int parentEffect : mParentSuppressedEffects) {
+                parentSuppressed |= mBackend.isVisualEffectSuppressed(parentEffect);
+            }
+        }
+        if (parentSuppressed) {
+            ((CheckBoxPreference) preference).setChecked(parentSuppressed);
+            onPreferenceChange(preference, parentSuppressed);
+            preference.setEnabled(false);
+        } else {
+            preference.setEnabled(true);
+            ((CheckBoxPreference) preference).setChecked(suppressed);
+        }
+    }
+
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        final boolean suppressEffect = (Boolean) newValue;
+
+        mMetricsFeatureProvider.action(mContext, mMetricsCategory, suppressEffect);
+        mBackend.saveVisualEffectsPolicy(mEffect, suppressEffect);
+        return true;
+    }
+}
index 1798d34..61f5fec 100644 (file)
@@ -74,6 +74,7 @@ import com.android.settings.notification.ConfigureNotificationSettings;
 import com.android.settings.notification.SoundSettings;
 import com.android.settings.notification.ZenModeAutomationSettings;
 import com.android.settings.notification.ZenModeBehaviorSettings;
+import com.android.settings.notification.ZenModeBlockedEffectsSettings;
 import com.android.settings.notification.ZenModeSettings;
 import com.android.settings.print.PrintSettingsFragment;
 import com.android.settings.security.EncryptionAndCredential;
@@ -175,6 +176,7 @@ public class SearchIndexableResourcesImpl implements SearchIndexableResources {
         addIndex(UsbDetailsFragment.class);
         addIndex(WifiDisplaySettings.class);
         addIndex(ZenModeBehaviorSettings.class);
+        addIndex(ZenModeBlockedEffectsSettings.class);
         addIndex(ZenModeAutomationSettings.class);
         addIndex(NightDisplaySettings.class);
         addIndex(SmartBatterySettings.class);
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 The Android Open Source Project
+ * Copyright (C) 2018 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package com.android.settings.notification;
 
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import android.app.NotificationManager;
 import android.content.Context;
-import android.support.v14.preference.SwitchPreference;
 
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -37,22 +37,17 @@ import org.robolectric.shadows.ShadowApplication;
 import org.robolectric.util.ReflectionHelpers;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-public class ZenModeScreenOnPreferenceControllerTest {
+public final class ZenModeBlockedEffectsPreferenceControllerTest {
 
-    private static final boolean MOCK_PRIORITY_SCREEN_ON_SETTING = false;
-
-    private ZenModeScreenOnPreferenceController mController;
-
-    @Mock
-    private ZenModeBackend mBackend;
+    private ZenModeBlockedEffectsPreferenceController mController;
     @Mock
     private NotificationManager mNotificationManager;
     @Mock
-    private SwitchPreference mockPref;
-    @Mock
     private NotificationManager.Policy mPolicy;
 
     private Context mContext;
+    @Mock
+    private ZenModeBackend mBackend;
 
     @Before
     public void setup() {
@@ -63,35 +58,18 @@ public class ZenModeScreenOnPreferenceControllerTest {
         mContext = RuntimeEnvironment.application;
         when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
 
-        mController = new ZenModeScreenOnPreferenceController(mContext, mock(Lifecycle.class));
+        mController = new ZenModeBlockedEffectsPreferenceController(
+                mContext, mock(Lifecycle.class));
         ReflectionHelpers.setField(mController, "mBackend", mBackend);
     }
 
     @Test
-    public void updateState() {
-        final SwitchPreference mockPref = mock(SwitchPreference.class);
-        when(mBackend.isEffectAllowed(NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_ON))
-                .thenReturn(MOCK_PRIORITY_SCREEN_ON_SETTING);
-        mController.updateState(mockPref);
-
-        verify(mockPref).setChecked(MOCK_PRIORITY_SCREEN_ON_SETTING);
-    }
-
-    @Test
-    public void onPreferenceChanged_EnableScreenOn() {
-        boolean allow = true;
-        mController.onPreferenceChange(mockPref, allow);
-
-        verify(mBackend)
-            .saveVisualEffectsPolicy(NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_ON, allow);
+    public void testIsAvailable() {
+        assertTrue(mController.isAvailable());
     }
 
     @Test
-    public void onPreferenceChanged_DisableScreenOn() {
-        boolean allow = false;
-        mController.onPreferenceChange(mockPref, allow);
-
-        verify(mBackend)
-            .saveVisualEffectsPolicy(NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_ON, allow);
+    public void testHasSummary() {
+        assertNotNull(mController.getSummary());
     }
-}
\ No newline at end of file
+}
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeScreenOffPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeScreenOffPreferenceControllerTest.java
deleted file mode 100644 (file)
index 6dd3c17..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.notification;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.app.NotificationManager;
-import android.content.Context;
-import android.support.v14.preference.SwitchPreference;
-
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.shadows.ShadowApplication;
-import org.robolectric.util.ReflectionHelpers;
-
-@RunWith(SettingsRobolectricTestRunner.class)
-public class ZenModeScreenOffPreferenceControllerTest {
-
-    private static final boolean MOCK_PRIORITY_SCREEN_OFF_SETTING = false;
-
-    private ZenModeScreenOffPreferenceController mController;
-
-    @Mock
-    private ZenModeBackend mBackend;
-    @Mock
-    private NotificationManager mNotificationManager;
-    @Mock
-    private SwitchPreference mockPref;
-    @Mock
-    private NotificationManager.Policy mPolicy;
-
-    private Context mContext;
-
-    @Before
-    public void setup() {
-        MockitoAnnotations.initMocks(this);
-        ShadowApplication shadowApplication = ShadowApplication.getInstance();
-        shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
-
-        mContext = shadowApplication.getApplicationContext();
-        when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
-
-        mController = new ZenModeScreenOffPreferenceController(mContext, mock(Lifecycle.class));
-        ReflectionHelpers.setField(mController, "mBackend", mBackend);
-    }
-
-    @Test
-    public void updateState() {
-        final SwitchPreference mockPref = mock(SwitchPreference.class);
-        when(mBackend.isEffectAllowed(NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_OFF))
-                .thenReturn(MOCK_PRIORITY_SCREEN_OFF_SETTING);
-        mController.updateState(mockPref);
-
-        verify(mockPref).setChecked(MOCK_PRIORITY_SCREEN_OFF_SETTING);
-    }
-
-    @Test
-    public void onPreferenceChanged_EnableScreenOff() {
-        boolean allow = true;
-        mController.onPreferenceChange(mockPref, allow);
-
-        verify(mBackend).saveVisualEffectsPolicy(
-                NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_OFF, allow);
-    }
-
-    @Test
-    public void onPreferenceChanged_DisableScreenOff() {
-        boolean allow = false;
-        mController.onPreferenceChange(mockPref, allow);
-
-        verify(mBackend).saveVisualEffectsPolicy(
-                NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_OFF, allow);
-    }
-}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeVisEffectPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeVisEffectPreferenceControllerTest.java
new file mode 100644 (file)
index 0000000..a424491
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.notification;
+
+import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_BADGE;
+import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST;
+import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK;
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationManager;
+import android.content.Context;
+import android.support.v7.preference.CheckBoxPreference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.shadows.ShadowApplication;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class ZenModeVisEffectPreferenceControllerTest {
+    private ZenModeVisEffectPreferenceController mController;
+
+    @Mock
+    private ZenModeBackend mBackend;
+    @Mock
+    private CheckBoxPreference mockPref;
+    private Context mContext;
+    private FakeFeatureFactory mFeatureFactory;
+    @Mock
+    private PreferenceScreen mScreen;
+    @Mock NotificationManager mNotificationManager;
+
+    private static final String PREF_KEY = "main_pref";
+    private static final int PREF_METRICS = 1;
+    private static final int PARENT_EFFECT1 = SUPPRESSED_EFFECT_BADGE;
+    private static final int PARENT_EFFECT2 = SUPPRESSED_EFFECT_NOTIFICATION_LIST;
+
+    @Before
+    public void setup() {
+        MockitoAnnotations.initMocks(this);
+        ShadowApplication shadowApplication = ShadowApplication.getInstance();
+        mContext = shadowApplication.getApplicationContext();
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
+        shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
+        when(mNotificationManager.getNotificationPolicy()).thenReturn(
+                mock(NotificationManager.Policy.class));
+        mController = new ZenModeVisEffectPreferenceController(mContext, mock(Lifecycle.class),
+                PREF_KEY, SUPPRESSED_EFFECT_PEEK, PREF_METRICS, null);
+        ReflectionHelpers.setField(mController, "mBackend", mBackend);
+
+        when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mockPref);
+        mController.displayPreference(mScreen);
+    }
+
+    @Test
+    public void updateState_notChecked() {
+        when(mBackend.isVisualEffectSuppressed(SUPPRESSED_EFFECT_PEEK)).thenReturn(false);
+        mController.updateState(mockPref);
+
+        verify(mockPref).setChecked(false);
+        verify(mockPref).setEnabled(true);
+    }
+
+    @Test
+    public void updateState_checked() {
+        when(mBackend.isVisualEffectSuppressed(SUPPRESSED_EFFECT_PEEK)).thenReturn(true);
+        mController.updateState(mockPref);
+
+        verify(mockPref).setChecked(true);
+        verify(mockPref).setEnabled(true);
+    }
+
+    @Test
+    public void updateState_checkedFalse_parentChecked() {
+        mController = new ZenModeVisEffectPreferenceController(mContext, mock(Lifecycle.class),
+                PREF_KEY, SUPPRESSED_EFFECT_PEEK, PREF_METRICS,
+                new int[] {PARENT_EFFECT1, PARENT_EFFECT2});
+        ReflectionHelpers.setField(mController, "mBackend", mBackend);
+        when(mBackend.isVisualEffectSuppressed(SUPPRESSED_EFFECT_PEEK)).thenReturn(false);
+        when(mBackend.isVisualEffectSuppressed(PARENT_EFFECT1)).thenReturn(false);
+        when(mBackend.isVisualEffectSuppressed(PARENT_EFFECT2)).thenReturn(true);
+        mController.updateState(mockPref);
+
+        verify(mockPref).setChecked(true);
+        verify(mockPref).setEnabled(false);
+        verify(mBackend, times(1)).saveVisualEffectsPolicy(SUPPRESSED_EFFECT_PEEK, true);
+    }
+
+    @Test
+    public void updateState_checkedFalse_parentNotChecked() {
+        mController = new ZenModeVisEffectPreferenceController(mContext, mock(Lifecycle.class),
+                PREF_KEY, SUPPRESSED_EFFECT_PEEK, PREF_METRICS,
+                new int[] {PARENT_EFFECT1, PARENT_EFFECT2});
+        ReflectionHelpers.setField(mController, "mBackend", mBackend);
+        when(mBackend.isVisualEffectSuppressed(SUPPRESSED_EFFECT_PEEK)).thenReturn(false);
+        when(mBackend.isVisualEffectSuppressed(PARENT_EFFECT1)).thenReturn(false);
+        when(mBackend.isVisualEffectSuppressed(PARENT_EFFECT2)).thenReturn(false);
+        mController.updateState(mockPref);
+
+        verify(mockPref).setChecked(false);
+        verify(mockPref).setEnabled(true);
+        verify(mBackend, never()).saveVisualEffectsPolicy(SUPPRESSED_EFFECT_PEEK, true);
+    }
+
+    @Test
+    public void onPreferenceChanged_checkedFalse() {
+        mController.onPreferenceChange(mockPref, false);
+
+        verify(mBackend).saveVisualEffectsPolicy(SUPPRESSED_EFFECT_PEEK, false);
+        verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
+                eq(PREF_METRICS),
+                eq(false));
+    }
+
+    @Test
+    public void onPreferenceChanged_checkedTrue() {
+        mController.onPreferenceChange(mockPref, true);
+        verify(mBackend).saveVisualEffectsPolicy(SUPPRESSED_EFFECT_PEEK, true);
+        verify(mFeatureFactory.metricsFeatureProvider).action(nullable(Context.class),
+                eq(PREF_METRICS),
+                eq(true));
+    }
+}