Home | History | Annotate | Download | only in cts
      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.cts;
     18 
     19 import java.lang.Exception;
     20 import java.lang.String;
     21 
     22 public class ActivityManagerPinnedStackTests extends ActivityManagerTestBase {
     23     private static final String PIP_ACTIVITY = "PipActivity";
     24     private static final String AUTO_ENTER_PIP_ACTIVITY = "AutoEnterPipActivity";
     25     private static final String ALWAYS_FOCUSABLE_PIP_ACTIVITY = "AlwaysFocusablePipActivity";
     26     private static final String LAUNCH_INTO_PINNED_STACK_PIP_ACTIVITY =
     27             "LaunchIntoPinnedStackPipActivity";
     28 
     29     public void testEnterPictureInPictureMode() throws Exception {
     30         pinnedStackTester(AUTO_ENTER_PIP_ACTIVITY, AUTO_ENTER_PIP_ACTIVITY, false, false);
     31     }
     32 
     33     public void testMoveTopActivityToPinnedStack() throws Exception {
     34         pinnedStackTester(PIP_ACTIVITY, PIP_ACTIVITY, true, false);
     35     }
     36 
     37     public void testAlwaysFocusablePipActivity() throws Exception {
     38         pinnedStackTester(ALWAYS_FOCUSABLE_PIP_ACTIVITY, ALWAYS_FOCUSABLE_PIP_ACTIVITY, true, true);
     39     }
     40 
     41     public void testLaunchIntoPinnedStack() throws Exception {
     42         pinnedStackTester(
     43                 LAUNCH_INTO_PINNED_STACK_PIP_ACTIVITY, ALWAYS_FOCUSABLE_PIP_ACTIVITY, false, true);
     44     }
     45 
     46     private void pinnedStackTester(String startActivity, String topActivityName,
     47             boolean moveTopToPinnedStack, boolean isFocusable) throws Exception {
     48 
     49         executeShellCommand(getAmStartCmd(startActivity));
     50         if (moveTopToPinnedStack) {
     51             executeShellCommand(AM_MOVE_TOP_ACTIVITY_TO_PINNED_STACK_COMMAND);
     52         }
     53 
     54         mAmWmState.waitForValidState(mDevice, true, new String[] {topActivityName},
     55                 new int[] {PINNED_STACK_ID}, false /* compareTaskAndStackBounds */);
     56         mAmWmState.computeState(mDevice, null);
     57 
     58         if (supportsPip()) {
     59             final String windowName = getWindowName(topActivityName);
     60             mAmWmState.assertContainsStack("Must contain pinned stack.", PINNED_STACK_ID);
     61             mAmWmState.assertFrontStack("Pinned stack must be the front stack.", PINNED_STACK_ID);
     62             mAmWmState.assertVisibility(topActivityName, true);
     63 
     64             if (isFocusable) {
     65                 mAmWmState.assertFocusedStack(
     66                         "Pinned stack must be the focused stack.", PINNED_STACK_ID);
     67                 mAmWmState.assertFocusedActivity(
     68                         "Pinned activity must be focused activity.", topActivityName);
     69                 mAmWmState.assertFocusedWindow(
     70                         "Pinned window must be focused window.", windowName);
     71                 // Not checking for resumed state here because PiP overlay can be launched on top
     72                 // in different task by SystemUI.
     73             } else {
     74                 mAmWmState.assertNotFocusedStack(
     75                         "Pinned stack can't be the focused stack.", PINNED_STACK_ID);
     76                 mAmWmState.assertNotFocusedActivity(
     77                         "Pinned activity can't be the focused activity.", topActivityName);
     78                 mAmWmState.assertNotResumedActivity(
     79                         "Pinned activity can't be the resumed activity.", topActivityName);
     80                 mAmWmState.assertNotFocusedWindow(
     81                         "Pinned window can't be focused window.", windowName);
     82             }
     83         } else {
     84             mAmWmState.assertDoesNotContainStack(
     85                     "Must not contain pinned stack.", PINNED_STACK_ID);
     86         }
     87     }
     88 }
     89