blob: 2554237cdbf5c9aa2e7b921b674f124d4d8f8800 [file] [log] [blame]
Andrii Kuliand2765632016-12-12 22:26:34 -08001/*
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
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070014 * limitations under the License.
Andrii Kuliand2765632016-12-12 22:26:34 -080015 */
16
17package com.android.server.wm;
18
Bryce Lee61fbcbc2017-03-10 14:14:03 -080019import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
20import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
21
Andrii Kuliand2765632016-12-12 22:26:34 -080022import static org.junit.Assert.assertEquals;
Yunfan Chen279f5582018-12-12 15:24:50 -080023import static org.junit.Assert.assertNotEquals;
24import static org.junit.Assert.assertNotNull;
Andrii Kuliand2765632016-12-12 22:26:34 -080025import static org.junit.Assert.assertNull;
Yunfan Chen279f5582018-12-12 15:24:50 -080026import static org.junit.Assert.assertTrue;
Brett Chabota26eda92018-07-23 13:08:30 -070027
Yunfan Chen279f5582018-12-12 15:24:50 -080028import android.graphics.Rect;
Brett Chabota26eda92018-07-23 13:08:30 -070029import android.platform.test.annotations.Presubmit;
30
31import androidx.test.filters.SmallTest;
Brett Chabota26eda92018-07-23 13:08:30 -070032
33import org.junit.Test;
Andrii Kuliand2765632016-12-12 22:26:34 -080034
35/**
36 * Tests for the {@link TaskStack} class.
37 *
38 * Build/Install/Run:
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070039 * atest FrameworksServicesTests:TaskStackTests
Andrii Kuliand2765632016-12-12 22:26:34 -080040 */
41@SmallTest
42@Presubmit
Andrii Kuliand2765632016-12-12 22:26:34 -080043public class TaskStackTests extends WindowTestsBase {
44
45 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070046 public void testStackPositionChildAt() {
Wale Ogunwale11cc5162017-04-25 20:29:13 -070047 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
Andrii Kuliand2765632016-12-12 22:26:34 -080048 final Task task1 = createTaskInStack(stack, 0 /* userId */);
49 final Task task2 = createTaskInStack(stack, 1 /* userId */);
50
51 // Current user task should be moved to top.
52 stack.positionChildAt(WindowContainer.POSITION_TOP, task1, false /* includingParents */);
53 assertEquals(stack.mChildren.get(0), task2);
54 assertEquals(stack.mChildren.get(1), task1);
55
56 // Non-current user won't be moved to top.
57 stack.positionChildAt(WindowContainer.POSITION_TOP, task2, false /* includingParents */);
58 assertEquals(stack.mChildren.get(0), task2);
59 assertEquals(stack.mChildren.get(1), task1);
60 }
Andrii Kulian45a61fe2017-01-05 16:53:19 -080061
62 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070063 public void testClosingAppDifferentStackOrientation() {
Wale Ogunwale11cc5162017-04-25 20:29:13 -070064 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080065 final Task task1 = createTaskInStack(stack, 0 /* userId */);
Bryce Leeaf691c02017-03-20 14:20:22 -070066 WindowTestUtils.TestAppWindowToken appWindowToken1 =
chaviw97d28202018-02-27 16:23:53 -080067 WindowTestUtils.createTestAppWindowToken(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080068 task1.addChild(appWindowToken1, 0);
69 appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
70
71 final Task task2 = createTaskInStack(stack, 1 /* userId */);
Bryce Leeaf691c02017-03-20 14:20:22 -070072 WindowTestUtils.TestAppWindowToken appWindowToken2 =
chaviw97d28202018-02-27 16:23:53 -080073 WindowTestUtils.createTestAppWindowToken(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080074 task2.addChild(appWindowToken2, 0);
75 appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT);
76
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070077 assertEquals(SCREEN_ORIENTATION_PORTRAIT, stack.getOrientation());
lumark588a3e82018-07-20 18:53:54 +080078 mDisplayContent.mClosingApps.add(appWindowToken2);
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070079 assertEquals(SCREEN_ORIENTATION_LANDSCAPE, stack.getOrientation());
Bryce Lee61fbcbc2017-03-10 14:14:03 -080080 }
81
82 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070083 public void testMoveTaskToBackDifferentStackOrientation() {
Wale Ogunwale11cc5162017-04-25 20:29:13 -070084 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080085 final Task task1 = createTaskInStack(stack, 0 /* userId */);
Bryce Leeaf691c02017-03-20 14:20:22 -070086 WindowTestUtils.TestAppWindowToken appWindowToken1 =
chaviw97d28202018-02-27 16:23:53 -080087 WindowTestUtils.createTestAppWindowToken(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080088 task1.addChild(appWindowToken1, 0);
89 appWindowToken1.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
90
91 final Task task2 = createTaskInStack(stack, 1 /* userId */);
Bryce Leeaf691c02017-03-20 14:20:22 -070092 WindowTestUtils.TestAppWindowToken appWindowToken2 =
chaviw97d28202018-02-27 16:23:53 -080093 WindowTestUtils.createTestAppWindowToken(mDisplayContent);
Bryce Lee61fbcbc2017-03-10 14:14:03 -080094 task2.addChild(appWindowToken2, 0);
95 appWindowToken2.setOrientation(SCREEN_ORIENTATION_PORTRAIT);
96
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070097 assertEquals(SCREEN_ORIENTATION_PORTRAIT, stack.getOrientation());
Bryce Lee61fbcbc2017-03-10 14:14:03 -080098 task2.setSendingToBottom(true);
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070099 assertEquals(SCREEN_ORIENTATION_LANDSCAPE, stack.getOrientation());
Bryce Lee61fbcbc2017-03-10 14:14:03 -0800100 }
101
102 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700103 public void testStackRemoveImmediately() {
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700104 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800105 final Task task = createTaskInStack(stack, 0 /* userId */);
106 assertEquals(stack, task.mStack);
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800107
108 // Remove stack and check if its child is also removed.
109 stack.removeImmediately();
110 assertNull(stack.getDisplayContent());
111 assertNull(task.mStack);
Andrii Kulian45a61fe2017-01-05 16:53:19 -0800112 }
Yunfan Chen279f5582018-12-12 15:24:50 -0800113
114 @Test
115 public void testRemoveContainer() {
116 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
117 final WindowTestUtils.TestTask task = WindowTestUtils.createTestTask(stack);
118
119 assertNotNull(stack);
120 assertNotNull(task);
121 stack.removeIfPossible();
122 // Assert that the container was removed.
123 assertNull(stack.getParent());
124 assertEquals(0, stack.getChildCount());
125 assertNull(stack.getDisplayContent());
126 assertNull(task.getDisplayContent());
127 assertNull(task.mStack);
128 }
129
130 @Test
131 public void testRemoveContainer_deferRemoval() {
132 final TaskStack stack = createTaskStackOnDisplay(mDisplayContent);
133 final WindowTestUtils.TestTask task = WindowTestUtils.createTestTask(stack);
134
135 // Stack removal is deferred if one of its child is animating.
136 task.setLocalIsAnimating(true);
137
138 stack.removeIfPossible();
139 // For the case of deferred removal the task controller will still be connected to the its
140 // container until the stack window container is removed.
141 assertNotNull(stack.getParent());
142 assertNotEquals(0, stack.getChildCount());
143 assertNotNull(task);
144
145 stack.removeImmediately();
146 // After removing, the task will be isolated.
147 assertNull(task.getParent());
148 assertEquals(0, task.getChildCount());
149 assertNull(task.getController());
150 }
151
152 @Test
153 public void testReparent() {
154 // Create first stack on primary display.
155 final TaskStack stack1 = createTaskStackOnDisplay(mDisplayContent);
156 final WindowTestUtils.TestTask task1 = WindowTestUtils.createTestTask(stack1);
157 task1.mOnDisplayChangedCalled = false;
158
159 // Create second display and put second stack on it.
160 final DisplayContent dc = createNewDisplay();
161 final TaskStack stack2 = createTaskStackOnDisplay(dc);
162
163 // Reparent
164 stack1.reparent(dc.getDisplayId(), new Rect(), true /* onTop */);
165 assertEquals(dc, stack1.getDisplayContent());
166 final int stack1PositionInParent = stack1.getParent().mChildren.indexOf(stack1);
167 final int stack2PositionInParent = stack1.getParent().mChildren.indexOf(stack2);
168 assertEquals(stack1PositionInParent, stack2PositionInParent + 1);
169 assertTrue(task1.mOnDisplayChangedCalled);
170 }
Andrii Kuliand2765632016-12-12 22:26:34 -0800171}