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; |
| 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; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame^] | 51 | import com.android.server.policy.WindowManagerPolicy.StartingSurface; |
| 52 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 53 | /** |
| 54 | * Controller for the app window token container. This is created by activity manager to link |
| 55 | * activity records to the app window token container they use in window manager. |
| 56 | * |
| 57 | * Test class: {@link AppWindowContainerControllerTests} |
| 58 | */ |
| 59 | public class AppWindowContainerController |
| 60 | extends WindowContainerController<AppWindowToken, AppWindowContainerListener> { |
| 61 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 62 | private static final int STARTING_WINDOW_TYPE_NONE = 0; |
| 63 | private static final int STARTING_WINDOW_TYPE_SNAPSHOT = 1; |
| 64 | private static final int STARTING_WINDOW_TYPE_SPLASH_SCREEN = 2; |
| 65 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 66 | private final IApplicationToken mToken; |
Jorim Jaggi | 9bafc71 | 2017-01-19 17:28:30 +0100 | [diff] [blame] | 67 | private final Handler mHandler; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 68 | |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 69 | private final class H extends Handler { |
| 70 | public static final int NOTIFY_WINDOWS_DRAWN = 1; |
| 71 | public static final int NOTIFY_STARTING_WINDOW_DRAWN = 2; |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 72 | |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 73 | public H(Looper looper) { |
| 74 | super(looper); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 75 | } |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 76 | |
| 77 | @Override |
| 78 | public void handleMessage(Message msg) { |
| 79 | switch (msg.what) { |
| 80 | case NOTIFY_WINDOWS_DRAWN: |
| 81 | if (mListener == null) { |
| 82 | return; |
| 83 | } |
| 84 | if (DEBUG_VISIBILITY) Slog.v(TAG_WM, "Reporting drawn in " |
| 85 | + AppWindowContainerController.this.mToken); |
| 86 | mListener.onWindowsDrawn(msg.getWhen()); |
| 87 | break; |
| 88 | case NOTIFY_STARTING_WINDOW_DRAWN: |
| 89 | if (mListener == null) { |
| 90 | return; |
| 91 | } |
| 92 | if (DEBUG_VISIBILITY) Slog.v(TAG_WM, "Reporting drawn in " |
| 93 | + AppWindowContainerController.this.mToken); |
| 94 | mListener.onStartingWindowDrawn(msg.getWhen()); |
| 95 | break; |
| 96 | default: |
| 97 | break; |
| 98 | } |
| 99 | } |
| 100 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 101 | |
| 102 | private final Runnable mOnWindowsVisible = () -> { |
| 103 | if (mListener == null) { |
| 104 | return; |
| 105 | } |
| 106 | if (DEBUG_VISIBILITY) Slog.v(TAG_WM, "Reporting visible in " |
| 107 | + AppWindowContainerController.this.mToken); |
| 108 | mListener.onWindowsVisible(); |
| 109 | }; |
| 110 | |
| 111 | private final Runnable mOnWindowsGone = () -> { |
| 112 | if (mListener == null) { |
| 113 | return; |
| 114 | } |
| 115 | if (DEBUG_VISIBILITY) Slog.v(TAG_WM, "Reporting gone in " |
| 116 | + AppWindowContainerController.this.mToken); |
| 117 | mListener.onWindowsGone(); |
| 118 | }; |
| 119 | |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 120 | private final Runnable mAddStartingWindow = () -> { |
| 121 | final StartingData startingData; |
Jorim Jaggi | e09fc6b | 2017-01-19 15:33:36 +0100 | [diff] [blame] | 122 | final AppWindowToken container; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 123 | |
| 124 | synchronized (mWindowMap) { |
Jorim Jaggi | 73f8820 | 2017-01-12 13:54:40 +0100 | [diff] [blame] | 125 | if (mContainer == null) { |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 126 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "mContainer was null while trying to" |
| 127 | + " add starting window"); |
Jorim Jaggi | 73f8820 | 2017-01-12 13:54:40 +0100 | [diff] [blame] | 128 | return; |
| 129 | } |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 130 | startingData = mContainer.startingData; |
Jorim Jaggi | e09fc6b | 2017-01-19 15:33:36 +0100 | [diff] [blame] | 131 | container = mContainer; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | if (startingData == null) { |
| 135 | // Animation has been canceled... do nothing. |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 136 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "startingData was nulled out before handling" |
| 137 | + " mAddStartingWindow: " + mContainer); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 138 | return; |
| 139 | } |
| 140 | |
| 141 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Add starting " |
Jorim Jaggi | e09fc6b | 2017-01-19 15:33:36 +0100 | [diff] [blame] | 142 | + this + ": startingData=" + container.startingData); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 143 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 144 | StartingSurface surface = null; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 145 | try { |
Jorim Jaggi | e09fc6b | 2017-01-19 15:33:36 +0100 | [diff] [blame] | 146 | surface = startingData.createStartingSurface(container); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 147 | } catch (Exception e) { |
| 148 | Slog.w(TAG_WM, "Exception when adding starting window", e); |
| 149 | } |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 150 | if (surface != null) { |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 151 | boolean abort = false; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 152 | synchronized(mWindowMap) { |
Jorim Jaggi | cfeff74 | 2017-05-23 18:00:48 +0200 | [diff] [blame] | 153 | // If the window was successfully added, then |
| 154 | // we need to remove it. |
Jorim Jaggi | e09fc6b | 2017-01-19 15:33:36 +0100 | [diff] [blame] | 155 | if (container.removed || container.startingData == null) { |
Jorim Jaggi | cfeff74 | 2017-05-23 18:00:48 +0200 | [diff] [blame] | 156 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, |
| 157 | "Aborted starting " + container |
| 158 | + ": removed=" + container.removed |
| 159 | + " startingData=" + container.startingData); |
| 160 | container.startingWindow = null; |
| 161 | container.startingData = null; |
| 162 | abort = true; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 163 | } else { |
Jorim Jaggi | e09fc6b | 2017-01-19 15:33:36 +0100 | [diff] [blame] | 164 | container.startingSurface = surface; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 165 | } |
| 166 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG_WM, |
| 167 | "Added starting " + mContainer |
| 168 | + ": startingWindow=" |
Jorim Jaggi | e09fc6b | 2017-01-19 15:33:36 +0100 | [diff] [blame] | 169 | + container.startingWindow + " startingView=" |
| 170 | + container.startingSurface); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 171 | } |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 172 | if (abort) { |
Jorim Jaggi | e09fc6b | 2017-01-19 15:33:36 +0100 | [diff] [blame] | 173 | surface.remove(); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 174 | } |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 175 | } else if (DEBUG_STARTING_WINDOW) { |
| 176 | Slog.v(TAG_WM, "Surface returned was null: " + mContainer); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 177 | } |
| 178 | }; |
| 179 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 180 | public AppWindowContainerController(TaskWindowContainerController taskController, |
| 181 | IApplicationToken token, AppWindowContainerListener listener, int index, |
| 182 | int requestedOrientation, boolean fullscreen, boolean showForAllUsers, int configChanges, |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 183 | boolean voiceInteraction, boolean launchTaskBehind, boolean alwaysFocusable, |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 184 | int targetSdkVersion, int rotationAnimationHint, long inputDispatchingTimeoutNanos, |
Wale Ogunwale | 034a8ec | 2017-09-02 17:14:40 -0700 | [diff] [blame] | 185 | Rect bounds) { |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 186 | this(taskController, token, listener, index, requestedOrientation, fullscreen, |
| 187 | showForAllUsers, |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 188 | configChanges, voiceInteraction, launchTaskBehind, alwaysFocusable, |
| 189 | targetSdkVersion, rotationAnimationHint, inputDispatchingTimeoutNanos, |
Wale Ogunwale | 034a8ec | 2017-09-02 17:14:40 -0700 | [diff] [blame] | 190 | WindowManagerService.getInstance(), bounds); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 191 | } |
| 192 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 193 | public AppWindowContainerController(TaskWindowContainerController taskController, |
| 194 | IApplicationToken token, AppWindowContainerListener listener, int index, |
| 195 | int requestedOrientation, boolean fullscreen, boolean showForAllUsers, int configChanges, |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 196 | boolean voiceInteraction, boolean launchTaskBehind, boolean alwaysFocusable, |
| 197 | int targetSdkVersion, int rotationAnimationHint, long inputDispatchingTimeoutNanos, |
Wale Ogunwale | 034a8ec | 2017-09-02 17:14:40 -0700 | [diff] [blame] | 198 | WindowManagerService service, Rect bounds) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 199 | super(listener, service); |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 200 | mHandler = new H(service.mH.getLooper()); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 201 | mToken = token; |
| 202 | synchronized(mWindowMap) { |
| 203 | AppWindowToken atoken = mRoot.getAppWindowToken(mToken.asBinder()); |
| 204 | if (atoken != null) { |
| 205 | // TODO: Should this throw an exception instead? |
| 206 | Slog.w(TAG_WM, "Attempted to add existing app token: " + mToken); |
| 207 | return; |
| 208 | } |
| 209 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 210 | final Task task = taskController.mContainer; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 211 | if (task == null) { |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 212 | throw new IllegalArgumentException("AppWindowContainerController: invalid " |
| 213 | + " controller=" + taskController); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 214 | } |
| 215 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 216 | atoken = createAppWindow(mService, token, voiceInteraction, task.getDisplayContent(), |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 217 | inputDispatchingTimeoutNanos, fullscreen, showForAllUsers, targetSdkVersion, |
| 218 | requestedOrientation, rotationAnimationHint, configChanges, launchTaskBehind, |
Wale Ogunwale | 034a8ec | 2017-09-02 17:14:40 -0700 | [diff] [blame] | 219 | alwaysFocusable, this, bounds); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 220 | 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] | 221 | + " controller=" + taskController + " at " + index); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 222 | task.addChild(atoken, index); |
| 223 | } |
| 224 | } |
| 225 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 226 | @VisibleForTesting |
| 227 | AppWindowToken createAppWindow(WindowManagerService service, IApplicationToken token, |
| 228 | boolean voiceInteraction, DisplayContent dc, long inputDispatchingTimeoutNanos, |
| 229 | boolean fullscreen, boolean showForAllUsers, int targetSdk, int orientation, |
| 230 | int rotationAnimationHint, int configChanges, boolean launchTaskBehind, |
Wale Ogunwale | 034a8ec | 2017-09-02 17:14:40 -0700 | [diff] [blame] | 231 | boolean alwaysFocusable, AppWindowContainerController controller, 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 | 034a8ec | 2017-09-02 17:14:40 -0700 | [diff] [blame] | 235 | controller, 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(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 368 | } else { |
| 369 | if (!mService.mAppTransition.isTransitionSet() |
| 370 | && mService.mAppTransition.isReady()) { |
| 371 | // Add the app mOpeningApps if transition is unset but ready. This means |
| 372 | // we're doing a screen freeze, and the unfreeze will wait for all opening |
| 373 | // apps to be ready. |
| 374 | mService.mOpeningApps.add(wtoken); |
| 375 | } |
| 376 | wtoken.startingMoved = false; |
| 377 | // If the token is currently hidden (should be the common case), or has been |
| 378 | // stopped, then we need to set up to wait for its windows to be ready. |
| 379 | if (wtoken.hidden || wtoken.mAppStopped) { |
| 380 | wtoken.clearAllDrawn(); |
| 381 | |
| 382 | // If the app was already visible, don't reset the waitingToShow state. |
| 383 | if (wtoken.hidden) { |
| 384 | wtoken.waitingToShow = true; |
| 385 | } |
| 386 | |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 387 | if (wtoken.isClientHidden()) { |
| 388 | // In the case where we are making an app visible but holding off for a |
| 389 | // transition, we still need to tell the client to make its windows visible |
| 390 | // so they get drawn. Otherwise, we will wait on performing the transition |
| 391 | // until all windows have been drawn, they never will be, and we are sad. |
| 392 | wtoken.setClientHidden(false); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | wtoken.requestUpdateWallpaperIfNeeded(); |
| 396 | |
| 397 | if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, "No longer Stopped: " + wtoken); |
| 398 | wtoken.mAppStopped = false; |
| 399 | } |
| 400 | |
| 401 | // If we are preparing an app transition, then delay changing |
| 402 | // the visibility of this token until we execute that transition. |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 403 | if (wtoken.okToAnimate() && mService.mAppTransition.isTransitionSet()) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 404 | // A dummy animation is a placeholder animation which informs others that an |
| 405 | // animation is going on (in this case an application transition). If the animation |
| 406 | // was transferred from another application/animator, no dummy animator should be |
| 407 | // created since an animation is already in progress. |
| 408 | if (wtoken.mAppAnimator.usingTransferredAnimation |
| 409 | && wtoken.mAppAnimator.animation == null) { |
| 410 | Slog.wtf(TAG_WM, "Will NOT set dummy animation on: " + wtoken |
| 411 | + ", using null transferred animation!"); |
| 412 | } |
| 413 | if (!wtoken.mAppAnimator.usingTransferredAnimation && |
| 414 | (!wtoken.startingDisplayed || mService.mSkipAppTransitionAnimation)) { |
| 415 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| 416 | TAG_WM, "Setting dummy animation on: " + wtoken); |
| 417 | wtoken.mAppAnimator.setDummyAnimation(); |
| 418 | } |
| 419 | wtoken.inPendingTransaction = true; |
| 420 | if (visible) { |
| 421 | mService.mOpeningApps.add(wtoken); |
| 422 | wtoken.mEnteringAnimation = true; |
| 423 | } else { |
| 424 | mService.mClosingApps.add(wtoken); |
| 425 | wtoken.mEnteringAnimation = false; |
| 426 | } |
| 427 | if (mService.mAppTransition.getAppTransition() |
| 428 | == AppTransition.TRANSIT_TASK_OPEN_BEHIND) { |
| 429 | // We're launchingBehind, add the launching activity to mOpeningApps. |
| 430 | final WindowState win = |
| 431 | mService.getDefaultDisplayContentLocked().findFocusedWindow(); |
| 432 | if (win != null) { |
| 433 | final AppWindowToken focusedToken = win.mAppToken; |
| 434 | if (focusedToken != null) { |
| 435 | if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "TRANSIT_TASK_OPEN_BEHIND, " |
| 436 | + " adding " + focusedToken + " to mOpeningApps"); |
| 437 | // Force animation to be loaded. |
| 438 | focusedToken.hidden = true; |
| 439 | mService.mOpeningApps.add(focusedToken); |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | return; |
| 444 | } |
| 445 | |
| 446 | wtoken.setVisibility(null, visible, TRANSIT_UNSET, true, wtoken.mVoiceInteraction); |
| 447 | wtoken.updateReportedVisibilityLocked(); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | /** |
| 452 | * Notifies that we launched an app that might be visible or not visible depending on what kind |
| 453 | * of Keyguard flags it's going to set on its windows. |
| 454 | */ |
| 455 | public void notifyUnknownVisibilityLaunched() { |
| 456 | synchronized(mWindowMap) { |
| 457 | if (mContainer != null) { |
| 458 | mService.mUnknownAppVisibilityController.notifyLaunched(mContainer); |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | public boolean addStartingWindow(String pkg, int theme, CompatibilityInfo compatInfo, |
| 464 | CharSequence nonLocalizedLabel, int labelRes, int icon, int logo, int windowFlags, |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 465 | IBinder transferFrom, boolean newTask, boolean taskSwitch, boolean processRunning, |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 466 | boolean allowTaskSnapshot, boolean activityCreated, boolean fromRecents) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 467 | synchronized(mWindowMap) { |
| 468 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "setAppStartingWindow: token=" + mToken |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 469 | + " pkg=" + pkg + " transferFrom=" + transferFrom + " newTask=" + newTask |
| 470 | + " taskSwitch=" + taskSwitch + " processRunning=" + processRunning |
| 471 | + " allowTaskSnapshot=" + allowTaskSnapshot); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 472 | |
| 473 | if (mContainer == null) { |
| 474 | Slog.w(TAG_WM, "Attempted to set icon of non-existing app token: " + mToken); |
| 475 | return false; |
| 476 | } |
| 477 | |
| 478 | // If the display is frozen, we won't do anything until the actual window is |
| 479 | // displayed so there is no reason to put in the starting window. |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 480 | if (!mContainer.okToDisplay()) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 481 | return false; |
| 482 | } |
| 483 | |
| 484 | if (mContainer.startingData != null) { |
| 485 | return false; |
| 486 | } |
| 487 | |
Wale Ogunwale | 4ba3e83 | 2017-04-20 16:45:13 -0700 | [diff] [blame] | 488 | final WindowState mainWin = mContainer.findMainWindow(); |
Jorim Jaggi | e6b1b3b | 2017-07-24 16:44:18 +0200 | [diff] [blame] | 489 | if (mainWin != null && mainWin.mWinAnimator.getShown()) { |
| 490 | // 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] | 491 | return false; |
| 492 | } |
| 493 | |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 494 | final TaskSnapshot snapshot = mService.mTaskSnapshotController.getSnapshot( |
| 495 | mContainer.getTask().mTaskId, mContainer.getTask().mUserId, |
| 496 | false /* restoreFromDisk */, false /* reducedResolution */); |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 497 | final int type = getStartingWindowType(newTask, taskSwitch, processRunning, |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 498 | allowTaskSnapshot, activityCreated, fromRecents, snapshot); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 499 | |
| 500 | if (type == STARTING_WINDOW_TYPE_SNAPSHOT) { |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 501 | return createSnapshot(snapshot); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 502 | } |
| 503 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 504 | // If this is a translucent window, then don't show a starting window -- the current |
| 505 | // effect (a full-screen opaque starting window that fades away to the real contents |
| 506 | // when it is ready) does not work for this. |
| 507 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Checking theme of starting window: 0x" |
| 508 | + Integer.toHexString(theme)); |
| 509 | if (theme != 0) { |
| 510 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 511 | com.android.internal.R.styleable.Window, mService.mCurrentUserId); |
| 512 | if (ent == null) { |
| 513 | // Whoops! App doesn't exist. Um. Okay. We'll just pretend like we didn't |
| 514 | // see that. |
| 515 | return false; |
| 516 | } |
| 517 | final boolean windowIsTranslucent = ent.array.getBoolean( |
| 518 | com.android.internal.R.styleable.Window_windowIsTranslucent, false); |
| 519 | final boolean windowIsFloating = ent.array.getBoolean( |
| 520 | com.android.internal.R.styleable.Window_windowIsFloating, false); |
| 521 | final boolean windowShowWallpaper = ent.array.getBoolean( |
| 522 | com.android.internal.R.styleable.Window_windowShowWallpaper, false); |
| 523 | final boolean windowDisableStarting = ent.array.getBoolean( |
| 524 | com.android.internal.R.styleable.Window_windowDisablePreview, false); |
| 525 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Translucent=" + windowIsTranslucent |
| 526 | + " Floating=" + windowIsFloating |
| 527 | + " ShowWallpaper=" + windowShowWallpaper); |
| 528 | if (windowIsTranslucent) { |
| 529 | return false; |
| 530 | } |
| 531 | if (windowIsFloating || windowDisableStarting) { |
| 532 | return false; |
| 533 | } |
| 534 | if (windowShowWallpaper) { |
| 535 | if (mContainer.getDisplayContent().mWallpaperController.getWallpaperTarget() |
| 536 | == null) { |
| 537 | // If this theme is requesting a wallpaper, and the wallpaper |
| 538 | // is not currently visible, then this effectively serves as |
| 539 | // an opaque window and our starting window transition animation |
| 540 | // can still work. We just need to make sure the starting window |
| 541 | // is also showing the wallpaper. |
| 542 | windowFlags |= FLAG_SHOW_WALLPAPER; |
| 543 | } else { |
| 544 | return false; |
| 545 | } |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | if (mContainer.transferStartingWindow(transferFrom)) { |
| 550 | return true; |
| 551 | } |
| 552 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 553 | // There is no existing starting window, and we don't want to create a splash screen, so |
| 554 | // that's it! |
| 555 | if (type != STARTING_WINDOW_TYPE_SPLASH_SCREEN) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 556 | return false; |
| 557 | } |
| 558 | |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 559 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Creating SplashScreenStartingData"); |
Jorim Jaggi | e09fc6b | 2017-01-19 15:33:36 +0100 | [diff] [blame] | 560 | mContainer.startingData = new SplashScreenStartingData(mService, pkg, theme, |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 561 | compatInfo, nonLocalizedLabel, labelRes, icon, logo, windowFlags, |
| 562 | mContainer.getMergedOverrideConfiguration()); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 563 | scheduleAddStartingWindow(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 564 | } |
| 565 | return true; |
| 566 | } |
| 567 | |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 568 | private int getStartingWindowType(boolean newTask, boolean taskSwitch, boolean processRunning, |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 569 | boolean allowTaskSnapshot, boolean activityCreated, boolean fromRecents, |
| 570 | TaskSnapshot snapshot) { |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 571 | if (mService.mAppTransition.getAppTransition() == TRANSIT_DOCK_TASK_FROM_RECENTS) { |
| 572 | // TODO(b/34099271): Remove this statement to add back the starting window and figure |
| 573 | // out why it causes flickering, the starting window appears over the thumbnail while |
| 574 | // the docked from recents transition occurs |
| 575 | return STARTING_WINDOW_TYPE_NONE; |
| 576 | } else if (newTask || !processRunning || (taskSwitch && !activityCreated)) { |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 577 | return STARTING_WINDOW_TYPE_SPLASH_SCREEN; |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 578 | } else if (taskSwitch && allowTaskSnapshot) { |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 579 | return snapshot == null ? STARTING_WINDOW_TYPE_NONE |
Jorim Jaggi | 1dda7a6 | 2017-06-28 14:40:27 -0400 | [diff] [blame] | 580 | : snapshotOrientationSameAsTask(snapshot) || fromRecents |
Wale Ogunwale | dfb7fb2 | 2017-06-23 14:52:40 -0700 | [diff] [blame] | 581 | ? STARTING_WINDOW_TYPE_SNAPSHOT : STARTING_WINDOW_TYPE_SPLASH_SCREEN; |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 582 | } else { |
| 583 | return STARTING_WINDOW_TYPE_NONE; |
| 584 | } |
| 585 | } |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 586 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 587 | void scheduleAddStartingWindow() { |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 588 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 589 | // want to process the message ASAP, before any other queued |
| 590 | // messages. |
| 591 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Enqueueing ADD_STARTING"); |
Jorim Jaggi | ed7993b | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 592 | mService.mAnimationHandler.postAtFrontOfQueue(mAddStartingWindow); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 593 | } |
| 594 | |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 595 | private boolean createSnapshot(TaskSnapshot snapshot) { |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 596 | if (snapshot == null) { |
| 597 | return false; |
| 598 | } |
| 599 | |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 600 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Creating SnapshotStartingData"); |
Jorim Jaggi | 30d64f3 | 2017-04-07 16:33:17 +0200 | [diff] [blame] | 601 | mContainer.startingData = new SnapshotStartingData(mService, snapshot); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 602 | scheduleAddStartingWindow(); |
| 603 | return true; |
| 604 | } |
| 605 | |
Jorim Jaggi | 1dda7a6 | 2017-06-28 14:40:27 -0400 | [diff] [blame] | 606 | private boolean snapshotOrientationSameAsTask(TaskSnapshot snapshot) { |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 607 | if (snapshot == null) { |
| 608 | return false; |
| 609 | } |
Jorim Jaggi | 1dda7a6 | 2017-06-28 14:40:27 -0400 | [diff] [blame] | 610 | return mContainer.getTask().getConfiguration().orientation == snapshot.getOrientation(); |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Jorim Jaggi | 19be605 | 2017-08-03 18:33:43 +0200 | [diff] [blame] | 613 | public void removeStartingWindow() { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 614 | synchronized (mWindowMap) { |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 615 | if (mContainer.startingWindow == null) { |
| 616 | if (mContainer.startingData != null) { |
| 617 | // Starting window has not been added yet, but it is scheduled to be added. |
| 618 | // Go ahead and cancel the request. |
| 619 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, |
| 620 | "Clearing startingData for token=" + mContainer); |
| 621 | mContainer.startingData = null; |
| 622 | } |
| 623 | return; |
| 624 | } |
| 625 | |
Seigo Nonaka | 82871bd | 2017-07-17 20:22:44 -0700 | [diff] [blame] | 626 | final StartingSurface surface; |
| 627 | if (mContainer.startingData != null) { |
| 628 | surface = mContainer.startingSurface; |
| 629 | mContainer.startingData = null; |
| 630 | mContainer.startingSurface = null; |
| 631 | mContainer.startingWindow = null; |
| 632 | mContainer.startingDisplayed = false; |
Seigo Nonaka | eafe737 | 2017-08-16 12:39:49 -0700 | [diff] [blame] | 633 | if (surface == null) { |
| 634 | if (DEBUG_STARTING_WINDOW) { |
| 635 | Slog.v(TAG_WM, "startingWindow was set but startingSurface==null, couldn't " |
| 636 | + "remove"); |
| 637 | } |
| 638 | return; |
Seigo Nonaka | 82871bd | 2017-07-17 20:22:44 -0700 | [diff] [blame] | 639 | } |
| 640 | } else { |
| 641 | if (DEBUG_STARTING_WINDOW) { |
| 642 | Slog.v(TAG_WM, "Tried to remove starting window but startingWindow was null:" |
| 643 | + mContainer); |
| 644 | } |
| 645 | return; |
| 646 | } |
| 647 | |
Jorim Jaggi | e4b0f28 | 2017-05-17 15:10:29 +0200 | [diff] [blame] | 648 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Schedule remove starting " + mContainer |
Seigo Nonaka | 82871bd | 2017-07-17 20:22:44 -0700 | [diff] [blame] | 649 | + " startingWindow=" + mContainer.startingWindow |
| 650 | + " startingView=" + mContainer.startingSurface); |
Jorim Jaggi | a338219 | 2017-07-18 14:33:21 +0200 | [diff] [blame] | 651 | |
| 652 | // Use the same thread to remove the window as we used to add it, as otherwise we end up |
| 653 | // with things in the view hierarchy being called from different threads. |
Jorim Jaggi | 8829cf1 | 2017-09-05 12:28:52 +0200 | [diff] [blame] | 654 | mService.mAnimationHandler.post(() -> { |
Seigo Nonaka | 82871bd | 2017-07-17 20:22:44 -0700 | [diff] [blame] | 655 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Removing startingView=" + surface); |
| 656 | try { |
| 657 | surface.remove(); |
| 658 | } catch (Exception e) { |
| 659 | Slog.w(TAG_WM, "Exception when removing starting window", e); |
| 660 | } |
| 661 | }); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | |
| 665 | public void pauseKeyDispatching() { |
| 666 | synchronized (mWindowMap) { |
| 667 | if (mContainer != null) { |
| 668 | mService.mInputMonitor.pauseDispatchingLw(mContainer); |
| 669 | } |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | public void resumeKeyDispatching() { |
| 674 | synchronized (mWindowMap) { |
| 675 | if (mContainer != null) { |
| 676 | mService.mInputMonitor.resumeDispatchingLw(mContainer); |
| 677 | } |
| 678 | } |
| 679 | } |
| 680 | |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 681 | public void notifyAppResumed(boolean wasStopped) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 682 | synchronized(mWindowMap) { |
| 683 | if (mContainer == null) { |
| 684 | Slog.w(TAG_WM, "Attempted to notify resumed of non-existing app token: " + mToken); |
| 685 | return; |
| 686 | } |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 687 | mContainer.notifyAppResumed(wasStopped); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | |
| 691 | public void notifyAppStopped() { |
| 692 | synchronized(mWindowMap) { |
| 693 | if (mContainer == null) { |
| 694 | Slog.w(TAG_WM, "Attempted to notify stopped of non-existing app token: " |
| 695 | + mToken); |
| 696 | return; |
| 697 | } |
| 698 | mContainer.notifyAppStopped(); |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | public void startFreezingScreen(int configChanges) { |
| 703 | synchronized(mWindowMap) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 704 | if (mContainer == null) { |
| 705 | Slog.w(TAG_WM, |
| 706 | "Attempted to freeze screen with non-existing app token: " + mContainer); |
| 707 | return; |
| 708 | } |
David Stevens | f62360c | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 709 | |
| 710 | if (configChanges == 0 && mContainer.okToDisplay()) { |
| 711 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Skipping set freeze of " + mToken); |
| 712 | return; |
| 713 | } |
| 714 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 715 | mContainer.startFreezingScreen(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | |
| 719 | public void stopFreezingScreen(boolean force) { |
| 720 | synchronized(mWindowMap) { |
| 721 | if (mContainer == null) { |
| 722 | return; |
| 723 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 724 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + mToken + ": hidden=" |
| 725 | + mContainer.hidden + " freezing=" + mContainer.mAppAnimator.freezingScreen); |
| 726 | mContainer.stopFreezingScreen(true, force); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 727 | } |
| 728 | } |
| 729 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 730 | void reportStartingWindowDrawn() { |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 731 | mHandler.sendMessage(mHandler.obtainMessage(H.NOTIFY_STARTING_WINDOW_DRAWN)); |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 732 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 733 | |
| 734 | void reportWindowsDrawn() { |
Sudheer Shanka | c766db0 | 2017-06-12 10:37:29 -0700 | [diff] [blame] | 735 | mHandler.sendMessage(mHandler.obtainMessage(H.NOTIFY_WINDOWS_DRAWN)); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | void reportWindowsVisible() { |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 739 | mHandler.post(mOnWindowsVisible); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | void reportWindowsGone() { |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 743 | mHandler.post(mOnWindowsGone); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | /** Calls directly into activity manager so window manager lock shouldn't held. */ |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 747 | boolean keyDispatchingTimedOut(String reason, int windowPid) { |
| 748 | return mListener != null && mListener.keyDispatchingTimedOut(reason, windowPid); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 749 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 750 | |
| 751 | @Override |
| 752 | public String toString() { |
Wale Ogunwale | 9c64cb6 | 2017-04-12 13:39:59 -0700 | [diff] [blame] | 753 | return "AppWindowContainerController{" |
| 754 | + " token=" + mToken |
| 755 | + " mContainer=" + mContainer |
| 756 | + " mListener=" + mListener |
| 757 | + "}"; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 758 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 759 | } |