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

Commit 09cced0e authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Reduce flakiness of WmTests

1. Same as I1b2eb77585ba0a1ee936ee921af95e9c2113ec63
   that waits for the completion of Activity#onDestroy.
2. Relax assertion of surfaceChanged count that occasionally
   an additional change may appear if the app updates earlier.

Fix: 293499710
Fix: 294403114
Test: atest TrustedPresentationCallbackTest SurfaceControlTests
Change-Id: I67daae8d17bc647af1d188d229dcfb064911f3b0
parent f98963f3
Loading
Loading
Loading
Loading
+20 −6
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ import androidx.annotation.NonNull;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.server.wm.utils.CommonUtils;

import org.junit.Test;
import org.junit.runner.RunWith;

@@ -131,18 +133,29 @@ public class SurfaceControlTests {
        final Activity activity = instrumentation.startActivitySync(intent);
        final SurfaceView sv = new SurfaceView(activity);
        final AtomicInteger surfaceChangedCount = new AtomicInteger();
        final boolean[] unexpectedTransformHint = new boolean[1];
        instrumentation.runOnMainSync(() -> activity.setContentView(sv));
        sv.getHolder().addCallback(new SurfaceHolder.Callback() {
            int mInitialTransformHint = -1;

            @Override
            public void surfaceCreated(@NonNull SurfaceHolder holder) {
            }
            @Override
            public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width,
                    int height) {
                final int transformHint =
                        sv.getViewRootImpl().getSurfaceControl().getTransformHint();
                if (mInitialTransformHint == -1) {
                    mInitialTransformHint = transformHint;
                } else if (mInitialTransformHint == transformHint) {
                    // For example, the initial hint is from portrait, so the later changes from
                    // landscape should not receive the same hint.
                    unexpectedTransformHint[0] = true;
                }
                surfaceChangedCount.getAndIncrement();
                Log.i("surfaceChanged", "width=" + width + " height=" + height
                        + " getTransformHint="
                        + sv.getViewRootImpl().getSurfaceControl().getTransformHint());
                        + " transformHint=" + transformHint);
            }
            @Override
            public void surfaceDestroyed(@NonNull SurfaceHolder holder) {
@@ -160,7 +173,7 @@ public class SurfaceControlTests {
                .windowConfiguration.getRotation();
        if (rotation == newRotation) {
            // The device might not support requested orientation.
            activity.finishAndRemoveTask();
            CommonUtils.waitUntilActivityRemoved(activity);
            return;
        }
        final int count = surfaceChangedCount.get();
@@ -169,11 +182,12 @@ public class SurfaceControlTests {
        context.startActivity(intent);
        instrumentation.getUiAutomation().syncInputTransactions();
        final int countAfterToFront = count - surfaceChangedCount.get();
        activity.finishAndRemoveTask();
        CommonUtils.waitUntilActivityRemoved(activity);

        // The first count is triggered from creation, so the target number is 2.
        if (count > 2) {
            fail("More than once surfaceChanged for rotation change: " + count);
        if (count > 2 && unexpectedTransformHint[0]) {
            fail("Received transform hint in previous orientation with more than once"
                    + " surfaceChanged for rotation change: " + count);
        }
        if (countAfterToFront > 1) {
            fail("More than once surfaceChanged for app transition with rotation change: "
+8 −0
Original line number Diff line number Diff line
@@ -30,6 +30,9 @@ import android.view.SurfaceControl.TrustedPresentationThresholds;

import androidx.test.ext.junit.rules.ActivityScenarioRule;

import com.android.server.wm.utils.CommonUtils;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -61,6 +64,11 @@ public class TrustedPresentationCallbackTest {
        mActivityRule.getScenario().onActivity(activity -> mActivity = activity);
    }

    @After
    public void tearDown() {
        CommonUtils.waitUntilActivityRemoved(mActivity);
    }

    @Test
    public void testAddTrustedPresentationListenerOnWindow() throws InterruptedException {
        boolean[] results = new boolean[1];