Show new visual effects options in dnd settings
Bug: 74075050
Test: make -j20 RunSettingsRoboTests
Change-Id: Ia629007d1c80b657aaf756d0f6d2edfd89a7f6b4
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 4baa77b..03853d1 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -100,6 +100,7 @@
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 */ }
diff --git a/src/com/android/settings/notification/ZenModeBackend.java b/src/com/android/settings/notification/ZenModeBackend.java
index e8f103e..8817417 100644
--- a/src/com/android/settings/notification/ZenModeBackend.java
+++ b/src/com/android/settings/notification/ZenModeBackend.java
@@ -88,6 +88,10 @@
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 @@
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);
}
diff --git a/src/com/android/settings/notification/ZenModeBehaviorSettings.java b/src/com/android/settings/notification/ZenModeBehaviorSettings.java
index 7b5fa04..31542c3 100644
--- a/src/com/android/settings/notification/ZenModeBehaviorSettings.java
+++ b/src/com/android/settings/notification/ZenModeBehaviorSettings.java
@@ -49,8 +49,6 @@
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 @@
@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
index 0000000..9500320
--- /dev/null
+++ b/src/com/android/settings/notification/ZenModeBlockedEffectsPreferenceController.java
@@ -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
index 0000000..0cac9cb
--- /dev/null
+++ b/src/com/android/settings/notification/ZenModeBlockedEffectsSettings.java
@@ -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
index 81c9b0d..0000000
--- a/src/com/android/settings/notification/ZenModeScreenOffPreferenceController.java
+++ /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
index bab4dd1..0000000
--- a/src/com/android/settings/notification/ZenModeScreenOnPreferenceController.java
+++ /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;
- }
-}
diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java
index 4e8793b..fdb5cc6 100644
--- a/src/com/android/settings/notification/ZenModeSettings.java
+++ b/src/com/android/settings/notification/ZenModeSettings.java
@@ -63,6 +63,7 @@
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 @@
}
}
+ 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
index 0000000..89b953d
--- /dev/null
+++ b/src/com/android/settings/notification/ZenModeVisEffectPreferenceController.java
@@ -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;
+ }
+}
diff --git a/src/com/android/settings/search/SearchIndexableResourcesImpl.java b/src/com/android/settings/search/SearchIndexableResourcesImpl.java
index 1798d34..61f5fec 100644
--- a/src/com/android/settings/search/SearchIndexableResourcesImpl.java
+++ b/src/com/android/settings/search/SearchIndexableResourcesImpl.java
@@ -74,6 +74,7 @@
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 @@
addIndex(UsbDetailsFragment.class);
addIndex(WifiDisplaySettings.class);
addIndex(ZenModeBehaviorSettings.class);
+ addIndex(ZenModeBlockedEffectsSettings.class);
addIndex(ZenModeAutomationSettings.class);
addIndex(NightDisplaySettings.class);
addIndex(SmartBatterySettings.class);