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

Commit 82dc9cb0 authored by Yuri Lin's avatar Yuri Lin Committed by Android (Google) Code Review
Browse files

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

parents 17d1886e bd4708cd
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -8543,6 +8543,9 @@ public class NotificationManagerService extends SystemService {
            if (interceptBefore && !record.isIntercepted()
                    && record.isNewEnoughForAlerting(System.currentTimeMillis())) {
                buzzBeepBlinkLocked(record);
                // Log alert after change in intercepted state to Zen Log as well
                ZenLog.traceAlertOnUpdatedIntercept(record);
            }
        }
        if (changed) {
+7 −0
Original line number Diff line number Diff line
@@ -114,6 +114,8 @@ public final class NotificationRecord {

    // is this notification currently being intercepted by Zen Mode?
    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?
    private boolean mHidden;
@@ -914,6 +916,7 @@ public final class NotificationRecord {

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

@@ -934,6 +937,10 @@ public final class NotificationRecord {
        return mIntercept;
    }

    public boolean hasInterceptBeenSet() {
        return mInterceptSet;
    }

    public boolean isNewEnoughForAlerting(long now) {
        return getFreshnessMs(now) <= MAX_SOUND_DELAY_MS;
    }
+6 −2
Original line number 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_RECORD_CALLER = 19;
    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 sSize;

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

    public static void traceNotIntercepted(NotificationRecord record, String reason) {
        if (record != null && record.isUpdate) return;  // already logged
        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,
            String caller, int ringerModeInternalIn, int ringerModeInternalOut) {
        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_RECORD_CALLER: return "record_caller";
            case TYPE_CHECK_REPEAT_CALLER: return "check_repeat_caller";
            case TYPE_ALERT_ON_UPDATED_INTERCEPT: return "alert_on_updated_intercept";
            default: return "unknown";
        }
    }
+53 −25
Original line number Diff line number Diff line
@@ -155,85 +155,85 @@ public class ZenModeFiltering {

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

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

                ZenLog.traceIntercepted(record, "!priority");
                maybeLogInterceptDecision(record, true, "!priority");
                return true;
            default:
                ZenLog.traceNotIntercepted(record, "unknownZenMode");
                maybeLogInterceptDecision(record, false, "unknownZenMode");
                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.
     *
@@ -285,10 +313,10 @@ public class ZenModeFiltering {
    private static boolean shouldInterceptAudience(int source, NotificationRecord record) {
        float affinity = record.getContactAffinity();
        if (!audienceMatches(source, affinity)) {
            ZenLog.traceIntercepted(record, "!audienceMatches,affinity=" + affinity);
            maybeLogInterceptDecision(record, true, "!audienceMatches,affinity=" + affinity);
            return true;
        }
        ZenLog.traceNotIntercepted(record, "affinity=" + affinity);
        maybeLogInterceptDecision(record, false, "affinity=" + affinity);
        return false;
    }