Merge changes Ic9d1b08c,Id6db9ce2,I7b980218

* changes:
  Add zen starred contacts preference
  Clear deprecated effects when saving zen policy
  DND settings redesign
This commit is contained in:
TreeHugger Robot
2018-05-11 20:33:10 +00:00
committed by Android (Google) Code Review
28 changed files with 1377 additions and 288 deletions

View File

@@ -106,9 +106,10 @@ import com.android.settings.notification.NotificationStation;
import com.android.settings.notification.SoundSettings;
import com.android.settings.notification.ZenAccessSettings;
import com.android.settings.notification.ZenModeAutomationSettings;
import com.android.settings.notification.ZenModeBehaviorSettings;
import com.android.settings.notification.ZenModeMsgEventReminderSettings;
import com.android.settings.notification.ZenModeBlockedEffectsSettings;
import com.android.settings.notification.ZenModeEventRuleSettings;
import com.android.settings.notification.ZenModeRestrictNotificationsSettings;
import com.android.settings.notification.ZenModeScheduleRuleSettings;
import com.android.settings.notification.ZenModeSettings;
import com.android.settings.password.ChooseLockPassword;
@@ -220,7 +221,6 @@ public class SettingsGateway {
ApnSettings.class.getName(),
ApnEditor.class.getName(),
WifiCallingSettings.class.getName(),
ZenModeBehaviorSettings.class.getName(),
ZenModeScheduleRuleSettings.class.getName(),
ZenModeEventRuleSettings.class.getName(),
ZenModeBlockedEffectsSettings.class.getName(),

View File

@@ -16,6 +16,9 @@
package com.android.settings.notification;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_OFF;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_ON;
import android.app.ActivityManager;
import android.app.AutomaticZenRule;
import android.app.NotificationManager;
@@ -146,19 +149,24 @@ public class ZenModeBackend {
protected void savePolicy(int priorityCategories, int priorityCallSenders,
int priorityMessageSenders, int suppressedVisualEffects) {
mPolicy = new NotificationManager.Policy(priorityCategories, priorityCallSenders,
priorityMessageSenders,
suppressedVisualEffects);
priorityMessageSenders, suppressedVisualEffects);
mNotificationManager.setNotificationPolicy(mPolicy);
}
protected int getNewSuppressedEffects(boolean suppress, int effectType) {
private int getNewSuppressedEffects(boolean suppress, int effectType) {
int effects = mPolicy.suppressedVisualEffects;
if (suppress) {
effects |= effectType;
} else {
effects &= ~effectType;
}
return effects;
return clearDeprecatedEffects(effects);
}
private int clearDeprecatedEffects(int effects) {
return effects & ~(SUPPRESSED_EFFECT_SCREEN_ON | SUPPRESSED_EFFECT_SCREEN_OFF);
}
protected boolean isEffectAllowed(int effect) {

View File

@@ -22,13 +22,13 @@ import androidx.preference.Preference;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenModeBehaviorPreferenceController extends
public class ZenModeBehaviorCallsPreferenceController extends
AbstractZenModePreferenceController implements PreferenceControllerMixin {
protected static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_behavior_settings";
protected static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_calls_settings";
private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
public ZenModeBehaviorPreferenceController(Context context, Lifecycle lifecycle) {
public ZenModeBehaviorCallsPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY_BEHAVIOR_SETTINGS, lifecycle);
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
}
@@ -47,7 +47,6 @@ public class ZenModeBehaviorPreferenceController extends
public void updateState(Preference preference) {
super.updateState(preference);
preference.setSummary(mSummaryBuilder.getBehaviorSettingSummary(getPolicy(),
getZenMode()));
preference.setSummary(mSummaryBuilder.getCallsSettingSummary(getPolicy()));
}
}

View File

@@ -16,8 +16,8 @@
package com.android.settings.notification;
import android.content.Context;
import android.content.ComponentName;
import android.content.Context;
import android.net.Uri;
import android.provider.Settings;
import android.service.notification.ZenModeConfig;
@@ -30,14 +30,17 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenModeBehaviorFooterPreferenceController extends AbstractZenModePreferenceController {
protected static final String KEY = "footer_preference";
private final int mTitleRes;
public ZenModeBehaviorFooterPreferenceController(Context context, Lifecycle lifecycle) {
public ZenModeBehaviorFooterPreferenceController(Context context, Lifecycle lifecycle,
int titleRes) {
super(context, KEY, lifecycle);
mTitleRes = titleRes;
}
@Override
public boolean isAvailable() {
return isDeprecatedZenMode(getZenMode());
return true;
}
@Override
@@ -48,45 +51,45 @@ public class ZenModeBehaviorFooterPreferenceController extends AbstractZenModePr
@Override
public void updateState(Preference preference) {
super.updateState(preference);
boolean isAvailable = isAvailable();
preference.setVisible(isAvailable);
if (isAvailable) {
preference.setTitle(getFooterText());
}
preference.setTitle(getFooterText());
}
protected String getFooterText() {
ZenModeConfig config = getZenModeConfig();
if (isDeprecatedZenMode(getZenMode())) {
ZenModeConfig config = getZenModeConfig();
// DND turned on by manual rule with deprecated zen mode
if (config.manualRule != null &&
isDeprecatedZenMode(config.manualRule.zenMode)) {
final Uri id = config.manualRule.conditionId;
if (config.manualRule.enabler != null) {
// app triggered manual rule
String appOwner = mZenModeConfigWrapper.getOwnerCaption(config.manualRule.enabler);
if (!appOwner.isEmpty()) {
return mContext.getString(R.string.zen_mode_app_set_behavior, appOwner);
}
} else {
return mContext.getString(R.string.zen_mode_qs_set_behavior);
}
}
// DND turned on by an automatic rule with deprecated zen mode
for (ZenModeConfig.ZenRule automaticRule : config.automaticRules.values()) {
if (automaticRule.isAutomaticActive() && isDeprecatedZenMode(automaticRule.zenMode)) {
ComponentName component = automaticRule.component;
if (component != null) {
return mContext.getString(R.string.zen_mode_app_set_behavior,
component.getPackageName());
// DND turned on by manual rule with deprecated zen mode
if (config.manualRule != null &&
isDeprecatedZenMode(config.manualRule.zenMode)) {
final Uri id = config.manualRule.conditionId;
if (config.manualRule.enabler != null) {
// app triggered manual rule
String appOwner = mZenModeConfigWrapper.getOwnerCaption(
config.manualRule.enabler);
if (!appOwner.isEmpty()) {
return mContext.getString(R.string.zen_mode_app_set_behavior, appOwner);
}
} else {
return mContext.getString(R.string.zen_mode_qs_set_behavior);
}
}
}
return mContext.getString(R.string.zen_mode_unknown_app_set_behavior);
// DND turned on by an automatic rule with deprecated zen mode
for (ZenModeConfig.ZenRule automaticRule : config.automaticRules.values()) {
if (automaticRule.isAutomaticActive() && isDeprecatedZenMode(
automaticRule.zenMode)) {
ComponentName component = automaticRule.component;
if (component != null) {
return mContext.getString(R.string.zen_mode_app_set_behavior,
component.getPackageName());
}
}
}
return mContext.getString(R.string.zen_mode_unknown_app_set_behavior);
} else {
return mContext.getString(mTitleRes);
}
}
private boolean isDeprecatedZenMode(int zenMode) {

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import android.content.Context;
import androidx.preference.Preference;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenModeBehaviorMsgEventReminderPreferenceController extends
AbstractZenModePreferenceController implements PreferenceControllerMixin {
protected static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_msg_event_reminder_settings";
private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
public ZenModeBehaviorMsgEventReminderPreferenceController(Context context,
Lifecycle lifecycle) {
super(context, KEY_BEHAVIOR_SETTINGS, lifecycle);
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
}
@Override
public String getPreferenceKey() {
return KEY_BEHAVIOR_SETTINGS;
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
preference.setSummary(mSummaryBuilder.getMsgEventReminderSettingSummary(getPolicy()));
}
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import android.content.Context;
import androidx.preference.Preference;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenModeBehaviorSoundPreferenceController extends
AbstractZenModePreferenceController implements PreferenceControllerMixin {
protected static final String KEY_BEHAVIOR_SETTINGS = "zen_sound_vibration_settings";
private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
public ZenModeBehaviorSoundPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY_BEHAVIOR_SETTINGS, lifecycle);
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
}
@Override
public String getPreferenceKey() {
return KEY_BEHAVIOR_SETTINGS;
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
preference.setSummary(mSummaryBuilder.getSoundSettingSummary(getPolicy()));
}
}

View File

@@ -0,0 +1,95 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_CALLS;
import android.content.Context;
import android.provider.SearchIndexableResource;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList;
import java.util.List;
@SearchIndexable
public class ZenModeCallsSettings extends ZenModeSettingsBase implements Indexable {
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, getLifecycle());
}
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new ZenModeCallsPreferenceController(context, lifecycle));
controllers.add(new ZenModeStarredContactsPreferenceController(context, lifecycle,
PRIORITY_CATEGORY_CALLS, "zen_mode_starred_contacts_callers"));
controllers.add(new ZenModeRepeatCallersPreferenceController(context, lifecycle,
context.getResources().getInteger(com.android.internal.R.integer
.config_zen_repeat_callers_threshold)));
controllers.add(new ZenModeBehaviorFooterPreferenceController(
context, lifecycle, R.string.zen_mode_calls_footer));
return controllers;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.zen_mode_calls_settings;
}
@Override
public int getMetricsCategory() {
return MetricsEvent.NOTIFICATION_ZEN_MODE_PRIORITY;
}
/**
* For Search.
*/
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
boolean enabled) {
final ArrayList<SearchIndexableResource> result = new ArrayList<>();
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.zen_mode_calls_settings;
result.add(sir);
return result;
}
@Override
public List<String> getNonIndexableKeys(Context context) {
final List<String> keys = super.getNonIndexableKeys(context);
return keys;
}
@Override
public List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, null);
}
};
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 The Android Open Source Project
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
package com.android.settings.notification;
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES;
import android.content.Context;
import android.provider.SearchIndexableResource;
@@ -31,7 +33,7 @@ import java.util.ArrayList;
import java.util.List;
@SearchIndexable
public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Indexable {
public class ZenModeMsgEventReminderSettings extends ZenModeSettingsBase implements Indexable {
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
@@ -41,23 +43,19 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new ZenModeAlarmsPreferenceController(context, lifecycle));
controllers.add(new ZenModeMediaPreferenceController(context, lifecycle));
controllers.add(new ZenModeSystemPreferenceController(context, lifecycle));
controllers.add(new ZenModeEventsPreferenceController(context, lifecycle));
controllers.add(new ZenModeRemindersPreferenceController(context, lifecycle));
controllers.add(new ZenModeMessagesPreferenceController(context, lifecycle));
controllers.add(new ZenModeCallsPreferenceController(context, lifecycle));
controllers.add(new ZenModeRepeatCallersPreferenceController(context, lifecycle,
context.getResources().getInteger(com.android.internal.R.integer
.config_zen_repeat_callers_threshold)));
controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle));
controllers.add(new ZenModeStarredContactsPreferenceController(context, lifecycle,
PRIORITY_CATEGORY_MESSAGES, "zen_mode_starred_contacts_messages"));
controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle,
R.string.zen_msg_event_reminder_footer));
return controllers;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.zen_mode_behavior_settings;
return R.xml.zen_mode_msg_event_reminder_settings;
}
@Override
@@ -77,7 +75,7 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde
final ArrayList<SearchIndexableResource> result = new ArrayList<>();
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.zen_mode_behavior_settings;
sir.xmlResId = R.xml.zen_mode_msg_event_reminder_settings;
result.add(sir);
return result;
}

