Replaced dnd priority setting page w/ behavior.
Bug: 63077372
Test: manual, make -j20 RunSettingsRoboTests
Change-Id: I79fd431da0cbed1407f0dab38e64f0bdb3ff3feb
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 44555db..746ada7 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -754,17 +754,17 @@
android:value="true" />
</activity>
- <activity android:name="Settings$ZenModePrioritySettingsActivity"
- android:label="@string/zen_mode_priority_settings_title"
+ <activity android:name="Settings$ZenModeBehaviorSettingsActivity"
+ android:label="@string/zen_mode_behavior_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" />
+ <action android:name="android.settings.ZEN_MODE_BEHAVIOR_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.notification.ZenModePrioritySettings" />
+ android:value="com.android.settings.notification.ZenModeBehaviorSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8f6cc9c..7c2eb55 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6693,10 +6693,25 @@
</plurals>
<!-- Sound: Title for the Do not Disturb option and associated settings page. [CHAR LIMIT=50]-->
- <string name="zen_mode_settings_title">Do Not Disturb preferences</string>
+ <string name="zen_mode_settings_title">Do Not Disturb</string>
- <!-- Do not disturb: Title for the Priority interruptions option and associated settings page. [CHAR LIMIT=30] -->
- <string name="zen_mode_priority_settings_title">Priority only allows</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: Instructions indicating what types of sounds can bypass DND. [CHAR LIMIT=30] -->
+ <string name="zen_mode_behavior_allow_title">Allow sounds and vibrations from</string>
+
+ <!-- Do not disturb: Subtitle for DND behavior indicating no sound will get past DND. [CHAR LIMIT=30] -->
+ <string name="zen_mode_behavior_no_sound">No sound</string>
+
+ <!-- Do not disturb: Subtitle for DND behavior indicating no sound will get past DND due to user and/or API-invoked Total Silence mode. [CHAR LIMIT=30] -->
+ <string name="zen_mode_behavior_total_silence">No sound (Total Silence)</string>
+
+ <!-- Do not disturb: Used before specifying which sounds can bypass DND (ie: No sound except alarms and reminders). [CHAR LIMIT=30] -->
+ <string name="zen_mode_behavior_no_sound_except">No sound except <xliff:g id="categories" example="alarms, media and system">%1$s</xliff:g></string>
+
+ <!-- Do not disturb: Specifies sounds that can bypass DND in user and/or API-invoked Alarms Only mode. [CHAR LIMIT=30] -->
+ <string name="zen_mode_behavior_alarms_only">No sound except alarms, media and system (Alarms only)</string>
<!-- Do not disturb: Title for the zen mode automation listing. [CHAR LIMIT=30] -->
<string name="zen_mode_automation_settings_title">Automatic rules</string>
@@ -7231,8 +7246,8 @@
<!-- [CHAR LIMIT=50] Zen mode settings: Alarms option -->
<string name="zen_mode_alarms">Alarms</string>
- <!-- [CHAR LIMIT=50] Zen mode settings: Alarms option summary -->
- <string name="zen_mode_alarms_summary">Alarms are always a priority and make sound</string>
+ <!-- [CHAR LIMIT=50] Zen mode settings: Media and system sounds option -->
+ <string name="zen_mode_media_system_other">Media and system sounds</string>
<!-- [CHAR LIMIT=50] Zen mode settings: Reminders option -->
<string name="zen_mode_reminders">Reminders</string>
@@ -7250,7 +7265,7 @@
<string name="zen_mode_repeat_callers">Repeat callers</string>
<!-- [CHAR LIMIT=200] Zen mode settings: Repeat callers option summary -->
- <string name="zen_mode_repeat_callers_summary">If the same person calls a second time within a <xliff:g id="minutes">%d</xliff:g> minute period, allow it</string>
+ <string name="zen_mode_repeat_callers_summary">If the same person calls a second time within a <xliff:g id="minutes">%d</xliff:g> minute period</string>
<!-- [CHAR LIMIT=20] Zen mode settings: When option -->
<string name="zen_mode_when">Automatically turn on</string>
diff --git a/res/xml/zen_mode_behavior_settings.xml b/res/xml/zen_mode_behavior_settings.xml
new file mode 100644
index 0000000..8281f65
--- /dev/null
+++ b/res/xml/zen_mode_behavior_settings.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ android:key="zen_mode_behavior_settings_page"
+ android:title="@string/zen_mode_behavior_settings_title" >
+
+ <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_other"/>
+
+ <!-- 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 -->
+ <DropDownPreference
+ android:key="zen_mode_messages"
+ android:title="@string/zen_mode_messages"
+ android:summary="%s" />
+
+ <!-- Calls -->
+ <DropDownPreference
+ android:key="zen_mode_calls"
+ android:title="@string/zen_mode_calls"
+ android:summary="%s" />
+
+ <!-- Repeat callers -->
+ <SwitchPreference
+ android:key="zen_mode_repeat_callers"
+ android:title="@string/zen_mode_repeat_callers"/>
+
+ </PreferenceCategory>
+
+</PreferenceScreen>
diff --git a/res/xml/zen_mode_priority_settings.xml b/res/xml/zen_mode_priority_settings.xml
deleted file mode 100644
index e4f8f5e..0000000
--- a/res/xml/zen_mode_priority_settings.xml
+++ /dev/null
@@ -1,57 +0,0 @@
-<?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"
- android:key="zen_mode_priority_settings"
- android:title="@string/zen_mode_priority_settings_title" >
-
- <!-- Reminders -->
- <SwitchPreference
- android:key="reminders"
- android:title="@string/zen_mode_reminders"/>
-
- <!-- Events -->
- <SwitchPreference
- android:key="events"
- android:title="@string/zen_mode_events"/>
-
- <!-- Alarms -->
- <SwitchPreference
- android:key="alarms"
- android:title="@string/zen_mode_alarms"
- android:summary="@string/zen_mode_alarms_summary"
- android:enabled="false"
- android:defaultValue="true"/>
-
- <!-- Messages -->
- <DropDownPreference
- android:key="messages"
- android:title="@string/zen_mode_messages"
- android:summary="%s" />
-
- <!-- Calls -->
- <DropDownPreference
- android:key="calls"
- android:title="@string/zen_mode_calls"
- android:summary="%s" />
-
- <!-- Repeat callers -->
- <SwitchPreference
- android:key="repeat_callers"
- android:title="@string/zen_mode_repeat_callers"/>
-
-</PreferenceScreen>
diff --git a/res/xml/zen_mode_settings.xml b/res/xml/zen_mode_settings.xml
index 5fc72aa..b8ee41d 100644
--- a/res/xml/zen_mode_settings.xml
+++ b/res/xml/zen_mode_settings.xml
@@ -19,20 +19,19 @@
android:key="zen_mode_settings"
android:title="@string/zen_mode_settings_title" >
- <!-- Priority only allows -->
<Preference
- android:key="priority_settings"
- android:title="@string/zen_mode_priority_settings_title"
- android:fragment="com.android.settings.notification.ZenModePrioritySettings" />
+ android:key="zen_mode_behavior_settings"
+ android:title="@string/zen_mode_behavior_settings_title"
+ android:fragment="com.android.settings.notification.ZenModeBehaviorSettings" />
<!-- Visual interruptions -->
<Preference
- android:key="visual_interruptions_settings"
+ android:key="zen_mode_visual_interruptions_settings"
android:title="@string/zen_mode_visual_interruptions_settings_title"
android:fragment="com.android.settings.notification.ZenModeVisualInterruptionSettings" />
<!-- Automatic rules -->
<PreferenceCategory
- android:key="automatic_rules"
+ android:key="zen_mode_automatic_rules"
android:title="@string/zen_mode_automation_settings_title" />
</PreferenceScreen>
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index cd479a5..8d4c71d 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -123,7 +123,7 @@
public static class PrintSettingsActivity extends SettingsActivity { /* empty */ }
public static class PrintJobSettingsActivity extends SettingsActivity { /* empty */ }
public static class ZenModeSettingsActivity extends SettingsActivity { /* empty */ }
- public static class ZenModePrioritySettingsActivity extends SettingsActivity { /* empty */ }
+ public static class ZenModeBehaviorSettingsActivity 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/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index 8ee61c6..f2d59d2 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -40,8 +40,8 @@
import com.android.settings.accounts.ChooseAccountActivity;
import com.android.settings.accounts.ManagedProfileSettings;
import com.android.settings.accounts.UserAndAccountDashboardFragment;
-import com.android.settings.applications.DefaultAppSettings;
import com.android.settings.applications.AppAndNotificationDashboardFragment;
+import com.android.settings.applications.DefaultAppSettings;
import com.android.settings.applications.DrawOverlayDetails;
import com.android.settings.applications.ExternalSourcesDetails;
import com.android.settings.applications.InstalledAppDetails;
@@ -100,15 +100,15 @@
import com.android.settings.nfc.AndroidBeam;
import com.android.settings.nfc.PaymentSettings;
import com.android.settings.notification.AppNotificationSettings;
-import com.android.settings.notification.ChannelNotificationSettings;
import com.android.settings.notification.ChannelGroupNotificationSettings;
+import com.android.settings.notification.ChannelNotificationSettings;
import com.android.settings.notification.ConfigureNotificationSettings;
import com.android.settings.notification.NotificationAccessSettings;
import com.android.settings.notification.NotificationStation;
import com.android.settings.notification.SoundSettings;
import com.android.settings.notification.ZenAccessSettings;
+import com.android.settings.notification.ZenModeBehaviorSettings;
import com.android.settings.notification.ZenModeEventRuleSettings;
-import com.android.settings.notification.ZenModePrioritySettings;
import com.android.settings.notification.ZenModeScheduleRuleSettings;
import com.android.settings.notification.ZenModeSettings;
import com.android.settings.notification.ZenModeVisualInterruptionSettings;
@@ -216,7 +216,7 @@
ApnSettings.class.getName(),
ApnEditor.class.getName(),
WifiCallingSettings.class.getName(),
- ZenModePrioritySettings.class.getName(),
+ ZenModeBehaviorSettings.class.getName(),
ZenModeScheduleRuleSettings.class.getName(),
ZenModeEventRuleSettings.class.getName(),
ZenModeVisualInterruptionSettings.class.getName(),
diff --git a/src/com/android/settings/notification/ZenModePrioritySettings.java b/src/com/android/settings/notification/ZenModeBehaviorSettings.java
similarity index 70%
rename from src/com/android/settings/notification/ZenModePrioritySettings.java
rename to src/com/android/settings/notification/ZenModeBehaviorSettings.java
index b164407..1b5e69f 100644
--- a/src/com/android/settings/notification/ZenModePrioritySettings.java
+++ b/src/com/android/settings/notification/ZenModeBehaviorSettings.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 The Android Open Source Project
+ * 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.
@@ -19,6 +19,7 @@
import android.app.NotificationManager;
import android.app.NotificationManager.Policy;
import android.os.Bundle;
+import android.provider.Settings;
import android.service.notification.ZenModeConfig;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.DropDownPreference;
@@ -29,14 +30,15 @@
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
-import com.android.settings.search.Indexable;
-public class ZenModePrioritySettings extends ZenModeSettingsBase {
- private static final String KEY_REMINDERS = "reminders";
- private static final String KEY_EVENTS = "events";
- private static final String KEY_MESSAGES = "messages";
- private static final String KEY_CALLS = "calls";
- private static final String KEY_REPEAT_CALLERS = "repeat_callers";
+public class ZenModeBehaviorSettings extends ZenModeSettingsBase {
+ private static final String KEY_ALARMS = "zen_mode_alarms";
+ private static final String KEY_MEDIA = "zen_mode_media";
+ private static final String KEY_REMINDERS = "zen_mode_reminders";
+ private static final String KEY_EVENTS = "zen_mode_events";
+ private static final String KEY_MESSAGES = "zen_mode_messages";
+ private static final String KEY_CALLS = "zen_mode_calls";
+ private static final String KEY_REPEAT_CALLERS = "zen_mode_repeat_callers";
private static final int SOURCE_NONE = -1;
@@ -46,13 +48,15 @@
private DropDownPreference mMessages;
private DropDownPreference mCalls;
private SwitchPreference mRepeatCallers;
+ private SwitchPreference mAlarms;
+ private SwitchPreference mMediaSystemOther;
private Policy mPolicy;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.zen_mode_priority_settings);
+ addPreferencesFromResource(R.xml.zen_mode_behavior_settings);
final PreferenceScreen root = getPreferenceScreen();
mPolicy = NotificationManager.from(mContext).getNotificationPolicy();
@@ -141,19 +145,50 @@
val);
if (DEBUG) Log.d(TAG, "onPrefChange allowRepeatCallers=" + val);
int priorityCategories = getNewPriorityCategories(val,
- NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS);
+ Policy.PRIORITY_CATEGORY_REPEAT_CALLERS);
savePolicy(priorityCategories, mPolicy.priorityCallSenders,
mPolicy.priorityMessageSenders, mPolicy.suppressedVisualEffects);
return true;
}
});
+ mAlarms = (SwitchPreference) root.findPreference(KEY_ALARMS);
+ mAlarms.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (mDisableListeners) return true;
+ final boolean val = (Boolean) newValue;
+ mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_ALARMS, val);
+ if (DEBUG) Log.d(TAG, "onPrefChange allowAlarms=" + val);
+ savePolicy(getNewPriorityCategories(val, Policy.PRIORITY_CATEGORY_ALARMS),
+ mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders,
+ mPolicy.suppressedVisualEffects);
+ return true;
+ }
+ });
+
+ mMediaSystemOther = (SwitchPreference) root.findPreference(KEY_MEDIA);
+ mMediaSystemOther.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (mDisableListeners) return true;
+ final boolean val = (Boolean) newValue;
+ mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_MEDIA, val);
+ if (DEBUG) Log.d(TAG, "onPrefChange allowMediaSystemOther=" + val);
+ savePolicy(getNewPriorityCategories(val,
+ Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER),
+ mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders,
+ mPolicy.suppressedVisualEffects);
+ return true;
+ }
+ });
+
updateControls();
}
@Override
protected void onZenModeChanged() {
- // don't care
+ updateControls();
}
@Override
@@ -162,8 +197,7 @@
updateControls();
}
- private void updateControls() {
- mDisableListeners = true;
+ private void updateControlsPolicy() {
if (mCalls != null) {
mCalls.setValue(Integer.toString(
isPriorityCategoryEnabled(Policy.PRIORITY_CATEGORY_CALLS)
@@ -172,15 +206,62 @@
mMessages.setValue(Integer.toString(
isPriorityCategoryEnabled(Policy.PRIORITY_CATEGORY_MESSAGES)
? mPolicy.priorityMessageSenders : SOURCE_NONE));
+ mAlarms.setChecked(isPriorityCategoryEnabled(Policy.PRIORITY_CATEGORY_ALARMS));
+ mMediaSystemOther.setChecked(isPriorityCategoryEnabled(
+ Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER));
mReminders.setChecked(isPriorityCategoryEnabled(Policy.PRIORITY_CATEGORY_REMINDERS));
mEvents.setChecked(isPriorityCategoryEnabled(Policy.PRIORITY_CATEGORY_EVENTS));
mRepeatCallers.setChecked(
isPriorityCategoryEnabled(Policy.PRIORITY_CATEGORY_REPEAT_CALLERS));
mRepeatCallers.setVisible(!isPriorityCategoryEnabled(Policy.PRIORITY_CATEGORY_CALLS)
|| mPolicy.priorityCallSenders != Policy.PRIORITY_SENDERS_ANY);
+
+ }
+
+ private void updateControls() {
+ mDisableListeners = true;
+ switch(mZenMode) {
+ case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
+ toggleBasicNoInterruptions();
+ mAlarms.setChecked(false);
+ mMediaSystemOther.setChecked(false);
+ setTogglesEnabled(false);
+ break;
+ case Settings.Global.ZEN_MODE_ALARMS:
+ toggleBasicNoInterruptions();
+ mAlarms.setChecked(true);
+ mMediaSystemOther.setChecked(true);
+ setTogglesEnabled(false);
+ break;
+ default:
+ updateControlsPolicy();
+ setTogglesEnabled(true);
+ }
mDisableListeners = false;
}
+ private void toggleBasicNoInterruptions() {
+ if (mCalls != null) {
+ mCalls.setValue(Integer.toString(SOURCE_NONE));
+ }
+ mMessages.setValue(Integer.toString(SOURCE_NONE));
+ mReminders.setChecked(false);
+ mEvents.setChecked(false);
+ mRepeatCallers.setChecked(false);
+ }
+
+ private void setTogglesEnabled(boolean enable) {
+ if (mCalls != null) {
+ mCalls.setEnabled(enable);
+ }
+ mMessages.setEnabled(enable);
+ mReminders.setEnabled(enable);
+ mEvents.setEnabled(enable);
+ mRepeatCallers.setEnabled(enable);
+ mAlarms.setEnabled(enable);
+ mMediaSystemOther.setEnabled(enable);
+ }
+
@Override
public int getMetricsCategory() {
return MetricsEvent.NOTIFICATION_ZEN_MODE_PRIORITY;
diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java
index 8cb700b..f112c1b 100644
--- a/src/com/android/settings/notification/ZenModeSettings.java
+++ b/src/com/android/settings/notification/ZenModeSettings.java
@@ -28,14 +28,10 @@
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.content.res.Resources;
-import android.graphics.drawable.Drawable;
-import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Settings;
import android.service.notification.ConditionProviderService;
import android.service.notification.ZenModeConfig;
-import com.android.settings.utils.ManagedServiceSettings;
-import com.android.settings.utils.ZenServiceListing;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
@@ -45,25 +41,27 @@
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
+import com.android.settings.utils.ManagedServiceSettings;
+import com.android.settings.utils.ZenServiceListing;
import com.android.settingslib.TwoTargetPreference;
-import java.lang.ref.WeakReference;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class ZenModeSettings extends ZenModeSettingsBase {
- public static final String KEY_VISUAL_SETTINGS = "visual_interruptions_settings";
-
- private static final String KEY_PRIORITY_SETTINGS = "priority_settings";
- private static final String KEY_AUTOMATIC_RULES = "automatic_rules";
+ public static final String KEY_VISUAL_SETTINGS = "zen_mode_visual_interruptions_settings";
+ private static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_behavior_settings";
+ private static final String KEY_AUTOMATIC_RULES = "zen_mode_automatic_rules";
static final ManagedServiceSettings.Config CONFIG = getConditionProviderConfig();
private PreferenceCategory mAutomaticRules;
- private Preference mPrioritySettings;
+ private Preference mBehaviorSettings;
private Preference mVisualSettings;
private Policy mPolicy;
private SummaryBuilder mSummaryBuilder;
@@ -78,7 +76,7 @@
final PreferenceScreen root = getPreferenceScreen();
mAutomaticRules = (PreferenceCategory) root.findPreference(KEY_AUTOMATIC_RULES);
- mPrioritySettings = root.findPreference(KEY_PRIORITY_SETTINGS);
+ mBehaviorSettings = root.findPreference(KEY_BEHAVIOR_SETTINGS);
mVisualSettings = root.findPreference(KEY_VISUAL_SETTINGS);
mPolicy = NotificationManager.from(mContext).getNotificationPolicy();
mSummaryBuilder = new SummaryBuilder(getContext());
@@ -113,13 +111,13 @@
}
private void updateControls() {
- updatePrioritySettingsSummary();
+ updateBehaviorSettingsSummary();
updateVisualSettingsSummary();
updateAutomaticRules();
}
- private void updatePrioritySettingsSummary() {
- mPrioritySettings.setSummary(mSummaryBuilder.getPrioritySettingSummary(mPolicy));
+ private void updateBehaviorSettingsSummary() {
+ mBehaviorSettings.setSummary(mSummaryBuilder.getBehaviorSettingSummary(mPolicy, mZenMode));
}
private void updateVisualSettingsSummary() {
@@ -352,29 +350,44 @@
mContext = context;
}
- String getPrioritySettingSummary(Policy policy) {
- String s = mContext.getString(R.string.zen_mode_alarms);
- s = prepend(s, isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_EVENTS),
- R.string.zen_mode_events);
- s = prepend(s, isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_REMINDERS),
- R.string.zen_mode_reminders);
- if (isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_MESSAGES)) {
- if (policy.priorityMessageSenders == Policy.PRIORITY_SENDERS_ANY) {
- s = append(s, true, R.string.zen_mode_all_messages);
+ private static final int[] ALL_PRIORITY_CATEGORIES = {
+ Policy.PRIORITY_CATEGORY_ALARMS,
+ Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER,
+ Policy.PRIORITY_CATEGORY_REMINDERS,
+ Policy.PRIORITY_CATEGORY_EVENTS,
+ Policy.PRIORITY_CATEGORY_MESSAGES,
+ Policy.PRIORITY_CATEGORY_CALLS,
+ Policy.PRIORITY_CATEGORY_REPEAT_CALLERS,
+ };
+
+ String getBehaviorSettingSummary(Policy policy, int zenMode) {
+ List<String> enabledCategories;
+
+ if (zenMode == Settings.Global.ZEN_MODE_NO_INTERRUPTIONS) {
+ return mContext.getString(R.string.zen_mode_behavior_total_silence);
+ } else if (zenMode == Settings.Global.ZEN_MODE_ALARMS) {
+ return mContext.getString(R.string.zen_mode_behavior_alarms_only);
+ } else {
+ enabledCategories = getEnabledCategories(policy);
+ }
+
+ int numCategories = enabledCategories.size();
+ if (numCategories == 0) {
+ return mContext.getString(R.string.zen_mode_behavior_no_sound);
+ }
+
+ String s = enabledCategories.get(0).toLowerCase();
+ for (int i = 1; i < numCategories; i++) {
+ if (i == numCategories - 1) {
+ s = mContext.getString(R.string.join_many_items_last,
+ s, enabledCategories.get(i).toLowerCase());
} else {
- s = append(s, true, R.string.zen_mode_selected_messages);
+ s = mContext.getString(R.string.join_many_items_middle,
+ s, enabledCategories.get(i).toLowerCase());
}
}
- if (isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_CALLS)) {
- if (policy.priorityCallSenders == Policy.PRIORITY_SENDERS_ANY) {
- s = append(s, true, R.string.zen_mode_all_callers);
- } else {
- s = append(s, true, R.string.zen_mode_selected_callers);
- }
- } else if (isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_REPEAT_CALLERS)) {
- s = append(s, true, R.string.zen_mode_repeat_callers);
- }
- return s;
+
+ return mContext.getString(R.string.zen_mode_behavior_no_sound_except, s);
}
String getVisualSettingSummary(Policy policy) {
@@ -413,22 +426,45 @@
return count;
}
- @VisibleForTesting
- String append(String s, boolean condition, int resId) {
- if (condition) {
- return mContext.getString(
- R.string.join_many_items_middle, s, mContext.getString(resId));
+ private List<String> getEnabledCategories(Policy policy) {
+ List<String> enabledCategories = new ArrayList<>();
+ for (int category : ALL_PRIORITY_CATEGORIES) {
+ if (isCategoryEnabled(policy, category)) {
+ if (category == Policy.PRIORITY_CATEGORY_ALARMS) {
+ enabledCategories.add(mContext.getString(R.string.zen_mode_alarms));
+ } else if (category == Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER) {
+ enabledCategories.add(mContext.getString(
+ R.string.zen_mode_media_system_other));
+ } else if (category == Policy.PRIORITY_CATEGORY_REMINDERS) {
+ enabledCategories.add(mContext.getString(R.string.zen_mode_reminders));
+ } else if (category == Policy.PRIORITY_CATEGORY_EVENTS) {
+ enabledCategories.add(mContext.getString(R.string.zen_mode_events));
+ } else if (category == Policy.PRIORITY_CATEGORY_MESSAGES) {
+ if (policy.priorityMessageSenders == Policy.PRIORITY_SENDERS_ANY) {
+ enabledCategories.add(mContext.getString(
+ R.string.zen_mode_all_messages));
+ } else {
+ enabledCategories.add(mContext.getString(
+ R.string.zen_mode_selected_messages));
+ }
+ } else if (category == Policy.PRIORITY_CATEGORY_CALLS) {
+ if (policy.priorityCallSenders == Policy.PRIORITY_SENDERS_ANY) {
+ enabledCategories.add(mContext.getString(
+ R.string.zen_mode_all_callers));
+ } else {
+ enabledCategories.add(mContext.getString(
+ R.string.zen_mode_selected_callers));
+ }
+ } else if (category == Policy.PRIORITY_CATEGORY_REPEAT_CALLERS) {
+ if (!enabledCategories.contains(mContext.getString(
+ R.string.zen_mode_all_callers))) {
+ enabledCategories.add(mContext.getString(
+ R.string.zen_mode_repeat_callers));
+ }
+ }
+ }
}
- return s;
- }
-
- @VisibleForTesting
- String prepend(String s, boolean condition, int resId) {
- if (condition) {
- return mContext.getString(
- R.string.join_many_items_middle, mContext.getString(resId), s);
- }
- return s;
+ return enabledCategories;
}
private boolean isCategoryEnabled(Policy policy, int categoryType) {
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index c946d46..9608aea 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -74,7 +74,7 @@
import com.android.settings.notification.ChannelImportanceSettings;
import com.android.settings.notification.ConfigureNotificationSettings;
import com.android.settings.notification.SoundSettings;
-import com.android.settings.notification.ZenModePrioritySettings;
+import com.android.settings.notification.ZenModeBehaviorSettings;
import com.android.settings.notification.ZenModeSettings;
import com.android.settings.notification.ZenModeVisualInterruptionSettings;
import com.android.settings.print.PrintSettingsFragment;
@@ -152,8 +152,8 @@
"android.settings.SOUND_SETTINGS");
addIndex(ZenModeSettings.class,
R.xml.zen_mode_settings, R.drawable.ic_settings_notifications);
- addIndex(ZenModePrioritySettings.class,
- R.xml.zen_mode_priority_settings, R.drawable.ic_settings_notifications);
+ addIndex(ZenModeBehaviorSettings.class,
+ R.xml.zen_mode_behavior_settings, R.drawable.ic_settings_notifications);
addIndex(StorageSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_storage);
addIndex(PowerUsageSummary.class,
R.xml.power_usage_summary, R.drawable.ic_settings_battery);
diff --git a/tests/robotests/assets/grandfather_not_implementing_indexable b/tests/robotests/assets/grandfather_not_implementing_indexable
index bbb4bb2..6ee58d2 100644
--- a/tests/robotests/assets/grandfather_not_implementing_indexable
+++ b/tests/robotests/assets/grandfather_not_implementing_indexable
@@ -1,5 +1,4 @@
com.android.settings.location.LocationMode
-com.android.settings.notification.ZenModePrioritySettings
com.android.settings.notification.ZenModeVisualInterruptionSettings
com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragment
com.android.settings.deviceinfo.SimStatus
@@ -70,6 +69,7 @@
com.android.settings.applications.AppStorageSettings
com.android.settings.notification.NotificationAccessSettings
com.android.settings.notification.ZenModeSettings
+com.android.settings.notification.ZenModeBehaviorSettings
com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment
com.android.settings.localepicker.LocaleListEditor
com.android.settings.qstile.DevelopmentTileConfigActivity$DevelopmentTileConfigFragment
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
index 716e2b2..1135d7c 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
@@ -16,12 +16,17 @@
package com.android.settings.notification;
+import static com.google.common.truth.Truth.assertThat;
+
+import static junit.framework.Assert.assertTrue;
+
import android.app.NotificationManager;
import android.content.Context;
+import android.provider.Settings;
import com.android.settings.R;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
@@ -29,10 +34,6 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import static com.google.common.truth.Truth.assertThat;
-
-import static junit.framework.Assert.assertTrue;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ZenModeSettingsTest {
@@ -47,54 +48,28 @@
}
@Test
- public void testAppend_conditionFalse_shouldNotAppend() {
- String original = "test";
-
- final String result = mBuilder.append(original, false, R.string.zen_mode_alarms);
-
- assertThat(result).isEqualTo(original);
- }
-
- @Test
- public void testAppend_conditionTrue_shouldAppend() {
- String original = "test";
- String alarm = mContext.getString(R.string.zen_mode_alarms);
-
- final String result = mBuilder.append(original, true, R.string.zen_mode_alarms);
-
- assertThat(result).contains(alarm);
- assertThat(result).contains(original);
- assertTrue(result.indexOf(original) < result.indexOf(alarm));
- }
-
- @Test
- public void testPrepend() {
- String original = mContext.getString(R.string.zen_mode_alarms);
- String reminders = mContext.getString(R.string.zen_mode_reminders);
-
- final String result = mBuilder.prepend(original, true, R.string.zen_mode_reminders);
- assertThat(result).contains(original);
- assertThat(result).contains(reminders);
- assertTrue(result.indexOf(reminders) < result.indexOf(original));
- }
-
- @Test
- public void testGetPrioritySettingSummary_sameOrderAsTargetPage() {
+ public void testGetBehaviorSettingSummary_sameOrderAsTargetPage() {
NotificationManager.Policy policy = new NotificationManager.Policy(
NotificationManager.Policy.PRIORITY_CATEGORY_EVENTS
- | NotificationManager.Policy.PRIORITY_CATEGORY_REMINDERS,
+ | NotificationManager.Policy.PRIORITY_CATEGORY_REMINDERS
+ | NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS
+ | NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA_SYSTEM_OTHER,
0, 0);
- final String result = mBuilder.getPrioritySettingSummary(policy);
+ final String result = mBuilder.getBehaviorSettingSummary(policy,
+ Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
- String alarms = mContext.getString(R.string.zen_mode_alarms);
- String reminders = mContext.getString(R.string.zen_mode_reminders);
- String events = mContext.getString(R.string.zen_mode_events);
+ String alarms = mContext.getString(R.string.zen_mode_alarms).toLowerCase();
+ String reminders = mContext.getString(R.string.zen_mode_reminders).toLowerCase();
+ String events = mContext.getString(R.string.zen_mode_events).toLowerCase();
+ String media = mContext.getString(R.string.zen_mode_media_system_other).toLowerCase();
assertThat(result).contains(alarms);
assertThat(result).contains(reminders);
assertThat(result).contains(events);
- assertTrue(result.indexOf(reminders) < result.indexOf(events) &&
- result.indexOf(events) < result.indexOf(alarms));
+ assertThat(result).contains(media);
+ assertTrue(result.indexOf(alarms) < result.indexOf(media)
+ && result.indexOf(media) < result.indexOf(reminders)
+ && result.indexOf(reminders) < result.indexOf(events));
}
}