diff options
author | Christopher Tate <ctate@android.com> | 2009-12-08 13:48:45 -0800 |
---|---|---|
committer | Christopher Tate <ctate@android.com> | 2009-12-08 13:48:45 -0800 |
commit | 08a462524a81bda336b17e25e3b178448880d448 (patch) | |
tree | 56df0fb929c8c2578a5fc2005bf7d30cea2d253a | |
parent | d59fb6e7435b57d83662b196f5430e6f2bc5427b (diff) | |
download | frameworks_base-08a462524a81bda336b17e25e3b178448880d448.zip frameworks_base-08a462524a81bda336b17e25e3b178448880d448.tar.gz frameworks_base-08a462524a81bda336b17e25e3b178448880d448.tar.bz2 |
Make sure to acknowledge stale broadcasts
If a broadcast arrives at a process but the receiver has been unregistered in
the interval between dispatch and its arrival on the receiving process's side,
we were simply dropping the broadcast entirely, leading to spurious ANRs and
potentially issues involving future broadcasts being timed out incorrectly. Fix
this by making sure to correctly 'finish' a broadcast even when the recipient
app no longer has any receiver that matches the broadcast's profile.
Change-Id: If990cab021a26668052cb536753f6c308d80a5b4
-rw-r--r-- | core/java/android/app/ActivityThread.java | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 467812e..1115f92 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -691,6 +691,20 @@ public final class ActivityThread { if (rd != null) { rd.performReceive(intent, resultCode, data, extras, ordered, sticky); + } else { + // The activity manager dispatched a broadcast to a registered + // receiver in this process, but before it could be delivered the + // receiver was unregistered. Acknowledge the broadcast on its + // behalf so that the system's broadcast sequence can continue. + if (DEBUG_BROADCAST) { + Log.i(TAG, "Broadcast to unregistered receiver"); + } + IActivityManager mgr = ActivityManagerNative.getDefault(); + try { + mgr.finishReceiver(this, resultCode, data, extras, false); + } catch (RemoteException e) { + Log.w(TAG, "Couldn't finish broadcast to unregistered receiver"); + } } } } @@ -716,8 +730,8 @@ public final class ActivityThread { BroadcastReceiver receiver = mReceiver; if (DEBUG_BROADCAST) { int seq = mCurIntent.getIntExtra("seq", -1); - Log.i(TAG, "Dispathing broadcast " + mCurIntent.getAction() + " seq=" + seq - + " to " + mReceiver); + Log.i(TAG, "Dispatching broadcast " + mCurIntent.getAction() + + " seq=" + seq + " to " + mReceiver); } if (receiver == null) { return; |