Dnd settings pages redesign (round 1)

Test: make RunSettingsRoboTests -j40
Bug: 111475013
Change-Id: Idb6bbfdfe377b61a8fe1f7e81171bbefe23a4ebf
This commit is contained in:
Beverly
2018-10-26 16:01:17 -04:00
parent 6d2fbea6e5
commit 69d11b2874
28 changed files with 835 additions and 983 deletions

View File

@@ -7185,20 +7185,26 @@
<string name="zen_mode_behavior_alarms_only">No sound except alarms and media</string> <string name="zen_mode_behavior_alarms_only">No sound except alarms and media</string>
<!-- Do not disturb: Title for the zen mode automation option in Settings. [CHAR LIMIT=40] --> <!-- Do not disturb: Title for the zen mode automation option in Settings. [CHAR LIMIT=40] -->
<string name="zen_mode_automation_settings_title">Turn on automatically</string> <string name="zen_mode_automation_settings_title">Schedules</string>
<!-- Do not disturb: Title for the zen mode automatic rules page in settings. [CHAR LIMIT=30] --> <!-- Do not disturb: Title for the zen mode automatic rules page in settings. [CHAR LIMIT=30] -->
<string name="zen_mode_automation_settings_page_title">Automatic rules</string> <string name="zen_mode_automation_settings_page_title">Do Not Disturb</string>
<!-- Do not disturb: Title for a specific zen mode automatic rule in settings. [CHAR LIMIT=30] --> <!-- Do not disturb: Title for a specific zen mode automatic rule in settings. [CHAR LIMIT=30] -->
<string name="zen_mode_automatic_rule_settings_page_title">Automatic rule</string> <string name="zen_mode_automatic_rule_settings_page_title">Automatic rule</string>
<!-- Do not disturb: Title do not disturb settings representing automatic (scheduled) do not disturb rules. [CHAR LIMIT=30] -->
<string name="zen_mode_schedule_category_title">Schedule</string>
<!-- Do not disturb: Title for the zen mode automation option Suggestion. [CHAR LIMIT=46] --> <!-- Do not disturb: Title for the zen mode automation option Suggestion. [CHAR LIMIT=46] -->
<string name="zen_mode_automation_suggestion_title">Silence phone at certain times</string> <string name="zen_mode_automation_suggestion_title">Silence phone at certain times</string>
<!-- Do not disturb: Summary for the zen mode automation option Suggestion. [CHAR LIMIT=55] --> <!-- Do not disturb: Summary for the zen mode automation option Suggestion. [CHAR LIMIT=55] -->
<string name="zen_mode_automation_suggestion_summary">Set Do Not Disturb rules</string> <string name="zen_mode_automation_suggestion_summary">Set Do Not Disturb rules</string>
<!-- Do not disturb: Header for the Do Not Disturb automatic rules. [CHAR LIMIT=55] -->
<string name="zen_mode_schedule_title">Schedule</string>
<!-- Do not disturb: Switch toggle to toggle whether to use an automatic dnd rule or not [CHAR LIMIT=40] --> <!-- Do not disturb: Switch toggle to toggle whether to use an automatic dnd rule or not [CHAR LIMIT=40] -->
<string name="zen_mode_use_automatic_rule">Use rule</string> <string name="zen_mode_use_automatic_rule">Use rule</string>
@@ -7221,10 +7227,10 @@
<string name="zen_mode_visual_signals_settings_subtitle">Allow visual signals</string> <string name="zen_mode_visual_signals_settings_subtitle">Allow visual signals</string>
<!-- Do not disturb: zen settings screens category title [CHAR LIMIT=100] --> <!-- Do not disturb: zen settings screens category title [CHAR LIMIT=100] -->
<string name="zen_mode_settings_category">When Do Not Disturb is turned on</string> <string name="zen_mode_settings_category">When Do Not Disturb is on</string>
<!-- Do not disturb: restrict notifications title [CHAR LIMIT=60] --> <!-- Do not disturb: restrict notifications title [CHAR LIMIT=80] -->
<string name="zen_mode_restrict_notifications_title">Notifications</string> <string name="zen_mode_restrict_notifications_title">Notification restrictions</string>
<!-- Do not disturb: Mute notifications option [CHAR LIMIT=60] --> <!-- Do not disturb: Mute notifications option [CHAR LIMIT=60] -->
<string name="zen_mode_restrict_notifications_mute">No sound from notifications</string> <string name="zen_mode_restrict_notifications_mute">No sound from notifications</string>
<!-- Do not disturb:Mute notifications summary [CHAR LIMIT=NONE] --> <!-- Do not disturb:Mute notifications summary [CHAR LIMIT=NONE] -->
@@ -7356,15 +7362,15 @@
<item quantity="other"><xliff:g id="on_count" example="3">%d</xliff:g> rules can turn on automatically</item> <item quantity="other"><xliff:g id="on_count" example="3">%d</xliff:g> rules can turn on automatically</item>
</plurals> </plurals>
<!-- Do not disturb settings, category header [CHAR LIMIT=100]--> <!-- Do not disturb settings, category header [CHAR LIMIT=120]-->
<string name="zen_category_behavior">Behavior</string> <string name="zen_category_behavior">Mute phone, but allow exceptions</string>
<!-- Do not disturb settings, category header [CHAR LIMIT=100]--> <!-- Do not disturb settings, exceptions to dnd title [CHAR LIMIT=100]-->
<string name="zen_category_exceptions">Exceptions</string> <string name="zen_category_exceptions">Exceptions</string>
<!-- Do not disturb settings, category header [CHAR LIMIT=100]--> <!-- Do not disturb settings, category header [CHAR LIMIT=100]-->
<string name="zen_category_schedule">Schedule</string> <string name="zen_category_schedule">Schedule</string>
<!-- Do not disturb settings, sound and vibrations title [CHAR LIMIT=100]--> <!-- Do not disturb settings, sound and vibrations exceptions title [CHAR LIMIT=100]-->
<string name="zen_sound_title">Sound &amp; vibration</string> <string name="zen_sound_title">See all exceptions</string>
<!-- Do not disturb settings, sound and vibrations screen footer [CHAR LIMIT=NONE]--> <!-- Do not disturb settings, sound and vibrations screen footer [CHAR LIMIT=NONE]-->
<string name="zen_sound_footer">When Do Not Disturb is on, sound and vibration will be muted, except for the items you allow above.</string> <string name="zen_sound_footer">When Do Not Disturb is on, sound and vibration will be muted, except for the items you allow above.</string>
<!-- Do not disturb settings, sound and vibrations screen category [CHAR LIMIT=100]--> <!-- Do not disturb settings, sound and vibrations screen category [CHAR LIMIT=100]-->
@@ -7816,8 +7822,8 @@
<!-- [CHAR LIMIT=100] Zen mode settings: Warning text for invalid zen rule names --> <!-- [CHAR LIMIT=100] Zen mode settings: Warning text for invalid zen rule names -->
<string name="zen_mode_rule_name_warning">Rule name already in use</string> <string name="zen_mode_rule_name_warning">Rule name already in use</string>
<!-- [CHAR LIMIT=40] Zen mode settings: Add rule menu option name --> <!-- [CHAR LIMIT=40] Zen mode settings: Add another automatic zen rule option name-->
<string name="zen_mode_add_rule">Add rule</string> <string name="zen_mode_add_rule">Add more</string>
<!-- [CHAR LIMIT=40] Zen mode settings: Add event-based rule, set rule name title --> <!-- [CHAR LIMIT=40] Zen mode settings: Add event-based rule, set rule name title -->
<string name="zen_mode_add_event_rule">Add event rule</string> <string name="zen_mode_add_event_rule">Add event rule</string>
@@ -7942,6 +7948,9 @@
<!-- [CHAR LIMIT=20] Zen mode settings: Messages option --> <!-- [CHAR LIMIT=20] Zen mode settings: Messages option -->
<string name="zen_mode_messages">Messages</string> <string name="zen_mode_messages">Messages</string>
<!-- Do not disturb settings, messages, events and reminders footer [CHAR LIMIT=NONE]-->
<string name="zen_mode_messages_footer">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.</string>
<!-- [CHAR LIMIT=40] Zen mode settings: Allow messages toggle title --> <!-- [CHAR LIMIT=40] Zen mode settings: Allow messages toggle title -->
<string name="zen_mode_messages_title">Allow messages</string> <string name="zen_mode_messages_title">Allow messages</string>
@@ -7978,42 +7987,36 @@
<!-- [CHAR LIMIT=40] Zen mode settings: Calls or messages option value: None --> <!-- [CHAR LIMIT=40] Zen mode settings: Calls or messages option value: None -->
<string name="zen_mode_from_none">None</string> <string name="zen_mode_from_none">None</string>
<!-- [CHAR LIMIT=50] Zen mode settings: Alarms option --> <!-- [CHAR LIMIT=80] Zen mode settings: Allow alarms option -->
<string name="zen_mode_alarms">Alarms</string> <string name="zen_mode_alarms">Allow alarms</string>
<!-- [CHAR LIMIT=50] Zen mode settings: Alarms option (ie: sound from alarm clock) --> <!-- [CHAR LIMIT=50] Zen mode settings: Alarms option (ie: sound from alarm clock) -->
<string name="zen_mode_alarms_list">alarms</string> <string name="zen_mode_alarms_list">alarms</string>
<!-- [CHAR LIMIT=50] Zen mode settings: Media option --> <!-- [CHAR LIMIT=80] Zen mode settings: Allow media (sound from video) to bypass dnd -->
<string name="zen_mode_media">Media</string> <string name="zen_mode_media">Allow media</string>
<!-- [CHAR LIMIT=50] Zen mode settings: Media (ie: sound from video) --> <!-- [CHAR LIMIT=50] Zen mode settings: Media (ie: sound from video) -->
<string name="zen_mode_media_list">media</string> <string name="zen_mode_media_list">media</string>
<!-- [CHAR LIMIT=50] Zen mode settings: System option which includes sounds such as touch sounds --> <!-- [CHAR LIMIT=80] Zen mode settings: allow touch sounds to bypass DND -->
<string name="zen_mode_system">Touch sounds</string> <string name="zen_mode_system">Allow touch sounds</string>
<!-- [CHAR LIMIT=50] Zen mode settings: System sounds (ie: touch sounds) --> <!-- [CHAR LIMIT=50] Zen mode settings: System sounds (ie: touch sounds) -->
<string name="zen_mode_system_list">touch sounds</string> <string name="zen_mode_system_list">touch sounds</string>
<!-- [CHAR LIMIT=50] Zen mode settings: Reminders option --> <!-- [CHAR LIMIT=80] Zen mode settings: Allow reminder notifications/sounds to bypass DND -->
<string name="zen_mode_reminders">Reminders</string> <string name="zen_mode_reminders">Allow reminders</string>
<!-- [CHAR LIMIT=50] Zen mode settings: Reminders (ie: calendar reminders are allowed to bypass dnd) --> <!-- [CHAR LIMIT=50] Zen mode settings: Reminders (ie: calendar reminders are allowed to bypass dnd) -->
<string name="zen_mode_reminders_list">reminders</string> <string name="zen_mode_reminders_list">reminders</string>
<!-- [CHAR LIMIT=70] Zen mode settings: Allow reminders toggle title --> <!-- [CHAR LIMIT=80] Zen mode settings: Allow event notifications/sounds to bypass DND -->
<string name="zen_mode_reminders_title">Allow reminders</string> <string name="zen_mode_events">Allow events</string>
<!-- [CHAR LIMIT=50] Zen mode settings: Events option -->
<string name="zen_mode_events">Events</string>
<!-- [CHAR LIMIT=50] Zen mode settings: Events (ie: calendar events) --> <!-- [CHAR LIMIT=50] Zen mode settings: Events (ie: calendar events) -->
<string name="zen_mode_events_list">events</string> <string name="zen_mode_events_list">events</string>
<!-- [CHAR LIMIT=70] Zen mode settings: Allow events toggle title -->
<string name="zen_mode_events_title">Allow events</string>
<!-- [CHAR LIMIT=50] Zen mode settings: All callers summary --> <!-- [CHAR LIMIT=50] Zen mode settings: All callers summary -->
<string name="zen_mode_all_callers">anyone</string> <string name="zen_mode_all_callers">anyone</string>

