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