blob: 65fb2c0451d82da7f277a08c4610c587610e9852 [file] [log] [blame]
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001/*
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. Takaokab6e148c2018-11-03 02:59:06 -070014 * limitations under the License.
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070015 */
16
17package com.android.server.wm;
18
chaviwb28de1f2018-03-02 10:42:36 -080019import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
20import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
lumarkf948afe2019-05-23 21:22:36 +080021import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
Adrian Roos0e7b70a2018-06-07 15:29:34 +020022import static android.hardware.camera2.params.OutputConfiguration.ROTATION_90;
Tiger Huang332793b2019-10-29 23:21:27 +080023import static android.view.InsetsState.ITYPE_STATUS_BAR;
Adrian Roos0e7b70a2018-06-07 15:29:34 +020024import static android.view.Surface.ROTATION_0;
Yunfan Chen5e696f12019-02-07 22:02:08 +090025import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070026import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Wale Ogunwale805d9ec2016-12-07 12:22:08 -080027import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
28import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070029import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwale34247952017-02-19 11:57:53 -080030import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL;
31import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
32import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
33import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
Suprabh Shukla69c71422018-04-02 18:39:01 -070034import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
Riddle Hsu5df3b752019-12-16 13:27:37 -060035import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale34247952017-02-19 11:57:53 -080036import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL;
Riddle Hsu5df3b752019-12-16 13:27:37 -060037import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale805d9ec2016-12-07 12:22:08 -080038import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
Jorim Jaggicfd6f3b2018-11-07 15:30:18 +010039import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
chaviwebcbc342018-02-07 13:19:00 -080040
Yunfan Chend6c85a42019-02-18 15:52:17 +090041import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
lumarkf948afe2019-05-23 21:22:36 +080042import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
Riddle Hsu839b5f52020-03-31 21:41:18 +080043import static com.android.dx.mockito.inline.extended.ExtendedMockito.doThrow;
Tadashi G. Takaokabf0d57b2018-11-19 16:09:58 +090044import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
45import static com.android.dx.mockito.inline.extended.ExtendedMockito.never;
46import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset;
47import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy;
Yunfan Chendb39c162019-02-08 16:14:14 +090048import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
Tadashi G. Takaokabf0d57b2018-11-19 16:09:58 +090049import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
50
Riddle Hsu839b5f52020-03-31 21:41:18 +080051import static com.google.common.truth.Truth.assertThat;
52
Adrian Roos5251b1d2018-03-23 18:57:43 +010053import static org.hamcrest.Matchers.is;
54import static org.hamcrest.Matchers.not;
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070055import static org.junit.Assert.assertEquals;
56import static org.junit.Assert.assertFalse;
57import static org.junit.Assert.assertNull;
Adrian Roos5251b1d2018-03-23 18:57:43 +010058import static org.junit.Assert.assertThat;
Wale Ogunwalea7e3b642016-08-29 10:15:34 -070059import static org.junit.Assert.assertTrue;
Vishnu Nairddd80742018-08-21 14:12:46 -070060import static org.mockito.ArgumentMatchers.any;
Riddle Hsu839b5f52020-03-31 21:41:18 +080061import static org.mockito.ArgumentMatchers.anyBoolean;
Michael Wrighte3001042019-02-05 00:13:14 +000062import static org.mockito.ArgumentMatchers.anyInt;
chaviw40234662018-02-07 09:37:16 -080063import static org.mockito.ArgumentMatchers.anyLong;
64import static org.mockito.ArgumentMatchers.anyString;
Vishnu Nairddd80742018-08-21 14:12:46 -070065import static org.mockito.ArgumentMatchers.eq;
Vinit Nayak8009e922019-09-05 11:49:53 -070066import static org.mockito.Mockito.when;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070067
Issei Suzuki43190bd2018-08-20 17:28:41 +020068import android.graphics.Insets;
Vishnu Nairddd80742018-08-21 14:12:46 -070069import android.graphics.Matrix;
Tarandeep Singhbcba88c2019-12-06 10:36:55 -080070import android.graphics.PixelFormat;
Adrian Roos49c27ff2018-08-31 13:07:33 -070071import android.graphics.Rect;
Riddle Hsu839b5f52020-03-31 21:41:18 +080072import android.os.RemoteException;
Brett Chabota26eda92018-07-23 13:08:30 -070073import android.platform.test.annotations.Presubmit;
Adrian Roos49c27ff2018-08-31 13:07:33 -070074import android.util.Size;
75import android.view.DisplayCutout;
Jorim Jaggicfd6f3b2018-11-07 15:30:18 +010076import android.view.InsetsSource;
Brett Chabota26eda92018-07-23 13:08:30 -070077import android.view.SurfaceControl;
Yunfan Chen5e696f12019-02-07 22:02:08 +090078import android.view.ViewRootImpl;
Brett Chabota26eda92018-07-23 13:08:30 -070079import android.view.WindowManager;
80
Yunfan Chendb39c162019-02-08 16:14:14 +090081import androidx.test.filters.FlakyTest;
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070082import androidx.test.filters.SmallTest;
83
Adrian Roos49c27ff2018-08-31 13:07:33 -070084import com.android.server.wm.utils.WmDisplayCutout;
85
Yunfan Chen5e696f12019-02-07 22:02:08 +090086import org.junit.AfterClass;
Yunfan Chendb39c162019-02-08 16:14:14 +090087import org.junit.Before;
Yunfan Chen5e696f12019-02-07 22:02:08 +090088import org.junit.BeforeClass;
Brett Chabota26eda92018-07-23 13:08:30 -070089import org.junit.Test;
Riddle Hsu2da2d032019-08-28 21:08:58 +080090import org.junit.runner.RunWith;
Brett Chabota26eda92018-07-23 13:08:30 -070091
Riddle Hsu5df3b752019-12-16 13:27:37 -060092import java.util.Arrays;
Brett Chabota26eda92018-07-23 13:08:30 -070093import java.util.LinkedList;
Riddle Hsu5df3b752019-12-16 13:27:37 -060094import java.util.List;
Brett Chabota26eda92018-07-23 13:08:30 -070095
Wale Ogunwaleb699ce02016-07-18 12:05:30 -070096/**
97 * Tests for the {@link WindowState} class.
98 *
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -070099 * Build/Install/Run:
Andrii Kulianf5d14112019-10-31 17:37:54 -0700100 * atest WmTests:WindowStateTests
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700101 */
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700102@SmallTest
103@Presubmit
Riddle Hsu2da2d032019-08-28 21:08:58 +0800104@RunWith(WindowTestRunner.class)
Wale Ogunwale44fbdf52016-11-16 10:18:45 -0800105public class WindowStateTests extends WindowTestsBase {
Yunfan Chen5e696f12019-02-07 22:02:08 +0900106 private static int sPreviousNewInsetsMode;
107
108 @BeforeClass
109 public static void setUpOnce() {
Yunfan Chendb39c162019-02-08 16:14:14 +0900110 // TODO: Make use of SettingsSession when it becomes feasible for this.
Yunfan Chen5e696f12019-02-07 22:02:08 +0900111 sPreviousNewInsetsMode = ViewRootImpl.sNewInsetsMode;
112 // To let the insets provider control the insets visibility, the insets mode has to be
113 // NEW_INSETS_MODE_FULL.
114 ViewRootImpl.sNewInsetsMode = NEW_INSETS_MODE_FULL;
115 }
116
117 @AfterClass
118 public static void tearDownOnce() {
119 ViewRootImpl.sNewInsetsMode = sPreviousNewInsetsMode;
120 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700121
Yunfan Chendb39c162019-02-08 16:14:14 +0900122 @Before
123 public void setUp() {
124 // TODO: Let the insets source with new mode keep the visibility control, and remove this
125 // setup code. Now mTopFullscreenOpaqueWindowState will take back the control of insets
126 // visibility.
Riddle Hsu2da2d032019-08-28 21:08:58 +0800127 spyOn(mDisplayContent);
128 doNothing().when(mDisplayContent).layoutAndAssignWindowLayersIfNeeded();
Yunfan Chendb39c162019-02-08 16:14:14 +0900129 }
130
Wale Ogunwalea7e3b642016-08-29 10:15:34 -0700131 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700132 public void testIsParentWindowHidden() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800133 final WindowState parentWindow = createWindow(null, TYPE_APPLICATION, "parentWindow");
134 final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child1");
135 final WindowState child2 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child2");
Wale Ogunwale9d147902016-07-16 11:58:55 -0700136
chaviwebcbc342018-02-07 13:19:00 -0800137 // parentWindow is initially set to hidden.
138 assertTrue(parentWindow.mHidden);
139 assertFalse(parentWindow.isParentWindowHidden());
140 assertTrue(child1.isParentWindowHidden());
141 assertTrue(child2.isParentWindowHidden());
142
143 parentWindow.mHidden = false;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700144 assertFalse(parentWindow.isParentWindowHidden());
145 assertFalse(child1.isParentWindowHidden());
146 assertFalse(child2.isParentWindowHidden());
Wale Ogunwale9d147902016-07-16 11:58:55 -0700147 }
148
Wale Ogunwalea7e3b642016-08-29 10:15:34 -0700149 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700150 public void testIsChildWindow() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800151 final WindowState parentWindow = createWindow(null, TYPE_APPLICATION, "parentWindow");
152 final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child1");
153 final WindowState child2 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child2");
154 final WindowState randomWindow = createWindow(null, TYPE_APPLICATION, "randomWindow");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700155
156 assertFalse(parentWindow.isChildWindow());
157 assertTrue(child1.isChildWindow());
158 assertTrue(child2.isChildWindow());
159 assertFalse(randomWindow.isChildWindow());
160 }
161
Wale Ogunwalea7e3b642016-08-29 10:15:34 -0700162 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700163 public void testHasChild() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800164 final WindowState win1 = createWindow(null, TYPE_APPLICATION, "win1");
165 final WindowState win11 = createWindow(win1, FIRST_SUB_WINDOW, "win11");
166 final WindowState win12 = createWindow(win1, FIRST_SUB_WINDOW, "win12");
167 final WindowState win2 = createWindow(null, TYPE_APPLICATION, "win2");
168 final WindowState win21 = createWindow(win2, FIRST_SUB_WINDOW, "win21");
169 final WindowState randomWindow = createWindow(null, TYPE_APPLICATION, "randomWindow");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700170
171 assertTrue(win1.hasChild(win11));
172 assertTrue(win1.hasChild(win12));
173 assertTrue(win2.hasChild(win21));
174
175 assertFalse(win1.hasChild(win21));
176 assertFalse(win1.hasChild(randomWindow));
177
178 assertFalse(win2.hasChild(win11));
179 assertFalse(win2.hasChild(win12));
180 assertFalse(win2.hasChild(randomWindow));
181 }
182
Wale Ogunwalea7e3b642016-08-29 10:15:34 -0700183 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700184 public void testGetParentWindow() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800185 final WindowState parentWindow = createWindow(null, TYPE_APPLICATION, "parentWindow");
186 final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child1");
187 final WindowState child2 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child2");
Wale Ogunwalecaa53af2016-07-17 14:50:26 -0700188
189 assertNull(parentWindow.getParentWindow());
190 assertEquals(parentWindow, child1.getParentWindow());
191 assertEquals(parentWindow, child2.getParentWindow());
192 }
193
Wale Ogunwalea7e3b642016-08-29 10:15:34 -0700194 @Test
Suprabh Shukla69c71422018-04-02 18:39:01 -0700195 public void testOverlayWindowHiddenWhenSuspended() {
196 final WindowState overlayWindow = spy(createWindow(null, TYPE_APPLICATION_OVERLAY,
197 "overlayWindow"));
198 overlayWindow.setHiddenWhileSuspended(true);
199 verify(overlayWindow).hideLw(true, true);
200 overlayWindow.setHiddenWhileSuspended(false);
201 verify(overlayWindow).showLw(true, true);
202 }
203
204 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700205 public void testGetTopParentWindow() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800206 final WindowState root = createWindow(null, TYPE_APPLICATION, "root");
207 final WindowState child1 = createWindow(root, FIRST_SUB_WINDOW, "child1");
208 final WindowState child2 = createWindow(child1, FIRST_SUB_WINDOW, "child2");
Wale Ogunwalecaa53af2016-07-17 14:50:26 -0700209
210 assertEquals(root, root.getTopParentWindow());
211 assertEquals(root, child1.getTopParentWindow());
212 assertEquals(child1, child2.getParentWindow());
213 assertEquals(root, child2.getTopParentWindow());
Wale Ogunwaleea92d972016-12-08 07:33:13 -0800214
215 // Test case were child is detached from parent.
216 root.removeChild(child1);
217 assertEquals(child1, child1.getTopParentWindow());
218 assertEquals(child1, child2.getParentWindow());
Wale Ogunwalecaa53af2016-07-17 14:50:26 -0700219 }
220
Jorim Jaggiaf221d12016-11-15 14:59:57 -0800221 @Test
222 public void testIsOnScreen_hiddenByPolicy() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800223 final WindowState window = createWindow(null, TYPE_APPLICATION, "window");
Jorim Jaggiaf221d12016-11-15 14:59:57 -0800224 window.setHasSurface(true);
225 assertTrue(window.isOnScreen());
226 window.hideLw(false /* doAnimation */);
227 assertFalse(window.isOnScreen());
228 }
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800229
230 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700231 public void testCanBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800232 final WindowState appWindow = createWindow(null, TYPE_APPLICATION, "appWindow");
233 final WindowState imeWindow = createWindow(null, TYPE_INPUT_METHOD, "imeWindow");
234
Tarandeep Singhbcba88c2019-12-06 10:36:55 -0800235 // Setting FLAG_NOT_FOCUSABLE prevents the window from being an IME target.
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800236 appWindow.mAttrs.flags |= FLAG_NOT_FOCUSABLE;
237 imeWindow.mAttrs.flags |= FLAG_NOT_FOCUSABLE;
238
239 // Make windows visible
240 appWindow.setHasSurface(true);
241 imeWindow.setHasSurface(true);
242
Tarandeep Singhbcba88c2019-12-06 10:36:55 -0800243 // Windows with FLAG_NOT_FOCUSABLE can't be IME targets
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800244 assertFalse(appWindow.canBeImeTarget());
245 assertFalse(imeWindow.canBeImeTarget());
246
247 // Add IME target flags
248 appWindow.mAttrs.flags |= (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
249 imeWindow.mAttrs.flags |= (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
250
Tarandeep Singhbcba88c2019-12-06 10:36:55 -0800251 // Visible app window with flags FLAG_NOT_FOCUSABLE or FLAG_ALT_FOCUSABLE_IM can't be IME
252 // target while an IME window can never be an IME target regardless of its visibility
253 // or flags.
254 assertFalse(appWindow.canBeImeTarget());
Andrew Chant17c896e2019-12-05 22:39:02 +0000255 assertFalse(imeWindow.canBeImeTarget());
Tarandeep Singh0ffa15a2019-11-04 13:40:15 -0800256
Tarandeep Singhbcba88c2019-12-06 10:36:55 -0800257 // b/145812508: special legacy use-case for transparent/translucent windows.
258 appWindow.mAttrs.format = PixelFormat.TRANSPARENT;
259 assertTrue(appWindow.canBeImeTarget());
260
261 appWindow.mAttrs.format = PixelFormat.OPAQUE;
262 appWindow.mAttrs.flags &= ~FLAG_ALT_FOCUSABLE_IM;
263 assertFalse(appWindow.canBeImeTarget());
264 appWindow.mAttrs.flags &= ~FLAG_NOT_FOCUSABLE;
265 assertTrue(appWindow.canBeImeTarget());
266
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800267 // Make windows invisible
268 appWindow.hideLw(false /* doAnimation */);
269 imeWindow.hideLw(false /* doAnimation */);
270
271 // Invisible window can't be IME targets even if they have the right flags.
272 assertFalse(appWindow.canBeImeTarget());
273 assertFalse(imeWindow.canBeImeTarget());
lumarkf948afe2019-05-23 21:22:36 +0800274
275 // Simulate the window is in split screen primary stack and the current state is
276 // minimized and home stack is resizable, so that we should ignore input for the stack.
277 final DockedStackDividerController controller =
278 mDisplayContent.getDockedDividerController();
Louis Changdc077272019-11-12 16:52:56 +0800279 final ActivityStack stack = createTaskStackOnDisplay(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY,
lumarkf948afe2019-05-23 21:22:36 +0800280 ACTIVITY_TYPE_STANDARD, mDisplayContent);
281 spyOn(appWindow);
282 spyOn(controller);
283 spyOn(stack);
Evan Rosky73a7fe92019-11-18 18:28:01 -0800284 stack.setFocusable(false);
Wale Ogunwale1ebcd8e2020-01-21 11:27:03 -0800285 doReturn(stack).when(appWindow).getRootTask();
lumarkf948afe2019-05-23 21:22:36 +0800286
287 // Make sure canBeImeTarget is false due to shouldIgnoreInput is true;
288 assertFalse(appWindow.canBeImeTarget());
289 assertTrue(stack.shouldIgnoreInput());
Wale Ogunwale805d9ec2016-12-07 12:22:08 -0800290 }
Wale Ogunwale34247952017-02-19 11:57:53 -0800291
292 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700293 public void testGetWindow() {
Wale Ogunwale34247952017-02-19 11:57:53 -0800294 final WindowState root = createWindow(null, TYPE_APPLICATION, "root");
295 final WindowState mediaChild = createWindow(root, TYPE_APPLICATION_MEDIA, "mediaChild");
296 final WindowState mediaOverlayChild = createWindow(root,
297 TYPE_APPLICATION_MEDIA_OVERLAY, "mediaOverlayChild");
298 final WindowState attachedDialogChild = createWindow(root,
299 TYPE_APPLICATION_ATTACHED_DIALOG, "attachedDialogChild");
300 final WindowState subPanelChild = createWindow(root,
301 TYPE_APPLICATION_SUB_PANEL, "subPanelChild");
302 final WindowState aboveSubPanelChild = createWindow(root,
303 TYPE_APPLICATION_ABOVE_SUB_PANEL, "aboveSubPanelChild");
304
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700305 final LinkedList<WindowState> windows = new LinkedList<>();
Wale Ogunwale34247952017-02-19 11:57:53 -0800306
307 root.getWindow(w -> {
308 windows.addLast(w);
309 return false;
310 });
311
312 // getWindow should have returned candidate windows in z-order.
313 assertEquals(aboveSubPanelChild, windows.pollFirst());
314 assertEquals(subPanelChild, windows.pollFirst());
315 assertEquals(attachedDialogChild, windows.pollFirst());
316 assertEquals(root, windows.pollFirst());
317 assertEquals(mediaOverlayChild, windows.pollFirst());
318 assertEquals(mediaChild, windows.pollFirst());
319 assertTrue(windows.isEmpty());
320 }
Bryce Leeae73ba42017-05-05 09:58:25 -0700321
322 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700323 public void testPrepareWindowToDisplayDuringRelayout() {
Riddle Hsu4bb06be2019-07-02 01:03:07 +0800324 // Call prepareWindowToDisplayDuringRelayout for a window without FLAG_TURN_SCREEN_ON before
Garfield Tane8d84ab2019-10-11 09:49:40 -0700325 // calling setCurrentLaunchCanTurnScreenOn for windows with flag in the same activity.
326 final ActivityRecord activity = createActivityRecord(mDisplayContent,
chaviwb28de1f2018-03-02 10:42:36 -0800327 WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
Garfield Tane8d84ab2019-10-11 09:49:40 -0700328 final WindowState first = createWindow(null, TYPE_APPLICATION, activity, "first");
329 final WindowState second = createWindow(null, TYPE_APPLICATION, activity, "second");
chaviwb28de1f2018-03-02 10:42:36 -0800330
Riddle Hsu4bb06be2019-07-02 01:03:07 +0800331 testPrepareWindowToDisplayDuringRelayout(first, false /* expectedWakeupCalled */,
332 true /* expectedCurrentLaunchCanTurnScreenOn */);
Andrii Kulian46799182019-10-17 16:26:17 -0700333 testPrepareWindowToDisplayDuringRelayout(second, false /* expectedWakeupCalled */,
334 true /* expectedCurrentLaunchCanTurnScreenOn */);
335
336 // Call prepareWindowToDisplayDuringRelayout for two windows from the same activity, one of
337 // which has FLAG_TURN_SCREEN_ON. The first processed one should trigger the wakeup.
338 second.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
339 testPrepareWindowToDisplayDuringRelayout(first, true /* expectedWakeupCalled */,
340 false /* expectedCurrentLaunchCanTurnScreenOn */);
341 testPrepareWindowToDisplayDuringRelayout(second, false /* expectedWakeupCalled */,
Riddle Hsu4bb06be2019-07-02 01:03:07 +0800342 false /* expectedCurrentLaunchCanTurnScreenOn */);
chaviwb28de1f2018-03-02 10:42:36 -0800343
344 // Call prepareWindowToDisplayDuringRelayout for two window that have FLAG_TURN_SCREEN_ON
Garfield Tane8d84ab2019-10-11 09:49:40 -0700345 // from the same activity. Only one should trigger the wakeup.
346 activity.setCurrentLaunchCanTurnScreenOn(true);
chaviwb28de1f2018-03-02 10:42:36 -0800347 first.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
348 second.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
349
Riddle Hsu4bb06be2019-07-02 01:03:07 +0800350 testPrepareWindowToDisplayDuringRelayout(first, true /* expectedWakeupCalled */,
351 false /* expectedCurrentLaunchCanTurnScreenOn */);
352 testPrepareWindowToDisplayDuringRelayout(second, false /* expectedWakeupCalled */,
353 false /* expectedCurrentLaunchCanTurnScreenOn */);
chaviwb28de1f2018-03-02 10:42:36 -0800354
Riddle Hsu4bb06be2019-07-02 01:03:07 +0800355 // Without window flags, the state of ActivityRecord.canTurnScreenOn should still be able to
356 // turn on the screen.
Garfield Tane8d84ab2019-10-11 09:49:40 -0700357 activity.setCurrentLaunchCanTurnScreenOn(true);
Riddle Hsu4bb06be2019-07-02 01:03:07 +0800358 first.mAttrs.flags &= ~WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Garfield Tane8d84ab2019-10-11 09:49:40 -0700359 doReturn(true).when(activity).canTurnScreenOn();
Riddle Hsu4bb06be2019-07-02 01:03:07 +0800360
361 testPrepareWindowToDisplayDuringRelayout(first, true /* expectedWakeupCalled */,
362 false /* expectedCurrentLaunchCanTurnScreenOn */);
chaviwb28de1f2018-03-02 10:42:36 -0800363
364 // Call prepareWindowToDisplayDuringRelayout for a windows that are not children of an
Garfield Tane8d84ab2019-10-11 09:49:40 -0700365 // activity. Both windows have the FLAG_TURNS_SCREEN_ON so both should call wakeup
chaviw97d28202018-02-27 16:23:53 -0800366 final WindowToken windowToken = WindowTestUtils.createTestWindowToken(FIRST_SUB_WINDOW,
chaviwb28de1f2018-03-02 10:42:36 -0800367 mDisplayContent);
368 final WindowState firstWindow = createWindow(null, TYPE_APPLICATION, windowToken,
369 "firstWindow");
370 final WindowState secondWindow = createWindow(null, TYPE_APPLICATION, windowToken,
371 "secondWindow");
372 firstWindow.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
373 secondWindow.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
374
Garfield Tane3d37b52019-07-23 12:43:05 -0700375 final WindowState.PowerManagerWrapper powerManagerWrapper =
376 mSystemServicesTestRule.getPowerManagerWrapper();
377 reset(powerManagerWrapper);
chaviwb28de1f2018-03-02 10:42:36 -0800378 firstWindow.prepareWindowToDisplayDuringRelayout(false /*wasVisible*/);
Garfield Tane3d37b52019-07-23 12:43:05 -0700379 verify(powerManagerWrapper).wakeUp(anyLong(), anyInt(), anyString());
chaviwb28de1f2018-03-02 10:42:36 -0800380
Garfield Tane3d37b52019-07-23 12:43:05 -0700381 reset(powerManagerWrapper);
chaviwb28de1f2018-03-02 10:42:36 -0800382 secondWindow.prepareWindowToDisplayDuringRelayout(false /*wasVisible*/);
Garfield Tane3d37b52019-07-23 12:43:05 -0700383 verify(powerManagerWrapper).wakeUp(anyLong(), anyInt(), anyString());
Bryce Leeae73ba42017-05-05 09:58:25 -0700384 }
385
Riddle Hsu4bb06be2019-07-02 01:03:07 +0800386 private void testPrepareWindowToDisplayDuringRelayout(WindowState appWindow,
387 boolean expectedWakeupCalled, boolean expectedCurrentLaunchCanTurnScreenOn) {
Garfield Tane3d37b52019-07-23 12:43:05 -0700388 final WindowState.PowerManagerWrapper powerManagerWrapper =
389 mSystemServicesTestRule.getPowerManagerWrapper();
390 reset(powerManagerWrapper);
Riddle Hsu4bb06be2019-07-02 01:03:07 +0800391 appWindow.prepareWindowToDisplayDuringRelayout(false /* wasVisible */);
392
393 if (expectedWakeupCalled) {
Garfield Tane3d37b52019-07-23 12:43:05 -0700394 verify(powerManagerWrapper).wakeUp(anyLong(), anyInt(), anyString());
Riddle Hsu4bb06be2019-07-02 01:03:07 +0800395 } else {
Garfield Tane3d37b52019-07-23 12:43:05 -0700396 verify(powerManagerWrapper, never()).wakeUp(anyLong(), anyInt(), anyString());
Riddle Hsu4bb06be2019-07-02 01:03:07 +0800397 }
398 // If wakeup is expected to be called, the currentLaunchCanTurnScreenOn should be false
399 // because the state will be consumed.
Garfield Tane8d84ab2019-10-11 09:49:40 -0700400 assertThat(appWindow.mActivityRecord.currentLaunchCanTurnScreenOn(),
Riddle Hsu4bb06be2019-07-02 01:03:07 +0800401 is(expectedCurrentLaunchCanTurnScreenOn));
402 }
403
Jorim Jaggi72207752018-01-08 13:16:59 +0100404 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700405 public void testCanAffectSystemUiFlags() {
Jorim Jaggi72207752018-01-08 13:16:59 +0100406 final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
Issei Suzukif2f6c912019-11-08 11:24:18 +0100407 app.mActivityRecord.setVisible(true);
Jorim Jaggi72207752018-01-08 13:16:59 +0100408 assertTrue(app.canAffectSystemUiFlags());
Issei Suzukif2f6c912019-11-08 11:24:18 +0100409 app.mActivityRecord.setVisible(false);
Jorim Jaggi72207752018-01-08 13:16:59 +0100410 assertFalse(app.canAffectSystemUiFlags());
Issei Suzukif2f6c912019-11-08 11:24:18 +0100411 app.mActivityRecord.setVisible(true);
Jorim Jaggi72207752018-01-08 13:16:59 +0100412 app.mAttrs.alpha = 0.0f;
413 assertFalse(app.canAffectSystemUiFlags());
Jorim Jaggi50bf59c2018-03-09 17:29:48 +0100414 }
415
416 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700417 public void testCanAffectSystemUiFlags_disallow() {
Jorim Jaggi50bf59c2018-03-09 17:29:48 +0100418 final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
Issei Suzukif2f6c912019-11-08 11:24:18 +0100419 app.mActivityRecord.setVisible(true);
Jorim Jaggi50bf59c2018-03-09 17:29:48 +0100420 assertTrue(app.canAffectSystemUiFlags());
421 app.getTask().setCanAffectSystemUiFlags(false);
422 assertFalse(app.canAffectSystemUiFlags());
Jorim Jaggi72207752018-01-08 13:16:59 +0100423 }
424
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100425 @Test
Jorim Jaggi956ca412019-01-07 14:49:14 +0100426 public void testVisibleWithInsetsProvider() {
Tiger Huang332793b2019-10-29 23:21:27 +0800427 final WindowState statusBar = createWindow(null, TYPE_STATUS_BAR, "statusBar");
Jorim Jaggicfd6f3b2018-11-07 15:30:18 +0100428 final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
Tiger Huang332793b2019-10-29 23:21:27 +0800429 statusBar.mHasSurface = true;
430 assertTrue(statusBar.isVisible());
431 mDisplayContent.getInsetsStateController().getSourceProvider(ITYPE_STATUS_BAR)
Jorim Jaggi9b4f4202020-01-28 17:05:06 +0100432 .setWindow(statusBar, null /* frameProvider */, null /* imeFrameProvider */);
Jorim Jaggi956ca412019-01-07 14:49:14 +0100433 mDisplayContent.getInsetsStateController().onBarControlTargetChanged(
434 app, null /* fakeTopControlling */, app, null /* fakeNavControlling */);
Jorim Jaggi0dd0cf92019-12-27 15:17:44 +0100435 final InsetsSource source = new InsetsSource(ITYPE_STATUS_BAR);
436 source.setVisible(false);
Tiger Huang332793b2019-10-29 23:21:27 +0800437 mDisplayContent.getInsetsStateController().getSourceProvider(ITYPE_STATUS_BAR)
Jorim Jaggi0dd0cf92019-12-27 15:17:44 +0100438 .onInsetsModified(app, source);
Yunfan Chendb39c162019-02-08 16:14:14 +0900439 waitUntilHandlersIdle();
Tiger Huang332793b2019-10-29 23:21:27 +0800440 assertFalse(statusBar.isVisible());
Jorim Jaggicfd6f3b2018-11-07 15:30:18 +0100441 }
442
443 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700444 public void testIsSelfOrAncestorWindowAnimating() {
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100445 final WindowState root = createWindow(null, TYPE_APPLICATION, "root");
446 final WindowState child1 = createWindow(root, FIRST_SUB_WINDOW, "child1");
447 final WindowState child2 = createWindow(child1, FIRST_SUB_WINDOW, "child2");
448 assertFalse(child2.isSelfOrAncestorWindowAnimatingExit());
449 child2.mAnimatingExit = true;
450 assertTrue(child2.isSelfOrAncestorWindowAnimatingExit());
451 child2.mAnimatingExit = false;
452 root.mAnimatingExit = true;
453 assertTrue(child2.isSelfOrAncestorWindowAnimatingExit());
454 }
455
Adrian Roos5251b1d2018-03-23 18:57:43 +0100456 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700457 public void testLayoutSeqResetOnReparent() {
Adrian Roos5251b1d2018-03-23 18:57:43 +0100458 final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
459 app.mLayoutSeq = 1;
460 mDisplayContent.mLayoutSeq = 1;
461
Garfield Tane223e682019-04-15 09:59:25 -0700462 DisplayContent newDisplay = createNewDisplay();
463
464 app.onDisplayChanged(newDisplay);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100465
466 assertThat(app.mLayoutSeq, not(is(mDisplayContent.mLayoutSeq)));
467 }
468
Brad Stenningaf596412018-04-02 12:03:19 -0700469 @Test
Tadashi G. Takaokab6e148c2018-11-03 02:59:06 -0700470 public void testDisplayIdUpdatedOnReparent() {
Brad Stenningaf596412018-04-02 12:03:19 -0700471 final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
472 // fake a different display
473 app.mInputWindowHandle.displayId = mDisplayContent.getDisplayId() + 1;
474 app.onDisplayChanged(mDisplayContent);
475
476 assertThat(app.mInputWindowHandle.displayId, is(mDisplayContent.getDisplayId()));
477 assertThat(app.getDisplayId(), is(mDisplayContent.getDisplayId()));
478 }
479
Adrian Roos0e7b70a2018-06-07 15:29:34 +0200480 @Test
481 public void testSeamlesslyRotateWindow() {
482 final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
chaviw619da692019-06-10 15:39:40 -0700483 final SurfaceControl.Transaction t = spy(StubTransaction.class);
Adrian Roos0e7b70a2018-06-07 15:29:34 +0200484
485 app.mHasSurface = true;
Vishnu Naird8c664b2018-09-24 12:52:35 -0700486 app.mSurfaceControl = mock(SurfaceControl.class);
Adrian Roos0e7b70a2018-06-07 15:29:34 +0200487 try {
chaviw492139a2018-07-16 16:07:35 -0700488 app.getFrameLw().set(10, 20, 60, 80);
Vishnu Naird8c664b2018-09-24 12:52:35 -0700489 app.updateSurfacePosition(t);
Adrian Roos0e7b70a2018-06-07 15:29:34 +0200490
Vishnu Nairddd80742018-08-21 14:12:46 -0700491 app.seamlesslyRotateIfAllowed(t, ROTATION_0, ROTATION_90, true);
Adrian Roos0e7b70a2018-06-07 15:29:34 +0200492
493 assertTrue(app.mSeamlesslyRotated);
Vishnu Naird8c664b2018-09-24 12:52:35 -0700494
495 // Verify we un-rotate the window state surface.
Vishnu Nairddd80742018-08-21 14:12:46 -0700496 Matrix matrix = new Matrix();
497 // Un-rotate 90 deg
498 matrix.setRotate(270);
499 // Translate it back to origin
500 matrix.postTranslate(0, mDisplayInfo.logicalWidth);
Vishnu Naird8c664b2018-09-24 12:52:35 -0700501 verify(t).setMatrix(eq(app.mSurfaceControl), eq(matrix), any(float[].class));
502
503 // Verify we update the position as well.
504 float[] currentSurfacePos = {app.mLastSurfacePosition.x, app.mLastSurfacePosition.y};
505 matrix.mapPoints(currentSurfacePos);
506 verify(t).setPosition(eq(app.mSurfaceControl), eq(currentSurfacePos[0]),
507 eq(currentSurfacePos[1]));
Adrian Roos0e7b70a2018-06-07 15:29:34 +0200508 } finally {
Vishnu Naird8c664b2018-09-24 12:52:35 -0700509 app.mSurfaceControl = null;
Adrian Roos0e7b70a2018-06-07 15:29:34 +0200510 app.mHasSurface = false;
511 }
512 }
513
Adrian Roos49c27ff2018-08-31 13:07:33 -0700514 @Test
515 public void testDisplayCutoutIsCalculatedRelativeToFrame() {
516 final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
chaviw1454b392018-08-06 09:54:04 -0700517 WindowFrames wf = app.getWindowFrames();
Adrian Roos49c27ff2018-08-31 13:07:33 -0700518 wf.mParentFrame.set(7, 10, 185, 380);
519 wf.mDisplayFrame.set(wf.mParentFrame);
Issei Suzuki43190bd2018-08-20 17:28:41 +0200520 final DisplayCutout cutout = new DisplayCutout(
521 Insets.of(0, 15, 0, 22) /* safeInset */,
522 null /* boundLeft */,
523 new Rect(95, 0, 105, 15),
524 null /* boundRight */,
525 new Rect(95, 378, 105, 400));
Adrian Roos49c27ff2018-08-31 13:07:33 -0700526 wf.setDisplayCutout(new WmDisplayCutout(cutout, new Size(200, 400)));
527
chaviw1454b392018-08-06 09:54:04 -0700528 app.computeFrameLw();
Adrian Roos49c27ff2018-08-31 13:07:33 -0700529 assertThat(app.getWmDisplayCutout().getDisplayCutout(), is(cutout.inset(7, 10, 5, 20)));
530 }
531
chaviw15ad49f2019-04-24 15:05:39 -0700532 @Test
533 public void testVisibilityChangeSwitchUser() {
534 final WindowState window = createWindow(null, TYPE_APPLICATION, "app");
535 window.mHasSurface = true;
Wale Ogunwale9bb1a1e2019-12-30 11:29:52 -0800536 spyOn(window);
537 doReturn(false).when(window).showForAllUsers();
chaviw15ad49f2019-04-24 15:05:39 -0700538
539 mWm.mCurrentUserId = 1;
Wale Ogunwalebebd8cd2019-10-28 15:53:31 -0700540 window.switchUser(mWm.mCurrentUserId);
chaviw15ad49f2019-04-24 15:05:39 -0700541 assertFalse(window.isVisible());
542 assertFalse(window.isVisibleByPolicy());
543
544 mWm.mCurrentUserId = 0;
Wale Ogunwalebebd8cd2019-10-28 15:53:31 -0700545 window.switchUser(mWm.mCurrentUserId);
chaviw15ad49f2019-04-24 15:05:39 -0700546 assertTrue(window.isVisible());
547 assertTrue(window.isVisibleByPolicy());
548 }
Tiger Huangd8ec9382019-04-18 14:35:09 -0700549
550 @Test
Riddle Hsu5df3b752019-12-16 13:27:37 -0600551 public void testRequestDrawIfNeeded() {
552 final WindowState startingApp = createWindow(null /* parent */,
553 TYPE_BASE_APPLICATION, "startingApp");
554 final WindowState startingWindow = createWindow(null /* parent */,
555 TYPE_APPLICATION_STARTING, startingApp.mToken, "starting");
556 startingApp.mActivityRecord.startingWindow = startingWindow;
wilsonshihe8321942019-10-18 18:39:46 +0800557 final WindowState keyguardHostWindow = mNotificationShadeWindow;
Riddle Hsu5df3b752019-12-16 13:27:37 -0600558 final WindowState allDrawnApp = mAppWindow;
559 allDrawnApp.mActivityRecord.allDrawn = true;
560
561 // The waiting list is used to ensure the content is ready when turning on screen.
562 final List<WindowState> outWaitingForDrawn = mDisplayContent.mWaitingForDrawn;
563 final List<WindowState> visibleWindows = Arrays.asList(mChildAppWindowAbove,
564 keyguardHostWindow, allDrawnApp, startingApp, startingWindow);
565 visibleWindows.forEach(w -> {
566 w.mHasSurface = true;
567 w.requestDrawIfNeeded(outWaitingForDrawn);
568 });
569
570 // Keyguard host window should be always contained. The drawn app or app with starting
571 // window are unnecessary to draw.
572 assertEquals(Arrays.asList(keyguardHostWindow, startingWindow), outWaitingForDrawn);
573 }
574
575 @Test
Riddle Hsu839b5f52020-03-31 21:41:18 +0800576 public void testReportResizedWithRemoteException() {
577 final WindowState win = mChildAppWindowAbove;
578 makeWindowVisible(win, win.getParentWindow());
579 win.mLayoutSeq = win.getDisplayContent().mLayoutSeq;
580 win.updateResizingWindowIfNeeded();
581
582 assertThat(mWm.mResizingWindows).contains(win);
583 assertTrue(win.getOrientationChanging());
584
585 mWm.mResizingWindows.remove(win);
586 spyOn(win.mClient);
587 try {
588 doThrow(new RemoteException("test")).when(win.mClient).resized(any() /* frame */,
589 any() /* contentInsets */, any() /* visibleInsets */, any() /* stableInsets */,
590 anyBoolean() /* reportDraw */, any() /* mergedConfig */,
591 any() /* backDropFrame */, anyBoolean() /* forceLayout */,
592 anyBoolean() /* alwaysConsumeSystemBars */, anyInt() /* displayId */,
593 any() /* displayCutout */);
594 } catch (RemoteException ignored) {
595 }
596 win.reportResized();
597 win.updateResizingWindowIfNeeded();
598
599 // Even "resized" throws remote exception, it is still considered as reported. So the window
600 // shouldn't be resized again (which may block unfreeze in real case).
601 assertThat(mWm.mResizingWindows).doesNotContain(win);
602 assertFalse(win.getOrientationChanging());
603 }
604
605 @Test
Tiger Huangd8ec9382019-04-18 14:35:09 -0700606 public void testGetTransformationMatrix() {
Wale Ogunwale8a1860a2019-06-05 08:57:19 -0700607 final int PARENT_WINDOW_OFFSET = 1;
608 final int DISPLAY_IN_PARENT_WINDOW_OFFSET = 2;
609 final int WINDOW_OFFSET = 3;
610 final float OFFSET_SUM =
611 PARENT_WINDOW_OFFSET + DISPLAY_IN_PARENT_WINDOW_OFFSET + WINDOW_OFFSET;
612
Riddle Hsu2da2d032019-08-28 21:08:58 +0800613 final WindowState win0 = createWindow(null, TYPE_APPLICATION, "win0");
Tiger Huangd8ec9382019-04-18 14:35:09 -0700614
Riddle Hsu2da2d032019-08-28 21:08:58 +0800615 final DisplayContent dc = createNewDisplay();
616 win0.getFrameLw().offsetTo(PARENT_WINDOW_OFFSET, 0);
617 dc.reparentDisplayContent(win0, win0.getSurfaceControl());
618 dc.updateLocation(win0, DISPLAY_IN_PARENT_WINDOW_OFFSET, 0);
Tiger Huangd8ec9382019-04-18 14:35:09 -0700619
Riddle Hsu2da2d032019-08-28 21:08:58 +0800620 final float[] values = new float[9];
621 final Matrix matrix = new Matrix();
chaviw619da692019-06-10 15:39:40 -0700622 final SurfaceControl.Transaction t = spy(StubTransaction.class);
Riddle Hsu2da2d032019-08-28 21:08:58 +0800623 final WindowState win1 = createWindow(null, TYPE_APPLICATION, dc, "win1");
624 win1.mHasSurface = true;
625 win1.mSurfaceControl = mock(SurfaceControl.class);
626 win1.getFrameLw().offsetTo(WINDOW_OFFSET, 0);
627 win1.updateSurfacePosition(t);
628 win1.getTransformationMatrix(values, matrix);
Tiger Huangd8ec9382019-04-18 14:35:09 -0700629
Riddle Hsu2da2d032019-08-28 21:08:58 +0800630 matrix.getValues(values);
631 assertEquals(OFFSET_SUM, values[Matrix.MTRANS_X], 0f);
632 assertEquals(0f, values[Matrix.MTRANS_Y], 0f);
Tiger Huangd8ec9382019-04-18 14:35:09 -0700633 }
Vinit Nayak8009e922019-09-05 11:49:53 -0700634
635 @Test
636 public void testCantReceiveTouchDuringRecentsAnimation() {
637 final WindowState win0 = createWindow(null, TYPE_APPLICATION, "win0");
638
639 // Mock active recents animation
640 RecentsAnimationController recentsController = mock(RecentsAnimationController.class);
Winson Chungdc4edb82019-12-16 16:31:04 -0800641 when(recentsController.shouldApplyInputConsumer(win0.mActivityRecord)).thenReturn(true);
Vinit Nayak8009e922019-09-05 11:49:53 -0700642 mWm.setRecentsAnimationController(recentsController);
643 assertTrue(win0.cantReceiveTouchInput());
644 }
645
646 @Test
647 public void testCantReceiveTouchWhenAppTokenHiddenRequested() {
648 final WindowState win0 = createWindow(null, TYPE_APPLICATION, "win0");
Issei Suzuki1669ea42019-11-06 14:20:59 +0100649 win0.mActivityRecord.mVisibleRequested = false;
Vinit Nayak8009e922019-09-05 11:49:53 -0700650 assertTrue(win0.cantReceiveTouchInput());
651 }
652
653 @Test
Evan Rosky73a7fe92019-11-18 18:28:01 -0800654 public void testCantReceiveTouchWhenNotFocusable() {
Vinit Nayak8009e922019-09-05 11:49:53 -0700655 final WindowState win0 = createWindow(null, TYPE_APPLICATION, "win0");
Evan Rosky73a7fe92019-11-18 18:28:01 -0800656 win0.mActivityRecord.getStack().setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
657 win0.mActivityRecord.getStack().setFocusable(false);
Vinit Nayak8009e922019-09-05 11:49:53 -0700658 assertTrue(win0.cantReceiveTouchInput());
659 }
Jorim Jaggib895e202020-04-16 00:39:55 +0200660
661 @Test
662 public void testNeedsRelativeLayeringToIme_notAttached() {
663 WindowState sameTokenWindow = createWindow(null, TYPE_BASE_APPLICATION, mAppWindow.mToken,
664 "SameTokenWindow");
665 mDisplayContent.mInputMethodTarget = mAppWindow;
666 sameTokenWindow.mActivityRecord.getStack().setWindowingMode(
667 WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
668 assertTrue(sameTokenWindow.needsRelativeLayeringToIme());
669 sameTokenWindow.removeImmediately();
670 assertFalse(sameTokenWindow.needsRelativeLayeringToIme());
671 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700672}