Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -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. |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
lumark | f948afe | 2019-05-23 21:22:36 +0800 | [diff] [blame] | 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Adrian Roos | 0e7b70a | 2018-06-07 15:29:34 +0200 | [diff] [blame] | 22 | import static android.hardware.camera2.params.OutputConfiguration.ROTATION_90; |
Jorim Jaggi | cfd6f3b | 2018-11-07 15:30:18 +0100 | [diff] [blame] | 23 | import static android.view.InsetsState.TYPE_TOP_BAR; |
Adrian Roos | 0e7b70a | 2018-06-07 15:29:34 +0200 | [diff] [blame] | 24 | import static android.view.Surface.ROTATION_0; |
Yunfan Chen | 5e696f1 | 2019-02-07 22:02:08 +0900 | [diff] [blame] | 25 | import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 26 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
| 28 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 29 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 30 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL; |
| 31 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 32 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; |
| 33 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; |
Suprabh Shukla | 69c7142 | 2018-04-02 18:39:01 -0700 | [diff] [blame] | 34 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 35 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL; |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 36 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
Jorim Jaggi | cfd6f3b | 2018-11-07 15:30:18 +0100 | [diff] [blame] | 37 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
chaviw | ebcbc34 | 2018-02-07 13:19:00 -0800 | [diff] [blame] | 38 | |
Yunfan Chen | d6c85a4 | 2019-02-18 15:52:17 +0900 | [diff] [blame] | 39 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing; |
lumark | f948afe | 2019-05-23 21:22:36 +0800 | [diff] [blame] | 40 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 41 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock; |
| 42 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; |
| 43 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset; |
| 44 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy; |
Yunfan Chen | db39c16 | 2019-02-08 16:14:14 +0900 | [diff] [blame] | 45 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; |
Tadashi G. Takaoka | bf0d57b | 2018-11-19 16:09:58 +0900 | [diff] [blame] | 46 | import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; |
| 47 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 48 | import static org.hamcrest.Matchers.is; |
| 49 | import static org.hamcrest.Matchers.not; |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 50 | import static org.junit.Assert.assertEquals; |
| 51 | import static org.junit.Assert.assertFalse; |
| 52 | import static org.junit.Assert.assertNull; |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 53 | import static org.junit.Assert.assertThat; |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 54 | import static org.junit.Assert.assertTrue; |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 55 | import static org.mockito.ArgumentMatchers.any; |
Michael Wright | e300104 | 2019-02-05 00:13:14 +0000 | [diff] [blame] | 56 | import static org.mockito.ArgumentMatchers.anyInt; |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 57 | import static org.mockito.ArgumentMatchers.anyLong; |
| 58 | import static org.mockito.ArgumentMatchers.anyString; |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 59 | import static org.mockito.ArgumentMatchers.eq; |
Vinit Nayak | 8009e92 | 2019-09-05 11:49:53 -0700 | [diff] [blame] | 60 | import static org.mockito.Mockito.when; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 61 | |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 62 | import android.graphics.Insets; |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 63 | import android.graphics.Matrix; |
Adrian Roos | 49c27ff | 2018-08-31 13:07:33 -0700 | [diff] [blame] | 64 | import android.graphics.Rect; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 65 | import android.platform.test.annotations.Presubmit; |
Adrian Roos | 49c27ff | 2018-08-31 13:07:33 -0700 | [diff] [blame] | 66 | import android.util.Size; |
| 67 | import android.view.DisplayCutout; |
Jorim Jaggi | cfd6f3b | 2018-11-07 15:30:18 +0100 | [diff] [blame] | 68 | import android.view.InsetsSource; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 69 | import android.view.SurfaceControl; |
Yunfan Chen | 5e696f1 | 2019-02-07 22:02:08 +0900 | [diff] [blame] | 70 | import android.view.ViewRootImpl; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 71 | import android.view.WindowManager; |
| 72 | |
Yunfan Chen | db39c16 | 2019-02-08 16:14:14 +0900 | [diff] [blame] | 73 | import androidx.test.filters.FlakyTest; |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 74 | import androidx.test.filters.SmallTest; |
| 75 | |
Adrian Roos | 49c27ff | 2018-08-31 13:07:33 -0700 | [diff] [blame] | 76 | import com.android.server.wm.utils.WmDisplayCutout; |
| 77 | |
Yunfan Chen | 5e696f1 | 2019-02-07 22:02:08 +0900 | [diff] [blame] | 78 | import org.junit.AfterClass; |
Yunfan Chen | db39c16 | 2019-02-08 16:14:14 +0900 | [diff] [blame] | 79 | import org.junit.Before; |
Yunfan Chen | 5e696f1 | 2019-02-07 22:02:08 +0900 | [diff] [blame] | 80 | import org.junit.BeforeClass; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 81 | import org.junit.Test; |
Riddle Hsu | 2da2d03 | 2019-08-28 21:08:58 +0800 | [diff] [blame] | 82 | import org.junit.runner.RunWith; |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 83 | |
| 84 | import java.util.LinkedList; |
| 85 | |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 86 | /** |
| 87 | * Tests for the {@link WindowState} class. |
| 88 | * |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 89 | * Build/Install/Run: |
| 90 | * atest FrameworksServicesTests:WindowStateTests |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 91 | */ |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 92 | @SmallTest |
| 93 | @Presubmit |
Riddle Hsu | 2da2d03 | 2019-08-28 21:08:58 +0800 | [diff] [blame] | 94 | @RunWith(WindowTestRunner.class) |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 95 | public class WindowStateTests extends WindowTestsBase { |
Yunfan Chen | 5e696f1 | 2019-02-07 22:02:08 +0900 | [diff] [blame] | 96 | private static int sPreviousNewInsetsMode; |
| 97 | |
| 98 | @BeforeClass |
| 99 | public static void setUpOnce() { |
Yunfan Chen | db39c16 | 2019-02-08 16:14:14 +0900 | [diff] [blame] | 100 | // TODO: Make use of SettingsSession when it becomes feasible for this. |
Yunfan Chen | 5e696f1 | 2019-02-07 22:02:08 +0900 | [diff] [blame] | 101 | sPreviousNewInsetsMode = ViewRootImpl.sNewInsetsMode; |
| 102 | // To let the insets provider control the insets visibility, the insets mode has to be |
| 103 | // NEW_INSETS_MODE_FULL. |
| 104 | ViewRootImpl.sNewInsetsMode = NEW_INSETS_MODE_FULL; |
| 105 | } |
| 106 | |
| 107 | @AfterClass |
| 108 | public static void tearDownOnce() { |
| 109 | ViewRootImpl.sNewInsetsMode = sPreviousNewInsetsMode; |
| 110 | } |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 111 | |
Yunfan Chen | db39c16 | 2019-02-08 16:14:14 +0900 | [diff] [blame] | 112 | @Before |
| 113 | public void setUp() { |
| 114 | // TODO: Let the insets source with new mode keep the visibility control, and remove this |
| 115 | // setup code. Now mTopFullscreenOpaqueWindowState will take back the control of insets |
| 116 | // visibility. |
Riddle Hsu | 2da2d03 | 2019-08-28 21:08:58 +0800 | [diff] [blame] | 117 | spyOn(mDisplayContent); |
| 118 | doNothing().when(mDisplayContent).layoutAndAssignWindowLayersIfNeeded(); |
Yunfan Chen | db39c16 | 2019-02-08 16:14:14 +0900 | [diff] [blame] | 119 | } |
| 120 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 121 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 122 | public void testIsParentWindowHidden() { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 123 | final WindowState parentWindow = createWindow(null, TYPE_APPLICATION, "parentWindow"); |
| 124 | final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child1"); |
| 125 | final WindowState child2 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child2"); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 126 | |
chaviw | ebcbc34 | 2018-02-07 13:19:00 -0800 | [diff] [blame] | 127 | // parentWindow is initially set to hidden. |
| 128 | assertTrue(parentWindow.mHidden); |
| 129 | assertFalse(parentWindow.isParentWindowHidden()); |
| 130 | assertTrue(child1.isParentWindowHidden()); |
| 131 | assertTrue(child2.isParentWindowHidden()); |
| 132 | |
| 133 | parentWindow.mHidden = false; |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 134 | assertFalse(parentWindow.isParentWindowHidden()); |
| 135 | assertFalse(child1.isParentWindowHidden()); |
| 136 | assertFalse(child2.isParentWindowHidden()); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 139 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 140 | public void testIsChildWindow() { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 141 | final WindowState parentWindow = createWindow(null, TYPE_APPLICATION, "parentWindow"); |
| 142 | final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child1"); |
| 143 | final WindowState child2 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child2"); |
| 144 | final WindowState randomWindow = createWindow(null, TYPE_APPLICATION, "randomWindow"); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 145 | |
| 146 | assertFalse(parentWindow.isChildWindow()); |
| 147 | assertTrue(child1.isChildWindow()); |
| 148 | assertTrue(child2.isChildWindow()); |
| 149 | assertFalse(randomWindow.isChildWindow()); |
| 150 | } |
| 151 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 152 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 153 | public void testHasChild() { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 154 | final WindowState win1 = createWindow(null, TYPE_APPLICATION, "win1"); |
| 155 | final WindowState win11 = createWindow(win1, FIRST_SUB_WINDOW, "win11"); |
| 156 | final WindowState win12 = createWindow(win1, FIRST_SUB_WINDOW, "win12"); |
| 157 | final WindowState win2 = createWindow(null, TYPE_APPLICATION, "win2"); |
| 158 | final WindowState win21 = createWindow(win2, FIRST_SUB_WINDOW, "win21"); |
| 159 | final WindowState randomWindow = createWindow(null, TYPE_APPLICATION, "randomWindow"); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 160 | |
| 161 | assertTrue(win1.hasChild(win11)); |
| 162 | assertTrue(win1.hasChild(win12)); |
| 163 | assertTrue(win2.hasChild(win21)); |
| 164 | |
| 165 | assertFalse(win1.hasChild(win21)); |
| 166 | assertFalse(win1.hasChild(randomWindow)); |
| 167 | |
| 168 | assertFalse(win2.hasChild(win11)); |
| 169 | assertFalse(win2.hasChild(win12)); |
| 170 | assertFalse(win2.hasChild(randomWindow)); |
| 171 | } |
| 172 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 173 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 174 | public void testGetParentWindow() { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 175 | final WindowState parentWindow = createWindow(null, TYPE_APPLICATION, "parentWindow"); |
| 176 | final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child1"); |
| 177 | final WindowState child2 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child2"); |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 178 | |
| 179 | assertNull(parentWindow.getParentWindow()); |
| 180 | assertEquals(parentWindow, child1.getParentWindow()); |
| 181 | assertEquals(parentWindow, child2.getParentWindow()); |
| 182 | } |
| 183 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 184 | @Test |
Suprabh Shukla | 69c7142 | 2018-04-02 18:39:01 -0700 | [diff] [blame] | 185 | public void testOverlayWindowHiddenWhenSuspended() { |
| 186 | final WindowState overlayWindow = spy(createWindow(null, TYPE_APPLICATION_OVERLAY, |
| 187 | "overlayWindow")); |
| 188 | overlayWindow.setHiddenWhileSuspended(true); |
| 189 | verify(overlayWindow).hideLw(true, true); |
| 190 | overlayWindow.setHiddenWhileSuspended(false); |
| 191 | verify(overlayWindow).showLw(true, true); |
| 192 | } |
| 193 | |
| 194 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 195 | public void testGetTopParentWindow() { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 196 | final WindowState root = createWindow(null, TYPE_APPLICATION, "root"); |
| 197 | final WindowState child1 = createWindow(root, FIRST_SUB_WINDOW, "child1"); |
| 198 | final WindowState child2 = createWindow(child1, FIRST_SUB_WINDOW, "child2"); |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 199 | |
| 200 | assertEquals(root, root.getTopParentWindow()); |
| 201 | assertEquals(root, child1.getTopParentWindow()); |
| 202 | assertEquals(child1, child2.getParentWindow()); |
| 203 | assertEquals(root, child2.getTopParentWindow()); |
Wale Ogunwale | ea92d97 | 2016-12-08 07:33:13 -0800 | [diff] [blame] | 204 | |
| 205 | // Test case were child is detached from parent. |
| 206 | root.removeChild(child1); |
| 207 | assertEquals(child1, child1.getTopParentWindow()); |
| 208 | assertEquals(child1, child2.getParentWindow()); |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Jorim Jaggi | af221d1 | 2016-11-15 14:59:57 -0800 | [diff] [blame] | 211 | @Test |
| 212 | public void testIsOnScreen_hiddenByPolicy() { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 213 | final WindowState window = createWindow(null, TYPE_APPLICATION, "window"); |
Jorim Jaggi | af221d1 | 2016-11-15 14:59:57 -0800 | [diff] [blame] | 214 | window.setHasSurface(true); |
| 215 | assertTrue(window.isOnScreen()); |
| 216 | window.hideLw(false /* doAnimation */); |
| 217 | assertFalse(window.isOnScreen()); |
| 218 | } |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 219 | |
| 220 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 221 | public void testCanBeImeTarget() { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 222 | final WindowState appWindow = createWindow(null, TYPE_APPLICATION, "appWindow"); |
| 223 | final WindowState imeWindow = createWindow(null, TYPE_INPUT_METHOD, "imeWindow"); |
| 224 | |
Tarandeep Singh | 0ffa15a | 2019-11-04 13:40:15 -0800 | [diff] [blame] | 225 | // Setting FLAG_NOT_FOCUSABLE prevents the window from being an IME target. |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 226 | appWindow.mAttrs.flags |= FLAG_NOT_FOCUSABLE; |
| 227 | imeWindow.mAttrs.flags |= FLAG_NOT_FOCUSABLE; |
| 228 | |
| 229 | // Make windows visible |
| 230 | appWindow.setHasSurface(true); |
| 231 | imeWindow.setHasSurface(true); |
| 232 | |
Tarandeep Singh | 0ffa15a | 2019-11-04 13:40:15 -0800 | [diff] [blame] | 233 | // Windows with FLAG_NOT_FOCUSABLE can't be IME targets |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 234 | assertFalse(appWindow.canBeImeTarget()); |
| 235 | assertFalse(imeWindow.canBeImeTarget()); |
| 236 | |
| 237 | // Add IME target flags |
| 238 | appWindow.mAttrs.flags |= (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM); |
| 239 | imeWindow.mAttrs.flags |= (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM); |
| 240 | |
Tarandeep Singh | 0ffa15a | 2019-11-04 13:40:15 -0800 | [diff] [blame] | 241 | // Visible app window with flags FLAG_NOT_FOCUSABLE or FLAG_ALT_FOCUSABLE_IM can't be IME |
| 242 | // target while an IME window can never be an IME target regardless of its visibility |
| 243 | // or flags. |
| 244 | assertFalse(appWindow.canBeImeTarget()); |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 245 | assertFalse(imeWindow.canBeImeTarget()); |
| 246 | |
Tarandeep Singh | 0ffa15a | 2019-11-04 13:40:15 -0800 | [diff] [blame] | 247 | appWindow.mAttrs.flags &= ~FLAG_ALT_FOCUSABLE_IM; |
| 248 | assertFalse(appWindow.canBeImeTarget()); |
| 249 | appWindow.mAttrs.flags &= ~FLAG_NOT_FOCUSABLE; |
| 250 | assertTrue(appWindow.canBeImeTarget()); |
| 251 | |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 252 | // Make windows invisible |
| 253 | appWindow.hideLw(false /* doAnimation */); |
| 254 | imeWindow.hideLw(false /* doAnimation */); |
| 255 | |
| 256 | // Invisible window can't be IME targets even if they have the right flags. |
| 257 | assertFalse(appWindow.canBeImeTarget()); |
| 258 | assertFalse(imeWindow.canBeImeTarget()); |
lumark | f948afe | 2019-05-23 21:22:36 +0800 | [diff] [blame] | 259 | |
| 260 | // Simulate the window is in split screen primary stack and the current state is |
| 261 | // minimized and home stack is resizable, so that we should ignore input for the stack. |
| 262 | final DockedStackDividerController controller = |
| 263 | mDisplayContent.getDockedDividerController(); |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 264 | final ActivityStack stack = createTaskStackOnDisplay(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, |
lumark | f948afe | 2019-05-23 21:22:36 +0800 | [diff] [blame] | 265 | ACTIVITY_TYPE_STANDARD, mDisplayContent); |
| 266 | spyOn(appWindow); |
| 267 | spyOn(controller); |
| 268 | spyOn(stack); |
| 269 | doReturn(true).when(controller).isMinimizedDock(); |
| 270 | doReturn(true).when(controller).isHomeStackResizable(); |
| 271 | doReturn(stack).when(appWindow).getStack(); |
| 272 | |
| 273 | // Make sure canBeImeTarget is false due to shouldIgnoreInput is true; |
| 274 | assertFalse(appWindow.canBeImeTarget()); |
| 275 | assertTrue(stack.shouldIgnoreInput()); |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 276 | } |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 277 | |
| 278 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 279 | public void testGetWindow() { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 280 | final WindowState root = createWindow(null, TYPE_APPLICATION, "root"); |
| 281 | final WindowState mediaChild = createWindow(root, TYPE_APPLICATION_MEDIA, "mediaChild"); |
| 282 | final WindowState mediaOverlayChild = createWindow(root, |
| 283 | TYPE_APPLICATION_MEDIA_OVERLAY, "mediaOverlayChild"); |
| 284 | final WindowState attachedDialogChild = createWindow(root, |
| 285 | TYPE_APPLICATION_ATTACHED_DIALOG, "attachedDialogChild"); |
| 286 | final WindowState subPanelChild = createWindow(root, |
| 287 | TYPE_APPLICATION_SUB_PANEL, "subPanelChild"); |
| 288 | final WindowState aboveSubPanelChild = createWindow(root, |
| 289 | TYPE_APPLICATION_ABOVE_SUB_PANEL, "aboveSubPanelChild"); |
| 290 | |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 291 | final LinkedList<WindowState> windows = new LinkedList<>(); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 292 | |
| 293 | root.getWindow(w -> { |
| 294 | windows.addLast(w); |
| 295 | return false; |
| 296 | }); |
| 297 | |
| 298 | // getWindow should have returned candidate windows in z-order. |
| 299 | assertEquals(aboveSubPanelChild, windows.pollFirst()); |
| 300 | assertEquals(subPanelChild, windows.pollFirst()); |
| 301 | assertEquals(attachedDialogChild, windows.pollFirst()); |
| 302 | assertEquals(root, windows.pollFirst()); |
| 303 | assertEquals(mediaOverlayChild, windows.pollFirst()); |
| 304 | assertEquals(mediaChild, windows.pollFirst()); |
| 305 | assertTrue(windows.isEmpty()); |
| 306 | } |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 307 | |
| 308 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 309 | public void testPrepareWindowToDisplayDuringRelayout() { |
Riddle Hsu | 4bb06be | 2019-07-02 01:03:07 +0800 | [diff] [blame] | 310 | // Call prepareWindowToDisplayDuringRelayout for a window without FLAG_TURN_SCREEN_ON before |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 311 | // calling setCurrentLaunchCanTurnScreenOn for windows with flag in the same activity. |
| 312 | final ActivityRecord activity = createActivityRecord(mDisplayContent, |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 313 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 314 | final WindowState first = createWindow(null, TYPE_APPLICATION, activity, "first"); |
| 315 | final WindowState second = createWindow(null, TYPE_APPLICATION, activity, "second"); |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 316 | second.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
| 317 | |
Riddle Hsu | 4bb06be | 2019-07-02 01:03:07 +0800 | [diff] [blame] | 318 | testPrepareWindowToDisplayDuringRelayout(first, false /* expectedWakeupCalled */, |
| 319 | true /* expectedCurrentLaunchCanTurnScreenOn */); |
| 320 | testPrepareWindowToDisplayDuringRelayout(second, true /* expectedWakeupCalled */, |
| 321 | false /* expectedCurrentLaunchCanTurnScreenOn */); |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 322 | |
| 323 | // Call prepareWindowToDisplayDuringRelayout for two window that have FLAG_TURN_SCREEN_ON |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 324 | // from the same activity. Only one should trigger the wakeup. |
| 325 | activity.setCurrentLaunchCanTurnScreenOn(true); |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 326 | first.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
| 327 | second.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
| 328 | |
Riddle Hsu | 4bb06be | 2019-07-02 01:03:07 +0800 | [diff] [blame] | 329 | testPrepareWindowToDisplayDuringRelayout(first, true /* expectedWakeupCalled */, |
| 330 | false /* expectedCurrentLaunchCanTurnScreenOn */); |
| 331 | testPrepareWindowToDisplayDuringRelayout(second, false /* expectedWakeupCalled */, |
| 332 | false /* expectedCurrentLaunchCanTurnScreenOn */); |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 333 | |
Riddle Hsu | 4bb06be | 2019-07-02 01:03:07 +0800 | [diff] [blame] | 334 | // Without window flags, the state of ActivityRecord.canTurnScreenOn should still be able to |
| 335 | // turn on the screen. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 336 | activity.setCurrentLaunchCanTurnScreenOn(true); |
Riddle Hsu | 4bb06be | 2019-07-02 01:03:07 +0800 | [diff] [blame] | 337 | first.mAttrs.flags &= ~WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 338 | doReturn(true).when(activity).canTurnScreenOn(); |
Riddle Hsu | 4bb06be | 2019-07-02 01:03:07 +0800 | [diff] [blame] | 339 | |
| 340 | testPrepareWindowToDisplayDuringRelayout(first, true /* expectedWakeupCalled */, |
| 341 | false /* expectedCurrentLaunchCanTurnScreenOn */); |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 342 | |
| 343 | // Call prepareWindowToDisplayDuringRelayout for a windows that are not children of an |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 344 | // activity. Both windows have the FLAG_TURNS_SCREEN_ON so both should call wakeup |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 345 | final WindowToken windowToken = WindowTestUtils.createTestWindowToken(FIRST_SUB_WINDOW, |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 346 | mDisplayContent); |
| 347 | final WindowState firstWindow = createWindow(null, TYPE_APPLICATION, windowToken, |
| 348 | "firstWindow"); |
| 349 | final WindowState secondWindow = createWindow(null, TYPE_APPLICATION, windowToken, |
| 350 | "secondWindow"); |
| 351 | firstWindow.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
| 352 | secondWindow.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
| 353 | |
Garfield Tan | e3d37b5 | 2019-07-23 12:43:05 -0700 | [diff] [blame] | 354 | final WindowState.PowerManagerWrapper powerManagerWrapper = |
| 355 | mSystemServicesTestRule.getPowerManagerWrapper(); |
| 356 | reset(powerManagerWrapper); |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 357 | firstWindow.prepareWindowToDisplayDuringRelayout(false /*wasVisible*/); |
Garfield Tan | e3d37b5 | 2019-07-23 12:43:05 -0700 | [diff] [blame] | 358 | verify(powerManagerWrapper).wakeUp(anyLong(), anyInt(), anyString()); |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 359 | |
Garfield Tan | e3d37b5 | 2019-07-23 12:43:05 -0700 | [diff] [blame] | 360 | reset(powerManagerWrapper); |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 361 | secondWindow.prepareWindowToDisplayDuringRelayout(false /*wasVisible*/); |
Garfield Tan | e3d37b5 | 2019-07-23 12:43:05 -0700 | [diff] [blame] | 362 | verify(powerManagerWrapper).wakeUp(anyLong(), anyInt(), anyString()); |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Riddle Hsu | 4bb06be | 2019-07-02 01:03:07 +0800 | [diff] [blame] | 365 | private void testPrepareWindowToDisplayDuringRelayout(WindowState appWindow, |
| 366 | boolean expectedWakeupCalled, boolean expectedCurrentLaunchCanTurnScreenOn) { |
Garfield Tan | e3d37b5 | 2019-07-23 12:43:05 -0700 | [diff] [blame] | 367 | final WindowState.PowerManagerWrapper powerManagerWrapper = |
| 368 | mSystemServicesTestRule.getPowerManagerWrapper(); |
| 369 | reset(powerManagerWrapper); |
Riddle Hsu | 4bb06be | 2019-07-02 01:03:07 +0800 | [diff] [blame] | 370 | appWindow.prepareWindowToDisplayDuringRelayout(false /* wasVisible */); |
| 371 | |
| 372 | if (expectedWakeupCalled) { |
Garfield Tan | e3d37b5 | 2019-07-23 12:43:05 -0700 | [diff] [blame] | 373 | verify(powerManagerWrapper).wakeUp(anyLong(), anyInt(), anyString()); |
Riddle Hsu | 4bb06be | 2019-07-02 01:03:07 +0800 | [diff] [blame] | 374 | } else { |
Garfield Tan | e3d37b5 | 2019-07-23 12:43:05 -0700 | [diff] [blame] | 375 | verify(powerManagerWrapper, never()).wakeUp(anyLong(), anyInt(), anyString()); |
Riddle Hsu | 4bb06be | 2019-07-02 01:03:07 +0800 | [diff] [blame] | 376 | } |
| 377 | // If wakeup is expected to be called, the currentLaunchCanTurnScreenOn should be false |
| 378 | // because the state will be consumed. |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 379 | assertThat(appWindow.mActivityRecord.currentLaunchCanTurnScreenOn(), |
Riddle Hsu | 4bb06be | 2019-07-02 01:03:07 +0800 | [diff] [blame] | 380 | is(expectedCurrentLaunchCanTurnScreenOn)); |
| 381 | } |
| 382 | |
Jorim Jaggi | 7220775 | 2018-01-08 13:16:59 +0100 | [diff] [blame] | 383 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 384 | public void testCanAffectSystemUiFlags() { |
Jorim Jaggi | 7220775 | 2018-01-08 13:16:59 +0100 | [diff] [blame] | 385 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Issei Suzuki | 7b9e257 | 2019-11-14 16:19:54 +0100 | [diff] [blame] | 386 | app.mToken.setHidden(false); |
Jorim Jaggi | 7220775 | 2018-01-08 13:16:59 +0100 | [diff] [blame] | 387 | assertTrue(app.canAffectSystemUiFlags()); |
Issei Suzuki | 7b9e257 | 2019-11-14 16:19:54 +0100 | [diff] [blame] | 388 | app.mToken.setHidden(true); |
Jorim Jaggi | 7220775 | 2018-01-08 13:16:59 +0100 | [diff] [blame] | 389 | assertFalse(app.canAffectSystemUiFlags()); |
Issei Suzuki | 7b9e257 | 2019-11-14 16:19:54 +0100 | [diff] [blame] | 390 | app.mToken.setHidden(false); |
Jorim Jaggi | 7220775 | 2018-01-08 13:16:59 +0100 | [diff] [blame] | 391 | app.mAttrs.alpha = 0.0f; |
| 392 | assertFalse(app.canAffectSystemUiFlags()); |
Jorim Jaggi | 50bf59c | 2018-03-09 17:29:48 +0100 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 396 | public void testCanAffectSystemUiFlags_disallow() { |
Jorim Jaggi | 50bf59c | 2018-03-09 17:29:48 +0100 | [diff] [blame] | 397 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
Issei Suzuki | 7b9e257 | 2019-11-14 16:19:54 +0100 | [diff] [blame] | 398 | app.mToken.setHidden(false); |
Jorim Jaggi | 50bf59c | 2018-03-09 17:29:48 +0100 | [diff] [blame] | 399 | assertTrue(app.canAffectSystemUiFlags()); |
| 400 | app.getTask().setCanAffectSystemUiFlags(false); |
| 401 | assertFalse(app.canAffectSystemUiFlags()); |
Jorim Jaggi | 7220775 | 2018-01-08 13:16:59 +0100 | [diff] [blame] | 402 | } |
| 403 | |
Jorim Jaggi | 4876b4a | 2018-01-11 15:43:49 +0100 | [diff] [blame] | 404 | @Test |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 405 | public void testVisibleWithInsetsProvider() { |
Jorim Jaggi | cfd6f3b | 2018-11-07 15:30:18 +0100 | [diff] [blame] | 406 | final WindowState topBar = createWindow(null, TYPE_STATUS_BAR, "topBar"); |
| 407 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
| 408 | topBar.mHasSurface = true; |
| 409 | assertTrue(topBar.isVisible()); |
| 410 | mDisplayContent.getInsetsStateController().getSourceProvider(TYPE_TOP_BAR) |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 411 | .setWindow(topBar, null /* frameProvider */); |
| 412 | mDisplayContent.getInsetsStateController().onBarControlTargetChanged( |
| 413 | app, null /* fakeTopControlling */, app, null /* fakeNavControlling */); |
Jorim Jaggi | cfd6f3b | 2018-11-07 15:30:18 +0100 | [diff] [blame] | 414 | mDisplayContent.getInsetsStateController().getSourceProvider(TYPE_TOP_BAR) |
| 415 | .onInsetsModified(app, new InsetsSource(TYPE_TOP_BAR)); |
Yunfan Chen | db39c16 | 2019-02-08 16:14:14 +0900 | [diff] [blame] | 416 | waitUntilHandlersIdle(); |
Jorim Jaggi | cfd6f3b | 2018-11-07 15:30:18 +0100 | [diff] [blame] | 417 | assertFalse(topBar.isVisible()); |
| 418 | } |
| 419 | |
| 420 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 421 | public void testIsSelfOrAncestorWindowAnimating() { |
Jorim Jaggi | 4876b4a | 2018-01-11 15:43:49 +0100 | [diff] [blame] | 422 | final WindowState root = createWindow(null, TYPE_APPLICATION, "root"); |
| 423 | final WindowState child1 = createWindow(root, FIRST_SUB_WINDOW, "child1"); |
| 424 | final WindowState child2 = createWindow(child1, FIRST_SUB_WINDOW, "child2"); |
| 425 | assertFalse(child2.isSelfOrAncestorWindowAnimatingExit()); |
| 426 | child2.mAnimatingExit = true; |
| 427 | assertTrue(child2.isSelfOrAncestorWindowAnimatingExit()); |
| 428 | child2.mAnimatingExit = false; |
| 429 | root.mAnimatingExit = true; |
| 430 | assertTrue(child2.isSelfOrAncestorWindowAnimatingExit()); |
| 431 | } |
| 432 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 433 | @Test |
Yunfan Chen | d6c85a4 | 2019-02-18 15:52:17 +0900 | [diff] [blame] | 434 | @FlakyTest(bugId = 74078662) |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 435 | public void testLayoutSeqResetOnReparent() { |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 436 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
| 437 | app.mLayoutSeq = 1; |
| 438 | mDisplayContent.mLayoutSeq = 1; |
| 439 | |
Garfield Tan | e223e68 | 2019-04-15 09:59:25 -0700 | [diff] [blame] | 440 | DisplayContent newDisplay = createNewDisplay(); |
| 441 | |
| 442 | app.onDisplayChanged(newDisplay); |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 443 | |
| 444 | assertThat(app.mLayoutSeq, not(is(mDisplayContent.mLayoutSeq))); |
| 445 | } |
| 446 | |
Brad Stenning | af59641 | 2018-04-02 12:03:19 -0700 | [diff] [blame] | 447 | @Test |
Tadashi G. Takaoka | b6e148c | 2018-11-03 02:59:06 -0700 | [diff] [blame] | 448 | public void testDisplayIdUpdatedOnReparent() { |
Brad Stenning | af59641 | 2018-04-02 12:03:19 -0700 | [diff] [blame] | 449 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
| 450 | // fake a different display |
| 451 | app.mInputWindowHandle.displayId = mDisplayContent.getDisplayId() + 1; |
| 452 | app.onDisplayChanged(mDisplayContent); |
| 453 | |
| 454 | assertThat(app.mInputWindowHandle.displayId, is(mDisplayContent.getDisplayId())); |
| 455 | assertThat(app.getDisplayId(), is(mDisplayContent.getDisplayId())); |
| 456 | } |
| 457 | |
Adrian Roos | 0e7b70a | 2018-06-07 15:29:34 +0200 | [diff] [blame] | 458 | @Test |
| 459 | public void testSeamlesslyRotateWindow() { |
| 460 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
chaviw | 619da69 | 2019-06-10 15:39:40 -0700 | [diff] [blame] | 461 | final SurfaceControl.Transaction t = spy(StubTransaction.class); |
Adrian Roos | 0e7b70a | 2018-06-07 15:29:34 +0200 | [diff] [blame] | 462 | |
| 463 | app.mHasSurface = true; |
Vishnu Nair | d8c664b | 2018-09-24 12:52:35 -0700 | [diff] [blame] | 464 | app.mSurfaceControl = mock(SurfaceControl.class); |
Adrian Roos | 0e7b70a | 2018-06-07 15:29:34 +0200 | [diff] [blame] | 465 | try { |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 466 | app.getFrameLw().set(10, 20, 60, 80); |
Vishnu Nair | d8c664b | 2018-09-24 12:52:35 -0700 | [diff] [blame] | 467 | app.updateSurfacePosition(t); |
Adrian Roos | 0e7b70a | 2018-06-07 15:29:34 +0200 | [diff] [blame] | 468 | |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 469 | app.seamlesslyRotateIfAllowed(t, ROTATION_0, ROTATION_90, true); |
Adrian Roos | 0e7b70a | 2018-06-07 15:29:34 +0200 | [diff] [blame] | 470 | |
| 471 | assertTrue(app.mSeamlesslyRotated); |
Vishnu Nair | d8c664b | 2018-09-24 12:52:35 -0700 | [diff] [blame] | 472 | |
| 473 | // Verify we un-rotate the window state surface. |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 474 | Matrix matrix = new Matrix(); |
| 475 | // Un-rotate 90 deg |
| 476 | matrix.setRotate(270); |
| 477 | // Translate it back to origin |
| 478 | matrix.postTranslate(0, mDisplayInfo.logicalWidth); |
Vishnu Nair | d8c664b | 2018-09-24 12:52:35 -0700 | [diff] [blame] | 479 | verify(t).setMatrix(eq(app.mSurfaceControl), eq(matrix), any(float[].class)); |
| 480 | |
| 481 | // Verify we update the position as well. |
| 482 | float[] currentSurfacePos = {app.mLastSurfacePosition.x, app.mLastSurfacePosition.y}; |
| 483 | matrix.mapPoints(currentSurfacePos); |
| 484 | verify(t).setPosition(eq(app.mSurfaceControl), eq(currentSurfacePos[0]), |
| 485 | eq(currentSurfacePos[1])); |
Adrian Roos | 0e7b70a | 2018-06-07 15:29:34 +0200 | [diff] [blame] | 486 | } finally { |
Vishnu Nair | d8c664b | 2018-09-24 12:52:35 -0700 | [diff] [blame] | 487 | app.mSurfaceControl = null; |
Adrian Roos | 0e7b70a | 2018-06-07 15:29:34 +0200 | [diff] [blame] | 488 | app.mHasSurface = false; |
| 489 | } |
| 490 | } |
| 491 | |
Adrian Roos | 49c27ff | 2018-08-31 13:07:33 -0700 | [diff] [blame] | 492 | @Test |
Yunfan Chen | d6c85a4 | 2019-02-18 15:52:17 +0900 | [diff] [blame] | 493 | @FlakyTest(bugId = 74078662) |
Adrian Roos | 49c27ff | 2018-08-31 13:07:33 -0700 | [diff] [blame] | 494 | public void testDisplayCutoutIsCalculatedRelativeToFrame() { |
| 495 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 496 | WindowFrames wf = app.getWindowFrames(); |
Adrian Roos | 49c27ff | 2018-08-31 13:07:33 -0700 | [diff] [blame] | 497 | wf.mParentFrame.set(7, 10, 185, 380); |
| 498 | wf.mDisplayFrame.set(wf.mParentFrame); |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 499 | final DisplayCutout cutout = new DisplayCutout( |
| 500 | Insets.of(0, 15, 0, 22) /* safeInset */, |
| 501 | null /* boundLeft */, |
| 502 | new Rect(95, 0, 105, 15), |
| 503 | null /* boundRight */, |
| 504 | new Rect(95, 378, 105, 400)); |
Adrian Roos | 49c27ff | 2018-08-31 13:07:33 -0700 | [diff] [blame] | 505 | wf.setDisplayCutout(new WmDisplayCutout(cutout, new Size(200, 400))); |
| 506 | |
chaviw | 1454b39 | 2018-08-06 09:54:04 -0700 | [diff] [blame] | 507 | app.computeFrameLw(); |
Adrian Roos | 49c27ff | 2018-08-31 13:07:33 -0700 | [diff] [blame] | 508 | assertThat(app.getWmDisplayCutout().getDisplayCutout(), is(cutout.inset(7, 10, 5, 20))); |
| 509 | } |
| 510 | |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 511 | @Test |
| 512 | public void testVisibilityChangeSwitchUser() { |
| 513 | final WindowState window = createWindow(null, TYPE_APPLICATION, "app"); |
| 514 | window.mHasSurface = true; |
| 515 | window.setShowToOwnerOnlyLocked(true); |
| 516 | |
| 517 | mWm.mCurrentUserId = 1; |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 518 | window.switchUser(mWm.mCurrentUserId); |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 519 | assertFalse(window.isVisible()); |
| 520 | assertFalse(window.isVisibleByPolicy()); |
| 521 | |
| 522 | mWm.mCurrentUserId = 0; |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 523 | window.switchUser(mWm.mCurrentUserId); |
chaviw | 15ad49f | 2019-04-24 15:05:39 -0700 | [diff] [blame] | 524 | assertTrue(window.isVisible()); |
| 525 | assertTrue(window.isVisibleByPolicy()); |
| 526 | } |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 527 | |
| 528 | @Test |
| 529 | public void testGetTransformationMatrix() { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 530 | final int PARENT_WINDOW_OFFSET = 1; |
| 531 | final int DISPLAY_IN_PARENT_WINDOW_OFFSET = 2; |
| 532 | final int WINDOW_OFFSET = 3; |
| 533 | final float OFFSET_SUM = |
| 534 | PARENT_WINDOW_OFFSET + DISPLAY_IN_PARENT_WINDOW_OFFSET + WINDOW_OFFSET; |
| 535 | |
Riddle Hsu | 2da2d03 | 2019-08-28 21:08:58 +0800 | [diff] [blame] | 536 | final WindowState win0 = createWindow(null, TYPE_APPLICATION, "win0"); |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 537 | |
Riddle Hsu | 2da2d03 | 2019-08-28 21:08:58 +0800 | [diff] [blame] | 538 | final DisplayContent dc = createNewDisplay(); |
| 539 | win0.getFrameLw().offsetTo(PARENT_WINDOW_OFFSET, 0); |
| 540 | dc.reparentDisplayContent(win0, win0.getSurfaceControl()); |
| 541 | dc.updateLocation(win0, DISPLAY_IN_PARENT_WINDOW_OFFSET, 0); |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 542 | |
Riddle Hsu | 2da2d03 | 2019-08-28 21:08:58 +0800 | [diff] [blame] | 543 | final float[] values = new float[9]; |
| 544 | final Matrix matrix = new Matrix(); |
chaviw | 619da69 | 2019-06-10 15:39:40 -0700 | [diff] [blame] | 545 | final SurfaceControl.Transaction t = spy(StubTransaction.class); |
Riddle Hsu | 2da2d03 | 2019-08-28 21:08:58 +0800 | [diff] [blame] | 546 | final WindowState win1 = createWindow(null, TYPE_APPLICATION, dc, "win1"); |
| 547 | win1.mHasSurface = true; |
| 548 | win1.mSurfaceControl = mock(SurfaceControl.class); |
| 549 | win1.getFrameLw().offsetTo(WINDOW_OFFSET, 0); |
| 550 | win1.updateSurfacePosition(t); |
| 551 | win1.getTransformationMatrix(values, matrix); |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 552 | |
Riddle Hsu | 2da2d03 | 2019-08-28 21:08:58 +0800 | [diff] [blame] | 553 | matrix.getValues(values); |
| 554 | assertEquals(OFFSET_SUM, values[Matrix.MTRANS_X], 0f); |
| 555 | assertEquals(0f, values[Matrix.MTRANS_Y], 0f); |
Tiger Huang | d8ec938 | 2019-04-18 14:35:09 -0700 | [diff] [blame] | 556 | } |
Vinit Nayak | 8009e92 | 2019-09-05 11:49:53 -0700 | [diff] [blame] | 557 | |
| 558 | @Test |
| 559 | public void testCantReceiveTouchDuringRecentsAnimation() { |
| 560 | final WindowState win0 = createWindow(null, TYPE_APPLICATION, "win0"); |
| 561 | |
| 562 | // Mock active recents animation |
| 563 | RecentsAnimationController recentsController = mock(RecentsAnimationController.class); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 564 | when(recentsController.isAnimatingTask(win0.mActivityRecord.getTask())).thenReturn(true); |
Vinit Nayak | 8009e92 | 2019-09-05 11:49:53 -0700 | [diff] [blame] | 565 | mWm.setRecentsAnimationController(recentsController); |
| 566 | assertTrue(win0.cantReceiveTouchInput()); |
| 567 | } |
| 568 | |
| 569 | @Test |
| 570 | public void testCantReceiveTouchWhenAppTokenHiddenRequested() { |
| 571 | final WindowState win0 = createWindow(null, TYPE_APPLICATION, "win0"); |
Issei Suzuki | 1669ea4 | 2019-11-06 14:20:59 +0100 | [diff] [blame] | 572 | win0.mActivityRecord.mVisibleRequested = false; |
Vinit Nayak | 8009e92 | 2019-09-05 11:49:53 -0700 | [diff] [blame] | 573 | assertTrue(win0.cantReceiveTouchInput()); |
| 574 | } |
| 575 | |
| 576 | @Test |
| 577 | public void testCantReceiveTouchWhenShouldIgnoreInput() { |
| 578 | final WindowState win0 = createWindow(null, TYPE_APPLICATION, "win0"); |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 579 | win0.mActivityRecord.getStack().setAdjustedForMinimizedDock(1 /* Any non 0 value works */); |
Vinit Nayak | 8009e92 | 2019-09-05 11:49:53 -0700 | [diff] [blame] | 580 | assertTrue(win0.cantReceiveTouchInput()); |
| 581 | } |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 582 | } |