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

Commit ff171e9f authored by Garfield Tan's avatar Garfield Tan
Browse files

Allow orientation request in testNotifyTaskRequestedOrientationChanged

Disable ignore orientation requests for
testNotifyTaskRequestedOrientationChanged on devices that have it
enabled.

Bug: 295866057
Test: testNotifyTaskRequestedOrientationChanged passed on CF foldable.
Test: ignore orientation request is true after running the test on CF
foldable.

Change-Id: Ic75cfe4fc8e2dc1a59be03655e57f45f570d60c0
parent b9416234
Loading
Loading
Loading
Loading
+31 −19
Original line number Diff line number Diff line
@@ -354,13 +354,21 @@ public class TaskStackChangedListenerTest {
            }
        });

        final boolean isIgnoringOrientationRequest =
                CommonUtils.getIgnoreOrientationRequest(Display.DEFAULT_DISPLAY);
        if (isIgnoringOrientationRequest) {
            CommonUtils.setIgnoreOrientationRequest(Display.DEFAULT_DISPLAY, false);
        }

        try {
            final LandscapeActivity activity =
                    (LandscapeActivity) startTestActivity(LandscapeActivity.class);

            int[] taskIdAndOrientation = waitForResult(taskIdAndOrientationQueue,
                    candidate -> candidate[0] == activity.getTaskId());
            assertNotNull(taskIdAndOrientation);
        assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, taskIdAndOrientation[1]);
            assertEquals(
                    ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, taskIdAndOrientation[1]);

            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
            taskIdAndOrientation = waitForResult(taskIdAndOrientationQueue,
@@ -373,6 +381,10 @@ public class TaskStackChangedListenerTest {
                    candidate -> candidate[0] == activity.getTaskId());
            assertNotNull(taskIdAndOrientation);
            assertEquals(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED, taskIdAndOrientation[1]);
        } finally {
            CommonUtils.setIgnoreOrientationRequest(
                    Display.DEFAULT_DISPLAY, isIgnoringOrientationRequest);
        }
    }

    /**
+34 −0
Original line number Diff line number Diff line
@@ -21,9 +21,12 @@ import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentat
import android.app.Activity;
import android.app.KeyguardManager;
import android.app.UiAutomation;
import android.os.RemoteException;
import android.os.SystemClock;
import android.util.Log;
import android.view.IWindowManager;
import android.view.KeyEvent;
import android.view.WindowManagerGlobal;

import androidx.test.uiautomator.UiDevice;

@@ -48,6 +51,37 @@ public class CommonUtils {
        }
    }

    public static boolean getIgnoreOrientationRequest(int displayId) {
        final UiDevice uiDevice = UiDevice.getInstance(getInstrumentation());
        final String result;
        try {
            result = uiDevice.executeShellCommand("cmd window get-ignore-orientation-request -d "
                    + displayId);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        final String[] tokens = result.split(" ");
        if (tokens.length != 4) {
            throw new RuntimeException("Expecting a result with 4 tokens, but got " + result);
        }

        // The output looks like "ignoreOrientationRequest true for displayId=0"
        return Boolean.parseBoolean(tokens[1]);
    }

    public static void setIgnoreOrientationRequest(
            int displayId, boolean ignoreOrientationRequest) {
        runWithShellPermissionIdentity(() -> {
            final IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
            try {
                wm.setIgnoreOrientationRequest(displayId, ignoreOrientationRequest);
            } catch (RemoteException e) {
                e.rethrowFromSystemServer();
            }
        });
    }

    /** Dismisses the Keyguard if it is locked. */
    public static void dismissKeyguard() {
        final KeyguardManager keyguardManager = getInstrumentation().getContext().getSystemService(