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