View File

@@ -19,9 +19,9 @@
android:key="zen_mode_automation_settings_page" android:key="zen_mode_automation_settings_page"
android:title="@string/zen_mode_automation_settings_page_title" > android:title="@string/zen_mode_automation_settings_page_title" >
<PreferenceCategory <PreferenceCategory
android:key="zen_mode_automatic_rules"> android:key="zen_mode_automatic_rules"
android:title="@string/zen_mode_schedule_title">
<!-- Rules added at runtime --> <!-- Rules added at runtime -->
</PreferenceCategory> </PreferenceCategory>

View File

@@ -17,6 +17,7 @@
<PreferenceScreen <PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="zen_mode_calls_settings_page" android:key="zen_mode_calls_settings_page"
android:title="@string/zen_mode_calls" > android:title="@string/zen_mode_calls" >

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:key="zen_mode_messages_settings_page"
android:title="@string/zen_mode_messages" >
<PreferenceCategory
android:title="@string/zen_mode_settings_category"
android:key="zen_mode_settings_category_messages">
<!-- Messages -->
<ListPreference
android:key="zen_mode_messages"
android:title="@string/zen_mode_messages_title"
android:entries="@array/zen_mode_contacts_entries"
android:entryValues="@array/zen_mode_contacts_values"/>
<Preference
android:key="zen_mode_starred_contacts_messages"
android:title="@string/zen_mode_starred_contacts_title"/>
</PreferenceCategory>
<com.android.settingslib.widget.FooterPreference/>
</PreferenceScreen>

