From 1f5ac4d322d76ca76fdf5dee40fe9549aad7437e Mon Sep 17 00:00:00 2001 From: riddle_hsu Date: Sat, 3 Jan 2015 15:38:21 +0800 Subject: [ActivityManager] Distinguish FG or BG receiver finished Symptom: Assume a foreground broadcast FG and a background BG. If a recevier registers both FG and BG. When sending BG and FG to the receiver, and the receiver BG receiver completes first, its finishReceiver will trigger next FG receiver rather than BG, and also deliver wrong result code/data to the next. More detail and sample: https://code.google.com/p/android/issues/detail?id=92917 Root cause: Due to BroadcastQueue:getMatchingOrderedReceiver will match by receiver(IBinder), so the caller ActivityManagerService: broadcastRecordForReceiverLocked will always match the first queue(fg) if a receiver is both receiving fg and bg. Solution: Add a parameter flags to finishReceiver, then server side could know the finished receiver should belong to which queue. Another general solution but with bigger scope: I60dce4a48e20c1002a61a979e4d78b9b0a8b94a0 Change-Id: I913ca6f101ac8ec6c7a8e42754e6781f80247b7f --- core/java/android/content/BroadcastReceiver.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'core/java/android/content') diff --git a/core/java/android/content/BroadcastReceiver.java b/core/java/android/content/BroadcastReceiver.java index 9a32fdf..af74e73 100644 --- a/core/java/android/content/BroadcastReceiver.java +++ b/core/java/android/content/BroadcastReceiver.java @@ -238,6 +238,7 @@ public abstract class BroadcastReceiver { final boolean mInitialStickyHint; final IBinder mToken; final int mSendingUser; + final int mFlags; int mResultCode; String mResultData; @@ -246,8 +247,8 @@ public abstract class BroadcastReceiver { boolean mFinished; /** @hide */ - public PendingResult(int resultCode, String resultData, Bundle resultExtras, - int type, boolean ordered, boolean sticky, IBinder token, int userId) { + public PendingResult(int resultCode, String resultData, Bundle resultExtras, int type, + boolean ordered, boolean sticky, IBinder token, int userId, int flags) { mResultCode = resultCode; mResultData = resultData; mResultExtras = resultExtras; @@ -256,6 +257,7 @@ public abstract class BroadcastReceiver { mInitialStickyHint = sticky; mToken = token; mSendingUser = userId; + mFlags = flags; } /** @@ -417,11 +419,11 @@ public abstract class BroadcastReceiver { } if (mOrderedHint) { am.finishReceiver(mToken, mResultCode, mResultData, mResultExtras, - mAbortBroadcast); + mAbortBroadcast, mFlags); } else { // This broadcast was sent to a component; it is not ordered, // but we still need to tell the activity manager we are done. - am.finishReceiver(mToken, 0, null, null, false); + am.finishReceiver(mToken, 0, null, null, false, mFlags); } } catch (RemoteException ex) { } -- cgit v1.1