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

Commit 1ce208cd authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Android (Google) Code Review
Browse files

Merge "Avoid replacing receivers with ones from the same BroadcastRecord." into main

parents 33674d8d 1d36edb6
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -353,8 +353,7 @@ class BroadcastProcessQueue {
            // If we come across the record that's being enqueued in the queue, then that means
            // we already enqueued it for a receiver in this process and trying to insert a new
            // one past this could create priority inversion in the queue, so bail out.
            if (record == testRecord && record.blockedUntilBeyondCount[recordIndex]
                    > testRecord.blockedUntilBeyondCount[testRecordIndex]) {
            if (record == testRecord) {
                break;
            }
            if ((record.callingUid == testRecord.callingUid)
+27 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import android.content.IIntentReceiver;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Binder;
import android.os.Bundle;
import android.os.DeadObjectException;
@@ -1877,6 +1878,32 @@ public class BroadcastQueueTest extends BaseBroadcastQueueTest {
        verifyScheduleRegisteredReceiver(times(1), receiverBlueApp, airplane);
    }

    @Test
    public void testReplacePending_withSingletonReceiver() throws Exception {
        final ProcessRecord callerApp = makeActiveProcessRecord(PACKAGE_PHONE);
        final ProcessRecord systemApp = makeActiveProcessRecord(PACKAGE_ANDROID, PROCESS_SYSTEM);

        final Intent airplane = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED)
                .addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);

        final ResolveInfo systemReceiverA = makeManifestReceiver(PACKAGE_ANDROID, PROCESS_SYSTEM,
                CLASS_BLUE, USER_SYSTEM);
        final ResolveInfo systemReceiverB = makeManifestReceiver(PACKAGE_ANDROID, PROCESS_SYSTEM,
                CLASS_BLUE, USER_GUEST);

        enqueueBroadcast(makeBroadcastRecord(airplane, callerApp, List.of(
                systemReceiverA, systemReceiverB)));

        assertEquals("Unexpected userId for receiverA", USER_SYSTEM,
                UserHandle.getUserId(systemReceiverA.activityInfo.applicationInfo.uid));
        assertEquals("Unexpected userId for receiverB", USER_SYSTEM,
                UserHandle.getUserId(systemReceiverB.activityInfo.applicationInfo.uid));

        waitForIdle();

        verifyScheduleReceiver(times(2), systemApp, airplane);
    }

    @Test
    public void testIdleAndBarrier() throws Exception {
        final ProcessRecord callerApp = makeActiveProcessRecord(PACKAGE_RED);