View File

@@ -1,50 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:key="zen_mode_msg_event_reminder_settings_page"
android:title="@string/zen_msg_event_reminder_title" >
<PreferenceCategory
android:title="@string/zen_mode_settings_category"
android:key="zen_mode_settings_category_msg_event_reminder">
<!-- Messages -->
<ListPreference
android:key="zen_mode_messages"
android:title="@string/zen_mode_messages_title"
android:entries="@array/zen_mode_contacts_entries"
android:entryValues="@array/zen_mode_contacts_values"/>
<Preference
android:key="zen_mode_starred_contacts_messages"
android:title="@string/zen_mode_starred_contacts_title"/>
<!-- Reminders -->
<SwitchPreference
android:key="zen_mode_reminders"
android:title="@string/zen_mode_reminders_title"/>
<!-- Events -->
<SwitchPreference
android:key="zen_mode_events"
android:title="@string/zen_mode_events_title"/>
</PreferenceCategory>
<com.android.settingslib.widget.FooterPreference />
</PreferenceScreen>

View File

@@ -25,62 +25,59 @@
<PreferenceCategory <PreferenceCategory
android:key="zen_mode_settings_category_behavior" android:key="zen_mode_settings_category_behavior"
android:title="@string/zen_category_behavior"> android:title="@string/zen_category_behavior">
<!-- sound vibration --> <!-- Calls -->
<Preference
android:key="zen_mode_behavior_calls"
android:title="@string/zen_mode_calls_title"
android:fragment="com.android.settings.notification.ZenModeCallsSettings" />
<!-- Messages -->
<Preference
android:key="zen_mode_behavior_messages"
android:title="@string/zen_mode_messages_title"
android:fragment="com.android.settings.notification.ZenModeMessagesSettings" />
<!-- Alarms -->
<SwitchPreference
android:key="zen_mode_behavior_alarms"
android:title="@string/zen_mode_alarms"/>
<!-- All sounds -->
<Preference <Preference
android:key="zen_sound_vibration_settings" android:key="zen_sound_vibration_settings"
android:title="@string/zen_sound_title" android:title="@string/zen_sound_title"
android:fragment="com.android.settings.notification.ZenModeSoundVibrationSettings"/> android:fragment="com.android.settings.notification.ZenModeSoundVibrationSettings"
android:icon="@drawable/ic_chevron_right_24dp"/>
<!-- What to block (effects) -->
<Preference
android:key="zen_mode_block_effects_settings"
android:title="@string/zen_mode_restrict_notifications_title"
android:fragment="com.android.settings.notification.ZenModeRestrictNotificationsSettings" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <!-- What to block (effects) -->
android:key="zen_mode_settings_category_exceptions" <Preference
android:title="@string/zen_category_exceptions"> android:key="zen_mode_block_effects_settings"
<Preference android:title="@string/zen_mode_restrict_notifications_title"
android:key="zen_mode_calls_settings" android:fragment="com.android.settings.notification.ZenModeRestrictNotificationsSettings"
android:title="@string/zen_mode_calls" settings:allowDividerAbove="true"/>
android:fragment="com.android.settings.notification.ZenModeCallsSettings" />
<Preference
android:key="zen_mode_msg_event_reminder_settings"
android:title="@string/zen_msg_event_reminder_title"
android:fragment="com.android.settings.notification.ZenModeMsgEventReminderSettings" />
</PreferenceCategory> <!-- DND duration settings -->
<com.android.settings.notification.ZenDurationDialogPreference
android:key="zen_mode_duration_settings"
android:title="@string/zen_mode_duration_settings_title"
android:widgetLayout="@null"/>
<PreferenceCategory <!-- Automatic rules -->
android:key="zen_mode_settings_category_schedule" <Preference
android:title="@string/zen_category_schedule"> android:key="zen_mode_automation_settings"
<!-- DND duration settings --> android:title="@string/zen_mode_automation_settings_title"
<com.android.settings.notification.ZenDurationDialogPreference android:fragment="com.android.settings.notification.ZenModeAutomationSettings"/>
android:key="zen_mode_duration_settings"
android:title="@string/zen_mode_duration_settings_title"
android:widgetLayout="@null"/>
<!-- Automatic rules -->
<Preference
android:key="zen_mode_automation_settings"
android:title="@string/zen_mode_automation_settings_title"
android:fragment="com.android.settings.notification.ZenModeAutomationSettings" />
</PreferenceCategory>
<!-- Turn on DND button --> <!-- Turn on DND button -->
<!-- Layout preference doesn't obey allowDividerAbove, so put it in a PreferenceCategory --> <com.android.settings.applications.LayoutPreference
<PreferenceCategory android:key="zen_mode_settings_button_container"
android:key="zen_mode_settings_button_category"> android:selectable="false"
<com.android.settings.applications.LayoutPreference android:layout="@layout/zen_mode_settings_button"
android:key="zen_mode_settings_button_container" settings:allowDividerAbove="true"
android:selectable="false" settings:allowDividerBelow="true"/>
android:layout="@layout/zen_mode_settings_button" />
</PreferenceCategory>
<PreferenceCategory <!-- Footer that shows if user is put into alarms only or total silence mode by an app -->
android:key="zen_mode_footer_container"> <com.android.settingslib.widget.FooterPreference/>
<com.android.settingslib.widget.FooterPreference />
</PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View File

