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 |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 19 | import android.view.WindowManager; |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 20 | import org.junit.Test; |
| 21 | import org.junit.runner.RunWith; |
| 22 | |
Wale Ogunwale | 5fc7096 | 2016-09-09 22:36:19 -0700 | [diff] [blame] | 23 | import android.platform.test.annotations.Presubmit; |
chaviw | 4f0f348 | 2018-03-01 15:47:56 -0800 | [diff] [blame] | 24 | import android.support.test.filters.FlakyTest; |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 25 | import android.support.test.filters.SmallTest; |
| 26 | import android.support.test.runner.AndroidJUnit4; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 27 | |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 28 | import java.util.LinkedList; |
| 29 | |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 30 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 31 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 32 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 33 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
| 34 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 35 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 36 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL; |
| 37 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 38 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; |
| 39 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; |
Suprabh Shukla | 69c7142 | 2018-04-02 18:39:01 -0700 | [diff] [blame] | 40 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 41 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL; |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 42 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
chaviw | ebcbc34 | 2018-02-07 13:19:00 -0800 | [diff] [blame] | 43 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 44 | import static org.hamcrest.Matchers.is; |
| 45 | import static org.hamcrest.Matchers.not; |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 46 | import static org.junit.Assert.assertEquals; |
| 47 | import static org.junit.Assert.assertFalse; |
| 48 | import static org.junit.Assert.assertNull; |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 49 | import static org.junit.Assert.assertThat; |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 50 | import static org.junit.Assert.assertTrue; |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 51 | import static org.mockito.ArgumentMatchers.anyLong; |
| 52 | import static org.mockito.ArgumentMatchers.anyString; |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 53 | import static org.mockito.Mockito.never; |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 54 | import static org.mockito.Mockito.reset; |
Suprabh Shukla | 69c7142 | 2018-04-02 18:39:01 -0700 | [diff] [blame] | 55 | import static org.mockito.Mockito.spy; |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 56 | import static org.mockito.Mockito.verify; |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * Tests for the {@link WindowState} class. |
| 60 | * |
Jorim Jaggi | 7220775 | 2018-01-08 13:16:59 +0100 | [diff] [blame] | 61 | * atest FrameworksServicesTests:com.android.server.wm.WindowStateTests |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 62 | */ |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 63 | @SmallTest |
chaviw | 36d0a34 | 2018-03-01 17:29:21 -0800 | [diff] [blame] | 64 | @FlakyTest(bugId = 74078662) |
Wale Ogunwale | 5fc7096 | 2016-09-09 22:36:19 -0700 | [diff] [blame] | 65 | @Presubmit |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 66 | @RunWith(AndroidJUnit4.class) |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 67 | public class WindowStateTests extends WindowTestsBase { |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 68 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 69 | @Test |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 70 | public void testIsParentWindowHidden() throws Exception { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 71 | final WindowState parentWindow = createWindow(null, TYPE_APPLICATION, "parentWindow"); |
| 72 | final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child1"); |
| 73 | final WindowState child2 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child2"); |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 74 | |
chaviw | ebcbc34 | 2018-02-07 13:19:00 -0800 | [diff] [blame] | 75 | // parentWindow is initially set to hidden. |
| 76 | assertTrue(parentWindow.mHidden); |
| 77 | assertFalse(parentWindow.isParentWindowHidden()); |
| 78 | assertTrue(child1.isParentWindowHidden()); |
| 79 | assertTrue(child2.isParentWindowHidden()); |
| 80 | |
| 81 | parentWindow.mHidden = false; |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 82 | assertFalse(parentWindow.isParentWindowHidden()); |
| 83 | assertFalse(child1.isParentWindowHidden()); |
| 84 | assertFalse(child2.isParentWindowHidden()); |
| 85 | |
Wale Ogunwale | 9d14790 | 2016-07-16 11:58:55 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 88 | @Test |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 89 | public void testIsChildWindow() throws Exception { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 90 | final WindowState parentWindow = createWindow(null, TYPE_APPLICATION, "parentWindow"); |
| 91 | final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child1"); |
| 92 | final WindowState child2 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child2"); |
| 93 | final WindowState randomWindow = createWindow(null, TYPE_APPLICATION, "randomWindow"); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 94 | |
| 95 | assertFalse(parentWindow.isChildWindow()); |
| 96 | assertTrue(child1.isChildWindow()); |
| 97 | assertTrue(child2.isChildWindow()); |
| 98 | assertFalse(randomWindow.isChildWindow()); |
| 99 | } |
| 100 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 101 | @Test |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 102 | public void testHasChild() throws Exception { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 103 | final WindowState win1 = createWindow(null, TYPE_APPLICATION, "win1"); |
| 104 | final WindowState win11 = createWindow(win1, FIRST_SUB_WINDOW, "win11"); |
| 105 | final WindowState win12 = createWindow(win1, FIRST_SUB_WINDOW, "win12"); |
| 106 | final WindowState win2 = createWindow(null, TYPE_APPLICATION, "win2"); |
| 107 | final WindowState win21 = createWindow(win2, FIRST_SUB_WINDOW, "win21"); |
| 108 | final WindowState randomWindow = createWindow(null, TYPE_APPLICATION, "randomWindow"); |
Wale Ogunwale | adde52e | 2016-07-16 13:11:55 -0700 | [diff] [blame] | 109 | |
| 110 | assertTrue(win1.hasChild(win11)); |
| 111 | assertTrue(win1.hasChild(win12)); |
| 112 | assertTrue(win2.hasChild(win21)); |
| 113 | |
| 114 | assertFalse(win1.hasChild(win21)); |
| 115 | assertFalse(win1.hasChild(randomWindow)); |
| 116 | |
| 117 | assertFalse(win2.hasChild(win11)); |
| 118 | assertFalse(win2.hasChild(win12)); |
| 119 | assertFalse(win2.hasChild(randomWindow)); |
| 120 | } |
| 121 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 122 | @Test |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 123 | public void testGetParentWindow() throws Exception { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 124 | final WindowState parentWindow = createWindow(null, TYPE_APPLICATION, "parentWindow"); |
| 125 | final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child1"); |
| 126 | final WindowState child2 = createWindow(parentWindow, FIRST_SUB_WINDOW, "child2"); |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 127 | |
| 128 | assertNull(parentWindow.getParentWindow()); |
| 129 | assertEquals(parentWindow, child1.getParentWindow()); |
| 130 | assertEquals(parentWindow, child2.getParentWindow()); |
| 131 | } |
| 132 | |
Wale Ogunwale | a7e3b64 | 2016-08-29 10:15:34 -0700 | [diff] [blame] | 133 | @Test |
Suprabh Shukla | 69c7142 | 2018-04-02 18:39:01 -0700 | [diff] [blame] | 134 | public void testOverlayWindowHiddenWhenSuspended() { |
| 135 | final WindowState overlayWindow = spy(createWindow(null, TYPE_APPLICATION_OVERLAY, |
| 136 | "overlayWindow")); |
| 137 | overlayWindow.setHiddenWhileSuspended(true); |
| 138 | verify(overlayWindow).hideLw(true, true); |
| 139 | overlayWindow.setHiddenWhileSuspended(false); |
| 140 | verify(overlayWindow).showLw(true, true); |
| 141 | } |
| 142 | |
| 143 | @Test |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 144 | public void testGetTopParentWindow() throws Exception { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 145 | final WindowState root = createWindow(null, TYPE_APPLICATION, "root"); |
| 146 | final WindowState child1 = createWindow(root, FIRST_SUB_WINDOW, "child1"); |
| 147 | final WindowState child2 = createWindow(child1, FIRST_SUB_WINDOW, "child2"); |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 148 | |
| 149 | assertEquals(root, root.getTopParentWindow()); |
| 150 | assertEquals(root, child1.getTopParentWindow()); |
| 151 | assertEquals(child1, child2.getParentWindow()); |
| 152 | assertEquals(root, child2.getTopParentWindow()); |
Wale Ogunwale | ea92d97 | 2016-12-08 07:33:13 -0800 | [diff] [blame] | 153 | |
| 154 | // Test case were child is detached from parent. |
| 155 | root.removeChild(child1); |
| 156 | assertEquals(child1, child1.getTopParentWindow()); |
| 157 | assertEquals(child1, child2.getParentWindow()); |
Wale Ogunwale | caa53af | 2016-07-17 14:50:26 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Jorim Jaggi | af221d1 | 2016-11-15 14:59:57 -0800 | [diff] [blame] | 160 | @Test |
| 161 | public void testIsOnScreen_hiddenByPolicy() { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 162 | final WindowState window = createWindow(null, TYPE_APPLICATION, "window"); |
Jorim Jaggi | af221d1 | 2016-11-15 14:59:57 -0800 | [diff] [blame] | 163 | window.setHasSurface(true); |
| 164 | assertTrue(window.isOnScreen()); |
| 165 | window.hideLw(false /* doAnimation */); |
| 166 | assertFalse(window.isOnScreen()); |
| 167 | } |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 168 | |
| 169 | @Test |
| 170 | public void testCanBeImeTarget() throws Exception { |
| 171 | final WindowState appWindow = createWindow(null, TYPE_APPLICATION, "appWindow"); |
| 172 | final WindowState imeWindow = createWindow(null, TYPE_INPUT_METHOD, "imeWindow"); |
| 173 | |
| 174 | // Setting FLAG_NOT_FOCUSABLE without FLAG_ALT_FOCUSABLE_IM prevents the window from being |
| 175 | // an IME target. |
| 176 | appWindow.mAttrs.flags |= FLAG_NOT_FOCUSABLE; |
| 177 | imeWindow.mAttrs.flags |= FLAG_NOT_FOCUSABLE; |
| 178 | |
| 179 | // Make windows visible |
| 180 | appWindow.setHasSurface(true); |
| 181 | imeWindow.setHasSurface(true); |
| 182 | |
| 183 | // Windows without flags (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM) can't be IME targets |
| 184 | assertFalse(appWindow.canBeImeTarget()); |
| 185 | assertFalse(imeWindow.canBeImeTarget()); |
| 186 | |
| 187 | // Add IME target flags |
| 188 | appWindow.mAttrs.flags |= (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM); |
| 189 | imeWindow.mAttrs.flags |= (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM); |
| 190 | |
| 191 | // Visible app window with flags can be IME target while an IME window can never be an IME |
| 192 | // target regardless of its visibility or flags. |
| 193 | assertTrue(appWindow.canBeImeTarget()); |
| 194 | assertFalse(imeWindow.canBeImeTarget()); |
| 195 | |
| 196 | // Make windows invisible |
| 197 | appWindow.hideLw(false /* doAnimation */); |
| 198 | imeWindow.hideLw(false /* doAnimation */); |
| 199 | |
| 200 | // Invisible window can't be IME targets even if they have the right flags. |
| 201 | assertFalse(appWindow.canBeImeTarget()); |
| 202 | assertFalse(imeWindow.canBeImeTarget()); |
| 203 | } |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 204 | |
| 205 | @Test |
| 206 | public void testGetWindow() throws Exception { |
| 207 | final WindowState root = createWindow(null, TYPE_APPLICATION, "root"); |
| 208 | final WindowState mediaChild = createWindow(root, TYPE_APPLICATION_MEDIA, "mediaChild"); |
| 209 | final WindowState mediaOverlayChild = createWindow(root, |
| 210 | TYPE_APPLICATION_MEDIA_OVERLAY, "mediaOverlayChild"); |
| 211 | final WindowState attachedDialogChild = createWindow(root, |
| 212 | TYPE_APPLICATION_ATTACHED_DIALOG, "attachedDialogChild"); |
| 213 | final WindowState subPanelChild = createWindow(root, |
| 214 | TYPE_APPLICATION_SUB_PANEL, "subPanelChild"); |
| 215 | final WindowState aboveSubPanelChild = createWindow(root, |
| 216 | TYPE_APPLICATION_ABOVE_SUB_PANEL, "aboveSubPanelChild"); |
| 217 | |
| 218 | final LinkedList<WindowState> windows = new LinkedList(); |
| 219 | |
| 220 | root.getWindow(w -> { |
| 221 | windows.addLast(w); |
| 222 | return false; |
| 223 | }); |
| 224 | |
| 225 | // getWindow should have returned candidate windows in z-order. |
| 226 | assertEquals(aboveSubPanelChild, windows.pollFirst()); |
| 227 | assertEquals(subPanelChild, windows.pollFirst()); |
| 228 | assertEquals(attachedDialogChild, windows.pollFirst()); |
| 229 | assertEquals(root, windows.pollFirst()); |
| 230 | assertEquals(mediaOverlayChild, windows.pollFirst()); |
| 231 | assertEquals(mediaChild, windows.pollFirst()); |
| 232 | assertTrue(windows.isEmpty()); |
| 233 | } |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 234 | |
| 235 | @Test |
| 236 | public void testPrepareWindowToDisplayDuringRelayout() throws Exception { |
| 237 | testPrepareWindowToDisplayDuringRelayout(false /*wasVisible*/); |
| 238 | testPrepareWindowToDisplayDuringRelayout(true /*wasVisible*/); |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 239 | |
| 240 | // Call prepareWindowToDisplayDuringRelayout for a window without FLAG_TURN_SCREEN_ON |
| 241 | // before calling prepareWindowToDisplayDuringRelayout for windows with flag in the same |
| 242 | // appWindowToken. |
| 243 | final AppWindowToken appWindowToken = createAppWindowToken(mDisplayContent, |
| 244 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); |
| 245 | final WindowState first = createWindow(null, TYPE_APPLICATION, appWindowToken, "first"); |
| 246 | final WindowState second = createWindow(null, TYPE_APPLICATION, appWindowToken, "second"); |
| 247 | second.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
| 248 | |
| 249 | reset(mPowerManagerWrapper); |
| 250 | first.prepareWindowToDisplayDuringRelayout(false /*wasVisible*/); |
| 251 | verify(mPowerManagerWrapper, never()).wakeUp(anyLong(), anyString()); |
| 252 | assertTrue(appWindowToken.canTurnScreenOn()); |
| 253 | |
| 254 | reset(mPowerManagerWrapper); |
| 255 | second.prepareWindowToDisplayDuringRelayout(false /*wasVisible*/); |
| 256 | verify(mPowerManagerWrapper).wakeUp(anyLong(), anyString()); |
| 257 | assertFalse(appWindowToken.canTurnScreenOn()); |
| 258 | |
| 259 | // Call prepareWindowToDisplayDuringRelayout for two window that have FLAG_TURN_SCREEN_ON |
| 260 | // from the same appWindowToken. Only one should trigger the wakeup. |
| 261 | appWindowToken.setCanTurnScreenOn(true); |
| 262 | first.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
| 263 | second.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
| 264 | |
| 265 | reset(mPowerManagerWrapper); |
| 266 | first.prepareWindowToDisplayDuringRelayout(false /*wasVisible*/); |
| 267 | verify(mPowerManagerWrapper).wakeUp(anyLong(), anyString()); |
| 268 | assertFalse(appWindowToken.canTurnScreenOn()); |
| 269 | |
| 270 | reset(mPowerManagerWrapper); |
| 271 | second.prepareWindowToDisplayDuringRelayout(false /*wasVisible*/); |
| 272 | verify(mPowerManagerWrapper, never()).wakeUp(anyLong(), anyString()); |
| 273 | assertFalse(appWindowToken.canTurnScreenOn()); |
| 274 | |
| 275 | // Call prepareWindowToDisplayDuringRelayout for a windows that are not children of an |
| 276 | // appWindowToken. Both windows have the FLAG_TURNS_SCREEN_ON so both should call wakeup |
chaviw | 97d2820 | 2018-02-27 16:23:53 -0800 | [diff] [blame] | 277 | final WindowToken windowToken = WindowTestUtils.createTestWindowToken(FIRST_SUB_WINDOW, |
chaviw | b28de1f | 2018-03-02 10:42:36 -0800 | [diff] [blame] | 278 | mDisplayContent); |
| 279 | final WindowState firstWindow = createWindow(null, TYPE_APPLICATION, windowToken, |
| 280 | "firstWindow"); |
| 281 | final WindowState secondWindow = createWindow(null, TYPE_APPLICATION, windowToken, |
| 282 | "secondWindow"); |
| 283 | firstWindow.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
| 284 | secondWindow.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
| 285 | |
| 286 | reset(mPowerManagerWrapper); |
| 287 | firstWindow.prepareWindowToDisplayDuringRelayout(false /*wasVisible*/); |
| 288 | verify(mPowerManagerWrapper).wakeUp(anyLong(), anyString()); |
| 289 | |
| 290 | reset(mPowerManagerWrapper); |
| 291 | secondWindow.prepareWindowToDisplayDuringRelayout(false /*wasVisible*/); |
| 292 | verify(mPowerManagerWrapper).wakeUp(anyLong(), anyString()); |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Jorim Jaggi | 7220775 | 2018-01-08 13:16:59 +0100 | [diff] [blame] | 295 | @Test |
| 296 | public void testCanAffectSystemUiFlags() throws Exception { |
| 297 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
| 298 | app.mToken.setHidden(false); |
| 299 | assertTrue(app.canAffectSystemUiFlags()); |
| 300 | app.mToken.setHidden(true); |
| 301 | assertFalse(app.canAffectSystemUiFlags()); |
| 302 | app.mToken.setHidden(false); |
| 303 | app.mAttrs.alpha = 0.0f; |
| 304 | assertFalse(app.canAffectSystemUiFlags()); |
Jorim Jaggi | 50bf59c | 2018-03-09 17:29:48 +0100 | [diff] [blame] | 305 | |
| 306 | } |
| 307 | |
| 308 | @Test |
| 309 | public void testCanAffectSystemUiFlags_disallow() throws Exception { |
| 310 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
| 311 | app.mToken.setHidden(false); |
| 312 | assertTrue(app.canAffectSystemUiFlags()); |
| 313 | app.getTask().setCanAffectSystemUiFlags(false); |
| 314 | assertFalse(app.canAffectSystemUiFlags()); |
Jorim Jaggi | 7220775 | 2018-01-08 13:16:59 +0100 | [diff] [blame] | 315 | } |
| 316 | |
Jorim Jaggi | 4876b4a | 2018-01-11 15:43:49 +0100 | [diff] [blame] | 317 | @Test |
| 318 | public void testIsSelfOrAncestorWindowAnimating() throws Exception { |
| 319 | final WindowState root = createWindow(null, TYPE_APPLICATION, "root"); |
| 320 | final WindowState child1 = createWindow(root, FIRST_SUB_WINDOW, "child1"); |
| 321 | final WindowState child2 = createWindow(child1, FIRST_SUB_WINDOW, "child2"); |
| 322 | assertFalse(child2.isSelfOrAncestorWindowAnimatingExit()); |
| 323 | child2.mAnimatingExit = true; |
| 324 | assertTrue(child2.isSelfOrAncestorWindowAnimatingExit()); |
| 325 | child2.mAnimatingExit = false; |
| 326 | root.mAnimatingExit = true; |
| 327 | assertTrue(child2.isSelfOrAncestorWindowAnimatingExit()); |
| 328 | } |
| 329 | |
Adrian Roos | 5251b1d | 2018-03-23 18:57:43 +0100 | [diff] [blame] | 330 | @Test |
| 331 | public void testLayoutSeqResetOnReparent() throws Exception { |
| 332 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
| 333 | app.mLayoutSeq = 1; |
| 334 | mDisplayContent.mLayoutSeq = 1; |
| 335 | |
| 336 | app.onDisplayChanged(mDisplayContent); |
| 337 | |
| 338 | assertThat(app.mLayoutSeq, not(is(mDisplayContent.mLayoutSeq))); |
| 339 | } |
| 340 | |
Brad Stenning | af59641 | 2018-04-02 12:03:19 -0700 | [diff] [blame] | 341 | @Test |
| 342 | public void testDisplayIdUpdatedOnReparent() throws Exception { |
| 343 | final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); |
| 344 | // fake a different display |
| 345 | app.mInputWindowHandle.displayId = mDisplayContent.getDisplayId() + 1; |
| 346 | app.onDisplayChanged(mDisplayContent); |
| 347 | |
| 348 | assertThat(app.mInputWindowHandle.displayId, is(mDisplayContent.getDisplayId())); |
| 349 | assertThat(app.getDisplayId(), is(mDisplayContent.getDisplayId())); |
| 350 | } |
| 351 | |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 352 | private void testPrepareWindowToDisplayDuringRelayout(boolean wasVisible) { |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 353 | reset(mPowerManagerWrapper); |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 354 | final WindowState root = createWindow(null, TYPE_APPLICATION, "root"); |
| 355 | root.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 356 | |
Bryce Lee | f858b57 | 2017-06-29 14:03:33 -0700 | [diff] [blame] | 357 | root.prepareWindowToDisplayDuringRelayout(wasVisible /*wasVisible*/); |
chaviw | 4023466 | 2018-02-07 09:37:16 -0800 | [diff] [blame] | 358 | verify(mPowerManagerWrapper).wakeUp(anyLong(), anyString()); |
Bryce Lee | ae73ba4 | 2017-05-05 09:58:25 -0700 | [diff] [blame] | 359 | } |
Wale Ogunwale | b699ce0 | 2016-07-18 12:05:30 -0700 | [diff] [blame] | 360 | } |