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

Commit 02315ed7 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by android-build-merger
Browse files

Merge "Offer listener to observe StrictMode violations." into oc-dev

am: a6b7e0a6

Change-Id: I1610373c91aa4fc2a60732c51145b585b6372729
parents e07ceaf9 a6b7e0a6
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -342,6 +342,18 @@ public final class StrictMode {
    private static volatile int sVmPolicyMask = 0;
    private static volatile VmPolicy sVmPolicy = VmPolicy.LAX;

    /** {@hide} */
    public interface ViolationListener {
        public void onViolation(String message);
    }

    private static volatile ViolationListener sListener;

    /** {@hide} */
    public static void setViolationListener(ViolationListener listener) {
        sListener = listener;
    }

    /**
     * The number of threads trying to do an async dropbox write.
     * Just to limit ourselves out of paranoia.
@@ -1581,6 +1593,9 @@ public final class StrictMode {
            long timeSinceLastViolationMillis = lastViolationTime == 0 ?
                    Long.MAX_VALUE : (now - lastViolationTime);

            if ((info.policy & PENALTY_LOG) != 0 && sListener != null) {
                sListener.onViolation(info.crashInfo.stackTrace);
            }
            if ((info.policy & PENALTY_LOG) != 0 &&
                timeSinceLastViolationMillis > MIN_LOG_INTERVAL_MS) {
                if (info.durationMillis != -1) {
@@ -2024,6 +2039,9 @@ public final class StrictMode {
            }
        }

        if (penaltyLog && sListener != null) {
            sListener.onViolation(originStack.toString());
        }
        if (penaltyLog && timeSinceLastViolationMillis > MIN_LOG_INTERVAL_MS) {
            Log.e(TAG, message, originStack);
        }