Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -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 | |
| 19 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 20 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 21 | import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS; |
| 22 | import static android.view.WindowManager.TRANSIT_UNSET; |
Vishnu Nair | c1d2ff6 | 2018-11-08 16:50:12 -0800 | [diff] [blame] | 23 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 24 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 25 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS; |
| 26 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 27 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW; |
| 28 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT; |
| 29 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
| 30 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 31 | |
Jorim Jaggi | e2c77f9 | 2016-12-29 14:57:22 +0100 | [diff] [blame] | 32 | import android.app.ActivityManager.TaskSnapshot; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 33 | import android.content.res.CompatibilityInfo; |
| 34 | import android.content.res.Configuration; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 35 | import android.os.Debug; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 36 | import android.os.Handler; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 37 | import android.os.IBinder; |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 38 | import android.os.Looper; |
| 39 | import android.os.Message; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 40 | import android.util.Slog; |
| 41 | import android.view.IApplicationToken; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 42 | import android.view.RemoteAnimationDefinition; |
| 43 | import android.view.WindowManager; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 44 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 45 | import com.android.internal.annotations.VisibleForTesting; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 46 | import com.android.server.AttributeCache; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 47 | import com.android.server.policy.WindowManagerPolicy.StartingSurface; |
| 48 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 49 | /** |
| 50 | * Controller for the app window token container. This is created by activity manager to link |
| 51 | * activity records to the app window token container they use in window manager. |
| 52 | * |
| 53 | * Test class: {@link AppWindowContainerControllerTests} |
| 54 | */ |
| 55 | public class AppWindowContainerController |
| 56 | extends WindowContainerController<AppWindowToken, AppWindowContainerListener> { |
| 57 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 58 | private static final int STARTING_WINDOW_TYPE_NONE = 0; |
| 59 | private static final int STARTING_WINDOW_TYPE_SNAPSHOT = 1; |
| 60 | private static final int STARTING_WINDOW_TYPE_SPLASH_SCREEN = 2; |
| 61 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 62 | private final IApplicationToken mToken; |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 63 | private final Handler mHandler; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 64 | |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 65 | private final class H extends Handler { |
| 66 | public static final int NOTIFY_WINDOWS_DRAWN = 1; |
| 67 | public static final int NOTIFY_STARTING_WINDOW_DRAWN = 2; |
Vishnu Nair | c1d2ff6 | 2018-11-08 16:50:12 -0800 | [diff] [blame] | 68 | public static final int NOTIFY_WINDOWS_NOTDRAWN = 3; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 69 | |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 70 | public H(Looper looper) { |
| 71 | super(looper); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 72 | } |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 73 | |
| 74 | @Override |
| 75 | public void handleMessage(Message msg) { |
| 76 | switch (msg.what) { |
| 77 | case NOTIFY_WINDOWS_DRAWN: |
| 78 | if (mListener == null) { |
| 79 | return; |
| 80 | } |
| 81 | if (DEBUG_VISIBILITY) Slog.v(TAG_WM, "Reporting drawn in " |
| 82 | + AppWindowContainerController.this.mToken); |
| 83 | mListener.onWindowsDrawn(msg.getWhen()); |
| 84 | break; |
| 85 | case NOTIFY_STARTING_WINDOW_DRAWN: |
| 86 | if (mListener == null) { |
| 87 | return; |
| 88 | } |
Vishnu Nair | c1d2ff6 | 2018-11-08 16:50:12 -0800 | [diff] [blame] | 89 | if (DEBUG_VISIBILITY) Slog.v(TAG_WM, "Reporting starting window drawn in " |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 90 | + AppWindowContainerController.this.mToken); |
| 91 | mListener.onStartingWindowDrawn(msg.getWhen()); |
| 92 | break; |
Vishnu Nair | c1d2ff6 | 2018-11-08 16:50:12 -0800 | [diff] [blame] | 93 | case NOTIFY_WINDOWS_NOTDRAWN: |
| 94 | if (mListener == null) { |
| 95 | return; |
| 96 | } |
| 97 | if (DEBUG_VISIBILITY) Slog.v(TAG_WM, "Reporting undrawn in " |
| 98 | + AppWindowContainerController.this.mToken); |
| 99 | mListener.onWindowsNotDrawn(msg.getWhen()); |
| 100 | break; |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 101 | default: |
| 102 | break; |
| 103 | } |
| 104 | } |
| 105 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 106 | |
| 107 | private final Runnable mOnWindowsVisible = () -> { |
| 108 | if (mListener == null) { |
| 109 | return; |
| 110 | } |
| 111 | if (DEBUG_VISIBILITY) Slog.v(TAG_WM, "Reporting visible in " |
| 112 | + AppWindowContainerController.this.mToken); |
| 113 | mListener.onWindowsVisible(); |
| 114 | }; |
| 115 | |
| 116 | private final Runnable mOnWindowsGone = () -> { |
| 117 | if (mListener == null) { |
| 118 | return; |
| 119 | } |
| 120 | if (DEBUG_VISIBILITY) Slog.v(TAG_WM, "Reporting gone in " |
| 121 | + AppWindowContainerController.this.mToken); |
| 122 | mListener.onWindowsGone(); |
| 123 | }; |
| 124 | |
Jorim Jaggi | d8665f2 | 2018-04-10 00:34:24 +0200 | [diff] [blame] | 125 | private final Runnable mAddStartingWindow = new Runnable() { |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 126 | |
Jorim Jaggi | d8665f2 | 2018-04-10 00:34:24 +0200 | [diff] [blame] | 127 | @Override |
| 128 | public void run() { |
| 129 | final StartingData startingData; |
| 130 | final AppWindowToken container; |
| 131 | |
| 132 | synchronized (mWindowMap) { |
| 133 | if (mContainer == null) { |
| 134 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "mContainer was null while trying to" |
| 135 | + " add starting window"); |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | // There can only be one adding request, silly caller! |
| 140 | mService.mAnimationHandler.removeCallbacks(this); |
| 141 | |
| 142 | startingData = mContainer.startingData; |
| 143 | container = mContainer; |
| 144 | } |
| 145 | |
| 146 | if (startingData == null) { |
| 147 | // Animation has been canceled... do nothing. |
| 148 | if (DEBUG_STARTING_WINDOW) |
| 149 | Slog.v(TAG_WM, "startingData was nulled out before handling" |
| 150 | + " mAddStartingWindow: " + mContainer); |
Jorim Jaggi | 73f8820 | 2017-01-12 13:54:40 +0100 | [diff] [blame] | 151 | return; |
| 152 | } |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 153 | |
Jorim Jaggi | d8665f2 | 2018-04-10 00:34:24 +0200 | [diff] [blame] | 154 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Add starting " |
| 155 | + AppWindowContainerController.this + ": startingData=" |
| 156 | + container.startingData); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 157 | |
Jorim Jaggi | d8665f2 | 2018-04-10 00:34:24 +0200 | [diff] [blame] | 158 | StartingSurface surface = null; |
| 159 | try { |
| 160 | surface = startingData.createStartingSurface(container); |
| 161 | } catch (Exception e) { |
| 162 | Slog.w(TAG_WM, "Exception when adding starting window", e); |
| 163 | } |
| 164 | if (surface != null) { |
| 165 | boolean abort = false; |
| 166 | synchronized (mWindowMap) { |
| 167 | // If the window was successfully added, then |
| 168 | // we need to remove it. |
| 169 | if (container.removed || container.startingData == null) { |
| 170 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, |
| 171 | "Aborted starting " + container |
| 172 | + ": removed=" + container.removed |
| 173 | + " startingData=" + container.startingData); |
| 174 | container.startingWindow = null; |
| 175 | container.startingData = null; |
| 176 | abort = true; |
| 177 | } else { |
| 178 | container.startingSurface = surface; |
| 179 | } |
| 180 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG_WM, |
| 181 | "Added starting " + mContainer |
| 182 | + ": startingWindow=" |
| 183 | + container.startingWindow + " startingView=" |
| 184 | + container.startingSurface); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 185 | } |
Jorim Jaggi | d8665f2 | 2018-04-10 00:34:24 +0200 | [diff] [blame] | 186 | if (abort) { |
| 187 | surface.remove(); |
| 188 | } |
| 189 | } else if (DEBUG_STARTING_WINDOW) { |
| 190 | Slog.v(TAG_WM, "Surface returned was null: " + mContainer); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 191 | } |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 192 | } |
| 193 | }; |
| 194 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 195 | public AppWindowContainerController(TaskWindowContainerController taskController, |
| 196 | IApplicationToken token, AppWindowContainerListener listener, int index, |
| 197 | int requestedOrientation, boolean fullscreen, boolean showForAllUsers, int configChanges, |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 198 | boolean voiceInteraction, boolean launchTaskBehind, boolean alwaysFocusable, |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 199 | int targetSdkVersion, int rotationAnimationHint, long inputDispatchingTimeoutNanos) { |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 200 | this(taskController, token, listener, index, requestedOrientation, fullscreen, |
| 201 | showForAllUsers, |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 202 | configChanges, voiceInteraction, launchTaskBehind, alwaysFocusable, |
| 203 | targetSdkVersion, rotationAnimationHint, inputDispatchingTimeoutNanos, |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 204 | WindowManagerService.getInstance()); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 205 | } |
| 206 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 207 | public AppWindowContainerController(TaskWindowContainerController taskController, |
| 208 | IApplicationToken token, AppWindowContainerListener listener, int index, |
| 209 | int requestedOrientation, boolean fullscreen, boolean showForAllUsers, int configChanges, |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 210 | boolean voiceInteraction, boolean launchTaskBehind, boolean alwaysFocusable, |
| 211 | int targetSdkVersion, int rotationAnimationHint, long inputDispatchingTimeoutNanos, |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 212 | WindowManagerService service) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 213 | super(listener, service); |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 214 | mHandler = new H(service.mH.getLooper()); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 215 | mToken = token; |
| 216 | synchronized(mWindowMap) { |
| 217 | AppWindowToken atoken = mRoot.getAppWindowToken(mToken.asBinder()); |
| 218 | if (atoken != null) { |
| 219 | // TODO: Should this throw an exception instead? |
| 220 | Slog.w(TAG_WM, "Attempted to add existing app token: " + mToken); |
| 221 | return; |
| 222 | } |
| 223 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 224 | final Task task = taskController.mContainer; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 225 | if (task == null) { |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 226 | throw new IllegalArgumentException("AppWindowContainerController: invalid " |
| 227 | + " controller=" + taskController); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 228 | } |
| 229 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 230 | atoken = createAppWindow(mService, token, voiceInteraction, task.getDisplayContent(), |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 231 | inputDispatchingTimeoutNanos, fullscreen, showForAllUsers, targetSdkVersion, |
| 232 | requestedOrientation, rotationAnimationHint, configChanges, launchTaskBehind, |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 233 | alwaysFocusable, this); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 234 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM, "addAppToken: " + atoken |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 235 | + " controller=" + taskController + " at " + index); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 236 | task.addChild(atoken, index); |
| 237 | } |
| 238 | } |
| 239 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 240 | @VisibleForTesting |
| 241 | AppWindowToken createAppWindow(WindowManagerService service, IApplicationToken token, |
| 242 | boolean voiceInteraction, DisplayContent dc, long inputDispatchingTimeoutNanos, |
| 243 | boolean fullscreen, boolean showForAllUsers, int targetSdk, int orientation, |
| 244 | int rotationAnimationHint, int configChanges, boolean launchTaskBehind, |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 245 | boolean alwaysFocusable, AppWindowContainerController controller) { |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 246 | return new AppWindowToken(service, token, voiceInteraction, dc, |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 247 | inputDispatchingTimeoutNanos, fullscreen, showForAllUsers, targetSdk, orientation, |
| 248 | rotationAnimationHint, configChanges, launchTaskBehind, alwaysFocusable, |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 249 | controller); |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 250 | } |
| 251 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 252 | public void removeContainer(int displayId) { |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 253 | synchronized(mWindowMap) { |
| 254 | final DisplayContent dc = mRoot.getDisplayContent(displayId); |
| 255 | if (dc == null) { |
| 256 | Slog.w(TAG_WM, "removeAppToken: Attempted to remove binder token: " |
| 257 | + mToken + " from non-existing displayId=" + displayId); |
| 258 | return; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 259 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 260 | dc.removeAppToken(mToken.asBinder()); |
| 261 | super.removeContainer(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 265 | @Override |
| 266 | public void removeContainer() { |
| 267 | throw new UnsupportedOperationException("Use removeContainer(displayId) instead."); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 268 | } |
| 269 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 270 | public void reparent(TaskWindowContainerController taskController, int position) { |
| 271 | synchronized (mWindowMap) { |
| 272 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_WM, "reparent: moving app token=" + mToken |
| 273 | + " to task=" + taskController + " at " + position); |
| 274 | if (mContainer == null) { |
| 275 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_WM, |
| 276 | "reparent: could not find app token=" + mToken); |
| 277 | return; |
| 278 | } |
| 279 | final Task task = taskController.mContainer; |
| 280 | if (task == null) { |
| 281 | throw new IllegalArgumentException("reparent: could not find task=" |
| 282 | + taskController); |
| 283 | } |
| 284 | mContainer.reparent(task, position); |
| 285 | mContainer.getDisplayContent().layoutAndAssignWindowLayersIfNeeded(); |
| 286 | } |
| 287 | } |
| 288 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 289 | public Configuration setOrientation(int requestedOrientation, int displayId, |
| 290 | Configuration displayConfig, boolean freezeScreenIfNeeded) { |
| 291 | synchronized(mWindowMap) { |
| 292 | if (mContainer == null) { |
| 293 | Slog.w(TAG_WM, |
| 294 | "Attempted to set orientation of non-existing app token: " + mToken); |
| 295 | return null; |
| 296 | } |
| 297 | |
| 298 | mContainer.setOrientation(requestedOrientation); |
| 299 | |
| 300 | final IBinder binder = freezeScreenIfNeeded ? mToken.asBinder() : null; |
| 301 | return mService.updateOrientationFromAppTokens(displayConfig, binder, displayId); |
| 302 | |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | public int getOrientation() { |
| 307 | synchronized(mWindowMap) { |
| 308 | if (mContainer == null) { |
| 309 | return SCREEN_ORIENTATION_UNSPECIFIED; |
| 310 | } |
| 311 | |
| 312 | return mContainer.getOrientationIgnoreVisibility(); |
| 313 | } |
| 314 | } |
| 315 | |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 316 | public void setDisablePreviewScreenshots(boolean disable) { |
| 317 | synchronized (mWindowMap) { |
| 318 | if (mContainer == null) { |
| 319 | Slog.w(TAG_WM, "Attempted to set disable screenshots of non-existing app" |
| 320 | + " token: " + mToken); |
| 321 | return; |
| 322 | } |
Jorim Jaggi | d635a4a | 2017-05-03 15:21:26 +0200 | [diff] [blame] | 323 | mContainer.setDisablePreviewScreenshots(disable); |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | |
Tim Murray | 68ed844 | 2017-08-29 23:21:27 +0000 | [diff] [blame] | 327 | public void setVisibility(boolean visible, boolean deferHidingClient) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 328 | synchronized(mWindowMap) { |
| 329 | if (mContainer == null) { |
| 330 | Slog.w(TAG_WM, "Attempted to set visibility of non-existing app token: " |
| 331 | + mToken); |
| 332 | return; |
| 333 | } |
| 334 | |
| 335 | final AppWindowToken wtoken = mContainer; |
| 336 | |
Wale Ogunwale | 0c20ee3 | 2017-05-23 10:34:48 -0700 | [diff] [blame] | 337 | // Don't set visibility to false if we were already not visible. This prevents WM from |
| 338 | // adding the app to the closing app list which doesn't make sense for something that is |
| 339 | // already not visible. However, set visibility to true even if we are already visible. |
| 340 | // This makes sure the app is added to the opening apps list so that the right |
| 341 | // transition can be selected. |
| 342 | // TODO: Probably a good idea to separate the concept of opening/closing apps from the |
| 343 | // concept of setting visibility... |
| 344 | if (!visible && wtoken.hiddenRequested) { |
| 345 | |
| 346 | if (!deferHidingClient && wtoken.mDeferHidingClient) { |
| 347 | // We previously deferred telling the client to hide itself when visibility was |
| 348 | // initially set to false. Now we would like it to hide, so go ahead and set it. |
| 349 | wtoken.mDeferHidingClient = deferHidingClient; |
| 350 | wtoken.setClientHidden(true); |
| 351 | } |
| 352 | return; |
| 353 | } |
| 354 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 355 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) Slog.v(TAG_WM, "setAppVisibility(" |
| 356 | + mToken + ", visible=" + visible + "): " + mService.mAppTransition |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 357 | + " hidden=" + wtoken.isHidden() + " hiddenRequested=" |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 358 | + wtoken.hiddenRequested + " Callers=" + Debug.getCallers(6)); |
| 359 | |
| 360 | mService.mOpeningApps.remove(wtoken); |
| 361 | mService.mClosingApps.remove(wtoken); |
| 362 | wtoken.waitingToShow = false; |
| 363 | wtoken.hiddenRequested = !visible; |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 364 | wtoken.mDeferHidingClient = deferHidingClient; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 365 | |
| 366 | if (!visible) { |
| 367 | // If the app is dead while it was visible, we kept its dead window on screen. |
| 368 | // Now that the app is going invisible, we can remove it. It will be restarted |
| 369 | // if made visible again. |
| 370 | wtoken.removeDeadWindows(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 371 | } else { |
| 372 | if (!mService.mAppTransition.isTransitionSet() |
| 373 | && mService.mAppTransition.isReady()) { |
| 374 | // Add the app mOpeningApps if transition is unset but ready. This means |
| 375 | // we're doing a screen freeze, and the unfreeze will wait for all opening |
| 376 | // apps to be ready. |
| 377 | mService.mOpeningApps.add(wtoken); |
| 378 | } |
| 379 | wtoken.startingMoved = false; |
| 380 | // If the token is currently hidden (should be the common case), or has been |
| 381 | // stopped, then we need to set up to wait for its windows to be ready. |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 382 | if (wtoken.isHidden() || wtoken.mAppStopped) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 383 | wtoken.clearAllDrawn(); |
| 384 | |
| 385 | // If the app was already visible, don't reset the waitingToShow state. |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 386 | if (wtoken.isHidden()) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 387 | wtoken.waitingToShow = true; |
| 388 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 389 | } |
Jorim Jaggi | 067b5bf | 2018-02-23 17:42:39 +0100 | [diff] [blame] | 390 | |
| 391 | // In the case where we are making an app visible but holding off for a transition, |
| 392 | // we still need to tell the client to make its windows visible so they get drawn. |
| 393 | // Otherwise, we will wait on performing the transition until all windows have been |
| 394 | // drawn, they never will be, and we are sad. |
| 395 | wtoken.setClientHidden(false); |
| 396 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 397 | wtoken.requestUpdateWallpaperIfNeeded(); |
| 398 | |
| 399 | if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, "No longer Stopped: " + wtoken); |
| 400 | wtoken.mAppStopped = false; |
Jorim Jaggi | 60f9c97 | 2018-02-01 19:21:07 +0100 | [diff] [blame] | 401 | |
| 402 | mContainer.transferStartingWindowFromHiddenAboveTokenIfNeeded(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | // If we are preparing an app transition, then delay changing |
| 406 | // the visibility of this token until we execute that transition. |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 407 | if (wtoken.okToAnimate() && mService.mAppTransition.isTransitionSet()) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 408 | wtoken.inPendingTransaction = true; |
| 409 | if (visible) { |
| 410 | mService.mOpeningApps.add(wtoken); |
| 411 | wtoken.mEnteringAnimation = true; |
| 412 | } else { |
| 413 | mService.mClosingApps.add(wtoken); |
| 414 | wtoken.mEnteringAnimation = false; |
| 415 | } |
| 416 | if (mService.mAppTransition.getAppTransition() |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 417 | == WindowManager.TRANSIT_TASK_OPEN_BEHIND) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 418 | // We're launchingBehind, add the launching activity to mOpeningApps. |
| 419 | final WindowState win = |
| 420 | mService.getDefaultDisplayContentLocked().findFocusedWindow(); |
| 421 | if (win != null) { |
| 422 | final AppWindowToken focusedToken = win.mAppToken; |
| 423 | if (focusedToken != null) { |
| 424 | if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "TRANSIT_TASK_OPEN_BEHIND, " |
| 425 | + " adding " + focusedToken + " to mOpeningApps"); |
| 426 | // Force animation to be loaded. |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 427 | focusedToken.setHidden(true); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 428 | mService.mOpeningApps.add(focusedToken); |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | return; |
| 433 | } |
| 434 | |
| 435 | wtoken.setVisibility(null, visible, TRANSIT_UNSET, true, wtoken.mVoiceInteraction); |
| 436 | wtoken.updateReportedVisibilityLocked(); |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | /** |
| 441 | * Notifies that we launched an app that might be visible or not visible depending on what kind |
| 442 | * of Keyguard flags it's going to set on its windows. |
| 443 | */ |
| 444 | public void notifyUnknownVisibilityLaunched() { |
| 445 | synchronized(mWindowMap) { |
| 446 | if (mContainer != null) { |
| 447 | mService.mUnknownAppVisibilityController.notifyLaunched(mContainer); |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | public boolean addStartingWindow(String pkg, int theme, CompatibilityInfo compatInfo, |
| 453 | CharSequence nonLocalizedLabel, int labelRes, int icon, int logo, int windowFlags, |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 454 | IBinder transferFrom, boolean newTask, boolean taskSwitch, boolean processRunning, |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 455 | boolean allowTaskSnapshot, boolean activityCreated, boolean fromRecents) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 456 | synchronized(mWindowMap) { |
| 457 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "setAppStartingWindow: token=" + mToken |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 458 | + " pkg=" + pkg + " transferFrom=" + transferFrom + " newTask=" + newTask |
| 459 | + " taskSwitch=" + taskSwitch + " processRunning=" + processRunning |
| 460 | + " allowTaskSnapshot=" + allowTaskSnapshot); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 461 | |
| 462 | if (mContainer == null) { |
| 463 | Slog.w(TAG_WM, "Attempted to set icon of non-existing app token: " + mToken); |
| 464 | return false; |
| 465 | } |
| 466 | |
| 467 | // If the display is frozen, we won't do anything until the actual window is |
| 468 | // displayed so there is no reason to put in the starting window. |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 469 | if (!mContainer.okToDisplay()) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 470 | return false; |
| 471 | } |
| 472 | |
| 473 | if (mContainer.startingData != null) { |
| 474 | return false; |
| 475 | } |
| 476 | |
Wale Ogunwale | 4ba3e83 | 2017-04-20 16:45:13 -0700 | [diff] [blame] | 477 | final WindowState mainWin = mContainer.findMainWindow(); |
Jorim Jaggi | e6b1b3b | 2017-07-24 16:44:18 +0200 | [diff] [blame] | 478 | if (mainWin != null && mainWin.mWinAnimator.getShown()) { |
| 479 | // App already has a visible window...why would you want a starting window? |
Wale Ogunwale | 4ba3e83 | 2017-04-20 16:45:13 -0700 | [diff] [blame] | 480 | return false; |
| 481 | } |
| 482 | |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 483 | final TaskSnapshot snapshot = mService.mTaskSnapshotController.getSnapshot( |
| 484 | mContainer.getTask().mTaskId, mContainer.getTask().mUserId, |
| 485 | false /* restoreFromDisk */, false /* reducedResolution */); |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 486 | final int type = getStartingWindowType(newTask, taskSwitch, processRunning, |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 487 | allowTaskSnapshot, activityCreated, fromRecents, snapshot); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 488 | |
| 489 | if (type == STARTING_WINDOW_TYPE_SNAPSHOT) { |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 490 | return createSnapshot(snapshot); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 491 | } |
| 492 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 493 | // If this is a translucent window, then don't show a starting window -- the current |
| 494 | // effect (a full-screen opaque starting window that fades away to the real contents |
| 495 | // when it is ready) does not work for this. |
| 496 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Checking theme of starting window: 0x" |
| 497 | + Integer.toHexString(theme)); |
| 498 | if (theme != 0) { |
| 499 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 500 | com.android.internal.R.styleable.Window, mService.mCurrentUserId); |
| 501 | if (ent == null) { |
| 502 | // Whoops! App doesn't exist. Um. Okay. We'll just pretend like we didn't |
| 503 | // see that. |
| 504 | return false; |
| 505 | } |
| 506 | final boolean windowIsTranslucent = ent.array.getBoolean( |
| 507 | com.android.internal.R.styleable.Window_windowIsTranslucent, false); |
| 508 | final boolean windowIsFloating = ent.array.getBoolean( |
| 509 | com.android.internal.R.styleable.Window_windowIsFloating, false); |
| 510 | final boolean windowShowWallpaper = ent.array.getBoolean( |
| 511 | com.android.internal.R.styleable.Window_windowShowWallpaper, false); |
| 512 | final boolean windowDisableStarting = ent.array.getBoolean( |
| 513 | com.android.internal.R.styleable.Window_windowDisablePreview, false); |
| 514 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Translucent=" + windowIsTranslucent |
| 515 | + " Floating=" + windowIsFloating |
| 516 | + " ShowWallpaper=" + windowShowWallpaper); |
| 517 | if (windowIsTranslucent) { |
| 518 | return false; |
| 519 | } |
| 520 | if (windowIsFloating || windowDisableStarting) { |
| 521 | return false; |
| 522 | } |
| 523 | if (windowShowWallpaper) { |
| 524 | if (mContainer.getDisplayContent().mWallpaperController.getWallpaperTarget() |
| 525 | == null) { |
| 526 | // If this theme is requesting a wallpaper, and the wallpaper |
| 527 | // is not currently visible, then this effectively serves as |
| 528 | // an opaque window and our starting window transition animation |
| 529 | // can still work. We just need to make sure the starting window |
| 530 | // is also showing the wallpaper. |
| 531 | windowFlags |= FLAG_SHOW_WALLPAPER; |
| 532 | } else { |
| 533 | return false; |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | if (mContainer.transferStartingWindow(transferFrom)) { |
| 539 | return true; |
| 540 | } |
| 541 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 542 | // There is no existing starting window, and we don't want to create a splash screen, so |
| 543 | // that's it! |
| 544 | if (type != STARTING_WINDOW_TYPE_SPLASH_SCREEN) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 545 | return false; |
| 546 | } |
| 547 | |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 548 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Creating SplashScreenStartingData"); |
Jorim Jaggi | e09fc6b | 2017-01-19 15:33:36 +0100 | [diff] [blame] | 549 | mContainer.startingData = new SplashScreenStartingData(mService, pkg, theme, |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 550 | compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags, |
| 551 | mContainer.getMergedOverrideConfiguration()); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 552 | scheduleAddStartingWindow(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 553 | } |
| 554 | return true; |
| 555 | } |
| 556 | |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 557 | private int getStartingWindowType(boolean newTask, boolean taskSwitch, boolean processRunning, |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 558 | boolean allowTaskSnapshot, boolean activityCreated, boolean fromRecents, |
| 559 | TaskSnapshot snapshot) { |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 560 | if (mService.mAppTransition.getAppTransition() == TRANSIT_DOCK_TASK_FROM_RECENTS) { |
| 561 | // TODO(b/34099271): Remove this statement to add back the starting window and figure |
| 562 | // out why it causes flickering, the starting window appears over the thumbnail while |
| 563 | // the docked from recents transition occurs |
| 564 | return STARTING_WINDOW_TYPE_NONE; |
| 565 | } else if (newTask || !processRunning || (taskSwitch && !activityCreated)) { |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 566 | return STARTING_WINDOW_TYPE_SPLASH_SCREEN; |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 567 | } else if (taskSwitch && allowTaskSnapshot) { |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 568 | return snapshot == null ? STARTING_WINDOW_TYPE_NONE |
Jorim Jaggi | 1dda7a6 | 2017-06-28 14:40:27 -0400 | [diff] [blame] | 569 | : snapshotOrientationSameAsTask(snapshot) || fromRecents |
Wale Ogunwale | dfb7fb2 | 2017-06-23 14:52:40 -0700 | [diff] [blame] | 570 | ? STARTING_WINDOW_TYPE_SNAPSHOT : STARTING_WINDOW_TYPE_SPLASH_SCREEN; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 571 | } else { |
| 572 | return STARTING_WINDOW_TYPE_NONE; |
| 573 | } |
| 574 | } |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 575 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 576 | void scheduleAddStartingWindow() { |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 577 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 578 | // want to process the message ASAP, before any other queued |
| 579 | // messages. |
Jorim Jaggi | d8665f2 | 2018-04-10 00:34:24 +0200 | [diff] [blame] | 580 | if (!mService.mAnimationHandler.hasCallbacks(mAddStartingWindow)) { |
| 581 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Enqueueing ADD_STARTING"); |
| 582 | mService.mAnimationHandler.postAtFrontOfQueue(mAddStartingWindow); |
| 583 | } |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 584 | } |
| 585 | |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 586 | private boolean createSnapshot(TaskSnapshot snapshot) { |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 587 | if (snapshot == null) { |
| 588 | return false; |
| 589 | } |
| 590 | |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 591 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Creating SnapshotStartingData"); |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 592 | mContainer.startingData = new SnapshotStartingData(mService, snapshot); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 593 | scheduleAddStartingWindow(); |
| 594 | return true; |
| 595 | } |
| 596 | |
Jorim Jaggi | 1dda7a6 | 2017-06-28 14:40:27 -0400 | [diff] [blame] | 597 | private boolean snapshotOrientationSameAsTask(TaskSnapshot snapshot) { |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 598 | if (snapshot == null) { |
| 599 | return false; |
| 600 | } |
Jorim Jaggi | 1dda7a6 | 2017-06-28 14:40:27 -0400 | [diff] [blame] | 601 | return mContainer.getTask().getConfiguration().orientation == snapshot.getOrientation(); |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Jorim Jaggi | 19be605 | 2017-08-03 18:33:43 +0200 | [diff] [blame] | 604 | public void removeStartingWindow() { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 605 | synchronized (mWindowMap) { |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 606 | if (mContainer.startingWindow == null) { |
| 607 | if (mContainer.startingData != null) { |
| 608 | // Starting window has not been added yet, but it is scheduled to be added. |
| 609 | // Go ahead and cancel the request. |
| 610 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, |
| 611 | "Clearing startingData for token=" + mContainer); |
| 612 | mContainer.startingData = null; |
| 613 | } |
| 614 | return; |
| 615 | } |
| 616 | |
Seigo Nonaka | 82871bd | 2017-07-17 20:22:44 -0700 | [diff] [blame] | 617 | final StartingSurface surface; |
| 618 | if (mContainer.startingData != null) { |
| 619 | surface = mContainer.startingSurface; |
| 620 | mContainer.startingData = null; |
| 621 | mContainer.startingSurface = null; |
| 622 | mContainer.startingWindow = null; |
| 623 | mContainer.startingDisplayed = false; |
Seigo Nonaka | eafe737 | 2017-08-16 12:39:49 -0700 | [diff] [blame] | 624 | if (surface == null) { |
| 625 | if (DEBUG_STARTING_WINDOW) { |
| 626 | Slog.v(TAG_WM, "startingWindow was set but startingSurface==null, couldn't " |
| 627 | + "remove"); |
| 628 | } |
| 629 | return; |
Seigo Nonaka | 82871bd | 2017-07-17 20:22:44 -0700 | [diff] [blame] | 630 | } |
| 631 | } else { |
| 632 | if (DEBUG_STARTING_WINDOW) { |
| 633 | Slog.v(TAG_WM, "Tried to remove starting window but startingWindow was null:" |
| 634 | + mContainer); |
| 635 | } |
| 636 | return; |
| 637 | } |
| 638 | |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 639 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Schedule remove starting " + mContainer |
Seigo Nonaka | 82871bd | 2017-07-17 20:22:44 -0700 | [diff] [blame] | 640 | + " startingWindow=" + mContainer.startingWindow |
Jorim Jaggi | 77d0f36c | 2018-03-16 17:49:49 +0100 | [diff] [blame] | 641 | + " startingView=" + mContainer.startingSurface |
| 642 | + " Callers=" + Debug.getCallers(5)); |
Jorim Jaggi | a338219 | 2017-07-18 14:33:21 +0200 | [diff] [blame] | 643 | |
| 644 | // Use the same thread to remove the window as we used to add it, as otherwise we end up |
| 645 | // with things in the view hierarchy being called from different threads. |
Jorim Jaggi | 8829cf1 | 2017-09-05 12:28:52 +0200 | [diff] [blame] | 646 | mService.mAnimationHandler.post(() -> { |
Seigo Nonaka | 82871bd | 2017-07-17 20:22:44 -0700 | [diff] [blame] | 647 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Removing startingView=" + surface); |
| 648 | try { |
| 649 | surface.remove(); |
| 650 | } catch (Exception e) { |
| 651 | Slog.w(TAG_WM, "Exception when removing starting window", e); |
| 652 | } |
| 653 | }); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 654 | } |
| 655 | } |
| 656 | |
| 657 | public void pauseKeyDispatching() { |
| 658 | synchronized (mWindowMap) { |
| 659 | if (mContainer != null) { |
| 660 | mService.mInputMonitor.pauseDispatchingLw(mContainer); |
| 661 | } |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | public void resumeKeyDispatching() { |
| 666 | synchronized (mWindowMap) { |
| 667 | if (mContainer != null) { |
| 668 | mService.mInputMonitor.resumeDispatchingLw(mContainer); |
| 669 | } |
| 670 | } |
| 671 | } |
| 672 | |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 673 | public void notifyAppResumed(boolean wasStopped) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 674 | synchronized(mWindowMap) { |
| 675 | if (mContainer == null) { |
| 676 | Slog.w(TAG_WM, "Attempted to notify resumed of non-existing app token: " + mToken); |
| 677 | return; |
| 678 | } |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 679 | mContainer.notifyAppResumed(wasStopped); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | |
Robert Carr | 29daa92 | 2018-04-27 11:56:48 -0700 | [diff] [blame] | 683 | public void notifyAppStopping() { |
| 684 | synchronized(mWindowMap) { |
| 685 | if (mContainer == null) { |
| 686 | Slog.w(TAG_WM, "Attempted to notify stopping on non-existing app token: " |
| 687 | + mToken); |
| 688 | return; |
| 689 | } |
| 690 | mContainer.detachChildren(); |
| 691 | } |
| 692 | } |
| 693 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 694 | public void notifyAppStopped() { |
| 695 | synchronized(mWindowMap) { |
| 696 | if (mContainer == null) { |
| 697 | Slog.w(TAG_WM, "Attempted to notify stopped of non-existing app token: " |
| 698 | + mToken); |
| 699 | return; |
| 700 | } |
| 701 | mContainer.notifyAppStopped(); |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | public void startFreezingScreen(int configChanges) { |
| 706 | synchronized(mWindowMap) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 707 | if (mContainer == null) { |
| 708 | Slog.w(TAG_WM, |
| 709 | "Attempted to freeze screen with non-existing app token: " + mContainer); |
| 710 | return; |
| 711 | } |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 712 | |
| 713 | if (configChanges == 0 && mContainer.okToDisplay()) { |
| 714 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Skipping set freeze of " + mToken); |
| 715 | return; |
| 716 | } |
| 717 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 718 | mContainer.startFreezingScreen(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | |
| 722 | public void stopFreezingScreen(boolean force) { |
| 723 | synchronized(mWindowMap) { |
| 724 | if (mContainer == null) { |
| 725 | return; |
| 726 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 727 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + mToken + ": hidden=" |
Jorim Jaggi | b0fc817 | 2017-11-23 17:04:08 +0000 | [diff] [blame] | 728 | + mContainer.isHidden() + " freezing=" + mContainer.isFreezingScreen()); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 729 | mContainer.stopFreezingScreen(true, force); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 730 | } |
| 731 | } |
| 732 | |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 733 | public void registerRemoteAnimations(RemoteAnimationDefinition definition) { |
| 734 | synchronized (mWindowMap) { |
| 735 | if (mContainer == null) { |
| 736 | Slog.w(TAG_WM, "Attempted to register remote animations with non-existing app" |
| 737 | + " token: " + mToken); |
| 738 | return; |
| 739 | } |
| 740 | mContainer.registerRemoteAnimations(definition); |
| 741 | } |
| 742 | } |
| 743 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 744 | void reportStartingWindowDrawn() { |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 745 | mHandler.sendMessage(mHandler.obtainMessage(H.NOTIFY_STARTING_WINDOW_DRAWN)); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 746 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 747 | |
| 748 | void reportWindowsDrawn() { |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 749 | mHandler.sendMessage(mHandler.obtainMessage(H.NOTIFY_WINDOWS_DRAWN)); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 750 | } |
| 751 | |
Vishnu Nair | c1d2ff6 | 2018-11-08 16:50:12 -0800 | [diff] [blame] | 752 | void reportWindowsNotDrawn() { |
| 753 | mHandler.sendMessage(mHandler.obtainMessage(H.NOTIFY_WINDOWS_NOTDRAWN)); |
| 754 | } |
| 755 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 756 | void reportWindowsVisible() { |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 757 | mHandler.post(mOnWindowsVisible); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | void reportWindowsGone() { |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 761 | mHandler.post(mOnWindowsGone); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | /** Calls directly into activity manager so window manager lock shouldn't held. */ |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 765 | boolean keyDispatchingTimedOut(String reason, int windowPid) { |
| 766 | return mListener != null && mListener.keyDispatchingTimedOut(reason, windowPid); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 767 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 768 | |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 769 | /** |
| 770 | * Notifies AWT that this app is waiting to pause in order to determine if it will enter PIP. |
| 771 | * This information helps AWT know that the app is in the process of pausing before it gets the |
| 772 | * signal on the WM side. |
| 773 | */ |
| 774 | public void setWillCloseOrEnterPip(boolean willCloseOrEnterPip) { |
| 775 | synchronized (mWindowMap) { |
| 776 | if (mContainer == null) { |
| 777 | return; |
| 778 | } |
| 779 | |
| 780 | mContainer.setWillCloseOrEnterPip(willCloseOrEnterPip); |
| 781 | } |
| 782 | } |
| 783 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 784 | @Override |
| 785 | public String toString() { |
Wale Ogunwale | 9c64cb6 | 2017-04-12 13:39:59 -0700 | [diff] [blame] | 786 | return "AppWindowContainerController{" |
| 787 | + " token=" + mToken |
| 788 | + " mContainer=" + mContainer |
| 789 | + " mListener=" + mListener |
| 790 | + "}"; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 791 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 792 | } |