Home | History | Annotate | Download | only in wm
      1 /*
      2  * Copyright (C) 2016 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 android.server.wm;
     18 
     19 import static android.app.ActivityTaskManager.INVALID_STACK_ID;
     20 import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
     21 import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
     22 import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY;
     23 import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
     24 import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
     25 import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY;
     26 import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
     27 import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;
     28 import static android.server.wm.ActivityManagerState.STATE_PAUSED;
     29 import static android.server.wm.ActivityManagerState.STATE_RESUMED;
     30 import static android.server.wm.ActivityManagerState.STATE_STOPPED;
     31 import static android.server.wm.UiDeviceUtils.pressBackButton;
     32 import static android.server.wm.UiDeviceUtils.pressHomeButton;
     33 import static android.server.wm.VirtualDisplayHelper.waitForDefaultDisplayState;
     34 import static android.server.wm.app.Components.ALT_LAUNCHING_ACTIVITY;
     35 import static android.server.wm.app.Components.ALWAYS_FOCUSABLE_PIP_ACTIVITY;
     36 import static android.server.wm.app.Components.BROADCAST_RECEIVER_ACTIVITY;
     37 import static android.server.wm.app.Components.DOCKED_ACTIVITY;
     38 import static android.server.wm.app.Components.LAUNCHING_ACTIVITY;
     39 import static android.server.wm.app.Components.LAUNCH_PIP_ON_PIP_ACTIVITY;
     40 import static android.server.wm.app.Components.MOVE_TASK_TO_BACK_ACTIVITY;
     41 import static android.server.wm.app.Components.MoveTaskToBackActivity.EXTRA_FINISH_POINT;
     42 import static android.server.wm.app.Components.MoveTaskToBackActivity.FINISH_POINT_ON_PAUSE;
     43 import static android.server.wm.app.Components.MoveTaskToBackActivity.FINISH_POINT_ON_STOP;
     44 import static android.server.wm.app.Components.NO_HISTORY_ACTIVITY;
     45 import static android.server.wm.app.Components.SWIPE_REFRESH_ACTIVITY;
     46 import static android.server.wm.app.Components.TEST_ACTIVITY;
     47 import static android.server.wm.app.Components.TRANSLUCENT_ACTIVITY;
     48 import static android.server.wm.app.Components.TURN_SCREEN_ON_ACTIVITY;
     49 import static android.server.wm.app.Components.TURN_SCREEN_ON_ATTR_ACTIVITY;
     50 import static android.server.wm.app.Components.TURN_SCREEN_ON_ATTR_REMOVE_ATTR_ACTIVITY;
     51 import static android.server.wm.app.Components.TURN_SCREEN_ON_SHOW_ON_LOCK_ACTIVITY;
     52 import static android.server.wm.app.Components.TURN_SCREEN_ON_SINGLE_TASK_ACTIVITY;
     53 import static android.server.wm.app.Components.TURN_SCREEN_ON_WITH_RELAYOUT_ACTIVITY;
     54 import static android.view.Display.DEFAULT_DISPLAY;
     55 
     56 import static org.junit.Assert.assertFalse;
     57 import static org.junit.Assert.assertNotEquals;
     58 import static org.junit.Assert.assertTrue;
     59 import static org.junit.Assume.assumeTrue;
     60 
     61 import android.platform.test.annotations.Presubmit;
     62 
     63 import androidx.test.filters.FlakyTest;
     64 
     65 import org.junit.Rule;
     66 import org.junit.Test;
     67 
     68 /**
     69  * Build/Install/Run:
     70  *     atest CtsWindowManagerDeviceTestCases:ActivityVisibilityTests
     71  */
     72 @Presubmit
     73 public class ActivityVisibilityTests extends ActivityManagerTestBase {
     74 
     75     @Rule
     76     public final DisableScreenDozeRule mDisableScreenDozeRule = new DisableScreenDozeRule();
     77 
     78     @Test
     79     @FlakyTest(bugId = 110276714)
     80     public void testTranslucentActivityOnTopOfPinnedStack() throws Exception {
     81         if (!supportsPip()) {
     82             return;
     83         }
     84 
     85         executeShellCommand(getAmStartCmdOverHome(LAUNCH_PIP_ON_PIP_ACTIVITY));
     86         mAmWmState.waitForValidState(LAUNCH_PIP_ON_PIP_ACTIVITY);
     87         // NOTE: moving to pinned stack will trigger the pip-on-pip activity to launch the
     88         // translucent activity.
     89         final int stackId = mAmWmState.getAmState().getStackIdByActivity(
     90                 LAUNCH_PIP_ON_PIP_ACTIVITY);
     91 
     92         assertNotEquals(stackId, INVALID_STACK_ID);
     93         moveTopActivityToPinnedStack(stackId);
     94         mAmWmState.waitForValidState(
     95                 new WaitForValidActivityState.Builder(ALWAYS_FOCUSABLE_PIP_ACTIVITY)
     96                         .setWindowingMode(WINDOWING_MODE_PINNED)
     97                         .setActivityType(ACTIVITY_TYPE_STANDARD)
     98                         .build());
     99 
    100         mAmWmState.assertFrontStack("Pinned stack must be the front stack.",
    101                 WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD);
    102         mAmWmState.assertVisibility(LAUNCH_PIP_ON_PIP_ACTIVITY, true);
    103         mAmWmState.assertVisibility(ALWAYS_FOCUSABLE_PIP_ACTIVITY, true);
    104     }
    105 
    106     /**
    107      * Asserts that the home activity is visible when a translucent activity is launched in the
    108      * fullscreen stack over the home activity.
    109      */
    110     @Test
    111     public void testTranslucentActivityOnTopOfHome() throws Exception {
    112         if (!hasHomeScreen()) {
    113             return;
    114         }
    115 
    116         launchHomeActivity();
    117         launchActivity(ALWAYS_FOCUSABLE_PIP_ACTIVITY);
    118 
    119         mAmWmState.assertFrontStack("Fullscreen stack must be the front stack.",
    120                 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
    121         mAmWmState.assertVisibility(ALWAYS_FOCUSABLE_PIP_ACTIVITY, true);
    122         mAmWmState.assertHomeActivityVisible(true);
    123     }
    124 
    125     /**
    126      * Assert that the home activity is visible if a task that was launched from home is pinned
    127      * and also assert the next task in the fullscreen stack isn't visible.
    128      */
    129     @Test
    130     public void testHomeVisibleOnActivityTaskPinned() throws Exception {
    131         if (!supportsPip()) {
    132             return;
    133         }
    134 
    135         launchHomeActivity();
    136         launchActivity(TEST_ACTIVITY);
    137         launchHomeActivity();
    138         launchActivity(ALWAYS_FOCUSABLE_PIP_ACTIVITY);
    139         final int stackId = mAmWmState.getAmState().getStackIdByActivity(
    140                 ALWAYS_FOCUSABLE_PIP_ACTIVITY);
    141 
    142         assertNotEquals(stackId, INVALID_STACK_ID);
    143         moveTopActivityToPinnedStack(stackId);
    144         mAmWmState.waitForValidState(
    145                 new WaitForValidActivityState.Builder(ALWAYS_FOCUSABLE_PIP_ACTIVITY)
    146                         .setWindowingMode(WINDOWING_MODE_PINNED)
    147                         .setActivityType(ACTIVITY_TYPE_STANDARD)
    148                         .build());
    149 
    150         mAmWmState.assertVisibility(ALWAYS_FOCUSABLE_PIP_ACTIVITY, true);
    151         mAmWmState.assertVisibility(TEST_ACTIVITY, false);
    152         mAmWmState.assertHomeActivityVisible(true);
    153     }
    154 
    155     @Test
    156     public void testTranslucentActivityOverDockedStack() throws Exception {
    157         if (!supportsSplitScreenMultiWindow()) {
    158             // Skipping test: no multi-window support
    159             return;
    160         }
    161 
    162         launchActivitiesInSplitScreen(
    163                 getLaunchActivityBuilder().setTargetActivity(DOCKED_ACTIVITY),
    164                 getLaunchActivityBuilder().setTargetActivity(TEST_ACTIVITY));
    165         launchActivity(TRANSLUCENT_ACTIVITY, WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
    166         mAmWmState.computeState(false /* compareTaskAndStackBounds */,
    167                 new WaitForValidActivityState(TEST_ACTIVITY),
    168                 new WaitForValidActivityState(DOCKED_ACTIVITY),
    169                 new WaitForValidActivityState(TRANSLUCENT_ACTIVITY));
    170         mAmWmState.assertContainsStack("Must contain fullscreen stack.",
    171                 WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_STANDARD);
    172         mAmWmState.assertContainsStack("Must contain docked stack.",
    173                 WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD);
    174         mAmWmState.assertVisibility(DOCKED_ACTIVITY, true);
    175         mAmWmState.assertVisibility(TEST_ACTIVITY, true);
    176         mAmWmState.assertVisibility(TRANSLUCENT_ACTIVITY, true);
    177     }
    178 
    179     @Test
    180     @FlakyTest(bugId = 110276714)
    181     public void testTurnScreenOnActivity() throws Exception {
    182         try (final LockScreenSession lockScreenSession = new LockScreenSession()) {
    183             lockScreenSession.sleepDevice();
    184             launchActivity(TURN_SCREEN_ON_ACTIVITY);
    185 
    186             mAmWmState.assertVisibility(TURN_SCREEN_ON_ACTIVITY, true);
    187             assertTrue("Display turns on", isDisplayOn(DEFAULT_DISPLAY));
    188         }
    189     }
    190 
    191     @Test
    192     @FlakyTest(bugId = 110276714)
    193     public void testFinishActivityInNonFocusedStack() throws Exception {
    194         if (!supportsSplitScreenMultiWindow()) {
    195             // Skipping test: no multi-window support
    196             return;
    197         }
    198 
    199         // Launch two activities in docked stack.
    200         launchActivityInSplitScreenWithRecents(LAUNCHING_ACTIVITY);
    201         getLaunchActivityBuilder()
    202                 .setTargetActivity(BROADCAST_RECEIVER_ACTIVITY)
    203                 .setWaitForLaunched(true)
    204                 .execute();
    205         mAmWmState.assertVisibility(BROADCAST_RECEIVER_ACTIVITY, true);
    206         // Launch something to fullscreen stack to make it focused.
    207         launchActivity(TEST_ACTIVITY, WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY);
    208         mAmWmState.assertVisibility(TEST_ACTIVITY, true);
    209         // Finish activity in non-focused (docked) stack.
    210         mBroadcastActionTrigger.finishBroadcastReceiverActivity();
    211 
    212         mAmWmState.waitForActivityState(LAUNCHING_ACTIVITY, STATE_PAUSED);
    213         mAmWmState.waitForAllExitingWindows();
    214 
    215         mAmWmState.computeState(LAUNCHING_ACTIVITY);
    216         mAmWmState.assertVisibility(LAUNCHING_ACTIVITY, true);
    217         mAmWmState.assertNotExist(BROADCAST_RECEIVER_ACTIVITY);
    218     }
    219 
    220     @Test
    221     public void testLaunchTaskOnHome() {
    222         if (!hasHomeScreen()) {
    223             return;
    224         }
    225 
    226         getLaunchActivityBuilder().setTargetActivity(BROADCAST_RECEIVER_ACTIVITY)
    227                 .setIntentFlags(FLAG_ACTIVITY_NEW_TASK).execute();
    228 
    229         getLaunchActivityBuilder().setTargetActivity(BROADCAST_RECEIVER_ACTIVITY)
    230                 .setIntentFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME).execute();
    231 
    232         mBroadcastActionTrigger.finishBroadcastReceiverActivity();
    233         mAmWmState.waitForHomeActivityVisible();
    234         mAmWmState.assertHomeActivityVisible(true);
    235     }
    236 
    237     @Test
    238     @FlakyTest
    239     public void testFinishActivityWithMoveTaskToBackAfterPause() throws Exception {
    240         performFinishActivityWithMoveTaskToBack(FINISH_POINT_ON_PAUSE);
    241     }
    242 
    243     @Test
    244     @FlakyTest
    245     public void testFinishActivityWithMoveTaskToBackAfterStop() throws Exception {
    246         performFinishActivityWithMoveTaskToBack(FINISH_POINT_ON_STOP);
    247     }
    248 
    249     private void performFinishActivityWithMoveTaskToBack(String finishPoint) throws Exception {
    250         // Make sure home activity is visible.
    251         launchHomeActivity();
    252         if (hasHomeScreen()) {
    253             mAmWmState.assertHomeActivityVisible(true /* visible */);
    254         }
    255 
    256         // Launch an activity that calls "moveTaskToBack" to finish itself.
    257         launchActivity(MOVE_TASK_TO_BACK_ACTIVITY, EXTRA_FINISH_POINT, finishPoint);
    258         mAmWmState.assertVisibility(MOVE_TASK_TO_BACK_ACTIVITY, true);
    259 
    260         // Launch a different activity on top.
    261         launchActivity(BROADCAST_RECEIVER_ACTIVITY);
    262         mAmWmState.waitForActivityState(BROADCAST_RECEIVER_ACTIVITY, STATE_RESUMED);
    263         mAmWmState.waitForActivityState(MOVE_TASK_TO_BACK_ACTIVITY,STATE_STOPPED);
    264         final boolean shouldBeVisible =
    265                 !mAmWmState.getAmState().isBehindOpaqueActivities(MOVE_TASK_TO_BACK_ACTIVITY);
    266         mAmWmState.assertVisibility(MOVE_TASK_TO_BACK_ACTIVITY, shouldBeVisible);
    267         mAmWmState.assertVisibility(BROADCAST_RECEIVER_ACTIVITY, true);
    268 
    269         // Finish the top-most activity.
    270         mBroadcastActionTrigger.finishBroadcastReceiverActivity();
    271         //TODO: BUG: MoveTaskToBackActivity returns to the top of the stack when
    272         // BroadcastActivity finishes, so homeActivity is not visible afterwards
    273 
    274         // Home must be visible.
    275         if (hasHomeScreen()) {
    276             mAmWmState.waitForHomeActivityVisible();
    277             mAmWmState.assertHomeActivityVisible(true /* visible */);
    278         }
    279     }
    280 
    281     /**
    282      * Asserts that launching between reorder to front activities exhibits the correct backstack
    283      * behavior.
    284      */
    285     @Test
    286     public void testReorderToFrontBackstack() throws Exception {
    287         // Start with home on top
    288         launchHomeActivity();
    289         if (hasHomeScreen()) {
    290             mAmWmState.assertHomeActivityVisible(true /* visible */);
    291         }
    292 
    293         // Launch the launching activity to the foreground
    294         launchActivity(LAUNCHING_ACTIVITY);
    295 
    296         // Launch the alternate launching activity from launching activity with reorder to front.
    297         getLaunchActivityBuilder().setTargetActivity(ALT_LAUNCHING_ACTIVITY)
    298                 .setReorderToFront(true).execute();
    299 
    300         // Launch the launching activity from the alternate launching activity with reorder to
    301         // front.
    302         getLaunchActivityBuilder().setTargetActivity(LAUNCHING_ACTIVITY)
    303                 .setLaunchingActivity(ALT_LAUNCHING_ACTIVITY)
    304                 .setReorderToFront(true)
    305                 .execute();
    306 
    307         // Press back
    308         pressBackButton();
    309 
    310         mAmWmState.waitForValidState(ALT_LAUNCHING_ACTIVITY);
    311 
    312         // Ensure the alternate launching activity is in focus
    313         mAmWmState.assertFocusedActivity("Alt Launching Activity must be focused",
    314                 ALT_LAUNCHING_ACTIVITY);
    315     }
    316 
    317     /**
    318      * Asserts that the activity focus and history is preserved moving between the activity and
    319      * home stack.
    320      */
    321     @Test
    322     public void testReorderToFrontChangingStack() throws Exception {
    323         // Start with home on top
    324         launchHomeActivity();
    325         if (hasHomeScreen()) {
    326             mAmWmState.assertHomeActivityVisible(true /* visible */);
    327         }
    328 
    329         // Launch the launching activity to the foreground
    330         launchActivity(LAUNCHING_ACTIVITY);
    331 
    332         // Launch the alternate launching activity from launching activity with reorder to front.
    333         getLaunchActivityBuilder().setTargetActivity(ALT_LAUNCHING_ACTIVITY)
    334                 .setReorderToFront(true)
    335                 .execute();
    336 
    337         // Return home
    338         launchHomeActivity();
    339         if (hasHomeScreen()) {
    340             mAmWmState.assertHomeActivityVisible(true /* visible */);
    341         }
    342         // Launch the launching activity from the alternate launching activity with reorder to
    343         // front.
    344 
    345         // Bring launching activity back to the foreground
    346         launchActivityNoWait(LAUNCHING_ACTIVITY);
    347         // Wait for the most front activity of the task.
    348         mAmWmState.waitForValidState(ALT_LAUNCHING_ACTIVITY);
    349 
    350         // Ensure the alternate launching activity is still in focus.
    351         mAmWmState.assertFocusedActivity("Alt Launching Activity must be focused",
    352                 ALT_LAUNCHING_ACTIVITY);
    353 
    354         pressBackButton();
    355 
    356         // Wait for the bottom activity back to the foreground.
    357         mAmWmState.waitForValidState(LAUNCHING_ACTIVITY);
    358 
    359         // Ensure launching activity was brought forward.
    360         mAmWmState.assertFocusedActivity("Launching Activity must be focused",
    361                 LAUNCHING_ACTIVITY);
    362     }
    363 
    364     /**
    365      * Asserts that a nohistory activity is stopped and removed immediately after a resumed activity
    366      * above becomes visible and does not idle.
    367      */
    368     @Test
    369     public void testNoHistoryActivityFinishedResumedActivityNotIdle() throws Exception {
    370         if (!hasHomeScreen()) {
    371             return;
    372         }
    373 
    374         // Start with home on top
    375         launchHomeActivity();
    376 
    377         // Launch no history activity
    378         launchActivity(NO_HISTORY_ACTIVITY);
    379 
    380         // Launch an activity with a swipe refresh layout configured to prevent idle.
    381         launchActivity(SWIPE_REFRESH_ACTIVITY);
    382 
    383         pressBackButton();
    384         mAmWmState.waitForHomeActivityVisible();
    385         mAmWmState.assertHomeActivityVisible(true);
    386     }
    387 
    388     @Test
    389     public void testTurnScreenOnAttrNoLockScreen() throws Exception {
    390         try (final LockScreenSession lockScreenSession = new LockScreenSession()) {
    391             lockScreenSession.disableLockScreen()
    392                     .sleepDevice();
    393             separateTestJournal();
    394             launchActivity(TURN_SCREEN_ON_ATTR_ACTIVITY);
    395             mAmWmState.assertVisibility(TURN_SCREEN_ON_ATTR_ACTIVITY, true);
    396             assertTrue("Display turns on", isDisplayOn(DEFAULT_DISPLAY));
    397             assertSingleLaunch(TURN_SCREEN_ON_ATTR_ACTIVITY);
    398         }
    399     }
    400 
    401     @Test
    402     public void testTurnScreenOnAttrWithLockScreen() throws Exception {
    403         assumeTrue(supportsSecureLock());
    404 
    405         try (final LockScreenSession lockScreenSession = new LockScreenSession()) {
    406             lockScreenSession.setLockCredential()
    407                     .sleepDevice();
    408             separateTestJournal();
    409             launchActivityNoWait(TURN_SCREEN_ON_ATTR_ACTIVITY);
    410             // Wait for the activity stopped because lock screen prevent showing the activity.
    411             mAmWmState.waitForActivityState(TURN_SCREEN_ON_ATTR_ACTIVITY, STATE_STOPPED);
    412             assertFalse("Display keeps off", isDisplayOn(DEFAULT_DISPLAY));
    413             assertSingleLaunchAndStop(TURN_SCREEN_ON_ATTR_ACTIVITY);
    414         }
    415     }
    416 
    417     @Test
    418     public void testTurnScreenOnShowOnLockAttr() throws Exception {
    419         try (final LockScreenSession lockScreenSession = new LockScreenSession()) {
    420             lockScreenSession.sleepDevice();
    421             mAmWmState.waitForAllStoppedActivities();
    422             separateTestJournal();
    423             launchActivity(TURN_SCREEN_ON_SHOW_ON_LOCK_ACTIVITY);
    424             mAmWmState.assertVisibility(TURN_SCREEN_ON_SHOW_ON_LOCK_ACTIVITY, true);
    425             assertTrue("Display turns on", isDisplayOn(DEFAULT_DISPLAY));
    426             assertSingleLaunch(TURN_SCREEN_ON_SHOW_ON_LOCK_ACTIVITY);
    427         }
    428     }
    429 
    430     @Test
    431     @FlakyTest
    432     public void testTurnScreenOnAttrRemove() throws Exception {
    433         try (final LockScreenSession lockScreenSession = new LockScreenSession()) {
    434             lockScreenSession.sleepDevice();
    435             mAmWmState.waitForAllStoppedActivities();
    436             separateTestJournal();
    437             launchActivity(TURN_SCREEN_ON_ATTR_REMOVE_ATTR_ACTIVITY);
    438             assertTrue("Display turns on", isDisplayOn(DEFAULT_DISPLAY));
    439             assertSingleLaunch(TURN_SCREEN_ON_ATTR_REMOVE_ATTR_ACTIVITY);
    440 
    441             lockScreenSession.sleepDevice();
    442             mAmWmState.waitForAllStoppedActivities();
    443             separateTestJournal();
    444             launchActivity(TURN_SCREEN_ON_ATTR_REMOVE_ATTR_ACTIVITY);
    445             mAmWmState.waitForActivityState(TURN_SCREEN_ON_ATTR_REMOVE_ATTR_ACTIVITY,
    446                 STATE_STOPPED);
    447             // Display should keep off, because setTurnScreenOn(false) has been called at
    448             // {@link TURN_SCREEN_ON_ATTR_REMOVE_ATTR_ACTIVITY}'s onStop.
    449             assertFalse("Display keeps off", isDisplayOn(DEFAULT_DISPLAY));
    450             assertSingleStartAndStop(TURN_SCREEN_ON_ATTR_REMOVE_ATTR_ACTIVITY);
    451         }
    452     }
    453 
    454     @Test
    455     public void testTurnScreenOnSingleTask() throws Exception {
    456         try (final LockScreenSession lockScreenSession = new LockScreenSession()) {
    457             lockScreenSession.sleepDevice();
    458             separateTestJournal();
    459             launchActivity(TURN_SCREEN_ON_SINGLE_TASK_ACTIVITY);
    460             mAmWmState.assertVisibility(TURN_SCREEN_ON_SINGLE_TASK_ACTIVITY, true);
    461             assertTrue("Display turns on", isDisplayOn(DEFAULT_DISPLAY));
    462             assertSingleLaunch(TURN_SCREEN_ON_SINGLE_TASK_ACTIVITY);
    463 
    464             lockScreenSession.sleepDevice();
    465             // We should make sure test activity stopped to prevent a false alarm stop state
    466             // included in the lifecycle count.
    467             waitAndAssertActivityState(TURN_SCREEN_ON_SINGLE_TASK_ACTIVITY, STATE_STOPPED,
    468                     "Activity should be stopped");
    469             separateTestJournal();
    470             launchActivity(TURN_SCREEN_ON_SINGLE_TASK_ACTIVITY);
    471             mAmWmState.assertVisibility(TURN_SCREEN_ON_SINGLE_TASK_ACTIVITY, true);
    472             // Wait more for display state change since turning the display ON may take longer
    473             // and reported after the activity launch.
    474             waitForDefaultDisplayState(true /* wantOn */);
    475             assertTrue("Display turns on", isDisplayOn(DEFAULT_DISPLAY));
    476             assertSingleStart(TURN_SCREEN_ON_SINGLE_TASK_ACTIVITY);
    477         }
    478     }
    479 
    480     @Test
    481     public void testTurnScreenOnActivity_withRelayout() throws Exception {
    482         try (final LockScreenSession lockScreenSession = new LockScreenSession()) {
    483             lockScreenSession.sleepDevice();
    484             launchActivity(TURN_SCREEN_ON_WITH_RELAYOUT_ACTIVITY);
    485             mAmWmState.assertVisibility(TURN_SCREEN_ON_WITH_RELAYOUT_ACTIVITY, true);
    486 
    487             lockScreenSession.sleepDevice();
    488             waitAndAssertActivityState(TURN_SCREEN_ON_WITH_RELAYOUT_ACTIVITY, STATE_STOPPED,
    489                     "Activity should be stopped");
    490             assertFalse("Display keeps off", isDisplayOn(DEFAULT_DISPLAY));
    491         }
    492     }
    493 
    494     @Test
    495     public void testGoingHomeMultipleTimes() throws Exception {
    496         for (int i = 0; i < 10; i++) {
    497             // Start activity normally
    498             launchActivityOnDisplay(TEST_ACTIVITY, DEFAULT_DISPLAY);
    499             waitAndAssertTopResumedActivity(TEST_ACTIVITY, DEFAULT_DISPLAY,
    500                     "Activity launched on default display must be focused");
    501 
    502             // Press home button
    503             launchHomeActivity();
    504 
    505             mAmWmState.assertHomeActivityVisible(true);
    506             waitAndAssertActivityState(TEST_ACTIVITY, STATE_STOPPED,
    507                     "Activity should become STOPPED");
    508             mAmWmState.assertVisibility(TEST_ACTIVITY, false);
    509         }
    510     }
    511 
    512     @Test
    513     public void testPressingHomeButtonMultipleTimes() throws Exception {
    514         for (int i = 0; i < 10; i++) {
    515             // Start activity normally
    516             launchActivityOnDisplay(TEST_ACTIVITY, DEFAULT_DISPLAY);
    517             waitAndAssertTopResumedActivity(TEST_ACTIVITY, DEFAULT_DISPLAY,
    518                     "Activity launched on default display must be focused");
    519 
    520             // Press home button
    521             pressHomeButton();
    522 
    523             // Wait and assert home and activity states
    524             mAmWmState.waitForHomeActivityVisible();
    525             mAmWmState.assertHomeActivityVisible(true);
    526             waitAndAssertActivityState(TEST_ACTIVITY, STATE_STOPPED,
    527                     "Activity should become STOPPED");
    528             mAmWmState.assertVisibility(TEST_ACTIVITY, false);
    529         }
    530     }
    531 
    532     @Test
    533     public void testPressingHomeButtonMultipleTimesQuick() throws Exception {
    534         for (int i = 0; i < 10; i++) {
    535             // Start activity normally
    536             launchActivityOnDisplay(TEST_ACTIVITY, DEFAULT_DISPLAY);
    537 
    538             // Press home button
    539             pressHomeButton();
    540             mAmWmState.waitForHomeActivityVisible();
    541             mAmWmState.assertHomeActivityVisible(true);
    542         }
    543         waitAndAssertActivityState(TEST_ACTIVITY, STATE_STOPPED,
    544                 "Activity should become STOPPED");
    545         mAmWmState.assertVisibility(TEST_ACTIVITY, false);
    546     }
    547 }
    548