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