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 | |
Jorim Jaggi | 829b9cd | 2017-01-23 16:20:53 +0100 | [diff] [blame] | 19 | import android.app.ActivityManager.TaskDescription; |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 20 | import android.app.ActivityManagerInternal; |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 21 | import android.content.res.Configuration; |
| 22 | import android.graphics.Rect; |
| 23 | import android.os.Binder; |
| 24 | import android.view.IApplicationToken; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 25 | import org.junit.Assert; |
| 26 | import org.junit.Before; |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 27 | import org.mockito.Mock; |
| 28 | import org.mockito.Mockito; |
| 29 | import org.mockito.MockitoAnnotations; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 30 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 31 | import android.app.ActivityManager.TaskSnapshot; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 32 | import android.content.Context; |
| 33 | import android.os.IBinder; |
| 34 | import android.support.test.InstrumentationRegistry; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 35 | import android.view.IWindow; |
| 36 | import android.view.WindowManager; |
| 37 | |
| 38 | import static android.app.ActivityManager.StackId.FIRST_DYNAMIC_STACK_ID; |
| 39 | import static android.app.AppOpsManager.OP_NONE; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 40 | import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 41 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 42 | import static android.content.res.Configuration.EMPTY; |
| 43 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 44 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 45 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 46 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY; |
| 47 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 48 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
| 49 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 50 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
| 51 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; |
| 52 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
| 53 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 54 | import static com.android.server.wm.WindowContainer.POSITION_TOP; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 55 | import static org.mockito.Mockito.mock; |
| 56 | |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 57 | import com.android.server.AttributeCache; |
| 58 | import com.android.server.LocalServices; |
| 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; |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 65 | static TestWindowManagerPolicy sPolicy = null; |
| 66 | private final static IWindow sIWindow = new TestIWindow(); |
| 67 | private final static Session sMockSession = mock(Session.class); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 68 | static int sNextStackId = FIRST_DYNAMIC_STACK_ID; |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 69 | private static int sNextTaskId = 0; |
| 70 | |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 71 | private static boolean sOneTimeSetupDone = false; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 72 | static DisplayContent sDisplayContent; |
| 73 | static WindowLayersController sLayersController; |
| 74 | static WindowState sWallpaperWindow; |
| 75 | static WindowState sImeWindow; |
| 76 | static WindowState sImeDialogWindow; |
| 77 | static WindowState sStatusBarWindow; |
| 78 | static WindowState sDockedDividerWindow; |
| 79 | static WindowState sNavBarWindow; |
| 80 | static WindowState sAppWindow; |
| 81 | static WindowState sChildAppWindowAbove; |
| 82 | static WindowState sChildAppWindowBelow; |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 83 | static @Mock ActivityManagerInternal sMockAm; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 84 | |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 85 | @Before |
| 86 | public void setUp() throws Exception { |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 87 | if (sOneTimeSetupDone) { |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 88 | Mockito.reset(sMockAm); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 89 | return; |
| 90 | } |
| 91 | sOneTimeSetupDone = true; |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 92 | MockitoAnnotations.initMocks(this); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 93 | final Context context = InstrumentationRegistry.getTargetContext(); |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 94 | LocalServices.addService(ActivityManagerInternal.class, sMockAm); |
| 95 | AttributeCache.init(context); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 96 | sWm = TestWindowManagerPolicy.getWindowManagerService(context); |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 97 | sPolicy = (TestWindowManagerPolicy) sWm.mPolicy; |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 98 | sLayersController = new WindowLayersController(sWm); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 99 | sDisplayContent = sWm.mRoot.getDisplayContent(context.getDisplay().getDisplayId()); |
| 100 | if (sDisplayContent != null) { |
| 101 | sDisplayContent.removeImmediately(); |
| 102 | } |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 103 | sDisplayContent = new DisplayContent(context.getDisplay(), sWm, sLayersController, |
| 104 | new WallpaperController(sWm)); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 105 | sWm.mRoot.addChild(sDisplayContent, 0); |
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. |
| 110 | sWallpaperWindow = createWindow(null, TYPE_WALLPAPER, sDisplayContent, "wallpaperWindow"); |
| 111 | sImeWindow = createWindow(null, TYPE_INPUT_METHOD, sDisplayContent, "sImeWindow"); |
| 112 | sImeDialogWindow = |
| 113 | createWindow(null, TYPE_INPUT_METHOD_DIALOG, sDisplayContent, "sImeDialogWindow"); |
| 114 | sStatusBarWindow = createWindow(null, TYPE_STATUS_BAR, sDisplayContent, "sStatusBarWindow"); |
| 115 | sNavBarWindow = |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 116 | createWindow(null, TYPE_NAVIGATION_BAR, sDisplayContent, "sNavBarWindow"); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 117 | sDockedDividerWindow = |
Wale Ogunwale | 6ce0fb8 | 2016-12-13 14:24:00 -0800 | [diff] [blame] | 118 | createWindow(null, TYPE_DOCK_DIVIDER, sDisplayContent, "sDockedDividerWindow"); |
Wale Ogunwale | 3c1170d | 2016-12-02 14:44:52 -0800 | [diff] [blame] | 119 | sAppWindow = createWindow(null, TYPE_BASE_APPLICATION, sDisplayContent, "sAppWindow"); |
| 120 | sChildAppWindowAbove = createWindow(sAppWindow, |
| 121 | TYPE_APPLICATION_ATTACHED_DIALOG, sAppWindow.mToken, "sChildAppWindowAbove"); |
| 122 | sChildAppWindowBelow = createWindow(sAppWindow, |
| 123 | TYPE_APPLICATION_MEDIA_OVERLAY, sAppWindow.mToken, "sChildAppWindowBelow"); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /** Asserts that the first entry is greater than the second entry. */ |
| 127 | void assertGreaterThan(int first, int second) throws Exception { |
| 128 | Assert.assertTrue("Excepted " + first + " to be greater than " + second, first > second); |
| 129 | } |
| 130 | |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 131 | /** |
| 132 | * Waits until the main handler for WM has processed all messages. |
| 133 | */ |
| 134 | void waitUntilHandlerIdle() { |
| 135 | sWm.mH.runWithScissors(() -> { }, 0); |
| 136 | } |
| 137 | |
| 138 | private static WindowToken createWindowToken(DisplayContent dc, int type) { |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 139 | if (type < FIRST_APPLICATION_WINDOW || type > LAST_APPLICATION_WINDOW) { |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 140 | return new TestWindowToken(type, dc); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 141 | } |
| 142 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 143 | final TaskStack stack = createTaskStackOnDisplay(dc); |
| 144 | final Task task = createTaskInStack(stack, 0 /* userId */); |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 145 | final TestAppWindowToken token = new TestAppWindowToken(dc); |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 146 | task.addChild(token, 0); |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 147 | return token; |
| 148 | } |
| 149 | |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 150 | static WindowState createWindow(WindowState parent, int type, String name) { |
Wale Ogunwale | 805d9ec | 2016-12-07 12:22:08 -0800 | [diff] [blame] | 151 | return (parent == null) |
| 152 | ? createWindow(parent, type, sDisplayContent, name) |
| 153 | : createWindow(parent, type, parent.mToken, name); |
| 154 | } |
| 155 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 156 | WindowState createAppWindow(Task task, int type, String name) { |
| 157 | final AppWindowToken token = new TestAppWindowToken(sDisplayContent); |
| 158 | task.addChild(token, 0); |
| 159 | return createWindow(null, type, token, name); |
| 160 | } |
| 161 | |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 162 | static WindowState createWindow(WindowState parent, int type, DisplayContent dc, String name) { |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 163 | final WindowToken token = createWindowToken(dc, type); |
| 164 | return createWindow(parent, type, token, name); |
| 165 | } |
| 166 | |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 167 | static WindowState createWindow(WindowState parent, int type, WindowToken token, String name) { |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 168 | final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type); |
| 169 | attrs.setTitle(name); |
| 170 | |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 171 | final WindowState w = new WindowState(sWm, sMockSession, sIWindow, token, parent, OP_NONE, |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 172 | 0, attrs, 0, 0); |
| 173 | // TODO: Probably better to make this call in the WindowState ctor to avoid errors with |
| 174 | // adding it to the token... |
| 175 | token.addWindow(w); |
| 176 | return w; |
| 177 | } |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 178 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 179 | /** Creates a {@link TaskStack} and adds it to the specified {@link DisplayContent}. */ |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 180 | static TaskStack createTaskStackOnDisplay(DisplayContent dc) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 181 | return createStackControllerOnDisplay(dc).mContainer; |
| 182 | } |
| 183 | |
| 184 | static StackWindowController createStackControllerOnDisplay(DisplayContent dc) { |
| 185 | final int stackId = ++sNextStackId; |
| 186 | return new StackWindowController(stackId, null, dc.getDisplayId(), |
| 187 | true /* onTop */, new Rect(), sWm); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /**Creates a {@link Task} and adds it to the specified {@link TaskStack}. */ |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 191 | static Task createTaskInStack(TaskStack stack, int userId) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 192 | final Task newTask = new Task(sNextTaskId++, stack, userId, sWm, null, EMPTY, false, 0, |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 193 | false, false, new TaskDescription(), null); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 194 | stack.addTask(newTask, POSITION_TOP); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 195 | return newTask; |
| 196 | } |
| 197 | |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 198 | /* Used so we can gain access to some protected members of the {@link WindowToken} class */ |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 199 | static class TestWindowToken extends WindowToken { |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 200 | |
| 201 | TestWindowToken(int type, DisplayContent dc) { |
| 202 | this(type, dc, false /* persistOnEmpty */); |
| 203 | } |
| 204 | |
| 205 | TestWindowToken(int type, DisplayContent dc, boolean persistOnEmpty) { |
| 206 | super(sWm, mock(IBinder.class), type, persistOnEmpty, dc); |
| 207 | } |
| 208 | |
| 209 | int getWindowsCount() { |
| 210 | return mChildren.size(); |
| 211 | } |
| 212 | |
| 213 | boolean hasWindow(WindowState w) { |
| 214 | return mChildren.contains(w); |
| 215 | } |
| 216 | } |
| 217 | |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 218 | /** Used so we can gain access to some protected members of the {@link AppWindowToken} class. */ |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 219 | static class TestAppWindowToken extends AppWindowToken { |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 220 | |
| 221 | TestAppWindowToken(DisplayContent dc) { |
| 222 | super(sWm, null, false, dc); |
| 223 | } |
| 224 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame^] | 225 | TestAppWindowToken(WindowManagerService service, IApplicationToken token, |
| 226 | boolean voiceInteraction, DisplayContent dc, long inputDispatchingTimeoutNanos, |
| 227 | boolean fullscreen, boolean showForAllUsers, int targetSdk, int orientation, |
| 228 | int rotationAnimationHint, int configChanges, boolean launchTaskBehind, |
| 229 | boolean alwaysFocusable, AppWindowContainerController controller) { |
| 230 | super(service, token, voiceInteraction, dc, inputDispatchingTimeoutNanos, fullscreen, |
| 231 | showForAllUsers, targetSdk, orientation, rotationAnimationHint, configChanges, |
| 232 | launchTaskBehind, alwaysFocusable, controller); |
| 233 | } |
| 234 | |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 235 | int getWindowsCount() { |
| 236 | return mChildren.size(); |
| 237 | } |
| 238 | |
| 239 | boolean hasWindow(WindowState w) { |
| 240 | return mChildren.contains(w); |
| 241 | } |
| 242 | |
| 243 | WindowState getFirstChild() { |
| 244 | return mChildren.getFirst(); |
| 245 | } |
| 246 | |
| 247 | WindowState getLastChild() { |
| 248 | return mChildren.getLast(); |
| 249 | } |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame^] | 250 | |
| 251 | int positionInParent() { |
| 252 | return getParent().mChildren.indexOf(this); |
| 253 | } |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 254 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 255 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 256 | /* Used so we can gain access to some protected members of the {@link Task} class */ |
| 257 | class TestTask extends Task { |
| 258 | |
| 259 | boolean mShouldDeferRemoval = false; |
Andrii Kulian | 7cd7c2d | 2017-01-18 12:14:37 -0800 | [diff] [blame] | 260 | boolean mOnDisplayChangedCalled = false; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 261 | private boolean mUseLocalIsAnimating = false; |
| 262 | private boolean mIsAnimating = false; |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 263 | |
| 264 | TestTask(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds, |
| 265 | Configuration overrideConfig, boolean isOnTopLauncher, int resizeMode, |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 266 | boolean supportsPictureInPicture, boolean homeTask, |
| 267 | TaskWindowContainerController controller) { |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 268 | super(taskId, stack, userId, service, bounds, overrideConfig, isOnTopLauncher, |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 269 | resizeMode, supportsPictureInPicture, homeTask, new TaskDescription(), |
| 270 | controller); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | boolean shouldDeferRemoval() { |
| 274 | return mShouldDeferRemoval; |
| 275 | } |
| 276 | |
| 277 | int positionInParent() { |
| 278 | return getParent().mChildren.indexOf(this); |
| 279 | } |
Andrii Kulian | 7cd7c2d | 2017-01-18 12:14:37 -0800 | [diff] [blame] | 280 | |
| 281 | @Override |
| 282 | void onDisplayChanged(DisplayContent dc) { |
| 283 | super.onDisplayChanged(dc); |
| 284 | mOnDisplayChangedCalled = true; |
| 285 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 286 | |
| 287 | @Override |
| 288 | boolean isAnimating() { |
| 289 | return mUseLocalIsAnimating ? mIsAnimating : super.isAnimating(); |
| 290 | } |
| 291 | |
| 292 | void setLocalIsAnimating(boolean isAnimating) { |
| 293 | mUseLocalIsAnimating = true; |
| 294 | mIsAnimating = isAnimating; |
| 295 | } |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 296 | } |
| 297 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 298 | /** |
| 299 | * Used so we can gain access to some protected members of {@link TaskWindowContainerController} |
| 300 | * class. |
| 301 | */ |
| 302 | class TestTaskWindowContainerController extends TaskWindowContainerController { |
| 303 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 304 | TestTaskWindowContainerController() { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 305 | this(createStackControllerOnDisplay(sDisplayContent)); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 306 | } |
| 307 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 308 | TestTaskWindowContainerController(StackWindowController stackController) { |
| 309 | super(sNextTaskId++, new TaskWindowContainerListener() { |
| 310 | @Override |
| 311 | public void onSnapshotChanged(TaskSnapshot snapshot) { |
| 312 | |
| 313 | } |
| 314 | |
| 315 | @Override |
| 316 | public void requestResize(Rect bounds, int resizeMode) { |
| 317 | |
| 318 | } |
| 319 | }, stackController, 0 /* userId */, null /* bounds */, |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 320 | EMPTY /* overrideConfig*/, RESIZE_MODE_UNRESIZEABLE, |
| 321 | false /* supportsPictureInPicture */, false /* homeTask*/, |
Jorim Jaggi | 829b9cd | 2017-01-23 16:20:53 +0100 | [diff] [blame] | 322 | false /* isOnTopLauncher */, true /* toTop*/, true /* showForAllUsers */, |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 323 | new TaskDescription(), sWm); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 324 | } |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 325 | |
| 326 | @Override |
| 327 | TestTask createTask(int taskId, TaskStack stack, int userId, Rect bounds, |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 328 | Configuration overrideConfig, int resizeMode, boolean supportsPictureInPicture, |
| 329 | boolean homeTask, boolean isOnTopLauncher, TaskDescription taskDescription) { |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 330 | return new TestTask(taskId, stack, userId, mService, bounds, overrideConfig, |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 331 | isOnTopLauncher, resizeMode, supportsPictureInPicture, homeTask, this); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | |
| 335 | class TestAppWindowContainerController extends AppWindowContainerController { |
| 336 | |
| 337 | final IApplicationToken mToken; |
| 338 | |
| 339 | TestAppWindowContainerController(TestTaskWindowContainerController taskController) { |
| 340 | this(taskController, new TestIApplicationToken()); |
| 341 | } |
| 342 | |
| 343 | TestAppWindowContainerController(TestTaskWindowContainerController taskController, |
| 344 | IApplicationToken token) { |
| 345 | super(taskController, token, null /* listener */, 0 /* index */, |
| 346 | SCREEN_ORIENTATION_UNSPECIFIED, true /* fullscreen */, |
| 347 | true /* showForAllUsers */, 0 /* configChanges */, false /* voiceInteraction */, |
| 348 | false /* launchTaskBehind */, false /* alwaysFocusable */, |
| 349 | 0 /* targetSdkVersion */, 0 /* rotationAnimationHint */, |
| 350 | 0 /* inputDispatchingTimeoutNanos */, sWm); |
| 351 | mToken = token; |
| 352 | } |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 353 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame^] | 354 | @Override |
| 355 | AppWindowToken createAppWindow(WindowManagerService service, IApplicationToken token, |
| 356 | boolean voiceInteraction, DisplayContent dc, long inputDispatchingTimeoutNanos, |
| 357 | boolean fullscreen, boolean showForAllUsers, int targetSdk, int orientation, |
| 358 | int rotationAnimationHint, int configChanges, boolean launchTaskBehind, |
| 359 | boolean alwaysFocusable, AppWindowContainerController controller) { |
| 360 | return new TestAppWindowToken(service, token, voiceInteraction, dc, |
| 361 | inputDispatchingTimeoutNanos, fullscreen, showForAllUsers, targetSdk, |
| 362 | orientation, |
| 363 | rotationAnimationHint, configChanges, launchTaskBehind, alwaysFocusable, |
| 364 | controller); |
| 365 | } |
| 366 | |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 367 | AppWindowToken getAppWindowToken() { |
| 368 | return (AppWindowToken) sDisplayContent.getWindowToken(mToken.asBinder()); |
| 369 | } |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | class TestIApplicationToken implements IApplicationToken { |
| 373 | |
| 374 | private final Binder mBinder = new Binder(); |
| 375 | @Override |
| 376 | public IBinder asBinder() { |
| 377 | return mBinder; |
| 378 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 379 | } |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 380 | |
| 381 | /** Used to track resize reports. */ |
| 382 | class TestWindowState extends WindowState { |
| 383 | boolean resizeReported; |
| 384 | |
| 385 | TestWindowState(WindowManager.LayoutParams attrs, WindowToken token) { |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 386 | super(sWm, sMockSession, sIWindow, token, null, OP_NONE, 0, attrs, 0, 0); |
Andrii Kulian | 4ede3e0 | 2017-01-12 11:52:31 -0800 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | @Override |
| 390 | void reportResized() { |
| 391 | super.reportResized(); |
| 392 | resizeReported = true; |
| 393 | } |
| 394 | |
| 395 | @Override |
| 396 | public boolean isGoneForLayoutLw() { |
| 397 | return false; |
| 398 | } |
| 399 | |
| 400 | @Override |
| 401 | void updateResizingWindowIfNeeded() { |
| 402 | // Used in AppWindowTokenTests#testLandscapeSeascapeRotationRelayout to deceive |
| 403 | // the system that it can actually update the window. |
| 404 | boolean hadSurface = mHasSurface; |
| 405 | mHasSurface = true; |
| 406 | |
| 407 | super.updateResizingWindowIfNeeded(); |
| 408 | |
| 409 | mHasSurface = hadSurface; |
| 410 | } |
| 411 | } |
Wale Ogunwale | 44fbdf5 | 2016-11-16 10:18:45 -0800 | [diff] [blame] | 412 | } |