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