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

Commit 68d881cf authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

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

Tell the broadcast receiver whether it is getting an initial sticky value,
so it will be quiet about attempts to do ordered broadcast stuff.

Note that the original bug being reported was not actually a crash, just
an error log.  So all we are doing here is making the log quieter.

Change-Id: Iaf1b718d82093ec1197142410a64feff47eb3859
parent 71060f29
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -27787,6 +27787,28 @@
<parameter name="makeMap" type="boolean">
</parameter>
</method>
<method name="isInitialStickyBroadcast"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="isOrderedBroadcast"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="onReceive"
 return="void"
 abstract="true"
+2 −1
Original line number Diff line number Diff line
@@ -340,7 +340,8 @@ public class Am {
        private boolean mFinished = false;

        public synchronized void performReceive(
                Intent intent, int rc, String data, Bundle ext, boolean ord) {
                Intent intent, int rc, String data, Bundle ext, boolean ord,
                boolean sticky) {
            String line = "Broadcast completed: result=" + rc;
            if (data != null) line = line + ", data=\"" + data + "\"";
            if (ext != null) line = line + ", extras: " + ext;
+10 −6
Original line number Diff line number Diff line
@@ -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() {
+4 −2
Original line number Diff line number Diff line
@@ -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();
+1 −1
Original line number Diff line number Diff line
@@ -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;
Loading