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.awt.Rectangle; 20 import java.util.ArrayList; 21 22 public class ActivityManagerFreeformStackTests extends ActivityManagerTestBase { 23 24 private static final String TEST_ACTIVITY = "TestActivity"; 25 private static final int TEST_TASK_OFFSET = 20; 26 private static final int TEST_TASK_OFFSET_2 = 100; 27 private static final int TEST_TASK_SIZE_1 = 500; 28 private static final int TEST_TASK_SIZE_2 = TEST_TASK_SIZE_1 * 2; 29 // NOTE: Launching the FreeformActivity will automatically launch the TestActivity 30 // with bounds (0, 0, 500, 500) 31 private static final String FREEFORM_ACTIVITY = "FreeformActivity"; 32 private static final String NON_RESIZEABLE_ACTIVITY = "NonResizeableActivity"; 33 private static final String NO_RELAUNCH_ACTIVITY = "NoRelaunchActivity"; 34 35 public void testFreeformWindowManagementSupport() throws Exception { 36 37 launchActivityInStack(FREEFORM_ACTIVITY, FREEFORM_WORKSPACE_STACK_ID); 38 39 mAmWmState.computeState(mDevice, new String[] {FREEFORM_ACTIVITY, TEST_ACTIVITY}); 40 41 if (!supportsFreeform()) { 42 mAmWmState.assertDoesNotContainStack( 43 "Must not contain freeform stack.", FREEFORM_WORKSPACE_STACK_ID); 44 return; 45 } 46 47 mAmWmState.assertFrontStack( 48 "Freeform stack must be the front stack.", FREEFORM_WORKSPACE_STACK_ID); 49 mAmWmState.assertVisibility(FREEFORM_ACTIVITY, true); 50 mAmWmState.assertVisibility(TEST_ACTIVITY, true); 51 mAmWmState.assertFocusedActivity( 52 TEST_ACTIVITY + " must be focused Activity", TEST_ACTIVITY); 53 assertEquals(new Rectangle(0, 0, TEST_TASK_SIZE_1, TEST_TASK_SIZE_1), 54 mAmWmState.getAmState().getTaskByActivityName(TEST_ACTIVITY).getBounds()); 55 } 56 57 public void testNonResizeableActivityNotLaunchedToFreeform() throws Exception { 58 launchActivityInStack(NON_RESIZEABLE_ACTIVITY, FREEFORM_WORKSPACE_STACK_ID); 59 60 mAmWmState.computeState(mDevice, new String[] {NON_RESIZEABLE_ACTIVITY}); 61 62 mAmWmState.assertFrontStack( 63 "Fullscreen stack must be the front stack.", FULLSCREEN_WORKSPACE_STACK_ID); 64 mAmWmState.assertDoesNotContainStack( 65 "Must not contain freeform stack.", FREEFORM_WORKSPACE_STACK_ID); 66 } 67 68 public void testActivityLifeCycleOnResizeFreeformTask() throws Exception { 69 launchActivityInStack(TEST_ACTIVITY, FREEFORM_WORKSPACE_STACK_ID); 70 launchActivityInStack(NO_RELAUNCH_ACTIVITY, FREEFORM_WORKSPACE_STACK_ID); 71 72 mAmWmState.computeState(mDevice, new String[]{TEST_ACTIVITY, NO_RELAUNCH_ACTIVITY}); 73 74 if (!supportsFreeform()) { 75 mAmWmState.assertDoesNotContainStack( 76 "Must not contain freeform stack.", FREEFORM_WORKSPACE_STACK_ID); 77 return; 78 } 79 80 resizeActivityTask(TEST_ACTIVITY, 81 TEST_TASK_OFFSET, TEST_TASK_OFFSET, TEST_TASK_SIZE_1, TEST_TASK_SIZE_2); 82 resizeActivityTask(NO_RELAUNCH_ACTIVITY, 83 TEST_TASK_OFFSET_2, TEST_TASK_OFFSET_2, TEST_TASK_SIZE_1, TEST_TASK_SIZE_2); 84 85 mAmWmState.computeState(mDevice, new String[]{TEST_ACTIVITY, NO_RELAUNCH_ACTIVITY}); 86 87 clearLogcat(); 88 resizeActivityTask(TEST_ACTIVITY, 89 TEST_TASK_OFFSET, TEST_TASK_OFFSET, TEST_TASK_SIZE_2, TEST_TASK_SIZE_1); 90 resizeActivityTask(NO_RELAUNCH_ACTIVITY, 91 TEST_TASK_OFFSET_2, TEST_TASK_OFFSET_2, TEST_TASK_SIZE_2, TEST_TASK_SIZE_1); 92 mAmWmState.computeState(mDevice, new String[]{TEST_ACTIVITY, NO_RELAUNCH_ACTIVITY}); 93 94 assertActivityLifecycle(TEST_ACTIVITY, true); 95 assertActivityLifecycle(NO_RELAUNCH_ACTIVITY, false); 96 } 97 } 98