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