blob: d605ab25bd576902ecea79ca5ab4e75ab964b381 [file] [log] [blame]
Tiger Huang7c610aa2018-10-27 00:01:01 +08001/*
2 * Copyright (C) 2018 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
chaviw0d833762019-06-20 17:09:53 -070019import static android.view.Gravity.BOTTOM;
20import static android.view.Gravity.LEFT;
21import static android.view.Gravity.RIGHT;
22import static android.view.Gravity.TOP;
Yuncheol Heo13a6eb62020-03-04 23:50:37 -080023import static android.view.InsetsState.ITYPE_NAVIGATION_BAR;
24import static android.view.InsetsState.ITYPE_STATUS_BAR;
25import static android.view.InsetsState.ITYPE_TOP_GESTURES;
Tiger Huang7c610aa2018-10-27 00:01:01 +080026import static android.view.Surface.ROTATION_0;
27import static android.view.Surface.ROTATION_270;
28import static android.view.Surface.ROTATION_90;
29import static android.view.View.SYSTEM_UI_FLAG_FULLSCREEN;
Yongjin Kwon2fe07262019-09-03 10:47:28 +090030import static android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Tiger Huang7c610aa2018-10-27 00:01:01 +080031import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
Charles Chen64172bb2019-04-22 17:30:29 +080032import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
Tiger Huang7c610aa2018-10-27 00:01:01 +080033import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
34import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
35import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
36import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
chaviw0d833762019-06-20 17:09:53 -070037import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
Tiger Huang7c610aa2018-10-27 00:01:01 +080038import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
39import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
shawnlin465b7de2020-02-11 20:45:35 +080040import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
chaviw0d833762019-06-20 17:09:53 -070041import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_IS_SCREEN_DECOR;
Issei Suzukia5dbf522019-02-01 17:58:15 +010042import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
43import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Tiger Huang7c610aa2018-10-27 00:01:01 +080044import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
45import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
Yuncheol Heo13a6eb62020-03-04 23:50:37 -080046import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
47import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
Tiger Huang7c610aa2018-10-27 00:01:01 +080048
49import static org.hamcrest.Matchers.is;
50import static org.junit.Assert.assertEquals;
Yuncheol Heo13a6eb62020-03-04 23:50:37 -080051import static org.junit.Assert.assertNotEquals;
Tiger Huang7c610aa2018-10-27 00:01:01 +080052import static org.junit.Assert.assertThat;
Tiger Huang4a7835f2019-11-06 00:07:56 +080053import static org.junit.Assume.assumeTrue;
Tiger Huang7c610aa2018-10-27 00:01:01 +080054import static org.mockito.Mockito.doNothing;
55import static org.mockito.Mockito.spy;
Yuncheol Heo13a6eb62020-03-04 23:50:37 -080056import static org.testng.Assert.expectThrows;
Tiger Huang7c610aa2018-10-27 00:01:01 +080057
Riddle Hsu55d7c402020-02-26 22:49:29 +080058import android.app.WindowConfiguration;
Issei Suzukia5dbf522019-02-01 17:58:15 +010059import android.graphics.Insets;
Tiger Huang7c610aa2018-10-27 00:01:01 +080060import android.graphics.PixelFormat;
61import android.graphics.Rect;
62import android.platform.test.annotations.Presubmit;
63import android.util.Pair;
64import android.view.DisplayCutout;
65import android.view.DisplayInfo;
Tiger Huang4a7835f2019-11-06 00:07:56 +080066import android.view.InsetsState;
67import android.view.ViewRootImpl;
68import android.view.WindowInsets.Side;
69import android.view.WindowInsets.Type;
Tiger Huang7c610aa2018-10-27 00:01:01 +080070import android.view.WindowManager;
71
Yongjin Kwon2fe07262019-09-03 10:47:28 +090072import androidx.test.filters.FlakyTest;
Tiger Huang7c610aa2018-10-27 00:01:01 +080073import androidx.test.filters.SmallTest;
Tiger Huang7c610aa2018-10-27 00:01:01 +080074
Brad Stenninge0573692019-03-11 13:52:46 -070075import com.android.server.policy.WindowManagerPolicy;
Tiger Huang7c610aa2018-10-27 00:01:01 +080076import com.android.server.wm.utils.WmDisplayCutout;
77
Yongjin Kwon2fe07262019-09-03 10:47:28 +090078import org.junit.After;
Tiger Huang7c610aa2018-10-27 00:01:01 +080079import org.junit.Before;
80import org.junit.Test;
Riddle Hsu73f53572019-09-23 23:13:01 +080081import org.junit.runner.RunWith;
Tiger Huang7c610aa2018-10-27 00:01:01 +080082
Riddle Hsuc7175762020-01-10 21:03:48 +080083import java.io.PrintWriter;
84import java.io.StringWriter;
85
Yongjin Kwon2fe07262019-09-03 10:47:28 +090086/**
87 * Tests for the {@link DisplayPolicy} class.
88 *
89 * Build/Install/Run:
90 * atest WmTests:DisplayPolicyLayoutTests
91 */
Tiger Huang7c610aa2018-10-27 00:01:01 +080092@SmallTest
93@Presubmit
Riddle Hsu73f53572019-09-23 23:13:01 +080094@RunWith(WindowTestRunner.class)
Tiger Huang7c610aa2018-10-27 00:01:01 +080095public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase {
96
97 private DisplayFrames mFrames;
98 private WindowState mWindow;
99 private int mRotation = ROTATION_0;
100 private boolean mHasDisplayCutout;
shawnlin465b7de2020-02-11 20:45:35 +0800101 private boolean mIsLongEdgeDisplayCutout;
chaviw0d833762019-06-20 17:09:53 -0700102 private static final int DECOR_WINDOW_INSET = 50;
Tiger Huang7c610aa2018-10-27 00:01:01 +0800103
104 @Before
105 public void setUp() throws Exception {
Tiger Huang7c610aa2018-10-27 00:01:01 +0800106 mWindow = spy(createWindow(null, TYPE_APPLICATION, "window"));
107 // We only test window frames set by DisplayPolicy, so here prevents computeFrameLw from
108 // changing those frames.
109 doNothing().when(mWindow).computeFrameLw();
110
111 final WindowManager.LayoutParams attrs = mWindow.mAttrs;
112 attrs.width = MATCH_PARENT;
113 attrs.height = MATCH_PARENT;
Tiger Huang7c610aa2018-10-27 00:01:01 +0800114 attrs.format = PixelFormat.TRANSLUCENT;
Tiger Huanga86bca92020-02-07 20:18:01 +0800115
116 updateDisplayFrames();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800117 }
118
Yongjin Kwon2fe07262019-09-03 10:47:28 +0900119 @After
120 public void tearDown() {
121 PolicyControl.setFilters("");
122 mWindow.getDisplayContent().mInputMethodTarget = null;
123 }
124
Tiger Huang7c610aa2018-10-27 00:01:01 +0800125 public void setRotation(int rotation) {
126 mRotation = rotation;
127 updateDisplayFrames();
128 }
129
130 public void addDisplayCutout() {
131 mHasDisplayCutout = true;
132 updateDisplayFrames();
133 }
134
shawnlin465b7de2020-02-11 20:45:35 +0800135 public void addLongEdgeDisplayCutout() {
136 mHasDisplayCutout = true;
137 mIsLongEdgeDisplayCutout = true;
138 updateDisplayFrames();
139 }
140
Tiger Huang7c610aa2018-10-27 00:01:01 +0800141 private void updateDisplayFrames() {
Riddle Hsuc7175762020-01-10 21:03:48 +0800142 mFrames = createDisplayFrames();
Tiger Huanga86bca92020-02-07 20:18:01 +0800143 mDisplayContent.mDisplayFrames = mFrames;
Riddle Hsuc7175762020-01-10 21:03:48 +0800144 }
145
146 private DisplayFrames createDisplayFrames() {
Tiger Huang7c610aa2018-10-27 00:01:01 +0800147 final Pair<DisplayInfo, WmDisplayCutout> info = displayInfoAndCutoutForRotation(mRotation,
shawnlin465b7de2020-02-11 20:45:35 +0800148 mHasDisplayCutout, mIsLongEdgeDisplayCutout);
Riddle Hsuc7175762020-01-10 21:03:48 +0800149 return new DisplayFrames(mDisplayContent.getDisplayId(), info.first, info.second);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800150 }
151
152 @Test
Tiger Huang7c610aa2018-10-27 00:01:01 +0800153 public void addingWindow_doesNotTamperWithSysuiFlags() {
154 mWindow.mAttrs.flags |= FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
155 addWindow(mWindow);
156
157 assertEquals(0, mWindow.mAttrs.systemUiVisibility);
158 assertEquals(0, mWindow.mAttrs.subtreeSystemUiVisibility);
159 }
160
161 @Test
Yuncheol Heo13a6eb62020-03-04 23:50:37 -0800162 public void addingWindow_withInsetsTypes() {
163 WindowState win = createWindow(null, TYPE_STATUS_BAR_SUB_PANEL, "StatusBarSubPanel");
164 win.mAttrs.providesInsetsTypes = new int[]{ITYPE_STATUS_BAR, ITYPE_TOP_GESTURES};
165 win.getFrameLw().set(0, 0, 500, 100);
166
167 addWindow(win);
168 InsetsStateController controller = mDisplayContent.getInsetsStateController();
169 controller.onPostLayout();
170
171 InsetsSourceProvider statusBarProvider = controller.getSourceProvider(ITYPE_STATUS_BAR);
172 assertEquals(new Rect(0, 0, 500, 100), statusBarProvider.getSource().getFrame());
173 assertEquals(Insets.of(0, 100, 0, 0),
174 statusBarProvider.getSource().calculateInsets(new Rect(0, 0, 500, 500),
175 false /* ignoreVisibility */));
176
177 InsetsSourceProvider topGesturesProvider = controller.getSourceProvider(ITYPE_TOP_GESTURES);
178 assertEquals(new Rect(0, 0, 500, 100), topGesturesProvider.getSource().getFrame());
179 assertEquals(Insets.of(0, 100, 0, 0),
180 topGesturesProvider.getSource().calculateInsets(new Rect(0, 0, 500, 500),
181 false /* ignoreVisibility */));
182
183 InsetsSourceProvider navigationBarProvider = controller.getSourceProvider(
184 ITYPE_NAVIGATION_BAR);
185 assertNotEquals(new Rect(0, 0, 500, 100), navigationBarProvider.getSource().getFrame());
186 }
187
188 @Test
189 public void addingWindow_ignoresInsetsTypes_InWindowTypeWithPredefinedInsets() {
190 mDisplayPolicy.removeWindowLw(mStatusBarWindow); // Removes the existing one.
191 WindowState win = createWindow(null, TYPE_STATUS_BAR, "StatusBar");
192 win.mAttrs.providesInsetsTypes = new int[]{ITYPE_STATUS_BAR};
193 win.getFrameLw().set(0, 0, 500, 100);
194
195 addWindow(win);
196 mDisplayContent.getInsetsStateController().onPostLayout();
197
198 InsetsSourceProvider provider =
199 mDisplayContent.getInsetsStateController().getSourceProvider(ITYPE_STATUS_BAR);
200 assertNotEquals(new Rect(0, 0, 500, 100), provider.getSource().getFrame());
201 }
202
203 @Test
204 public void addingWindow_throwsException_WithMultipleInsetTypes() {
205 WindowState win = createWindow(null, TYPE_STATUS_BAR_SUB_PANEL, "StatusBarSubPanel");
206 win.mAttrs.providesInsetsTypes = new int[]{ITYPE_STATUS_BAR, ITYPE_NAVIGATION_BAR};
207
208 expectThrows(IllegalArgumentException.class, () -> addWindow(win));
209 }
210
211 @Test
Tiger Huang4a7835f2019-11-06 00:07:56 +0800212 public void layoutWindowLw_fitStatusBars() {
213 assumeTrue(ViewRootImpl.sNewInsetsMode == ViewRootImpl.NEW_INSETS_MODE_FULL);
214
Tiger Huang52724442020-01-20 21:38:42 +0800215 mWindow.mAttrs.setFitInsetsTypes(Type.statusBars());
Tiger Huang4a7835f2019-11-06 00:07:56 +0800216 addWindow(mWindow);
217
218 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
219 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
220
221 assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
222 assertInsetByTopBottom(mWindow.getDisplayFrameLw(), STATUS_BAR_HEIGHT, 0);
223 assertInsetByTopBottom(mWindow.getParentFrame(), STATUS_BAR_HEIGHT, 0);
224 assertInsetByTopBottom(mWindow.getVisibleFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
225 assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
226 assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
227 }
228
229 @Test
230 public void layoutWindowLw_fitNavigationBars() {
231 assumeTrue(ViewRootImpl.sNewInsetsMode == ViewRootImpl.NEW_INSETS_MODE_FULL);
232
Tiger Huang52724442020-01-20 21:38:42 +0800233 mWindow.mAttrs.setFitInsetsTypes(Type.navigationBars());
Tiger Huang4a7835f2019-11-06 00:07:56 +0800234 addWindow(mWindow);
235
236 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
237 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
238
239 assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
240 assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, NAV_BAR_HEIGHT);
241 assertInsetByTopBottom(mWindow.getParentFrame(), 0, NAV_BAR_HEIGHT);
242 assertInsetByTopBottom(mWindow.getVisibleFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
243 assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
244 assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
245 }
246
247 @Test
Tiger Huang4a7835f2019-11-06 00:07:56 +0800248 public void layoutWindowLw_fitAllSides() {
249 assumeTrue(ViewRootImpl.sNewInsetsMode == ViewRootImpl.NEW_INSETS_MODE_FULL);
250
Tiger Huang52724442020-01-20 21:38:42 +0800251 mWindow.mAttrs.setFitInsetsSides(Side.all());
Tiger Huang4a7835f2019-11-06 00:07:56 +0800252 addWindow(mWindow);
253
254 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
255 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
256
257 assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
258 assertInsetByTopBottom(mWindow.getDisplayFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
259 assertInsetByTopBottom(mWindow.getParentFrame(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
260 assertInsetByTopBottom(mWindow.getVisibleFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
261 assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
262 assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
263 }
264
265 @Test
266 public void layoutWindowLw_fitTopOnly() {
267 assumeTrue(ViewRootImpl.sNewInsetsMode == ViewRootImpl.NEW_INSETS_MODE_FULL);
268
Tiger Huang52724442020-01-20 21:38:42 +0800269 mWindow.mAttrs.setFitInsetsSides(Side.TOP);
Tiger Huang4a7835f2019-11-06 00:07:56 +0800270 addWindow(mWindow);
271
272 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
273 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
274
275 assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
276 assertInsetByTopBottom(mWindow.getDisplayFrameLw(), STATUS_BAR_HEIGHT, 0);
277 assertInsetByTopBottom(mWindow.getParentFrame(), STATUS_BAR_HEIGHT, 0);
278 assertInsetByTopBottom(mWindow.getVisibleFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
279 assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
280 assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
281 }
282
283 @Test
Tiger Huanga86bca92020-02-07 20:18:01 +0800284 public void layoutWindowLw_fitInsetsIgnoringVisibility() {
Tiger Huang4a7835f2019-11-06 00:07:56 +0800285 assumeTrue(ViewRootImpl.sNewInsetsMode == ViewRootImpl.NEW_INSETS_MODE_FULL);
286
287 final InsetsState state =
Tiger Huang82520fc2019-12-19 22:29:20 +0800288 mDisplayContent.getInsetsPolicy().getInsetsForDispatch(mWindow);
Tiger Huang4a7835f2019-11-06 00:07:56 +0800289 state.getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false);
290 state.getSource(InsetsState.ITYPE_NAVIGATION_BAR).setVisible(false);
Tiger Huang52724442020-01-20 21:38:42 +0800291 mWindow.mAttrs.setFitInsetsIgnoringVisibility(true);
Tiger Huang4a7835f2019-11-06 00:07:56 +0800292 addWindow(mWindow);
293
294 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
295 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
296
297 assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
298 assertInsetByTopBottom(mWindow.getDisplayFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
299 assertInsetByTopBottom(mWindow.getParentFrame(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
300 assertInsetByTopBottom(mWindow.getVisibleFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
301 assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
302 assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
303 }
304
305 @Test
Tiger Huanga86bca92020-02-07 20:18:01 +0800306 public void layoutWindowLw_fitInsetsNotIgnoringVisibility() {
Tiger Huang4a7835f2019-11-06 00:07:56 +0800307 assumeTrue(ViewRootImpl.sNewInsetsMode == ViewRootImpl.NEW_INSETS_MODE_FULL);
308
309 final InsetsState state =
Tiger Huang82520fc2019-12-19 22:29:20 +0800310 mDisplayContent.getInsetsPolicy().getInsetsForDispatch(mWindow);
Tiger Huang4a7835f2019-11-06 00:07:56 +0800311 state.getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false);
312 state.getSource(InsetsState.ITYPE_NAVIGATION_BAR).setVisible(false);
Tiger Huang52724442020-01-20 21:38:42 +0800313 mWindow.mAttrs.setFitInsetsIgnoringVisibility(false);
Tiger Huang4a7835f2019-11-06 00:07:56 +0800314 addWindow(mWindow);
315
316 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
317 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
318
319 assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
320 assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, 0);
321 assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
322 assertInsetByTopBottom(mWindow.getVisibleFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
323 assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
324 assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
325 }
326
Tiger Huange16645a2020-02-25 22:24:39 +0800327 @Test
328 public void layoutWindowLw_fitDisplayCutout() {
329 assumeTrue(ViewRootImpl.sNewInsetsMode == ViewRootImpl.NEW_INSETS_MODE_FULL);
330 addDisplayCutout();
331
332 mWindow.mAttrs.setFitInsetsTypes(Type.displayCutout());
333 mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
334 addWindow(mWindow);
335
336 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
337 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
338
339 assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
340 assertInsetByTopBottom(mWindow.getDisplayFrameLw(), DISPLAY_CUTOUT_HEIGHT, 0);
341 assertInsetByTopBottom(mWindow.getParentFrame(), DISPLAY_CUTOUT_HEIGHT, 0);
342 assertInsetByTopBottom(mWindow.getVisibleFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
343 assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
344 assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
345 }
346
Charles Chen64172bb2019-04-22 17:30:29 +0800347 @Test
Tiger Huang7c610aa2018-10-27 00:01:01 +0800348 public void layoutWindowLw_withDisplayCutout() {
Riddle Hsu73f53572019-09-23 23:13:01 +0800349 addDisplayCutout();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800350
Tiger Huang4a7835f2019-11-06 00:07:56 +0800351 mWindow.mAttrs.flags =
352 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
Tiger Huanga86bca92020-02-07 20:18:01 +0800353 mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
Riddle Hsu73f53572019-09-23 23:13:01 +0800354 addWindow(mWindow);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800355
Riddle Hsu73f53572019-09-23 23:13:01 +0800356 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
357 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800358
Riddle Hsu73f53572019-09-23 23:13:01 +0800359 assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
360 assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
361 assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
362 assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
363 assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, 0);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800364 }
365
366 @Test
367 public void layoutWindowLw_withDisplayCutout_never() {
Riddle Hsu73f53572019-09-23 23:13:01 +0800368 addDisplayCutout();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800369
Tiger Huang4a7835f2019-11-06 00:07:56 +0800370 mWindow.mAttrs.flags =
371 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
Tiger Huanga86bca92020-02-07 20:18:01 +0800372 mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
Riddle Hsu73f53572019-09-23 23:13:01 +0800373 mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
374 addWindow(mWindow);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800375
Riddle Hsu73f53572019-09-23 23:13:01 +0800376 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
377 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800378
Riddle Hsu73f53572019-09-23 23:13:01 +0800379 assertInsetByTopBottom(mWindow.getParentFrame(), STATUS_BAR_HEIGHT, 0);
380 assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
381 assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
382 assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
383 assertInsetByTopBottom(mWindow.getDisplayFrameLw(), STATUS_BAR_HEIGHT, 0);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800384 }
385
386 @Test
shawnlin465b7de2020-02-11 20:45:35 +0800387 public void layoutWindowLw_withDisplayCutout_shortEdges() {
388 addDisplayCutout();
389
390 mWindow.mAttrs.flags =
391 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
392 mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
393 mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
394 addWindow(mWindow);
395
396 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
397 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
398
399 assertInsetBy(mWindow.getParentFrame(), 0, 0, 0, 0);
400 assertInsetBy(mWindow.getStableFrameLw(), 0, STATUS_BAR_HEIGHT, 0, NAV_BAR_HEIGHT);
401 assertInsetBy(mWindow.getContentFrameLw(), 0, STATUS_BAR_HEIGHT, 0, NAV_BAR_HEIGHT);
402 assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
403 assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, 0, 0);
404 }
405
406 @Test
407 public void layoutWindowLw_withDisplayCutout_always() {
408 addDisplayCutout();
409
410 mWindow.mAttrs.flags =
411 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
412 mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
413 mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
414 addWindow(mWindow);
415
416 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
417 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
418
419 assertInsetBy(mWindow.getParentFrame(), 0, 0, 0, 0);
420 assertInsetBy(mWindow.getStableFrameLw(), 0, STATUS_BAR_HEIGHT, 0, NAV_BAR_HEIGHT);
421 assertInsetBy(mWindow.getContentFrameLw(), 0, STATUS_BAR_HEIGHT, 0, NAV_BAR_HEIGHT);
422 assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
423 assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, 0, 0);
424 }
425
426 @Test
Tiger Huang7c610aa2018-10-27 00:01:01 +0800427 public void layoutWindowLw_withDisplayCutout_layoutFullscreen() {
Riddle Hsu73f53572019-09-23 23:13:01 +0800428 addDisplayCutout();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800429
Tiger Huang4a7835f2019-11-06 00:07:56 +0800430 mWindow.mAttrs.flags =
431 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
Tiger Huanga86bca92020-02-07 20:18:01 +0800432 mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
Riddle Hsu73f53572019-09-23 23:13:01 +0800433 mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
Tiger Huang52724442020-01-20 21:38:42 +0800434 mWindow.mAttrs.setFitInsetsTypes(
435 mWindow.mAttrs.getFitInsetsTypes() & ~Type.statusBars());
Riddle Hsu73f53572019-09-23 23:13:01 +0800436 addWindow(mWindow);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800437
Riddle Hsu73f53572019-09-23 23:13:01 +0800438 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
439 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800440
Riddle Hsu73f53572019-09-23 23:13:01 +0800441 assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
442 assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
443 assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
444 assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
Tiger Huang4a7835f2019-11-06 00:07:56 +0800445 assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, 0);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800446 }
447
448 @Test
449 public void layoutWindowLw_withDisplayCutout_fullscreen() {
Riddle Hsu73f53572019-09-23 23:13:01 +0800450 addDisplayCutout();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800451
Tiger Huang4a7835f2019-11-06 00:07:56 +0800452 mWindow.mAttrs.flags =
453 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
Tiger Huanga86bca92020-02-07 20:18:01 +0800454 mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
Riddle Hsu73f53572019-09-23 23:13:01 +0800455 mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_FULLSCREEN;
Tiger Huang82520fc2019-12-19 22:29:20 +0800456 mDisplayContent.getInsetsPolicy().getInsetsForDispatch(mWindow)
Tiger Huang4a7835f2019-11-06 00:07:56 +0800457 .getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false);
Riddle Hsu73f53572019-09-23 23:13:01 +0800458 addWindow(mWindow);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800459
Riddle Hsu73f53572019-09-23 23:13:01 +0800460 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
461 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800462
Riddle Hsu73f53572019-09-23 23:13:01 +0800463 assertInsetByTopBottom(mWindow.getParentFrame(), STATUS_BAR_HEIGHT, 0);
464 assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
465 assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
466 assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
467 assertInsetByTopBottom(mWindow.getDisplayFrameLw(), STATUS_BAR_HEIGHT, 0);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800468 }
469
470 @Test
471 public void layoutWindowLw_withDisplayCutout_fullscreenInCutout() {
Riddle Hsu73f53572019-09-23 23:13:01 +0800472 addDisplayCutout();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800473
Tiger Huang4a7835f2019-11-06 00:07:56 +0800474 mWindow.mAttrs.flags =
475 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
Tiger Huanga86bca92020-02-07 20:18:01 +0800476 mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
Riddle Hsu73f53572019-09-23 23:13:01 +0800477 mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_FULLSCREEN;
Tiger Huang82520fc2019-12-19 22:29:20 +0800478 mDisplayContent.getInsetsPolicy().getInsetsForDispatch(mWindow)
Tiger Huang4a7835f2019-11-06 00:07:56 +0800479 .getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false);
Riddle Hsu73f53572019-09-23 23:13:01 +0800480 mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
481 addWindow(mWindow);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800482
Riddle Hsu73f53572019-09-23 23:13:01 +0800483 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
484 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800485
Riddle Hsu73f53572019-09-23 23:13:01 +0800486 assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
487 assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
488 assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
489 assertInsetByTopBottom(mWindow.getDecorFrame(), 0, 0);
490 assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, 0);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800491 }
492
493
494 @Test
495 public void layoutWindowLw_withDisplayCutout_landscape() {
Riddle Hsu73f53572019-09-23 23:13:01 +0800496 addDisplayCutout();
497 setRotation(ROTATION_90);
Tiger Huang4a7835f2019-11-06 00:07:56 +0800498
499 mWindow.mAttrs.flags =
500 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
Tiger Huanga86bca92020-02-07 20:18:01 +0800501 mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
Riddle Hsu73f53572019-09-23 23:13:01 +0800502 addWindow(mWindow);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800503
Riddle Hsu73f53572019-09-23 23:13:01 +0800504 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
505 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800506
Riddle Hsu73f53572019-09-23 23:13:01 +0800507 assertInsetBy(mWindow.getParentFrame(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
508 assertInsetBy(mWindow.getStableFrameLw(), 0, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
509 assertInsetBy(mWindow.getContentFrameLw(),
510 DISPLAY_CUTOUT_HEIGHT, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
511 assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
512 assertInsetBy(mWindow.getDisplayFrameLw(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800513 }
514
515 @Test
516 public void layoutWindowLw_withDisplayCutout_seascape() {
Riddle Hsu73f53572019-09-23 23:13:01 +0800517 addDisplayCutout();
518 setRotation(ROTATION_270);
Tiger Huang4a7835f2019-11-06 00:07:56 +0800519
520 mWindow.mAttrs.flags =
521 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
Tiger Huanga86bca92020-02-07 20:18:01 +0800522 mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
Riddle Hsu73f53572019-09-23 23:13:01 +0800523 addWindow(mWindow);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800524
Riddle Hsu73f53572019-09-23 23:13:01 +0800525 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
526 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800527
Riddle Hsu73f53572019-09-23 23:13:01 +0800528 assertInsetBy(mWindow.getParentFrame(), 0, 0, DISPLAY_CUTOUT_HEIGHT, 0);
529 assertInsetBy(mWindow.getStableFrameLw(), NAV_BAR_HEIGHT, STATUS_BAR_HEIGHT, 0, 0);
530 assertInsetBy(mWindow.getContentFrameLw(),
531 NAV_BAR_HEIGHT, STATUS_BAR_HEIGHT, DISPLAY_CUTOUT_HEIGHT, 0);
532 assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
533 assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, DISPLAY_CUTOUT_HEIGHT, 0);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800534 }
535
536 @Test
537 public void layoutWindowLw_withDisplayCutout_fullscreen_landscape() {
Riddle Hsu73f53572019-09-23 23:13:01 +0800538 addDisplayCutout();
539 setRotation(ROTATION_90);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800540
Tiger Huang4a7835f2019-11-06 00:07:56 +0800541 mWindow.mAttrs.flags =
542 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
Tiger Huanga86bca92020-02-07 20:18:01 +0800543 mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
Riddle Hsu73f53572019-09-23 23:13:01 +0800544 mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
Tiger Huang52724442020-01-20 21:38:42 +0800545 mWindow.mAttrs.setFitInsetsTypes(
546 mWindow.mAttrs.getFitInsetsTypes() & ~Type.statusBars());
Riddle Hsu73f53572019-09-23 23:13:01 +0800547 addWindow(mWindow);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800548
Riddle Hsu73f53572019-09-23 23:13:01 +0800549 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
550 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800551
Riddle Hsu73f53572019-09-23 23:13:01 +0800552 assertInsetBy(mWindow.getParentFrame(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
553 assertInsetBy(mWindow.getStableFrameLw(), 0, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
554 assertInsetBy(mWindow.getContentFrameLw(),
555 DISPLAY_CUTOUT_HEIGHT, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
556 assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800557 }
558
559 @Test
560 public void layoutWindowLw_withDisplayCutout_floatingInScreen() {
Riddle Hsu73f53572019-09-23 23:13:01 +0800561 addDisplayCutout();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800562
Riddle Hsu73f53572019-09-23 23:13:01 +0800563 mWindow.mAttrs.flags = FLAG_LAYOUT_IN_SCREEN;
Tiger Huang52724442020-01-20 21:38:42 +0800564 mWindow.mAttrs.setFitInsetsTypes(Type.systemBars() & ~Type.statusBars());
Riddle Hsu73f53572019-09-23 23:13:01 +0800565 mWindow.mAttrs.type = TYPE_APPLICATION_OVERLAY;
566 mWindow.mAttrs.width = DISPLAY_WIDTH;
567 mWindow.mAttrs.height = DISPLAY_HEIGHT;
568 addWindow(mWindow);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800569
Riddle Hsu73f53572019-09-23 23:13:01 +0800570 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
571 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800572
Riddle Hsu73f53572019-09-23 23:13:01 +0800573 assertInsetByTopBottom(mWindow.getParentFrame(), 0, NAV_BAR_HEIGHT);
574 assertInsetByTopBottom(mWindow.getDisplayFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800575 }
576
577 @Test
578 public void layoutWindowLw_withDisplayCutout_fullscreenInCutout_landscape() {
Riddle Hsu73f53572019-09-23 23:13:01 +0800579 addDisplayCutout();
580 setRotation(ROTATION_90);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800581
Tiger Huang4a7835f2019-11-06 00:07:56 +0800582 mWindow.mAttrs.flags =
583 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
Tiger Huanga86bca92020-02-07 20:18:01 +0800584 mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
Riddle Hsu73f53572019-09-23 23:13:01 +0800585 mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
Tiger Huang52724442020-01-20 21:38:42 +0800586 mWindow.mAttrs.setFitInsetsTypes(
587 mWindow.mAttrs.getFitInsetsTypes() & ~Type.statusBars());
Riddle Hsu73f53572019-09-23 23:13:01 +0800588 mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
589 addWindow(mWindow);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800590
Riddle Hsu73f53572019-09-23 23:13:01 +0800591 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
592 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800593
Riddle Hsu73f53572019-09-23 23:13:01 +0800594 assertInsetBy(mWindow.getParentFrame(), 0, 0, 0, 0);
595 assertInsetBy(mWindow.getStableFrameLw(), 0, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
596 assertInsetBy(mWindow.getContentFrameLw(),
597 DISPLAY_CUTOUT_HEIGHT, STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT, 0);
598 assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800599 }
600
601 @Test
shawnlin465b7de2020-02-11 20:45:35 +0800602 public void layoutWindowLw_withLongEdgeDisplayCutout() {
603 addLongEdgeDisplayCutout();
604
605 mWindow.mAttrs.flags =
606 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
shawnline9e801e2020-02-19 19:53:48 +0800607 mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
shawnlin465b7de2020-02-11 20:45:35 +0800608 addWindow(mWindow);
609
610 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
611 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
612
613 assertInsetBy(mWindow.getParentFrame(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
614 assertInsetBy(mWindow.getStableFrameLw(), 0, STATUS_BAR_HEIGHT, 0, NAV_BAR_HEIGHT);
615 assertInsetBy(mWindow.getContentFrameLw(), DISPLAY_CUTOUT_HEIGHT, STATUS_BAR_HEIGHT, 0,
616 NAV_BAR_HEIGHT);
617 assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
618 assertInsetBy(mWindow.getDisplayFrameLw(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
619 }
620
621 @Test
622 public void layoutWindowLw_withLongEdgeDisplayCutout_never() {
623 addLongEdgeDisplayCutout();
624
625 mWindow.mAttrs.flags =
626 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
shawnline9e801e2020-02-19 19:53:48 +0800627 mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
shawnlin465b7de2020-02-11 20:45:35 +0800628 mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
629 addWindow(mWindow);
630
631 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
632 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
633
634 assertInsetBy(mWindow.getParentFrame(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
635 assertInsetBy(mWindow.getStableFrameLw(), 0, STATUS_BAR_HEIGHT, 0,
636 NAV_BAR_HEIGHT);
637 assertInsetBy(mWindow.getContentFrameLw(), DISPLAY_CUTOUT_HEIGHT, STATUS_BAR_HEIGHT, 0,
638 NAV_BAR_HEIGHT);
639 assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
640 assertInsetBy(mWindow.getDisplayFrameLw(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
641 }
642
643 @Test
644 public void layoutWindowLw_withLongEdgeDisplayCutout_shortEdges() {
645 addLongEdgeDisplayCutout();
646
647 mWindow.mAttrs.flags =
648 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
649 mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
650 mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
651 addWindow(mWindow);
652
653 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
654 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
655
656 assertInsetBy(mWindow.getParentFrame(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
657 assertInsetBy(mWindow.getStableFrameLw(), 0, STATUS_BAR_HEIGHT, 0, NAV_BAR_HEIGHT);
658 assertInsetBy(mWindow.getContentFrameLw(), DISPLAY_CUTOUT_HEIGHT, STATUS_BAR_HEIGHT, 0,
659 NAV_BAR_HEIGHT);
660 assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
661 assertInsetBy(mWindow.getDisplayFrameLw(), DISPLAY_CUTOUT_HEIGHT, 0, 0, 0);
662 }
663
664 @Test
665 public void layoutWindowLw_withLongEdgeDisplayCutout_always() {
666 addLongEdgeDisplayCutout();
667
668 mWindow.mAttrs.flags =
669 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
670 mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
671 mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
672 addWindow(mWindow);
673
674 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
675 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
676
677 assertInsetBy(mWindow.getParentFrame(), 0, 0, 0, 0);
678 assertInsetBy(mWindow.getStableFrameLw(), 0, STATUS_BAR_HEIGHT, 0, NAV_BAR_HEIGHT);
679 assertInsetBy(mWindow.getContentFrameLw(), DISPLAY_CUTOUT_HEIGHT, STATUS_BAR_HEIGHT, 0,
680 NAV_BAR_HEIGHT);
681 assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
682 assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, 0, 0);
683 }
684
685 @Test
Issei Suzukia5dbf522019-02-01 17:58:15 +0100686 public void layoutWindowLw_withForwardInset_SoftInputAdjustResize() {
Tarandeep Singh24f04662020-01-06 16:48:46 -0800687 assumeTrue(ViewRootImpl.sNewInsetsMode == ViewRootImpl.NEW_INSETS_MODE_NONE);
688
Tiger Huang4a7835f2019-11-06 00:07:56 +0800689 mWindow.mAttrs.flags =
690 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
Tiger Huanga86bca92020-02-07 20:18:01 +0800691 mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
Riddle Hsu73f53572019-09-23 23:13:01 +0800692 mWindow.mAttrs.softInputMode = SOFT_INPUT_ADJUST_RESIZE;
693 addWindow(mWindow);
Issei Suzukia5dbf522019-02-01 17:58:15 +0100694
Riddle Hsu73f53572019-09-23 23:13:01 +0800695 final int forwardedInsetBottom = 50;
696 mDisplayPolicy.setForwardedInsets(Insets.of(0, 0, 0, forwardedInsetBottom));
697 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
698 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
Issei Suzukia5dbf522019-02-01 17:58:15 +0100699
Riddle Hsu73f53572019-09-23 23:13:01 +0800700 assertInsetBy(mWindow.getParentFrame(), 0, 0, 0, 0);
701 assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
702 assertInsetByTopBottom(mWindow.getContentFrameLw(),
703 STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT + forwardedInsetBottom);
704 assertInsetByTopBottom(mWindow.getVisibleFrameLw(),
705 STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT + forwardedInsetBottom);
706 assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
707 assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, 0, 0);
Issei Suzukia5dbf522019-02-01 17:58:15 +0100708 }
709
710 @Test
711 public void layoutWindowLw_withForwardInset_SoftInputAdjustNothing() {
Tiger Huang4a7835f2019-11-06 00:07:56 +0800712 mWindow.mAttrs.flags =
713 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
Tiger Huanga86bca92020-02-07 20:18:01 +0800714 mWindow.mAttrs.setFitInsetsTypes(0 /* types */);
Riddle Hsu73f53572019-09-23 23:13:01 +0800715 mWindow.mAttrs.softInputMode = SOFT_INPUT_ADJUST_NOTHING;
716 addWindow(mWindow);
Issei Suzukia5dbf522019-02-01 17:58:15 +0100717
Riddle Hsu73f53572019-09-23 23:13:01 +0800718 final int forwardedInsetBottom = 50;
719 mDisplayPolicy.setForwardedInsets(Insets.of(0, 0, 0, forwardedInsetBottom));
720 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
721 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
Issei Suzukia5dbf522019-02-01 17:58:15 +0100722
Riddle Hsu73f53572019-09-23 23:13:01 +0800723 assertInsetBy(mWindow.getParentFrame(), 0, 0, 0, 0);
724 assertInsetByTopBottom(mWindow.getStableFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
725 assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
726 assertInsetByTopBottom(mWindow.getVisibleFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
727 assertInsetBy(mWindow.getDecorFrame(), 0, 0, 0, 0);
728 assertInsetBy(mWindow.getDisplayFrameLw(), 0, 0, 0, 0);
Issei Suzukia5dbf522019-02-01 17:58:15 +0100729 }
730
Tiger Huang4a7835f2019-11-06 00:07:56 +0800731 // TODO(b/118118435): remove after removing PolicyControl
Yongjin Kwon2fe07262019-09-03 10:47:28 +0900732 @FlakyTest(bugId = 129711077)
733 @Test
734 public void layoutWindowLw_withImmersive_SoftInputAdjustResize() {
Tiger Huang4a7835f2019-11-06 00:07:56 +0800735 assumeTrue(ViewRootImpl.sNewInsetsMode != ViewRootImpl.NEW_INSETS_MODE_FULL);
736
Yongjin Kwon2fe07262019-09-03 10:47:28 +0900737 synchronized (mWm.mGlobalLock) {
738 mWindow.mAttrs.softInputMode = SOFT_INPUT_ADJUST_RESIZE;
739 mWindow.mAttrs.flags = 0;
740 mWindow.mAttrs.systemUiVisibility =
741 SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
742 | SYSTEM_UI_FLAG_FULLSCREEN | SYSTEM_UI_FLAG_HIDE_NAVIGATION;
743
744 addWindow(mWindow);
745
746 mWindow.getDisplayContent().mInputMethodTarget = mWindow;
747 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
748 mFrames.mContent.bottom = mFrames.mVoiceContent.bottom = INPUT_METHOD_WINDOW_TOP;
749 mFrames.mCurrent.bottom = INPUT_METHOD_WINDOW_TOP;
750 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
751
752 int bottomInset = mFrames.mDisplayHeight - INPUT_METHOD_WINDOW_TOP;
753 assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
754 assertInsetByTopBottom(mWindow.getContentFrameLw(), 0, 0);
755 assertInsetByTopBottom(mWindow.getVisibleFrameLw(), STATUS_BAR_HEIGHT, bottomInset);
756 }
757 }
758
Tiger Huang4a7835f2019-11-06 00:07:56 +0800759 // TODO(b/118118435): remove after removing PolicyControl
Yongjin Kwon2fe07262019-09-03 10:47:28 +0900760 @FlakyTest(bugId = 129711077)
761 @Test
762 public void layoutWindowLw_withImmersive_SoftInputAdjustNothing() {
Tiger Huang4a7835f2019-11-06 00:07:56 +0800763 assumeTrue(ViewRootImpl.sNewInsetsMode != ViewRootImpl.NEW_INSETS_MODE_FULL);
764
Yongjin Kwon2fe07262019-09-03 10:47:28 +0900765 synchronized (mWm.mGlobalLock) {
766 mWindow.mAttrs.softInputMode = SOFT_INPUT_ADJUST_NOTHING;
767 mWindow.mAttrs.flags = 0;
768 mWindow.mAttrs.systemUiVisibility =
769 SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
770 | SYSTEM_UI_FLAG_FULLSCREEN | SYSTEM_UI_FLAG_HIDE_NAVIGATION;
771
772 addWindow(mWindow);
773
774 mWindow.getDisplayContent().mInputMethodTarget = mWindow;
775 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
776 mFrames.mContent.bottom = mFrames.mVoiceContent.bottom = INPUT_METHOD_WINDOW_TOP;
777 mFrames.mCurrent.bottom = INPUT_METHOD_WINDOW_TOP;
778 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
779
780 assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
781 assertInsetByTopBottom(mWindow.getContentFrameLw(), 0, 0);
782 assertInsetByTopBottom(mWindow.getVisibleFrameLw(), 0, 0);
783 }
784 }
785
Tiger Huang4a7835f2019-11-06 00:07:56 +0800786 // TODO(b/118118435): remove after removing PolicyControl
Yongjin Kwon2fe07262019-09-03 10:47:28 +0900787 @FlakyTest(bugId = 129711077)
788 @Test
789 public void layoutWindowLw_withForceImmersive_fullscreen() {
Tiger Huang4a7835f2019-11-06 00:07:56 +0800790 assumeTrue(ViewRootImpl.sNewInsetsMode != ViewRootImpl.NEW_INSETS_MODE_FULL);
791
Yongjin Kwon2fe07262019-09-03 10:47:28 +0900792 synchronized (mWm.mGlobalLock) {
793 mWindow.mAttrs.softInputMode = SOFT_INPUT_ADJUST_RESIZE;
794 mWindow.mAttrs.flags = 0;
795 mWindow.mAttrs.systemUiVisibility = 0;
796 PolicyControl.setFilters(PolicyControl.NAME_IMMERSIVE_FULL + "=*");
797
798 addWindow(mWindow);
799
800 mWindow.getDisplayContent().mInputMethodTarget = mWindow;
801 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
802 mFrames.mContent.bottom = mFrames.mVoiceContent.bottom = INPUT_METHOD_WINDOW_TOP;
803 mFrames.mCurrent.bottom = INPUT_METHOD_WINDOW_TOP;
804 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
805
806 int bottomInset = mFrames.mDisplayHeight - INPUT_METHOD_WINDOW_TOP;
807 assertInsetByTopBottom(mWindow.getParentFrame(), 0, 0);
808 assertInsetByTopBottom(mWindow.getContentFrameLw(), 0, 0);
809 assertInsetByTopBottom(mWindow.getVisibleFrameLw(), STATUS_BAR_HEIGHT, bottomInset);
810 }
811 }
812
Tiger Huang4a7835f2019-11-06 00:07:56 +0800813 // TODO(b/118118435): remove after removing PolicyControl
Yongjin Kwon2fe07262019-09-03 10:47:28 +0900814 @FlakyTest(bugId = 129711077)
815 @Test
816 public void layoutWindowLw_withForceImmersive_nonFullscreen() {
Tiger Huang4a7835f2019-11-06 00:07:56 +0800817 assumeTrue(ViewRootImpl.sNewInsetsMode != ViewRootImpl.NEW_INSETS_MODE_FULL);
818
Yongjin Kwon2fe07262019-09-03 10:47:28 +0900819 synchronized (mWm.mGlobalLock) {
820 mWindow.mAttrs.softInputMode = SOFT_INPUT_ADJUST_RESIZE;
821 mWindow.mAttrs.flags = 0;
822 mWindow.mAttrs.systemUiVisibility = 0;
823 mWindow.mAttrs.width = DISPLAY_WIDTH / 2;
824 mWindow.mAttrs.height = DISPLAY_HEIGHT / 2;
825 PolicyControl.setFilters(PolicyControl.NAME_IMMERSIVE_FULL + "=*");
826
827 addWindow(mWindow);
828
829 mWindow.getDisplayContent().mInputMethodTarget = mWindow;
830 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
831 mFrames.mContent.bottom = mFrames.mVoiceContent.bottom = INPUT_METHOD_WINDOW_TOP;
832 mFrames.mCurrent.bottom = INPUT_METHOD_WINDOW_TOP;
833 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
834
835 int bottomInset = mFrames.mDisplayHeight - INPUT_METHOD_WINDOW_TOP;
836 assertInsetByTopBottom(mWindow.getParentFrame(), STATUS_BAR_HEIGHT, bottomInset);
837 assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, bottomInset);
838 assertInsetByTopBottom(mWindow.getVisibleFrameLw(), STATUS_BAR_HEIGHT, bottomInset);
839 }
840 }
841
Issei Suzukia5dbf522019-02-01 17:58:15 +0100842 @Test
Tiger Huang7c610aa2018-10-27 00:01:01 +0800843 public void layoutHint_appWindow() {
Tiger Huang4a7835f2019-11-06 00:07:56 +0800844 mWindow.mAttrs.flags =
845 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
846
Riddle Hsu73f53572019-09-23 23:13:01 +0800847 // Initialize DisplayFrames
848 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800849
Riddle Hsu73f53572019-09-23 23:13:01 +0800850 final Rect outFrame = new Rect();
851 final Rect outContentInsets = new Rect();
852 final Rect outStableInsets = new Rect();
Riddle Hsu73f53572019-09-23 23:13:01 +0800853 final DisplayCutout.ParcelableWrapper outDisplayCutout =
854 new DisplayCutout.ParcelableWrapper();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800855
Riddle Hsu55d7c402020-02-26 22:49:29 +0800856 mDisplayPolicy.getLayoutHint(mWindow.mAttrs, null /* windowToken */, outFrame,
857 outContentInsets, outStableInsets, outDisplayCutout);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800858
Riddle Hsu73f53572019-09-23 23:13:01 +0800859 assertThat(outFrame, is(mFrames.mUnrestricted));
860 assertThat(outContentInsets, is(new Rect(0, STATUS_BAR_HEIGHT, 0, NAV_BAR_HEIGHT)));
861 assertThat(outStableInsets, is(new Rect(0, STATUS_BAR_HEIGHT, 0, NAV_BAR_HEIGHT)));
Riddle Hsu73f53572019-09-23 23:13:01 +0800862 assertThat(outDisplayCutout, is(new DisplayCutout.ParcelableWrapper()));
Tiger Huang7c610aa2018-10-27 00:01:01 +0800863 }
864
865 @Test
866 public void layoutHint_appWindowInTask() {
Tiger Huang4a7835f2019-11-06 00:07:56 +0800867 mWindow.mAttrs.flags =
868 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
869
Riddle Hsu73f53572019-09-23 23:13:01 +0800870 // Initialize DisplayFrames
871 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800872
Riddle Hsu73f53572019-09-23 23:13:01 +0800873 final Rect taskBounds = new Rect(100, 100, 200, 200);
Riddle Hsu55d7c402020-02-26 22:49:29 +0800874 final Task task = mWindow.getTask();
875 // Force the bounds because the task may resolve different bounds from Task#setBounds.
876 task.getWindowConfiguration().setBounds(taskBounds);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800877
Riddle Hsu73f53572019-09-23 23:13:01 +0800878 final Rect outFrame = new Rect();
879 final Rect outContentInsets = new Rect();
880 final Rect outStableInsets = new Rect();
Riddle Hsu73f53572019-09-23 23:13:01 +0800881 final DisplayCutout.ParcelableWrapper outDisplayCutout =
882 new DisplayCutout.ParcelableWrapper();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800883
Riddle Hsu55d7c402020-02-26 22:49:29 +0800884 mDisplayPolicy.getLayoutHint(mWindow.mAttrs, mWindow.mToken, outFrame,
885 outContentInsets, outStableInsets, outDisplayCutout);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800886
Riddle Hsu73f53572019-09-23 23:13:01 +0800887 assertThat(outFrame, is(taskBounds));
888 assertThat(outContentInsets, is(new Rect()));
889 assertThat(outStableInsets, is(new Rect()));
Riddle Hsu73f53572019-09-23 23:13:01 +0800890 assertThat(outDisplayCutout, is(new DisplayCutout.ParcelableWrapper()));
Tiger Huang7c610aa2018-10-27 00:01:01 +0800891 }
892
893 @Test
894 public void layoutHint_appWindowInTask_outsideContentFrame() {
Tiger Huang4a7835f2019-11-06 00:07:56 +0800895 mWindow.mAttrs.flags =
896 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
897
Riddle Hsu73f53572019-09-23 23:13:01 +0800898 // Initialize DisplayFrames
899 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800900
Riddle Hsu73f53572019-09-23 23:13:01 +0800901 // Task is in the nav bar area (usually does not happen, but this is similar enough to
902 // the possible overlap with the IME)
903 final Rect taskBounds = new Rect(100, mFrames.mContent.bottom + 1,
904 200, mFrames.mContent.bottom + 10);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800905
Riddle Hsu55d7c402020-02-26 22:49:29 +0800906 final Task task = mWindow.getTask();
907 // Make the task floating.
908 task.setWindowingMode(WindowConfiguration.WINDOWING_MODE_FREEFORM);
909 // Force the bounds because the task may resolve different bounds from Task#setBounds.
910 task.getWindowConfiguration().setBounds(taskBounds);
911
Riddle Hsu73f53572019-09-23 23:13:01 +0800912 final Rect outFrame = new Rect();
913 final Rect outContentInsets = new Rect();
914 final Rect outStableInsets = new Rect();
Riddle Hsu73f53572019-09-23 23:13:01 +0800915 final DisplayCutout.ParcelableWrapper outDisplayCutout =
916 new DisplayCutout.ParcelableWrapper();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800917
Riddle Hsu55d7c402020-02-26 22:49:29 +0800918 mDisplayPolicy.getLayoutHint(mWindow.mAttrs, mWindow.mToken, outFrame, outContentInsets,
919 outStableInsets, outDisplayCutout);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800920
Riddle Hsu73f53572019-09-23 23:13:01 +0800921 assertThat(outFrame, is(taskBounds));
922 assertThat(outContentInsets, is(new Rect()));
923 assertThat(outStableInsets, is(new Rect()));
Riddle Hsu73f53572019-09-23 23:13:01 +0800924 assertThat(outDisplayCutout, is(new DisplayCutout.ParcelableWrapper()));
Tiger Huang7c610aa2018-10-27 00:01:01 +0800925 }
926
Riddle Hsuc7175762020-01-10 21:03:48 +0800927 /**
928 * Verify that {@link DisplayPolicy#simulateLayoutDisplay} outputs the same display frames as
929 * {@link DisplayPolicy#beginLayoutLw}.
930 */
931 @Test
932 public void testSimulateLayoutDisplay() {
933 assertSimulateLayoutSameDisplayFrames();
934 setRotation(ROTATION_90);
935 assertSimulateLayoutSameDisplayFrames();
936 addDisplayCutout();
937 assertSimulateLayoutSameDisplayFrames();
938 }
939
940 private void assertSimulateLayoutSameDisplayFrames() {
941 final int uiMode = 0;
942 final String prefix = "";
943 final InsetsState simulatedInsetsState = new InsetsState();
944 final DisplayFrames simulatedDisplayFrames = createDisplayFrames();
Riddle Hsuc7175762020-01-10 21:03:48 +0800945 mDisplayPolicy.beginLayoutLw(mFrames, uiMode);
Riddle Hsu55d7c402020-02-26 22:49:29 +0800946 // Force the display bounds because it is not synced with display frames in policy test.
947 mDisplayContent.getWindowConfiguration().setBounds(mFrames.mUnrestricted);
Riddle Hsuc7175762020-01-10 21:03:48 +0800948 mDisplayContent.getInsetsStateController().onPostLayout();
949 mDisplayPolicy.simulateLayoutDisplay(simulatedDisplayFrames, simulatedInsetsState, uiMode);
950
951 final StringWriter realFramesDump = new StringWriter();
952 mFrames.dump(prefix, new PrintWriter(realFramesDump));
953 final StringWriter simulatedFramesDump = new StringWriter();
954 simulatedDisplayFrames.dump(prefix, new PrintWriter(simulatedFramesDump));
955
Riddle Hsu55d7c402020-02-26 22:49:29 +0800956 assertEquals(new ToStringComparatorWrapper<>(realFramesDump),
957 new ToStringComparatorWrapper<>(simulatedFramesDump));
Riddle Hsuc7175762020-01-10 21:03:48 +0800958
Riddle Hsuc7175762020-01-10 21:03:48 +0800959 final InsetsState realInsetsState = new InsetsState(
960 mDisplayContent.getInsetsStateController().getRawInsetsState());
961 // Exclude comparing IME insets because currently the simulated layout only focuses on the
962 // insets from status bar and navigation bar.
963 realInsetsState.removeSource(InsetsState.ITYPE_IME);
Tiger Huanga86bca92020-02-07 20:18:01 +0800964 realInsetsState.removeSource(InsetsState.ITYPE_CAPTION_BAR);
Riddle Hsuc7175762020-01-10 21:03:48 +0800965
Riddle Hsu55d7c402020-02-26 22:49:29 +0800966 assertEquals(new ToStringComparatorWrapper<>(realInsetsState),
967 new ToStringComparatorWrapper<>(simulatedInsetsState));
Riddle Hsuc7175762020-01-10 21:03:48 +0800968 }
969
Brad Stenninge0573692019-03-11 13:52:46 -0700970 @Test
971 public void forceShowSystemBars_clearsSystemUIFlags() {
Riddle Hsu73f53572019-09-23 23:13:01 +0800972 mDisplayPolicy.mLastSystemUiFlags |= SYSTEM_UI_FLAG_FULLSCREEN;
973 mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
Tiger Huang4a7835f2019-11-06 00:07:56 +0800974 mWindow.mAttrs.flags =
975 FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
Riddle Hsu73f53572019-09-23 23:13:01 +0800976 mWindow.mSystemUiVisibility = SYSTEM_UI_FLAG_FULLSCREEN;
977 mDisplayPolicy.setForceShowSystemBars(true);
978 addWindow(mWindow);
Brad Stenninge0573692019-03-11 13:52:46 -0700979
Riddle Hsu73f53572019-09-23 23:13:01 +0800980 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
981 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
982 // triggers updateSystemUiVisibilityLw which will reset the flags as needed
983 int finishPostLayoutPolicyLw = mDisplayPolicy.focusChangedLw(mWindow, mWindow);
Brad Stenninge0573692019-03-11 13:52:46 -0700984
Riddle Hsu73f53572019-09-23 23:13:01 +0800985 assertEquals(WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT, finishPostLayoutPolicyLw);
986 assertEquals(0, mDisplayPolicy.mLastSystemUiFlags);
987 assertEquals(0, mWindow.mAttrs.systemUiVisibility);
988 assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
Brad Stenninge0573692019-03-11 13:52:46 -0700989 }
990
chaviw0d833762019-06-20 17:09:53 -0700991 @Test
992 public void testScreenDecorWindows() {
Riddle Hsu73f53572019-09-23 23:13:01 +0800993 final WindowState decorWindow = createWindow(null, TYPE_APPLICATION_OVERLAY, "decorWindow");
Tiger Huang4a7835f2019-11-06 00:07:56 +0800994 mWindow.mAttrs.flags = FLAG_NOT_FOCUSABLE | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR
995 | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
Riddle Hsu73f53572019-09-23 23:13:01 +0800996 decorWindow.mAttrs.privateFlags |= PRIVATE_FLAG_IS_SCREEN_DECOR;
997 addWindow(decorWindow);
998 addWindow(mWindow);
chaviw0d833762019-06-20 17:09:53 -0700999
Riddle Hsu73f53572019-09-23 23:13:01 +08001000 // Decor on top
1001 updateDecorWindow(decorWindow, MATCH_PARENT, DECOR_WINDOW_INSET, TOP);
1002 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
1003 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
1004 assertInsetByTopBottom(mWindow.getContentFrameLw(), DECOR_WINDOW_INSET, NAV_BAR_HEIGHT);
chaviw0d833762019-06-20 17:09:53 -07001005
Riddle Hsu73f53572019-09-23 23:13:01 +08001006 // Decor on bottom
1007 updateDecorWindow(decorWindow, MATCH_PARENT, DECOR_WINDOW_INSET, BOTTOM);
1008 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
1009 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
1010 assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT,
1011 DECOR_WINDOW_INSET);
chaviw0d833762019-06-20 17:09:53 -07001012
Riddle Hsu73f53572019-09-23 23:13:01 +08001013 // Decor on the left
1014 updateDecorWindow(decorWindow, DECOR_WINDOW_INSET, MATCH_PARENT, LEFT);
1015 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
1016 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
1017 assertInsetBy(mWindow.getContentFrameLw(), DECOR_WINDOW_INSET, STATUS_BAR_HEIGHT, 0,
1018 NAV_BAR_HEIGHT);
chaviw0d833762019-06-20 17:09:53 -07001019
Riddle Hsu73f53572019-09-23 23:13:01 +08001020 // Decor on the right
1021 updateDecorWindow(decorWindow, DECOR_WINDOW_INSET, MATCH_PARENT, RIGHT);
1022 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
1023 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
1024 assertInsetBy(mWindow.getContentFrameLw(), 0, STATUS_BAR_HEIGHT, DECOR_WINDOW_INSET,
1025 NAV_BAR_HEIGHT);
chaviw0d833762019-06-20 17:09:53 -07001026
Riddle Hsu73f53572019-09-23 23:13:01 +08001027 // Decor not allowed as inset
1028 updateDecorWindow(decorWindow, DECOR_WINDOW_INSET, DECOR_WINDOW_INSET, TOP);
1029 mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */);
1030 mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames);
1031 assertInsetByTopBottom(mWindow.getContentFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT);
chaviw0d833762019-06-20 17:09:53 -07001032 }
1033
1034 private void updateDecorWindow(WindowState decorWindow, int width, int height, int gravity) {
1035 decorWindow.mAttrs.width = width;
1036 decorWindow.mAttrs.height = height;
1037 decorWindow.mAttrs.gravity = gravity;
1038 decorWindow.setRequestedSize(width, height);
1039 }
1040
Tiger Huang7c610aa2018-10-27 00:01:01 +08001041 /**
1042 * Asserts that {@code actual} is inset by the given amounts from the full display rect.
1043 *
1044 * Convenience wrapper for when only the top and bottom inset are non-zero.
1045 */
1046 private void assertInsetByTopBottom(Rect actual, int expectedInsetTop,
1047 int expectedInsetBottom) {
1048 assertInsetBy(actual, 0, expectedInsetTop, 0, expectedInsetBottom);
1049 }
1050
1051 /** Asserts that {@code actual} is inset by the given amounts from the full display rect. */
1052 private void assertInsetBy(Rect actual, int expectedInsetLeft, int expectedInsetTop,
1053 int expectedInsetRight, int expectedInsetBottom) {
1054 assertEquals(new Rect(expectedInsetLeft, expectedInsetTop,
1055 mFrames.mDisplayWidth - expectedInsetRight,
1056 mFrames.mDisplayHeight - expectedInsetBottom), actual);
1057 }
1058}