@@ -18,11 +18,24 @@
<PreferenceScreen <PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:key="zen_mode_sound_vibration_settings_page" android:key="zen_mode_sound_vibration_settings_page"
android:title="@string/zen_sound_title" > android:title="@string/zen_category_exceptions" >
<PreferenceCategory <PreferenceCategory
android:title="@string/zen_mode_settings_category" android:title="@string/zen_mode_settings_category"
android:key="zen_mode_settings_category_sound_vibration"> android:key="zen_mode_settings_category_sound_vibration">
<!-- Calls -->
<Preference
android:key="zen_mode_calls_settings"
android:title="@string/zen_mode_calls_title"
android:fragment="com.android.settings.notification.ZenModeCallsSettings" />
<!-- Messages -->
<Preference
android:key="zen_mode_messages_settings"
android:title="@string/zen_mode_messages_title"
android:fragment="com.android.settings.notification.ZenModeMessagesSettings" />
<!-- Alarms --> <!-- Alarms -->
<SwitchPreference <SwitchPreference
android:key="zen_mode_alarms" android:key="zen_mode_alarms"
@@ -37,6 +50,18 @@
<SwitchPreference <SwitchPreference
android:key="zen_mode_system" android:key="zen_mode_system"
android:title="@string/zen_mode_system"/> android:title="@string/zen_mode_system"/>
<!-- Reminders -->
<SwitchPreference
android:key="zen_mode_reminders"
android:title="@string/zen_mode_reminders"/>
<!-- Events -->
<SwitchPreference
android:key="zen_mode_events"
android:title="@string/zen_mode_events"/>
<!-- TODO: beverlyt, add "Allow apps to override" -->
</PreferenceCategory> </PreferenceCategory>
<com.android.settingslib.widget.FooterPreference/> <com.android.settingslib.widget.FooterPreference/>

