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

Commit 3789c092 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Wait for broadcast barrier to speed up tests.

For tests interesting in knowing if a broadcast has been sent, we
have a new "am wait-for-broadcast-barrier" command which can be
used to confirm that any broadcasts enqueued before that instant in
time have been scheduled for delivery.

Adding this "barrier" helps speed up tests and decrease flakiness.

Bug: 253906105
Test: TH
Change-Id: I8feee75102d353980d6ec94068f60fe00de429d9
parent 9e717f1b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -772,6 +772,7 @@ interface IActivityManager {

    /** Blocks until all broadcast queues become idle. */
    void waitForBroadcastIdle();
    void waitForBroadcastBarrier();

    /** Delays delivering broadcasts to the specified package. */
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.DUMP)")
+3 −0
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ import androidx.test.InstrumentationRegistry;
import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.compatibility.common.util.SystemUtil;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -96,6 +98,7 @@ abstract class AbstractCrossUserContentResolverTest {
        mContext.registerReceiverAsUser(receiver, UserHandle.of(mCrossUserId),
                new IntentFilter(Intent.ACTION_USER_UNLOCKED), null, null);
        ActivityManager.getService().startUserInBackground(mCrossUserId);
        SystemUtil.runShellCommand("am wait-for-broadcast-barrier");

        try {
            if (!latch.await(TIMEOUT_USER_UNLOCK_SEC, TimeUnit.SECONDS)) {
+5 −0
Original line number Diff line number Diff line
@@ -18577,6 +18577,11 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
    }
    @Override
    public void waitForBroadcastBarrier() {
        waitForBroadcastBarrier(/* printWriter= */ null, false);
    }
    public void waitForBroadcastBarrier(@Nullable PrintWriter pw, boolean flushBroadcastLoopers) {
        enforceCallingPermission(permission.DUMP, "waitForBroadcastBarrier()");
        if (flushBroadcastLoopers) {