From 4359d4b9c9ebfa26c50acb2be4d8817d6aebe708 Mon Sep 17 00:00:00 2001 From: Beverly Date: Mon, 2 Oct 2017 09:45:48 -0400 Subject: [PATCH] Moved zenMode visual effects + automatic rule page - Automatic zen rules have their own page like in N - Minor string changes to page and add rule dialog - Zen mode visual effects was moved into behavior settings Bug: 63077372 Test: $ make SettingsUnitTests -j40 $ adb install -r ${OUT}/data/app/SettingsUnitTests/SettingsUnitTests.apk $ adb shell am instrument -w com.android.settings.tests.unit/android.support.test.runner.AndroidJUnitRunner Change-Id: I9635f8f7969b76d036bc06ec44705815e540777a --- AndroidManifest.xml | 54 +-- res/layout/zen_rule_name.xml | 4 +- res/values/strings.xml | 59 +-- ...s.xml => zen_mode_automation_settings.xml} | 19 +- res/xml/zen_mode_behavior_settings.xml | 21 +- res/xml/zen_mode_settings.xml | 15 +- src/com/android/settings/Settings.java | 1 - .../core/gateway/SettingsGateway.java | 4 +- .../settings/notification/SoundSettings.java | 1 - .../ZenModeAutomationSettings.java | 348 ++++++++++++++++++ .../notification/ZenModeBehaviorSettings.java | 59 +++ .../notification/ZenModeRuleSettingsBase.java | 2 +- .../notification/ZenModeSettings.java | 268 +------------- .../ZenModeVisualInterruptionSettings.java | 146 -------- .../notification/ZenRuleNameDialog.java | 29 +- .../notification/ZenRuleSelectionDialog.java | 7 +- .../search/SearchIndexableResources.java | 6 +- .../ZenModeSettingsIntegrationTest.java | 43 ++- 18 files changed, 572 insertions(+), 514 deletions(-) rename res/xml/{zen_mode_visual_interruptions_settings.xml => zen_mode_automation_settings.xml} (51%) create mode 100644 src/com/android/settings/notification/ZenModeAutomationSettings.java delete mode 100644 src/com/android/settings/notification/ZenModeVisualInterruptionSettings.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index bc63d14f96f..7190968b109 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -735,6 +735,32 @@ + + + + + + + + + + + + + + @@ -744,37 +770,11 @@ - - - - - + android:value="com.android.settings.notification.ZenModeAutomationSettings" /> - - - - - - - - - Power on sounds - No automatic rules turned on + Never - 1 automatic rule turned on - %d automatic rules turned on + 1 rule + %d rules @@ -6718,8 +6718,11 @@ No sound except alarms, media and system feedback (Alarms only) - - Automatic rules + + Turn on automatically + + + Automatic rules Set Do Not Disturb rules @@ -6742,6 +6745,12 @@ Block visual disturbances + + Allow visual signals + + + Add + Work profile sounds @@ -7129,7 +7138,13 @@ Rule name already in use - Add more + Add rule + + + Add event rule + + + Add time rule Delete rule @@ -7153,13 +7168,13 @@ Configure rule - Time rule + Time Automatic rule set to turn on Do Not Disturb during specified times - Event rule + Event Automatic rule set to turn on Do Not Disturb during specified events @@ -7314,28 +7329,16 @@ Change to always interrupt - - Block when screen is on - - - Prevent notifications silenced by Do Not Disturb from peeking or popping on screen - - - Block when screen is off - + + When the screen is on + + Let notifications silenced by Do Not Disturb pop on screen + + When the screen is off - Prevent notifications silenced by Do Not Disturb from turning on the screen or pulsing the notification light + Let notifications silenced by Do Not Disturb turn on the screen and blink the light - Prevent notifications silenced by Do Not Disturb from turning on the screen - - - Off - - When screen is on - - When screen is off - - When screen is on or off + Let notifications silenced by Do Not Disturb turn on the screen diff --git a/res/xml/zen_mode_visual_interruptions_settings.xml b/res/xml/zen_mode_automation_settings.xml similarity index 51% rename from res/xml/zen_mode_visual_interruptions_settings.xml rename to res/xml/zen_mode_automation_settings.xml index 64c79ec6765..33842ec2165 100644 --- a/res/xml/zen_mode_visual_interruptions_settings.xml +++ b/res/xml/zen_mode_automation_settings.xml @@ -1,5 +1,6 @@ - - - - - - - + android:key="zen_mode_automation_settings_page" + android:title="@string/zen_mode_automation_settings_page_title" > + diff --git a/res/xml/zen_mode_behavior_settings.xml b/res/xml/zen_mode_behavior_settings.xml index 8281f6567fa..999d6b4b05a 100644 --- a/res/xml/zen_mode_behavior_settings.xml +++ b/res/xml/zen_mode_behavior_settings.xml @@ -15,9 +15,12 @@ limitations under the License. --> - + android:title="@string/zen_mode_behavior_settings_title" + settings:initialExpandedChildrenCount="7"> + + + + + + + + diff --git a/res/xml/zen_mode_settings.xml b/res/xml/zen_mode_settings.xml index b8ee41debd9..92e2b7fb6fa 100644 --- a/res/xml/zen_mode_settings.xml +++ b/res/xml/zen_mode_settings.xml @@ -17,21 +17,16 @@ + android:title="@string/zen_mode_settings_title"> - - - - + diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index eac38015312..6c21ff4be05 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -125,7 +125,6 @@ public class Settings extends SettingsActivity { public static class ZenModeScheduleRuleSettingsActivity extends SettingsActivity { /* empty */ } public static class ZenModeEventRuleSettingsActivity extends SettingsActivity { /* empty */ } public static class ZenModeExternalRuleSettingsActivity extends SettingsActivity { /* empty */ } - public static class ZenModeVisualInterruptionSettingsActivity extends SettingsActivity { /* empty */} public static class SoundSettingsActivity extends SettingsActivity { /* empty */ } public static class ConfigureNotificationSettingsActivity extends SettingsActivity { /* empty */ } public static class NotificationAppListActivity extends SettingsActivity { /* empty */ } diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java index f2e49a45d78..057392be85b 100644 --- a/src/com/android/settings/core/gateway/SettingsGateway.java +++ b/src/com/android/settings/core/gateway/SettingsGateway.java @@ -108,10 +108,10 @@ import com.android.settings.notification.NotificationStation; import com.android.settings.notification.SoundSettings; import com.android.settings.notification.ZenAccessSettings; import com.android.settings.notification.ZenModeBehaviorSettings; +import com.android.settings.notification.ZenModeAutomationSettings; import com.android.settings.notification.ZenModeEventRuleSettings; import com.android.settings.notification.ZenModeScheduleRuleSettings; import com.android.settings.notification.ZenModeSettings; -import com.android.settings.notification.ZenModeVisualInterruptionSettings; import com.android.settings.password.ChooseLockPassword; import com.android.settings.password.ChooseLockPattern; import com.android.settings.print.PrintJobSettingsFragment; @@ -197,6 +197,7 @@ public class SettingsGateway { SpecialAccessSettings.class.getName(), NotificationAccessSettings.class.getName(), ZenAccessSettings.class.getName(), + ZenModeAutomationSettings.class.getName(), PrintSettingsFragment.class.getName(), PrintJobSettingsFragment.class.getName(), TrustedCredentialsSettings.class.getName(), @@ -219,7 +220,6 @@ public class SettingsGateway { ZenModeBehaviorSettings.class.getName(), ZenModeScheduleRuleSettings.class.getName(), ZenModeEventRuleSettings.class.getName(), - ZenModeVisualInterruptionSettings.class.getName(), ProcessStatsUi.class.getName(), AdvancedPowerUsageDetail.class.getName(), ProcessStatsSummary.class.getName(), diff --git a/src/com/android/settings/notification/SoundSettings.java b/src/com/android/settings/notification/SoundSettings.java index 982f4a4c420..06f15bb3c62 100644 --- a/src/com/android/settings/notification/SoundSettings.java +++ b/src/com/android/settings/notification/SoundSettings.java @@ -244,7 +244,6 @@ public class SoundSettings extends DashboardFragment { List keys = super.getNonIndexableKeys(context); // Duplicate results keys.add((new ZenModePreferenceController(context)).getPreferenceKey()); - keys.add(ZenModeSettings.KEY_VISUAL_SETTINGS); keys.add(KEY_CELL_BROADCAST_SETTINGS); return keys; } diff --git a/src/com/android/settings/notification/ZenModeAutomationSettings.java b/src/com/android/settings/notification/ZenModeAutomationSettings.java new file mode 100644 index 00000000000..07e9228abe6 --- /dev/null +++ b/src/com/android/settings/notification/ZenModeAutomationSettings.java @@ -0,0 +1,348 @@ +/* + * 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.app.AlertDialog; +import android.app.AutomaticZenRule; +import android.app.NotificationManager; +import android.content.ComponentName; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.content.pm.ServiceInfo; +import android.content.res.Resources; +import android.os.Bundle; +import android.provider.SearchIndexableResource; +import android.provider.Settings; +import android.service.notification.ConditionProviderService; +import android.service.notification.ZenModeConfig; +import android.support.v7.preference.Preference; +import android.support.v7.preference.Preference.OnPreferenceClickListener; +import android.support.v7.preference.PreferenceScreen; +import android.support.v7.preference.PreferenceViewHolder; +import android.view.View; + +import com.android.internal.logging.nano.MetricsProto.MetricsEvent; +import com.android.settings.R; +import com.android.settings.search.BaseSearchIndexProvider; +import com.android.settings.search.Indexable; +import com.android.settings.utils.ManagedServiceSettings.Config; +import com.android.settings.utils.ZenServiceListing; +import com.android.settingslib.TwoTargetPreference; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.Map; + +public class ZenModeAutomationSettings extends ZenModeSettingsBase implements Indexable { + + static final Config CONFIG = getConditionProviderConfig(); + + private PackageManager mPm; + private ZenServiceListing mServiceListing; + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + addPreferencesFromResource(R.xml.zen_mode_automation_settings); + + mPm = mContext.getPackageManager(); + mServiceListing = new ZenServiceListing(mContext, CONFIG); + mServiceListing.reloadApprovedServices(); + } + + @Override + protected void onZenModeChanged() { + // don't care + } + + @Override + protected void onZenModeConfigChanged() { + updateControls(); + } + + @Override + public void onResume() { + super.onResume(); + if (isUiRestricted()) { + return; + } + updateControls(); + } + + private void showAddRuleDialog() { + new ZenRuleSelectionDialog(mContext, mServiceListing) { + @Override + public void onSystemRuleSelected(ZenRuleInfo ri) { + showNameRuleDialog(ri); + } + + @Override + public void onExternalRuleSelected(ZenRuleInfo ri) { + Intent intent = new Intent().setComponent(ri.configurationActivity); + startActivity(intent); + } + }.show(); + } + + private void showNameRuleDialog(final ZenRuleInfo ri) { + new ZenRuleNameDialog(mContext, null, ri.defaultConditionId) { + @Override + public void onOk(String ruleName) { + mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_ZEN_ADD_RULE_OK); + AutomaticZenRule rule = new AutomaticZenRule(ruleName, ri.serviceComponent, + ri.defaultConditionId, NotificationManager.INTERRUPTION_FILTER_PRIORITY, + true); + String savedRuleId = addZenRule(rule); + if (savedRuleId != null) { + startActivity(getRuleIntent(ri.settingsAction, null, savedRuleId)); + } + } + }.show(); + } + + private void showDeleteRuleDialog(final String ruleId, final CharSequence ruleName) { + new AlertDialog.Builder(mContext) + .setMessage(getString(R.string.zen_mode_delete_rule_confirmation, ruleName)) + .setNegativeButton(R.string.cancel, null) + .setPositiveButton(R.string.zen_mode_delete_rule_button, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + mMetricsFeatureProvider.action(mContext, + MetricsEvent.ACTION_ZEN_DELETE_RULE_OK); + removeZenRule(ruleId); + } + }) + .show(); + } + + private Intent getRuleIntent(String settingsAction, ComponentName configurationActivity, + String ruleId) { + final Intent intent = new Intent() + .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + .putExtra(ConditionProviderService.EXTRA_RULE_ID, ruleId); + if (configurationActivity != null) { + intent.setComponent(configurationActivity); + } else { + intent.setAction(settingsAction); + } + return intent; + } + + private Map.Entry[] sortedRules() { + final Map.Entry[] rt = + mRules.toArray(new Map.Entry[mRules.size()]); + Arrays.sort(rt, RULE_COMPARATOR); + return rt; + } + + private void updateControls() { + final PreferenceScreen root = getPreferenceScreen(); + root.removeAll(); + final Map.Entry[] sortedRules = sortedRules(); + for (Map.Entry sortedRule : sortedRules) { + ZenRulePreference pref = new ZenRulePreference(getPrefContext(), sortedRule); + if (pref.appExists) { + root.addPreference(pref); + } + } + final Preference p = new Preference(getPrefContext()); + p.setIcon(R.drawable.ic_menu_add); + p.setTitle(R.string.zen_mode_add_rule); + p.setPersistent(false); + p.setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_ZEN_ADD_RULE); + showAddRuleDialog(); + return true; + } + }); + root.addPreference(p); + } + + @Override + public int getMetricsCategory() { + return MetricsEvent.NOTIFICATION_ZEN_MODE_AUTOMATION; + } + + private String computeRuleSummary(AutomaticZenRule rule, boolean isSystemRule, + CharSequence providerLabel) { + final String mode = computeZenModeCaption(getResources(), rule.getInterruptionFilter()); + final String ruleState = (rule == null || !rule.isEnabled()) + ? getString(R.string.switch_off_text) + : getString(R.string.zen_mode_rule_summary_enabled_combination, mode); + + return ruleState; + } + + private static Config getConditionProviderConfig() { + final Config c = new Config(); + c.tag = TAG; + c.intentAction = ConditionProviderService.SERVICE_INTERFACE; + c.permission = android.Manifest.permission.BIND_CONDITION_PROVIDER_SERVICE; + c.noun = "condition provider"; + return c; + } + + private static String computeZenModeCaption(Resources res, int zenMode) { + switch (zenMode) { + case NotificationManager.INTERRUPTION_FILTER_ALARMS: + return res.getString(R.string.zen_mode_option_alarms); + case NotificationManager.INTERRUPTION_FILTER_PRIORITY: + return res.getString(R.string.zen_mode_option_important_interruptions); + case NotificationManager.INTERRUPTION_FILTER_NONE: + return res.getString(R.string.zen_mode_option_no_interruptions); + default: + return null; + } + } + + public static ZenRuleInfo getRuleInfo(PackageManager pm, ServiceInfo si) { + if (si == null || si.metaData == null) { + return null; + } + final String ruleType = si.metaData.getString(ConditionProviderService.META_DATA_RULE_TYPE); + final ComponentName configurationActivity = getSettingsActivity(si); + if (ruleType != null && !ruleType.trim().isEmpty() && configurationActivity != null) { + final ZenRuleInfo ri = new ZenRuleInfo(); + ri.serviceComponent = new ComponentName(si.packageName, si.name); + ri.settingsAction = Settings.ACTION_ZEN_MODE_EXTERNAL_RULE_SETTINGS; + ri.title = ruleType; + ri.packageName = si.packageName; + ri.configurationActivity = getSettingsActivity(si); + ri.packageLabel = si.applicationInfo.loadLabel(pm); + ri.ruleInstanceLimit = + si.metaData.getInt(ConditionProviderService.META_DATA_RULE_INSTANCE_LIMIT, -1); + return ri; + } + return null; + } + + private static ComponentName getSettingsActivity(ServiceInfo si) { + if (si == null || si.metaData == null) { + return null; + } + final String configurationActivity = + si.metaData.getString(ConditionProviderService.META_DATA_CONFIGURATION_ACTIVITY); + if (configurationActivity != null) { + return ComponentName.unflattenFromString(configurationActivity); + } + return null; + } + + private static final Comparator> RULE_COMPARATOR = + new Comparator>() { + @Override + public int compare(Map.Entry lhs, + Map.Entry rhs) { + int byDate = Long.compare(lhs.getValue().getCreationTime(), + rhs.getValue().getCreationTime()); + if (byDate != 0) { + return byDate; + } else { + return key(lhs.getValue()).compareTo(key(rhs.getValue())); + } + } + + private String key(AutomaticZenRule rule) { + final int type = ZenModeConfig.isValidScheduleConditionId(rule.getConditionId()) + ? 1 : ZenModeConfig.isValidEventConditionId(rule.getConditionId()) + ? 2 : 3; + return type + rule.getName().toString(); + } + }; + + private class ZenRulePreference extends TwoTargetPreference { + final CharSequence mName; + final String mId; + final boolean appExists; + + public ZenRulePreference(Context context, + final Map.Entry ruleEntry) { + super(context); + + final AutomaticZenRule rule = ruleEntry.getValue(); + mName = rule.getName(); + mId = ruleEntry.getKey(); + + final boolean isSchedule = ZenModeConfig.isValidScheduleConditionId( + rule.getConditionId()); + final boolean isEvent = ZenModeConfig.isValidEventConditionId(rule.getConditionId()); + final boolean isSystemRule = isSchedule || isEvent; + + try { + ApplicationInfo info = mPm.getApplicationInfo(rule.getOwner().getPackageName(), 0); + setSummary(computeRuleSummary(rule, isSystemRule, info.loadLabel(mPm))); + } catch (PackageManager.NameNotFoundException e) { + appExists = false; + return; + } + + appExists = true; + setTitle(rule.getName()); + setPersistent(false); + + final String action = isSchedule ? ZenModeScheduleRuleSettings.ACTION + : isEvent ? ZenModeEventRuleSettings.ACTION : ""; + ServiceInfo si = mServiceListing.findService(rule.getOwner()); + ComponentName settingsActivity = getSettingsActivity(si); + setIntent(getRuleIntent(action, settingsActivity, mId)); + setSelectable(settingsActivity != null || isSystemRule); + } + + @Override + protected int getSecondTargetResId() { + return R.layout.zen_rule_widget; + } + + @Override + public void onBindViewHolder(PreferenceViewHolder view) { + super.onBindViewHolder(view); + + View v = view.findViewById(R.id.delete_zen_rule); + if (v != null) { + v.setOnClickListener(mDeleteListener); + } + } + + private final View.OnClickListener mDeleteListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + showDeleteRuleDialog(mId, mName); + } + }; + } + + /** + * For Search. + */ + public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = + new BaseSearchIndexProvider() { + @Override + public List getXmlResourcesToIndex( + Context context, boolean enabled) { + final SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.zen_mode_automation_settings; + return Arrays.asList(sir); + } + }; +} diff --git a/src/com/android/settings/notification/ZenModeBehaviorSettings.java b/src/com/android/settings/notification/ZenModeBehaviorSettings.java index d03b0158860..6fc97cffb40 100644 --- a/src/com/android/settings/notification/ZenModeBehaviorSettings.java +++ b/src/com/android/settings/notification/ZenModeBehaviorSettings.java @@ -46,6 +46,11 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde private static final String KEY_MESSAGES = "zen_mode_messages"; private static final String KEY_CALLS = "zen_mode_calls"; private static final String KEY_REPEAT_CALLERS = "zen_mode_repeat_callers"; + private static final String KEY_SCREEN_OFF = "zen_mode_screen_off"; + private static final String KEY_SCREEN_ON = "zen_mode_screen_on"; + + private SwitchPreference mScreenOff; + private SwitchPreference mScreenOn; private static final int SOURCE_NONE = -1; @@ -190,6 +195,43 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde } }); + mScreenOff = (SwitchPreference) root.findPreference(KEY_SCREEN_OFF); + if (!getResources() + .getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed)) { + mScreenOff.setSummary(R.string.zen_mode_screen_off_summary_no_led); + } + + mScreenOff.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if (mDisableListeners) return true; + final boolean bypass = (Boolean) newValue; + mMetricsFeatureProvider.action(mContext, + MetricsEvent.ACTION_ZEN_ALLOW_WHEN_SCREEN_OFF, !bypass); + if (DEBUG) Log.d(TAG, "onPrefChange suppressWhenScreenOff=" + !bypass); + savePolicy(mPolicy.priorityCategories, + mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders, + getNewSuppressedEffects(!bypass, Policy.SUPPRESSED_EFFECT_SCREEN_OFF)); + return true; + } + }); + + mScreenOn = (SwitchPreference) root.findPreference(KEY_SCREEN_ON); + mScreenOn.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if (mDisableListeners) return true; + final boolean bypass = (Boolean) newValue; + mMetricsFeatureProvider.action(mContext, + MetricsEvent.ACTION_ZEN_ALLOW_WHEN_SCREEN_ON, bypass); + if (DEBUG) Log.d(TAG, "onPrefChange allowWhenScreenOn=" + !bypass); + savePolicy(mPolicy.priorityCategories, + mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders, + getNewSuppressedEffects(!bypass, Policy.SUPPRESSED_EFFECT_SCREEN_ON)); + return true; + } + }); + updateControls(); } @@ -244,6 +286,10 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde updateControlsPolicy(); setTogglesEnabled(true); } + + mScreenOff.setChecked(isEffectAllowed(Policy.SUPPRESSED_EFFECT_SCREEN_OFF)); + mScreenOn.setChecked(isEffectAllowed(Policy.SUPPRESSED_EFFECT_SCREEN_ON)); + mDisableListeners = false; } @@ -324,4 +370,17 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde } }; + private int getNewSuppressedEffects(boolean suppress, int effectType) { + int effects = mPolicy.suppressedVisualEffects; + if (suppress) { + effects |= effectType; + } else { + effects &= ~effectType; + } + return effects; + } + + private boolean isEffectAllowed(int effect) { + return (mPolicy.suppressedVisualEffects & effect) == 0; + } } diff --git a/src/com/android/settings/notification/ZenModeRuleSettingsBase.java b/src/com/android/settings/notification/ZenModeRuleSettingsBase.java index 86576cf3812..83c67534e98 100644 --- a/src/com/android/settings/notification/ZenModeRuleSettingsBase.java +++ b/src/com/android/settings/notification/ZenModeRuleSettingsBase.java @@ -221,7 +221,7 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase } private void showRuleNameDialog() { - new ZenRuleNameDialog(mContext, mRule.getName()) { + new ZenRuleNameDialog(mContext, mRule.getName(), null) { @Override public void onOk(String ruleName) { mRule.setName(ruleName); diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java index 7f9a7c34940..2699cfdb2d1 100644 --- a/src/com/android/settings/notification/ZenModeSettings.java +++ b/src/com/android/settings/notification/ZenModeSettings.java @@ -16,37 +16,22 @@ package com.android.settings.notification; -import android.app.AlertDialog; import android.app.AutomaticZenRule; import android.app.NotificationManager; import android.app.NotificationManager.Policy; -import android.content.ComponentName; import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageManager; -import android.content.pm.ServiceInfo; -import android.content.res.Resources; import android.os.Bundle; import android.provider.SearchIndexableResource; import android.provider.Settings; -import android.service.notification.ConditionProviderService; import android.service.notification.ZenModeConfig; import android.support.annotation.VisibleForTesting; import android.support.v7.preference.Preference; -import android.support.v7.preference.PreferenceCategory; import android.support.v7.preference.PreferenceScreen; -import android.support.v7.preference.PreferenceViewHolder; -import android.view.View; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.R; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; -import com.android.settings.utils.ManagedServiceSettings; -import com.android.settings.utils.ZenServiceListing; -import com.android.settingslib.TwoTargetPreference; import java.util.ArrayList; import java.util.Arrays; @@ -57,19 +42,13 @@ import java.util.Map.Entry; public class ZenModeSettings extends ZenModeSettingsBase implements Indexable { - public static final String KEY_VISUAL_SETTINGS = "zen_mode_visual_interruptions_settings"; private static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_behavior_settings"; - private static final String KEY_AUTOMATIC_RULES = "zen_mode_automatic_rules"; + private static final String KEY_AUTOMATION_SETTINGS = "zen_mode_automation_settings"; - static final ManagedServiceSettings.Config CONFIG = getConditionProviderConfig(); - - private PreferenceCategory mAutomaticRules; private Preference mBehaviorSettings; - private Preference mVisualSettings; + private Preference mAutomationSettings; private Policy mPolicy; private SummaryBuilder mSummaryBuilder; - private PackageManager mPm; - private ZenServiceListing mServiceListing; @Override public void onCreate(Bundle savedInstanceState) { @@ -78,14 +57,10 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable { addPreferencesFromResource(R.xml.zen_mode_settings); final PreferenceScreen root = getPreferenceScreen(); - mAutomaticRules = (PreferenceCategory) root.findPreference(KEY_AUTOMATIC_RULES); mBehaviorSettings = root.findPreference(KEY_BEHAVIOR_SETTINGS); - mVisualSettings = root.findPreference(KEY_VISUAL_SETTINGS); + mAutomationSettings = root.findPreference(KEY_AUTOMATION_SETTINGS); mPolicy = NotificationManager.from(mContext).getNotificationPolicy(); mSummaryBuilder = new SummaryBuilder(getContext()); - mPm = mContext.getPackageManager(); - mServiceListing = new ZenServiceListing(mContext, CONFIG); - mServiceListing.reloadApprovedServices(); } @Override @@ -115,168 +90,15 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable { private void updateControls() { updateBehaviorSettingsSummary(); - updateVisualSettingsSummary(); - updateAutomaticRules(); + updateAutomationSettingsSummary(); } private void updateBehaviorSettingsSummary() { mBehaviorSettings.setSummary(mSummaryBuilder.getBehaviorSettingSummary(mPolicy, mZenMode)); } - private void updateVisualSettingsSummary() { - mVisualSettings.setSummary(mSummaryBuilder.getVisualSettingSummary(mPolicy)); - } - - private void updateAutomaticRules() { - mAutomaticRules.removeAll(); - final Map.Entry[] sortedRules = sortedRules(); - for (Map.Entry sortedRule : sortedRules) { - ZenRulePreference pref = new ZenRulePreference(getPrefContext(), sortedRule); - if (pref.appExists) { - mAutomaticRules.addPreference(pref); - } - } - final Preference p = new Preference(getPrefContext()); - p.setIcon(R.drawable.ic_menu_add); - p.setTitle(R.string.zen_mode_add_rule); - p.setPersistent(false); - p.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_ZEN_ADD_RULE); - showAddRuleDialog(); - return true; - } - }); - mAutomaticRules.addPreference(p); - } - - private void showAddRuleDialog() { - new ZenRuleSelectionDialog(mContext, mServiceListing) { - @Override - public void onSystemRuleSelected(ZenRuleInfo ri) { - showNameRuleDialog(ri); - } - - @Override - public void onExternalRuleSelected(ZenRuleInfo ri) { - Intent intent = new Intent().setComponent(ri.configurationActivity); - startActivity(intent); - } - }.show(); - } - - private String computeRuleSummary(AutomaticZenRule rule, boolean isSystemRule, - CharSequence providerLabel) { - final String mode = computeZenModeCaption(getResources(), rule.getInterruptionFilter()); - final String ruleState = (rule == null || !rule.isEnabled()) - ? getString(R.string.switch_off_text) - : getString(R.string.zen_mode_rule_summary_enabled_combination, mode); - - return ruleState; - } - - private static ManagedServiceSettings.Config getConditionProviderConfig() { - final ManagedServiceSettings.Config c = new ManagedServiceSettings.Config(); - c.tag = TAG; - c.intentAction = ConditionProviderService.SERVICE_INTERFACE; - c.permission = android.Manifest.permission.BIND_CONDITION_PROVIDER_SERVICE; - c.noun = "condition provider"; - return c; - } - - private static String computeZenModeCaption(Resources res, int zenMode) { - switch (zenMode) { - case NotificationManager.INTERRUPTION_FILTER_ALARMS: - return res.getString(R.string.zen_mode_option_alarms); - case NotificationManager.INTERRUPTION_FILTER_PRIORITY: - return res.getString(R.string.zen_mode_option_important_interruptions); - case NotificationManager.INTERRUPTION_FILTER_NONE: - return res.getString(R.string.zen_mode_option_no_interruptions); - default: - return null; - } - } - - public static ZenRuleInfo getRuleInfo(PackageManager pm, ServiceInfo si) { - if (si == null || si.metaData == null) return null; - final String ruleType = si.metaData.getString(ConditionProviderService.META_DATA_RULE_TYPE); - final ComponentName configurationActivity = getSettingsActivity(si); - if (ruleType != null && !ruleType.trim().isEmpty() && configurationActivity != null) { - final ZenRuleInfo ri = new ZenRuleInfo(); - ri.serviceComponent = new ComponentName(si.packageName, si.name); - ri.settingsAction = Settings.ACTION_ZEN_MODE_EXTERNAL_RULE_SETTINGS; - ri.title = ruleType; - ri.packageName = si.packageName; - ri.configurationActivity = getSettingsActivity(si); - ri.packageLabel = si.applicationInfo.loadLabel(pm); - ri.ruleInstanceLimit = - si.metaData.getInt(ConditionProviderService.META_DATA_RULE_INSTANCE_LIMIT, -1); - return ri; - } - return null; - } - - private static ComponentName getSettingsActivity(ServiceInfo si) { - if (si == null || si.metaData == null) return null; - final String configurationActivity = - si.metaData.getString(ConditionProviderService.META_DATA_CONFIGURATION_ACTIVITY); - if (configurationActivity != null) { - return ComponentName.unflattenFromString(configurationActivity); - } - return null; - } - - private void showNameRuleDialog(final ZenRuleInfo ri) { - new ZenRuleNameDialog(mContext, null) { - @Override - public void onOk(String ruleName) { - mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_ZEN_ADD_RULE_OK); - AutomaticZenRule rule = new AutomaticZenRule(ruleName, ri.serviceComponent, - ri.defaultConditionId, NotificationManager.INTERRUPTION_FILTER_PRIORITY, - true); - String savedRuleId = addZenRule(rule); - if (savedRuleId != null) { - startActivity(getRuleIntent(ri.settingsAction, null, savedRuleId)); - } - } - }.show(); - } - - private void showDeleteRuleDialog(final String ruleId, final CharSequence ruleName) { - new AlertDialog.Builder(mContext) - .setMessage(getString(R.string.zen_mode_delete_rule_confirmation, ruleName)) - .setNegativeButton(R.string.cancel, null) - .setPositiveButton(R.string.zen_mode_delete_rule_button, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - mMetricsFeatureProvider.action(mContext, - MetricsEvent.ACTION_ZEN_DELETE_RULE_OK); - removeZenRule(ruleId); - } - }) - .show(); - } - - private Intent getRuleIntent(String settingsAction, ComponentName configurationActivity, - String ruleId) { - Intent intent = new Intent() - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - .putExtra(ConditionProviderService.EXTRA_RULE_ID, ruleId); - if (configurationActivity != null) { - intent.setComponent(configurationActivity); - } else { - intent.setAction(settingsAction); - } - return intent; - } - - private Map.Entry[] sortedRules() { - final Map.Entry[] rt = - mRules.toArray(new Map.Entry[mRules.size()]); - Arrays.sort(rt, RULE_COMPARATOR); - return rt; + private void updateAutomationSettingsSummary() { + mAutomationSettings.setSummary(mSummaryBuilder.getAutomaticRulesSummary()); } @Override @@ -284,67 +106,6 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable { return R.string.help_uri_interruptions; } - private class ZenRulePreference extends TwoTargetPreference { - final CharSequence mName; - final String mId; - final boolean appExists; - - public ZenRulePreference(Context context, - final Map.Entry ruleEntry) { - super(context); - - final AutomaticZenRule rule = ruleEntry.getValue(); - mName = rule.getName(); - mId = ruleEntry.getKey(); - - final boolean isSchedule = ZenModeConfig.isValidScheduleConditionId( - rule.getConditionId()); - final boolean isEvent = ZenModeConfig.isValidEventConditionId(rule.getConditionId()); - final boolean isSystemRule = isSchedule || isEvent; - - try { - ApplicationInfo info = mPm.getApplicationInfo(rule.getOwner().getPackageName(), 0); - setSummary(computeRuleSummary(rule, isSystemRule, info.loadLabel(mPm))); - } catch (PackageManager.NameNotFoundException e) { - appExists = false; - return; - } - - appExists = true; - setTitle(rule.getName()); - setPersistent(false); - - final String action = isSchedule ? ZenModeScheduleRuleSettings.ACTION - : isEvent ? ZenModeEventRuleSettings.ACTION : ""; - ServiceInfo si = mServiceListing.findService(rule.getOwner()); - ComponentName settingsActivity = getSettingsActivity(si); - setIntent(getRuleIntent(action, settingsActivity, mId)); - setSelectable(settingsActivity != null || isSystemRule); - } - - @Override - protected int getSecondTargetResId() { - return R.layout.zen_rule_widget; - } - - @Override - public void onBindViewHolder(PreferenceViewHolder view) { - super.onBindViewHolder(view); - - View v = view.findViewById(R.id.delete_zen_rule); - if (v != null) { - v.setOnClickListener(mDeleteListener); - } - } - - private final View.OnClickListener mDeleteListener = new View.OnClickListener() { - @Override - public void onClick(View v) { - showDeleteRuleDialog(mId, mName); - } - }; - } - public static class SummaryBuilder { private Context mContext; @@ -393,19 +154,6 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable { return mContext.getString(R.string.zen_mode_behavior_no_sound_except, s); } - String getVisualSettingSummary(Policy policy) { - String s = mContext.getString(R.string.zen_mode_all_visual_interruptions); - if (isEffectSuppressed(policy, Policy.SUPPRESSED_EFFECT_SCREEN_ON) - && isEffectSuppressed(policy, Policy.SUPPRESSED_EFFECT_SCREEN_OFF)) { - s = mContext.getString(R.string.zen_mode_no_visual_interruptions); - } else if (isEffectSuppressed(policy, Policy.SUPPRESSED_EFFECT_SCREEN_ON)) { - s = mContext.getString(R.string.zen_mode_screen_on_visual_interruptions); - } else if (isEffectSuppressed(policy, Policy.SUPPRESSED_EFFECT_SCREEN_OFF)) { - s = mContext.getString(R.string.zen_mode_screen_off_visual_interruptions); - } - return s; - } - String getAutomaticRulesSummary() { final int count = getEnabledAutomaticRulesCount(); return count == 0 ? mContext.getString(R.string.zen_mode_settings_summary_off) @@ -479,7 +227,7 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable { } } - private static final Comparator> RULE_COMPARATOR = + private static final Comparator> RULE_COMPARATOR = new Comparator>() { @Override public int compare(Map.Entry lhs, @@ -502,6 +250,7 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable { return type + rule.getName().toString(); } }; + /** * For Search. */ @@ -515,4 +264,5 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable { return Arrays.asList(sir); } }; + } diff --git a/src/com/android/settings/notification/ZenModeVisualInterruptionSettings.java b/src/com/android/settings/notification/ZenModeVisualInterruptionSettings.java deleted file mode 100644 index 474992c1c91..00000000000 --- a/src/com/android/settings/notification/ZenModeVisualInterruptionSettings.java +++ /dev/null @@ -1,146 +0,0 @@ -/** - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.notification; - -import android.app.NotificationManager; -import android.app.NotificationManager.Policy; -import android.content.Context; -import android.os.Bundle; -import android.provider.SearchIndexableResource; -import android.support.v14.preference.SwitchPreference; -import android.support.v7.preference.Preference; -import android.support.v7.preference.PreferenceScreen; -import android.util.Log; - -import com.android.internal.logging.nano.MetricsProto.MetricsEvent; -import com.android.settings.R; -import com.android.settings.search.BaseSearchIndexProvider; -import com.android.settings.search.Indexable; - -import java.util.Arrays; -import java.util.List; - -public class ZenModeVisualInterruptionSettings extends ZenModeSettingsBase implements Indexable { - - private static final String KEY_SCREEN_OFF = "screenOff"; - private static final String KEY_SCREEN_ON = "screenOn"; - - private SwitchPreference mScreenOff; - private SwitchPreference mScreenOn; - - private boolean mDisableListeners; - private NotificationManager.Policy mPolicy; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.zen_mode_visual_interruptions_settings); - final PreferenceScreen root = getPreferenceScreen(); - - mPolicy = NotificationManager.from(mContext).getNotificationPolicy(); - - mScreenOff = (SwitchPreference) root.findPreference(KEY_SCREEN_OFF); - if (!getResources() - .getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed)) { - mScreenOff.setSummary(R.string.zen_mode_screen_off_summary_no_led); - } - mScreenOff.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - if (mDisableListeners) return true; - final boolean val = (Boolean) newValue; - mMetricsFeatureProvider.action(mContext, - MetricsEvent.ACTION_ZEN_ALLOW_WHEN_SCREEN_OFF, val); - if (DEBUG) Log.d(TAG, "onPrefChange suppressWhenScreenOff=" + val); - savePolicy(getNewSuppressedEffects(val, Policy.SUPPRESSED_EFFECT_SCREEN_OFF)); - return true; - } - }); - - mScreenOn = (SwitchPreference) root.findPreference(KEY_SCREEN_ON); - mScreenOn.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - if (mDisableListeners) return true; - final boolean val = (Boolean) newValue; - mMetricsFeatureProvider.action(mContext, - MetricsEvent.ACTION_ZEN_ALLOW_WHEN_SCREEN_ON, val); - if (DEBUG) Log.d(TAG, "onPrefChange suppressWhenScreenOn=" + val); - savePolicy(getNewSuppressedEffects(val, Policy.SUPPRESSED_EFFECT_SCREEN_ON)); - return true; - } - }); - } - - @Override - public int getMetricsCategory() { - return MetricsEvent.NOTIFICATION_ZEN_MODE_VISUAL_INTERRUPTIONS; - } - - @Override - protected void onZenModeChanged() { - // Don't care - } - - @Override - protected void onZenModeConfigChanged() { - mPolicy = NotificationManager.from(mContext).getNotificationPolicy(); - updateControls(); - } - - private void updateControls() { - mDisableListeners = true; - mScreenOff.setChecked(isEffectSuppressed(Policy.SUPPRESSED_EFFECT_SCREEN_OFF)); - mScreenOn.setChecked(isEffectSuppressed(Policy.SUPPRESSED_EFFECT_SCREEN_ON)); - mDisableListeners = false; - } - - private boolean isEffectSuppressed(int effect) { - return (mPolicy.suppressedVisualEffects & effect) != 0; - } - - private int getNewSuppressedEffects(boolean suppress, int effectType) { - int effects = mPolicy.suppressedVisualEffects; - if (suppress) { - effects |= effectType; - } else { - effects &= ~effectType; - } - return effects; - } - - private void savePolicy(int suppressedVisualEffects) { - mPolicy = new Policy(mPolicy.priorityCategories, - mPolicy.priorityCallSenders, mPolicy.priorityMessageSenders, - suppressedVisualEffects); - NotificationManager.from(mContext).setNotificationPolicy(mPolicy); - } - - /** - * For Search. - */ - public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = - new BaseSearchIndexProvider() { - @Override - public List getXmlResourcesToIndex( - Context context, boolean enabled) { - final SearchIndexableResource sir = new SearchIndexableResource(context); - sir.xmlResId = R.xml.zen_mode_visual_interruptions_settings; - return Arrays.asList(sir); - } - }; -} diff --git a/src/com/android/settings/notification/ZenRuleNameDialog.java b/src/com/android/settings/notification/ZenRuleNameDialog.java index c6ce23b011d..eb854318a05 100644 --- a/src/com/android/settings/notification/ZenRuleNameDialog.java +++ b/src/com/android/settings/notification/ZenRuleNameDialog.java @@ -19,6 +19,8 @@ package com.android.settings.notification; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; +import android.net.Uri; +import android.service.notification.ZenModeConfig; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; @@ -35,20 +37,21 @@ public abstract class ZenRuleNameDialog { private final CharSequence mOriginalRuleName; private final boolean mIsNew; - public ZenRuleNameDialog(Context context, CharSequence ruleName) { + public ZenRuleNameDialog(Context context, CharSequence ruleName, Uri conditionId) { mIsNew = ruleName == null; mOriginalRuleName = ruleName; - final View v = LayoutInflater.from(context).inflate(R.layout.zen_rule_name, null, false); - mEditText = (EditText) v.findViewById(R.id.rule_name); + final View v = LayoutInflater.from(context).inflate(R.layout.zen_rule_name, null, + false); + mEditText = (EditText) v.findViewById(R.id.zen_mode_rule_name); if (!mIsNew) { mEditText.setText(ruleName); } mEditText.setSelectAllOnFocus(true); - mDialog = new AlertDialog.Builder(context) - .setTitle(mIsNew ? R.string.zen_mode_add_rule : R.string.zen_mode_rule_name) + .setTitle(getTitleResource(conditionId)) .setView(v) - .setPositiveButton(R.string.okay, new DialogInterface.OnClickListener() { + .setPositiveButton(mIsNew ? R.string.zen_mode_add : R.string.okay, + new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final String newName = trimmedText(); @@ -75,4 +78,18 @@ public abstract class ZenRuleNameDialog { private String trimmedText() { return mEditText.getText() == null ? null : mEditText.getText().toString().trim(); } + + private int getTitleResource(Uri conditionId) { + final boolean isEvent = ZenModeConfig.isValidEventConditionId(conditionId); + final boolean isTime = ZenModeConfig.isValidScheduleConditionId(conditionId); + int titleResource = R.string.zen_mode_rule_name; + if (mIsNew) { + if (isEvent) { + titleResource = R.string.zen_mode_add_event_rule; + } else if (isTime) { + titleResource = R.string.zen_mode_add_time_rule; + } + } + return titleResource; + } } diff --git a/src/com/android/settings/notification/ZenRuleSelectionDialog.java b/src/com/android/settings/notification/ZenRuleSelectionDialog.java index 4fa632a72b6..3c49dcb222a 100644 --- a/src/com/android/settings/notification/ZenRuleSelectionDialog.java +++ b/src/com/android/settings/notification/ZenRuleSelectionDialog.java @@ -27,7 +27,6 @@ import android.content.pm.ServiceInfo; import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.service.notification.ZenModeConfig; -import android.util.ArraySet; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -36,15 +35,11 @@ import android.widget.LinearLayout; import android.widget.TextView; import com.android.settings.R; -import com.android.settings.utils.ServiceListing; import com.android.settings.utils.ZenServiceListing; import java.lang.ref.WeakReference; import java.text.Collator; -import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; -import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -169,7 +164,7 @@ public abstract class ZenRuleSelectionDialog { if (DEBUG) Log.d(TAG, "Services reloaded: count=" + services.size()); Set externalRuleTypes = new TreeSet<>(RULE_TYPE_COMPARATOR); for (ServiceInfo serviceInfo : services) { - final ZenRuleInfo ri = ZenModeSettings.getRuleInfo(mPm, serviceInfo); + final ZenRuleInfo ri = ZenModeAutomationSettings.getRuleInfo(mPm, serviceInfo); if (ri != null && ri.configurationActivity != null && mNm.isNotificationPolicyAccessGrantedForPackage(ri.packageName) && (ri.ruleInstanceLimit <= 0 || ri.ruleInstanceLimit diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java index 7252e2d492b..af631fdc50e 100644 --- a/src/com/android/settings/search/SearchIndexableResources.java +++ b/src/com/android/settings/search/SearchIndexableResources.java @@ -72,9 +72,9 @@ import com.android.settings.nfc.PaymentSettings; import com.android.settings.notification.ChannelImportanceSettings; import com.android.settings.notification.ConfigureNotificationSettings; import com.android.settings.notification.SoundSettings; +import com.android.settings.notification.ZenModeAutomationSettings; import com.android.settings.notification.ZenModeBehaviorSettings; import com.android.settings.notification.ZenModeSettings; -import com.android.settings.notification.ZenModeVisualInterruptionSettings; import com.android.settings.print.PrintSettingsFragment; import com.android.settings.security.LockscreenDashboardFragment; import com.android.settings.sim.SimSettings; @@ -192,7 +192,7 @@ public final class SearchIndexableResources { addIndex(BatterySaverSettings.class); addIndex(LockscreenDashboardFragment.class); addIndex(ZenModeBehaviorSettings.class); - addIndex(ZenModeVisualInterruptionSettings.class); + addIndex(ZenModeAutomationSettings.class); } private SearchIndexableResources() { @@ -209,4 +209,4 @@ public final class SearchIndexableResources { public static Collection values() { return sResMap.values(); } -} +} \ No newline at end of file diff --git a/tests/unit/src/com/android/settings/notification/ZenModeSettingsIntegrationTest.java b/tests/unit/src/com/android/settings/notification/ZenModeSettingsIntegrationTest.java index e7e5e199cbf..d5e7aaeb3eb 100644 --- a/tests/unit/src/com/android/settings/notification/ZenModeSettingsIntegrationTest.java +++ b/tests/unit/src/com/android/settings/notification/ZenModeSettingsIntegrationTest.java @@ -1,4 +1,4 @@ -package com.android.settings.notification; +package com.android.settings; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; @@ -36,12 +36,29 @@ public class ZenModeSettingsIntegrationTest { } @Test - public void testAutomaticRulesAppear() { + public void testZenModeSettingsPreferences() { launchZenSettings(); - onView(withText("Automatic rules")).check(matches(isDisplayed())); + onView(withText("Behavior")).check(matches(isDisplayed())); + onView(withText("Turn on automatically")).check(matches(isDisplayed())); + } + + @Test + public void testZenModeBehaviorPreferences() { + launchZenBehaviorSettings(); + onView(withText("Alarms")).check(matches(isDisplayed())); + onView(withText("Media and system feedback")).check(matches(isDisplayed())); + onView(withText("Reminders")).check(matches(isDisplayed())); + onView(withText("Events")).check(matches(isDisplayed())); + onView(withText("Messages")).check(matches(isDisplayed())); + onView(withText("Calls")).check(matches(isDisplayed())); + onView(withText("Repeat callers")).check(matches(isDisplayed())); + } + + @Test + public void testZenModeAutomationPreferences() { + launchZenAutomationSettings(); onView(withText("Weekend")).check(matches(isDisplayed())); - onView(withText("Add more")).check(matches(isDisplayed())).perform(click()); - onView(withText("Choose rule type")).check(matches(isDisplayed())); + onView(withText("Add rule")).check(matches(isDisplayed())); } private void launchZenSettings() { @@ -50,4 +67,18 @@ public class ZenModeSettingsIntegrationTest { .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(settingsIntent); } -} + + private void launchZenAutomationSettings() { + Intent settingsIntent = new Intent(Settings.ACTION_ZEN_MODE_AUTOMATION_SETTINGS) + .setPackage(mContext.getPackageName()) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mContext.startActivity(settingsIntent); + } + + private void launchZenBehaviorSettings() { + Intent settingsIntent = new Intent(Settings.ACTION_ZEN_MODE_PRIORITY_SETTINGS) + .setPackage(mContext.getPackageName()) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + mContext.startActivity(settingsIntent); + } +} \ No newline at end of file