View File

@@ -21,19 +21,20 @@ import android.content.Context;
import android.provider.Settings; import android.provider.Settings;
import android.util.Log; import android.util.Log;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import com.android.internal.logging.nano.MetricsProto; import com.android.internal.logging.nano.MetricsProto;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
public class ZenModeAlarmsPreferenceController extends public class ZenModeAlarmsPreferenceController extends
AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener { AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
protected static final String KEY = "zen_mode_alarms"; private final String KEY;
public ZenModeAlarmsPreferenceController(Context context, Lifecycle lifecycle) { public ZenModeAlarmsPreferenceController(Context context, Lifecycle lifecycle, String key) {
super(context, KEY, lifecycle); super(context, key, lifecycle);
KEY = key;
} }
@Override @Override

View File

@@ -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()));
}
}

View File

@@ -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()));
}
}

View File

@@ -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()));
}
}

View File

@@ -16,36 +16,29 @@
package com.android.settings.notification; package com.android.settings.notification;
import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.provider.Settings;
import android.text.TextUtils;
import androidx.annotation.VisibleForTesting; import com.android.settings.core.PreferenceControllerMixin;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenModeCallsPreferenceController extends AbstractZenModePreferenceController implements import androidx.preference.Preference;
Preference.OnPreferenceChangeListener {
protected static final String KEY = "zen_mode_calls"; public class ZenModeCallsPreferenceController extends
private final ZenModeBackend mBackend; AbstractZenModePreferenceController implements PreferenceControllerMixin {
private ListPreference mPreference;
private final String[] mListValues;
public ZenModeCallsPreferenceController(Context context, Lifecycle lifecycle) { private final String KEY_BEHAVIOR_SETTINGS;
super(context, KEY, lifecycle); private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
mBackend = ZenModeBackend.getInstance(context);
mListValues = context.getResources().getStringArray(R.array.zen_mode_contacts_values); public ZenModeCallsPreferenceController(Context context, Lifecycle lifecycle,
String key) {
super(context, key, lifecycle);
KEY_BEHAVIOR_SETTINGS = key;
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
} }
@Override @Override
public String getPreferenceKey() { public String getPreferenceKey() {
return KEY; return KEY_BEHAVIOR_SETTINGS;
} }
@Override @Override
@@ -53,55 +46,10 @@ public class ZenModeCallsPreferenceController extends AbstractZenModePreferenceC
return true; return true;
} }
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = (ListPreference) screen.findPreference(KEY);
}
@Override @Override
public void updateState(Preference preference) { public void updateState(Preference preference) {
super.updateState(preference); super.updateState(preference);
updateFromContactsValue(preference);
}
@Override preference.setSummary(mSummaryBuilder.getCallsSettingSummary(getPolicy()));
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;
} }
} }

