diff options
| author | 2023-08-16 11:15:43 -0700 | |
|---|---|---|
| committer | 2023-08-16 11:15:43 -0700 | |
| commit | ff171e9fadb3158fe6aff4ea8cdebc8c808250f2 (patch) | |
| tree | 04b427ad178bfdbcdf7b0f210abac635f66054ae | |
| parent | b9416234b7c5313a942a19420f85fb41fc0ed8c9 (diff) | |
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
| -rw-r--r-- | services/tests/wmtests/src/com/android/server/wm/TaskStackChangedListenerTest.java | 50 | ||||
| -rw-r--r-- | services/tests/wmtests/src/com/android/server/wm/utils/CommonUtils.java | 34 |
2 files changed, 65 insertions, 19 deletions
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskStackChangedListenerTest.java b/services/tests/wmtests/src/com/android/server/wm/TaskStackChangedListenerTest.java index 16c38ac9fac3..08438c8cca5d 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TaskStackChangedListenerTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/TaskStackChangedListenerTest.java @@ -354,25 +354,37 @@ public class TaskStackChangedListenerTest { } }); - 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]); - - activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); - taskIdAndOrientation = waitForResult(taskIdAndOrientationQueue, - candidate -> candidate[0] == activity.getTaskId()); - assertNotNull(taskIdAndOrientation); - assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT, taskIdAndOrientation[1]); - - activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); - taskIdAndOrientation = waitForResult(taskIdAndOrientationQueue, - candidate -> candidate[0] == activity.getTaskId()); - assertNotNull(taskIdAndOrientation); - assertEquals(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED, taskIdAndOrientation[1]); + 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]); + + activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); + taskIdAndOrientation = waitForResult(taskIdAndOrientationQueue, + candidate -> candidate[0] == activity.getTaskId()); + assertNotNull(taskIdAndOrientation); + assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT, taskIdAndOrientation[1]); + + activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); + taskIdAndOrientation = waitForResult(taskIdAndOrientationQueue, + candidate -> candidate[0] == activity.getTaskId()); + assertNotNull(taskIdAndOrientation); + assertEquals(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED, taskIdAndOrientation[1]); + } finally { + CommonUtils.setIgnoreOrientationRequest( + Display.DEFAULT_DISPLAY, isIgnoringOrientationRequest); + } } /** diff --git a/services/tests/wmtests/src/com/android/server/wm/utils/CommonUtils.java b/services/tests/wmtests/src/com/android/server/wm/utils/CommonUtils.java index ed23296785c5..bfbba5f33f6c 100644 --- a/services/tests/wmtests/src/com/android/server/wm/utils/CommonUtils.java +++ b/services/tests/wmtests/src/com/android/server/wm/utils/CommonUtils.java @@ -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( |