Apply DND to visual effects.
Bug: 25423508
Change-Id: I00ace3da8a7fea089f4d0fc3f6161452285abb8e
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 774cb45..df00ad1 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -729,6 +729,26 @@
android:value="true" />
</activity>
+ <activity android:name="Settings$ZenModeVisualInterruptionSettingsActivity"
+ android:label="@string/zen_mode_visual_interruptions_settings_title"
+ android:icon="@drawable/ic_settings_notifications"
+ android:exported="true"
+ android:taskAffinity="">
+ <intent-filter android:priority="1">
+ <action android:name="android.settings.ZEN_MODE_PRIORITY_SETTINGS" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="com.android.settings.SHORTCUT" />
+ </intent-filter>
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.notification.ZenModeVisualInterruptionSettings" />
+ <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+ android:value="true" />
+ </activity>
+
<activity android:name="Settings$ZenModePrioritySettingsActivity"
android:label="@string/zen_mode_priority_settings_title"
android:icon="@drawable/ic_settings_notifications"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 6a6a03e..bba72c5 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5964,6 +5964,9 @@
<!-- Sound & notification > Sound section: Zen mode combined summary + condition line [CHAR LIMIT=60] -->
<string name="zen_mode_summary_combination"><xliff:g id="mode" example="Priority only">%1$s</xliff:g>: <xliff:g id="exit condition" example="Until you turn this off">%2$s</xliff:g></string>
+ <!-- Sound & notification > Do not disturb section: Title for the Visual interruptions option and associated settings page. [CHAR LIMIT=30] -->
+ <string name="zen_mode_visual_interruptions_settings_title">Visual interruptions</string>
+
<!-- Sound & notification > Sound section: Title for the option defining the phone ringtone. [CHAR LIMIT=30] -->
<string name="ringtone_title">Phone ringtone</string>
@@ -6306,6 +6309,18 @@
<!-- [CHAR LIMIT=NONE] Zen mode summary spoken when changing mode by voice: Turn on all notifications. -->
<string name="zen_mode_summary_always">Change to always interrupt</string>
+ <!-- [CHAR LIMIT=20] Zen mode settings: No screen interruptions option -->
+ <string name="zen_mode_peek">No screen interruptions</string>
+
+ <!-- [CHAR LIMIT=20] Zen mode settings: No screen interruptions summary -->
+ <string name="zen_mode_peek_summary">Prevent notifications silenced by Do Not Disturb from peeking or appearing on the current screen</string>
+
+ <!-- [CHAR LIMIT=20] Zen mode settings: No notification light option -->
+ <string name="zen_mode_lights">No notification light</string>
+
+ <!-- [CHAR LIMIT=20] Zen mode settings: No notification light summary -->
+ <string name="zen_mode_lights_summary">Prevent notifications silenced by Do Not Disturb from causing the light to pulse</string>
+
<!-- [CHAR LIMIT=20] Notifications settings: Apps section header -->
<string name="notification_settings_apps_title">App notifications</string>
diff --git a/res/xml/zen_mode_settings.xml b/res/xml/zen_mode_settings.xml
index 267727f..d8ad10d 100644
--- a/res/xml/zen_mode_settings.xml
+++ b/res/xml/zen_mode_settings.xml
@@ -25,9 +25,15 @@
android:title="@string/zen_mode_priority_settings_title"
android:fragment="com.android.settings.notification.ZenModePrioritySettings" />
- <!-- Downtime -->
+ <!-- Automated rules -->
<PreferenceScreen
android:key="automation_settings"
android:title="@string/zen_mode_automation_settings_title"
android:fragment="com.android.settings.notification.ZenModeAutomationSettings" />
+
+ <!-- Visual interruptions -->
+ <PreferenceScreen
+ android:key="visual_interruptions_settings"
+ android:title="@string/zen_mode_visual_interruptions_settings_title"
+ android:fragment="com.android.settings.notification.ZenModeVisualInterruptionSettings" />
</PreferenceScreen>
diff --git a/res/xml/zen_mode_visual_interruptions_settings.xml b/res/xml/zen_mode_visual_interruptions_settings.xml
new file mode 100644
index 0000000..8131650
--- /dev/null
+++ b/res/xml/zen_mode_visual_interruptions_settings.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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"
+ xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
+ android:title="@string/zen_mode_visual_interruptions_settings_title" >
+
+ <SwitchPreference android:key="peek"
+ android:title="@string/zen_mode_peek"
+ android:summary="@string/zen_mode_peek_summary"
+ android:persistent="false" />
+
+ <SwitchPreference android:key="lights"
+ android:title="@string/zen_mode_lights"
+ android:summary="@string/zen_mode_lights_summary"
+ android:persistent="false" />
+
+</PreferenceScreen>
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index fdc55d7..46d24ae 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -104,6 +104,7 @@
public static class ZenModeScheduleRuleSettingsActivity extends SettingsActivity { /* empty */ }
public static class ZenModeEventRuleSettingsActivity extends SettingsActivity { /* empty */ }
public static class ZenModeExternalRuleSettingsActivity extends SettingsActivity { /* empty */ }
+ public static class ZenModeVisualInterruptionSettingsActivity extends SettingsActivity { /* empty */}
public static class NotificationSettingsActivity extends SettingsActivity { /* empty */ }
public static class NotificationAppListActivity extends SettingsActivity { /* empty */ }
public static class AppNotificationSettingsActivity extends SettingsActivity { /* empty */ }
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 4eaabe9..b0a1120 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -92,6 +92,7 @@
import com.android.settings.notification.ZenModePrioritySettings;
import com.android.settings.notification.ZenModeScheduleRuleSettings;
import com.android.settings.notification.ZenModeSettings;
+import com.android.settings.notification.ZenModeVisualInterruptionSettings;
import com.android.settings.print.PrintJobSettingsFragment;
import com.android.settings.print.PrintSettingsFragment;
import com.android.settings.search.DynamicIndexableContentMonitor;
@@ -296,6 +297,7 @@
ZenModeAutomationSettings.class.getName(),
ZenModeScheduleRuleSettings.class.getName(),
ZenModeEventRuleSettings.class.getName(),
+ ZenModeVisualInterruptionSettings.class.getName(),
ProcessStatsUi.class.getName(),
PowerUsageDetail.class.getName(),
ProcessStatsSummary.class.getName(),
diff --git a/src/com/android/settings/notification/ZenModePrioritySettings.java b/src/com/android/settings/notification/ZenModePrioritySettings.java
index 6168e57..e3413a7 100644
--- a/src/com/android/settings/notification/ZenModePrioritySettings.java
+++ b/src/com/android/settings/notification/ZenModePrioritySettings.java
@@ -66,7 +66,8 @@
MetricsLogger.action(mContext, MetricsLogger.ACTION_ZEN_ALLOW_REMINDERS, val);
if (DEBUG) Log.d(TAG, "onPrefChange allowReminders=" + val);
savePolicy(getNewPriorityCategories(val, Policy.PRIORITY_CATEGORY_REMINDERS),
- mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders);
+ mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders,
+ mPolicy.suppressedVisualEffects);
return true;
}
});
@@ -80,7 +81,8 @@
MetricsLogger.action(mContext, MetricsLogger.ACTION_ZEN_ALLOW_EVENTS, val);
if (DEBUG) Log.d(TAG, "onPrefChange allowEvents=" + val);
savePolicy(getNewPriorityCategories(val, Policy.PRIORITY_CATEGORY_EVENTS),
- mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders);
+ mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders,
+ mPolicy.suppressedVisualEffects);
return true;
}
});
@@ -100,7 +102,8 @@
+ " allowMessagesFrom=" + ZenModeConfig.sourceToString(allowMessagesFrom));
savePolicy(
getNewPriorityCategories(allowMessages, Policy.PRIORITY_CATEGORY_MESSAGES),
- mPolicy.priorityCallSenders, allowMessagesFrom);
+ mPolicy.priorityCallSenders, allowMessagesFrom,
+ mPolicy.suppressedVisualEffects);
return true;
}
});
@@ -118,7 +121,8 @@
if (DEBUG) Log.d(TAG, "onPrefChange allowCalls=" + allowCalls
+ " allowCallsFrom=" + ZenModeConfig.sourceToString(allowCallsFrom));
savePolicy(getNewPriorityCategories(allowCalls, Policy.PRIORITY_CATEGORY_CALLS),
- allowCallsFrom, mPolicy.priorityMessageSenders);
+ allowCallsFrom, mPolicy.priorityMessageSenders,
+ mPolicy.suppressedVisualEffects);
return true;
}
});
@@ -137,7 +141,7 @@
int priorityCategories = getNewPriorityCategories(val,
NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS);
savePolicy(priorityCategories, mPolicy.priorityCallSenders,
- mPolicy.priorityMessageSenders);
+ mPolicy.priorityMessageSenders, mPolicy.suppressedVisualEffects);
return true;
}
});
@@ -210,8 +214,9 @@
}
private void savePolicy(int priorityCategories, int priorityCallSenders,
- int priorityMessageSenders) {
- mPolicy = new Policy(priorityCategories, priorityCallSenders, priorityMessageSenders);
+ int priorityMessageSenders, int suppressedVisualEffects) {
+ mPolicy = new Policy(priorityCategories, priorityCallSenders, priorityMessageSenders,
+ suppressedVisualEffects);
NotificationManager.from(mContext).setNotificationPolicy(mPolicy);
}
diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java
index 3e32abc..39ec08c 100644
--- a/src/com/android/settings/notification/ZenModeSettings.java
+++ b/src/com/android/settings/notification/ZenModeSettings.java
@@ -37,6 +37,7 @@
public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
private static final String KEY_PRIORITY_SETTINGS = "priority_settings";
private static final String KEY_AUTOMATION_SETTINGS = "automation_settings";
+ private static final String KEY_VISUAL_INTERRUPTIONS_SETTINGS = "visual_interruptions_settings";
private Preference mPrioritySettings;
@@ -116,10 +117,12 @@
return s;
}
- private static SparseArray<String> allKeyTitles(Context context) {
+ private static SparseArray<String> allKeyTitles() {
final SparseArray<String> rt = new SparseArray<String>();
rt.put(R.string.zen_mode_priority_settings_title, KEY_PRIORITY_SETTINGS);
rt.put(R.string.zen_mode_automation_settings_title, KEY_AUTOMATION_SETTINGS);
+ rt.put(R.string.zen_mode_visual_interruptions_settings_title,
+ KEY_VISUAL_INTERRUPTIONS_SETTINGS);
return rt;
}
@@ -134,7 +137,7 @@
@Override
public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
- final SparseArray<String> keyTitles = allKeyTitles(context);
+ final SparseArray<String> keyTitles = allKeyTitles();
final int N = keyTitles.size();
final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>(N);
final Resources res = context.getResources();
diff --git a/src/com/android/settings/notification/ZenModeVisualInterruptionSettings.java b/src/com/android/settings/notification/ZenModeVisualInterruptionSettings.java
new file mode 100644
index 0000000..ba1b378
--- /dev/null
+++ b/src/com/android/settings/notification/ZenModeVisualInterruptionSettings.java
@@ -0,0 +1,126 @@
+/**
+ * Copyright (C) 2015 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;
+import android.app.NotificationManager.Policy;
+import android.content.Context;
+import android.os.Bundle;
+import android.provider.SearchIndexableResource;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.util.Log;
+
+import com.android.internal.logging.MetricsLogger;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
+import com.android.settings.R;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class ZenModeVisualInterruptionSettings extends ZenModeSettingsBase {
+
+ private static final String KEY_PEEK = "peek";
+ private static final String KEY_LIGHTS = "lights";
+
+ private SwitchPreference mPeek;
+ private SwitchPreference mLights;
+
+ private boolean mDisableListeners;
+ private NotificationManager.Policy mPolicy;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.zen_mode_visual_interruptions_settings);
+ final PreferenceScreen root = getPreferenceScreen();
+
+ mPolicy = NotificationManager.from(mContext).getNotificationPolicy();
+
+ mPeek = (SwitchPreference) root.findPreference(KEY_PEEK);
+ mPeek.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (mDisableListeners) return true;
+ final boolean val = (Boolean) newValue;
+ MetricsLogger.action(mContext, MetricsLogger.ACTION_ZEN_ALLOW_PEEK, val);
+ if (DEBUG) Log.d(TAG, "onPrefChange suppressPeek=" + val);
+ savePolicy(getNewSuppressedEffects(val, Policy.SUPPRESSED_EFFECT_PEEK));
+ return true;
+ }
+ });
+
+ mLights = (SwitchPreference) root.findPreference(KEY_LIGHTS);
+ mLights.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (mDisableListeners) return true;
+ final boolean val = (Boolean) newValue;
+ MetricsLogger.action(mContext, MetricsLogger.ACTION_ZEN_ALLOW_LIGHTS, val);
+ if (DEBUG) Log.d(TAG, "onPrefChange suppressLights=" + val);
+ savePolicy(getNewSuppressedEffects(val, Policy.SUPPRESSED_EFFECT_LIGHTS));
+ return true;
+ }
+ });
+ }
+
+ @Override
+ protected int getMetricsCategory() {
+ return MetricsLogger.NOTIFICATION_ZEN_MODE_VISUAL_INTERRUPTIONS;
+ }
+
+ @Override
+ protected void onZenModeChanged() {
+ // Don't care
+ }
+
+ @Override
+ protected void onZenModeConfigChanged() {
+ mPolicy = NotificationManager.from(mContext).getNotificationPolicy();
+ updateControls();
+ }
+
+ private void updateControls() {
+ mDisableListeners = true;
+ mPeek.setChecked(isEffectSuppressed(Policy.SUPPRESSED_EFFECT_PEEK));
+ mLights.setChecked(isEffectSuppressed(Policy.SUPPRESSED_EFFECT_LIGHTS));
+ mDisableListeners = false;
+ }
+
+ private boolean isEffectSuppressed(int effect) {
+ return (mPolicy.suppressedVisualEffects & effect) != 0;
+ }
+
+ private int getNewSuppressedEffects(boolean suppress, int effectType) {
+ int effects = mPolicy.suppressedVisualEffects;
+ if (suppress) {
+ effects |= effectType;
+ } else {
+ effects &= ~effectType;
+ }
+ return effects;
+ }
+
+ private void savePolicy(int suppressedVisualEffects) {
+ mPolicy = new Policy(mPolicy.priorityCategories,
+ mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders,
+ suppressedVisualEffects);
+ NotificationManager.from(mContext).setNotificationPolicy(mPolicy);
+ }
+}
diff --git a/src/com/android/settings/search/Ranking.java b/src/com/android/settings/search/Ranking.java
index 18ae1ec..1f464df 100644
--- a/src/com/android/settings/search/Ranking.java
+++ b/src/com/android/settings/search/Ranking.java
@@ -47,6 +47,7 @@
import com.android.settings.notification.ZenModeAutomationSettings;
import com.android.settings.notification.ZenModePrioritySettings;
import com.android.settings.notification.ZenModeSettings;
+import com.android.settings.notification.ZenModeVisualInterruptionSettings;
import com.android.settings.print.PrintSettingsFragment;
import com.android.settings.sim.SimSettings;
import com.android.settings.users.UserSettings;
@@ -129,6 +130,7 @@
sRankMap.put(ZenModeSettings.class.getName(), RANK_NOTIFICATIONS);
sRankMap.put(ZenModePrioritySettings.class.getName(), RANK_NOTIFICATIONS);
sRankMap.put(ZenModeAutomationSettings.class.getName(), RANK_NOTIFICATIONS);
+ sRankMap.put(ZenModeVisualInterruptionSettings.class.getName(), RANK_NOTIFICATIONS);
// Storage
sRankMap.put(StorageSettings.class.getName(), RANK_STORAGE);
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index 6b4a947..7e669e0 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -48,6 +48,7 @@
import com.android.settings.notification.OtherSoundSettings;
import com.android.settings.notification.ZenModePrioritySettings;
import com.android.settings.notification.ZenModeSettings;
+import com.android.settings.notification.ZenModeVisualInterruptionSettings;
import com.android.settings.print.PrintSettingsFragment;
import com.android.settings.sim.SimSettings;
import com.android.settings.users.UserSettings;
@@ -310,6 +311,14 @@
R.xml.wifi_calling_settings,
WifiCallingSettings.class.getName(),
R.drawable.ic_settings_wireless));
+
+ sResMap.put(ZenModeVisualInterruptionSettings.class.getName(),
+ new SearchIndexableResource(
+ Ranking.getRankForClassName(
+ ZenModeVisualInterruptionSettings.class.getName()),
+ R.xml.zen_mode_visual_interruptions_settings,
+ ZenModeVisualInterruptionSettings.class.getName(),
+ R.drawable.ic_settings_notifications));
}
private SearchIndexableResources() {