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

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

Merge "Don't mute ringer if apps can bypass dnd" into pi-dev

parents 67332c73 86d076f9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ interface INotificationManager
    boolean onlyHasDefaultChannel(String pkg, int uid);
    ParceledListSlice getRecentNotifyingAppsForUser(int userId);
    int getBlockedAppCount(int userId);
    boolean areChannelsBypassingDnd();

    // TODO: Remove this when callers have been migrated to the equivalent
    // INotificationListener method.
+34 −2
Original line number Diff line number Diff line
@@ -1166,6 +1166,23 @@ public class NotificationManager {
         */
        public final int suppressedVisualEffects;

        /**
         * @hide
         */
        public static final int STATE_CHANNELS_BYPASSING_DND = 1 << 0;

        /**
         * @hide
         */
        public static final int STATE_UNSET = -1;

        /**
         * Notification state information that is necessary to determine Do Not Disturb behavior.
         * Bitmask of STATE_* constants.
         * @hide
         */
        public final int state;

        /**
         * Constructs a policy for Do Not Disturb priority mode behavior.
         *
@@ -1181,7 +1198,7 @@ public class NotificationManager {
         */
        public Policy(int priorityCategories, int priorityCallSenders, int priorityMessageSenders) {
            this(priorityCategories, priorityCallSenders, priorityMessageSenders,
                    SUPPRESSED_EFFECTS_UNSET);
                    SUPPRESSED_EFFECTS_UNSET, STATE_UNSET);
        }

        /**
@@ -1219,11 +1236,23 @@ public class NotificationManager {
            this.priorityCallSenders = priorityCallSenders;
            this.priorityMessageSenders = priorityMessageSenders;
            this.suppressedVisualEffects = suppressedVisualEffects;
            this.state = STATE_UNSET;
        }

        /** @hide */
        public Policy(int priorityCategories, int priorityCallSenders, int priorityMessageSenders,
                int suppressedVisualEffects, int state) {
            this.priorityCategories = priorityCategories;
            this.priorityCallSenders = priorityCallSenders;
            this.priorityMessageSenders = priorityMessageSenders;
            this.suppressedVisualEffects = suppressedVisualEffects;
            this.state = state;
        }

        /** @hide */
        public Policy(Parcel source) {
            this(source.readInt(), source.readInt(), source.readInt(), source.readInt());
            this(source.readInt(), source.readInt(), source.readInt(), source.readInt(),
                    source.readInt());
        }

        @Override
@@ -1232,6 +1261,7 @@ public class NotificationManager {
            dest.writeInt(priorityCallSenders);
            dest.writeInt(priorityMessageSenders);
            dest.writeInt(suppressedVisualEffects);
            dest.writeInt(state);
        }

        @Override
@@ -1264,6 +1294,8 @@ public class NotificationManager {
                    + ",priorityMessageSenders=" + prioritySendersToString(priorityMessageSenders)
                    + ",suppressedVisualEffects="
                    + suppressedEffectsToString(suppressedVisualEffects)
                    + ",areChannelsBypassingDnd=" + (((state & STATE_CHANNELS_BYPASSING_DND) != 0)
                        ? "true" : "false")
                    + "]";
        }

