Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b9bfae64 authored by Beverly Tai's avatar Beverly Tai Committed by Android (Google) Code Review
Browse files

Merge "Use consolidated zen policy for dnd"

parents 3853952b ff2df9b8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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();
    }

    /**
+1 −0
Original line number Diff line number Diff line
@@ -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);
+78 −2
Original line number Diff line number Diff line
@@ -822,6 +822,18 @@ public class NotificationManager {
        }
    }

    /**
     * @hide
     */
    public NotificationManager.Policy getConsolidatedNotificationPolicy() {
        INotificationManager service = getService();
        try {
            return service.getConsolidatedNotificationPolicy();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * @hide
     */
@@ -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;
        }
    }

}
+19 −24
Original line number Diff line number Diff line
@@ -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;
@@ -776,24 +776,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);
@@ -1731,14 +1714,26 @@ public class ZenModeConfig implements Parcelable {
                && !allowRepeatCallers && !areChannelsBypassingDnd;
    }

    /**
     * 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));
    }

    /**
+4 −0
Original line number Diff line number Diff line
@@ -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) {
Loading