Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
chaviw | 0d83376 | 2019-06-20 17:09:53 -0700 | [diff] [blame] | 19 | import static android.view.Gravity.BOTTOM; |
| 20 | import static android.view.Gravity.LEFT; |
| 21 | import static android.view.Gravity.RIGHT; |
| 22 | import static android.view.Gravity.TOP; |
Yuncheol Heo | 13a6eb6 | 2020-03-04 23:50:37 -0800 | [diff] [blame] | 23 | import static android.view.InsetsState.ITYPE_NAVIGATION_BAR; |
| 24 | import static android.view.InsetsState.ITYPE_STATUS_BAR; |
| 25 | import static android.view.InsetsState.ITYPE_TOP_GESTURES; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 26 | import static android.view.Surface.ROTATION_0; |
| 27 | import static android.view.Surface.ROTATION_270; |
| 28 | import static android.view.Surface.ROTATION_90; |
| 29 | import static android.view.View.SYSTEM_UI_FLAG_FULLSCREEN; |
Yongjin Kwon | 2fe0726 | 2019-09-03 10:47:28 +0900 | [diff] [blame] | 30 | import static android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 31 | import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
Charles Chen | 64172bb | 2019-04-22 17:30:29 +0800 | [diff] [blame] | 32 | import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 33 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
| 34 | import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
| 35 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR; |
| 36 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
chaviw | 0d83376 | 2019-06-20 17:09:53 -0700 | [diff] [blame] | 37 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 38 | import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
| 39 | import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER; |
shawnlin | 465b7de | 2020-02-11 20:45:35 +0800 | [diff] [blame] | 40 | import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; |
chaviw | 0d83376 | 2019-06-20 17:09:53 -0700 | [diff] [blame] | 41 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_IS_SCREEN_DECOR; |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 42 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; |
| 43 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 44 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
| 45 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; |
Yuncheol Heo | 13a6eb6 | 2020-03-04 23:50:37 -0800 | [diff] [blame] | 46 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
| 47 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 48 | |
| 49 | import static org.hamcrest.Matchers.is; |
| 50 | import static org.junit.Assert.assertEquals; |
Yuncheol Heo | 13a6eb6 | 2020-03-04 23:50:37 -0800 | [diff] [blame] | 51 | import static org.junit.Assert.assertNotEquals; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 52 | import static org.junit.Assert.assertThat; |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 53 | import static org.junit.Assume.assumeTrue; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 54 | import static org.mockito.Mockito.doNothing; |
| 55 | import static org.mockito.Mockito.spy; |
Yuncheol Heo | 13a6eb6 | 2020-03-04 23:50:37 -0800 | [diff] [blame] | 56 | import static org.testng.Assert.expectThrows; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 57 | |
Riddle Hsu | 55d7c40 | 2020-02-26 22:49:29 +0800 | [diff] [blame] | 58 | import android.app.WindowConfiguration; |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 59 | import android.graphics.Insets; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 60 | import android.graphics.PixelFormat; |
| 61 | import android.graphics.Rect; |
| 62 | import android.platform.test.annotations.Presubmit; |
| 63 | import android.util.Pair; |
| 64 | import android.view.DisplayCutout; |
| 65 | import android.view.DisplayInfo; |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 66 | import android.view.InsetsState; |
| 67 | import android.view.ViewRootImpl; |
| 68 | import android.view.WindowInsets.Side; |
| 69 | import android.view.WindowInsets.Type; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 70 | import android.view.WindowManager; |
| 71 | |
Yongjin Kwon | 2fe0726 | 2019-09-03 10:47:28 +0900 | [diff] [blame] | 72 | import androidx.test.filters.FlakyTest; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 73 | import androidx.test.filters.SmallTest; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 74 | |
Brad Stenning | e057369 | 2019-03-11 13:52:46 -0700 | [diff] [blame] | 75 | import com.android.server.policy.WindowManagerPolicy; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 76 | import com.android.server.wm.utils.WmDisplayCutout; |
| 77 | |
Yongjin Kwon | 2fe0726 | 2019-09-03 10:47:28 +0900 | [diff] [blame] | 78 | import org.junit.After; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 79 | import org.junit.Before; |
| 80 | import org.junit.Test; |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 81 | import org.junit.runner.RunWith; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 82 | |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 83 | import java.io.PrintWriter; |
| 84 | import java.io.StringWriter; |
| 85 | |
Yongjin Kwon | 2fe0726 | 2019-09-03 10:47:28 +0900 | [diff] [blame] | 86 | /** |
| 87 | * Tests for the {@link DisplayPolicy} class. |
| 88 | * |
| 89 | * Build/Install/Run: |
| 90 | * atest WmTests:DisplayPolicyLayoutTests |
| 91 | */ |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 92 | @SmallTest |
| 93 | @Presubmit |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 94 | @RunWith(WindowTestRunner.class) |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 95 | public class DisplayPolicyLayoutTests extends DisplayPolicyTestsBase { |
| 96 | |
| 97 | private DisplayFrames mFrames; |
| 98 | private WindowState mWindow; |
| 99 | private int mRotation = ROTATION_0; |
| 100 | private boolean mHasDisplayCutout; |
shawnlin | 465b7de | 2020-02-11 20:45:35 +0800 | [diff] [blame] | 101 | private boolean mIsLongEdgeDisplayCutout; |
chaviw | 0d83376 | 2019-06-20 17:09:53 -0700 | [diff] [blame] | 102 | private static final int DECOR_WINDOW_INSET = 50; |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 103 | |
| 104 | @Before |
| 105 | public void setUp() throws Exception { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 106 | 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 Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 114 | attrs.format = PixelFormat.TRANSLUCENT; |
Tiger Huang | a86bca9 | 2020-02-07 20:18:01 +0800 | [diff] [blame] | 115 | |
| 116 | updateDisplayFrames(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 117 | } |
| 118 | |
Yongjin Kwon | 2fe0726 | 2019-09-03 10:47:28 +0900 | [diff] [blame] | 119 | @After |
| 120 | public void tearDown() { |
| 121 | PolicyControl.setFilters(""); |
| 122 | mWindow.getDisplayContent().mInputMethodTarget = null; |
| 123 | } |
| 124 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 125 | public void setRotation(int rotation) { |
| 126 | mRotation = rotation; |
| 127 | updateDisplayFrames(); |
| 128 | } |
| 129 | |
| 130 | public void addDisplayCutout() { |
| 131 | mHasDisplayCutout = true; |
| 132 | updateDisplayFrames(); |
| 133 | } |
| 134 | |
shawnlin | 465b7de | 2020-02-11 20:45:35 +0800 | [diff] [blame] | 135 | public void addLongEdgeDisplayCutout() { |
| 136 | mHasDisplayCutout = true; |
| 137 | mIsLongEdgeDisplayCutout = true; |
| 138 | updateDisplayFrames(); |
| 139 | } |
| 140 | |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 141 | private void updateDisplayFrames() { |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 142 | mFrames = createDisplayFrames(); |
Tiger Huang | a86bca9 | 2020-02-07 20:18:01 +0800 | [diff] [blame] | 143 | mDisplayContent.mDisplayFrames = mFrames; |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | private DisplayFrames createDisplayFrames() { |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 147 | final Pair<DisplayInfo, WmDisplayCutout> info = displayInfoAndCutoutForRotation(mRotation, |
shawnlin | 465b7de | 2020-02-11 20:45:35 +0800 | [diff] [blame] | 148 | mHasDisplayCutout, mIsLongEdgeDisplayCutout); |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 149 | return new DisplayFrames(mDisplayContent.getDisplayId(), info.first, info.second); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | @Test |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 153 | 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 Heo | 13a6eb6 | 2020-03-04 23:50:37 -0800 | [diff] [blame] | 162 | 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 Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 212 | public void layoutWindowLw_fitStatusBars() { |
| 213 | assumeTrue(ViewRootImpl.sNewInsetsMode == ViewRootImpl.NEW_INSETS_MODE_FULL); |
| 214 | |
Tiger Huang | 5272444 | 2020-01-20 21:38:42 +0800 | [diff] [blame] | 215 | mWindow.mAttrs.setFitInsetsTypes(Type.statusBars()); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 216 | 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 Huang | 5272444 | 2020-01-20 21:38:42 +0800 | [diff] [blame] | 233 | mWindow.mAttrs.setFitInsetsTypes(Type.navigationBars()); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 234 | 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 Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 248 | public void layoutWindowLw_fitAllSides() { |
| 249 | assumeTrue(ViewRootImpl.sNewInsetsMode == ViewRootImpl.NEW_INSETS_MODE_FULL); |
| 250 | |
Tiger Huang | 5272444 | 2020-01-20 21:38:42 +0800 | [diff] [blame] | 251 | mWindow.mAttrs.setFitInsetsSides(Side.all()); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 252 | 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 Huang | 5272444 | 2020-01-20 21:38:42 +0800 | [diff] [blame] | 269 | mWindow.mAttrs.setFitInsetsSides(Side.TOP); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 270 | 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 Huang | a86bca9 | 2020-02-07 20:18:01 +0800 | [diff] [blame] | 284 | public void layoutWindowLw_fitInsetsIgnoringVisibility() { |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 285 | assumeTrue(ViewRootImpl.sNewInsetsMode == ViewRootImpl.NEW_INSETS_MODE_FULL); |
| 286 | |
| 287 | final InsetsState state = |
Tiger Huang | 82520fc | 2019-12-19 22:29:20 +0800 | [diff] [blame] | 288 | mDisplayContent.getInsetsPolicy().getInsetsForDispatch(mWindow); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 289 | state.getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false); |
| 290 | state.getSource(InsetsState.ITYPE_NAVIGATION_BAR).setVisible(false); |
Tiger Huang | 5272444 | 2020-01-20 21:38:42 +0800 | [diff] [blame] | 291 | mWindow.mAttrs.setFitInsetsIgnoringVisibility(true); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 292 | 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 Huang | a86bca9 | 2020-02-07 20:18:01 +0800 | [diff] [blame] | 306 | public void layoutWindowLw_fitInsetsNotIgnoringVisibility() { |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 307 | assumeTrue(ViewRootImpl.sNewInsetsMode == ViewRootImpl.NEW_INSETS_MODE_FULL); |
| 308 | |
| 309 | final InsetsState state = |
Tiger Huang | 82520fc | 2019-12-19 22:29:20 +0800 | [diff] [blame] | 310 | mDisplayContent.getInsetsPolicy().getInsetsForDispatch(mWindow); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 311 | state.getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false); |
| 312 | state.getSource(InsetsState.ITYPE_NAVIGATION_BAR).setVisible(false); |
Tiger Huang | 5272444 | 2020-01-20 21:38:42 +0800 | [diff] [blame] | 313 | mWindow.mAttrs.setFitInsetsIgnoringVisibility(false); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 314 | 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 Huang | e16645a | 2020-02-25 22:24:39 +0800 | [diff] [blame] | 327 | @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 Chen | 64172bb | 2019-04-22 17:30:29 +0800 | [diff] [blame] | 347 | @Test |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 348 | public void layoutWindowLw_withDisplayCutout() { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 349 | addDisplayCutout(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 350 | |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 351 | mWindow.mAttrs.flags = |
| 352 | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
Tiger Huang | a86bca9 | 2020-02-07 20:18:01 +0800 | [diff] [blame] | 353 | mWindow.mAttrs.setFitInsetsTypes(0 /* types */); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 354 | addWindow(mWindow); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 355 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 356 | mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */); |
| 357 | mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 358 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 359 | 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 Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | @Test |
| 367 | public void layoutWindowLw_withDisplayCutout_never() { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 368 | addDisplayCutout(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 369 | |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 370 | mWindow.mAttrs.flags = |
| 371 | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
Tiger Huang | a86bca9 | 2020-02-07 20:18:01 +0800 | [diff] [blame] | 372 | mWindow.mAttrs.setFitInsetsTypes(0 /* types */); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 373 | mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER; |
| 374 | addWindow(mWindow); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 375 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 376 | mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */); |
| 377 | mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 378 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 379 | 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 Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | @Test |
shawnlin | 465b7de | 2020-02-11 20:45:35 +0800 | [diff] [blame] | 387 | 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 Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 427 | public void layoutWindowLw_withDisplayCutout_layoutFullscreen() { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 428 | addDisplayCutout(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 429 | |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 430 | mWindow.mAttrs.flags = |
| 431 | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
Tiger Huang | a86bca9 | 2020-02-07 20:18:01 +0800 | [diff] [blame] | 432 | mWindow.mAttrs.setFitInsetsTypes(0 /* types */); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 433 | mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
Tiger Huang | 5272444 | 2020-01-20 21:38:42 +0800 | [diff] [blame] | 434 | mWindow.mAttrs.setFitInsetsTypes( |
| 435 | mWindow.mAttrs.getFitInsetsTypes() & ~Type.statusBars()); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 436 | addWindow(mWindow); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 437 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 438 | mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */); |
| 439 | mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 440 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 441 | 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 Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 445 | assertInsetByTopBottom(mWindow.getDisplayFrameLw(), 0, 0); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | @Test |
| 449 | public void layoutWindowLw_withDisplayCutout_fullscreen() { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 450 | addDisplayCutout(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 451 | |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 452 | mWindow.mAttrs.flags = |
| 453 | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
Tiger Huang | a86bca9 | 2020-02-07 20:18:01 +0800 | [diff] [blame] | 454 | mWindow.mAttrs.setFitInsetsTypes(0 /* types */); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 455 | mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_FULLSCREEN; |
Tiger Huang | 82520fc | 2019-12-19 22:29:20 +0800 | [diff] [blame] | 456 | mDisplayContent.getInsetsPolicy().getInsetsForDispatch(mWindow) |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 457 | .getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 458 | addWindow(mWindow); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 459 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 460 | mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */); |
| 461 | mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 462 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 463 | 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 Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | @Test |
| 471 | public void layoutWindowLw_withDisplayCutout_fullscreenInCutout() { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 472 | addDisplayCutout(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 473 | |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 474 | mWindow.mAttrs.flags = |
| 475 | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
Tiger Huang | a86bca9 | 2020-02-07 20:18:01 +0800 | [diff] [blame] | 476 | mWindow.mAttrs.setFitInsetsTypes(0 /* types */); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 477 | mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_FULLSCREEN; |
Tiger Huang | 82520fc | 2019-12-19 22:29:20 +0800 | [diff] [blame] | 478 | mDisplayContent.getInsetsPolicy().getInsetsForDispatch(mWindow) |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 479 | .getSource(InsetsState.ITYPE_STATUS_BAR).setVisible(false); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 480 | mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
| 481 | addWindow(mWindow); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 482 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 483 | mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */); |
| 484 | mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 485 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 486 | 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 Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | |
| 494 | @Test |
| 495 | public void layoutWindowLw_withDisplayCutout_landscape() { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 496 | addDisplayCutout(); |
| 497 | setRotation(ROTATION_90); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 498 | |
| 499 | mWindow.mAttrs.flags = |
| 500 | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
Tiger Huang | a86bca9 | 2020-02-07 20:18:01 +0800 | [diff] [blame] | 501 | mWindow.mAttrs.setFitInsetsTypes(0 /* types */); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 502 | addWindow(mWindow); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 503 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 504 | mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */); |
| 505 | mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 506 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 507 | 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 Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | @Test |
| 516 | public void layoutWindowLw_withDisplayCutout_seascape() { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 517 | addDisplayCutout(); |
| 518 | setRotation(ROTATION_270); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 519 | |
| 520 | mWindow.mAttrs.flags = |
| 521 | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
Tiger Huang | a86bca9 | 2020-02-07 20:18:01 +0800 | [diff] [blame] | 522 | mWindow.mAttrs.setFitInsetsTypes(0 /* types */); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 523 | addWindow(mWindow); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 524 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 525 | mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */); |
| 526 | mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 527 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 528 | 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 Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | @Test |
| 537 | public void layoutWindowLw_withDisplayCutout_fullscreen_landscape() { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 538 | addDisplayCutout(); |
| 539 | setRotation(ROTATION_90); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 540 | |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 541 | mWindow.mAttrs.flags = |
| 542 | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
Tiger Huang | a86bca9 | 2020-02-07 20:18:01 +0800 | [diff] [blame] | 543 | mWindow.mAttrs.setFitInsetsTypes(0 /* types */); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 544 | mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
Tiger Huang | 5272444 | 2020-01-20 21:38:42 +0800 | [diff] [blame] | 545 | mWindow.mAttrs.setFitInsetsTypes( |
| 546 | mWindow.mAttrs.getFitInsetsTypes() & ~Type.statusBars()); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 547 | addWindow(mWindow); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 548 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 549 | mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */); |
| 550 | mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 551 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 552 | 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 Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | @Test |
| 560 | public void layoutWindowLw_withDisplayCutout_floatingInScreen() { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 561 | addDisplayCutout(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 562 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 563 | mWindow.mAttrs.flags = FLAG_LAYOUT_IN_SCREEN; |
Tiger Huang | 5272444 | 2020-01-20 21:38:42 +0800 | [diff] [blame] | 564 | mWindow.mAttrs.setFitInsetsTypes(Type.systemBars() & ~Type.statusBars()); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 565 | mWindow.mAttrs.type = TYPE_APPLICATION_OVERLAY; |
| 566 | mWindow.mAttrs.width = DISPLAY_WIDTH; |
| 567 | mWindow.mAttrs.height = DISPLAY_HEIGHT; |
| 568 | addWindow(mWindow); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 569 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 570 | mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */); |
| 571 | mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 572 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 573 | assertInsetByTopBottom(mWindow.getParentFrame(), 0, NAV_BAR_HEIGHT); |
| 574 | assertInsetByTopBottom(mWindow.getDisplayFrameLw(), STATUS_BAR_HEIGHT, NAV_BAR_HEIGHT); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | @Test |
| 578 | public void layoutWindowLw_withDisplayCutout_fullscreenInCutout_landscape() { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 579 | addDisplayCutout(); |
| 580 | setRotation(ROTATION_90); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 581 | |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 582 | mWindow.mAttrs.flags = |
| 583 | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
Tiger Huang | a86bca9 | 2020-02-07 20:18:01 +0800 | [diff] [blame] | 584 | mWindow.mAttrs.setFitInsetsTypes(0 /* types */); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 585 | mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
Tiger Huang | 5272444 | 2020-01-20 21:38:42 +0800 | [diff] [blame] | 586 | mWindow.mAttrs.setFitInsetsTypes( |
| 587 | mWindow.mAttrs.getFitInsetsTypes() & ~Type.statusBars()); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 588 | mWindow.mAttrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
| 589 | addWindow(mWindow); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 590 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 591 | mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */); |
| 592 | mDisplayPolicy.layoutWindowLw(mWindow, null, mFrames); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 593 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 594 | 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 Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | @Test |
shawnlin | 465b7de | 2020-02-11 20:45:35 +0800 | [diff] [blame] | 602 | 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; |
shawnlin | e9e801e | 2020-02-19 19:53:48 +0800 | [diff] [blame] | 607 | mWindow.mAttrs.setFitInsetsTypes(0 /* types */); |
shawnlin | 465b7de | 2020-02-11 20:45:35 +0800 | [diff] [blame] | 608 | 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; |
shawnlin | e9e801e | 2020-02-19 19:53:48 +0800 | [diff] [blame] | 627 | mWindow.mAttrs.setFitInsetsTypes(0 /* types */); |
shawnlin | 465b7de | 2020-02-11 20:45:35 +0800 | [diff] [blame] | 628 | 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 Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 686 | public void layoutWindowLw_withForwardInset_SoftInputAdjustResize() { |
Tarandeep Singh | 24f0466 | 2020-01-06 16:48:46 -0800 | [diff] [blame] | 687 | assumeTrue(ViewRootImpl.sNewInsetsMode == ViewRootImpl.NEW_INSETS_MODE_NONE); |
| 688 | |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 689 | mWindow.mAttrs.flags = |
| 690 | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
Tiger Huang | a86bca9 | 2020-02-07 20:18:01 +0800 | [diff] [blame] | 691 | mWindow.mAttrs.setFitInsetsTypes(0 /* types */); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 692 | mWindow.mAttrs.softInputMode = SOFT_INPUT_ADJUST_RESIZE; |
| 693 | addWindow(mWindow); |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 694 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 695 | 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 Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 699 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 700 | 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 Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | @Test |
| 711 | public void layoutWindowLw_withForwardInset_SoftInputAdjustNothing() { |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 712 | mWindow.mAttrs.flags = |
| 713 | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
Tiger Huang | a86bca9 | 2020-02-07 20:18:01 +0800 | [diff] [blame] | 714 | mWindow.mAttrs.setFitInsetsTypes(0 /* types */); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 715 | mWindow.mAttrs.softInputMode = SOFT_INPUT_ADJUST_NOTHING; |
| 716 | addWindow(mWindow); |
Issei Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 717 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 718 | 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 Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 722 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 723 | 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 Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 729 | } |
| 730 | |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 731 | // TODO(b/118118435): remove after removing PolicyControl |
Yongjin Kwon | 2fe0726 | 2019-09-03 10:47:28 +0900 | [diff] [blame] | 732 | @FlakyTest(bugId = 129711077) |
| 733 | @Test |
| 734 | public void layoutWindowLw_withImmersive_SoftInputAdjustResize() { |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 735 | assumeTrue(ViewRootImpl.sNewInsetsMode != ViewRootImpl.NEW_INSETS_MODE_FULL); |
| 736 | |
Yongjin Kwon | 2fe0726 | 2019-09-03 10:47:28 +0900 | [diff] [blame] | 737 | 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 Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 759 | // TODO(b/118118435): remove after removing PolicyControl |
Yongjin Kwon | 2fe0726 | 2019-09-03 10:47:28 +0900 | [diff] [blame] | 760 | @FlakyTest(bugId = 129711077) |
| 761 | @Test |
| 762 | public void layoutWindowLw_withImmersive_SoftInputAdjustNothing() { |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 763 | assumeTrue(ViewRootImpl.sNewInsetsMode != ViewRootImpl.NEW_INSETS_MODE_FULL); |
| 764 | |
Yongjin Kwon | 2fe0726 | 2019-09-03 10:47:28 +0900 | [diff] [blame] | 765 | 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 Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 786 | // TODO(b/118118435): remove after removing PolicyControl |
Yongjin Kwon | 2fe0726 | 2019-09-03 10:47:28 +0900 | [diff] [blame] | 787 | @FlakyTest(bugId = 129711077) |
| 788 | @Test |
| 789 | public void layoutWindowLw_withForceImmersive_fullscreen() { |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 790 | assumeTrue(ViewRootImpl.sNewInsetsMode != ViewRootImpl.NEW_INSETS_MODE_FULL); |
| 791 | |
Yongjin Kwon | 2fe0726 | 2019-09-03 10:47:28 +0900 | [diff] [blame] | 792 | 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 Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 813 | // TODO(b/118118435): remove after removing PolicyControl |
Yongjin Kwon | 2fe0726 | 2019-09-03 10:47:28 +0900 | [diff] [blame] | 814 | @FlakyTest(bugId = 129711077) |
| 815 | @Test |
| 816 | public void layoutWindowLw_withForceImmersive_nonFullscreen() { |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 817 | assumeTrue(ViewRootImpl.sNewInsetsMode != ViewRootImpl.NEW_INSETS_MODE_FULL); |
| 818 | |
Yongjin Kwon | 2fe0726 | 2019-09-03 10:47:28 +0900 | [diff] [blame] | 819 | 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 Suzuki | a5dbf52 | 2019-02-01 17:58:15 +0100 | [diff] [blame] | 842 | @Test |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 843 | public void layoutHint_appWindow() { |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 844 | mWindow.mAttrs.flags = |
| 845 | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
| 846 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 847 | // Initialize DisplayFrames |
| 848 | mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 849 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 850 | final Rect outFrame = new Rect(); |
| 851 | final Rect outContentInsets = new Rect(); |
| 852 | final Rect outStableInsets = new Rect(); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 853 | final DisplayCutout.ParcelableWrapper outDisplayCutout = |
| 854 | new DisplayCutout.ParcelableWrapper(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 855 | |
Riddle Hsu | 55d7c40 | 2020-02-26 22:49:29 +0800 | [diff] [blame] | 856 | mDisplayPolicy.getLayoutHint(mWindow.mAttrs, null /* windowToken */, outFrame, |
| 857 | outContentInsets, outStableInsets, outDisplayCutout); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 858 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 859 | 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 Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 862 | assertThat(outDisplayCutout, is(new DisplayCutout.ParcelableWrapper())); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | @Test |
| 866 | public void layoutHint_appWindowInTask() { |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 867 | mWindow.mAttrs.flags = |
| 868 | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
| 869 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 870 | // Initialize DisplayFrames |
| 871 | mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 872 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 873 | final Rect taskBounds = new Rect(100, 100, 200, 200); |
Riddle Hsu | 55d7c40 | 2020-02-26 22:49:29 +0800 | [diff] [blame] | 874 | 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 Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 877 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 878 | final Rect outFrame = new Rect(); |
| 879 | final Rect outContentInsets = new Rect(); |
| 880 | final Rect outStableInsets = new Rect(); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 881 | final DisplayCutout.ParcelableWrapper outDisplayCutout = |
| 882 | new DisplayCutout.ParcelableWrapper(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 883 | |
Riddle Hsu | 55d7c40 | 2020-02-26 22:49:29 +0800 | [diff] [blame] | 884 | mDisplayPolicy.getLayoutHint(mWindow.mAttrs, mWindow.mToken, outFrame, |
| 885 | outContentInsets, outStableInsets, outDisplayCutout); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 886 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 887 | assertThat(outFrame, is(taskBounds)); |
| 888 | assertThat(outContentInsets, is(new Rect())); |
| 889 | assertThat(outStableInsets, is(new Rect())); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 890 | assertThat(outDisplayCutout, is(new DisplayCutout.ParcelableWrapper())); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | @Test |
| 894 | public void layoutHint_appWindowInTask_outsideContentFrame() { |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 895 | mWindow.mAttrs.flags = |
| 896 | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
| 897 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 898 | // Initialize DisplayFrames |
| 899 | mDisplayPolicy.beginLayoutLw(mFrames, 0 /* UI mode */); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 900 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 901 | // 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 Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 905 | |
Riddle Hsu | 55d7c40 | 2020-02-26 22:49:29 +0800 | [diff] [blame] | 906 | 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 Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 912 | final Rect outFrame = new Rect(); |
| 913 | final Rect outContentInsets = new Rect(); |
| 914 | final Rect outStableInsets = new Rect(); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 915 | final DisplayCutout.ParcelableWrapper outDisplayCutout = |
| 916 | new DisplayCutout.ParcelableWrapper(); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 917 | |
Riddle Hsu | 55d7c40 | 2020-02-26 22:49:29 +0800 | [diff] [blame] | 918 | mDisplayPolicy.getLayoutHint(mWindow.mAttrs, mWindow.mToken, outFrame, outContentInsets, |
| 919 | outStableInsets, outDisplayCutout); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 920 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 921 | assertThat(outFrame, is(taskBounds)); |
| 922 | assertThat(outContentInsets, is(new Rect())); |
| 923 | assertThat(outStableInsets, is(new Rect())); |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 924 | assertThat(outDisplayCutout, is(new DisplayCutout.ParcelableWrapper())); |
Tiger Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 925 | } |
| 926 | |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 927 | /** |
| 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 Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 945 | mDisplayPolicy.beginLayoutLw(mFrames, uiMode); |
Riddle Hsu | 55d7c40 | 2020-02-26 22:49:29 +0800 | [diff] [blame] | 946 | // Force the display bounds because it is not synced with display frames in policy test. |
| 947 | mDisplayContent.getWindowConfiguration().setBounds(mFrames.mUnrestricted); |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 948 | 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 Hsu | 55d7c40 | 2020-02-26 22:49:29 +0800 | [diff] [blame] | 956 | assertEquals(new ToStringComparatorWrapper<>(realFramesDump), |
| 957 | new ToStringComparatorWrapper<>(simulatedFramesDump)); |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 958 | |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 959 | 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 Huang | a86bca9 | 2020-02-07 20:18:01 +0800 | [diff] [blame] | 964 | realInsetsState.removeSource(InsetsState.ITYPE_CAPTION_BAR); |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 965 | |
Riddle Hsu | 55d7c40 | 2020-02-26 22:49:29 +0800 | [diff] [blame] | 966 | assertEquals(new ToStringComparatorWrapper<>(realInsetsState), |
| 967 | new ToStringComparatorWrapper<>(simulatedInsetsState)); |
Riddle Hsu | c717576 | 2020-01-10 21:03:48 +0800 | [diff] [blame] | 968 | } |
| 969 | |
Brad Stenning | e057369 | 2019-03-11 13:52:46 -0700 | [diff] [blame] | 970 | @Test |
| 971 | public void forceShowSystemBars_clearsSystemUIFlags() { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 972 | mDisplayPolicy.mLastSystemUiFlags |= SYSTEM_UI_FLAG_FULLSCREEN; |
| 973 | mWindow.mAttrs.subtreeSystemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 974 | mWindow.mAttrs.flags = |
| 975 | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 976 | mWindow.mSystemUiVisibility = SYSTEM_UI_FLAG_FULLSCREEN; |
| 977 | mDisplayPolicy.setForceShowSystemBars(true); |
| 978 | addWindow(mWindow); |
Brad Stenning | e057369 | 2019-03-11 13:52:46 -0700 | [diff] [blame] | 979 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 980 | 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 Stenning | e057369 | 2019-03-11 13:52:46 -0700 | [diff] [blame] | 984 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 985 | 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 Stenning | e057369 | 2019-03-11 13:52:46 -0700 | [diff] [blame] | 989 | } |
| 990 | |
chaviw | 0d83376 | 2019-06-20 17:09:53 -0700 | [diff] [blame] | 991 | @Test |
| 992 | public void testScreenDecorWindows() { |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 993 | final WindowState decorWindow = createWindow(null, TYPE_APPLICATION_OVERLAY, "decorWindow"); |
Tiger Huang | 4a7835f | 2019-11-06 00:07:56 +0800 | [diff] [blame] | 994 | mWindow.mAttrs.flags = FLAG_NOT_FOCUSABLE | FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR |
| 995 | | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 996 | decorWindow.mAttrs.privateFlags |= PRIVATE_FLAG_IS_SCREEN_DECOR; |
| 997 | addWindow(decorWindow); |
| 998 | addWindow(mWindow); |
chaviw | 0d83376 | 2019-06-20 17:09:53 -0700 | [diff] [blame] | 999 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 1000 | // 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); |
chaviw | 0d83376 | 2019-06-20 17:09:53 -0700 | [diff] [blame] | 1005 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 1006 | // 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); |
chaviw | 0d83376 | 2019-06-20 17:09:53 -0700 | [diff] [blame] | 1012 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 1013 | // 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); |
chaviw | 0d83376 | 2019-06-20 17:09:53 -0700 | [diff] [blame] | 1019 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 1020 | // 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); |
chaviw | 0d83376 | 2019-06-20 17:09:53 -0700 | [diff] [blame] | 1026 | |
Riddle Hsu | 73f5357 | 2019-09-23 23:13:01 +0800 | [diff] [blame] | 1027 | // 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); |
chaviw | 0d83376 | 2019-06-20 17:09:53 -0700 | [diff] [blame] | 1032 | } |
| 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 Huang | 7c610aa | 2018-10-27 00:01:01 +0800 | [diff] [blame] | 1041 | /** |
| 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 | } |