diff --git a/res/values/strings.xml b/res/values/strings.xml
index 56dbc6b8e97..7a449284589 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -7185,20 +7185,26 @@
No sound except alarms and media
- Turn on automatically
+ Schedules
- Automatic rules
+ Do Not Disturb
Automatic rule
+
+ Schedule
+
Silence phone at certain times
Set Do Not Disturb rules
+
+ Schedule
+
Use rule
@@ -7221,10 +7227,10 @@
Allow visual signals
- When Do Not Disturb is turned on
+ When Do Not Disturb is on
-
- Notifications
+
+ Notification restrictions
No sound from notifications
@@ -7356,15 +7362,15 @@
- %d rules can turn on automatically
-
- Behavior
-
+
+ Mute phone, but allow exceptions
+
Exceptions
Schedule
-
- Sound & vibration
+
+ See all exceptions
When Do Not Disturb is on, sound and vibration will be muted, except for the items you allow above.
@@ -7816,8 +7822,8 @@
Rule name already in use
-
- Add rule
+
+ Add more
Add event rule
@@ -7942,6 +7948,9 @@
Messages
+
+ When Do Not Disturb is on, incoming text messages are blocked. You can adjust settings to allow your friends, family, or other contacts to reach you.
+
Allow messages
@@ -7978,42 +7987,36 @@
None
-
- Alarms
+
+ Allow alarms
alarms
-
- Media
+
+ Allow media
media
-
- Touch sounds
+
+ Allow touch sounds
touch sounds
-
- Reminders
+
+ Allow reminders
reminders
-
- Allow reminders
-
-
- Events
+
+ Allow events
events
-
- Allow events
-
anyone
diff --git a/res/xml/zen_mode_automation_settings.xml b/res/xml/zen_mode_automation_settings.xml
index 99826eaac84..dade454312e 100644
--- a/res/xml/zen_mode_automation_settings.xml
+++ b/res/xml/zen_mode_automation_settings.xml
@@ -19,9 +19,9 @@
android:key="zen_mode_automation_settings_page"
android:title="@string/zen_mode_automation_settings_page_title" >
-
+ android:key="zen_mode_automatic_rules"
+ android:title="@string/zen_mode_schedule_title">
diff --git a/res/xml/zen_mode_calls_settings.xml b/res/xml/zen_mode_calls_settings.xml
index 2da022c56a1..74b6986f3cc 100644
--- a/res/xml/zen_mode_calls_settings.xml
+++ b/res/xml/zen_mode_calls_settings.xml
@@ -17,6 +17,7 @@
diff --git a/res/xml/zen_mode_messages_settings.xml b/res/xml/zen_mode_messages_settings.xml
new file mode 100644
index 00000000000..4ca6c92c020
--- /dev/null
+++ b/res/xml/zen_mode_messages_settings.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/xml/zen_mode_msg_event_reminder_settings.xml b/res/xml/zen_mode_msg_event_reminder_settings.xml
deleted file mode 100644
index 8fc6b4717be..00000000000
--- a/res/xml/zen_mode_msg_event_reminder_settings.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/res/xml/zen_mode_settings.xml b/res/xml/zen_mode_settings.xml
index b8af6505b62..19664840239 100644
--- a/res/xml/zen_mode_settings.xml
+++ b/res/xml/zen_mode_settings.xml
@@ -25,62 +25,59 @@
-
+
+
+
+
+
+
+
+
+
+
-
-
-
+ android:fragment="com.android.settings.notification.ZenModeSoundVibrationSettings"
+ android:icon="@drawable/ic_chevron_right_24dp"/>
-
-
-
+
+
-
+
+
-
-
-
-
-
-
-
+
+
-
-
-
-
+
-
-
-
+
+
diff --git a/res/xml/zen_mode_sound_vibration_settings.xml b/res/xml/zen_mode_sound_vibration_settings.xml
index b3b81395ed9..3d1da2fec8c 100644
--- a/res/xml/zen_mode_sound_vibration_settings.xml
+++ b/res/xml/zen_mode_sound_vibration_settings.xml
@@ -18,11 +18,24 @@
+ android:title="@string/zen_category_exceptions" >
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/com/android/settings/notification/ZenModeAlarmsPreferenceController.java b/src/com/android/settings/notification/ZenModeAlarmsPreferenceController.java
index 96495dfbf76..67d9e9374c2 100644
--- a/src/com/android/settings/notification/ZenModeAlarmsPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeAlarmsPreferenceController.java
@@ -21,19 +21,20 @@ import android.content.Context;
import android.provider.Settings;
import android.util.Log;
-import androidx.preference.Preference;
-import androidx.preference.SwitchPreference;
-
import com.android.internal.logging.nano.MetricsProto;
import com.android.settingslib.core.lifecycle.Lifecycle;
+import androidx.preference.Preference;
+import androidx.preference.SwitchPreference;
+
public class ZenModeAlarmsPreferenceController extends
AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
- protected static final String KEY = "zen_mode_alarms";
+ private final String KEY;
- public ZenModeAlarmsPreferenceController(Context context, Lifecycle lifecycle) {
- super(context, KEY, lifecycle);
+ public ZenModeAlarmsPreferenceController(Context context, Lifecycle lifecycle, String key) {
+ super(context, key, lifecycle);
+ KEY = key;
}
@Override
diff --git a/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceController.java b/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceController.java
deleted file mode 100644
index 0dba4d6dd5d..00000000000
--- a/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceController.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.notification;
-
-import android.content.Context;
-
-import androidx.preference.Preference;
-
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-
-public class ZenModeBehaviorCallsPreferenceController extends
- AbstractZenModePreferenceController implements PreferenceControllerMixin {
-
- protected static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_calls_settings";
- private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
-
- public ZenModeBehaviorCallsPreferenceController(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.getCallsSettingSummary(getPolicy()));
- }
-}
diff --git a/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceController.java b/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceController.java
deleted file mode 100644
index 2046244c622..00000000000
--- a/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceController.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.notification;
-
-import android.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
deleted file mode 100644
index 425f7709374..00000000000
--- a/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceController.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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/ZenModeCallsPreferenceController.java b/src/com/android/settings/notification/ZenModeCallsPreferenceController.java
index 3f689d7b4f2..5bacafbec04 100644
--- a/src/com/android/settings/notification/ZenModeCallsPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeCallsPreferenceController.java
@@ -16,36 +16,29 @@
package com.android.settings.notification;
-import android.app.NotificationManager;
import android.content.Context;
-import android.provider.Settings;
-import android.text.TextUtils;
-import androidx.annotation.VisibleForTesting;
-import androidx.preference.ListPreference;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.R;
+import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
-public class ZenModeCallsPreferenceController extends AbstractZenModePreferenceController implements
- Preference.OnPreferenceChangeListener {
+import androidx.preference.Preference;
- protected static final String KEY = "zen_mode_calls";
- private final ZenModeBackend mBackend;
- private ListPreference mPreference;
- private final String[] mListValues;
+public class ZenModeCallsPreferenceController extends
+ AbstractZenModePreferenceController implements PreferenceControllerMixin {
- public ZenModeCallsPreferenceController(Context context, Lifecycle lifecycle) {
- super(context, KEY, lifecycle);
- mBackend = ZenModeBackend.getInstance(context);
- mListValues = context.getResources().getStringArray(R.array.zen_mode_contacts_values);
+ private final String KEY_BEHAVIOR_SETTINGS;
+ private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
+
+ public ZenModeCallsPreferenceController(Context context, Lifecycle lifecycle,
+ String key) {
+ super(context, key, lifecycle);
+ KEY_BEHAVIOR_SETTINGS = key;
+ mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
}
@Override
public String getPreferenceKey() {
- return KEY;
+ return KEY_BEHAVIOR_SETTINGS;
}
@Override
@@ -53,55 +46,10 @@ public class ZenModeCallsPreferenceController extends AbstractZenModePreferenceC
return true;
}
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- mPreference = (ListPreference) screen.findPreference(KEY);
- }
-
@Override
public void updateState(Preference preference) {
super.updateState(preference);
- updateFromContactsValue(preference);
- }
- @Override
- public boolean onPreferenceChange(Preference preference, Object selectedContactsFrom) {
- mBackend.saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS,
- ZenModeBackend.getSettingFromPrefKey(selectedContactsFrom.toString()));
- updateFromContactsValue(preference);
- return true;
- }
-
- private void updateFromContactsValue(Preference preference) {
- mPreference = (ListPreference) preference;
- switch (getZenMode()) {
- case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
- case Settings.Global.ZEN_MODE_ALARMS:
- mPreference.setEnabled(false);
- mPreference.setValue(ZenModeBackend.ZEN_MODE_FROM_NONE);
- mPreference.setSummary(mBackend.getContactsSummary(ZenModeBackend.SOURCE_NONE));
- break;
- default:
- preference.setEnabled(true);
- preference.setSummary(mBackend.getContactsSummary(
- NotificationManager.Policy.PRIORITY_CATEGORY_CALLS));
-
- final String currentVal = ZenModeBackend.getKeyFromSetting(
- mBackend.getPriorityCallSenders());
- mPreference.setValue(mListValues[getIndexOfSendersValue(currentVal)]);
- }
- }
-
- @VisibleForTesting
- protected int getIndexOfSendersValue(String currentVal) {
- int index = 3; // defaults to "none" based on R.array.zen_mode_contacts_values
- for (int i = 0; i < mListValues.length; i++) {
- if (TextUtils.equals(currentVal, mListValues[i])) {
- return i;
- }
- }
-
- return index;
+ preference.setSummary(mSummaryBuilder.getCallsSettingSummary(getPolicy()));
}
}
diff --git a/src/com/android/settings/notification/ZenModeCallsSettings.java b/src/com/android/settings/notification/ZenModeCallsSettings.java
index 6ba53b5bf9d..fa77bb04a39 100644
--- a/src/com/android/settings/notification/ZenModeCallsSettings.java
+++ b/src/com/android/settings/notification/ZenModeCallsSettings.java
@@ -43,7 +43,7 @@ public class ZenModeCallsSettings extends ZenModeSettingsBase implements Indexab
private static List buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
List controllers = new ArrayList<>();
- controllers.add(new ZenModeCallsPreferenceController(context, lifecycle));
+ controllers.add(new ZenModePriorityCallsPreferenceController(context, lifecycle));
controllers.add(new ZenModeStarredContactsPreferenceController(context, lifecycle,
PRIORITY_CATEGORY_CALLS, "zen_mode_starred_contacts_callers"));
controllers.add(new ZenModeRepeatCallersPreferenceController(context, lifecycle,
diff --git a/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java b/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java
index 321d94efa7f..19ee809732b 100644
--- a/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java
@@ -1,31 +1,38 @@
+/*
+ * 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.app.NotificationManager;
import android.content.Context;
-import android.provider.Settings;
-import android.text.TextUtils;
-import androidx.annotation.VisibleForTesting;
-import androidx.preference.ListPreference;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.R;
+import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
-public class ZenModeMessagesPreferenceController extends AbstractZenModePreferenceController
- implements Preference.OnPreferenceChangeListener {
+import androidx.preference.Preference;
- protected static final String KEY = "zen_mode_messages";
+public class ZenModeMessagesPreferenceController extends
+ AbstractZenModePreferenceController implements PreferenceControllerMixin {
- private final ZenModeBackend mBackend;
- private ListPreference mPreference;
- private final String[] mListValues;
+ private final String KEY;
+ private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
- public ZenModeMessagesPreferenceController(Context context, Lifecycle lifecycle) {
- super(context, KEY, lifecycle);
- mBackend = ZenModeBackend.getInstance(context);
- mListValues = context.getResources().getStringArray(R.array.zen_mode_contacts_values);
+ public ZenModeMessagesPreferenceController(Context context, Lifecycle lifecycle, String key) {
+ super(context, key, lifecycle);
+ KEY = key;
+ mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
}
@Override
@@ -38,55 +45,9 @@ public class ZenModeMessagesPreferenceController extends AbstractZenModePreferen
return true;
}
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- mPreference = (ListPreference) screen.findPreference(KEY);
- }
-
@Override
public void updateState(Preference preference) {
super.updateState(preference);
- updateFromContactsValue(preference);
- }
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object selectedContactsFrom) {
- mBackend.saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES,
- ZenModeBackend.getSettingFromPrefKey(selectedContactsFrom.toString()));
- updateFromContactsValue(preference);
- return true;
- }
-
- private void updateFromContactsValue(Preference preference) {
- mPreference = (ListPreference) preference;
- switch (getZenMode()) {
- case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
- case Settings.Global.ZEN_MODE_ALARMS:
- mPreference.setEnabled(false);
- mPreference.setValue(ZenModeBackend.ZEN_MODE_FROM_NONE);
- mPreference.setSummary(mBackend.getContactsSummary(ZenModeBackend.SOURCE_NONE));
- break;
- default:
- preference.setEnabled(true);
- preference.setSummary(mBackend.getContactsSummary(
- NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES));
-
- final String currentVal = ZenModeBackend.getKeyFromSetting(
- mBackend.getPriorityMessageSenders());
- mPreference.setValue(mListValues[getIndexOfSendersValue(currentVal)]);
- }
- }
-
- @VisibleForTesting
- protected int getIndexOfSendersValue(String currentVal) {
- int index = 3; // defaults to "none" based on R.array.zen_mode_contacts_values
- for (int i = 0; i < mListValues.length; i++) {
- if (TextUtils.equals(currentVal, mListValues[i])) {
- return i;
- }
- }
-
- return index;
+ // TODO: (b/111475013 - beverlyt) set messages summary
}
}
diff --git a/src/com/android/settings/notification/ZenModeMsgEventReminderSettings.java b/src/com/android/settings/notification/ZenModeMessagesSettings.java
similarity index 75%
rename from src/com/android/settings/notification/ZenModeMsgEventReminderSettings.java
rename to src/com/android/settings/notification/ZenModeMessagesSettings.java
index 0e6747a6f57..e09d5839084 100644
--- a/src/com/android/settings/notification/ZenModeMsgEventReminderSettings.java
+++ b/src/com/android/settings/notification/ZenModeMessagesSettings.java
@@ -33,7 +33,7 @@ import java.util.ArrayList;
import java.util.List;
@SearchIndexable
-public class ZenModeMsgEventReminderSettings extends ZenModeSettingsBase implements Indexable {
+public class ZenModeMessagesSettings extends ZenModeSettingsBase implements Indexable {
@Override
protected List createPreferenceControllers(Context context) {
@@ -43,19 +43,17 @@ public class ZenModeMsgEventReminderSettings extends ZenModeSettingsBase impleme
private static List buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
List controllers = new ArrayList<>();
- controllers.add(new ZenModeEventsPreferenceController(context, lifecycle));
- controllers.add(new ZenModeRemindersPreferenceController(context, lifecycle));
- controllers.add(new ZenModeMessagesPreferenceController(context, lifecycle));
+ controllers.add(new ZenModePriorityMessagesPreferenceController(context, lifecycle));
controllers.add(new ZenModeStarredContactsPreferenceController(context, lifecycle,
PRIORITY_CATEGORY_MESSAGES, "zen_mode_starred_contacts_messages"));
- controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle,
- R.string.zen_msg_event_reminder_footer));
+ controllers.add(new ZenModeBehaviorFooterPreferenceController(
+ context, lifecycle, R.string.zen_mode_messages_footer));
return controllers;
}
@Override
protected int getPreferenceScreenResId() {
- return R.xml.zen_mode_msg_event_reminder_settings;
+ return R.xml.zen_mode_messages_settings;
}
@Override
@@ -66,7 +64,7 @@ public class ZenModeMsgEventReminderSettings extends ZenModeSettingsBase impleme
/**
* For Search.
*/
- public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -75,14 +73,15 @@ public class ZenModeMsgEventReminderSettings extends ZenModeSettingsBase impleme
final ArrayList result = new ArrayList<>();
final SearchIndexableResource sir = new SearchIndexableResource(context);
- sir.xmlResId = R.xml.zen_mode_msg_event_reminder_settings;
+ sir.xmlResId = R.xml.zen_mode_messages_settings;
result.add(sir);
return result;
}
- @Override
- public List createPreferenceControllers(Context context) {
- return buildPreferenceControllers(context, null);
- }
- };
+ @Override
+ public List createPreferenceControllers(
+ Context context) {
+ return buildPreferenceControllers(context, null);
+ }
+ };
}
diff --git a/src/com/android/settings/notification/ZenModePriorityCallsPreferenceController.java b/src/com/android/settings/notification/ZenModePriorityCallsPreferenceController.java
new file mode 100644
index 00000000000..44b6c2474f8
--- /dev/null
+++ b/src/com/android/settings/notification/ZenModePriorityCallsPreferenceController.java
@@ -0,0 +1,107 @@
+/*
+ * 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.app.NotificationManager;
+import android.content.Context;
+import android.provider.Settings;
+import android.text.TextUtils;
+
+import com.android.settings.R;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+public class ZenModePriorityCallsPreferenceController extends AbstractZenModePreferenceController
+ implements Preference.OnPreferenceChangeListener {
+
+ protected static final String KEY = "zen_mode_calls";
+ private final ZenModeBackend mBackend;
+ private ListPreference mPreference;
+ private final String[] mListValues;
+
+ public ZenModePriorityCallsPreferenceController(Context context, Lifecycle lifecycle) {
+ super(context, KEY, lifecycle);
+ mBackend = ZenModeBackend.getInstance(context);
+ mListValues = context.getResources().getStringArray(R.array.zen_mode_contacts_values);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = (ListPreference) screen.findPreference(KEY);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ updateFromContactsValue(preference);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object selectedContactsFrom) {
+ mBackend.saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS,
+ ZenModeBackend.getSettingFromPrefKey(selectedContactsFrom.toString()));
+ updateFromContactsValue(preference);
+ return true;
+ }
+
+ private void updateFromContactsValue(Preference preference) {
+ mPreference = (ListPreference) preference;
+ switch (getZenMode()) {
+ case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
+ case Settings.Global.ZEN_MODE_ALARMS:
+ mPreference.setEnabled(false);
+ mPreference.setValue(ZenModeBackend.ZEN_MODE_FROM_NONE);
+ mPreference.setSummary(mBackend.getContactsSummary(ZenModeBackend.SOURCE_NONE));
+ break;
+ default:
+ preference.setEnabled(true);
+ preference.setSummary(mBackend.getContactsSummary(
+ NotificationManager.Policy.PRIORITY_CATEGORY_CALLS));
+
+ final String currentVal = ZenModeBackend.getKeyFromSetting(
+ mBackend.getPriorityCallSenders());
+ mPreference.setValue(mListValues[getIndexOfSendersValue(currentVal)]);
+ }
+ }
+
+ @VisibleForTesting
+ protected int getIndexOfSendersValue(String currentVal) {
+ int index = 3; // defaults to "none" based on R.array.zen_mode_contacts_values
+ for (int i = 0; i < mListValues.length; i++) {
+ if (TextUtils.equals(currentVal, mListValues[i])) {
+ return i;
+ }
+ }
+
+ return index;
+ }
+}
diff --git a/src/com/android/settings/notification/ZenModePriorityMessagesPreferenceController.java b/src/com/android/settings/notification/ZenModePriorityMessagesPreferenceController.java
new file mode 100644
index 00000000000..56829a74acb
--- /dev/null
+++ b/src/com/android/settings/notification/ZenModePriorityMessagesPreferenceController.java
@@ -0,0 +1,107 @@
+/*
+ * 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.app.NotificationManager;
+import android.content.Context;
+import android.provider.Settings;
+import android.text.TextUtils;
+
+import com.android.settings.R;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+public class ZenModePriorityMessagesPreferenceController extends AbstractZenModePreferenceController
+ implements Preference.OnPreferenceChangeListener {
+
+ protected static final String KEY = "zen_mode_messages";
+ private final ZenModeBackend mBackend;
+ private ListPreference mPreference;
+ private final String[] mListValues;
+
+ public ZenModePriorityMessagesPreferenceController(Context context, Lifecycle lifecycle) {
+ super(context, KEY, lifecycle);
+ mBackend = ZenModeBackend.getInstance(context);
+ mListValues = context.getResources().getStringArray(R.array.zen_mode_contacts_values);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = (ListPreference) screen.findPreference(KEY);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ updateFromContactsValue(preference);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object selectedContactsFrom) {
+ mBackend.saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES,
+ ZenModeBackend.getSettingFromPrefKey(selectedContactsFrom.toString()));
+ updateFromContactsValue(preference);
+ return true;
+ }
+
+ private void updateFromContactsValue(Preference preference) {
+ mPreference = (ListPreference) preference;
+ switch (getZenMode()) {
+ case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
+ case Settings.Global.ZEN_MODE_ALARMS:
+ mPreference.setEnabled(false);
+ mPreference.setValue(ZenModeBackend.ZEN_MODE_FROM_NONE);
+ mPreference.setSummary(mBackend.getContactsSummary(ZenModeBackend.SOURCE_NONE));
+ break;
+ default:
+ preference.setEnabled(true);
+ preference.setSummary(mBackend.getContactsSummary(
+ NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES));
+
+ final String currentVal = ZenModeBackend.getKeyFromSetting(
+ mBackend.getPriorityMessageSenders());
+ mPreference.setValue(mListValues[getIndexOfSendersValue(currentVal)]);
+ }
+ }
+
+ @VisibleForTesting
+ protected int getIndexOfSendersValue(String currentVal) {
+ int index = 3; // defaults to "none" based on R.array.zen_mode_contacts_values
+ for (int i = 0; i < mListValues.length; i++) {
+ if (TextUtils.equals(currentVal, mListValues[i])) {
+ return i;
+ }
+ }
+
+ return index;
+ }
+}
diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java
index 9cd310724bf..3a270d2ed98 100644
--- a/src/com/android/settings/notification/ZenModeSettings.java
+++ b/src/com/android/settings/notification/ZenModeSettings.java
@@ -82,9 +82,12 @@ public class ZenModeSettings extends ZenModeSettingsBase {
private static List buildPreferenceControllers(Context context,
Lifecycle lifecycle, FragmentManager fragmentManager) {
List controllers = new ArrayList<>();
- controllers.add(new ZenModeBehaviorMsgEventReminderPreferenceController(context, lifecycle));
- controllers.add(new ZenModeBehaviorSoundPreferenceController(context, lifecycle));
- controllers.add(new ZenModeBehaviorCallsPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeCallsPreferenceController(context, lifecycle,
+ "zen_mode_behavior_calls"));
+ controllers.add(new ZenModeMessagesPreferenceController(context, lifecycle,
+ "zen_mode_behavior_messages"));
+ controllers.add(new ZenModeAlarmsPreferenceController(context, lifecycle,
+ "zen_mode_behavior_alarms"));
controllers.add(new ZenModeBlockedEffectsPreferenceController(context, lifecycle));
controllers.add(new ZenModeDurationPreferenceController(context, lifecycle));
controllers.add(new ZenModeAutomationPreferenceController(context));
diff --git a/src/com/android/settings/notification/ZenModeSoundVibrationSettings.java b/src/com/android/settings/notification/ZenModeSoundVibrationSettings.java
index 32ff2d1d30e..df924468924 100644
--- a/src/com/android/settings/notification/ZenModeSoundVibrationSettings.java
+++ b/src/com/android/settings/notification/ZenModeSoundVibrationSettings.java
@@ -16,6 +16,8 @@
package com.android.settings.notification;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES;
+
import android.content.Context;
import android.provider.SearchIndexableResource;
@@ -41,9 +43,16 @@ public class ZenModeSoundVibrationSettings extends ZenModeSettingsBase implement
private static List buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
List controllers = new ArrayList<>();
- controllers.add(new ZenModeAlarmsPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeCallsPreferenceController(context, lifecycle,
+ "zen_mode_calls_settings"));
+ controllers.add(new ZenModeMessagesPreferenceController(context, lifecycle,
+ "zen_mode_messages_settings"));
+ controllers.add(new ZenModeAlarmsPreferenceController(context, lifecycle,
+ "zen_mode_alarms"));
controllers.add(new ZenModeMediaPreferenceController(context, lifecycle));
controllers.add(new ZenModeSystemPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeRemindersPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeEventsPreferenceController(context, lifecycle));
controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle,
R.string.zen_sound_footer));
return controllers;
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeAlarmsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeAlarmsPreferenceControllerTest.java
index 67021187142..df4df51e857 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeAlarmsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeAlarmsPreferenceControllerTest.java
@@ -30,9 +30,6 @@ import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
-import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
-
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -45,6 +42,9 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+
@RunWith(SettingsRobolectricTestRunner.class)
public class ZenModeAlarmsPreferenceControllerTest {
@@ -75,7 +75,8 @@ public class ZenModeAlarmsPreferenceControllerTest {
mContext = RuntimeEnvironment.application;
mContentResolver = RuntimeEnvironment.application.getContentResolver();
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
- mController = new ZenModeAlarmsPreferenceController(mContext, mock(Lifecycle.class));
+ mController = new ZenModeAlarmsPreferenceController(mContext, mock(Lifecycle.class),
+ "zen_mode_behavior_alarms");
ReflectionHelpers.setField(mController, "mBackend", mBackend);
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceControllerTest.java
deleted file mode 100644
index f1f1b2ea488..00000000000
--- a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceControllerTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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/ZenModeBehaviorMsgEventReminderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceControllerTest.java
deleted file mode 100644
index 11cdfcc2697..00000000000
--- a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceControllerTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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
deleted file mode 100644
index c854e8ad357..00000000000
--- a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceControllerTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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/ZenModeCallsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeCallsPreferenceControllerTest.java
index 79619a74446..fdc43f3fcbd 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeCallsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeCallsPreferenceControllerTest.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.
@@ -16,24 +16,15 @@
package com.android.settings.notification;
-import static android.provider.Settings.Global.ZEN_MODE;
-import static android.provider.Settings.Global.ZEN_MODE_ALARMS;
-import static android.provider.Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
-import static android.provider.Settings.Global.ZEN_MODE_NO_INTERRUPTIONS;
-
+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.ContentResolver;
import android.content.Context;
-import android.provider.Settings;
-import androidx.preference.ListPreference;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -46,32 +37,20 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
+import androidx.preference.Preference;
+
@RunWith(SettingsRobolectricTestRunner.class)
-public class ZenModeCallsPreferenceControllerTest {
+public final class ZenModeCallsPreferenceControllerTest {
private ZenModeCallsPreferenceController mController;
-
- @Mock
- private ZenModeBackend mBackend;
@Mock
private NotificationManager mNotificationManager;
@Mock
- private ListPreference mockPref;
- @Mock
private NotificationManager.Policy mPolicy;
- @Mock
- private PreferenceScreen mPreferenceScreen;
- private ContentResolver mContentResolver;
- private Context mContext;
- /**
- * Array Values Key
- * 0: anyone
- * 1: contacts
- * 2: starred
- * 3: none
- */
- private String[] mValues;
+ private Context mContext;
+ @Mock
+ private ZenModeBackend mBackend;
@Before
public void setup() {
@@ -80,100 +59,22 @@ public class ZenModeCallsPreferenceControllerTest {
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
mContext = RuntimeEnvironment.application;
- mValues = mContext.getResources().getStringArray(R.array.zen_mode_contacts_values);
- mContentResolver = RuntimeEnvironment.application.getContentResolver();
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
- when(mBackend.getPriorityCallSenders())
- .thenReturn(NotificationManager.Policy.PRIORITY_SENDERS_STARRED);
- when(mBackend.getContactsSummary(ZenModeBackend.SOURCE_NONE))
- .thenCallRealMethod();
- when(mBackend.getContactsSummary(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
- .thenCallRealMethod();
-
- mController = new ZenModeCallsPreferenceController(mContext, mock(Lifecycle.class));
+ mController = new ZenModeCallsPreferenceController(
+ mContext, mock(Lifecycle.class), "zen_mode_calls_settings");
ReflectionHelpers.setField(mController, "mBackend", mBackend);
-
- when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
- mockPref);
- mController.displayPreference(mPreferenceScreen);
}
@Test
- public void updateState_TotalSilence() {
- Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_NO_INTERRUPTIONS);
-
- when(mBackend.isPriorityCategoryEnabled(
- NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
- .thenReturn(false);
- final ListPreference mockPref = mock(ListPreference.class);
- mController.updateState(mockPref);
-
- verify(mockPref).setEnabled(false);
- verify(mockPref).setSummary(R.string.zen_mode_from_none);
+ public void testIsAvailable() {
+ assertTrue(mController.isAvailable());
}
@Test
- public void updateState_AlarmsOnly() {
- Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_ALARMS);
-
- final ListPreference mockPref = mock(ListPreference.class);
- mController.updateState(mockPref);
-
- verify(mockPref).setEnabled(false);
- verify(mockPref).setSummary(R.string.zen_mode_from_none);
+ public void testHasSummary() {
+ Preference pref = mock(Preference.class);
+ mController.updateState(pref);
+ verify(pref).setSummary(any());
}
-
- @Test
- public void updateState_Priority() {
- Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
-
- when(mBackend.isPriorityCategoryEnabled(
- NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
- .thenReturn(true);
-
- mController.updateState(mockPref);
-
- verify(mockPref).setEnabled(true);
- verify(mockPref).setSummary(R.string.zen_mode_from_starred);
- }
-
- @Test
- public void onPreferenceChange_setSelectedContacts_any() {
- Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
- when(mBackend.getPriorityCallSenders()).thenReturn(
- NotificationManager.Policy.PRIORITY_SENDERS_ANY);
- mController.updateState(mockPref);
- verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
- ZenModeBackend.ZEN_MODE_FROM_ANYONE)]);
- }
-
- @Test
- public void onPreferenceChange_setSelectedContacts_none() {
- Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
- when(mBackend.getPriorityCallSenders()).thenReturn(ZenModeBackend.SOURCE_NONE);
- mController.updateState(mockPref);
- verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
- ZenModeBackend.ZEN_MODE_FROM_NONE)]);
- }
-
- @Test
- public void onPreferenceChange_setSelectedContacts_starred() {
- Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
- when(mBackend.getPriorityCallSenders()).thenReturn(
- NotificationManager.Policy.PRIORITY_SENDERS_STARRED);
- mController.updateState(mockPref);
- verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
- ZenModeBackend.ZEN_MODE_FROM_STARRED)]);
- }
-
- @Test
- public void onPreferenceChange_setSelectedContacts_contacts() {
- Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
- when(mBackend.getPriorityCallSenders()).thenReturn(
- NotificationManager.Policy.PRIORITY_SENDERS_CONTACTS);
- mController.updateState(mockPref);
- verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
- ZenModeBackend.ZEN_MODE_FROM_CONTACTS)]);
- }
-}
\ No newline at end of file
+}
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeMessagesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeMessagesPreferenceControllerTest.java
index 0ff0665334e..890f6c2afb2 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeMessagesPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeMessagesPreferenceControllerTest.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.
@@ -16,24 +16,13 @@
package com.android.settings.notification;
-import static android.provider.Settings.Global.ZEN_MODE;
-import static android.provider.Settings.Global.ZEN_MODE_ALARMS;
-import static android.provider.Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
-import static android.provider.Settings.Global.ZEN_MODE_NO_INTERRUPTIONS;
-
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.NotificationManager;
-import android.content.ContentResolver;
import android.content.Context;
-import android.provider.Settings;
-import androidx.preference.ListPreference;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -47,31 +36,17 @@ import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
-public class ZenModeMessagesPreferenceControllerTest {
+public final class ZenModeMessagesPreferenceControllerTest {
private ZenModeMessagesPreferenceController mController;
-
- @Mock
- private ZenModeBackend mBackend;
@Mock
private NotificationManager mNotificationManager;
@Mock
- private ListPreference mockPref;
- @Mock
private NotificationManager.Policy mPolicy;
- @Mock
- private PreferenceScreen mPreferenceScreen;
- private ContentResolver mContentResolver;
- private Context mContext;
- /**
- * Array Values Key
- * 0: anyone
- * 1: contacts
- * 2: starred
- * 3: none
- */
- private String[] mValues;
+ private Context mContext;
+ @Mock
+ private ZenModeBackend mBackend;
@Before
public void setup() {
@@ -80,100 +55,23 @@ public class ZenModeMessagesPreferenceControllerTest {
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
mContext = RuntimeEnvironment.application;
- mValues = mContext.getResources().getStringArray(R.array.zen_mode_contacts_values);
- mContentResolver = RuntimeEnvironment.application.getContentResolver();
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
- when(mBackend.getPriorityMessageSenders())
- .thenReturn(NotificationManager.Policy.PRIORITY_SENDERS_STARRED);
- when(mBackend.getContactsSummary(ZenModeBackend.SOURCE_NONE))
- .thenCallRealMethod();
- when(mBackend.getContactsSummary(NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES))
- .thenCallRealMethod();
-
- mController = new ZenModeMessagesPreferenceController(mContext, mock(Lifecycle.class));
+ mController = new ZenModeMessagesPreferenceController(
+ mContext, mock(Lifecycle.class), "zen_mode_messages_settings");
ReflectionHelpers.setField(mController, "mBackend", mBackend);
-
- when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
- mockPref);
- mController.displayPreference(mPreferenceScreen);
}
@Test
- public void updateState_TotalSilence() {
- Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_NO_INTERRUPTIONS);
-
- when(mBackend.isPriorityCategoryEnabled(
- NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES))
- .thenReturn(false);
- final ListPreference mockPref = mock(ListPreference.class);
- mController.updateState(mockPref);
-
- verify(mockPref).setEnabled(false);
- verify(mockPref).setSummary(R.string.zen_mode_from_none);
+ public void testIsAvailable() {
+ assertTrue(mController.isAvailable());
}
- @Test
- public void updateState_AlarmsOnly() {
- Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_ALARMS);
-
- final ListPreference mockPref = mock(ListPreference.class);
- mController.updateState(mockPref);
-
- verify(mockPref).setEnabled(false);
- verify(mockPref).setSummary(R.string.zen_mode_from_none);
- }
-
- @Test
- public void updateState_Priority() {
- Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
-
- when(mBackend.isPriorityCategoryEnabled(
- NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES))
- .thenReturn(true);
-
- mController.updateState(mockPref);
-
- verify(mockPref).setEnabled(true);
- verify(mockPref).setSummary(R.string.zen_mode_from_starred);
- }
-
- @Test
- public void onPreferenceChange_setSelectedContacts_any() {
- Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
- when(mBackend.getPriorityMessageSenders()).thenReturn(
- NotificationManager.Policy.PRIORITY_SENDERS_ANY);
- mController.updateState(mockPref);
- verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
- ZenModeBackend.ZEN_MODE_FROM_ANYONE)]);
- }
-
- @Test
- public void onPreferenceChange_setSelectedContacts_none() {
- Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
- when(mBackend.getPriorityMessageSenders()).thenReturn(ZenModeBackend.SOURCE_NONE);
- mController.updateState(mockPref);
- verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
- ZenModeBackend.ZEN_MODE_FROM_NONE)]);
- }
-
- @Test
- public void onPreferenceChange_setSelectedContacts_starred() {
- Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
- when(mBackend.getPriorityMessageSenders()).thenReturn(
- NotificationManager.Policy.PRIORITY_SENDERS_STARRED);
- mController.updateState(mockPref);
- verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
- ZenModeBackend.ZEN_MODE_FROM_STARRED)]);
- }
-
- @Test
- public void onPreferenceChange_setSelectedContacts_contacts() {
- Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
- when(mBackend.getPriorityMessageSenders()).thenReturn(
- NotificationManager.Policy.PRIORITY_SENDERS_CONTACTS);
- mController.updateState(mockPref);
- verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
- ZenModeBackend.ZEN_MODE_FROM_CONTACTS)]);
- }
-}
\ No newline at end of file
+// TODO: (b/111475013 - beverlyt) set messages summary
+// @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/ZenModePriorityCallsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModePriorityCallsPreferenceControllerTest.java
new file mode 100644
index 00000000000..36a1382d7c6
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/ZenModePriorityCallsPreferenceControllerTest.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.notification;
+
+import static android.provider.Settings.Global.ZEN_MODE;
+import static android.provider.Settings.Global.ZEN_MODE_ALARMS;
+import static android.provider.Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
+import static android.provider.Settings.Global.ZEN_MODE_NO_INTERRUPTIONS;
+
+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.ContentResolver;
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.settings.R;
+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;
+
+import androidx.preference.ListPreference;
+import androidx.preference.PreferenceScreen;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class ZenModePriorityCallsPreferenceControllerTest {
+
+ private ZenModePriorityCallsPreferenceController mController;
+
+ @Mock
+ private ZenModeBackend mBackend;
+ @Mock
+ private NotificationManager mNotificationManager;
+ @Mock
+ private ListPreference mockPref;
+ @Mock
+ private NotificationManager.Policy mPolicy;
+ @Mock
+ private PreferenceScreen mPreferenceScreen;
+ private ContentResolver mContentResolver;
+ private Context mContext;
+
+ /**
+ * Array Values Key
+ * 0: anyone
+ * 1: contacts
+ * 2: starred
+ * 3: none
+ */
+ private String[] mValues;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
+
+ mContext = RuntimeEnvironment.application;
+ mValues = mContext.getResources().getStringArray(R.array.zen_mode_contacts_values);
+ mContentResolver = RuntimeEnvironment.application.getContentResolver();
+ when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
+
+ when(mBackend.getPriorityCallSenders())
+ .thenReturn(NotificationManager.Policy.PRIORITY_SENDERS_STARRED);
+ when(mBackend.getContactsSummary(ZenModeBackend.SOURCE_NONE))
+ .thenCallRealMethod();
+ when(mBackend.getContactsSummary(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
+ .thenCallRealMethod();
+
+ mController = new ZenModePriorityCallsPreferenceController(mContext, mock(Lifecycle.class));
+ ReflectionHelpers.setField(mController, "mBackend", mBackend);
+
+ when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
+ mockPref);
+ mController.displayPreference(mPreferenceScreen);
+ }
+
+ @Test
+ public void updateState_TotalSilence() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_NO_INTERRUPTIONS);
+
+ when(mBackend.isPriorityCategoryEnabled(
+ NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
+ .thenReturn(false);
+ final ListPreference mockPref = mock(ListPreference.class);
+ mController.updateState(mockPref);
+
+ verify(mockPref).setEnabled(false);
+ verify(mockPref).setSummary(R.string.zen_mode_from_none);
+ }
+
+ @Test
+ public void updateState_AlarmsOnly() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_ALARMS);
+
+ final ListPreference mockPref = mock(ListPreference.class);
+ mController.updateState(mockPref);
+
+ verify(mockPref).setEnabled(false);
+ verify(mockPref).setSummary(R.string.zen_mode_from_none);
+ }
+
+ @Test
+ public void updateState_Priority() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+
+ when(mBackend.isPriorityCategoryEnabled(
+ NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
+ .thenReturn(true);
+
+ mController.updateState(mockPref);
+
+ verify(mockPref).setEnabled(true);
+ verify(mockPref).setSummary(R.string.zen_mode_from_starred);
+ }
+
+ @Test
+ public void onPreferenceChange_setSelectedContacts_any() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+ when(mBackend.getPriorityCallSenders()).thenReturn(
+ NotificationManager.Policy.PRIORITY_SENDERS_ANY);
+ mController.updateState(mockPref);
+ verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
+ ZenModeBackend.ZEN_MODE_FROM_ANYONE)]);
+ }
+
+ @Test
+ public void onPreferenceChange_setSelectedContacts_none() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+ when(mBackend.getPriorityCallSenders()).thenReturn(ZenModeBackend.SOURCE_NONE);
+ mController.updateState(mockPref);
+ verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
+ ZenModeBackend.ZEN_MODE_FROM_NONE)]);
+ }
+
+ @Test
+ public void onPreferenceChange_setSelectedContacts_starred() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+ when(mBackend.getPriorityCallSenders()).thenReturn(
+ NotificationManager.Policy.PRIORITY_SENDERS_STARRED);
+ mController.updateState(mockPref);
+ verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
+ ZenModeBackend.ZEN_MODE_FROM_STARRED)]);
+ }
+
+ @Test
+ public void onPreferenceChange_setSelectedContacts_contacts() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+ when(mBackend.getPriorityCallSenders()).thenReturn(
+ NotificationManager.Policy.PRIORITY_SENDERS_CONTACTS);
+ mController.updateState(mockPref);
+ verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
+ ZenModeBackend.ZEN_MODE_FROM_CONTACTS)]);
+ }
+}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModePriorityMessagesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModePriorityMessagesPreferenceControllerTest.java
new file mode 100644
index 00000000000..75605a4d2f0
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/ZenModePriorityMessagesPreferenceControllerTest.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.notification;
+
+import static android.provider.Settings.Global.ZEN_MODE;
+import static android.provider.Settings.Global.ZEN_MODE_ALARMS;
+import static android.provider.Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
+import static android.provider.Settings.Global.ZEN_MODE_NO_INTERRUPTIONS;
+
+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.ContentResolver;
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.settings.R;
+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;
+
+import androidx.preference.ListPreference;
+import androidx.preference.PreferenceScreen;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class ZenModePriorityMessagesPreferenceControllerTest {
+
+ private ZenModePriorityMessagesPreferenceController mController;
+
+ @Mock
+ private ZenModeBackend mBackend;
+ @Mock
+ private NotificationManager mNotificationManager;
+ @Mock
+ private ListPreference mockPref;
+ @Mock
+ private NotificationManager.Policy mPolicy;
+ @Mock
+ private PreferenceScreen mPreferenceScreen;
+ private ContentResolver mContentResolver;
+ private Context mContext;
+
+ /**
+ * Array Values Key
+ * 0: anyone
+ * 1: contacts
+ * 2: starred
+ * 3: none
+ */
+ private String[] mValues;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
+
+ mContext = RuntimeEnvironment.application;
+ mValues = mContext.getResources().getStringArray(R.array.zen_mode_contacts_values);
+ mContentResolver = RuntimeEnvironment.application.getContentResolver();
+ when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
+
+ when(mBackend.getPriorityMessageSenders())
+ .thenReturn(NotificationManager.Policy.PRIORITY_SENDERS_STARRED);
+ when(mBackend.getContactsSummary(ZenModeBackend.SOURCE_NONE))
+ .thenCallRealMethod();
+ when(mBackend.getContactsSummary(NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES))
+ .thenCallRealMethod();
+
+ mController = new ZenModePriorityMessagesPreferenceController(mContext, mock(Lifecycle.class));
+ ReflectionHelpers.setField(mController, "mBackend", mBackend);
+
+ when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
+ mockPref);
+ mController.displayPreference(mPreferenceScreen);
+ }
+
+ @Test
+ public void updateState_TotalSilence() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_NO_INTERRUPTIONS);
+
+ when(mBackend.isPriorityCategoryEnabled(
+ NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES))
+ .thenReturn(false);
+ final ListPreference mockPref = mock(ListPreference.class);
+ mController.updateState(mockPref);
+
+ verify(mockPref).setEnabled(false);
+ verify(mockPref).setSummary(R.string.zen_mode_from_none);
+ }
+
+ @Test
+ public void updateState_AlarmsOnly() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_ALARMS);
+
+ final ListPreference mockPref = mock(ListPreference.class);
+ mController.updateState(mockPref);
+
+ verify(mockPref).setEnabled(false);
+ verify(mockPref).setSummary(R.string.zen_mode_from_none);
+ }
+
+ @Test
+ public void updateState_Priority() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+
+ when(mBackend.isPriorityCategoryEnabled(
+ NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES))
+ .thenReturn(true);
+
+ mController.updateState(mockPref);
+
+ verify(mockPref).setEnabled(true);
+ verify(mockPref).setSummary(R.string.zen_mode_from_starred);
+ }
+
+ @Test
+ public void onPreferenceChange_setSelectedContacts_any() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+ when(mBackend.getPriorityMessageSenders()).thenReturn(
+ NotificationManager.Policy.PRIORITY_SENDERS_ANY);
+ mController.updateState(mockPref);
+ verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
+ ZenModeBackend.ZEN_MODE_FROM_ANYONE)]);
+ }
+
+ @Test
+ public void onPreferenceChange_setSelectedContacts_none() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+ when(mBackend.getPriorityMessageSenders()).thenReturn(ZenModeBackend.SOURCE_NONE);
+ mController.updateState(mockPref);
+ verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
+ ZenModeBackend.ZEN_MODE_FROM_NONE)]);
+ }
+
+ @Test
+ public void onPreferenceChange_setSelectedContacts_starred() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+ when(mBackend.getPriorityMessageSenders()).thenReturn(
+ NotificationManager.Policy.PRIORITY_SENDERS_STARRED);
+ mController.updateState(mockPref);
+ verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
+ ZenModeBackend.ZEN_MODE_FROM_STARRED)]);
+ }
+
+ @Test
+ public void onPreferenceChange_setSelectedContacts_contacts() {
+ Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
+ when(mBackend.getPriorityMessageSenders()).thenReturn(
+ NotificationManager.Policy.PRIORITY_SENDERS_CONTACTS);
+ mController.updateState(mockPref);
+ verify(mockPref).setValue(mValues[mController.getIndexOfSendersValue(
+ ZenModeBackend.ZEN_MODE_FROM_CONTACTS)]);
+ }
+}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
index 96e56582995..4fc7d57f5fb 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
@@ -68,63 +68,6 @@ public class ZenModeSettingsTest {
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);