Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [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 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 21 | import static android.view.Display.DEFAULT_DISPLAY; |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 22 | import static android.view.View.VISIBLE; |
| 23 | |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 24 | import android.content.res.Configuration; |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 25 | import android.graphics.Rect; |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 26 | import android.hardware.display.DisplayManagerGlobal; |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 27 | import android.view.Display; |
| 28 | import android.view.DisplayInfo; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 29 | import org.junit.Assert; |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 30 | import org.junit.After; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 31 | import org.junit.Before; |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 32 | import org.mockito.MockitoAnnotations; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 33 | |
| 34 | import android.content.Context; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 35 | import android.support.test.InstrumentationRegistry; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 36 | import android.view.IWindow; |
| 37 | import android.view.WindowManager; |
| 38 | |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 39 | import static android.app.AppOpsManager.OP_NONE; |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 40 | import static android.view.DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 41 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 42 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 43 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 44 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 45 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; |
| 46 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 47 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
| 48 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 49 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
| 50 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; |
| 51 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
| 52 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 53 | import static org.mockito.Mockito.mock; |
| 54 | |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 55 | import com.android.server.AttributeCache; |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 56 | |
| 57 | import java.util.HashSet; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 58 | import java.util.LinkedList; |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 59 | |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 60 | /** |
| 61 | * Common base class for window manager unit test classes. |
| 62 | */ |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 63 | class WindowTestsBase { |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 64 | static WindowManagerService sWm = null; |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 65 | private static final IWindow sIWindow = new TestIWindow(); |
Bryce Lee | a559286 | 2017-10-23 12:57:37 -0700 | [diff] [blame] | 66 | private static Session sMockSession; |
Bryce Lee | 310de9e | 2017-03-15 10:18:21 -0700 | [diff] [blame] | 67 | // The default display is removed in {@link #setUp} and then we iterate over all displays to |
| 68 | // make sure we don't collide with any existing display. If we run into no other display, the |
Bryce Lee | 6272c7f | 2017-03-17 17:22:35 -0700 | [diff] [blame] | 69 | // added display should be treated as default. This cannot be the default display |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 70 | private static int sNextDisplayId = DEFAULT_DISPLAY + 1; |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 71 | static int sNextStackId = 1000; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 72 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 73 | private static boolean sOneTimeSetupDone = false; |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 74 | DisplayContent mDisplayContent; |
| 75 | DisplayInfo mDisplayInfo = new DisplayInfo(); |
| 76 | WindowLayersController mLayersController; |
| 77 | WindowState mWallpaperWindow; |
| 78 | WindowState mImeWindow; |
| 79 | WindowState mImeDialogWindow; |
| 80 | WindowState mStatusBarWindow; |
| 81 | WindowState mDockedDividerWindow; |
| 82 | WindowState mNavBarWindow; |
| 83 | WindowState mAppWindow; |
| 84 | WindowState mChildAppWindowAbove; |
| 85 | WindowState mChildAppWindowBelow; |
| 86 | HashSet<WindowState> mCommonWindows; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 87 | |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 88 | @Before |
| 89 | public void setUp() throws Exception { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 90 | if (!sOneTimeSetupDone) { |
| 91 | sOneTimeSetupDone = true; |
Jorim Jaggi | 771d5b4 | 2017-10-20 15:07:41 +0200 | [diff] [blame] | 92 | |
| 93 | // Allows to mock package local classes and methods |
| 94 | System.setProperty("dexmaker.share_classloader", "true"); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 95 | MockitoAnnotations.initMocks(this); |
Bryce Lee | a559286 | 2017-10-23 12:57:37 -0700 | [diff] [blame] | 96 | sMockSession = mock(Session.class); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 97 | } |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 98 | |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 99 | final Context context = InstrumentationRegistry.getTargetContext(); |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 100 | AttributeCache.init(context); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 101 | sWm = TestWindowManagerPolicy.getWindowManagerService(context); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 102 | mLayersController = new WindowLayersController(sWm); |
Bryce Lee | 6272c7f | 2017-03-17 17:22:35 -0700 | [diff] [blame] | 103 | |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 104 | context.getDisplay().getDisplayInfo(mDisplayInfo); |
| 105 | mDisplayContent = createNewDisplay(); |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 106 | sWm.mDisplayEnabled = true; |
| 107 | sWm.mDisplayReady = true; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 108 | |
| 109 | // Set-up some common windows. |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 110 | mCommonWindows = new HashSet(); |
| 111 | mWallpaperWindow = createCommonWindow(null, TYPE_WALLPAPER, "wallpaperWindow"); |
| 112 | mImeWindow = createCommonWindow(null, TYPE_INPUT_METHOD, "mImeWindow"); |
| 113 | sWm.mInputMethodWindow = mImeWindow; |
| 114 | mImeDialogWindow = createCommonWindow(null, TYPE_INPUT_METHOD_DIALOG, "mImeDialogWindow"); |
| 115 | mStatusBarWindow = createCommonWindow(null, TYPE_STATUS_BAR, "mStatusBarWindow"); |
| 116 | mNavBarWindow = createCommonWindow(null, TYPE_NAVIGATION_BAR, "mNavBarWindow"); |
| 117 | mDockedDividerWindow = createCommonWindow(null, TYPE_DOCK_DIVIDER, "mDockedDividerWindow"); |
| 118 | mAppWindow = createCommonWindow(null, TYPE_BASE_APPLICATION, "mAppWindow"); |
| 119 | mChildAppWindowAbove = createCommonWindow(mAppWindow, TYPE_APPLICATION_ATTACHED_DIALOG, |
| 120 | "mChildAppWindowAbove"); |
| 121 | mChildAppWindowBelow = createCommonWindow(mAppWindow, TYPE_APPLICATION_MEDIA_OVERLAY, |
| 122 | "mChildAppWindowBelow"); |
Jorim Jaggi | 153badb | 2017-05-24 13:18:28 +0200 | [diff] [blame] | 123 | |
| 124 | // Adding a display will cause freezing the display. Make sure to wait until it's unfrozen |
| 125 | // to not run into race conditions with the tests. |
| 126 | waitUntilHandlersIdle(); |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | @After |
| 130 | public void tearDown() throws Exception { |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 131 | final LinkedList<WindowState> nonCommonWindows = new LinkedList(); |
Wale Ogunwale | 027f475 | 2017-05-12 10:37:16 -0700 | [diff] [blame] | 132 | |
| 133 | synchronized (sWm.mWindowMap) { |
| 134 | sWm.mRoot.forAllWindows(w -> { |
| 135 | if (!mCommonWindows.contains(w)) { |
| 136 | nonCommonWindows.addLast(w); |
| 137 | } |
| 138 | }, true /* traverseTopToBottom */); |
| 139 | |
| 140 | while (!nonCommonWindows.isEmpty()) { |
| 141 | nonCommonWindows.pollLast().removeImmediately(); |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 142 | } |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 143 | |
Wale Ogunwale | 027f475 | 2017-05-12 10:37:16 -0700 | [diff] [blame] | 144 | mDisplayContent.removeImmediately(); |
| 145 | sWm.mInputMethodTarget = null; |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 146 | } |
Jorim Jaggi | 153badb | 2017-05-24 13:18:28 +0200 | [diff] [blame] | 147 | |
| 148 | // Wait until everything is really cleaned up. |
| 149 | waitUntilHandlersIdle(); |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 150 | } |
| 151 | |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 152 | private WindowState createCommonWindow(WindowState parent, int type, String name) { |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 153 | final WindowState win = createWindow(parent, type, name); |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 154 | mCommonWindows.add(win); |
Wale Ogunwale | 3424795 | 2017-02-19 11:57:53 -0800 | [diff] [blame] | 155 | // Prevent common windows from been IMe targets |
| 156 | win.mAttrs.flags |= FLAG_NOT_FOCUSABLE; |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 157 | return win; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | /** Asserts that the first entry is greater than the second entry. */ |
| 161 | void assertGreaterThan(int first, int second) throws Exception { |
| 162 | Assert.assertTrue("Excepted " + first + " to be greater than " + second, first > second); |
| 163 | } |
| 164 | |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 165 | /** |
| 166 | * Waits until the main handler for WM has processed all messages. |
| 167 | */ |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 168 | void waitUntilHandlersIdle() { |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 169 | sWm.mH.runWithScissors(() -> { }, 0); |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 170 | sWm.mAnimationHandler.runWithScissors(() -> { }, 0); |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 171 | } |
| 172 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 173 | private WindowToken createWindowToken( |
| 174 | DisplayContent dc, int windowingMode, int activityType, int type) { |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 175 | if (type < FIRST_APPLICATION_WINDOW || type > LAST_APPLICATION_WINDOW) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 176 | return new WindowTestUtils.TestWindowToken(type, dc); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 177 | } |
| 178 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 179 | final TaskStack stack = |
| 180 | createStackControllerOnStackOnDisplay(windowingMode, activityType, dc).mContainer; |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 181 | final Task task = createTaskInStack(stack, 0 /* userId */); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 182 | final WindowTestUtils.TestAppWindowToken token = new WindowTestUtils.TestAppWindowToken(dc); |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 183 | task.addChild(token, 0); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 184 | return token; |
| 185 | } |
| 186 | |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 187 | WindowState createWindow(WindowState parent, int type, String name) { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 188 | return (parent == null) |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 189 | ? createWindow(parent, type, mDisplayContent, name) |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 190 | : createWindow(parent, type, parent.mToken, name); |
| 191 | } |
| 192 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 193 | WindowState createWindowOnStack(WindowState parent, int windowingMode, int activityType, |
| 194 | int type, DisplayContent dc, String name) { |
| 195 | final WindowToken token = createWindowToken(dc, windowingMode, activityType, type); |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 196 | return createWindow(parent, type, token, name); |
| 197 | } |
| 198 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 199 | WindowState createAppWindow(Task task, int type, String name) { |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 200 | final AppWindowToken token = new WindowTestUtils.TestAppWindowToken(mDisplayContent); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 201 | task.addChild(token, 0); |
| 202 | return createWindow(null, type, token, name); |
| 203 | } |
| 204 | |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 205 | WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 206 | final WindowToken token = createWindowToken( |
| 207 | dc, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, type); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 208 | return createWindow(parent, type, token, name); |
| 209 | } |
| 210 | |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 211 | WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name, |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 212 | boolean ownerCanAddInternalSystemWindow) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 213 | final WindowToken token = createWindowToken( |
| 214 | dc, WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, type); |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 215 | return createWindow(parent, type, token, name, ownerCanAddInternalSystemWindow); |
| 216 | } |
| 217 | |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 218 | static WindowState createWindow(WindowState parent, int type, WindowToken token, String name) { |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 219 | return createWindow(parent, type, token, name, false /* ownerCanAddInternalSystemWindow */); |
| 220 | } |
| 221 | |
| 222 | static WindowState createWindow(WindowState parent, int type, WindowToken token, String name, |
| 223 | boolean ownerCanAddInternalSystemWindow) { |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 224 | final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type); |
| 225 | attrs.setTitle(name); |
| 226 | |
Wale Ogunwale | 8e44f6c | 2017-03-09 15:25:10 -0800 | [diff] [blame] | 227 | final WindowState w = new WindowState(sWm, sMockSession, sIWindow, token, parent, OP_NONE, |
David Stevens | 4693956 | 2017-03-24 13:04:00 -0700 | [diff] [blame] | 228 | 0, attrs, VISIBLE, 0, ownerCanAddInternalSystemWindow); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 229 | // TODO: Probably better to make this call in the WindowState ctor to avoid errors with |
| 230 | // adding it to the token... |
| 231 | token.addWindow(w); |
| 232 | return w; |
| 233 | } |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 234 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 235 | /** Creates a {@link TaskStack} and adds it to the specified {@link DisplayContent}. */ |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 236 | TaskStack createTaskStackOnDisplay(DisplayContent dc) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 237 | return createStackControllerOnDisplay(dc).mContainer; |
| 238 | } |
| 239 | |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 240 | StackWindowController createStackControllerOnDisplay(DisplayContent dc) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 241 | return createStackControllerOnStackOnDisplay( |
| 242 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, dc); |
Winson Chung | 8347163 | 2016-12-13 11:02:12 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 245 | StackWindowController createStackControllerOnStackOnDisplay( |
| 246 | int windowingMode, int activityType, DisplayContent dc) { |
Wale Ogunwale | f75962a | 2017-08-23 14:58:04 -0700 | [diff] [blame] | 247 | final Configuration overrideConfig = new Configuration(); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 248 | overrideConfig.windowConfiguration.setWindowingMode(windowingMode); |
| 249 | overrideConfig.windowConfiguration.setActivityType(activityType); |
| 250 | final int stackId = ++sNextStackId; |
Wale Ogunwale | 034a8ec | 2017-09-02 17:14:40 -0700 | [diff] [blame] | 251 | final StackWindowController controller = new StackWindowController(stackId, null, |
| 252 | dc.getDisplayId(), true /* onTop */, new Rect(), sWm); |
| 253 | controller.onOverrideConfigurationChanged(overrideConfig); |
| 254 | return controller; |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 257 | /** Creates a {@link Task} and adds it to the specified {@link TaskStack}. */ |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 258 | Task createTaskInStack(TaskStack stack, int userId) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 259 | return WindowTestUtils.createTaskInStack(sWm, stack, userId); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 260 | } |
| 261 | |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 262 | /** Creates a {@link DisplayContent} and adds it to the system. */ |
| 263 | DisplayContent createNewDisplay() { |
| 264 | final int displayId = sNextDisplayId++; |
| 265 | final Display display = new Display(DisplayManagerGlobal.getInstance(), displayId, |
Wale Ogunwale | 11cc516 | 2017-04-25 20:29:13 -0700 | [diff] [blame] | 266 | mDisplayInfo, DEFAULT_DISPLAY_ADJUSTMENTS); |
| 267 | return new DisplayContent(display, sWm, mLayersController, new WallpaperController(sWm)); |
Andrii Kulian | 367ff7f | 2017-01-25 19:45:34 -0800 | [diff] [blame] | 268 | } |
| 269 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 270 | /** Creates a {@link com.android.server.wm.WindowTestUtils.TestWindowState} */ |
| 271 | WindowTestUtils.TestWindowState createWindowState(WindowManager.LayoutParams attrs, |
| 272 | WindowToken token) { |
| 273 | return new WindowTestUtils.TestWindowState(sWm, sMockSession, sIWindow, attrs, token); |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 274 | } |
| 275 | |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 276 | } |