1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.pixel.tests; 18 19 import android.os.SystemClock; 20 21 import androidx.test.ext.junit.runners.AndroidJUnit4; 22 23 import org.junit.After; 24 import org.junit.Assert; 25 import org.junit.Test; 26 import org.junit.runner.RunWith; 27 28 @RunWith(AndroidJUnit4.class) 29 public class AppLaunchRotateTest extends PixelAppCompatTestBase { 30 private static final String ROTATE_LANDSCAPE = 31 "content insert --uri content://settings/system" 32 + " --bind name:s:user_rotation --bind value:i:1"; 33 private static final String ROTATE_PORTRAIT = 34 "content insert --uri content://settings/system" 35 + " --bind name:s:user_rotation --bind value:i:0"; 36 private static final int LAUNCH_TIME_MS = 15000; // 15 seconds 37 private static final long WAIT_ONE_SECOND_IN_MS = 1000; 38 39 @Override 40 @After tearDown()41 public void tearDown() throws Exception { 42 super.tearDown(); 43 getUiDevice().unfreezeRotation(); 44 } 45 46 @Test testRotateDevice()47 public void testRotateDevice() throws Exception { 48 launchAndWaitAppOpen(LAUNCH_TIME_MS); 49 50 // Turn off the automatic rotation 51 getUiDevice().freezeRotation(); 52 getUiDevice().executeShellCommand(ROTATE_PORTRAIT); 53 SystemClock.sleep(WAIT_ONE_SECOND_IN_MS); 54 getDeviceUtils().takeScreenshot(getPackage(), "set_portrait_mode"); 55 Assert.assertTrue( 56 "Screen should be in portrait mode", getUiDevice().isNaturalOrientation()); 57 58 getUiDevice().executeShellCommand(ROTATE_LANDSCAPE); 59 SystemClock.sleep(WAIT_ONE_SECOND_IN_MS); 60 getDeviceUtils().takeScreenshot(getPackage(), "rotate_landscape"); 61 Assert.assertFalse( 62 "Screen should be in landscape mode", getUiDevice().isNaturalOrientation()); 63 64 getUiDevice().executeShellCommand(ROTATE_PORTRAIT); 65 SystemClock.sleep(WAIT_ONE_SECOND_IN_MS); 66 getDeviceUtils().takeScreenshot(getPackage(), "rotate_portrait"); 67 Assert.assertTrue( 68 "Screen should be in portrait mode", getUiDevice().isNaturalOrientation()); 69 } 70 } 71