View File

@@ -70,7 +70,6 @@ public class ZenModeRestrictNotificationsSettings extends ZenModeSettingsBase im
custom.displayPreference(getPreferenceScreen());
if (mShowMenuSelected) {
custom.select();
metrics.action(mContext, ACTION_ZEN_SHOW_CUSTOM, true);
} else {
metrics.action(mContext, ACTION_ZEN_SHOW_CUSTOM, false);

View File

@@ -16,6 +16,15 @@
package com.android.settings.notification;
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS;
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_CALLS;
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_EVENTS;
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA;
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES;
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_REMINDERS;
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS;
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_SYSTEM;
import android.app.AutomaticZenRule;
import android.app.FragmentManager;
import android.app.NotificationManager;
@@ -42,19 +51,13 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Predicate;
@SearchIndexable
public class ZenModeSettings extends ZenModeSettingsBase {
private static final String KEY_SOUND = "zen_effect_sound";
@Override
public void onResume() {
super.onResume();
CheckBoxPreference soundPreference =
(CheckBoxPreference) getPreferenceScreen().findPreference(KEY_SOUND);
if (soundPreference != null) {
soundPreference.setChecked(true);
}
}
@Override
@@ -80,7 +83,9 @@ public class ZenModeSettings extends ZenModeSettingsBase {
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle, FragmentManager fragmentManager) {
List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new ZenModeBehaviorPreferenceController(context, lifecycle));
controllers.add(new ZenModeBehaviorMsgEventReminderPreferenceController(context, lifecycle));
controllers.add(new ZenModeBehaviorSoundPreferenceController(context, lifecycle));
controllers.add(new ZenModeBehaviorCallsPreferenceController(context, lifecycle));
controllers.add(new ZenModeBlockedEffectsPreferenceController(context, lifecycle));
controllers.add(new ZenModeDurationPreferenceController(context, lifecycle,
fragmentManager));
@@ -100,19 +105,63 @@ public class ZenModeSettings extends ZenModeSettingsBase {
// these should match NotificationManager.Policy#ALL_PRIORITY_CATEGORIES
private static final int[] ALL_PRIORITY_CATEGORIES = {
Policy.PRIORITY_CATEGORY_ALARMS,
Policy.PRIORITY_CATEGORY_MEDIA,
Policy.PRIORITY_CATEGORY_SYSTEM,
Policy.PRIORITY_CATEGORY_REMINDERS,
Policy.PRIORITY_CATEGORY_EVENTS,
Policy.PRIORITY_CATEGORY_MESSAGES,
Policy.PRIORITY_CATEGORY_CALLS,
Policy.PRIORITY_CATEGORY_REPEAT_CALLERS,
PRIORITY_CATEGORY_ALARMS,
PRIORITY_CATEGORY_MEDIA,
PRIORITY_CATEGORY_SYSTEM,
PRIORITY_CATEGORY_MESSAGES,
PRIORITY_CATEGORY_EVENTS,
PRIORITY_CATEGORY_REMINDERS,
PRIORITY_CATEGORY_CALLS,
PRIORITY_CATEGORY_REPEAT_CALLERS,
};
String getBehaviorSettingSummary(Policy policy, int zenMode) {
List<String> enabledCategories = getEnabledCategories(policy);
String getSoundSettingSummary(Policy policy) {
List<String> enabledCategories = getEnabledCategories(policy,
category -> PRIORITY_CATEGORY_ALARMS == category
|| PRIORITY_CATEGORY_MEDIA == category
|| PRIORITY_CATEGORY_SYSTEM == category);
int numCategories = enabledCategories.size();
if (numCategories == 0) {
return mContext.getString(R.string.zen_sound_all_muted);
} else if (numCategories == 1) {
return mContext.getString(R.string.zen_sound_one_allowed,
enabledCategories.get(0).toLowerCase());
} else if (numCategories == 2) {
return mContext.getString(R.string.zen_sound_two_allowed,
enabledCategories.get(0).toLowerCase(),
enabledCategories.get(1).toLowerCase());
} else if (numCategories == 3) {
return mContext.getString(R.string.zen_sound_three_allowed,
enabledCategories.get(0).toLowerCase(),
enabledCategories.get(1).toLowerCase(),
enabledCategories.get(2).toLowerCase());
} else {
return mContext.getString(R.string.zen_sound_none_muted);
}
}
String getCallsSettingSummary(Policy policy) {
List<String> enabledCategories = getEnabledCategories(policy,
category -> PRIORITY_CATEGORY_CALLS == category
|| PRIORITY_CATEGORY_REPEAT_CALLERS == category);
int numCategories = enabledCategories.size();
if (numCategories == 0) {
return mContext.getString(R.string.zen_mode_no_exceptions);
} else if (numCategories == 1) {
return mContext.getString(R.string.zen_mode_calls_summary_one,
enabledCategories.get(0).toLowerCase());
} else {
return mContext.getString(R.string.zen_mode_calls_summary_two,
enabledCategories.get(0).toLowerCase(),
enabledCategories.get(1).toLowerCase());
}
}
String getMsgEventReminderSettingSummary(Policy policy) {
List<String> enabledCategories = getEnabledCategories(policy,
category -> PRIORITY_CATEGORY_EVENTS == category
|| PRIORITY_CATEGORY_REMINDERS == category
|| PRIORITY_CATEGORY_MESSAGES == category);
int numCategories = enabledCategories.size();
if (numCategories == 0) {
return mContext.getString(R.string.zen_mode_no_exceptions);
@@ -201,22 +250,19 @@ public class ZenModeSettings extends ZenModeSettingsBase {
return count;
}
private List<String> getEnabledCategories(Policy policy) {
private List<String> getEnabledCategories(Policy policy,
Predicate<Integer> filteredCategories) {
List<String> enabledCategories = new ArrayList<>();
for (int category : ALL_PRIORITY_CATEGORIES) {
if (isCategoryEnabled(policy, category)) {
if (category == Policy.PRIORITY_CATEGORY_ALARMS) {
if (filteredCategories.test(category) && isCategoryEnabled(policy, category)) {
if (category == PRIORITY_CATEGORY_ALARMS) {
enabledCategories.add(mContext.getString(R.string.zen_mode_alarms));
} else if (category == Policy.PRIORITY_CATEGORY_MEDIA) {
} else if (category == PRIORITY_CATEGORY_MEDIA) {
enabledCategories.add(mContext.getString(
R.string.zen_mode_media));
} else if (category == Policy.PRIORITY_CATEGORY_SYSTEM) {
} else if (category == PRIORITY_CATEGORY_SYSTEM) {
enabledCategories.add(mContext.getString(
R.string.zen_mode_system));
} else if (category == Policy.PRIORITY_CATEGORY_REMINDERS) {
enabledCategories.add(mContext.getString(R.string.zen_mode_reminders));
} else if (category == Policy.PRIORITY_CATEGORY_EVENTS) {
enabledCategories.add(mContext.getString(R.string.zen_mode_events));
} else if (category == Policy.PRIORITY_CATEGORY_MESSAGES) {
if (policy.priorityMessageSenders == Policy.PRIORITY_SENDERS_ANY) {
enabledCategories.add(mContext.getString(
@@ -225,13 +271,20 @@ public class ZenModeSettings extends ZenModeSettingsBase {
enabledCategories.add(mContext.getString(
R.string.zen_mode_selected_messages));
}
} else if (category == Policy.PRIORITY_CATEGORY_EVENTS) {
enabledCategories.add(mContext.getString(R.string.zen_mode_events));
} else if (category == Policy.PRIORITY_CATEGORY_REMINDERS) {
enabledCategories.add(mContext.getString(R.string.zen_mode_reminders));
} else if (category == Policy.PRIORITY_CATEGORY_CALLS) {
if (policy.priorityCallSenders == Policy.PRIORITY_SENDERS_ANY) {
enabledCategories.add(mContext.getString(
R.string.zen_mode_all_callers));
} else if (policy.priorityCallSenders == Policy.PRIORITY_SENDERS_CONTACTS){
enabledCategories.add(mContext.getString(
R.string.zen_mode_contacts_callers));
} else {
enabledCategories.add(mContext.getString(
R.string.zen_mode_selected_callers));
R.string.zen_mode_starred_callers));
}
} else if (category == Policy.PRIORITY_CATEGORY_REPEAT_CALLERS) {
if (!enabledCategories.contains(mContext.getString(
@@ -248,10 +301,6 @@ public class ZenModeSettings extends ZenModeSettingsBase {
private boolean isCategoryEnabled(Policy policy, int categoryType) {
return (policy.priorityCategories & categoryType) != 0;
}
private boolean isEffectSuppressed(Policy policy, int effect) {
return (policy.suppressedVisualEffects & effect) != 0;
}
}
/**

View File

@@ -0,0 +1,90 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import android.content.Context;
import android.provider.SearchIndexableResource;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList;
import java.util.List;
@SearchIndexable
public class ZenModeSoundVibrationSettings extends ZenModeSettingsBase implements Indexable {
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, getLifecycle());
}
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new ZenModeAlarmsPreferenceController(context, lifecycle));
controllers.add(new ZenModeMediaPreferenceController(context, lifecycle));
controllers.add(new ZenModeSystemPreferenceController(context, lifecycle));
controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle,
R.string.zen_sound_footer));
return controllers;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.zen_mode_sound_vibration_settings;
}
@Override
public int getMetricsCategory() {
return MetricsEvent.NOTIFICATION_ZEN_MODE_PRIORITY;
}
/**
* For Search.
*/
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
boolean enabled) {
final ArrayList<SearchIndexableResource> result = new ArrayList<>();
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.zen_mode_sound_vibration_settings;
result.add(sir);
return result;
}
@Override
public List<String> getNonIndexableKeys(Context context) {
final List<String> keys = super.getNonIndexableKeys(context);
return keys;
}
@Override
public List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, null);
}
};
}

View File

@@ -0,0 +1,153 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_CALLS;
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES;
import static android.app.NotificationManager.Policy.PRIORITY_SENDERS_STARRED;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.icu.text.ListFormatter;
import android.provider.Contacts;
import android.provider.ContactsContract;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.ArrayList;
import java.util.List;
public class ZenModeStarredContactsPreferenceController extends
AbstractZenModePreferenceController implements Preference.OnPreferenceClickListener {
protected static String KEY;
private Preference mPreference;
private final int mPriorityCategory;
private final PackageManager mPackageManager;
@VisibleForTesting
Intent mStarredContactsIntent;
@VisibleForTesting
Intent mFallbackIntent;
public ZenModeStarredContactsPreferenceController(Context context, Lifecycle lifecycle, int
priorityCategory, String key) {
super(context, key, lifecycle);
KEY = key;
mPriorityCategory = priorityCategory;
mPackageManager = mContext.getPackageManager();
mStarredContactsIntent = new Intent(Contacts.Intents.UI.LIST_STARRED_ACTION);
mFallbackIntent = new Intent(Intent.ACTION_MAIN);
mFallbackIntent.addCategory(Intent.CATEGORY_APP_CONTACTS);
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(KEY);
mPreference.setOnPreferenceClickListener(this);
}
@Override
public String getPreferenceKey() {
return KEY;
}
@Override
public boolean isAvailable() {
if (mPriorityCategory == PRIORITY_CATEGORY_CALLS) {
return mBackend.isPriorityCategoryEnabled(PRIORITY_CATEGORY_CALLS)
&& mBackend.getPriorityCallSenders() == PRIORITY_SENDERS_STARRED
&& isIntentValid();
} else if (mPriorityCategory == PRIORITY_CATEGORY_MESSAGES) {
return mBackend.isPriorityCategoryEnabled(PRIORITY_CATEGORY_MESSAGES)
&& mBackend.getPriorityMessageSenders() == PRIORITY_SENDERS_STARRED
&& isIntentValid();
} else {
// invalid category
return false;
}
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
List<String> starredContacts = getStarredContacts();
int numStarredContacts = starredContacts.size();
List<String> displayContacts = new ArrayList<>();
if (numStarredContacts == 0) {
displayContacts.add(mContext.getString(R.string.zen_mode_from_none));
} else {
for (int i = 0; i < 2 && i < numStarredContacts; i++) {
displayContacts.add(starredContacts.get(i));
}
if (numStarredContacts == 3) {
displayContacts.add(starredContacts.get(2));
} else if (numStarredContacts > 2) {
displayContacts.add(mContext.getResources().getQuantityString(
R.plurals.zen_mode_starred_contacts_summary_additional_contacts,
numStarredContacts - 2, numStarredContacts - 2));
}
}
mPreference.setSummary(ListFormatter.getInstance().format(displayContacts));
}
@Override
public boolean onPreferenceClick(Preference preference) {
if (mStarredContactsIntent.resolveActivity(mPackageManager) != null) {
mContext.startActivity(mStarredContactsIntent);
} else {
mContext.startActivity(mFallbackIntent);
}
return true;
}
private List<String> getStarredContacts() {
List<String> starredContacts = new ArrayList<>();
Cursor cursor = mContext.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
new String[]{ContactsContract.Contacts.DISPLAY_NAME_PRIMARY},
ContactsContract.Data.STARRED + "=1", null,
ContactsContract.Data.TIMES_CONTACTED);
if (cursor.moveToFirst()) {
do {
starredContacts.add(cursor.getString(0));
} while (cursor.moveToNext());
}
return starredContacts;
}
private boolean isIntentValid() {
return mStarredContactsIntent.resolveActivity(mPackageManager) != null
|| mFallbackIntent.resolveActivity(mPackageManager) != null;
}
}

View File

@@ -18,6 +18,7 @@ package com.android.settings.notification;
import android.app.NotificationManager.Policy;
import android.content.Context;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -57,15 +58,12 @@ public class ZenModeVisEffectsCustomPreferenceController
pref.setChecked(areCustomOptionsSelected());
pref.setOnGearClickListener(p -> {
new SubSettingLauncher(mContext)
.setDestination(ZenModeBlockedEffectsSettings.class.getName())
.setTitleRes(R.string.zen_mode_what_to_block_title)
.setSourceMetricsCategory(MetricsProto.MetricsEvent.SETTINGS_ZEN_NOTIFICATIONS)
.launch();
launchCustomSettings();
});
pref.setOnRadioButtonClickListener(p -> {
select();
launchCustomSettings();
});
}
@@ -84,9 +82,14 @@ public class ZenModeVisEffectsCustomPreferenceController
protected void select() {
mMetricsFeatureProvider.action(mContext,
MetricsProto.MetricsEvent.ACTION_ZEN_CUSTOM, true);
mBackend.savePolicy(mBackend.mPolicy.priorityCategories,
mBackend.mPolicy.priorityCallSenders,
mBackend.mPolicy.priorityMessageSenders,
INTERRUPTIVE_EFFECTS);
}
private void launchCustomSettings() {
select();
new SubSettingLauncher(mContext)
.setDestination(ZenModeBlockedEffectsSettings.class.getName())
.setTitleRes(R.string.zen_mode_what_to_block_title)
.setSourceMetricsCategory(MetricsProto.MetricsEvent.SETTINGS_ZEN_NOTIFICATIONS)
.launch();
}
}