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

Commit 995f0e41 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Specify reverse rotation config for unit test

Some devices may use config_reverseDefaultRotation=true, which
doesn't match the assumption of the test that calculates the
bounds depending on which side the display cutout is on.

Fix: 296070744
Fix: 295867717
Test: SizeCompatTests#testLaunchWithFixedRotationTransform

Change-Id: Ie90e56495fe3b8f20aedc2f063039da907782c64
parent 7b193950
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1880,6 +1880,11 @@ public class SizeCompatTests extends WindowTestsBase {
        final int dh = 2500;
        final int notchHeight = 200;
        setUpApp(new TestDisplayContent.Builder(mAtm, dw, dh).setNotch(notchHeight).build());
        // The test assumes the notch will be at left side when the orientation is landscape.
        if (mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_reverseDefaultRotation)) {
            setReverseDefaultRotation(mActivity.mDisplayContent, false);
        }
        addStatusBar(mActivity.mDisplayContent);

        mActivity.setVisible(false);
+34 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;

import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
@@ -59,6 +60,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;

import android.annotation.IntDef;
@@ -956,6 +958,38 @@ class WindowTestsBase extends SystemServiceTestsBase {
        return testPlayer;
    }

    /** Overrides the behavior of config_reverseDefaultRotation for the given display. */
    void setReverseDefaultRotation(DisplayContent dc, boolean reverse) {
        final DisplayRotation displayRotation = dc.getDisplayRotation();
        if (!Mockito.mockingDetails(displayRotation).isSpy()) {
            spyOn(displayRotation);
        }
        doAnswer(invocation -> {
            invocation.callRealMethod();
            final int w = invocation.getArgument(0);
            final int h = invocation.getArgument(1);
            if (w > h) {
                if (reverse) {
                    displayRotation.mPortraitRotation = Surface.ROTATION_90;
                    displayRotation.mUpsideDownRotation = Surface.ROTATION_270;
                } else {
                    displayRotation.mPortraitRotation = Surface.ROTATION_270;
                    displayRotation.mUpsideDownRotation = Surface.ROTATION_90;
                }
            } else {
                if (reverse) {
                    displayRotation.mLandscapeRotation = Surface.ROTATION_270;
                    displayRotation.mSeascapeRotation = Surface.ROTATION_90;
                } else {
                    displayRotation.mLandscapeRotation = Surface.ROTATION_90;
                    displayRotation.mSeascapeRotation = Surface.ROTATION_270;
                }
            }
            return null;
        }).when(displayRotation).configure(anyInt(), anyInt());
        displayRotation.configure(dc.mBaseDisplayWidth, dc.mBaseDisplayHeight);
    }

    /**
     * Avoids rotating screen disturbed by some conditions. It is usually used for the default
     * display that is not the instance of {@link TestDisplayContent} (it bypasses the conditions).