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
This commit is contained in:
Beverly
2017-10-02 09:45:48 -04:00
parent 9e1570c5f3
commit 4359d4b9c9
18 changed files with 572 additions and 514 deletions

View File

@@ -735,6 +735,32 @@
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="com.android.settings.SHORTCUT" /> <category android:name="com.android.settings.SHORTCUT" />
</intent-filter> </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.notification.ZenModeSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
<activity android:name="Settings$ZenModeBehaviorSettingsActivity"
android:label="@string/zen_mode_behavior_settings_title"
android:icon="@drawable/ic_settings_notifications"
android:exported="true"
android:taskAffinity="">
<intent-filter android:priority="1">
<action android:name="android.settings.ZEN_MODE_PRIORITY_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.notification.ZenModeBehaviorSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
<activity android:name="Settings$ZenModeAutomationSettingsActivity"
android:label="@string/zen_mode_automation_settings_title"
android:icon="@drawable/ic_settings_notifications"
android:exported="true"
android:taskAffinity="">
<intent-filter android:priority="1"> <intent-filter android:priority="1">
<action android:name="android.settings.ZEN_MODE_AUTOMATION_SETTINGS" /> <action android:name="android.settings.ZEN_MODE_AUTOMATION_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
@@ -744,37 +770,11 @@
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS" <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.notification.ZenModeSettings" /> android:value="com.android.settings.notification.ZenModeAutomationSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
<activity android:name="Settings$ZenModeVisualInterruptionSettingsActivity"
android:label="@string/zen_mode_visual_interruptions_settings_title"
android:icon="@drawable/ic_settings_notifications"
android:exported="true"
android:taskAffinity="">
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.notification.ZenModeVisualInterruptionSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED" <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" /> android:value="true" />
</activity> </activity>
<activity android:name="Settings$ZenModeBehaviorSettingsActivity"
android:label="@string/zen_mode_behavior_settings_title"
android:icon="@drawable/ic_settings_notifications"
android:exported="true"
android:taskAffinity="">
<intent-filter android:priority="1">
<action android:name="android.settings.ZEN_MODE_BEHAVIOR_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.notification.ZenModeBehaviorSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
<activity android:name="Settings$WallpaperSettingsActivity" <activity android:name="Settings$WallpaperSettingsActivity"
android:label="@string/wallpaper_settings_fragment_title" android:label="@string/wallpaper_settings_fragment_title"
android:icon="@drawable/ic_wallpaper" android:icon="@drawable/ic_wallpaper"

View File

