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

Commit fbef74b3 authored by Yuri Lin's avatar Yuri Lin Committed by Automerger Merge Worker
Browse files

Merge "Track whether we've logged the "intercepted" state of a record." into...

Merge "Track whether we've logged the "intercepted" state of a record." into tm-qpr-dev am: 82dc9cb0 am: 065b8b58

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21447287



Change-Id: I0c132a720917dfe0428b251cfa9b04977e9bca8f
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 93c61731 065b8b58
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -8695,6 +8695,9 @@ public class NotificationManagerService extends SystemService {
            if (interceptBefore && !record.isIntercepted()
            if (interceptBefore && !record.isIntercepted()
                    && record.isNewEnoughForAlerting(System.currentTimeMillis())) {
                    && record.isNewEnoughForAlerting(System.currentTimeMillis())) {
                buzzBeepBlinkLocked(record);
                buzzBeepBlinkLocked(record);
                // Log alert after change in intercepted state to Zen Log as well
                ZenLog.traceAlertOnUpdatedIntercept(record);
            }
            }
        }
        }
        if (changed) {
        if (changed) {
+7 −0
Original line number Original line Diff line number Diff line
@@ -114,6 +114,8 @@ public final class NotificationRecord {


    // is this notification currently being intercepted by Zen Mode?
    // is this notification currently being intercepted by Zen Mode?
    private boolean mIntercept;
    private boolean mIntercept;
    // has the intercept value been set explicitly? we only want to log it if new or changed
    private boolean mInterceptSet;


    // is this notification hidden since the app pkg is suspended?
    // is this notification hidden since the app pkg is suspended?
    private boolean mHidden;
    private boolean mHidden;
@@ -929,6 +931,7 @@ public final class NotificationRecord {


    public boolean setIntercepted(boolean intercept) {
    public boolean setIntercepted(boolean intercept) {
        mIntercept = intercept;
        mIntercept = intercept;
        mInterceptSet = true;
        return mIntercept;
        return mIntercept;
    }
    }


@@ -949,6 +952,10 @@ public final class NotificationRecord {
        return mIntercept;
        return mIntercept;
    }
    }


    public boolean hasInterceptBeenSet() {
        return mInterceptSet;
    }

    public boolean isNewEnoughForAlerting(long now) {
    public boolean isNewEnoughForAlerting(long now) {
        return getFreshnessMs(now) <= MAX_SOUND_DELAY_MS;
        return getFreshnessMs(now) <= MAX_SOUND_DELAY_MS;
    }
    }
+6 −2
Original line number Original line Diff line number Diff line
@@ -68,20 +68,23 @@ public class ZenLog {
    private static final int TYPE_MATCHES_CALL_FILTER = 18;
    private static final int TYPE_MATCHES_CALL_FILTER = 18;
    private static final int TYPE_RECORD_CALLER = 19;
    private static final int TYPE_RECORD_CALLER = 19;
    private static final int TYPE_CHECK_REPEAT_CALLER = 20;
    private static final int TYPE_CHECK_REPEAT_CALLER = 20;
    private static final int TYPE_ALERT_ON_UPDATED_INTERCEPT = 21;


    private static int sNext;
    private static int sNext;
    private static int sSize;
    private static int sSize;


    public static void traceIntercepted(NotificationRecord record, String reason) {
    public static void traceIntercepted(NotificationRecord record, String reason) {
        if (record != null && record.isIntercepted()) return;  // already logged
        append(TYPE_INTERCEPTED, record.getKey() + "," + reason);
        append(TYPE_INTERCEPTED, record.getKey() + "," + reason);
    }
    }


    public static void traceNotIntercepted(NotificationRecord record, String reason) {
    public static void traceNotIntercepted(NotificationRecord record, String reason) {
        if (record != null && record.isUpdate) return;  // already logged
        append(TYPE_NOT_INTERCEPTED, record.getKey() + "," + reason);
        append(TYPE_NOT_INTERCEPTED, record.getKey() + "," + reason);
    }
    }


    public static void traceAlertOnUpdatedIntercept(NotificationRecord record) {
        append(TYPE_ALERT_ON_UPDATED_INTERCEPT, record.getKey());
    }

    public static void traceSetRingerModeExternal(int ringerModeOld, int ringerModeNew,
    public static void traceSetRingerModeExternal(int ringerModeOld, int ringerModeNew,
            String caller, int ringerModeInternalIn, int ringerModeInternalOut) {
            String caller, int ringerModeInternalIn, int ringerModeInternalOut) {
        append(TYPE_SET_RINGER_MODE_EXTERNAL, caller + ",e:" +
        append(TYPE_SET_RINGER_MODE_EXTERNAL, caller + ",e:" +
@@ -219,6 +222,7 @@ public class ZenLog {
            case TYPE_MATCHES_CALL_FILTER: return "matches_call_filter";
            case TYPE_MATCHES_CALL_FILTER: return "matches_call_filter";
            case TYPE_RECORD_CALLER: return "record_caller";
            case TYPE_RECORD_CALLER: return "record_caller";
            case TYPE_CHECK_REPEAT_CALLER: return "check_repeat_caller";
            case TYPE_CHECK_REPEAT_CALLER: return "check_repeat_caller";
            case TYPE_ALERT_ON_UPDATED_INTERCEPT: return "alert_on_updated_intercept";
            default: return "unknown";
            default: return "unknown";
        }
        }
    }
    }
+53 −25
Original line number Original line Diff line number Diff line
@@ -155,85 +155,85 @@ public class ZenModeFiltering {


        if (isCritical(record)) {
        if (isCritical(record)) {
            // Zen mode is ignored for critical notifications.
            // Zen mode is ignored for critical notifications.
            ZenLog.traceNotIntercepted(record, "criticalNotification");
            maybeLogInterceptDecision(record, false, "criticalNotification");
            return false;
            return false;
        }
        }
        // Make an exception to policy for the notification saying that policy has changed
        // Make an exception to policy for the notification saying that policy has changed
        if (NotificationManager.Policy.areAllVisualEffectsSuppressed(policy.suppressedVisualEffects)
        if (NotificationManager.Policy.areAllVisualEffectsSuppressed(policy.suppressedVisualEffects)
                && "android".equals(record.getSbn().getPackageName())
                && "android".equals(record.getSbn().getPackageName())
                && SystemMessageProto.SystemMessage.NOTE_ZEN_UPGRADE == record.getSbn().getId()) {
                && SystemMessageProto.SystemMessage.NOTE_ZEN_UPGRADE == record.getSbn().getId()) {
            ZenLog.traceNotIntercepted(record, "systemDndChangedNotification");
            maybeLogInterceptDecision(record, false, "systemDndChangedNotification");
            return false;
            return false;
        }
        }
        switch (zen) {
        switch (zen) {
            case Global.ZEN_MODE_NO_INTERRUPTIONS:
            case Global.ZEN_MODE_NO_INTERRUPTIONS:
                // #notevenalarms
                // #notevenalarms
                ZenLog.traceIntercepted(record, "none");
                maybeLogInterceptDecision(record, true, "none");
                return true;
                return true;
            case Global.ZEN_MODE_ALARMS:
            case Global.ZEN_MODE_ALARMS:
                if (isAlarm(record)) {
                if (isAlarm(record)) {
                    // Alarms only
                    // Alarms only
                    ZenLog.traceNotIntercepted(record, "alarm");
                    maybeLogInterceptDecision(record, false, "alarm");
                    return false;
                    return false;
                }
                }
                ZenLog.traceIntercepted(record, "alarmsOnly");
                maybeLogInterceptDecision(record, true, "alarmsOnly");
                return true;
                return true;
            case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS:
            case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS:
                // allow user-prioritized packages through in priority mode
                // allow user-prioritized packages through in priority mode
                if (record.getPackagePriority() == Notification.PRIORITY_MAX) {
                if (record.getPackagePriority() == Notification.PRIORITY_MAX) {
                    ZenLog.traceNotIntercepted(record, "priorityApp");
                    maybeLogInterceptDecision(record, false, "priorityApp");
                    return false;
                    return false;
                }
                }


                if (isAlarm(record)) {
                if (isAlarm(record)) {
                    if (!policy.allowAlarms()) {
                    if (!policy.allowAlarms()) {
                        ZenLog.traceIntercepted(record, "!allowAlarms");
                        maybeLogInterceptDecision(record, true, "!allowAlarms");
                        return true;
                        return true;
                    }
                    }
                    ZenLog.traceNotIntercepted(record, "allowedAlarm");
                    maybeLogInterceptDecision(record, false, "allowedAlarm");
                    return false;
                    return false;
                }
                }
                if (isEvent(record)) {
                if (isEvent(record)) {
                    if (!policy.allowEvents()) {
                    if (!policy.allowEvents()) {
                        ZenLog.traceIntercepted(record, "!allowEvents");
                        maybeLogInterceptDecision(record, true, "!allowEvents");
                        return true;
                        return true;
                    }
                    }
                    ZenLog.traceNotIntercepted(record, "allowedEvent");
                    maybeLogInterceptDecision(record, false, "allowedEvent");
                    return false;
                    return false;
                }
                }
                if (isReminder(record)) {
                if (isReminder(record)) {
                    if (!policy.allowReminders()) {
                    if (!policy.allowReminders()) {
                        ZenLog.traceIntercepted(record, "!allowReminders");
                        maybeLogInterceptDecision(record, true, "!allowReminders");
                        return true;
                        return true;
                    }
                    }
                    ZenLog.traceNotIntercepted(record, "allowedReminder");
                    maybeLogInterceptDecision(record, false, "allowedReminder");
                    return false;
                    return false;
                }
                }
                if (isMedia(record)) {
                if (isMedia(record)) {
                    if (!policy.allowMedia()) {
                    if (!policy.allowMedia()) {
                        ZenLog.traceIntercepted(record, "!allowMedia");
                        maybeLogInterceptDecision(record, true, "!allowMedia");
                        return true;
                        return true;
                    }
                    }
                    ZenLog.traceNotIntercepted(record, "allowedMedia");
                    maybeLogInterceptDecision(record, false, "allowedMedia");
                    return false;
                    return false;
                }
                }
                if (isSystem(record)) {
                if (isSystem(record)) {
                    if (!policy.allowSystem()) {
                    if (!policy.allowSystem()) {
                        ZenLog.traceIntercepted(record, "!allowSystem");
                        maybeLogInterceptDecision(record, true, "!allowSystem");
                        return true;
                        return true;
                    }
                    }
                    ZenLog.traceNotIntercepted(record, "allowedSystem");
                    maybeLogInterceptDecision(record, false, "allowedSystem");
                    return false;
                    return false;
                }
                }
                if (isConversation(record)) {
                if (isConversation(record)) {
                    if (policy.allowConversations()) {
                    if (policy.allowConversations()) {
                        if (policy.priorityConversationSenders == CONVERSATION_SENDERS_ANYONE) {
                        if (policy.priorityConversationSenders == CONVERSATION_SENDERS_ANYONE) {
                            ZenLog.traceNotIntercepted(record, "conversationAnyone");
                            maybeLogInterceptDecision(record, false, "conversationAnyone");
                            return false;
                            return false;
                        } else if (policy.priorityConversationSenders
                        } else if (policy.priorityConversationSenders
                                == NotificationManager.Policy.CONVERSATION_SENDERS_IMPORTANT
                                == NotificationManager.Policy.CONVERSATION_SENDERS_IMPORTANT
                                && record.getChannel().isImportantConversation()) {
                                && record.getChannel().isImportantConversation()) {
                            ZenLog.traceNotIntercepted(record, "conversationMatches");
                            maybeLogInterceptDecision(record, false, "conversationMatches");
                            return false;
                            return false;
                        }
                        }
                    }
                    }
@@ -244,31 +244,59 @@ public class ZenModeFiltering {
                    if (policy.allowRepeatCallers()
                    if (policy.allowRepeatCallers()
                            && REPEAT_CALLERS.isRepeat(
                            && REPEAT_CALLERS.isRepeat(
                                    mContext, extras(record), record.getPhoneNumbers())) {
                                    mContext, extras(record), record.getPhoneNumbers())) {
                        ZenLog.traceNotIntercepted(record, "repeatCaller");
                        maybeLogInterceptDecision(record, false, "repeatCaller");
                        return false;
                        return false;
                    }
                    }
                    if (!policy.allowCalls()) {
                    if (!policy.allowCalls()) {
                        ZenLog.traceIntercepted(record, "!allowCalls");
                        maybeLogInterceptDecision(record, true, "!allowCalls");
                        return true;
                        return true;
                    }
                    }
                    return shouldInterceptAudience(policy.allowCallsFrom(), record);
                    return shouldInterceptAudience(policy.allowCallsFrom(), record);
                }
                }
                if (isMessage(record)) {
                if (isMessage(record)) {
                    if (!policy.allowMessages()) {
                    if (!policy.allowMessages()) {
                        ZenLog.traceIntercepted(record, "!allowMessages");
                        maybeLogInterceptDecision(record, true, "!allowMessages");
                        return true;
                        return true;
                    }
                    }
                    return shouldInterceptAudience(policy.allowMessagesFrom(), record);
                    return shouldInterceptAudience(policy.allowMessagesFrom(), record);
                }
                }


                ZenLog.traceIntercepted(record, "!priority");
                maybeLogInterceptDecision(record, true, "!priority");
                return true;
                return true;
            default:
            default:
                ZenLog.traceNotIntercepted(record, "unknownZenMode");
                maybeLogInterceptDecision(record, false, "unknownZenMode");
                return false;
                return false;
        }
        }
    }
    }


    // Consider logging the decision of shouldIntercept for the given record.
    // This will log the outcome if one of the following is true:
    //   - it's the first time the intercept decision is set for the record
    //   - OR it's not the first time, but the intercept decision changed
    private static void maybeLogInterceptDecision(NotificationRecord record, boolean intercept,
            String reason) {
        boolean interceptBefore = record.isIntercepted();
        if (record.hasInterceptBeenSet() && (interceptBefore == intercept)) {
            // this record has already been evaluated for whether it should be intercepted, and
            // the decision has not changed.
            return;
        }

        // add a note to the reason indicating whether it's new or updated
        String annotatedReason = reason;
        if (!record.hasInterceptBeenSet()) {
            annotatedReason = "new:" + reason;
        } else if (interceptBefore != intercept) {
            annotatedReason = "updated:" + reason;
        }

        if (intercept) {
            ZenLog.traceIntercepted(record, annotatedReason);
        } else {
            ZenLog.traceNotIntercepted(record, annotatedReason);
        }
    }

    /**
    /**
     * Check if the notification is too critical to be suppressed.
     * Check if the notification is too critical to be suppressed.
     *
     *
@@ -285,10 +313,10 @@ public class ZenModeFiltering {
    private static boolean shouldInterceptAudience(int source, NotificationRecord record) {
    private static boolean shouldInterceptAudience(int source, NotificationRecord record) {
        float affinity = record.getContactAffinity();
        float affinity = record.getContactAffinity();
        if (!audienceMatches(source, affinity)) {
        if (!audienceMatches(source, affinity)) {
            ZenLog.traceIntercepted(record, "!audienceMatches,affinity=" + affinity);
            maybeLogInterceptDecision(record, true, "!audienceMatches,affinity=" + affinity);
            return true;
            return true;
        }
        }
        ZenLog.traceNotIntercepted(record, "affinity=" + affinity);
        maybeLogInterceptDecision(record, false, "affinity=" + affinity);
        return false;
        return false;
    }
    }