+33 −6
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ public class ZenModeConfig implements Parcelable {
    private static final boolean DEFAULT_ALLOW_REPEAT_CALLERS = false;
    private static final boolean DEFAULT_ALLOW_SCREEN_OFF = false;
    private static final boolean DEFAULT_ALLOW_SCREEN_ON = false;
    private static final boolean DEFAULT_CHANNELS_BYPASSING_DND = false;
    private static final int DEFAULT_SUPPRESSED_VISUAL_EFFECTS =
            Policy.getAllSuppressedVisualEffects();

@@ -118,6 +119,8 @@ public class ZenModeConfig implements Parcelable {
    private static final String ALLOW_ATT_SCREEN_ON = "visualScreenOn";
    private static final String DISALLOW_TAG = "disallow";
    private static final String DISALLOW_ATT_VISUAL_EFFECTS = "visualEffects";
    private static final String STATE_TAG = "state";
    private static final String STATE_ATT_CHANNELS_BYPASSING_DND = "areChannelsBypassingDnd";

    private static final String CONDITION_ATT_ID = "id";
    private static final String CONDITION_ATT_SUMMARY = "summary";
@@ -154,6 +157,7 @@ public class ZenModeConfig implements Parcelable {
    public int suppressedVisualEffects = DEFAULT_SUPPRESSED_VISUAL_EFFECTS;
    public boolean allowWhenScreenOff = DEFAULT_ALLOW_SCREEN_OFF;
    public boolean allowWhenScreenOn = DEFAULT_ALLOW_SCREEN_ON;
    public boolean areChannelsBypassingDnd = DEFAULT_CHANNELS_BYPASSING_DND;
    public int version;

    public ZenRule manualRule;
@@ -187,6 +191,7 @@ public class ZenModeConfig implements Parcelable {
        allowMedia = source.readInt() == 1;
        allowSystem = source.readInt() == 1;
        suppressedVisualEffects = source.readInt();
        areChannelsBypassingDnd = source.readInt() == 1;
    }

    @Override
@@ -220,6 +225,7 @@ public class ZenModeConfig implements Parcelable {
        dest.writeInt(allowMedia ? 1 : 0);
        dest.writeInt(allowSystem ? 1 : 0);
        dest.writeInt(suppressedVisualEffects);
        dest.writeInt(areChannelsBypassingDnd ? 1 : 0);
    }

    @Override
@@ -239,6 +245,7 @@ public class ZenModeConfig implements Parcelable {
                .append(",allowWhenScreenOff=").append(allowWhenScreenOff)
                .append(",allowWhenScreenOn=").append(allowWhenScreenOn)
                .append(",suppressedVisualEffects=").append(suppressedVisualEffects)
                .append(",areChannelsBypassingDnd=").append(areChannelsBypassingDnd)
                .append(",automaticRules=").append(automaticRules)
                .append(",manualRule=").append(manualRule)
                .append(']').toString();
@@ -303,6 +310,11 @@ public class ZenModeConfig implements Parcelable {
            ZenRule.appendDiff(d, "automaticRule[" + rule + "]", fromRule, toRule);
        }
        ZenRule.appendDiff(d, "manualRule", manualRule, to.manualRule);

        if (areChannelsBypassingDnd != to.areChannelsBypassingDnd) {
            d.addLine("areChannelsBypassingDnd", areChannelsBypassingDnd,
                    to.areChannelsBypassingDnd);
        }
        return d;
    }

@@ -397,7 +409,8 @@ public class ZenModeConfig implements Parcelable {
                && other.user == user
                && Objects.equals(other.automaticRules, automaticRules)
                && Objects.equals(other.manualRule, manualRule)
                && other.suppressedVisualEffects == suppressedVisualEffects;
                && other.suppressedVisualEffects == suppressedVisualEffects
                && other.areChannelsBypassingDnd == areChannelsBypassingDnd;
    }

    @Override
@@ -406,7 +419,7 @@ public class ZenModeConfig implements Parcelable {
                allowRepeatCallers, allowMessages,
                allowCallsFrom, allowMessagesFrom, allowReminders, allowEvents,
                allowWhenScreenOff, allowWhenScreenOn, user, automaticRules, manualRule,
                suppressedVisualEffects);
                suppressedVisualEffects, areChannelsBypassingDnd);
    }

    private static String toDayList(int[] days) {
@@ -511,6 +524,9 @@ public class ZenModeConfig implements Parcelable {
                        automaticRule.id = id;
                        rt.automaticRules.put(id, automaticRule);
                    }
                } else if (STATE_TAG.equals(tag)) {
                    rt.areChannelsBypassingDnd = safeBoolean(parser,
                            STATE_ATT_CHANNELS_BYPASSING_DND, DEFAULT_CHANNELS_BYPASSING_DND);
                }
            }
        }
@@ -561,6 +577,12 @@ public class ZenModeConfig implements Parcelable {
            writeRuleXml(automaticRule, out);
            out.endTag(null, AUTOMATIC_TAG);
        }

        out.startTag(null, STATE_TAG);
        out.attribute(null, STATE_ATT_CHANNELS_BYPASSING_DND,
                Boolean.toString(areChannelsBypassingDnd));
        out.endTag(null, STATE_TAG);

        out.endTag(null, ZEN_TAG);
    }