@@ -19,7 +19,7 @@
android:layout_height="wrap_content" > android:layout_height="wrap_content" >
<EditText <EditText
android:id="@+id/rule_name" android:id="@+id/zen_mode_rule_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="true" android:singleLine="true"
@@ -33,7 +33,7 @@
</EditText> </EditText>
<TextView <TextView
android:id="@+id/rule_name_warning" android:id="@+id/zen_mode_rule_name_warning"
android:visibility="invisible" android:visibility="invisible"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@@ -6689,12 +6689,12 @@
<string name="boot_sounds_title">Power on sounds</string> <string name="boot_sounds_title">Power on sounds</string>
<!-- Sound: Summary for the Do not Disturb option when there is no automatic rules turned on. [CHAR LIMIT=NONE]--> <!-- Sound: Summary for the Do not Disturb option when there is no automatic rules turned on. [CHAR LIMIT=NONE]-->
<string name="zen_mode_settings_summary_off">No automatic rules turned on</string> <string name="zen_mode_settings_summary_off">Never</string>
<!-- Sound: Summary for the Do not Disturb option when at least one automatic rules turned on. [CHAR LIMIT=NONE]--> <!-- Sound: Summary for the Do not Disturb option when at least one automatic rules turned on. [CHAR LIMIT=NONE]-->
<plurals name="zen_mode_settings_summary_on"> <plurals name="zen_mode_settings_summary_on">
<item quantity="one">1 automatic rule turned on</item> <item quantity="one">1 rule</item>
<item quantity="other"><xliff:g id="on_count" example="10">%d</xliff:g> automatic rules turned on</item> <item quantity="other"><xliff:g id="on_count" example="10">%d</xliff:g> rules</item>
</plurals> </plurals>
<!-- Sound: Title for the Do not Disturb option and associated settings page. [CHAR LIMIT=50]--> <!-- Sound: Title for the Do not Disturb option and associated settings page. [CHAR LIMIT=50]-->
@@ -6718,8 +6718,11 @@
<!-- Do not disturb: Specifies sounds that can bypass DND in user and/or API-invoked Alarms Only mode. [CHAR LIMIT=100] --> <!-- Do not disturb: Specifies sounds that can bypass DND in user and/or API-invoked Alarms Only mode. [CHAR LIMIT=100] -->
<string name="zen_mode_behavior_alarms_only">No sound except alarms, media and system feedback (Alarms only)</string> <string name="zen_mode_behavior_alarms_only">No sound except alarms, media and system feedback (Alarms only)</string>
<!-- Do not disturb: Title for the zen mode automation listing. [CHAR LIMIT=30] --> <!-- Do not disturb: Title for the zen mode automation option in Settings. [CHAR LIMIT=40] -->
<string name="zen_mode_automation_settings_title">Automatic rules</string> <string name="zen_mode_automation_settings_title">Turn on automatically</string>
<!-- 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>
<!-- Do not disturb: Title for the zen mode automation option Suggestion. [CHAR LIMIT=50] --> <!-- Do not disturb: Title for the zen mode automation option Suggestion. [CHAR LIMIT=50] -->
<string name="zen_mode_automation_suggestion_title">Set Do Not Disturb rules</string> <string name="zen_mode_automation_suggestion_title">Set Do Not Disturb rules</string>
@@ -6742,6 +6745,12 @@
<!-- Do not disturb: Title for the Visual interruptions option and associated settings page. [CHAR LIMIT=30] --> <!-- Do not disturb: Title for the Visual interruptions option and associated settings page. [CHAR LIMIT=30] -->
<string name="zen_mode_visual_interruptions_settings_title">Block visual disturbances</string> <string name="zen_mode_visual_interruptions_settings_title">Block visual disturbances</string>
<!-- Do not disturb: Subtitle for the Visual signals option to toggle on/off visual signals/alerts when the screen is on/when screen is off. [CHAR LIMIT=30] -->
<string name="zen_mode_visual_signals_settings_subtitle">Allow visual signals</string>
<!-- Do not disturb: Button to add new automatic rule to DND. [CHAR LIMIT=30] -->
<string name="zen_mode_add">Add</string>
<!-- Work Sounds: Work sound settings section header. [CHAR LIMIT=50] --> <!-- Work Sounds: Work sound settings section header. [CHAR LIMIT=50] -->
<string name="sound_work_settings">Work profile sounds</string> <string name="sound_work_settings">Work profile sounds</string>
@@ -7129,7 +7138,13 @@
<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 rule menu option name -->
<string name="zen_mode_add_rule">Add more</string> <string name="zen_mode_add_rule">Add rule</string>
<!-- [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>
<!-- [CHAR LIMIT=40] Zen mode settings: Add time-based rule, set rule name title -->
<string name="zen_mode_add_time_rule">Add time rule</string>
<!-- [CHAR LIMIT=40] Zen mode settings: Delete rule menu option name --> <!-- [CHAR LIMIT=40] Zen mode settings: Delete rule menu option name -->
<string name="zen_mode_delete_rule">Delete rule</string> <string name="zen_mode_delete_rule">Delete rule</string>
@@ -7153,13 +7168,13 @@
<string name="zen_mode_configure_rule">Configure rule</string> <string name="zen_mode_configure_rule">Configure rule</string>
<!-- [CHAR LIMIT=40] Zen mode settings: Schedule rule type name --> <!-- [CHAR LIMIT=40] Zen mode settings: Schedule rule type name -->
<string name="zen_schedule_rule_type_name">Time rule</string> <string name="zen_schedule_rule_type_name">Time</string>
<!-- [CHAR LIMIT=NONE] Zen mode settings: Schedule rule toast hint when enabled --> <!-- [CHAR LIMIT=NONE] Zen mode settings: Schedule rule toast hint when enabled -->
<string name="zen_schedule_rule_enabled_toast">Automatic rule set to turn on Do Not Disturb during specified times</string> <string name="zen_schedule_rule_enabled_toast">Automatic rule set to turn on Do Not Disturb during specified times</string>
<!-- [CHAR LIMIT=40] Zen mode settings: Event rule type name --> <!-- [CHAR LIMIT=40] Zen mode settings: Event rule type name -->
<string name="zen_event_rule_type_name">Event rule</string> <string name="zen_event_rule_type_name">Event</string>
<!-- [CHAR LIMIT=NONE] Zen mode settings: Event rule toast hint when enabled --> <!-- [CHAR LIMIT=NONE] Zen mode settings: Event rule toast hint when enabled -->
<string name="zen_event_rule_enabled_toast">Automatic rule set to turn on Do Not Disturb during specified events</string> <string name="zen_event_rule_enabled_toast">Automatic rule set to turn on Do Not Disturb during specified events</string>
@@ -7314,28 +7329,16 @@
<!-- [CHAR LIMIT=NONE] Zen mode summary spoken when changing mode by voice: Turn on all notifications. --> <!-- [CHAR LIMIT=NONE] Zen mode summary spoken when changing mode by voice: Turn on all notifications. -->
<string name="zen_mode_summary_always">Change to always interrupt</string> <string name="zen_mode_summary_always">Change to always interrupt</string>
<!-- [CHAR LIMIT=40] Zen mode settings: visual interruptions: screen is on: title --> <!-- [CHAR LIMIT=40] Zen mode settings: visual signals: screen is on: title -->
<string name="zen_mode_screen_on">Block when screen is on</string> <string name="zen_mode_screen_on">When the screen is on</string>
<!-- [CHAR LIMIT=130] Zen mode settings: visual signals: screen is on: summary -->
<!-- [CHAR LIMIT=130] Zen mode settings: visual interruptions: screen is on: summary --> <string name="zen_mode_screen_on_summary">Let notifications silenced by Do Not Disturb pop on screen</string>
<string name="zen_mode_screen_on_summary">Prevent notifications silenced by Do Not Disturb from peeking or popping on screen</string> <!-- [CHAR LIMIT=40] Zen mode settings: visual signals: screen is off: title -->
<string name="zen_mode_screen_off">When the screen is off</string>
<!-- [CHAR LIMIT=40] Zen mode settings: visual interruptions: screen is off: title -->
<string name="zen_mode_screen_off">Block when screen is off</string>
<!-- [CHAR LIMIT=130] Zen mode settings: visual interruptions: screen is off: summary --> <!-- [CHAR LIMIT=130] Zen mode settings: visual interruptions: screen is off: summary -->
<string name="zen_mode_screen_off_summary">Prevent notifications silenced by Do Not Disturb from turning on the screen or pulsing the notification light</string> <string name="zen_mode_screen_off_summary">Let notifications silenced by Do Not Disturb turn on the screen and blink the light</string>
<!-- [CHAR LIMIT=130] Zen mode settings: visual interruptions: screen is off: summary --> <!-- [CHAR LIMIT=130] Zen mode settings: visual interruptions: screen is off: summary -->
<string name="zen_mode_screen_off_summary_no_led">Prevent notifications silenced by Do Not Disturb from turning on the screen</string> <string name="zen_mode_screen_off_summary_no_led">Let notifications silenced by Do Not Disturb turn on the screen</string>
<!-- [CHAR LIMIT=130] Zen mode settings: visual interruptions summary -->
<string name="zen_mode_all_visual_interruptions">Off</string>
<!-- [CHAR LIMIT=130] Zen mode settings: visual interruptions summary -->
<string name="zen_mode_screen_on_visual_interruptions">When screen is on</string>
<!-- [CHAR LIMIT=130] Zen mode settings: visual interruptions summary -->
<string name="zen_mode_screen_off_visual_interruptions">When screen is off</string>
<!-- [CHAR LIMIT=130] Zen mode settings: visual interruptions summary -->
<string name="zen_mode_no_visual_interruptions">When screen is on or off</string>
<!-- [CHAR LIMIT=NONE] Content description for per-app notification <!-- [CHAR LIMIT=NONE] Content description for per-app notification
settings button --> settings button -->

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 The Android Open Source Project <!--
Copyright (C) 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License"); 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.
@@ -15,18 +16,8 @@
--> -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings" android:key="zen_mode_automation_settings_page"
android:title="@string/zen_mode_visual_interruptions_settings_title" android:title="@string/zen_mode_automation_settings_page_title" >
android:key="zen_mode_visual_interruptions_screen">
<SwitchPreference android:key="screenOn"
android:title="@string/zen_mode_screen_on"
android:summary="@string/zen_mode_screen_on_summary" />
<SwitchPreference android:key="screenOff"
android:title="@string/zen_mode_screen_off"
android:summary="@string/zen_mode_screen_off_summary" />
<!-- Rules added at runtime -->
</PreferenceScreen> </PreferenceScreen>

View File

@@ -15,9 +15,12 @@
limitations under the License. limitations under the License.
--> -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
android:key="zen_mode_behavior_settings_page" android:key="zen_mode_behavior_settings_page"
android:title="@string/zen_mode_behavior_settings_title" > android:title="@string/zen_mode_behavior_settings_title"
settings:initialExpandedChildrenCount="7">
<PreferenceCategory <PreferenceCategory
android:title="@string/zen_mode_behavior_allow_title" android:title="@string/zen_mode_behavior_allow_title"
@@ -62,4 +65,18 @@
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory
android:title="@string/zen_mode_visual_signals_settings_subtitle"
android:key="zen_mode_visual_signals_preferences">
<SwitchPreference android:key="zen_mode_screen_on"
android:title="@string/zen_mode_screen_on"
android:summary="@string/zen_mode_screen_on_summary" />
<SwitchPreference android:key="zen_mode_screen_off"
android:title="@string/zen_mode_screen_off"
android:summary="@string/zen_mode_screen_off_summary" />
</PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View File

@@ -17,21 +17,16 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="zen_mode_settings" android:key="zen_mode_settings"
android:title="@string/zen_mode_settings_title" > android:title="@string/zen_mode_settings_title">
<Preference <Preference
android:key="zen_mode_behavior_settings" android:key="zen_mode_behavior_settings"
android:title="@string/zen_mode_behavior_settings_title" android:title="@string/zen_mode_behavior_settings_title"
android:fragment="com.android.settings.notification.ZenModeBehaviorSettings" /> android:fragment="com.android.settings.notification.ZenModeBehaviorSettings" />
<!-- Visual interruptions -->
<Preference
android:key="zen_mode_visual_interruptions_settings"
android:title="@string/zen_mode_visual_interruptions_settings_title"
android:fragment="com.android.settings.notification.ZenModeVisualInterruptionSettings" />
<!-- Automatic rules --> <!-- Automatic rules -->
<PreferenceCategory <Preference
android:key="zen_mode_automatic_rules" android:key="zen_mode_automation_settings"
android:title="@string/zen_mode_automation_settings_title" /> android:title="@string/zen_mode_automation_settings_title"
android:fragment="com.android.settings.notification.ZenModeAutomationSettings" />
</PreferenceScreen> </PreferenceScreen>

View File

@@ -125,7 +125,6 @@ public class Settings extends SettingsActivity {
public static class ZenModeScheduleRuleSettingsActivity extends SettingsActivity { /* empty */ } public static class ZenModeScheduleRuleSettingsActivity extends SettingsActivity { /* empty */ }
public static class ZenModeEventRuleSettingsActivity extends SettingsActivity { /* empty */ } public static class ZenModeEventRuleSettingsActivity extends SettingsActivity { /* empty */ }
public static class ZenModeExternalRuleSettingsActivity 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 SoundSettingsActivity extends SettingsActivity { /* empty */ }
public static class ConfigureNotificationSettingsActivity extends SettingsActivity { /* empty */ } public static class ConfigureNotificationSettingsActivity extends SettingsActivity { /* empty */ }
public static class NotificationAppListActivity extends SettingsActivity { /* empty */ } public static class NotificationAppListActivity extends SettingsActivity { /* empty */ }

View File

@@ -108,10 +108,10 @@ import com.android.settings.notification.NotificationStation;
import com.android.settings.notification.SoundSettings; import com.android.settings.notification.SoundSettings;
import com.android.settings.notification.ZenAccessSettings; import com.android.settings.notification.ZenAccessSettings;
import com.android.settings.notification.ZenModeBehaviorSettings; import com.android.settings.notification.ZenModeBehaviorSettings;
import com.android.settings.notification.ZenModeAutomationSettings;
import com.android.settings.notification.ZenModeEventRuleSettings; import com.android.settings.notification.ZenModeEventRuleSettings;
import com.android.settings.notification.ZenModeScheduleRuleSettings; import com.android.settings.notification.ZenModeScheduleRuleSettings;
import com.android.settings.notification.ZenModeSettings; import com.android.settings.notification.ZenModeSettings;
import com.android.settings.notification.ZenModeVisualInterruptionSettings;
import com.android.settings.password.ChooseLockPassword; import com.android.settings.password.ChooseLockPassword;
import com.android.settings.password.ChooseLockPattern; import com.android.settings.password.ChooseLockPattern;
import com.android.settings.print.PrintJobSettingsFragment; import com.android.settings.print.PrintJobSettingsFragment;
@@ -197,6 +197,7 @@ public class SettingsGateway {
SpecialAccessSettings.class.getName(), SpecialAccessSettings.class.getName(),
NotificationAccessSettings.class.getName(), NotificationAccessSettings.class.getName(),
ZenAccessSettings.class.getName(), ZenAccessSettings.class.getName(),
ZenModeAutomationSettings.class.getName(),
PrintSettingsFragment.class.getName(), PrintSettingsFragment.class.getName(),
PrintJobSettingsFragment.class.getName(), PrintJobSettingsFragment.class.getName(),
TrustedCredentialsSettings.class.getName(), TrustedCredentialsSettings.class.getName(),
@@ -219,7 +220,6 @@ public class SettingsGateway {
ZenModeBehaviorSettings.class.getName(), ZenModeBehaviorSettings.class.getName(),
ZenModeScheduleRuleSettings.class.getName(), ZenModeScheduleRuleSettings.class.getName(),
ZenModeEventRuleSettings.class.getName(), ZenModeEventRuleSettings.class.getName(),
ZenModeVisualInterruptionSettings.class.getName(),
ProcessStatsUi.class.getName(), ProcessStatsUi.class.getName(),
AdvancedPowerUsageDetail.class.getName(), AdvancedPowerUsageDetail.class.getName(),
ProcessStatsSummary.class.getName(), ProcessStatsSummary.class.getName(),

View File

@@ -244,7 +244,6 @@ public class SoundSettings extends DashboardFragment {
List<String> keys = super.getNonIndexableKeys(context); List<String> keys = super.getNonIndexableKeys(context);
// Duplicate results // Duplicate results
keys.add((new ZenModePreferenceController(context)).getPreferenceKey()); keys.add((new ZenModePreferenceController(context)).getPreferenceKey());
keys.add(ZenModeSettings.KEY_VISUAL_SETTINGS);
keys.add(KEY_CELL_BROADCAST_SETTINGS); keys.add(KEY_CELL_BROADCAST_SETTINGS);
return keys; return keys;
} }

View File

@@ -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<String,AutomaticZenRule>[] sortedRules() {
final Map.Entry<String,AutomaticZenRule>[] 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<String,AutomaticZenRule>[] sortedRules = sortedRules();
for (Map.Entry<String,AutomaticZenRule> 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<Map.Entry<String,AutomaticZenRule>> RULE_COMPARATOR =
new Comparator<Map.Entry<String,AutomaticZenRule>>() {
@Override
public int compare(Map.Entry<String,AutomaticZenRule> lhs,
Map.Entry<String,AutomaticZenRule> 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<String, AutomaticZenRule> 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<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.zen_mode_automation_settings;
return Arrays.asList(sir);
}
};
}

View File

@@ -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_MESSAGES = "zen_mode_messages";
private static final String KEY_CALLS = "zen_mode_calls"; 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_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; 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(); updateControls();
} }
@@ -244,6 +286,10 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde
updateControlsPolicy(); updateControlsPolicy();
setTogglesEnabled(true); setTogglesEnabled(true);
} }
mScreenOff.setChecked(isEffectAllowed(Policy.SUPPRESSED_EFFECT_SCREEN_OFF));
mScreenOn.setChecked(isEffectAllowed(Policy.SUPPRESSED_EFFECT_SCREEN_ON));
mDisableListeners = false; 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;
}
} }