View File

@@ -43,7 +43,7 @@ public class ZenModeCallsSettings extends ZenModeSettingsBase implements Indexab
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) { Lifecycle lifecycle) {
List<AbstractPreferenceController> controllers = new ArrayList<>(); List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new ZenModeCallsPreferenceController(context, lifecycle)); controllers.add(new ZenModePriorityCallsPreferenceController(context, lifecycle));
controllers.add(new ZenModeStarredContactsPreferenceController(context, lifecycle, controllers.add(new ZenModeStarredContactsPreferenceController(context, lifecycle,
PRIORITY_CATEGORY_CALLS, "zen_mode_starred_contacts_callers")); PRIORITY_CATEGORY_CALLS, "zen_mode_starred_contacts_callers"));
controllers.add(new ZenModeRepeatCallersPreferenceController(context, lifecycle, controllers.add(new ZenModeRepeatCallersPreferenceController(context, lifecycle,

View File

@@ -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; package com.android.settings.notification;
import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.provider.Settings;
import android.text.TextUtils;
import androidx.annotation.VisibleForTesting; import com.android.settings.core.PreferenceControllerMixin;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenModeMessagesPreferenceController extends AbstractZenModePreferenceController import androidx.preference.Preference;
implements Preference.OnPreferenceChangeListener {
protected static final String KEY = "zen_mode_messages"; public class ZenModeMessagesPreferenceController extends
AbstractZenModePreferenceController implements PreferenceControllerMixin {
private final ZenModeBackend mBackend; private final String KEY;
private ListPreference mPreference; private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
private final String[] mListValues;
public ZenModeMessagesPreferenceController(Context context, Lifecycle lifecycle) { public ZenModeMessagesPreferenceController(Context context, Lifecycle lifecycle, String key) {
super(context, KEY, lifecycle); super(context, key, lifecycle);
mBackend = ZenModeBackend.getInstance(context); KEY = key;
mListValues = context.getResources().getStringArray(R.array.zen_mode_contacts_values); mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
} }
@Override @Override
@@ -38,55 +45,9 @@ public class ZenModeMessagesPreferenceController extends AbstractZenModePreferen
return true; return true;
} }
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = (ListPreference) screen.findPreference(KEY);
}
@Override @Override
public void updateState(Preference preference) { public void updateState(Preference preference) {
super.updateState(preference); super.updateState(preference);
updateFromContactsValue(preference); // TODO: (b/111475013 - beverlyt) set messages summary
}
@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;
} }
} }

View File

@@ -33,7 +33,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@SearchIndexable @SearchIndexable
public class ZenModeMsgEventReminderSettings extends ZenModeSettingsBase implements Indexable { public class ZenModeMessagesSettings extends ZenModeSettingsBase implements Indexable {
@Override @Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
@@ -43,19 +43,17 @@ public class ZenModeMsgEventReminderSettings extends ZenModeSettingsBase impleme
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) { Lifecycle lifecycle) {
List<AbstractPreferenceController> controllers = new ArrayList<>(); List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new ZenModeEventsPreferenceController(context, lifecycle)); controllers.add(new ZenModePriorityMessagesPreferenceController(context, lifecycle));
controllers.add(new ZenModeRemindersPreferenceController(context, lifecycle));
controllers.add(new ZenModeMessagesPreferenceController(context, lifecycle));
controllers.add(new ZenModeStarredContactsPreferenceController(context, lifecycle, controllers.add(new ZenModeStarredContactsPreferenceController(context, lifecycle,
PRIORITY_CATEGORY_MESSAGES, "zen_mode_starred_contacts_messages")); PRIORITY_CATEGORY_MESSAGES, "zen_mode_starred_contacts_messages"));
controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle, controllers.add(new ZenModeBehaviorFooterPreferenceController(
R.string.zen_msg_event_reminder_footer)); context, lifecycle, R.string.zen_mode_messages_footer));
return controllers; return controllers;
} }
@Override @Override
protected int getPreferenceScreenResId() { protected int getPreferenceScreenResId() {
return R.xml.zen_mode_msg_event_reminder_settings; return R.xml.zen_mode_messages_settings;
} }
@Override @Override
@@ -66,7 +64,7 @@ public class ZenModeMsgEventReminderSettings extends ZenModeSettingsBase impleme
/** /**
* For Search. * For Search.
*/ */
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() { new BaseSearchIndexProvider() {
@Override @Override
@@ -75,14 +73,15 @@ public class ZenModeMsgEventReminderSettings extends ZenModeSettingsBase impleme
final ArrayList<SearchIndexableResource> result = new ArrayList<>(); final ArrayList<SearchIndexableResource> result = new ArrayList<>();
final SearchIndexableResource sir = new SearchIndexableResource(context); 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); result.add(sir);
return result; return result;
} }
@Override @Override
public List<AbstractPreferenceController> createPreferenceControllers(Context context) { public List<AbstractPreferenceController> createPreferenceControllers(
return buildPreferenceControllers(context, null); Context context) {
} return buildPreferenceControllers(context, null);
}; }
};
} }

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -82,9 +82,12 @@ public class ZenModeSettings extends ZenModeSettingsBase {
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle, FragmentManager fragmentManager) { Lifecycle lifecycle, FragmentManager fragmentManager) {
List<AbstractPreferenceController> controllers = new ArrayList<>(); List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new ZenModeBehaviorMsgEventReminderPreferenceController(context, lifecycle)); controllers.add(new ZenModeCallsPreferenceController(context, lifecycle,
controllers.add(new ZenModeBehaviorSoundPreferenceController(context, lifecycle)); "zen_mode_behavior_calls"));
controllers.add(new ZenModeBehaviorCallsPreferenceController(context, lifecycle)); 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 ZenModeBlockedEffectsPreferenceController(context, lifecycle));
controllers.add(new ZenModeDurationPreferenceController(context, lifecycle)); controllers.add(new ZenModeDurationPreferenceController(context, lifecycle));
controllers.add(new ZenModeAutomationPreferenceController(context)); controllers.add(new ZenModeAutomationPreferenceController(context));