@@ -743,7 +765,8 @@ public class ZenModeConfig implements Parcelable {
        priorityCallSenders = sourceToPrioritySenders(allowCallsFrom, priorityCallSenders);
        priorityMessageSenders = sourceToPrioritySenders(allowMessagesFrom, priorityMessageSenders);
        return new Policy(priorityCategories, priorityCallSenders, priorityMessageSenders,
                suppressedVisualEffects);
                suppressedVisualEffects, areChannelsBypassingDnd
                ? Policy.STATE_CHANNELS_BYPASSING_DND : 0);
    }

    /**
@@ -795,6 +818,9 @@ public class ZenModeConfig implements Parcelable {
        if (policy.suppressedVisualEffects != Policy.SUPPRESSED_EFFECTS_UNSET) {
            suppressedVisualEffects = policy.suppressedVisualEffects;
        }
        if (policy.state != Policy.STATE_UNSET) {
            areChannelsBypassingDnd = (policy.state & Policy.STATE_CHANNELS_BYPASSING_DND) != 0;
        }
    }

    public static Condition toTimeCondition(Context context, int minutesFromNow, int userHandle) {
@@ -1465,15 +1491,15 @@ public class ZenModeConfig implements Parcelable {
                & NotificationManager.Policy.PRIORITY_CATEGORY_EVENTS) != 0;
        boolean allowRepeatCallers = (policy.priorityCategories
                & NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS) != 0;
        boolean areChannelsBypassingDnd = (policy.state & Policy.STATE_CHANNELS_BYPASSING_DND) != 0;
        return !allowReminders && !allowCalls && !allowMessages && !allowEvents
                && !allowRepeatCallers;
                && !allowRepeatCallers && !areChannelsBypassingDnd;
    }

    /**
     * Determines if DND is currently overriding the ringer
     */
    public static boolean isZenOverridingRinger(int zen, ZenModeConfig zenConfig) {
        // TODO (beverlyt): check if apps can bypass dnd b/77729075
        return zen == Global.ZEN_MODE_NO_INTERRUPTIONS
                || zen == Global.ZEN_MODE_ALARMS
                || (zen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS
@@ -1485,7 +1511,8 @@ public class ZenModeConfig implements Parcelable {
     */
    public static boolean areAllPriorityOnlyNotificationZenSoundsMuted(ZenModeConfig config) {
        return !config.allowReminders && !config.allowCalls && !config.allowMessages
                && !config.allowEvents && !config.allowRepeatCallers;
                && !config.allowEvents && !config.allowRepeatCallers
                && !config.areChannelsBypassingDnd;
    }

    /**
+6 −2
Original line number Diff line number Diff line
@@ -19,8 +19,12 @@

<!-- Default configuration for zen mode.  See android.service.notification.ZenModeConfig. -->
<zen version="7">
    <allow alarms="true" media="true" system="false" calls="false" messages="false" reminders="false"
           events="false" />
    <allow alarms="true" media="true" system="false" calls="false" messages="false"
           reminders="false" events="false" />

    <!-- all visual effects that exist as of P -->
    <disallow suppressedVisualEffect="511" />

    <!-- whether there are notification channels that can bypass dnd -->
    <state areChannelsBypassingDnd="false" />
</zen>
+5 −1
Original line number Diff line number Diff line
@@ -2396,6 +2396,11 @@ public class NotificationManagerService extends SystemService {
            return mRankingHelper.getBlockedAppCount(userId);
        }

        @Override
        public boolean areChannelsBypassingDnd() {
            return mRankingHelper.areChannelsBypassingDnd();
        }

        @Override
        public void clearData(String packageName, int uid, boolean fromApp) throws RemoteException {
            checkCallerIsSystem();
@@ -3278,7 +3283,6 @@ public class NotificationManagerService extends SystemService {
                policy = new Policy(policy.priorityCategories,
                        policy.priorityCallSenders, policy.priorityMessageSenders,
                        newVisualEffects);

                ZenLog.traceSetNotificationPolicy(pkg, applicationInfo.targetSdkVersion, policy);
                mZenModeHelper.setNotificationPolicy(policy);
            } catch (RemoteException e) {
Loading