Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 14 | * limitations under the License. |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 21 | import static android.view.DisplayCutout.BOUNDS_POSITION_TOP; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 22 | import static android.view.DisplayCutout.fromBoundingRect; |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 23 | import static android.view.WindowManager.LayoutParams.MATCH_PARENT; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 24 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
| 25 | |
| 26 | import static org.junit.Assert.assertEquals; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 27 | import static org.mockito.Mockito.mock; |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 28 | |
Jorim Jaggi | 829b9cd | 2017-01-23 16:20:53 +0100 | [diff] [blame] | 29 | import android.app.ActivityManager.TaskDescription; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 30 | import android.content.res.Configuration; |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 31 | import android.graphics.Rect; |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 32 | import android.platform.test.annotations.Presubmit; |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 33 | import android.view.DisplayInfo; |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 34 | import android.view.Gravity; |
| 35 | import android.view.IWindow; |
| 36 | import android.view.WindowManager; |
| 37 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 38 | import androidx.test.filters.SmallTest; |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 39 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 40 | import com.android.server.wm.utils.WmDisplayCutout; |
| 41 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 42 | import org.junit.Before; |
| 43 | import org.junit.Test; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 44 | |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 45 | /** |
| 46 | * Tests for the {@link WindowState#computeFrameLw} method and other window frame machinery. |
| 47 | * |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 48 | * Build/Install/Run: |
| 49 | * atest FrameworksServicesTests:WindowFrameTests |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 50 | */ |
| 51 | @SmallTest |
| 52 | @Presubmit |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 53 | public class WindowFrameTests extends WindowTestsBase { |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 54 | |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 55 | private WindowToken mWindowToken; |
| 56 | private final IWindow mIWindow = new TestIWindow(); |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 57 | private final Rect mEmptyRect = new Rect(); |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 58 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 59 | static class WindowStateWithTask extends WindowState { |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 60 | final Task mTask; |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 61 | boolean mDockedResizingForTest = false; |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 62 | WindowStateWithTask(WindowManagerService wm, IWindow iWindow, WindowToken windowToken, |
| 63 | WindowManager.LayoutParams attrs, Task t) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 64 | super(wm, mock(Session.class), iWindow, windowToken, null, 0, 0, attrs, 0, 0, |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 65 | false /* ownerCanAddInternalSystemWindow */); |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 66 | mTask = t; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | Task getTask() { |
| 71 | return mTask; |
| 72 | } |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 73 | |
| 74 | @Override |
| 75 | boolean isDockedResizing() { |
| 76 | return mDockedResizingForTest; |
| 77 | } |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 78 | } |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 79 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 80 | private static class TaskWithBounds extends Task { |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 81 | final Rect mBounds; |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 82 | final Rect mOverrideDisplayedBounds = new Rect(); |
Robert Carr | 15dd7ef | 2016-11-03 14:26:58 -0700 | [diff] [blame] | 83 | boolean mFullscreenForTest = true; |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 84 | |
| 85 | TaskWithBounds(TaskStack stack, WindowManagerService wm, Rect bounds) { |
| 86 | super(0, stack, 0, wm, 0, false, new TaskDescription(), null); |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 87 | mBounds = bounds; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 88 | setBounds(bounds); |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 89 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 90 | |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 91 | @Override |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 92 | public Rect getBounds() { |
| 93 | return mBounds; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public void getBounds(Rect out) { |
| 98 | out.set(mBounds); |
| 99 | } |
| 100 | |
| 101 | @Override |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 102 | public void getRequestedOverrideBounds(Rect outBounds) { |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 103 | outBounds.set(mBounds); |
| 104 | } |
| 105 | @Override |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 106 | Rect getOverrideDisplayedBounds() { |
| 107 | return mOverrideDisplayedBounds; |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 108 | } |
| 109 | @Override |
| 110 | boolean isFullscreen() { |
Robert Carr | 15dd7ef | 2016-11-03 14:26:58 -0700 | [diff] [blame] | 111 | return mFullscreenForTest; |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | |
| 115 | TaskStack mStubStack; |
| 116 | |
| 117 | @Before |
| 118 | public void setUp() throws Exception { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 119 | mWindowToken = createAppWindowToken(mWm.getDefaultDisplayContentLocked(), |
| 120 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
Tadashi G. Takaoka | d7aa79a | 2019-02-08 17:42:37 +0900 | [diff] [blame] | 121 | mStubStack = mock(TaskStack.class); |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 124 | // Do not use this function directly in the tests below. Instead, use more explicit function |
| 125 | // such as assertFlame(). |
| 126 | private void assertRect(Rect rect, int left, int top, int right, int bottom) { |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 127 | assertEquals(left, rect.left); |
| 128 | assertEquals(top, rect.top); |
| 129 | assertEquals(right, rect.right); |
| 130 | assertEquals(bottom, rect.bottom); |
| 131 | } |
| 132 | |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 133 | private void assertContentInset(WindowState w, int left, int top, int right, int bottom) { |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 134 | assertRect(w.getContentInsets(), left, top, right, bottom); |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | private void assertVisibleInset(WindowState w, int left, int top, int right, int bottom) { |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 138 | assertRect(w.getVisibleInsets(), left, top, right, bottom); |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | private void assertStableInset(WindowState w, int left, int top, int right, int bottom) { |
chaviw | 9c81e63 | 2018-07-31 11:17:52 -0700 | [diff] [blame] | 142 | assertRect(w.getStableInsets(), left, top, right, bottom); |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | private void assertFrame(WindowState w, int left, int top, int right, int bottom) { |
| 146 | assertRect(w.getFrameLw(), left, top, right, bottom); |
| 147 | } |
| 148 | |
| 149 | private void assertContentFrame(WindowState w, Rect expectedRect) { |
| 150 | assertRect(w.getContentFrameLw(), expectedRect.left, expectedRect.top, expectedRect.right, |
| 151 | expectedRect.bottom); |
| 152 | } |
| 153 | |
| 154 | private void assertVisibleFrame(WindowState w, Rect expectedRect) { |
| 155 | assertRect(w.getVisibleFrameLw(), expectedRect.left, expectedRect.top, expectedRect.right, |
| 156 | expectedRect.bottom); |
| 157 | } |
| 158 | |
| 159 | private void assertStableFrame(WindowState w, Rect expectedRect) { |
| 160 | assertRect(w.getStableFrameLw(), expectedRect.left, expectedRect.top, expectedRect.right, |
| 161 | expectedRect.bottom); |
| 162 | } |
| 163 | |
| 164 | private void assertPolicyCrop(WindowStateWithTask w, int left, int top, int right, int bottom) { |
| 165 | Rect policyCrop = new Rect(); |
| 166 | w.calculatePolicyCrop(policyCrop); |
| 167 | assertRect(policyCrop, left, top, right, bottom); |
| 168 | } |
| 169 | |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 170 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 171 | public void testLayoutInFullscreenTaskInsets() { |
| 172 | // fullscreen task doesn't use bounds for computeFrame |
| 173 | final Task task = new TaskWithBounds(mStubStack, mWm, null); |
| 174 | WindowState w = createWindow(task, MATCH_PARENT, MATCH_PARENT); |
Robert Carr | e4ee8f8a | 2016-10-31 12:40:15 -0700 | [diff] [blame] | 175 | w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP; |
| 176 | |
| 177 | final int bottomContentInset = 100; |
| 178 | final int topContentInset = 50; |
| 179 | final int bottomVisibleInset = 30; |
| 180 | final int topVisibleInset = 70; |
| 181 | final int leftStableInset = 20; |
| 182 | final int rightStableInset = 90; |
| 183 | |
| 184 | // With no insets or system decor all the frames incoming from PhoneWindowManager |
| 185 | // are identical. |
| 186 | final Rect pf = new Rect(0, 0, 1000, 1000); |
| 187 | final Rect df = pf; |
| 188 | final Rect of = df; |
| 189 | final Rect cf = new Rect(pf); |
| 190 | // Produce some insets |
| 191 | cf.top += 50; |
| 192 | cf.bottom -= 100; |
| 193 | final Rect vf = new Rect(pf); |
| 194 | vf.top += topVisibleInset; |
| 195 | vf.bottom -= bottomVisibleInset; |
| 196 | final Rect sf = new Rect(pf); |
| 197 | sf.left += leftStableInset; |
| 198 | sf.right -= rightStableInset; |
| 199 | |
| 200 | final Rect dcf = pf; |
| 201 | // When mFrame extends past cf, the content insets are |
| 202 | // the difference between mFrame and ContentFrame. Visible |
| 203 | // and stable frames work the same way. |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 204 | w.getWindowFrames().setFrames(pf, df, of, cf, vf, dcf, sf, mEmptyRect); |
| 205 | w.computeFrameLw(); |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 206 | assertFrame(w, 0, 0, 1000, 1000); |
| 207 | assertContentInset(w, 0, topContentInset, 0, bottomContentInset); |
| 208 | assertVisibleInset(w, 0, topVisibleInset, 0, bottomVisibleInset); |
| 209 | assertStableInset(w, leftStableInset, 0, rightStableInset, 0); |
| 210 | assertContentFrame(w, cf); |
| 211 | assertVisibleFrame(w, vf); |
| 212 | assertStableFrame(w, sf); |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 213 | // On the other hand getFrame() doesn't extend past cf we won't get any insets |
Robert Carr | e4ee8f8a | 2016-10-31 12:40:15 -0700 | [diff] [blame] | 214 | w.mAttrs.x = 100; |
| 215 | w.mAttrs.y = 100; |
| 216 | w.mAttrs.width = 100; w.mAttrs.height = 100; //have to clear MATCH_PARENT |
| 217 | w.mRequestedWidth = 100; |
| 218 | w.mRequestedHeight = 100; |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 219 | w.computeFrameLw(); |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 220 | assertFrame(w, 100, 100, 200, 200); |
| 221 | assertContentInset(w, 0, 0, 0, 0); |
Robert Carr | e4ee8f8a | 2016-10-31 12:40:15 -0700 | [diff] [blame] | 222 | // In this case the frames are shrunk to the window frame. |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 223 | assertContentFrame(w, w.getFrameLw()); |
| 224 | assertVisibleFrame(w, w.getFrameLw()); |
| 225 | assertStableFrame(w, w.getFrameLw()); |
Robert Carr | e4ee8f8a | 2016-10-31 12:40:15 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 229 | public void testLayoutInFullscreenTaskNoInsets() { |
| 230 | // fullscreen task doesn't use bounds for computeFrame |
| 231 | final Task task = new TaskWithBounds(mStubStack, mWm, null); |
| 232 | WindowState w = createWindow(task, MATCH_PARENT, MATCH_PARENT); |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 233 | w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP; |
| 234 | |
| 235 | // With no insets or system decor all the frames incoming from PhoneWindowManager |
| 236 | // are identical. |
| 237 | final Rect pf = new Rect(0, 0, 1000, 1000); |
| 238 | |
| 239 | // Here the window has FILL_PARENT, FILL_PARENT |
| 240 | // so we expect it to fill the entire available frame. |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 241 | w.getWindowFrames().setFrames(pf, pf, pf, pf, pf, pf, pf, pf); |
| 242 | w.computeFrameLw(); |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 243 | assertFrame(w, 0, 0, 1000, 1000); |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 244 | |
| 245 | // It can select various widths and heights within the bounds. |
| 246 | // Strangely the window attribute width is ignored for normal windows |
| 247 | // and we use mRequestedWidth/mRequestedHeight |
| 248 | w.mAttrs.width = 300; |
| 249 | w.mAttrs.height = 300; |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 250 | w.computeFrameLw(); |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 251 | // Explicit width and height without requested width/height |
| 252 | // gets us nothing. |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 253 | assertFrame(w, 0, 0, 0, 0); |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 254 | |
| 255 | w.mRequestedWidth = 300; |
| 256 | w.mRequestedHeight = 300; |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 257 | w.computeFrameLw(); |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 258 | // With requestedWidth/Height we can freely choose our size within the |
| 259 | // parent bounds. |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 260 | assertFrame(w, 0, 0, 300, 300); |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 261 | |
| 262 | // With FLAG_SCALED though, requestedWidth/height is used to control |
| 263 | // the unscaled surface size, and mAttrs.width/height becomes the |
| 264 | // layout controller. |
| 265 | w.mAttrs.flags = WindowManager.LayoutParams.FLAG_SCALED; |
| 266 | w.mRequestedHeight = -1; |
| 267 | w.mRequestedWidth = -1; |
| 268 | w.mAttrs.width = 100; |
| 269 | w.mAttrs.height = 100; |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 270 | w.computeFrameLw(); |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 271 | assertFrame(w, 0, 0, 100, 100); |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 272 | w.mAttrs.flags = 0; |
| 273 | |
| 274 | // But sizes too large will be clipped to the containing frame |
| 275 | w.mRequestedWidth = 1200; |
| 276 | w.mRequestedHeight = 1200; |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 277 | w.computeFrameLw(); |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 278 | assertFrame(w, 0, 0, 1000, 1000); |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 279 | |
| 280 | // Before they are clipped though windows will be shifted |
| 281 | w.mAttrs.x = 300; |
| 282 | w.mAttrs.y = 300; |
| 283 | w.mRequestedWidth = 1000; |
| 284 | w.mRequestedHeight = 1000; |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 285 | w.computeFrameLw(); |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 286 | assertFrame(w, 0, 0, 1000, 1000); |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 287 | |
| 288 | // If there is room to move around in the parent frame the window will be shifted according |
| 289 | // to gravity. |
| 290 | w.mAttrs.x = 0; |
| 291 | w.mAttrs.y = 0; |
| 292 | w.mRequestedWidth = 300; |
| 293 | w.mRequestedHeight = 300; |
| 294 | w.mAttrs.gravity = Gravity.RIGHT | Gravity.TOP; |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 295 | w.computeFrameLw(); |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 296 | assertFrame(w, 700, 0, 1000, 300); |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 297 | w.mAttrs.gravity = Gravity.RIGHT | Gravity.BOTTOM; |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 298 | w.computeFrameLw(); |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 299 | assertFrame(w, 700, 700, 1000, 1000); |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 300 | // Window specified x and y are interpreted as offsets in the opposite |
| 301 | // direction of gravity |
| 302 | w.mAttrs.x = 100; |
| 303 | w.mAttrs.y = 100; |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 304 | w.computeFrameLw(); |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 305 | assertFrame(w, 600, 600, 900, 900); |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Robert Carr | 15dd7ef | 2016-11-03 14:26:58 -0700 | [diff] [blame] | 308 | @Test |
| 309 | public void testLayoutNonfullscreenTask() { |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 310 | final DisplayInfo displayInfo = mWm.getDefaultDisplayContentLocked().getDisplayInfo(); |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 311 | final int logicalWidth = displayInfo.logicalWidth; |
| 312 | final int logicalHeight = displayInfo.logicalHeight; |
| 313 | |
| 314 | final int taskLeft = logicalWidth / 4; |
| 315 | final int taskTop = logicalHeight / 4; |
| 316 | final int taskRight = logicalWidth / 4 * 3; |
| 317 | final int taskBottom = logicalHeight / 4 * 3; |
| 318 | final Rect taskBounds = new Rect(taskLeft, taskTop, taskRight, taskBottom); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 319 | final TaskWithBounds task = new TaskWithBounds(mStubStack, mWm, taskBounds); |
Robert Carr | 15dd7ef | 2016-11-03 14:26:58 -0700 | [diff] [blame] | 320 | task.mFullscreenForTest = false; |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 321 | WindowState w = createWindow(task, MATCH_PARENT, MATCH_PARENT); |
Robert Carr | 15dd7ef | 2016-11-03 14:26:58 -0700 | [diff] [blame] | 322 | w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP; |
| 323 | |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 324 | final Rect pf = new Rect(0, 0, logicalWidth, logicalHeight); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 325 | final WindowFrames windowFrames = w.getWindowFrames(); |
| 326 | windowFrames.setFrames(pf, pf, pf, pf, pf, pf, pf, mEmptyRect); |
| 327 | w.computeFrameLw(); |
Robert Carr | 15dd7ef | 2016-11-03 14:26:58 -0700 | [diff] [blame] | 328 | // For non fullscreen tasks the containing frame is based off the |
| 329 | // task bounds not the parent frame. |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 330 | assertFrame(w, taskLeft, taskTop, taskRight, taskBottom); |
| 331 | assertContentFrame(w, taskBounds); |
| 332 | assertContentInset(w, 0, 0, 0, 0); |
Robert Carr | 15dd7ef | 2016-11-03 14:26:58 -0700 | [diff] [blame] | 333 | |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 334 | pf.set(0, 0, logicalWidth, logicalHeight); |
Robert Carr | 15dd7ef | 2016-11-03 14:26:58 -0700 | [diff] [blame] | 335 | // We still produce insets against the containing frame the same way. |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 336 | final int cfRight = logicalWidth / 2; |
| 337 | final int cfBottom = logicalHeight / 2; |
| 338 | final Rect cf = new Rect(0, 0, cfRight, cfBottom); |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 339 | windowFrames.setFrames(pf, pf, pf, cf, cf, pf, cf, mEmptyRect); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 340 | w.computeFrameLw(); |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 341 | assertFrame(w, taskLeft, taskTop, taskRight, taskBottom); |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 342 | int contentInsetRight = taskRight - cfRight; |
| 343 | int contentInsetBottom = taskBottom - cfBottom; |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 344 | assertContentInset(w, 0, 0, contentInsetRight, contentInsetBottom); |
| 345 | assertContentFrame(w, new Rect(taskLeft, taskTop, taskRight - contentInsetRight, |
| 346 | taskBottom - contentInsetBottom)); |
Robert Carr | 15dd7ef | 2016-11-03 14:26:58 -0700 | [diff] [blame] | 347 | |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 348 | pf.set(0, 0, logicalWidth, logicalHeight); |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 349 | // If we set displayed bounds, the insets will be computed with the main task bounds |
| 350 | // but the frame will be positioned according to the displayed bounds. |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 351 | final int insetLeft = logicalWidth / 5; |
| 352 | final int insetTop = logicalHeight / 5; |
| 353 | final int insetRight = insetLeft + (taskRight - taskLeft); |
| 354 | final int insetBottom = insetTop + (taskBottom - taskTop); |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 355 | task.mOverrideDisplayedBounds.set(taskBounds); |
| 356 | task.mBounds.set(insetLeft, insetTop, insetRight, insetBottom); |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 357 | windowFrames.setFrames(pf, pf, pf, cf, cf, pf, cf, mEmptyRect); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 358 | w.computeFrameLw(); |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 359 | assertFrame(w, taskLeft, taskTop, taskRight, taskBottom); |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 360 | contentInsetRight = insetRight - cfRight; |
| 361 | contentInsetBottom = insetBottom - cfBottom; |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 362 | assertContentInset(w, 0, 0, contentInsetRight, contentInsetBottom); |
| 363 | assertContentFrame(w, new Rect(taskLeft, taskTop, taskRight - contentInsetRight, |
| 364 | taskBottom - contentInsetBottom)); |
Robert Carr | 15dd7ef | 2016-11-03 14:26:58 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 367 | @Test |
| 368 | public void testCalculatePolicyCrop() { |
| 369 | final WindowStateWithTask w = createWindow( |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 370 | new TaskWithBounds(mStubStack, mWm, null), MATCH_PARENT, MATCH_PARENT); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 371 | w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP; |
| 372 | |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 373 | final DisplayInfo displayInfo = w.getDisplayContent().getDisplayInfo(); |
| 374 | final int logicalWidth = displayInfo.logicalWidth; |
| 375 | final int logicalHeight = displayInfo.logicalHeight; |
| 376 | final Rect pf = new Rect(0, 0, logicalWidth, logicalHeight); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 377 | final Rect df = pf; |
| 378 | final Rect of = df; |
| 379 | final Rect cf = new Rect(pf); |
| 380 | // Produce some insets |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 381 | cf.top += displayInfo.logicalWidth / 10; |
| 382 | cf.bottom -= displayInfo.logicalWidth / 5; |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 383 | final Rect vf = cf; |
| 384 | final Rect sf = vf; |
| 385 | // We use a decor content frame with insets to produce cropping. |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 386 | Rect dcf = new Rect(cf); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 387 | |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 388 | final WindowFrames windowFrames = w.getWindowFrames(); |
| 389 | windowFrames.setFrames(pf, df, of, cf, vf, dcf, sf, mEmptyRect); |
| 390 | w.computeFrameLw(); |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 391 | assertPolicyCrop(w, 0, cf.top, logicalWidth, cf.bottom); |
chaviw | 0eac168 | 2017-11-02 11:27:51 -0700 | [diff] [blame] | 392 | |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 393 | windowFrames.mDecorFrame.setEmpty(); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 394 | // Likewise with no decor frame we would get no crop |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 395 | w.computeFrameLw(); |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 396 | assertPolicyCrop(w, 0, 0, logicalWidth, logicalHeight); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 397 | |
| 398 | // Now we set up a window which doesn't fill the entire decor frame. |
| 399 | // Normally it would be cropped to it's frame but in the case of docked resizing |
| 400 | // we need to account for the fact the windows surface will be made |
| 401 | // fullscreen and thus also make the crop fullscreen. |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 402 | |
| 403 | windowFrames.setFrames(pf, pf, pf, pf, pf, pf, pf, pf); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 404 | w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP; |
Andrii Kulian | a95bfff | 2017-03-30 19:00:41 -0700 | [diff] [blame] | 405 | w.mAttrs.width = logicalWidth / 2; |
| 406 | w.mAttrs.height = logicalHeight / 2; |
| 407 | w.mRequestedWidth = logicalWidth / 2; |
| 408 | w.mRequestedHeight = logicalHeight / 2; |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 409 | w.computeFrameLw(); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 410 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 411 | // Normally the crop is shrunk from the decor frame |
| 412 | // to the computed window frame. |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 413 | assertPolicyCrop(w, 0, 0, logicalWidth / 2, logicalHeight / 2); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 414 | |
| 415 | w.mDockedResizingForTest = true; |
Robert Carr | 186d9de | 2017-02-09 12:41:03 -0800 | [diff] [blame] | 416 | // But if we are docked resizing it won't be, however we will still be |
| 417 | // shrunk to the decor frame and the display. |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 418 | assertPolicyCrop(w, 0, 0, |
Robert Carr | 186d9de | 2017-02-09 12:41:03 -0800 | [diff] [blame] | 419 | Math.min(pf.width(), displayInfo.logicalWidth), |
| 420 | Math.min(pf.height(), displayInfo.logicalHeight)); |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Andrii Kulian | c24f373 | 2017-08-08 19:35:17 -0700 | [diff] [blame] | 423 | @Test |
| 424 | public void testLayoutLetterboxedWindow() { |
| 425 | // First verify task behavior in multi-window mode. |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 426 | final DisplayInfo displayInfo = mWm.getDefaultDisplayContentLocked().getDisplayInfo(); |
Andrii Kulian | c24f373 | 2017-08-08 19:35:17 -0700 | [diff] [blame] | 427 | final int logicalWidth = displayInfo.logicalWidth; |
| 428 | final int logicalHeight = displayInfo.logicalHeight; |
| 429 | |
| 430 | final int taskLeft = logicalWidth / 5; |
| 431 | final int taskTop = logicalHeight / 5; |
| 432 | final int taskRight = logicalWidth / 4 * 3; |
| 433 | final int taskBottom = logicalHeight / 4 * 3; |
| 434 | final Rect taskBounds = new Rect(taskLeft, taskTop, taskRight, taskBottom); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 435 | final TaskWithBounds task = new TaskWithBounds(mStubStack, mWm, taskBounds); |
Andrii Kulian | c24f373 | 2017-08-08 19:35:17 -0700 | [diff] [blame] | 436 | task.mFullscreenForTest = false; |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 437 | WindowState w = createWindow(task, MATCH_PARENT, MATCH_PARENT); |
Andrii Kulian | c24f373 | 2017-08-08 19:35:17 -0700 | [diff] [blame] | 438 | w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP; |
| 439 | |
| 440 | final Rect pf = new Rect(0, 0, logicalWidth, logicalHeight); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 441 | final WindowFrames windowFrames = w.getWindowFrames(); |
| 442 | windowFrames.setFrames(pf, pf, pf, pf, pf, pf, pf, mEmptyRect); |
| 443 | w.computeFrameLw(); |
Andrii Kulian | c24f373 | 2017-08-08 19:35:17 -0700 | [diff] [blame] | 444 | // For non fullscreen tasks the containing frame is based off the |
| 445 | // task bounds not the parent frame. |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 446 | assertFrame(w, taskLeft, taskTop, taskRight, taskBottom); |
| 447 | assertContentFrame(w, taskBounds); |
| 448 | assertContentInset(w, 0, 0, 0, 0); |
Andrii Kulian | c24f373 | 2017-08-08 19:35:17 -0700 | [diff] [blame] | 449 | |
| 450 | // Now simulate switch to fullscreen for letterboxed app. |
| 451 | final int xInset = logicalWidth / 10; |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 452 | final Rect cf = new Rect(xInset, 0, logicalWidth - xInset, logicalHeight); |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 453 | Configuration config = new Configuration(w.mAppToken.getRequestedOverrideConfiguration()); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 454 | config.windowConfiguration.setBounds(cf); |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 455 | w.mAppToken.onRequestedOverrideConfigurationChanged(config); |
Andrii Kulian | c24f373 | 2017-08-08 19:35:17 -0700 | [diff] [blame] | 456 | pf.set(0, 0, logicalWidth, logicalHeight); |
| 457 | task.mFullscreenForTest = true; |
chaviw | 553b021 | 2018-07-12 13:37:01 -0700 | [diff] [blame] | 458 | windowFrames.setFrames(pf, pf, pf, cf, cf, pf, cf, mEmptyRect); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 459 | w.computeFrameLw(); |
Kazuki Takise | e8d6d44 | 2018-07-23 17:40:20 +0900 | [diff] [blame] | 460 | assertFrame(w, cf.left, cf.top, cf.right, cf.bottom); |
| 461 | assertContentFrame(w, cf); |
| 462 | assertContentInset(w, 0, 0, 0, 0); |
Andrii Kulian | c24f373 | 2017-08-08 19:35:17 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 465 | @Test |
| 466 | public void testDisplayCutout() { |
| 467 | // Regular fullscreen task and window |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 468 | final Task task = new TaskWithBounds(mStubStack, mWm, null); |
| 469 | WindowState w = createWindow(task, MATCH_PARENT, MATCH_PARENT); |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 470 | w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP; |
| 471 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 472 | final Rect pf = new Rect(0, 0, 1000, 2000); |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 473 | // Create a display cutout of size 50x50, aligned top-center |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 474 | final WmDisplayCutout cutout = WmDisplayCutout.computeSafeInsets( |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 475 | fromBoundingRect(500, 0, 550, 50, BOUNDS_POSITION_TOP), |
| 476 | pf.width(), pf.height()); |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 477 | |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 478 | final WindowFrames windowFrames = w.getWindowFrames(); |
| 479 | windowFrames.setFrames(pf, pf, pf, pf, pf, pf, pf, pf); |
chaviw | cdba9a4 | 2018-07-19 11:36:42 -0700 | [diff] [blame] | 480 | windowFrames.setDisplayCutout(cutout); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 481 | w.computeFrameLw(); |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 482 | |
chaviw | cdba9a4 | 2018-07-19 11:36:42 -0700 | [diff] [blame] | 483 | assertEquals(w.getWmDisplayCutout().getDisplayCutout().getSafeInsetTop(), 50); |
| 484 | assertEquals(w.getWmDisplayCutout().getDisplayCutout().getSafeInsetBottom(), 0); |
| 485 | assertEquals(w.getWmDisplayCutout().getDisplayCutout().getSafeInsetLeft(), 0); |
| 486 | assertEquals(w.getWmDisplayCutout().getDisplayCutout().getSafeInsetRight(), 0); |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 487 | } |
| 488 | |
Jorim Jaggi | bae2b15 | 2018-04-18 17:27:27 +0200 | [diff] [blame] | 489 | @Test |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 490 | public void testDisplayCutout_tempDisplayedBounds() { |
Jorim Jaggi | bae2b15 | 2018-04-18 17:27:27 +0200 | [diff] [blame] | 491 | // Regular fullscreen task and window |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 492 | final TaskWithBounds task = new TaskWithBounds(mStubStack, mWm, |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 493 | new Rect(0, 0, 1000, 2000)); |
Jorim Jaggi | bae2b15 | 2018-04-18 17:27:27 +0200 | [diff] [blame] | 494 | task.mFullscreenForTest = false; |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 495 | task.setOverrideDisplayedBounds(new Rect(0, -500, 1000, 1500)); |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 496 | WindowState w = createWindow(task, MATCH_PARENT, MATCH_PARENT); |
Jorim Jaggi | bae2b15 | 2018-04-18 17:27:27 +0200 | [diff] [blame] | 497 | w.mAttrs.gravity = Gravity.LEFT | Gravity.TOP; |
| 498 | |
| 499 | final Rect pf = new Rect(0, -500, 1000, 1500); |
| 500 | // Create a display cutout of size 50x50, aligned top-center |
| 501 | final WmDisplayCutout cutout = WmDisplayCutout.computeSafeInsets( |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 502 | fromBoundingRect(500, 0, 550, 50, BOUNDS_POSITION_TOP), |
| 503 | pf.width(), pf.height()); |
Jorim Jaggi | bae2b15 | 2018-04-18 17:27:27 +0200 | [diff] [blame] | 504 | |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 505 | final WindowFrames windowFrames = w.getWindowFrames(); |
| 506 | windowFrames.setFrames(pf, pf, pf, pf, pf, pf, pf, pf); |
chaviw | cdba9a4 | 2018-07-19 11:36:42 -0700 | [diff] [blame] | 507 | windowFrames.setDisplayCutout(cutout); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 508 | w.computeFrameLw(); |
Jorim Jaggi | bae2b15 | 2018-04-18 17:27:27 +0200 | [diff] [blame] | 509 | |
chaviw | cdba9a4 | 2018-07-19 11:36:42 -0700 | [diff] [blame] | 510 | assertEquals(w.getWmDisplayCutout().getDisplayCutout().getSafeInsetTop(), 50); |
| 511 | assertEquals(w.getWmDisplayCutout().getDisplayCutout().getSafeInsetBottom(), 0); |
| 512 | assertEquals(w.getWmDisplayCutout().getDisplayCutout().getSafeInsetLeft(), 0); |
| 513 | assertEquals(w.getWmDisplayCutout().getDisplayCutout().getSafeInsetRight(), 0); |
Jorim Jaggi | bae2b15 | 2018-04-18 17:27:27 +0200 | [diff] [blame] | 514 | } |
| 515 | |
Robert Carr | fbbde85 | 2016-10-18 11:02:28 -0700 | [diff] [blame] | 516 | private WindowStateWithTask createWindow(Task task, int width, int height) { |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 517 | final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(TYPE_APPLICATION); |
| 518 | attrs.width = width; |
| 519 | attrs.height = height; |
| 520 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 521 | return new WindowStateWithTask(mWm, mIWindow, mWindowToken, attrs, task); |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 522 | } |
Robert Carr | 16a4e3c | 2016-10-28 11:45:22 -0700 | [diff] [blame] | 523 | } |