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

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

Merge "Add logging in ZenLog for calls to matchesCallFilter."

parents 9217d6e4 56ed7581
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ public class ZenLog {
    private static final int TYPE_LISTENER_HINTS_CHANGED = 15;
    private static final int TYPE_SET_NOTIFICATION_POLICY = 16;
    private static final int TYPE_SET_CONSOLIDATED_ZEN_POLICY = 17;
    private static final int TYPE_MATCHES_CALL_FILTER = 18;

    private static int sNext;
    private static int sSize;
@@ -166,6 +167,13 @@ public class ZenLog {
            + hintsToString(newHints) + ",listeners=" + listenerCount);
    }

    /*
     * Trace calls to matchesCallFilter with the result of the call and the reason for the result.
     */
    public static void traceMatchesCallFilter(boolean result, String reason) {
        append(TYPE_MATCHES_CALL_FILTER, "result=" + result + ", reason=" + reason);
    }

    private static String subscribeResult(IConditionProvider provider, RemoteException e) {
        return provider == null ? "no provider" : e != null ? e.getMessage() : "ok";
    }
@@ -189,6 +197,7 @@ public class ZenLog {
            case TYPE_LISTENER_HINTS_CHANGED: return "listener_hints_changed";
            case TYPE_SET_NOTIFICATION_POLICY: return "set_notification_policy";
            case TYPE_SET_CONSOLIDATED_ZEN_POLICY: return "set_consolidated_policy";
            case TYPE_MATCHES_CALL_FILTER: return "matches_call_filter";
            default: return "unknown";
        }
    }
+18 −4
Original line number Diff line number Diff line
@@ -89,20 +89,34 @@ public class ZenModeFiltering {
    public static boolean matchesCallFilter(Context context, int zen, NotificationManager.Policy
            consolidatedPolicy, UserHandle userHandle, Bundle extras,
            ValidateNotificationPeople validator, int contactsTimeoutMs, float timeoutAffinity) {
        if (zen == Global.ZEN_MODE_NO_INTERRUPTIONS) return false; // nothing gets through
        if (zen == Global.ZEN_MODE_ALARMS) return false; // not an alarm
        if (zen == Global.ZEN_MODE_NO_INTERRUPTIONS) {
            ZenLog.traceMatchesCallFilter(false, "no interruptions");
            return false; // nothing gets through
        }
        if (zen == Global.ZEN_MODE_ALARMS) {
            ZenLog.traceMatchesCallFilter(false, "alarms only");
            return false; // not an alarm
        }
        if (zen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) {
            if (consolidatedPolicy.allowRepeatCallers()
                    && REPEAT_CALLERS.isRepeat(context, extras)) {
                ZenLog.traceMatchesCallFilter(true, "repeat caller");
                return true;
            }
            if (!consolidatedPolicy.allowCalls()) return false; // no other calls get through
            if (!consolidatedPolicy.allowCalls()) {
                ZenLog.traceMatchesCallFilter(false, "calls not allowed");
                return false; // no other calls get through
            }
            if (validator != null) {
                final float contactAffinity = validator.getContactAffinity(userHandle, extras,
                        contactsTimeoutMs, timeoutAffinity);
                return audienceMatches(consolidatedPolicy.allowCallsFrom(), contactAffinity);
                boolean match =
                        audienceMatches(consolidatedPolicy.allowCallsFrom(), contactAffinity);
                ZenLog.traceMatchesCallFilter(match, "contact affinity " + contactAffinity);
                return match;
            }
        }
        ZenLog.traceMatchesCallFilter(true, "no restrictions");
        return true;
    }