View File

@@ -221,7 +221,7 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase
} }
private void showRuleNameDialog() { private void showRuleNameDialog() {
new ZenRuleNameDialog(mContext, mRule.getName()) { new ZenRuleNameDialog(mContext, mRule.getName(), null) {
@Override @Override
public void onOk(String ruleName) { public void onOk(String ruleName) {
mRule.setName(ruleName); mRule.setName(ruleName);

View File

@@ -16,37 +16,22 @@
package com.android.settings.notification; package com.android.settings.notification;
import android.app.AlertDialog;
import android.app.AutomaticZenRule; import android.app.AutomaticZenRule;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.NotificationManager.Policy; import android.app.NotificationManager.Policy;
import android.content.ComponentName;
import android.content.Context; 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.os.Bundle;
import android.provider.SearchIndexableResource; import android.provider.SearchIndexableResource;
import android.provider.Settings; import android.provider.Settings;
import android.service.notification.ConditionProviderService;
import android.service.notification.ZenModeConfig; import android.service.notification.ZenModeConfig;
import android.support.annotation.VisibleForTesting; import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceScreen; 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.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable; 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.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@@ -57,19 +42,13 @@ import java.util.Map.Entry;
public class ZenModeSettings extends ZenModeSettingsBase implements Indexable { 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_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 mBehaviorSettings;
private Preference mVisualSettings; private Preference mAutomationSettings;
private Policy mPolicy; private Policy mPolicy;
private SummaryBuilder mSummaryBuilder; private SummaryBuilder mSummaryBuilder;
private PackageManager mPm;
private ZenServiceListing mServiceListing;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@@ -78,14 +57,10 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
addPreferencesFromResource(R.xml.zen_mode_settings); addPreferencesFromResource(R.xml.zen_mode_settings);
final PreferenceScreen root = getPreferenceScreen(); final PreferenceScreen root = getPreferenceScreen();
mAutomaticRules = (PreferenceCategory) root.findPreference(KEY_AUTOMATIC_RULES);
mBehaviorSettings = root.findPreference(KEY_BEHAVIOR_SETTINGS); mBehaviorSettings = root.findPreference(KEY_BEHAVIOR_SETTINGS);
mVisualSettings = root.findPreference(KEY_VISUAL_SETTINGS); mAutomationSettings = root.findPreference(KEY_AUTOMATION_SETTINGS);
mPolicy = NotificationManager.from(mContext).getNotificationPolicy(); mPolicy = NotificationManager.from(mContext).getNotificationPolicy();
mSummaryBuilder = new SummaryBuilder(getContext()); mSummaryBuilder = new SummaryBuilder(getContext());
mPm = mContext.getPackageManager();
mServiceListing = new ZenServiceListing(mContext, CONFIG);
mServiceListing.reloadApprovedServices();
} }
@Override @Override
@@ -115,168 +90,15 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
private void updateControls() { private void updateControls() {
updateBehaviorSettingsSummary(); updateBehaviorSettingsSummary();
updateVisualSettingsSummary(); updateAutomationSettingsSummary();
updateAutomaticRules();
} }
private void updateBehaviorSettingsSummary() { private void updateBehaviorSettingsSummary() {
mBehaviorSettings.setSummary(mSummaryBuilder.getBehaviorSettingSummary(mPolicy, mZenMode)); mBehaviorSettings.setSummary(mSummaryBuilder.getBehaviorSettingSummary(mPolicy, mZenMode));
} }
private void updateVisualSettingsSummary() { private void updateAutomationSettingsSummary() {
mVisualSettings.setSummary(mSummaryBuilder.getVisualSettingSummary(mPolicy)); mAutomationSettings.setSummary(mSummaryBuilder.getAutomaticRulesSummary());
}
private void updateAutomaticRules() {
mAutomaticRules.removeAll();
final Map.Entry<String,AutomaticZenRule>[] sortedRules = sortedRules();
for (Map.Entry<String,AutomaticZenRule> 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<String,AutomaticZenRule>[] sortedRules() {
final Map.Entry<String,AutomaticZenRule>[] rt =
mRules.toArray(new Map.Entry[mRules.size()]);
Arrays.sort(rt, RULE_COMPARATOR);
return rt;
} }
@Override @Override
@@ -284,67 +106,6 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
return R.string.help_uri_interruptions; 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<String, AutomaticZenRule> 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 { public static class SummaryBuilder {
private Context mContext; 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); 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() { String getAutomaticRulesSummary() {
final int count = getEnabledAutomaticRulesCount(); final int count = getEnabledAutomaticRulesCount();
return count == 0 ? mContext.getString(R.string.zen_mode_settings_summary_off) 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<Map.Entry<String,AutomaticZenRule>> RULE_COMPARATOR = private static final Comparator<Entry<String,AutomaticZenRule>> RULE_COMPARATOR =
new Comparator<Map.Entry<String,AutomaticZenRule>>() { new Comparator<Map.Entry<String,AutomaticZenRule>>() {
@Override @Override
public int compare(Map.Entry<String,AutomaticZenRule> lhs, public int compare(Map.Entry<String,AutomaticZenRule> lhs,
@@ -502,6 +250,7 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
return type + rule.getName().toString(); return type + rule.getName().toString();
} }
}; };
/** /**
* For Search. * For Search.
*/ */
@@ -515,4 +264,5 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
return Arrays.asList(sir); return Arrays.asList(sir);
} }
}; };
} }

View File

@@ -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<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.zen_mode_visual_interruptions_settings;
return Arrays.asList(sir);
}
};
}

View File

@@ -19,6 +19,8 @@ package com.android.settings.notification;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.net.Uri;
import android.service.notification.ZenModeConfig;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@@ -35,20 +37,21 @@ public abstract class ZenRuleNameDialog {
private final CharSequence mOriginalRuleName; private final CharSequence mOriginalRuleName;
private final boolean mIsNew; private final boolean mIsNew;
public ZenRuleNameDialog(Context context, CharSequence ruleName) { public ZenRuleNameDialog(Context context, CharSequence ruleName, Uri conditionId) {
mIsNew = ruleName == null; mIsNew = ruleName == null;
mOriginalRuleName = ruleName; mOriginalRuleName = ruleName;
final View v = LayoutInflater.from(context).inflate(R.layout.zen_rule_name, null, false); final View v = LayoutInflater.from(context).inflate(R.layout.zen_rule_name, null,
mEditText = (EditText) v.findViewById(R.id.rule_name); false);
mEditText = (EditText) v.findViewById(R.id.zen_mode_rule_name);
if (!mIsNew) { if (!mIsNew) {
mEditText.setText(ruleName); mEditText.setText(ruleName);
} }
mEditText.setSelectAllOnFocus(true); mEditText.setSelectAllOnFocus(true);
mDialog = new AlertDialog.Builder(context) mDialog = new AlertDialog.Builder(context)
.setTitle(mIsNew ? R.string.zen_mode_add_rule : R.string.zen_mode_rule_name) .setTitle(getTitleResource(conditionId))
.setView(v) .setView(v)
.setPositiveButton(R.string.okay, new DialogInterface.OnClickListener() { .setPositiveButton(mIsNew ? R.string.zen_mode_add : R.string.okay,
new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
final String newName = trimmedText(); final String newName = trimmedText();
@@ -75,4 +78,18 @@ public abstract class ZenRuleNameDialog {
private String trimmedText() { private String trimmedText() {
return mEditText.getText() == null ? null : mEditText.getText().toString().trim(); 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;
}
} }

View File

@@ -27,7 +27,6 @@ import android.content.pm.ServiceInfo;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.service.notification.ZenModeConfig; import android.service.notification.ZenModeConfig;
import android.util.ArraySet;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@@ -36,15 +35,11 @@ import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.utils.ServiceListing;
import com.android.settings.utils.ZenServiceListing; import com.android.settings.utils.ZenServiceListing;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.text.Collator; import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
@@ -169,7 +164,7 @@ public abstract class ZenRuleSelectionDialog {
if (DEBUG) Log.d(TAG, "Services reloaded: count=" + services.size()); if (DEBUG) Log.d(TAG, "Services reloaded: count=" + services.size());
Set<ZenRuleInfo> externalRuleTypes = new TreeSet<>(RULE_TYPE_COMPARATOR); Set<ZenRuleInfo> externalRuleTypes = new TreeSet<>(RULE_TYPE_COMPARATOR);
for (ServiceInfo serviceInfo : services) { for (ServiceInfo serviceInfo : services) {
final ZenRuleInfo ri = ZenModeSettings.getRuleInfo(mPm, serviceInfo); final ZenRuleInfo ri = ZenModeAutomationSettings.getRuleInfo(mPm, serviceInfo);
if (ri != null && ri.configurationActivity != null if (ri != null && ri.configurationActivity != null
&& mNm.isNotificationPolicyAccessGrantedForPackage(ri.packageName) && mNm.isNotificationPolicyAccessGrantedForPackage(ri.packageName)
&& (ri.ruleInstanceLimit <= 0 || ri.ruleInstanceLimit && (ri.ruleInstanceLimit <= 0 || ri.ruleInstanceLimit

View File

@@ -72,9 +72,9 @@ import com.android.settings.nfc.PaymentSettings;
import com.android.settings.notification.ChannelImportanceSettings; import com.android.settings.notification.ChannelImportanceSettings;
import com.android.settings.notification.ConfigureNotificationSettings; import com.android.settings.notification.ConfigureNotificationSettings;
import com.android.settings.notification.SoundSettings; import com.android.settings.notification.SoundSettings;
import com.android.settings.notification.ZenModeAutomationSettings;
import com.android.settings.notification.ZenModeBehaviorSettings; import com.android.settings.notification.ZenModeBehaviorSettings;
import com.android.settings.notification.ZenModeSettings; import com.android.settings.notification.ZenModeSettings;
import com.android.settings.notification.ZenModeVisualInterruptionSettings;
import com.android.settings.print.PrintSettingsFragment; import com.android.settings.print.PrintSettingsFragment;
import com.android.settings.security.LockscreenDashboardFragment; import com.android.settings.security.LockscreenDashboardFragment;
import com.android.settings.sim.SimSettings; import com.android.settings.sim.SimSettings;
@@ -192,7 +192,7 @@ public final class SearchIndexableResources {
addIndex(BatterySaverSettings.class); addIndex(BatterySaverSettings.class);
addIndex(LockscreenDashboardFragment.class); addIndex(LockscreenDashboardFragment.class);
addIndex(ZenModeBehaviorSettings.class); addIndex(ZenModeBehaviorSettings.class);
addIndex(ZenModeVisualInterruptionSettings.class); addIndex(ZenModeAutomationSettings.class);
} }
private SearchIndexableResources() { private SearchIndexableResources() {

View File

@@ -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.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.action.ViewActions.click;
@@ -36,12 +36,29 @@ public class ZenModeSettingsIntegrationTest {
} }
@Test @Test
public void testAutomaticRulesAppear() { public void testZenModeSettingsPreferences() {
launchZenSettings(); 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("Weekend")).check(matches(isDisplayed()));
onView(withText("Add more")).check(matches(isDisplayed())).perform(click()); onView(withText("Add rule")).check(matches(isDisplayed()));
onView(withText("Choose rule type")).check(matches(isDisplayed()));
} }
private void launchZenSettings() { private void launchZenSettings() {
@@ -50,4 +67,18 @@ public class ZenModeSettingsIntegrationTest {
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(settingsIntent); 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);
}
} }