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

Commit c3cb9f2e authored by Brad Fitzpatrick's avatar Brad Fitzpatrick Committed by Android (Google) Code Review
Browse files

Merge "StrictMode: annotate violations with the Broadcast Intent's action, if any."

parents 1219ea3b bfb19199
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -1781,6 +1781,17 @@ public final class ActivityThread {
        performNewIntents(data.token, data.intents);
    }

    private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>();

    /**
     * Return the Intent that's currently being handled by a
     * BroadcastReceiver on this thread, or null if none.
     * @hide
     */
    public static Intent getIntentBeingBroadcast() {
        return sCurrentBroadcastIntent.get();
    }

    private final void handleReceiver(ReceiverData data) {
        // If we are getting ready to gc after going to the background, well
        // we are back active so skip it.
@@ -1820,6 +1831,7 @@ public final class ActivityThread {
                + ", dir=" + packageInfo.getAppDir());

            ContextImpl context = (ContextImpl)app.getBaseContext();
            sCurrentBroadcastIntent.set(data.intent);
            receiver.setPendingResult(data);
            receiver.onReceive(context.getReceiverRestrictedContext(),
                    data.intent);
@@ -1832,6 +1844,8 @@ public final class ActivityThread {
                    "Unable to start receiver " + component
                    + ": " + e.toString(), e);
            }
        } finally {
            sCurrentBroadcastIntent.set(null);
        }

        if (receiver.getPendingResult() != null) {
+17 −0
Original line number Diff line number Diff line
@@ -17,7 +17,9 @@ package android.os;

import android.animation.ValueAnimator;
import android.app.ActivityManagerNative;
import android.app.ActivityThread;
import android.app.ApplicationErrorReport;
import android.content.Intent;
import android.util.Log;
import android.util.Printer;

@@ -1204,6 +1206,12 @@ public final class StrictMode {
         */
        public long violationUptimeMillis;

        /**
         * The action of the Intent being broadcast to somebody's onReceive
         * on this thread right now, or null.
         */
        public String broadcastIntentAction;

        /**
         * Create an uninitialized instance of ViolationInfo
         */
@@ -1220,6 +1228,10 @@ public final class StrictMode {
            violationUptimeMillis = SystemClock.uptimeMillis();
            this.policy = policy;
            this.numAnimationsRunning = ValueAnimator.getCurrentAnimationsCount();
            Intent broadcastIntent = ActivityThread.getIntentBeingBroadcast();
            if (broadcastIntent != null) {
                broadcastIntentAction = broadcastIntent.getAction();
            }
        }

        /**
@@ -1247,6 +1259,7 @@ public final class StrictMode {
            violationNumThisLoop = in.readInt();
            numAnimationsRunning = in.readInt();
            violationUptimeMillis = in.readLong();
            broadcastIntentAction = in.readString();
        }

        /**
@@ -1259,6 +1272,7 @@ public final class StrictMode {
            dest.writeInt(violationNumThisLoop);
            dest.writeInt(numAnimationsRunning);
            dest.writeLong(violationUptimeMillis);
            dest.writeString(broadcastIntentAction);
        }


@@ -1278,6 +1292,9 @@ public final class StrictMode {
                pw.println(prefix + "numAnimationsRunning: " + numAnimationsRunning);
            }
            pw.println(prefix + "violationUptimeMillis: " + violationUptimeMillis);
            if (broadcastIntentAction != null) {
                pw.println(prefix + "broadcastIntentAction: " + broadcastIntentAction);
            }
        }

    }
+3 −0
Original line number Diff line number Diff line
@@ -6679,6 +6679,9 @@ public final class ActivityManagerService extends ActivityManagerNative
            if (info.numAnimationsRunning != 0) {
                sb.append("Animations-Running: ").append(info.numAnimationsRunning).append("\n");
            }
            if (info.broadcastIntentAction != null) {
                sb.append("Broadcast-Intent-Action: ").append(info.broadcastIntentAction).append("\n");
            }
            if (info != null && info.durationMillis != -1) {
                sb.append("Duration-Millis: ").append(info.durationMillis).append("\n");
            }