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