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