blob: 693264cbe4ee382e877605a2076b89a62bb2c3d5 [file] [log] [blame]
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001/*
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
17package com.android.server.wm;
18
Wale Ogunwale68278562017-09-23 17:13:55 -070019import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
20import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
Andrii Kulian92c9a942017-10-10 00:41:41 -070021import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
22import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
23import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale34247952017-02-19 11:57:53 -080024import static android.view.Display.DEFAULT_DISPLAY;
25import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
26import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
27import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Andrii Kulian92c9a942017-10-10 00:41:41 -070028import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Wale Ogunwale34247952017-02-19 11:57:53 -080029import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION;
David Stevens46939562017-03-24 13:04:00 -070030import static com.android.server.wm.WindowContainer.POSITION_TOP;
Wale Ogunwale34247952017-02-19 11:57:53 -080031import static org.junit.Assert.assertEquals;
32import static org.junit.Assert.assertTrue;
33
Wale Ogunwale42bab782017-05-02 13:16:39 -070034import org.junit.Ignore;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070035import org.junit.Test;
36import org.junit.runner.RunWith;
37
Andrii Kulian92c9a942017-10-10 00:41:41 -070038import android.annotation.SuppressLint;
Andrii Kuliand68501e2017-01-10 22:57:27 -080039import android.content.res.Configuration;
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -070040import android.os.SystemClock;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070041import android.platform.test.annotations.Presubmit;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070042import android.support.test.filters.SmallTest;
43import android.support.test.runner.AndroidJUnit4;
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -070044import android.util.DisplayMetrics;
Andrii Kulian0214ed92017-05-16 13:44:05 -070045import android.util.SparseIntArray;
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -070046import android.view.MotionEvent;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070047
Wale Ogunwale34247952017-02-19 11:57:53 -080048import java.util.Arrays;
49import java.util.LinkedList;
50import java.util.List;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070051
52/**
53 * Tests for the {@link DisplayContent} class.
54 *
55 * Build/Install/Run:
56 * bit FrameworksServicesTests:com.android.server.wm.DisplayContentTests
57 */
58@SmallTest
59@Presubmit
60@RunWith(AndroidJUnit4.class)
Wale Ogunwale44fbdf52016-11-16 10:18:45 -080061public class DisplayContentTests extends WindowTestsBase {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070062
63 @Test
64 public void testForAllWindows() throws Exception {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080065 final WindowState exitingAppWindow = createWindow(null, TYPE_BASE_APPLICATION,
Wale Ogunwale11cc5162017-04-25 20:29:13 -070066 mDisplayContent, "exiting app");
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070067 final AppWindowToken exitingAppToken = exitingAppWindow.mAppToken;
68 exitingAppToken.mIsExiting = true;
Bryce Lee6d410262017-02-28 15:30:17 -080069 exitingAppToken.getTask().mStack.mExitingAppTokens.add(exitingAppToken);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -070070
Wale Ogunwale34247952017-02-19 11:57:53 -080071 assertForAllWindowsOrder(Arrays.asList(
Wale Ogunwale11cc5162017-04-25 20:29:13 -070072 mWallpaperWindow,
Wale Ogunwale34247952017-02-19 11:57:53 -080073 exitingAppWindow,
Wale Ogunwale11cc5162017-04-25 20:29:13 -070074 mChildAppWindowBelow,
75 mAppWindow,
76 mChildAppWindowAbove,
77 mDockedDividerWindow,
78 mStatusBarWindow,
79 mNavBarWindow,
80 mImeWindow,
81 mImeDialogWindow));
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080082 }
83
84 @Test
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -080085 public void testForAllWindows_WithAppImeTarget() throws Exception {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080086 final WindowState imeAppTarget =
Wale Ogunwale11cc5162017-04-25 20:29:13 -070087 createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "imeAppTarget");
Wale Ogunwale3c1170d2016-12-02 14:44:52 -080088
89 sWm.mInputMethodTarget = imeAppTarget;
90
Wale Ogunwale34247952017-02-19 11:57:53 -080091 assertForAllWindowsOrder(Arrays.asList(
Wale Ogunwale11cc5162017-04-25 20:29:13 -070092 mWallpaperWindow,
93 mChildAppWindowBelow,
94 mAppWindow,
95 mChildAppWindowAbove,
Wale Ogunwale34247952017-02-19 11:57:53 -080096 imeAppTarget,
Wale Ogunwale11cc5162017-04-25 20:29:13 -070097 mImeWindow,
98 mImeDialogWindow,
99 mDockedDividerWindow,
100 mStatusBarWindow,
101 mNavBarWindow));
Wale Ogunwale34247952017-02-19 11:57:53 -0800102 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800103
Wale Ogunwale34247952017-02-19 11:57:53 -0800104 @Test
105 public void testForAllWindows_WithChildWindowImeTarget() throws Exception {
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700106 sWm.mInputMethodTarget = mChildAppWindowAbove;
Wale Ogunwale3c1170d2016-12-02 14:44:52 -0800107
Wale Ogunwale34247952017-02-19 11:57:53 -0800108 assertForAllWindowsOrder(Arrays.asList(
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700109 mWallpaperWindow,
110 mChildAppWindowBelow,
111 mAppWindow,
112 mChildAppWindowAbove,
113 mImeWindow,
114 mImeDialogWindow,
115 mDockedDividerWindow,
116 mStatusBarWindow,
117 mNavBarWindow));
Wale Ogunwaleb783fd82016-11-04 09:51:54 -0700118 }
Wale Ogunwale5d7e7f12016-12-12 14:47:05 -0800119
120 @Test
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800121 public void testForAllWindows_WithStatusBarImeTarget() throws Exception {
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700122 sWm.mInputMethodTarget = mStatusBarWindow;
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800123
Wale Ogunwale34247952017-02-19 11:57:53 -0800124 assertForAllWindowsOrder(Arrays.asList(
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700125 mWallpaperWindow,
126 mChildAppWindowBelow,
127 mAppWindow,
128 mChildAppWindowAbove,
129 mDockedDividerWindow,
130 mStatusBarWindow,
131 mImeWindow,
132 mImeDialogWindow,
133 mNavBarWindow));
Wale Ogunwale6ce0fb82016-12-13 14:24:00 -0800134 }
135
136 @Test
Wale Ogunwale5d7e7f12016-12-12 14:47:05 -0800137 public void testForAllWindows_WithInBetweenWindowToken() throws Exception {
138 // This window is set-up to be z-ordered between some windows that go in the same token like
139 // the nav bar and status bar.
140 final WindowState voiceInteractionWindow = createWindow(null, TYPE_VOICE_INTERACTION,
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700141 mDisplayContent, "voiceInteractionWindow");
Wale Ogunwale5d7e7f12016-12-12 14:47:05 -0800142
Wale Ogunwale34247952017-02-19 11:57:53 -0800143 assertForAllWindowsOrder(Arrays.asList(
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700144 mWallpaperWindow,
145 mChildAppWindowBelow,
146 mAppWindow,
147 mChildAppWindowAbove,
148 mDockedDividerWindow,
Wale Ogunwale34247952017-02-19 11:57:53 -0800149 voiceInteractionWindow,
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700150 mStatusBarWindow,
151 mNavBarWindow,
152 mImeWindow,
153 mImeDialogWindow));
Wale Ogunwale34247952017-02-19 11:57:53 -0800154 }
Wale Ogunwale5d7e7f12016-12-12 14:47:05 -0800155
Wale Ogunwale34247952017-02-19 11:57:53 -0800156 @Test
157 public void testComputeImeTarget() throws Exception {
158 // Verify that an app window can be an ime target.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700159 final WindowState appWin = createWindow(null, TYPE_APPLICATION, mDisplayContent, "appWin");
Wale Ogunwale34247952017-02-19 11:57:53 -0800160 appWin.setHasSurface(true);
161 assertTrue(appWin.canBeImeTarget());
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700162 WindowState imeTarget = mDisplayContent.computeImeTarget(false /* updateImeTarget */);
Wale Ogunwale34247952017-02-19 11:57:53 -0800163 assertEquals(appWin, imeTarget);
Wale Ogunwale5d7e7f12016-12-12 14:47:05 -0800164
Wale Ogunwale34247952017-02-19 11:57:53 -0800165 // Verify that an child window can be an ime target.
166 final WindowState childWin = createWindow(appWin,
167 TYPE_APPLICATION_ATTACHED_DIALOG, "childWin");
168 childWin.setHasSurface(true);
169 assertTrue(childWin.canBeImeTarget());
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700170 imeTarget = mDisplayContent.computeImeTarget(false /* updateImeTarget */);
Wale Ogunwale34247952017-02-19 11:57:53 -0800171 assertEquals(childWin, imeTarget);
Wale Ogunwale5d7e7f12016-12-12 14:47:05 -0800172 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800173
Andrii Kuliand68501e2017-01-10 22:57:27 -0800174 /**
175 * This tests stack movement between displays and proper stack's, task's and app token's display
176 * container references updates.
177 */
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800178 @Test
179 public void testMoveStackBetweenDisplays() throws Exception {
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800180 // Create a second display.
181 final DisplayContent dc = createNewDisplay();
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800182
183 // Add stack with activity.
184 final TaskStack stack = createTaskStackOnDisplay(dc);
185 assertEquals(dc.getDisplayId(), stack.getDisplayContent().getDisplayId());
186 assertEquals(dc, stack.getParent().getParent());
187 assertEquals(dc, stack.getDisplayContent());
188
189 final Task task = createTaskInStack(stack, 0 /* userId */);
Bryce Leeaf691c02017-03-20 14:20:22 -0700190 final WindowTestUtils.TestAppWindowToken token = new WindowTestUtils.TestAppWindowToken(dc);
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800191 task.addChild(token, 0);
192 assertEquals(dc, task.getDisplayContent());
193 assertEquals(dc, token.getDisplayContent());
194
195 // Move stack to first display.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700196 mDisplayContent.moveStackToDisplay(stack, true /* onTop */);
197 assertEquals(mDisplayContent.getDisplayId(), stack.getDisplayContent().getDisplayId());
198 assertEquals(mDisplayContent, stack.getParent().getParent());
199 assertEquals(mDisplayContent, stack.getDisplayContent());
200 assertEquals(mDisplayContent, task.getDisplayContent());
201 assertEquals(mDisplayContent, token.getDisplayContent());
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800202 }
Andrii Kuliand68501e2017-01-10 22:57:27 -0800203
204 /**
205 * This tests override configuration updates for display content.
206 */
207 @Test
208 public void testDisplayOverrideConfigUpdate() throws Exception {
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700209 final int displayId = mDisplayContent.getDisplayId();
210 final Configuration currentOverrideConfig = mDisplayContent.getOverrideConfiguration();
Andrii Kuliand68501e2017-01-10 22:57:27 -0800211
212 // Create new, slightly changed override configuration and apply it to the display.
213 final Configuration newOverrideConfig = new Configuration(currentOverrideConfig);
214 newOverrideConfig.densityDpi += 120;
215 newOverrideConfig.fontScale += 0.3;
216
217 sWm.setNewDisplayOverrideConfiguration(newOverrideConfig, displayId);
218
219 // Check that override config is applied.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700220 assertEquals(newOverrideConfig, mDisplayContent.getOverrideConfiguration());
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800221 }
222
223 /**
224 * This tests global configuration updates when default display config is updated.
225 */
226 @Test
227 public void testDefaultDisplayOverrideConfigUpdate() throws Exception {
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700228 final Configuration currentConfig = mDisplayContent.getConfiguration();
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800229
230 // Create new, slightly changed override configuration and apply it to the display.
Andrii Kuliana95bfff2017-03-30 19:00:41 -0700231 final Configuration newOverrideConfig = new Configuration(currentConfig);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800232 newOverrideConfig.densityDpi += 120;
233 newOverrideConfig.fontScale += 0.3;
234
235 sWm.setNewDisplayOverrideConfiguration(newOverrideConfig, DEFAULT_DISPLAY);
Andrii Kuliand68501e2017-01-10 22:57:27 -0800236
237 // Check that global configuration is updated, as we've updated default display's config.
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800238 Configuration globalConfig = sWm.mRoot.getConfiguration();
Andrii Kuliand68501e2017-01-10 22:57:27 -0800239 assertEquals(newOverrideConfig.densityDpi, globalConfig.densityDpi);
240 assertEquals(newOverrideConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800241
242 // Return back to original values.
Andrii Kuliana95bfff2017-03-30 19:00:41 -0700243 sWm.setNewDisplayOverrideConfiguration(currentConfig, DEFAULT_DISPLAY);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800244 globalConfig = sWm.mRoot.getConfiguration();
Andrii Kuliana95bfff2017-03-30 19:00:41 -0700245 assertEquals(currentConfig.densityDpi, globalConfig.densityDpi);
246 assertEquals(currentConfig.fontScale, globalConfig.fontScale, 0.1 /* delta */);
Andrii Kuliand68501e2017-01-10 22:57:27 -0800247 }
Wale Ogunwale34247952017-02-19 11:57:53 -0800248
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700249 /**
250 * Tests tapping on a stack in different display results in window gaining focus.
251 */
252 @Test
253 public void testInputEventBringsCorrectDisplayInFocus() throws Exception {
254 DisplayContent dc0 = sWm.getDefaultDisplayContentLocked();
255 // Create a second display
256 final DisplayContent dc1 = createNewDisplay();
257
258 // Add stack with activity.
259 final TaskStack stack0 = createTaskStackOnDisplay(dc0);
260 final Task task0 = createTaskInStack(stack0, 0 /* userId */);
261 final WindowTestUtils.TestAppWindowToken token =
262 new WindowTestUtils.TestAppWindowToken(dc0);
263 task0.addChild(token, 0);
264 dc0.mTapDetector = new TaskTapPointerEventListener(sWm, dc0);
265 sWm.registerPointerEventListener(dc0.mTapDetector);
266 final TaskStack stack1 = createTaskStackOnDisplay(dc1);
267 final Task task1 = createTaskInStack(stack1, 0 /* userId */);
268 final WindowTestUtils.TestAppWindowToken token1 =
269 new WindowTestUtils.TestAppWindowToken(dc0);
270 task1.addChild(token1, 0);
271 dc1.mTapDetector = new TaskTapPointerEventListener(sWm, dc0);
272 sWm.registerPointerEventListener(dc1.mTapDetector);
273
274 // tap on primary display (by sending ACTION_DOWN followed by ACTION_UP)
275 DisplayMetrics dm0 = dc0.getDisplayMetrics();
276 dc0.mTapDetector.onPointerEvent(
277 createTapEvent(dm0.widthPixels / 2, dm0.heightPixels / 2, true));
278 dc0.mTapDetector.onPointerEvent(
279 createTapEvent(dm0.widthPixels / 2, dm0.heightPixels / 2, false));
280
281 // Check focus is on primary display.
282 assertEquals(sWm.mCurrentFocus, dc0.findFocusedWindow());
283
284 // Tap on secondary display
285 DisplayMetrics dm1 = dc1.getDisplayMetrics();
286 dc1.mTapDetector.onPointerEvent(
287 createTapEvent(dm1.widthPixels / 2, dm1.heightPixels / 2, true));
288 dc1.mTapDetector.onPointerEvent(
289 createTapEvent(dm1.widthPixels / 2, dm1.heightPixels / 2, false));
290
291 // Check focus is on secondary.
292 assertEquals(sWm.mCurrentFocus, dc1.findFocusedWindow());
293 }
294
David Stevens46939562017-03-24 13:04:00 -0700295 @Test
Wale Ogunwale42bab782017-05-02 13:16:39 -0700296 @Ignore
David Stevens46939562017-03-24 13:04:00 -0700297 public void testFocusedWindowMultipleDisplays() throws Exception {
Andrii Kulian0214ed92017-05-16 13:44:05 -0700298 // Create a focusable window and check that focus is calculated correctly
David Stevens46939562017-03-24 13:04:00 -0700299 final WindowState window1 =
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700300 createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, "window1");
David Stevens46939562017-03-24 13:04:00 -0700301 assertEquals(window1, sWm.mRoot.computeFocusedWindow());
302
303 // Check that a new display doesn't affect focus
304 final DisplayContent dc = createNewDisplay();
305 assertEquals(window1, sWm.mRoot.computeFocusedWindow());
306
307 // Add a window to the second display, and it should be focused
308 final WindowState window2 = createWindow(null, TYPE_BASE_APPLICATION, dc, "window2");
309 assertEquals(window2, sWm.mRoot.computeFocusedWindow());
310
311 // Move the first window to the to including parents, and make sure focus is updated
312 window1.getParent().positionChildAt(POSITION_TOP, window1, true);
313 assertEquals(window1, sWm.mRoot.computeFocusedWindow());
314 }
315
Bryce Lee27cec322017-03-21 09:41:37 -0700316 /**
317 * This tests setting the maximum ui width on a display.
318 */
319 @Test
320 public void testMaxUiWidth() throws Exception {
321 final int baseWidth = 1440;
322 final int baseHeight = 2560;
323 final int baseDensity = 300;
324
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700325 mDisplayContent.updateBaseDisplayMetrics(baseWidth, baseHeight, baseDensity);
Bryce Lee27cec322017-03-21 09:41:37 -0700326
327 final int maxWidth = 300;
328 final int resultingHeight = (maxWidth * baseHeight) / baseWidth;
329 final int resultingDensity = (maxWidth * baseDensity) / baseWidth;
330
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700331 mDisplayContent.setMaxUiWidth(maxWidth);
332 verifySizes(mDisplayContent, maxWidth, resultingHeight, resultingDensity);
Bryce Lee27cec322017-03-21 09:41:37 -0700333
334 // Assert setting values again does not change;
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700335 mDisplayContent.updateBaseDisplayMetrics(baseWidth, baseHeight, baseDensity);
336 verifySizes(mDisplayContent, maxWidth, resultingHeight, resultingDensity);
Bryce Lee27cec322017-03-21 09:41:37 -0700337
338 final int smallerWidth = 200;
339 final int smallerHeight = 400;
340 final int smallerDensity = 100;
341
342 // Specify smaller dimension, verify that it is honored
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700343 mDisplayContent.updateBaseDisplayMetrics(smallerWidth, smallerHeight, smallerDensity);
344 verifySizes(mDisplayContent, smallerWidth, smallerHeight, smallerDensity);
Bryce Lee27cec322017-03-21 09:41:37 -0700345
346 // Verify that setting the max width to a greater value than the base width has no effect
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700347 mDisplayContent.setMaxUiWidth(maxWidth);
348 verifySizes(mDisplayContent, smallerWidth, smallerHeight, smallerDensity);
Bryce Lee27cec322017-03-21 09:41:37 -0700349 }
350
Bryce Lee48f4b572017-04-10 10:54:15 -0700351 /**
352 * This test enforces that the pinned stack is always kept as the top stack.
353 */
354 @Test
355 public void testPinnedStackLocation() {
Wale Ogunwale61911492017-10-11 08:50:50 -0700356 final TaskStack pinnedStack = createStackControllerOnStackOnDisplay(
357 WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, mDisplayContent).mContainer;
358 // Ensure that the pinned stack is the top stack
359 assertEquals(pinnedStack, mDisplayContent.getPinnedStack());
360 assertEquals(pinnedStack, mDisplayContent.getTopStack());
Bryce Lee48f4b572017-04-10 10:54:15 -0700361 // By default, this should try to create a new stack on top
Wale Ogunwale61911492017-10-11 08:50:50 -0700362 final TaskStack otherStack = createTaskStackOnDisplay(mDisplayContent);
363 // Ensure that the other stack is on the display.
364 assertEquals(mDisplayContent, otherStack.getDisplayContent());
Bryce Lee48f4b572017-04-10 10:54:15 -0700365 // Ensure that the pinned stack is still on top
Wale Ogunwale61911492017-10-11 08:50:50 -0700366 assertEquals(pinnedStack, mDisplayContent.getTopStack());
Bryce Lee48f4b572017-04-10 10:54:15 -0700367 }
368
Andrii Kulian0214ed92017-05-16 13:44:05 -0700369 /**
370 * Test that WM does not report displays to AM that are pending to be removed.
371 */
372 @Test
373 public void testDontReportDeferredRemoval() {
374 // Create a display and add an animating window to it.
375 final DisplayContent dc = createNewDisplay();
376 final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w");
377 window.mAnimatingExit = true;
378 // Request display removal, it should be deferred.
379 dc.removeIfPossible();
380 // Request ordered display ids from WM.
381 final SparseIntArray orderedDisplayIds = new SparseIntArray();
382 sWm.getDisplaysInFocusOrder(orderedDisplayIds);
383 // Make sure that display that is marked for removal is not reported.
384 assertEquals(-1, orderedDisplayIds.indexOfValue(dc.getDisplayId()));
385 }
386
Andrii Kulian92c9a942017-10-10 00:41:41 -0700387 @Test
388 @SuppressLint("InlinedApi")
389 public void testOrientationDefinedByKeyguard() {
390 final DisplayContent dc = createNewDisplay();
391 // Create a window that requests landscape orientation. It will define device orientation
392 // by default.
393 final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w");
394 window.mAppToken.setOrientation(SCREEN_ORIENTATION_LANDSCAPE);
395
396 final WindowState keyguard = createWindow(null, TYPE_STATUS_BAR, dc, "keyguard");
397 keyguard.mHasSurface = true;
398 keyguard.mAttrs.screenOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
399
400 assertEquals("Screen orientation must be defined by the app window by default",
401 SCREEN_ORIENTATION_LANDSCAPE, dc.getOrientation());
402
403 keyguard.mAttrs.screenOrientation = SCREEN_ORIENTATION_PORTRAIT;
404 assertEquals("Visible keyguard must influence device orientation",
405 SCREEN_ORIENTATION_PORTRAIT, dc.getOrientation());
406
407 sWm.setKeyguardGoingAway(true);
408 assertEquals("Keyguard that is going away must not influence device orientation",
409 SCREEN_ORIENTATION_LANDSCAPE, dc.getOrientation());
410 }
411
Bryce Lee27cec322017-03-21 09:41:37 -0700412 private static void verifySizes(DisplayContent displayContent, int expectedBaseWidth,
413 int expectedBaseHeight, int expectedBaseDensity) {
414 assertEquals(displayContent.mBaseDisplayWidth, expectedBaseWidth);
415 assertEquals(displayContent.mBaseDisplayHeight, expectedBaseHeight);
416 assertEquals(displayContent.mBaseDisplayDensity, expectedBaseDensity);
417 }
418
Wale Ogunwale34247952017-02-19 11:57:53 -0800419 private void assertForAllWindowsOrder(List<WindowState> expectedWindows) {
420 final LinkedList<WindowState> actualWindows = new LinkedList();
421
422 // Test forward traversal.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700423 mDisplayContent.forAllWindows(actualWindows::addLast, false /* traverseTopToBottom */);
Wale Ogunwale34247952017-02-19 11:57:53 -0800424 assertEquals(expectedWindows.size(), actualWindows.size());
425 for (WindowState w : expectedWindows) {
426 assertEquals(w, actualWindows.pollFirst());
427 }
428 assertTrue(actualWindows.isEmpty());
429
430 // Test backward traversal.
Wale Ogunwale11cc5162017-04-25 20:29:13 -0700431 mDisplayContent.forAllWindows(actualWindows::addLast, true /* traverseTopToBottom */);
Wale Ogunwale34247952017-02-19 11:57:53 -0800432 assertEquals(expectedWindows.size(), actualWindows.size());
433 for (WindowState w : expectedWindows) {
434 assertEquals(w, actualWindows.pollLast());
435 }
436 assertTrue(actualWindows.isEmpty());
437 }
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700438
439 private MotionEvent createTapEvent(float x, float y, boolean isDownEvent) {
440 final long downTime = SystemClock.uptimeMillis();
441 final long eventTime = SystemClock.uptimeMillis() + 100;
442 final int metaState = 0;
443
444 return MotionEvent.obtain(
445 downTime,
446 eventTime,
447 isDownEvent ? MotionEvent.ACTION_DOWN : MotionEvent.ACTION_UP,
448 x,
449 y,
450 metaState);
451 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -0700452}