View File

@@ -16,6 +16,8 @@
package com.android.settings.notification; package com.android.settings.notification;
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES;
import android.content.Context; import android.content.Context;
import android.provider.SearchIndexableResource; import android.provider.SearchIndexableResource;
@@ -41,9 +43,16 @@ public class ZenModeSoundVibrationSettings extends ZenModeSettingsBase implement
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) { Lifecycle lifecycle) {
List<AbstractPreferenceController> controllers = new ArrayList<>(); List<AbstractPreferenceController> 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 ZenModeMediaPreferenceController(context, lifecycle));
controllers.add(new ZenModeSystemPreferenceController(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, controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle,
R.string.zen_sound_footer)); R.string.zen_sound_footer));
return controllers; return controllers;

View File

@@ -30,9 +30,6 @@ import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.provider.Settings; import android.provider.Settings;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -45,6 +42,9 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication; import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers; import org.robolectric.util.ReflectionHelpers;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
public class ZenModeAlarmsPreferenceControllerTest { public class ZenModeAlarmsPreferenceControllerTest {
@@ -75,7 +75,8 @@ public class ZenModeAlarmsPreferenceControllerTest {
mContext = RuntimeEnvironment.application; mContext = RuntimeEnvironment.application;
mContentResolver = RuntimeEnvironment.application.getContentResolver(); mContentResolver = RuntimeEnvironment.application.getContentResolver();
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy); 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); ReflectionHelpers.setField(mController, "mBackend", mBackend);
when(mPreferenceScreen.findPreference(mController.getPreferenceKey())) when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,24 +16,15 @@
package com.android.settings.notification; package com.android.settings.notification;
import static android.provider.Settings.Global.ZEN_MODE; import static org.junit.Assert.assertTrue;
import static android.provider.Settings.Global.ZEN_MODE_ALARMS; import static org.mockito.ArgumentMatchers.any;
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.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.ContentResolver;
import android.content.Context; 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.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -46,32 +37,20 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication; import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers; import org.robolectric.util.ReflectionHelpers;
import androidx.preference.Preference;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
public class ZenModeCallsPreferenceControllerTest { public final class ZenModeCallsPreferenceControllerTest {
private ZenModeCallsPreferenceController mController; private ZenModeCallsPreferenceController mController;
@Mock
private ZenModeBackend mBackend;
@Mock @Mock
private NotificationManager mNotificationManager; private NotificationManager mNotificationManager;
@Mock @Mock
private ListPreference mockPref;
@Mock
private NotificationManager.Policy mPolicy; private NotificationManager.Policy mPolicy;
@Mock
private PreferenceScreen mPreferenceScreen;
private ContentResolver mContentResolver;
private Context mContext;
/** private Context mContext;
* Array Values Key @Mock
* 0: anyone private ZenModeBackend mBackend;
* 1: contacts
* 2: starred
* 3: none
*/
private String[] mValues;
@Before @Before
public void setup() { public void setup() {
@@ -80,100 +59,22 @@ public class ZenModeCallsPreferenceControllerTest {
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager); shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
mContext = RuntimeEnvironment.application; mContext = RuntimeEnvironment.application;
mValues = mContext.getResources().getStringArray(R.array.zen_mode_contacts_values);
mContentResolver = RuntimeEnvironment.application.getContentResolver();
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy); when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
when(mBackend.getPriorityCallSenders()) mController = new ZenModeCallsPreferenceController(
.thenReturn(NotificationManager.Policy.PRIORITY_SENDERS_STARRED); mContext, mock(Lifecycle.class), "zen_mode_calls_settings");
when(mBackend.getContactsSummary(ZenModeBackend.SOURCE_NONE))
.thenCallRealMethod();
when(mBackend.getContactsSummary(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
.thenCallRealMethod();
mController = new ZenModeCallsPreferenceController(mContext, mock(Lifecycle.class));
ReflectionHelpers.setField(mController, "mBackend", mBackend); ReflectionHelpers.setField(mController, "mBackend", mBackend);
when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
mockPref);
mController.displayPreference(mPreferenceScreen);
} }
@Test @Test
public void updateState_TotalSilence() { public void testIsAvailable() {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_NO_INTERRUPTIONS); assertTrue(mController.isAvailable());
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 @Test
public void updateState_AlarmsOnly() { public void testHasSummary() {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_ALARMS); Preference pref = mock(Preference.class);
mController.updateState(pref);
final ListPreference mockPref = mock(ListPreference.class); verify(pref).setSummary(any());
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)]);
}
}

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,24 +16,13 @@
package com.android.settings.notification; package com.android.settings.notification;
import static android.provider.Settings.Global.ZEN_MODE; import static org.junit.Assert.assertTrue;
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.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.ContentResolver;
import android.content.Context; 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.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -47,31 +36,17 @@ import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers; import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
public class ZenModeMessagesPreferenceControllerTest { public final class ZenModeMessagesPreferenceControllerTest {
private ZenModeMessagesPreferenceController mController; private ZenModeMessagesPreferenceController mController;
@Mock
private ZenModeBackend mBackend;
@Mock @Mock
private NotificationManager mNotificationManager; private NotificationManager mNotificationManager;
@Mock @Mock
private ListPreference mockPref;
@Mock
private NotificationManager.Policy mPolicy; private NotificationManager.Policy mPolicy;
@Mock
private PreferenceScreen mPreferenceScreen;
private ContentResolver mContentResolver;
private Context mContext;
/** private Context mContext;
* Array Values Key @Mock
* 0: anyone private ZenModeBackend mBackend;
* 1: contacts
* 2: starred
* 3: none
*/
private String[] mValues;
@Before @Before
public void setup() { public void setup() {
@@ -80,100 +55,23 @@ public class ZenModeMessagesPreferenceControllerTest {
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager); shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
mContext = RuntimeEnvironment.application; mContext = RuntimeEnvironment.application;
mValues = mContext.getResources().getStringArray(R.array.zen_mode_contacts_values);
mContentResolver = RuntimeEnvironment.application.getContentResolver();
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy); when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
when(mBackend.getPriorityMessageSenders()) mController = new ZenModeMessagesPreferenceController(
.thenReturn(NotificationManager.Policy.PRIORITY_SENDERS_STARRED); mContext, mock(Lifecycle.class), "zen_mode_messages_settings");
when(mBackend.getContactsSummary(ZenModeBackend.SOURCE_NONE))
.thenCallRealMethod();
when(mBackend.getContactsSummary(NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES))
.thenCallRealMethod();
mController = new ZenModeMessagesPreferenceController(mContext, mock(Lifecycle.class));
ReflectionHelpers.setField(mController, "mBackend", mBackend); ReflectionHelpers.setField(mController, "mBackend", mBackend);
when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
mockPref);
mController.displayPreference(mPreferenceScreen);
} }
@Test @Test
public void updateState_TotalSilence() { public void testIsAvailable() {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_NO_INTERRUPTIONS); assertTrue(mController.isAvailable());
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 // TODO: (b/111475013 - beverlyt) set messages summary
public void updateState_AlarmsOnly() { // @Test
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_ALARMS); // public void testHasSummary() {
// Preference pref = mock(Preference.class);
final ListPreference mockPref = mock(ListPreference.class); // mController.updateState(pref);
mController.updateState(mockPref); // verify(pref).setSummary(any());
// }
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)]);
}
}

View File

@@ -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)]);
}
}

View File

@@ -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)]);
}
}

View File

@@ -68,63 +68,6 @@ public class ZenModeSettingsTest {
mBuilder.getBlockedEffectsSummary(policy)); 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 @Test
public void testGetCallsSettingSummary_none() { public void testGetCallsSettingSummary_none() {
Policy policy = new Policy(0, 0, 0, 0); Policy policy = new Policy(0, 0, 0, 0);