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

Change-Id: If36ab776bb95054a109b5475c6be041c75c7e0af
This commit is contained in:
Brad Fitzpatrick
2010-10-29 15:25:44 -07:00
parent 06487a58be
commit bfb191998e
3 changed files with 34 additions and 0 deletions

View File

@@ -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) {

View File

@@ -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);
}
}
}