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