am 68d881cf: Fix issue #2166755: BroadcastReceiver trying to return result during a non-ordered broadcast

Merge commit '68d881cf2d2b252f6f795cd64d43e316a1d736e5' into eclair-mr2

* commit '68d881cf2d2b252f6f795cd64d43e316a1d736e5':
  Fix issue #2166755: BroadcastReceiver trying to return result during a non-ordered broadcast
This commit is contained in:
Dianne Hackborn
2009-10-05 15:58:13 -07:00
committed by Android Git Automerger
12 changed files with 92 additions and 29 deletions

View File

@@ -653,7 +653,7 @@ public final class ActivityThread {
mStrongRef = strong ? rd : null;
}
public void performReceive(Intent intent, int resultCode,
String data, Bundle extras, boolean ordered) {
String data, Bundle extras, boolean ordered, boolean sticky) {
ReceiverDispatcher rd = mDispatcher.get();
if (DEBUG_BROADCAST) {
int seq = intent.getIntExtra("seq", -1);
@@ -661,7 +661,8 @@ public final class ActivityThread {
+ " to " + rd);
}
if (rd != null) {
rd.performReceive(intent, resultCode, data, extras, ordered);
rd.performReceive(intent, resultCode, data, extras,
ordered, sticky);
}
}
}
@@ -681,6 +682,7 @@ public final class ActivityThread {
private String mCurData;
private Bundle mCurMap;
private boolean mCurOrdered;
private boolean mCurSticky;
public void run() {
BroadcastReceiver receiver = mReceiver;
@@ -706,6 +708,7 @@ public final class ActivityThread {
receiver.setResult(mCurCode, mCurData, mCurMap);
receiver.clearAbortBroadcast();
receiver.setOrderedHint(mCurOrdered);
receiver.setInitialStickyHint(mCurSticky);
receiver.onReceive(mContext, intent);
} catch (Exception e) {
if (mRegistered && mCurOrdered) {
@@ -788,7 +791,7 @@ public final class ActivityThread {
}
public void performReceive(Intent intent, int resultCode,
String data, Bundle extras, boolean ordered) {
String data, Bundle extras, boolean ordered, boolean sticky) {
if (DEBUG_BROADCAST) {
int seq = intent.getIntExtra("seq", -1);
Log.i(TAG, "Enqueueing broadcast " + intent.getAction() + " seq=" + seq
@@ -800,6 +803,7 @@ public final class ActivityThread {
args.mCurData = data;
args.mCurMap = extras;
args.mCurOrdered = ordered;
args.mCurSticky = sticky;
if (!mActivityThread.post(args)) {
if (mRegistered) {
IActivityManager mgr = ActivityManagerNative.getDefault();
@@ -1515,9 +1519,9 @@ public final class ActivityThread {
// correctly ordered, since these are one-way calls and the binder driver
// applies transaction ordering per object for such calls.
public void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent,
int resultCode, String dataStr, Bundle extras, boolean ordered)
throws RemoteException {
receiver.performReceive(intent, resultCode, dataStr, extras, ordered);
int resultCode, String dataStr, Bundle extras, boolean ordered,
boolean sticky) throws RemoteException {
receiver.performReceive(intent, resultCode, dataStr, extras, ordered, sticky);
}
public void scheduleLowMemory() {

View File

@@ -317,8 +317,9 @@ public abstract class ApplicationThreadNative extends Binder
String dataStr = data.readString();
Bundle extras = data.readBundle();
boolean ordered = data.readInt() != 0;
boolean sticky = data.readInt() != 0;
scheduleRegisteredReceiver(receiver, intent,
resultCode, dataStr, extras, ordered);
resultCode, dataStr, extras, ordered, sticky);
return true;
}
@@ -716,7 +717,7 @@ class ApplicationThreadProxy implements IApplicationThread {
}
public void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent,
int resultCode, String dataStr, Bundle extras, boolean ordered)
int resultCode, String dataStr, Bundle extras, boolean ordered, boolean sticky)
throws RemoteException {
Parcel data = Parcel.obtain();
data.writeInterfaceToken(IApplicationThread.descriptor);
@@ -726,6 +727,7 @@ class ApplicationThreadProxy implements IApplicationThread {
data.writeString(dataStr);
data.writeBundle(extras);
data.writeInt(ordered ? 1 : 0);
data.writeInt(sticky ? 1 : 0);
mRemote.transact(SCHEDULE_REGISTERED_RECEIVER_TRANSACTION, data, null,
IBinder.FLAG_ONEWAY);
data.recycle();

View File

@@ -91,7 +91,7 @@ public interface IApplicationThread extends IInterface {
void dumpService(FileDescriptor fd, IBinder servicetoken, String[] args)
throws RemoteException;
void scheduleRegisteredReceiver(IIntentReceiver receiver, Intent intent,
int resultCode, String data, Bundle extras, boolean ordered)
int resultCode, String data, Bundle extras, boolean ordered, boolean sticky)
throws RemoteException;
void scheduleLowMemory() throws RemoteException;
void scheduleActivityConfigurationChanged(IBinder token) throws RemoteException;

View File

@@ -147,7 +147,7 @@ public final class PendingIntent implements Parcelable {
mHandler = handler;
}
public void performReceive(Intent intent, int resultCode,
String data, Bundle extras, boolean serialized) {
String data, Bundle extras, boolean serialized, boolean sticky) {
mIntent = intent;
mResultCode = resultCode;
mResultData = data;

View File

@@ -383,6 +383,24 @@ public abstract class BroadcastReceiver {
mAbortBroadcast = false;
}
/**
* Returns true if the receiver is currently processing an ordered
* broadcast.
*/
public final boolean isOrderedBroadcast() {
return mOrderedHint;
}
/**
* Returns true if the receiver is currently processing the initial
* value of a sticky broadcast -- that is, the value that was last
* broadcast and is currently held in the sticky cache, so this is
* not directly the result of a broadcast right now.
*/
public final boolean isInitialStickyBroadcast() {
return mInitialStickyHint;
}
/**
* For internal use, sets the hint about whether this BroadcastReceiver is
* running in ordered mode.
@@ -391,6 +409,14 @@ public abstract class BroadcastReceiver {
mOrderedHint = isOrdered;
}
/**
* For internal use, sets the hint about whether this BroadcastReceiver is
* receiving the initial sticky broadcast value. @hide
*/
public final void setInitialStickyHint(boolean isInitialSticky) {
mInitialStickyHint = isInitialSticky;
}
/**
* Control inclusion of debugging help for mismatched
* calls to {@ Context#registerReceiver(BroadcastReceiver, IntentFilter)
@@ -414,7 +440,10 @@ public abstract class BroadcastReceiver {
}
void checkSynchronousHint() {
if (mOrderedHint) {
// Note that we don't assert when receiving the initial sticky value,
// since that may have come from an ordered broadcast. We'll catch
// them later when the real broadcast happens again.
if (mOrderedHint || mInitialStickyHint) {
return;
}
RuntimeException e = new RuntimeException(
@@ -429,5 +458,6 @@ public abstract class BroadcastReceiver {
private boolean mAbortBroadcast;
private boolean mDebugUnregister;
private boolean mOrderedHint;
private boolean mInitialStickyHint;
}

View File

@@ -28,6 +28,6 @@ import android.os.Bundle;
*/
oneway interface IIntentReceiver {
void performReceive(in Intent intent, int resultCode,
String data, in Bundle extras, boolean ordered);
String data, in Bundle extras, boolean ordered, boolean sticky);
}

View File

@@ -113,7 +113,7 @@ public class IntentSender implements Parcelable {
mHandler = handler;
}
public void performReceive(Intent intent, int resultCode,
String data, Bundle extras, boolean serialized) {
String data, Bundle extras, boolean serialized, boolean sticky) {
mIntent = intent;
mResultCode = resultCode;
mResultData = data;