From 200da8978f45d2afeeaa8f5a5a03603102d7809e Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Fri, 4 May 2018 08:54:53 -0400 Subject: [PATCH] DND settings redesign Test: robotests Change-Id: I7b980218feea28e945994c8b7f8a934df6bc11f9 Bug: 78447976 --- AndroidManifest.xml | 21 +-- res/values/strings.xml | 77 +++++++++-- res/xml/zen_mode_behavior_settings.xml | 70 ---------- res/xml/zen_mode_calls_settings.xml | 43 ++++++ res/xml/zen_mode_msg_event_reminder_settings.xml | 46 +++++++ .../zen_mode_restrict_notifications_settings.xml | 4 +- res/xml/zen_mode_settings.xml | 67 ++++++---- res/xml/zen_mode_sound_vibration_settings.xml | 44 ++++++ .../settings/core/gateway/SettingsGateway.java | 4 +- ... ZenModeBehaviorCallsPreferenceController.java} | 9 +- .../ZenModeBehaviorFooterPreferenceController.java | 69 +++++----- ...haviorMsgEventReminderPreferenceController.java | 53 ++++++++ .../ZenModeBehaviorSoundPreferenceController.java | 52 ++++++++ .../notification/ZenModeCallsSettings.java | 93 +++++++++++++ ...s.java => ZenModeMsgEventReminderSettings.java} | 18 +-- .../settings/notification/ZenModeSettings.java | 113 +++++++++++----- .../ZenModeSoundVibrationSettings.java | 90 +++++++++++++ ...nModeBehaviorCallsPreferenceControllerTest.java | 79 +++++++++++ ...ModeBehaviorFooterPreferenceControllerTest.java | 16 ++- ...orMsgEventReminderPreferenceControllerTest.java | 79 +++++++++++ ...nModeBehaviorSoundPreferenceControllerTest.java | 79 +++++++++++ .../settings/notification/ZenModeSettingsTest.java | 148 ++++++++++++++++----- 22 files changed, 1021 insertions(+), 253 deletions(-) delete mode 100644 res/xml/zen_mode_behavior_settings.xml create mode 100644 res/xml/zen_mode_calls_settings.xml create mode 100644 res/xml/zen_mode_msg_event_reminder_settings.xml create mode 100644 res/xml/zen_mode_sound_vibration_settings.xml rename src/com/android/settings/notification/{ZenModeBehaviorPreferenceController.java => ZenModeBehaviorCallsPreferenceController.java} (83%) create mode 100644 src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceController.java create mode 100644 src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceController.java create mode 100644 src/com/android/settings/notification/ZenModeCallsSettings.java rename src/com/android/settings/notification/{ZenModeBehaviorSettings.java => ZenModeMsgEventReminderSettings.java} (78%) create mode 100644 src/com/android/settings/notification/ZenModeSoundVibrationSettings.java create mode 100644 tests/robotests/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceControllerTest.java create mode 100644 tests/robotests/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceControllerTest.java create mode 100644 tests/robotests/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceControllerTest.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 52a18b9aa5..b59ee56e64 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -727,6 +727,10 @@ + + + + @@ -753,23 +757,6 @@ - - - - - - - - - Allow visual signals - - Restrict notifications + + When Do Not Disturb is turned on + Notifications - - When Do Not Disturb is turned on - Mute notifications + Show notifications silently - Show notifications but mute sounds & vibrations + Notifications will be muted - When new notifications arrive your phone won\u2019t make a sound or vibration + When notifications arrive, your phone won\u2019t make a sound or vibrate. - Hide & mute notifications + Hide notifications - Notifications will not appear at all + You won\u2019t see new or existing notifications - You won\u2019t see new or existing notifications when Do Not Disturb is on. However, notifications needed for basic phone activity and status will still appear. + Your phone won\u2019t show new or existing notifications, and won\u2019t make a sound or vibrate. Notifications won\u2019t appear when you swipe down from the top of your screen.\n\nKeep in mind, critical notifications for phone activity and status will still appear. Custom @@ -7362,6 +7361,35 @@ %d rules can turn on automatically + + Behavior + + Exceptions + + Schedule + + + Sound & vibration + + When Do Not Disturb is on, sound and vibration will be muted, except for the items you allow above. + + Mute all except + + Muted + + Not muted + + Muted, but allow %1$s + + Muted, but allow %1$s and %2$s + + Muted, but allow %1$s, %2$s, and %3$s + + + Messages, events & reminders + + When Do Not Disturb is on, messages, reminders, and events will muted, except for the items you allow above. You can adjust messages settings to allow your friends, family, or other contacts to reach you. + Update @@ -7893,14 +7921,17 @@ Calls + + When Do Not Disturb is on, incoming calls are blocked. You can adjust settings to allow your friends, family, or other contacts to reach you. + Messages - All messages + Messages - Selected messages + Some messages From anyone @@ -7911,6 +7942,15 @@ From starred contacts only + + From starred contacts and repeat callers + + + From contacts and repeat callers + + + From repeat callers only + None @@ -7930,14 +7970,23 @@ Events - All callers + anyone + + + contacts - Selected callers + starred contacts Repeat callers + + From %1$s only + + + From %1$s and %2$s + If the same person calls a second time within a %d minute period diff --git a/res/xml/zen_mode_behavior_settings.xml b/res/xml/zen_mode_behavior_settings.xml deleted file mode 100644 index 8426d9154c..0000000000 --- a/res/xml/zen_mode_behavior_settings.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/res/xml/zen_mode_calls_settings.xml b/res/xml/zen_mode_calls_settings.xml new file mode 100644 index 0000000000..01ca499c44 --- /dev/null +++ b/res/xml/zen_mode_calls_settings.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + diff --git a/res/xml/zen_mode_msg_event_reminder_settings.xml b/res/xml/zen_mode_msg_event_reminder_settings.xml new file mode 100644 index 0000000000..40b25139af --- /dev/null +++ b/res/xml/zen_mode_msg_event_reminder_settings.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + diff --git a/res/xml/zen_mode_restrict_notifications_settings.xml b/res/xml/zen_mode_restrict_notifications_settings.xml index d5243f6294..e024ab9d97 100644 --- a/res/xml/zen_mode_restrict_notifications_settings.xml +++ b/res/xml/zen_mode_restrict_notifications_settings.xml @@ -18,11 +18,11 @@ + android:title="@string/zen_mode_restrict_notifications_title"> + android:title="@string/zen_mode_settings_category"> - - - - - + + + - - + + + - - + + + - - + - + android:key="zen_mode_settings_category_schedule" + android:title="@string/zen_category_schedule"> + + + + + + diff --git a/res/xml/zen_mode_sound_vibration_settings.xml b/res/xml/zen_mode_sound_vibration_settings.xml new file mode 100644 index 0000000000..b3b81395ed --- /dev/null +++ b/res/xml/zen_mode_sound_vibration_settings.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java index ced158eb3e..aab3512cf1 100644 --- a/src/com/android/settings/core/gateway/SettingsGateway.java +++ b/src/com/android/settings/core/gateway/SettingsGateway.java @@ -106,9 +106,10 @@ import com.android.settings.notification.NotificationStation; import com.android.settings.notification.SoundSettings; import com.android.settings.notification.ZenAccessSettings; import com.android.settings.notification.ZenModeAutomationSettings; -import com.android.settings.notification.ZenModeBehaviorSettings; +import com.android.settings.notification.ZenModeMsgEventReminderSettings; import com.android.settings.notification.ZenModeBlockedEffectsSettings; import com.android.settings.notification.ZenModeEventRuleSettings; +import com.android.settings.notification.ZenModeRestrictNotificationsSettings; import com.android.settings.notification.ZenModeScheduleRuleSettings; import com.android.settings.notification.ZenModeSettings; import com.android.settings.password.ChooseLockPassword; @@ -220,7 +221,6 @@ public class SettingsGateway { ApnSettings.class.getName(), ApnEditor.class.getName(), WifiCallingSettings.class.getName(), - ZenModeBehaviorSettings.class.getName(), ZenModeScheduleRuleSettings.class.getName(), ZenModeEventRuleSettings.class.getName(), ZenModeBlockedEffectsSettings.class.getName(), diff --git a/src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java b/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceController.java similarity index 83% rename from src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java rename to src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceController.java index 908ec04ad7..4ab14379e9 100644 --- a/src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java +++ b/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceController.java @@ -22,13 +22,13 @@ import androidx.preference.Preference; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.core.lifecycle.Lifecycle; -public class ZenModeBehaviorPreferenceController extends +public class ZenModeBehaviorCallsPreferenceController extends AbstractZenModePreferenceController implements PreferenceControllerMixin { - protected static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_behavior_settings"; + protected static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_calls_settings"; private final ZenModeSettings.SummaryBuilder mSummaryBuilder; - public ZenModeBehaviorPreferenceController(Context context, Lifecycle lifecycle) { + public ZenModeBehaviorCallsPreferenceController(Context context, Lifecycle lifecycle) { super(context, KEY_BEHAVIOR_SETTINGS, lifecycle); mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context); } @@ -47,7 +47,6 @@ public class ZenModeBehaviorPreferenceController extends public void updateState(Preference preference) { super.updateState(preference); - preference.setSummary(mSummaryBuilder.getBehaviorSettingSummary(getPolicy(), - getZenMode())); + preference.setSummary(mSummaryBuilder.getCallsSettingSummary(getPolicy())); } } diff --git a/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceController.java b/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceController.java index a36c2661b8..1a6a3b4357 100644 --- a/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceController.java +++ b/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceController.java @@ -16,8 +16,8 @@ package com.android.settings.notification; -import android.content.Context; import android.content.ComponentName; +import android.content.Context; import android.net.Uri; import android.provider.Settings; import android.service.notification.ZenModeConfig; @@ -30,14 +30,17 @@ import com.android.settingslib.core.lifecycle.Lifecycle; public class ZenModeBehaviorFooterPreferenceController extends AbstractZenModePreferenceController { protected static final String KEY = "footer_preference"; + private final int mTitleRes; - public ZenModeBehaviorFooterPreferenceController(Context context, Lifecycle lifecycle) { + public ZenModeBehaviorFooterPreferenceController(Context context, Lifecycle lifecycle, + int titleRes) { super(context, KEY, lifecycle); + mTitleRes = titleRes; } @Override public boolean isAvailable() { - return isDeprecatedZenMode(getZenMode()); + return true; } @Override @@ -48,45 +51,45 @@ public class ZenModeBehaviorFooterPreferenceController extends AbstractZenModePr @Override public void updateState(Preference preference) { super.updateState(preference); - - boolean isAvailable = isAvailable(); - preference.setVisible(isAvailable); - if (isAvailable) { - preference.setTitle(getFooterText()); - } - + preference.setTitle(getFooterText()); } protected String getFooterText() { - ZenModeConfig config = getZenModeConfig(); - - // DND turned on by manual rule with deprecated zen mode - if (config.manualRule != null && - isDeprecatedZenMode(config.manualRule.zenMode)) { - final Uri id = config.manualRule.conditionId; - if (config.manualRule.enabler != null) { - // app triggered manual rule - String appOwner = mZenModeConfigWrapper.getOwnerCaption(config.manualRule.enabler); - if (!appOwner.isEmpty()) { - return mContext.getString(R.string.zen_mode_app_set_behavior, appOwner); + if (isDeprecatedZenMode(getZenMode())) { + ZenModeConfig config = getZenModeConfig(); + + // DND turned on by manual rule with deprecated zen mode + if (config.manualRule != null && + isDeprecatedZenMode(config.manualRule.zenMode)) { + final Uri id = config.manualRule.conditionId; + if (config.manualRule.enabler != null) { + // app triggered manual rule + String appOwner = mZenModeConfigWrapper.getOwnerCaption( + config.manualRule.enabler); + if (!appOwner.isEmpty()) { + return mContext.getString(R.string.zen_mode_app_set_behavior, appOwner); + } + } else { + return mContext.getString(R.string.zen_mode_qs_set_behavior); } - } else { - return mContext.getString(R.string.zen_mode_qs_set_behavior); } - } - // DND turned on by an automatic rule with deprecated zen mode - for (ZenModeConfig.ZenRule automaticRule : config.automaticRules.values()) { - if (automaticRule.isAutomaticActive() && isDeprecatedZenMode(automaticRule.zenMode)) { - ComponentName component = automaticRule.component; - if (component != null) { - return mContext.getString(R.string.zen_mode_app_set_behavior, - component.getPackageName()); + // DND turned on by an automatic rule with deprecated zen mode + for (ZenModeConfig.ZenRule automaticRule : config.automaticRules.values()) { + if (automaticRule.isAutomaticActive() && isDeprecatedZenMode( + automaticRule.zenMode)) { + ComponentName component = automaticRule.component; + if (component != null) { + return mContext.getString(R.string.zen_mode_app_set_behavior, + component.getPackageName()); + } } } - } - return mContext.getString(R.string.zen_mode_unknown_app_set_behavior); + return mContext.getString(R.string.zen_mode_unknown_app_set_behavior); + } else { + return mContext.getString(mTitleRes); + } } private boolean isDeprecatedZenMode(int zenMode) { diff --git a/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceController.java b/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceController.java new file mode 100644 index 0000000000..d11baee8e8 --- /dev/null +++ b/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceController.java @@ -0,0 +1,53 @@ +/* + * 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.content.Context; +import androidx.preference.Preference; + +import com.android.settings.core.PreferenceControllerMixin; +import com.android.settingslib.core.lifecycle.Lifecycle; + +public class ZenModeBehaviorMsgEventReminderPreferenceController extends + AbstractZenModePreferenceController implements PreferenceControllerMixin { + + protected static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_msg_event_reminder_settings"; + private final ZenModeSettings.SummaryBuilder mSummaryBuilder; + + public ZenModeBehaviorMsgEventReminderPreferenceController(Context context, + Lifecycle lifecycle) { + super(context, KEY_BEHAVIOR_SETTINGS, lifecycle); + mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context); + } + + @Override + public String getPreferenceKey() { + return KEY_BEHAVIOR_SETTINGS; + } + + @Override + public boolean isAvailable() { + return true; + } + + @Override + public void updateState(Preference preference) { + super.updateState(preference); + + preference.setSummary(mSummaryBuilder.getMsgEventReminderSettingSummary(getPolicy())); + } +} diff --git a/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceController.java b/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceController.java new file mode 100644 index 0000000000..3d250639e1 --- /dev/null +++ b/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceController.java @@ -0,0 +1,52 @@ +/* + * 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 androidx.preference.Preference; + +import com.android.settings.core.PreferenceControllerMixin; +import com.android.settingslib.core.lifecycle.Lifecycle; + +public class ZenModeBehaviorSoundPreferenceController extends + AbstractZenModePreferenceController implements PreferenceControllerMixin { + + protected static final String KEY_BEHAVIOR_SETTINGS = "zen_sound_vibration_settings"; + private final ZenModeSettings.SummaryBuilder mSummaryBuilder; + + public ZenModeBehaviorSoundPreferenceController(Context context, Lifecycle lifecycle) { + super(context, KEY_BEHAVIOR_SETTINGS, lifecycle); + mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context); + } + + @Override + public String getPreferenceKey() { + return KEY_BEHAVIOR_SETTINGS; + } + + @Override + public boolean isAvailable() { + return true; + } + + @Override + public void updateState(Preference preference) { + super.updateState(preference); + + preference.setSummary(mSummaryBuilder.getSoundSettingSummary(getPolicy())); + } +} diff --git a/src/com/android/settings/notification/ZenModeCallsSettings.java b/src/com/android/settings/notification/ZenModeCallsSettings.java new file mode 100644 index 0000000000..3c7f0c96c9 --- /dev/null +++ b/src/com/android/settings/notification/ZenModeCallsSettings.java @@ -0,0 +1,93 @@ +/* + * 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.provider.SearchIndexableResource; + +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 com.android.settingslib.search.SearchIndexable; + +import java.util.ArrayList; +import java.util.List; + +@SearchIndexable +public class ZenModeCallsSettings extends ZenModeSettingsBase implements Indexable { + + @Override + protected List createPreferenceControllers(Context context) { + return buildPreferenceControllers(context, getLifecycle()); + } + + private static List buildPreferenceControllers(Context context, + Lifecycle lifecycle) { + List controllers = new ArrayList<>(); + controllers.add(new ZenModeCallsPreferenceController(context, lifecycle)); + // TODO: is a controller needed for a pref that just launches an external activity? + // or can the contacts app insert this setting themselves? + controllers.add(new ZenModeRepeatCallersPreferenceController(context, lifecycle, + context.getResources().getInteger(com.android.internal.R.integer + .config_zen_repeat_callers_threshold))); + controllers.add(new ZenModeBehaviorFooterPreferenceController( + context, lifecycle, R.string.zen_mode_calls_footer)); + return controllers; + } + + @Override + protected int getPreferenceScreenResId() { + return R.xml.zen_mode_calls_settings; + } + + @Override + public int getMetricsCategory() { + return MetricsEvent.NOTIFICATION_ZEN_MODE_PRIORITY; + } + + /** + * For Search. + */ + public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = + new BaseSearchIndexProvider() { + + @Override + public List getXmlResourcesToIndex(Context context, + boolean enabled) { + final ArrayList result = new ArrayList<>(); + + final SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.zen_mode_calls_settings; + result.add(sir); + return result; + } + + @Override + public List getNonIndexableKeys(Context context) { + final List keys = super.getNonIndexableKeys(context); + return keys; + } + + @Override + public List createPreferenceControllers(Context context) { + return buildPreferenceControllers(context, null); + } + }; +} diff --git a/src/com/android/settings/notification/ZenModeBehaviorSettings.java b/src/com/android/settings/notification/ZenModeMsgEventReminderSettings.java similarity index 78% rename from src/com/android/settings/notification/ZenModeBehaviorSettings.java rename to src/com/android/settings/notification/ZenModeMsgEventReminderSettings.java index 5a084e88e2..5a00c47473 100644 --- a/src/com/android/settings/notification/ZenModeBehaviorSettings.java +++ b/src/com/android/settings/notification/ZenModeMsgEventReminderSettings.java @@ -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. @@ -31,7 +31,7 @@ import java.util.ArrayList; import java.util.List; @SearchIndexable -public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Indexable { +public class ZenModeMsgEventReminderSettings extends ZenModeSettingsBase implements Indexable { @Override protected List createPreferenceControllers(Context context) { @@ -41,23 +41,17 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde private static List buildPreferenceControllers(Context context, Lifecycle lifecycle) { List controllers = new ArrayList<>(); - controllers.add(new ZenModeAlarmsPreferenceController(context, lifecycle)); - controllers.add(new ZenModeMediaPreferenceController(context, lifecycle)); - controllers.add(new ZenModeSystemPreferenceController(context, lifecycle)); controllers.add(new ZenModeEventsPreferenceController(context, lifecycle)); controllers.add(new ZenModeRemindersPreferenceController(context, lifecycle)); controllers.add(new ZenModeMessagesPreferenceController(context, lifecycle)); - controllers.add(new ZenModeCallsPreferenceController(context, lifecycle)); - controllers.add(new ZenModeRepeatCallersPreferenceController(context, lifecycle, - context.getResources().getInteger(com.android.internal.R.integer - .config_zen_repeat_callers_threshold))); - controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle)); + controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle, + R.string.zen_msg_event_reminder_footer)); return controllers; } @Override protected int getPreferenceScreenResId() { - return R.xml.zen_mode_behavior_settings; + return R.xml.zen_mode_msg_event_reminder_settings; } @Override @@ -77,7 +71,7 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde final ArrayList result = new ArrayList<>(); final SearchIndexableResource sir = new SearchIndexableResource(context); - sir.xmlResId = R.xml.zen_mode_behavior_settings; + sir.xmlResId = R.xml.zen_mode_msg_event_reminder_settings; result.add(sir); return result; } diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java index ddbfcb6487..3fb5a4b9be 100644 --- a/src/com/android/settings/notification/ZenModeSettings.java +++ b/src/com/android/settings/notification/ZenModeSettings.java @@ -16,6 +16,15 @@ package com.android.settings.notification; +import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS; +import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_CALLS; +import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_EVENTS; +import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA; +import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES; +import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_REMINDERS; +import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS; +import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_SYSTEM; + import android.app.AutomaticZenRule; import android.app.FragmentManager; import android.app.NotificationManager; @@ -42,19 +51,13 @@ import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.function.Predicate; @SearchIndexable public class ZenModeSettings extends ZenModeSettingsBase { - private static final String KEY_SOUND = "zen_effect_sound"; - @Override public void onResume() { super.onResume(); - CheckBoxPreference soundPreference = - (CheckBoxPreference) getPreferenceScreen().findPreference(KEY_SOUND); - if (soundPreference != null) { - soundPreference.setChecked(true); - } } @Override @@ -80,7 +83,9 @@ public class ZenModeSettings extends ZenModeSettingsBase { private static List buildPreferenceControllers(Context context, Lifecycle lifecycle, FragmentManager fragmentManager) { List controllers = new ArrayList<>(); - controllers.add(new ZenModeBehaviorPreferenceController(context, lifecycle)); + controllers.add(new ZenModeBehaviorMsgEventReminderPreferenceController(context, lifecycle)); + controllers.add(new ZenModeBehaviorSoundPreferenceController(context, lifecycle)); + controllers.add(new ZenModeBehaviorCallsPreferenceController(context, lifecycle)); controllers.add(new ZenModeBlockedEffectsPreferenceController(context, lifecycle)); controllers.add(new ZenModeDurationPreferenceController(context, lifecycle, fragmentManager)); @@ -100,19 +105,63 @@ public class ZenModeSettings extends ZenModeSettingsBase { // these should match NotificationManager.Policy#ALL_PRIORITY_CATEGORIES private static final int[] ALL_PRIORITY_CATEGORIES = { - Policy.PRIORITY_CATEGORY_ALARMS, - Policy.PRIORITY_CATEGORY_MEDIA, - Policy.PRIORITY_CATEGORY_SYSTEM, - Policy.PRIORITY_CATEGORY_REMINDERS, - Policy.PRIORITY_CATEGORY_EVENTS, - Policy.PRIORITY_CATEGORY_MESSAGES, - Policy.PRIORITY_CATEGORY_CALLS, - Policy.PRIORITY_CATEGORY_REPEAT_CALLERS, + PRIORITY_CATEGORY_ALARMS, + PRIORITY_CATEGORY_MEDIA, + PRIORITY_CATEGORY_SYSTEM, + PRIORITY_CATEGORY_MESSAGES, + PRIORITY_CATEGORY_EVENTS, + PRIORITY_CATEGORY_REMINDERS, + PRIORITY_CATEGORY_CALLS, + PRIORITY_CATEGORY_REPEAT_CALLERS, }; - String getBehaviorSettingSummary(Policy policy, int zenMode) { - List enabledCategories = getEnabledCategories(policy); + String getSoundSettingSummary(Policy policy) { + List enabledCategories = getEnabledCategories(policy, + category -> PRIORITY_CATEGORY_ALARMS == category + || PRIORITY_CATEGORY_MEDIA == category + || PRIORITY_CATEGORY_SYSTEM == category); + int numCategories = enabledCategories.size(); + if (numCategories == 0) { + return mContext.getString(R.string.zen_sound_all_muted); + } else if (numCategories == 1) { + return mContext.getString(R.string.zen_sound_one_allowed, + enabledCategories.get(0).toLowerCase()); + } else if (numCategories == 2) { + return mContext.getString(R.string.zen_sound_two_allowed, + enabledCategories.get(0).toLowerCase(), + enabledCategories.get(1).toLowerCase()); + } else if (numCategories == 3) { + return mContext.getString(R.string.zen_sound_three_allowed, + enabledCategories.get(0).toLowerCase(), + enabledCategories.get(1).toLowerCase(), + enabledCategories.get(2).toLowerCase()); + } else { + return mContext.getString(R.string.zen_sound_none_muted); + } + } + + String getCallsSettingSummary(Policy policy) { + List enabledCategories = getEnabledCategories(policy, + category -> PRIORITY_CATEGORY_CALLS == category + || PRIORITY_CATEGORY_REPEAT_CALLERS == category); + int numCategories = enabledCategories.size(); + if (numCategories == 0) { + return mContext.getString(R.string.zen_mode_no_exceptions); + } else if (numCategories == 1) { + return mContext.getString(R.string.zen_mode_calls_summary_one, + enabledCategories.get(0).toLowerCase()); + } else { + return mContext.getString(R.string.zen_mode_calls_summary_two, + enabledCategories.get(0).toLowerCase(), + enabledCategories.get(1).toLowerCase()); + } + } + String getMsgEventReminderSettingSummary(Policy policy) { + List enabledCategories = getEnabledCategories(policy, + category -> PRIORITY_CATEGORY_EVENTS == category + || PRIORITY_CATEGORY_REMINDERS == category + || PRIORITY_CATEGORY_MESSAGES == category); int numCategories = enabledCategories.size(); if (numCategories == 0) { return mContext.getString(R.string.zen_mode_no_exceptions); @@ -201,22 +250,19 @@ public class ZenModeSettings extends ZenModeSettingsBase { return count; } - private List getEnabledCategories(Policy policy) { + private List getEnabledCategories(Policy policy, + Predicate filteredCategories) { List enabledCategories = new ArrayList<>(); for (int category : ALL_PRIORITY_CATEGORIES) { - if (isCategoryEnabled(policy, category)) { - if (category == Policy.PRIORITY_CATEGORY_ALARMS) { + if (filteredCategories.test(category) && isCategoryEnabled(policy, category)) { + if (category == PRIORITY_CATEGORY_ALARMS) { enabledCategories.add(mContext.getString(R.string.zen_mode_alarms)); - } else if (category == Policy.PRIORITY_CATEGORY_MEDIA) { + } else if (category == PRIORITY_CATEGORY_MEDIA) { enabledCategories.add(mContext.getString( R.string.zen_mode_media)); - } else if (category == Policy.PRIORITY_CATEGORY_SYSTEM) { + } else if (category == PRIORITY_CATEGORY_SYSTEM) { enabledCategories.add(mContext.getString( R.string.zen_mode_system)); - } 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( @@ -225,13 +271,20 @@ public class ZenModeSettings extends ZenModeSettingsBase { enabledCategories.add(mContext.getString( R.string.zen_mode_selected_messages)); } + } else if (category == Policy.PRIORITY_CATEGORY_EVENTS) { + enabledCategories.add(mContext.getString(R.string.zen_mode_events)); + } else if (category == Policy.PRIORITY_CATEGORY_REMINDERS) { + enabledCategories.add(mContext.getString(R.string.zen_mode_reminders)); } 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 if (policy.priorityCallSenders == Policy.PRIORITY_SENDERS_CONTACTS){ + enabledCategories.add(mContext.getString( + R.string.zen_mode_contacts_callers)); } else { enabledCategories.add(mContext.getString( - R.string.zen_mode_selected_callers)); + R.string.zen_mode_starred_callers)); } } else if (category == Policy.PRIORITY_CATEGORY_REPEAT_CALLERS) { if (!enabledCategories.contains(mContext.getString( @@ -248,10 +301,6 @@ public class ZenModeSettings extends ZenModeSettingsBase { private boolean isCategoryEnabled(Policy policy, int categoryType) { return (policy.priorityCategories & categoryType) != 0; } - - private boolean isEffectSuppressed(Policy policy, int effect) { - return (policy.suppressedVisualEffects & effect) != 0; - } } /** diff --git a/src/com/android/settings/notification/ZenModeSoundVibrationSettings.java b/src/com/android/settings/notification/ZenModeSoundVibrationSettings.java new file mode 100644 index 0000000000..b72460c8a3 --- /dev/null +++ b/src/com/android/settings/notification/ZenModeSoundVibrationSettings.java @@ -0,0 +1,90 @@ +/* + * 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.provider.SearchIndexableResource; + +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 com.android.settingslib.search.SearchIndexable; + +import java.util.ArrayList; +import java.util.List; + +@SearchIndexable +public class ZenModeSoundVibrationSettings extends ZenModeSettingsBase implements Indexable { + + @Override + protected List createPreferenceControllers(Context context) { + return buildPreferenceControllers(context, getLifecycle()); + } + + private static List buildPreferenceControllers(Context context, + Lifecycle lifecycle) { + List controllers = new ArrayList<>(); + controllers.add(new ZenModeAlarmsPreferenceController(context, lifecycle)); + controllers.add(new ZenModeMediaPreferenceController(context, lifecycle)); + controllers.add(new ZenModeSystemPreferenceController(context, lifecycle)); + controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle, + R.string.zen_sound_footer)); + return controllers; + } + + @Override + protected int getPreferenceScreenResId() { + return R.xml.zen_mode_sound_vibration_settings; + } + + @Override + public int getMetricsCategory() { + return MetricsEvent.NOTIFICATION_ZEN_MODE_PRIORITY; + } + + /** + * For Search. + */ + public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = + new BaseSearchIndexProvider() { + + @Override + public List getXmlResourcesToIndex(Context context, + boolean enabled) { + final ArrayList result = new ArrayList<>(); + + final SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.zen_mode_sound_vibration_settings; + result.add(sir); + return result; + } + + @Override + public List getNonIndexableKeys(Context context) { + final List keys = super.getNonIndexableKeys(context); + return keys; + } + + @Override + public List createPreferenceControllers(Context context) { + return buildPreferenceControllers(context, null); + } + }; +} diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceControllerTest.java new file mode 100644 index 0000000000..b3a4b90b09 --- /dev/null +++ b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceControllerTest.java @@ -0,0 +1,79 @@ +/* + * 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 org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +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 androidx.preference.Preference; + +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.RuntimeEnvironment; +import org.robolectric.shadows.ShadowApplication; +import org.robolectric.util.ReflectionHelpers; + +@RunWith(SettingsRobolectricTestRunner.class) +public final class ZenModeBehaviorCallsPreferenceControllerTest { + + private ZenModeBehaviorCallsPreferenceController mController; + @Mock + private NotificationManager mNotificationManager; + @Mock + private NotificationManager.Policy mPolicy; + + private Context mContext; + @Mock + private ZenModeBackend mBackend; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + ShadowApplication shadowApplication = ShadowApplication.getInstance(); + shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager); + + mContext = RuntimeEnvironment.application; + when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy); + + mController = new ZenModeBehaviorCallsPreferenceController( + mContext, mock(Lifecycle.class)); + ReflectionHelpers.setField(mController, "mBackend", mBackend); + } + + @Test + public void testIsAvailable() { + assertTrue(mController.isAvailable()); + } + + @Test + public void testHasSummary() { + Preference pref = mock(Preference.class); + mController.updateState(pref); + verify(pref).setSummary(any()); + } +} diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceControllerTest.java index 760efb281c..0bf8214426 100644 --- a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceControllerTest.java @@ -41,6 +41,7 @@ import androidx.preference.Preference; import androidx.preference.PreferenceScreen; import android.util.ArrayMap; +import com.android.settings.R; import com.android.settings.notification.AbstractZenModePreferenceController.ZenModeConfigWrapper; import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settingslib.core.lifecycle.Lifecycle; @@ -77,6 +78,7 @@ public class ZenModeBehaviorFooterPreferenceControllerTest { private Context mContext; private ContentResolver mContentResolver; + private int mTitleResId = R.string.zen_sound_title; @Before public void setup() { @@ -88,8 +90,8 @@ public class ZenModeBehaviorFooterPreferenceControllerTest { mContentResolver = RuntimeEnvironment.application.getContentResolver(); when(mNotificationManager.getZenModeConfig()).thenReturn(mZenModeConfig); - mController = - new ZenModeBehaviorFooterPreferenceController(mContext, mock(Lifecycle.class)); + mController = new ZenModeBehaviorFooterPreferenceController( + mContext, mock(Lifecycle.class), mTitleResId); ReflectionHelpers.setField(mController, "mZenModeConfigWrapper", mConfigWrapper); when(mPreferenceScreen.findPreference(mController.getPreferenceKey())) @@ -112,13 +114,13 @@ public class ZenModeBehaviorFooterPreferenceControllerTest { @Test public void priorityOnly_footerIsAvailable() { Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS); - assertFalse(mController.isAvailable()); + assertTrue(mController.isAvailable()); } @Test - public void zenModeOff_footerIsNotAvailable() { + public void zenModeOff_footerIsAvailable() { Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_OFF); - assertFalse(mController.isAvailable()); + assertTrue(mController.isAvailable()); } @Test @@ -126,7 +128,7 @@ public class ZenModeBehaviorFooterPreferenceControllerTest { Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_OFF); mController.updateState(mockPref); - verify(mockPref, never()).setTitle(any(String.class)); + verify(mockPref).setTitle(mContext.getString(mTitleResId)); } @Test @@ -134,7 +136,7 @@ public class ZenModeBehaviorFooterPreferenceControllerTest { Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS); mController.updateState(mockPref); - verify(mockPref, never()).setTitle(any(String.class)); + verify(mockPref).setTitle(mContext.getString(mTitleResId)); } @Test diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceControllerTest.java new file mode 100644 index 0000000000..e30fc71eff --- /dev/null +++ b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceControllerTest.java @@ -0,0 +1,79 @@ +/* + * 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 org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +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 androidx.preference.Preference; + +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.RuntimeEnvironment; +import org.robolectric.shadows.ShadowApplication; +import org.robolectric.util.ReflectionHelpers; + +@RunWith(SettingsRobolectricTestRunner.class) +public final class ZenModeBehaviorMsgEventReminderPreferenceControllerTest { + + private ZenModeBehaviorMsgEventReminderPreferenceController mController; + @Mock + private NotificationManager mNotificationManager; + @Mock + private NotificationManager.Policy mPolicy; + + private Context mContext; + @Mock + private ZenModeBackend mBackend; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + ShadowApplication shadowApplication = ShadowApplication.getInstance(); + shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager); + + mContext = RuntimeEnvironment.application; + when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy); + + mController = new ZenModeBehaviorMsgEventReminderPreferenceController( + mContext, mock(Lifecycle.class)); + ReflectionHelpers.setField(mController, "mBackend", mBackend); + } + + @Test + public void testIsAvailable() { + assertTrue(mController.isAvailable()); + } + + @Test + public void testHasSummary() { + Preference pref = mock(Preference.class); + mController.updateState(pref); + verify(pref).setSummary(any()); + } +} diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceControllerTest.java new file mode 100644 index 0000000000..d3fab8fdf2 --- /dev/null +++ b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceControllerTest.java @@ -0,0 +1,79 @@ +/* + * 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 org.junit.Assert.assertTrue; +import static org.mockito.Mockito.any; +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 androidx.preference.Preference; + +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.RuntimeEnvironment; +import org.robolectric.shadows.ShadowApplication; +import org.robolectric.util.ReflectionHelpers; + +@RunWith(SettingsRobolectricTestRunner.class) +public final class ZenModeBehaviorSoundPreferenceControllerTest { + + private ZenModeBehaviorSoundPreferenceController mController; + @Mock + private NotificationManager mNotificationManager; + @Mock + private NotificationManager.Policy mPolicy; + + private Context mContext; + @Mock + private ZenModeBackend mBackend; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + ShadowApplication shadowApplication = ShadowApplication.getInstance(); + shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager); + + mContext = RuntimeEnvironment.application; + when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy); + + mController = new ZenModeBehaviorSoundPreferenceController( + mContext, mock(Lifecycle.class)); + ReflectionHelpers.setField(mController, "mBackend", mBackend); + } + + @Test + public void testIsAvailable() { + assertTrue(mController.isAvailable()); + } + + @Test + public void testHasSummary() { + Preference pref = mock(Preference.class); + mController.updateState(pref); + verify(pref).setSummary(any()); + } +} diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java index b26989d347..5b2782fb6b 100644 --- a/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java +++ b/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java @@ -20,9 +20,9 @@ import static com.google.common.truth.Truth.assertThat; import static junit.framework.Assert.assertEquals; import android.app.NotificationManager; +import android.app.NotificationManager.Policy; import android.content.Context; import android.provider.SearchIndexableResource; -import android.provider.Settings; import com.android.settings.R; import com.android.settings.testutils.SettingsRobolectricTestRunner; @@ -47,54 +47,140 @@ public class ZenModeSettingsTest { } @Test - public void testGetBehaviorSettingSummary_noSoundsCanBypass() { - NotificationManager.Policy policy = new NotificationManager.Policy(0, 0, 0); - final String result = mBuilder.getBehaviorSettingSummary(policy, - Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS); - - String totalSilence = mContext.getString(R.string.zen_mode_no_exceptions); - assertEquals(totalSilence, result); - } - - @Test - public void testGetBehaviorSettingSummary_alarmsAndMedia() { - NotificationManager.Policy policy = new NotificationManager.Policy( - NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS - | NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA, - 0, 0); - final String result = mBuilder.getBehaviorSettingSummary(policy, - Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS); - - String alarmsAndMedia = mContext.getString(R.string.join_two_items, - mContext.getString(R.string.zen_mode_alarms), - mContext.getString(R.string.zen_mode_media).toLowerCase()); - assertEquals(alarmsAndMedia, result); - } - - @Test public void testBlockedEffectsSummary_none() { - NotificationManager.Policy policy = new NotificationManager.Policy(0, 0, 0, 0); + Policy policy = new Policy(0, 0, 0, 0); assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_muted), mBuilder.getBlockedEffectsSummary(policy)); } @Test public void testBlockedEffectsSummary_some() { - NotificationManager.Policy policy = new NotificationManager.Policy( - 0, 0, 0, NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK); + Policy policy = new Policy(0, 0, 0, NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK); assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_custom), mBuilder.getBlockedEffectsSummary(policy)); } @Test public void testBlockedEffectsSummary_all() { - NotificationManager.Policy policy = new NotificationManager.Policy( - 0, 0, 0, 511); + Policy policy = new Policy(0, 0, 0, 511); assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_hidden), mBuilder.getBlockedEffectsSummary(policy)); } @Test + public void testGetMsgEventReminderSettingSummary_none() { + Policy policy = new Policy(0, 0, 0, 0); + assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("None"); + } + + @Test + public void testGetMsgEventReminderSettingSummary_single() { + Policy policy = new Policy( + Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_EVENTS, 0 , 0 , 0); + assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Events"); + } + + @Test + public void testGetMsgEventReminderSettingSummary_someMsgs() { + Policy policy = new Policy(Policy.PRIORITY_CATEGORY_MESSAGES, 0, + Policy.PRIORITY_SENDERS_CONTACTS , 0); + assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Some messages"); + + policy = new Policy(Policy.PRIORITY_CATEGORY_MESSAGES, 0, + Policy.PRIORITY_SENDERS_STARRED , 0); + assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Some messages"); + } + + @Test + public void testGetMsgEventReminderSettingSummary_msgs() { + Policy policy = new Policy(Policy.PRIORITY_CATEGORY_MESSAGES, 0, 0, 0); + assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Messages"); + } + + @Test + public void testGetMsgEventReminderSettingSummary_someMsgsAndOther() { + Policy policy = new Policy( + Policy.PRIORITY_CATEGORY_MESSAGES | Policy.PRIORITY_CATEGORY_REMINDERS, + 0, Policy.PRIORITY_SENDERS_CONTACTS , 0); + assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)) + .isEqualTo("Some messages and reminders"); + } + + @Test + public void testGetMsgEventReminderSettingSummary_someMsgsAndAllOthers() { + Policy policy = new Policy(Policy.PRIORITY_CATEGORY_EVENTS + | Policy.PRIORITY_CATEGORY_MESSAGES | Policy.PRIORITY_CATEGORY_REMINDERS, + 0, Policy.PRIORITY_SENDERS_CONTACTS , 0); + assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)) + .isEqualTo("Some messages, events, and reminders"); + } + + @Test + public void testGetMsgEventReminderSettingSummary_noMsgsAndOther() { + Policy policy = new Policy( + Policy.PRIORITY_CATEGORY_EVENTS | Policy.PRIORITY_CATEGORY_REMINDERS, + 0,0, 0); + assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)) + .isEqualTo("Events and reminders"); + } + + @Test + public void testGetCallsSettingSummary_none() { + Policy policy = new Policy(0, 0, 0, 0); + assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("None"); + } + + @Test + public void testGetCallsSettingSummary_contacts() { + Policy policy = new Policy(Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_CALLS, + Policy.PRIORITY_SENDERS_CONTACTS, 0, 0); + assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("From contacts only"); + } + + @Test + public void testGetCallsSettingSummary_repeatCallers() { + Policy policy = new Policy(Policy.PRIORITY_CATEGORY_REPEAT_CALLERS, 0, 0, 0); + assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("From repeat callers only"); + } + + @Test + public void testGetCallsSettingSummary_starredRepeatCallers() { + Policy policy = new Policy( + Policy.PRIORITY_CATEGORY_REPEAT_CALLERS | Policy.PRIORITY_CATEGORY_CALLS, + Policy.PRIORITY_SENDERS_STARRED, 0, 0); + assertThat(mBuilder.getCallsSettingSummary(policy)) + .isEqualTo("From starred contacts and repeat callers"); + } + + @Test + public void testGetSoundSettingSummary_allOff() { + Policy policy = new Policy(0, 0, 0, 0); + assertThat(mBuilder.getSoundSettingSummary(policy)).isEqualTo("Muted"); + } + + @Test + public void testGetSoundSettingSummary_allOn() { + Policy policy = new Policy(Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_SYSTEM + | Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0); + assertThat(mBuilder.getSoundSettingSummary(policy)) + .isEqualTo("Muted, but allow alarms, media, and touch sounds"); + } + + @Test + public void testGetSoundSettingSummary_allOffButOne() { + Policy policy = new Policy(Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0); + assertThat(mBuilder.getSoundSettingSummary(policy)).isEqualTo("Muted, but allow media"); + } + + @Test + public void testGetSoundSettingSummary_allOffButTwo() { + Policy policy = new Policy(Policy.PRIORITY_CATEGORY_SYSTEM + | Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0); + assertThat(mBuilder.getSoundSettingSummary(policy)) + .isEqualTo("Muted, but allow media and touch sounds"); + } + + @Test public void searchProvider_shouldIndexDefaultXml() { final List sir = ZenModeSettings.SEARCH_INDEX_DATA_PROVIDER .getXmlResourcesToIndex(mContext, true /* enabled */); -- 2.11.0