diff options
Diffstat (limited to 'core/java/android')
5 files changed, 103 insertions, 27 deletions
diff --git a/core/java/android/app/AutomaticZenRule.java b/core/java/android/app/AutomaticZenRule.java index 62f6bac2a24f..9d68133c01da 100644 --- a/core/java/android/app/AutomaticZenRule.java +++ b/core/java/android/app/AutomaticZenRule.java @@ -151,7 +151,7 @@ public final class AutomaticZenRule implements Parcelable { * Gets the zen policy. */ public ZenPolicy getZenPolicy() { - return this.mZenPolicy.copy(); + return mZenPolicy == null ? null : this.mZenPolicy.copy(); } /** diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index 357420bd0217..bd9cf6dda7ff 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -146,6 +146,7 @@ interface INotificationManager int getZenMode(); ZenModeConfig getZenModeConfig(); + NotificationManager.Policy getConsolidatedNotificationPolicy(); oneway void setZenMode(int mode, in Uri conditionId, String reason); oneway void notifyConditions(String pkg, in IConditionProvider provider, in Condition[] conditions); boolean isNotificationPolicyAccessGranted(String pkg); diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java index 3f07024d1e5a..89ec19bbc6dd 100644 --- a/core/java/android/app/NotificationManager.java +++ b/core/java/android/app/NotificationManager.java @@ -825,6 +825,18 @@ public class NotificationManager { /** * @hide */ + public NotificationManager.Policy getConsolidatedNotificationPolicy() { + INotificationManager service = getService(); + try { + return service.getConsolidatedNotificationPolicy(); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * @hide + */ public int getRuleInstanceCount(ComponentName owner) { INotificationManager service = getService(); try { @@ -1062,7 +1074,7 @@ public class NotificationManager { } /** - * Gets the current notification policy. + * Gets the current user-specified default notification policy. * * <p> */ @@ -1621,6 +1633,71 @@ public class NotificationManager { return new Policy[size]; } }; + + /** @hide **/ + public boolean allowAlarms() { + return (priorityCategories & PRIORITY_CATEGORY_ALARMS) != 0; + } + + /** @hide **/ + public boolean allowMedia() { + return (priorityCategories & PRIORITY_CATEGORY_MEDIA) != 0; + } + + /** @hide **/ + public boolean allowSystem() { + return (priorityCategories & PRIORITY_CATEGORY_SYSTEM) != 0; + } + + /** @hide **/ + public boolean allowRepeatCallers() { + return (priorityCategories & PRIORITY_CATEGORY_REPEAT_CALLERS) != 0; + } + + /** @hide **/ + public boolean allowCalls() { + return (priorityCategories & PRIORITY_CATEGORY_CALLS) != 0; + } + + /** @hide **/ + public boolean allowMessages() { + return (priorityCategories & PRIORITY_CATEGORY_MESSAGES) != 0; + } + + /** @hide **/ + public boolean allowEvents() { + return (priorityCategories & PRIORITY_CATEGORY_EVENTS) != 0; + } + + /** @hide **/ + public boolean allowReminders() { + return (priorityCategories & PRIORITY_CATEGORY_REMINDERS) != 0; + } + + /** @hide **/ + public int allowCallsFrom() { + return priorityCallSenders; + } + + /** @hide **/ + public int allowMessagesFrom() { + return priorityMessageSenders; + } + + /** + * returns a deep copy of this policy + * @hide + */ + public Policy copy() { + final Parcel parcel = Parcel.obtain(); + try { + writeToParcel(parcel, 0); + parcel.setDataPosition(0); + return new Policy(parcel); + } finally { + parcel.recycle(); + } + } } /** @@ -1708,5 +1785,4 @@ public class NotificationManager { default: return defValue; } } - } diff --git a/core/java/android/service/notification/ZenModeConfig.java b/core/java/android/service/notification/ZenModeConfig.java index 37a9b10aeb6d..8371c31b5ac5 100644 --- a/core/java/android/service/notification/ZenModeConfig.java +++ b/core/java/android/service/notification/ZenModeConfig.java @@ -69,9 +69,9 @@ import java.util.UUID; public class ZenModeConfig implements Parcelable { private static String TAG = "ZenModeConfig"; - public static final int SOURCE_ANYONE = 0; - public static final int SOURCE_CONTACT = 1; - public static final int SOURCE_STAR = 2; + public static final int SOURCE_ANYONE = Policy.PRIORITY_SENDERS_ANY; + public static final int SOURCE_CONTACT = Policy.PRIORITY_SENDERS_CONTACTS; + public static final int SOURCE_STAR = Policy.PRIORITY_SENDERS_STARRED; public static final int MAX_SOURCE = SOURCE_STAR; private static final int DEFAULT_SOURCE = SOURCE_CONTACT; private static final int DEFAULT_CALLS_SOURCE = SOURCE_STAR; @@ -777,24 +777,6 @@ public class ZenModeConfig implements Parcelable { }; /** - * @return notification policy based on manual and automatic rules - */ - public Policy getConsolidatedNotificationPolicy() { - ZenPolicy policy = new ZenPolicy(); - - // assumption: manual rule always uses the default policy - for (ZenRule rule : automaticRules.values()) { - if (rule.isAutomaticActive()) { - if (rule.zenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) { - policy.apply(rule.zenPolicy); - } - } - } - - return toNotificationPolicy(policy); - } - - /** * Converts a zenPolicy to a notificationPolicy using this ZenModeConfig's values as its * defaults for all unset values in zenPolicy */ @@ -891,7 +873,7 @@ public class ZenModeConfig implements Parcelable { } return new NotificationManager.Policy(priorityCategories, callSenders, - messageSenders, suppressedVisualEffects); + messageSenders, suppressedVisualEffects, defaultPolicy.state); } private boolean isPriorityCategoryEnabled(int categoryType, Policy policy) { @@ -945,6 +927,7 @@ public class ZenModeConfig implements Parcelable { } priorityCallSenders = sourceToPrioritySenders(allowCallsFrom, priorityCallSenders); priorityMessageSenders = sourceToPrioritySenders(allowMessagesFrom, priorityMessageSenders); + return new Policy(priorityCategories, priorityCallSenders, priorityMessageSenders, suppressedVisualEffects, areChannelsBypassingDnd ? Policy.STATE_CHANNELS_BYPASSING_DND : 0); @@ -1732,13 +1715,25 @@ public class ZenModeConfig implements Parcelable { } /** + * Determines whether dnd behavior should mute all sounds controlled by ringer + */ + public static boolean areAllZenBehaviorSoundsMuted(NotificationManager.Policy + policy) { + boolean allowAlarms = (policy.priorityCategories & Policy.PRIORITY_CATEGORY_ALARMS) != 0; + boolean allowMedia = (policy.priorityCategories & Policy.PRIORITY_CATEGORY_MEDIA) != 0; + boolean allowSystem = (policy.priorityCategories & Policy.PRIORITY_CATEGORY_SYSTEM) != 0; + return !allowAlarms && !allowMedia && !allowSystem + && areAllPriorityOnlyNotificationZenSoundsMuted(policy); + } + + /** * Determines if DND is currently overriding the ringer */ - public static boolean isZenOverridingRinger(int zen, ZenModeConfig zenConfig) { + public static boolean isZenOverridingRinger(int zen, Policy consolidatedPolicy) { return zen == Global.ZEN_MODE_NO_INTERRUPTIONS || zen == Global.ZEN_MODE_ALARMS || (zen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS - && ZenModeConfig.areAllPriorityOnlyNotificationZenSoundsMuted(zenConfig)); + && ZenModeConfig.areAllPriorityOnlyNotificationZenSoundsMuted(consolidatedPolicy)); } /** diff --git a/core/java/android/service/notification/ZenPolicy.java b/core/java/android/service/notification/ZenPolicy.java index 1ccf529d3009..43ab8dc07000 100644 --- a/core/java/android/service/notification/ZenPolicy.java +++ b/core/java/android/service/notification/ZenPolicy.java @@ -818,6 +818,10 @@ public final class ZenPolicy implements Parcelable { * @hide */ public void apply(ZenPolicy policyToApply) { + if (policyToApply == null) { + return; + } + // apply priority categories for (int category = 0; category < mPriorityCategories.size(); category++) { if (mPriorityCategories.get(category) == STATE_DISALLOW) { |
