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