Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId; |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 20 | import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION; |
| 21 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE; |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 22 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 23 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 24 | import static android.view.Display.DEFAULT_DISPLAY; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 25 | import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; |
| 26 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 29 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 30 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
| 31 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 32 | import static com.android.server.wm.AppTransition.TRANSIT_UNSET; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 33 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 34 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
| 35 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS; |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 36 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 37 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; |
| 38 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 39 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW; |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 40 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 41 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
| 42 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT; |
| 43 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 44 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 45 | import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN; |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 46 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 47 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 48 | import static com.android.server.wm.WindowManagerService.logWithStack; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 49 | |
Filip Gruszczynski | a590c99 | 2015-11-25 16:45:26 -0800 | [diff] [blame] | 50 | import android.annotation.NonNull; |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 51 | import android.content.res.Configuration; |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 52 | import android.graphics.Rect; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 53 | import android.os.Binder; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 54 | import android.os.Debug; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 55 | import android.os.IBinder; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 56 | import android.os.SystemClock; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 57 | import android.util.Slog; |
| 58 | import android.view.IApplicationToken; |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 59 | import android.view.SurfaceControl; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 60 | import android.view.WindowManager; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 61 | import android.view.WindowManagerPolicy.StartingSurface; |
| 62 | |
| 63 | import com.android.internal.util.ToBooleanFunction; |
| 64 | import com.android.server.input.InputApplicationHandle; |
| 65 | import com.android.server.wm.WindowManagerService.H; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 66 | |
| 67 | import java.io.PrintWriter; |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 68 | import java.util.ArrayDeque; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 69 | import java.util.ArrayList; |
| 70 | |
| 71 | class AppTokenList extends ArrayList<AppWindowToken> { |
| 72 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * Version of WindowToken that is specifically for a particular application (or |
| 76 | * really activity) that is displaying windows. |
| 77 | */ |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 78 | class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 79 | private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM; |
| 80 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 81 | // Non-null only for application tokens. |
| 82 | final IApplicationToken appToken; |
| 83 | |
Filip Gruszczynski | a590c99 | 2015-11-25 16:45:26 -0800 | [diff] [blame] | 84 | @NonNull final AppWindowAnimator mAppAnimator; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 85 | |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 86 | final boolean mVoiceInteraction; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 87 | |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 88 | /** @see WindowContainer#fillsParent() */ |
| 89 | private boolean mFillsParent; |
Craig Mautner | 4c5eb22 | 2013-11-18 12:59:05 -0800 | [diff] [blame] | 90 | boolean layoutConfigChanges; |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 91 | boolean mShowForAllUsers; |
| 92 | int mTargetSdk; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 93 | |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 94 | // Flag set while reparenting to prevent actions normally triggered by an individual parent |
| 95 | // change. |
| 96 | private boolean mReparenting; |
| 97 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 98 | // The input dispatching timeout for this application token in nanoseconds. |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 99 | long mInputDispatchingTimeoutNanos; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 100 | |
| 101 | // These are used for determining when all windows associated with |
| 102 | // an activity have been drawn, so they can be made visible together |
| 103 | // at the same time. |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 104 | // initialize so that it doesn't match mTransactionSequence which is an int. |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 105 | private long mLastTransactionSequence = Long.MIN_VALUE; |
| 106 | private int mNumInterestingWindows; |
| 107 | private int mNumDrawnWindows; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 108 | boolean inPendingTransaction; |
| 109 | boolean allDrawn; |
Craig Mautner | 7636dfb | 2012-11-16 15:24:11 -0800 | [diff] [blame] | 110 | // Set to true when this app creates a surface while in the middle of an animation. In that |
| 111 | // case do not clear allDrawn until the animation completes. |
| 112 | boolean deferClearAllDrawn; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 113 | |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 114 | /** |
| 115 | * These are to track the app's real drawing status if there were no saved surfaces. |
| 116 | * @see #updateDrawnWindowStates |
| 117 | */ |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 118 | boolean allDrawnExcludingSaved; |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 119 | private int mNumInterestingWindowsExcludingSaved; |
| 120 | private int mNumDrawnWindowsExcludingSaved; |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 121 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 122 | // Is this window's surface needed? This is almost like hidden, except |
| 123 | // it will sometimes be true a little earlier: when the token has |
| 124 | // been shown, but is still waiting for its app transition to execute |
| 125 | // before making its windows shown. |
| 126 | boolean hiddenRequested; |
| 127 | |
| 128 | // Have we told the window clients to hide themselves? |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame^] | 129 | private boolean mClientHidden; |
| 130 | |
| 131 | // If true we will defer setting mClientHidden to true and reporting to the client that it is |
| 132 | // hidden. |
| 133 | boolean mDeferHidingClient; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 134 | |
| 135 | // Last visibility state we reported to the app token. |
| 136 | boolean reportedVisible; |
| 137 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 138 | // Last drawn state we reported to the app token. |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 139 | private boolean reportedDrawn; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 140 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 141 | // Set to true when the token has been removed from the window mgr. |
| 142 | boolean removed; |
| 143 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 144 | // Information about an application starting window if displayed. |
| 145 | StartingData startingData; |
| 146 | WindowState startingWindow; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 147 | StartingSurface startingSurface; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 148 | boolean startingDisplayed; |
| 149 | boolean startingMoved; |
| 150 | boolean firstWindowDrawn; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 151 | private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults = |
| 152 | new WindowState.UpdateReportedVisibilityResults(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 153 | |
| 154 | // Input application handle used by the input dispatcher. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 155 | final InputApplicationHandle mInputApplicationHandle; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 156 | |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 157 | // TODO: Have a WindowContainer state for tracking exiting/deferred removal. |
Craig Mautner | 799bc1d | 2015-01-14 10:33:48 -0800 | [diff] [blame] | 158 | boolean mIsExiting; |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 159 | |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 160 | boolean mLaunchTaskBehind; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 161 | boolean mEnteringAnimation; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 162 | |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 163 | private boolean mAlwaysFocusable; |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 164 | |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 165 | boolean mAppStopped; |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 166 | int mRotationAnimationHint; |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 167 | private int mPendingRelaunchCount; |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 168 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 169 | private boolean mLastContainsShowWhenLockedWindow; |
| 170 | private boolean mLastContainsDismissKeyguardWindow; |
| 171 | |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 172 | // The bounds of this activity. Mainly used for aspect-ratio compatibility. |
| 173 | // TODO(b/36505427): Every level on WindowContainer now has bounds information, which directly |
| 174 | // affects the configuration. We should probably move this into that class. |
| 175 | private final Rect mBounds = new Rect(); |
| 176 | |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 177 | ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>(); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 178 | ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>(); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 179 | |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 180 | private boolean mDisbalePreviewScreenshots; |
| 181 | |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 182 | AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction, |
| 183 | DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen, |
| 184 | boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint, |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 185 | int configChanges, boolean launchTaskBehind, boolean alwaysFocusable, |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 186 | AppWindowContainerController controller, Configuration overrideConfig, Rect bounds) { |
| 187 | this(service, token, voiceInteraction, dc, fullscreen, overrideConfig, bounds); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 188 | setController(controller); |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 189 | mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 190 | mShowForAllUsers = showForAllUsers; |
| 191 | mTargetSdk = targetSdk; |
| 192 | mOrientation = orientation; |
| 193 | layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0; |
| 194 | mLaunchTaskBehind = launchTaskBehind; |
| 195 | mAlwaysFocusable = alwaysFocusable; |
| 196 | mRotationAnimationHint = rotationAnimationHint; |
| 197 | |
| 198 | // Application tokens start out hidden. |
| 199 | hidden = true; |
| 200 | hiddenRequested = true; |
| 201 | } |
| 202 | |
| 203 | AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction, |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 204 | DisplayContent dc, boolean fillsParent, Configuration overrideConfig, Rect bounds) { |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 205 | super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc, |
| 206 | false /* ownerCanManageAppTokens */); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 207 | appToken = token; |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 208 | mVoiceInteraction = voiceInteraction; |
Wale Ogunwale | 17f175c | 2017-02-07 16:54:10 -0800 | [diff] [blame] | 209 | mFillsParent = fillsParent; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 210 | mInputApplicationHandle = new InputApplicationHandle(this); |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 211 | mAppAnimator = new AppWindowAnimator(this, service); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 212 | if (overrideConfig != null) { |
| 213 | onOverrideConfigurationChanged(overrideConfig); |
| 214 | } |
| 215 | if (bounds != null) { |
| 216 | mBounds.set(bounds); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | void onOverrideConfigurationChanged(Configuration overrideConfiguration, Rect bounds) { |
| 221 | onOverrideConfigurationChanged(overrideConfiguration); |
| 222 | if (mBounds.equals(bounds)) { |
| 223 | return; |
| 224 | } |
| 225 | // TODO(b/36505427): If bounds is in WC, then we can automatically call onResize() when set. |
| 226 | mBounds.set(bounds); |
| 227 | onResize(); |
| 228 | } |
| 229 | |
| 230 | void getBounds(Rect outBounds) { |
| 231 | outBounds.set(mBounds); |
| 232 | } |
| 233 | |
| 234 | boolean hasBounds() { |
| 235 | return !mBounds.isEmpty(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 236 | } |
| 237 | |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 238 | void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) { |
| 239 | firstWindowDrawn = true; |
| 240 | |
| 241 | // We now have a good window to show, remove dead placeholders |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 242 | removeDeadWindows(); |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 243 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 244 | if (startingWindow != null) { |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 245 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting " |
| 246 | + win.mToken + ": first real window is shown, no animation"); |
| 247 | // If this initial window is animating, stop it -- we will do an animation to reveal |
| 248 | // it from behind the starting window, so there is no need for it to also be doing its |
| 249 | // own stuff. |
| 250 | winAnimator.clearAnimation(); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 251 | if (getController() != null) { |
| 252 | getController().removeStartingWindow(); |
| 253 | } |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 254 | } |
| 255 | updateReportedVisibilityLocked(); |
| 256 | } |
| 257 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 258 | void updateReportedVisibilityLocked() { |
| 259 | if (appToken == null) { |
| 260 | return; |
| 261 | } |
| 262 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 263 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 264 | final int count = mChildren.size(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 265 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 266 | mReportedVisibilityResults.reset(); |
| 267 | |
| 268 | for (int i = 0; i < count; i++) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 269 | final WindowState win = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 270 | win.updateReportedVisibility(mReportedVisibilityResults); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 271 | } |
| 272 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 273 | int numInteresting = mReportedVisibilityResults.numInteresting; |
| 274 | int numVisible = mReportedVisibilityResults.numVisible; |
| 275 | int numDrawn = mReportedVisibilityResults.numDrawn; |
| 276 | boolean nowGone = mReportedVisibilityResults.nowGone; |
| 277 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 278 | boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 279 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 280 | if (!nowGone) { |
| 281 | // If the app is not yet gone, then it can only become visible/drawn. |
| 282 | if (!nowDrawn) { |
| 283 | nowDrawn = reportedDrawn; |
| 284 | } |
| 285 | if (!nowVisible) { |
| 286 | nowVisible = reportedVisible; |
| 287 | } |
| 288 | } |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 289 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 290 | + numInteresting + " visible=" + numVisible); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 291 | final AppWindowContainerController controller = getController(); |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 292 | if (nowDrawn != reportedDrawn) { |
| 293 | if (nowDrawn) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 294 | if (controller != null) { |
| 295 | controller.reportWindowsDrawn(); |
| 296 | } |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 297 | } |
| 298 | reportedDrawn = nowDrawn; |
| 299 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 300 | if (nowVisible != reportedVisible) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 301 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 302 | "Visibility changed in " + this + ": vis=" + nowVisible); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 303 | reportedVisible = nowVisible; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 304 | if (controller != null) { |
| 305 | if (nowVisible) { |
| 306 | controller.reportWindowsVisible(); |
| 307 | } else { |
| 308 | controller.reportWindowsGone(); |
| 309 | } |
| 310 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame^] | 314 | boolean isClientHidden() { |
| 315 | return mClientHidden; |
| 316 | } |
| 317 | |
| 318 | void setClientHidden(boolean hideClient) { |
| 319 | if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) { |
| 320 | return; |
| 321 | } |
| 322 | mClientHidden = hideClient; |
| 323 | sendAppVisibilityToClients(); |
| 324 | } |
| 325 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 326 | boolean setVisibility(WindowManager.LayoutParams lp, |
| 327 | boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) { |
| 328 | |
| 329 | boolean delayed = false; |
| 330 | inPendingTransaction = false; |
| 331 | |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame^] | 332 | setClientHidden(!visible); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 333 | |
| 334 | // Allow for state changes and animation to be applied if: |
| 335 | // * token is transitioning visibility state |
| 336 | // * or the token was marked as hidden and is exiting before we had a chance to play the |
| 337 | // transition animation |
| 338 | // * or this is an opening app and windows are being replaced. |
| 339 | boolean visibilityChanged = false; |
| 340 | if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) { |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 341 | final AccessibilityController accessibilityController = mService.mAccessibilityController; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 342 | boolean changed = false; |
| 343 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, |
| 344 | "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout); |
| 345 | |
| 346 | boolean runningAppAnimation = false; |
| 347 | |
| 348 | if (transit != AppTransition.TRANSIT_UNSET) { |
| 349 | if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) { |
| 350 | mAppAnimator.setNullAnimation(); |
| 351 | } |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 352 | if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 353 | delayed = runningAppAnimation = true; |
| 354 | } |
| 355 | final WindowState window = findMainWindow(); |
| 356 | //TODO (multidisplay): Magnification is supported only for the default display. |
| 357 | if (window != null && accessibilityController != null |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 358 | && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 359 | accessibilityController.onAppWindowTransitionLocked(window, transit); |
| 360 | } |
| 361 | changed = true; |
| 362 | } |
| 363 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 364 | final int windowsCount = mChildren.size(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 365 | for (int i = 0; i < windowsCount; i++) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 366 | final WindowState win = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 367 | changed |= win.onAppVisibilityChanged(visible, runningAppAnimation); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | hidden = hiddenRequested = !visible; |
| 371 | visibilityChanged = true; |
| 372 | if (!visible) { |
| 373 | stopFreezingScreen(true, true); |
| 374 | } else { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 375 | // If we are being set visible, and the starting window is not yet displayed, |
| 376 | // then make sure it doesn't get displayed. |
| 377 | if (startingWindow != null && !startingWindow.isDrawnLw()) { |
| 378 | startingWindow.mPolicyVisibility = false; |
| 379 | startingWindow.mPolicyVisibilityAfterAnim = false; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | |
| 383 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this |
| 384 | + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested); |
| 385 | |
| 386 | if (changed) { |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 387 | mService.mInputMonitor.setUpdateInputWindowsNeededLw(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 388 | if (performLayout) { |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 389 | mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 390 | false /*updateInputWindows*/); |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 391 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 392 | } |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 393 | mService.mInputMonitor.updateInputWindowsLw(false /*force*/); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | |
| 397 | if (mAppAnimator.animation != null) { |
| 398 | delayed = true; |
| 399 | } |
| 400 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 401 | for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 402 | if ((mChildren.get(i)).isWindowAnimationSet()) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 403 | delayed = true; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | if (visibilityChanged) { |
| 408 | if (visible && !delayed) { |
| 409 | // The token was made immediately visible, there will be no entrance animation. |
| 410 | // We need to inform the client the enter animation was finished. |
| 411 | mEnteringAnimation = true; |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 412 | mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 413 | } |
Robert Carr | e7cc44d | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 414 | // If we are hidden but there is no delay needed we immediately |
| 415 | // apply the Surface transaction so that the ActivityManager |
| 416 | // can have some guarantee on the Surface state |
| 417 | // following setting the visibility. |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 418 | if (hidden && !delayed) { |
| 419 | SurfaceControl.openTransaction(); |
| 420 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 421 | mChildren.get(i).mWinAnimator.hide("immediately hidden"); |
| 422 | } |
| 423 | SurfaceControl.closeTransaction(); |
| 424 | } |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 425 | |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 426 | if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 427 | // The token is not closing nor opening, so even if there is an animation set, that |
| 428 | // doesn't mean that it goes through the normal app transition cycle so we have |
| 429 | // to inform the docked controller about visibility change. |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 430 | // TODO(multi-display): notify docked divider on all displays where visibility was |
| 431 | // affected. |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 432 | mService.getDefaultDisplayContentLocked().getDockedDividerController() |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 433 | .notifyAppVisibilityChanged(); |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 434 | mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 435 | } |
| 436 | } |
| 437 | |
| 438 | return delayed; |
| 439 | } |
| 440 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 441 | WindowState findMainWindow() { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 442 | WindowState candidate = null; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 443 | int j = mChildren.size(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 444 | while (j > 0) { |
| 445 | j--; |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 446 | final WindowState win = mChildren.get(j); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 447 | final int type = win.mAttrs.type; |
| 448 | // No need to loop through child window as base application and starting types can't be |
| 449 | // child windows. |
| 450 | if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 451 | // In cases where there are multiple windows, we prefer the non-exiting window. This |
Sungsoo Lim | 0d3d1f8 | 2015-12-02 14:47:59 +0900 | [diff] [blame] | 452 | // happens for example when replacing windows during an activity relaunch. When |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 453 | // constructing the animation, we want the new window, not the exiting one. |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 454 | if (win.mAnimatingExit) { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 455 | candidate = win; |
| 456 | } else { |
| 457 | return win; |
| 458 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 459 | } |
| 460 | } |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 461 | return candidate; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 462 | } |
| 463 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 464 | boolean windowsAreFocusable() { |
Bryce Lee | 7fbeb8a | 2017-03-02 08:42:30 -0800 | [diff] [blame] | 465 | return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable; |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 466 | } |
| 467 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 468 | AppWindowContainerController getController() { |
| 469 | final WindowContainerController controller = super.getController(); |
| 470 | return controller != null ? (AppWindowContainerController) controller : null; |
| 471 | } |
| 472 | |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 473 | @Override |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 474 | boolean isVisible() { |
Wale Ogunwale | e471be6 | 2016-10-03 07:53:55 -0700 | [diff] [blame] | 475 | // If the app token isn't hidden then it is considered visible and there is no need to check |
| 476 | // its children windows to see if they are visible. |
| 477 | return !hidden; |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | @Override |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 481 | void removeIfPossible() { |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 482 | mIsExiting = false; |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 483 | removeAllWindowsIfPossible(); |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 484 | removeImmediately(); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 485 | } |
| 486 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 487 | @Override |
| 488 | boolean checkCompleteDeferredRemoval() { |
| 489 | if (mIsExiting) { |
| 490 | removeIfPossible(); |
| 491 | } |
| 492 | return super.checkCompleteDeferredRemoval(); |
| 493 | } |
| 494 | |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 495 | void onRemovedFromDisplay() { |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 496 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this); |
| 497 | |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 498 | boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction); |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 499 | |
| 500 | mService.mOpeningApps.remove(this); |
Jorim Jaggi | 1b4b23e | 2016-11-15 16:30:12 -0800 | [diff] [blame] | 501 | mService.mUnknownAppVisibilityController.appRemoved(this); |
Jorim Jaggi | 10abe2f | 2017-01-03 16:44:46 +0100 | [diff] [blame] | 502 | mService.mTaskSnapshotController.onAppRemoved(this); |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 503 | waitingToShow = false; |
| 504 | if (mService.mClosingApps.contains(this)) { |
| 505 | delayed = true; |
| 506 | } else if (mService.mAppTransition.isTransitionSet()) { |
| 507 | mService.mClosingApps.add(this); |
| 508 | delayed = true; |
| 509 | } |
| 510 | |
| 511 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed |
| 512 | + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating); |
| 513 | |
| 514 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: " |
| 515 | + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4)); |
| 516 | |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 517 | if (startingData != null && getController() != null) { |
| 518 | getController().removeStartingWindow(); |
| 519 | } |
| 520 | |
Winson Chung | 87e5d55 | 2017-04-05 11:49:38 -0700 | [diff] [blame] | 521 | // If this window was animating, then we need to ensure that the app transition notifies |
| 522 | // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so |
| 523 | // add to that list now |
| 524 | if (mAppAnimator.animating) { |
| 525 | mService.mNoAnimationNotifyOnTransitionFinished.add(token); |
| 526 | } |
| 527 | |
Bryce Lee | 7fbeb8a | 2017-03-02 08:42:30 -0800 | [diff] [blame] | 528 | final TaskStack stack = getTask().mStack; |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 529 | if (delayed && !isEmpty()) { |
| 530 | // set the token aside because it has an active animation to be finished |
| 531 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, |
| 532 | "removeAppToken make exiting: " + this); |
| 533 | stack.mExitingAppTokens.add(this); |
| 534 | mIsExiting = true; |
| 535 | } else { |
| 536 | // Make sure there is no animation running on this token, so any windows associated |
| 537 | // with it will be removed as soon as their animations are complete |
| 538 | mAppAnimator.clearAnimation(); |
| 539 | mAppAnimator.animating = false; |
| 540 | removeIfPossible(); |
| 541 | } |
| 542 | |
| 543 | removed = true; |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 544 | stopFreezingScreen(true, true); |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 545 | |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 546 | if (mService.mFocusedApp == this) { |
| 547 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this); |
| 548 | mService.mFocusedApp = null; |
| 549 | mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
| 550 | mService.mInputMonitor.setFocusedAppLw(null); |
| 551 | } |
| 552 | |
| 553 | if (!delayed) { |
| 554 | updateReportedVisibilityLocked(); |
| 555 | } |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Chong Zhang | e05bcb1 | 2016-07-26 17:47:29 -0700 | [diff] [blame] | 558 | void clearAnimatingFlags() { |
Chong Zhang | b0d2670 | 2016-08-12 16:03:29 -0700 | [diff] [blame] | 559 | boolean wallpaperMightChange = false; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 560 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 561 | final WindowState win = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 562 | wallpaperMightChange |= win.clearAnimatingFlags(); |
Chong Zhang | e05bcb1 | 2016-07-26 17:47:29 -0700 | [diff] [blame] | 563 | } |
Chong Zhang | b0d2670 | 2016-08-12 16:03:29 -0700 | [diff] [blame] | 564 | if (wallpaperMightChange) { |
| 565 | requestUpdateWallpaperIfNeeded(); |
| 566 | } |
Chong Zhang | e05bcb1 | 2016-07-26 17:47:29 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 569 | void destroySurfaces() { |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 570 | destroySurfaces(false /*cleanupOnResume*/); |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure |
| 575 | * the client has finished with them. |
| 576 | * |
| 577 | * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If |
| 578 | * set to true, destroy only surfaces of removed windows, and clear relevant flags of the |
| 579 | * others so that they are ready to be reused. If set to false (common case), destroy all |
| 580 | * surfaces that's eligible, if the app is already stopped. |
| 581 | */ |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 582 | private void destroySurfaces(boolean cleanupOnResume) { |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 583 | boolean destroyedSomething = false; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 584 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 585 | final WindowState win = mChildren.get(i); |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 586 | destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped); |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 587 | } |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 588 | if (destroyedSomething) { |
| 589 | final DisplayContent dc = getDisplayContent(); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 590 | dc.assignWindowLayers(true /*setLayoutNeeded*/); |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 594 | /** |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 595 | * Notify that the app is now resumed, and it was not stopped before, perform a clean |
| 596 | * up of the surfaces |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 597 | */ |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 598 | void notifyAppResumed(boolean wasStopped) { |
Chong Zhang | ad24f96 | 2016-08-25 12:12:33 -0700 | [diff] [blame] | 599 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped |
Jorim Jaggi | bae01b1 | 2017-04-11 16:29:10 -0700 | [diff] [blame] | 600 | + " " + this); |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 601 | mAppStopped = false; |
| 602 | if (!wasStopped) { |
| 603 | destroySurfaces(true /*cleanupOnResume*/); |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 604 | } |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 605 | } |
| 606 | |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 607 | /** |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 608 | * Notify that the app has stopped, and it is okay to destroy any surfaces which were |
| 609 | * keeping alive in case they were still being used. |
| 610 | */ |
| 611 | void notifyAppStopped() { |
| 612 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this); |
| 613 | mAppStopped = true; |
| 614 | destroySurfaces(); |
| 615 | // Remove any starting window that was added for this app if they are still around. |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 616 | if (getController() != null) { |
| 617 | getController().removeStartingWindow(); |
| 618 | } |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | /** |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 622 | * Checks whether we should save surfaces for this app. |
| 623 | * |
| 624 | * @return true if the surfaces should be saved, false otherwise. |
| 625 | */ |
| 626 | boolean shouldSaveSurface() { |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 627 | // We want to save surface if the app's windows are "allDrawn". |
| 628 | // (If we started entering animation early with saved surfaces, allDrawn |
| 629 | // should have been restored to true. So we'll save again in that case |
| 630 | // even if app didn't actually finish drawing.) |
| 631 | return allDrawn; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 632 | } |
| 633 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 634 | private boolean canRestoreSurfaces() { |
| 635 | for (int i = mChildren.size() -1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 636 | final WindowState w = mChildren.get(i); |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 637 | if (w.canRestoreSurface()) { |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 638 | return true; |
| 639 | } |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 640 | } |
| 641 | return false; |
| 642 | } |
| 643 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 644 | private void clearWasVisibleBeforeClientHidden() { |
| 645 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 646 | final WindowState w = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 647 | w.clearWasVisibleBeforeClientHidden(); |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 648 | } |
| 649 | } |
| 650 | |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 651 | /** |
| 652 | * Whether the app has some window that is invisible in layout, but |
| 653 | * animating with saved surface. |
| 654 | */ |
| 655 | boolean isAnimatingInvisibleWithSavedSurface() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 656 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 657 | final WindowState w = mChildren.get(i); |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 658 | if (w.isAnimatingInvisibleWithSavedSurface()) { |
| 659 | return true; |
| 660 | } |
| 661 | } |
| 662 | return false; |
| 663 | } |
| 664 | |
| 665 | /** |
| 666 | * Hide all window surfaces that's still invisible in layout but animating |
| 667 | * with a saved surface, and mark them destroying. |
| 668 | */ |
| 669 | void stopUsingSavedSurfaceLocked() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 670 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 671 | final WindowState w = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 672 | w.stopUsingSavedSurface(); |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 673 | } |
| 674 | destroySurfaces(); |
| 675 | } |
| 676 | |
Chong Zhang | f58631a | 2016-05-24 16:02:10 -0700 | [diff] [blame] | 677 | void markSavedSurfaceExiting() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 678 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 679 | final WindowState w = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 680 | w.markSavedSurfaceExiting(); |
Chong Zhang | f58631a | 2016-05-24 16:02:10 -0700 | [diff] [blame] | 681 | } |
| 682 | } |
| 683 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 684 | void restoreSavedSurfaceForInterestingWindows() { |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 685 | if (!canRestoreSurfaces()) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 686 | clearWasVisibleBeforeClientHidden(); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 687 | return; |
| 688 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 689 | |
| 690 | // Check if all interesting windows are drawn and we can mark allDrawn=true. |
| 691 | int interestingNotDrawn = -1; |
| 692 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 693 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 694 | final WindowState w = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 695 | interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow(); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 696 | } |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 697 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 698 | if (!allDrawn) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 699 | allDrawn = (interestingNotDrawn == 0); |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 700 | if (allDrawn) { |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 701 | mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget(); |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 702 | } |
| 703 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 704 | clearWasVisibleBeforeClientHidden(); |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 705 | |
| 706 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 707 | "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn |
| 708 | + " interestingNotDrawn=" + interestingNotDrawn); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | void destroySavedSurfaces() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 712 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 713 | final WindowState win = mChildren.get(i); |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 714 | win.destroySavedSurface(); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 715 | } |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | void clearAllDrawn() { |
| 719 | allDrawn = false; |
| 720 | deferClearAllDrawn = false; |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 721 | allDrawnExcludingSaved = false; |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 722 | } |
| 723 | |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 724 | Task getTask() { |
Bryce Lee | 7fbeb8a | 2017-03-02 08:42:30 -0800 | [diff] [blame] | 725 | return (Task) getParent(); |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 726 | } |
| 727 | |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 728 | TaskStack getStack() { |
| 729 | final Task task = getTask(); |
| 730 | if (task != null) { |
| 731 | return task.mStack; |
| 732 | } else { |
| 733 | return null; |
| 734 | } |
| 735 | } |
| 736 | |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 737 | @Override |
| 738 | void onParentSet() { |
| 739 | super.onParentSet(); |
| 740 | |
| 741 | // When the associated task is {@code null}, the {@link AppWindowToken} can no longer |
| 742 | // access visual elements like the {@link DisplayContent}. We must remove any associations |
| 743 | // such as animations. |
Bryce Lee | 7fbeb8a | 2017-03-02 08:42:30 -0800 | [diff] [blame] | 744 | if (!mReparenting) { |
| 745 | final Task task = getTask(); |
| 746 | if (task == null) { |
| 747 | // It is possible we have been marked as a closing app earlier. We must remove ourselves |
| 748 | // from this list so we do not participate in any future animations. |
| 749 | mService.mClosingApps.remove(this); |
| 750 | } else if (task.mStack != null) { |
| 751 | task.mStack.mExitingAppTokens.remove(this); |
| 752 | } |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 753 | } |
| 754 | } |
| 755 | |
Wale Ogunwale | fa854eb | 2016-09-20 13:43:52 -0700 | [diff] [blame] | 756 | void postWindowRemoveStartingWindowCleanup(WindowState win) { |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 757 | // TODO: Something smells about the code below...Is there a better way? |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 758 | if (startingWindow == win) { |
| 759 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 760 | if (getController() != null) { |
| 761 | getController().removeStartingWindow(); |
| 762 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 763 | } else if (mChildren.size() == 0 && startingData != null) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 764 | // If this is the last window and we had requested a starting transition window, |
| 765 | // well there is no point now. |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 766 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData"); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 767 | startingData = null; |
Jorim Jaggi | 829b9cd | 2017-01-23 16:20:53 +0100 | [diff] [blame] | 768 | } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 769 | // If this is the last window except for a starting transition window, |
| 770 | // we need to get rid of the starting transition. |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 771 | if (getController() != null) { |
| 772 | getController().removeStartingWindow(); |
| 773 | } |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 777 | void removeDeadWindows() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 778 | for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 779 | WindowState win = mChildren.get(winNdx); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 780 | if (win.mAppDied) { |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 781 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG, |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 782 | "removeDeadWindows: " + win); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 783 | // Set mDestroying, we don't want any animation or delayed removal here. |
| 784 | win.mDestroying = true; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 785 | // Also removes child windows. |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 786 | win.removeIfPossible(); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | } |
| 790 | |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 791 | boolean hasWindowsAlive() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 792 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 793 | // No need to loop through child windows as the answer should be the same as that of the |
| 794 | // parent window. |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 795 | if (!(mChildren.get(i)).mAppDied) { |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 796 | return true; |
| 797 | } |
| 798 | } |
| 799 | return false; |
| 800 | } |
| 801 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 802 | void setWillReplaceWindows(boolean animate) { |
Wale Ogunwale | 455fac5 | 2016-07-21 07:24:49 -0700 | [diff] [blame] | 803 | if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, |
| 804 | "Marking app token " + this + " with replacing windows."); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 805 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 806 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 807 | final WindowState w = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 808 | w.setWillReplaceWindow(animate); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 809 | } |
| 810 | if (animate) { |
| 811 | // Set-up dummy animation so we can start treating windows associated with this |
| 812 | // token like they are in transition before the new app window is ready for us to |
| 813 | // run the real transition animation. |
| 814 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 815 | "setWillReplaceWindow() Setting dummy animation on: " + this); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 816 | mAppAnimator.setDummyAnimation(); |
| 817 | } |
| 818 | } |
| 819 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 820 | void setWillReplaceChildWindows() { |
Wale Ogunwale | 455fac5 | 2016-07-21 07:24:49 -0700 | [diff] [blame] | 821 | if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 822 | + " with replacing child windows."); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 823 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 824 | final WindowState w = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 825 | w.setWillReplaceChildWindows(); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 829 | void clearWillReplaceWindows() { |
Wale Ogunwale | 455fac5 | 2016-07-21 07:24:49 -0700 | [diff] [blame] | 830 | if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, |
| 831 | "Resetting app token " + this + " of replacing window marks."); |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 832 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 833 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 834 | final WindowState w = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 835 | w.clearWillReplaceWindow(); |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 836 | } |
| 837 | } |
| 838 | |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 839 | void requestUpdateWallpaperIfNeeded() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 840 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 841 | final WindowState w = mChildren.get(i); |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 842 | w.requestUpdateWallpaperIfNeeded(); |
| 843 | } |
| 844 | } |
| 845 | |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 846 | boolean isRelaunching() { |
| 847 | return mPendingRelaunchCount > 0; |
| 848 | } |
| 849 | |
| 850 | void startRelaunching() { |
| 851 | if (canFreezeBounds()) { |
| 852 | freezeBounds(); |
| 853 | } |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 854 | |
| 855 | // In the process of tearing down before relaunching, the app will |
| 856 | // try and clean up it's child surfaces. We need to prevent this from |
| 857 | // happening, so we sever the children, transfering their ownership |
| 858 | // from the client it-self to the parent surface (owned by us). |
| 859 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 860 | final WindowState w = mChildren.get(i); |
| 861 | w.mWinAnimator.detachChildren(); |
| 862 | } |
| 863 | |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 864 | mPendingRelaunchCount++; |
| 865 | } |
| 866 | |
| 867 | void finishRelaunching() { |
| 868 | if (canFreezeBounds()) { |
| 869 | unfreezeBounds(); |
| 870 | } |
| 871 | if (mPendingRelaunchCount > 0) { |
| 872 | mPendingRelaunchCount--; |
| 873 | } |
| 874 | } |
| 875 | |
Wale Ogunwale | 8fd7542 | 2016-06-24 14:20:37 -0700 | [diff] [blame] | 876 | void clearRelaunching() { |
Wale Ogunwale | 37dbafc | 2016-06-27 10:15:20 -0700 | [diff] [blame] | 877 | if (mPendingRelaunchCount == 0) { |
| 878 | return; |
| 879 | } |
Wale Ogunwale | 8fd7542 | 2016-06-24 14:20:37 -0700 | [diff] [blame] | 880 | if (canFreezeBounds()) { |
| 881 | unfreezeBounds(); |
| 882 | } |
| 883 | mPendingRelaunchCount = 0; |
| 884 | } |
| 885 | |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 886 | /** |
| 887 | * Returns true if the new child window we are adding to this token is considered greater than |
| 888 | * the existing child window in this token in terms of z-order. |
| 889 | */ |
| 890 | @Override |
| 891 | protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow, |
| 892 | WindowState existingWindow) { |
| 893 | final int type1 = newWindow.mAttrs.type; |
| 894 | final int type2 = existingWindow.mAttrs.type; |
| 895 | |
| 896 | // Base application windows should be z-ordered BELOW all other windows in the app token. |
| 897 | if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) { |
| 898 | return false; |
| 899 | } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) { |
| 900 | return true; |
| 901 | } |
| 902 | |
| 903 | // Starting windows should be z-ordered ABOVE all other windows in the app token. |
| 904 | if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) { |
| 905 | return true; |
| 906 | } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) { |
| 907 | return false; |
| 908 | } |
| 909 | |
| 910 | // Otherwise the new window is greater than the existing window. |
| 911 | return true; |
| 912 | } |
| 913 | |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 914 | @Override |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 915 | void addWindow(WindowState w) { |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 916 | super.addWindow(w); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 917 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 918 | boolean gotReplacementWindow = false; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 919 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 920 | final WindowState candidate = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 921 | gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w); |
| 922 | } |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 923 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 924 | // if we got a replacement window, reset the timeout to give drawing more time |
| 925 | if (gotReplacementWindow) { |
| 926 | mService.scheduleWindowReplacementTimeouts(this); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 927 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 928 | checkKeyguardFlagsChanged(); |
| 929 | } |
| 930 | |
| 931 | @Override |
| 932 | void removeChild(WindowState child) { |
| 933 | super.removeChild(child); |
| 934 | checkKeyguardFlagsChanged(); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 935 | } |
| 936 | |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 937 | private boolean waitingForReplacement() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 938 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 939 | final WindowState candidate = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 940 | if (candidate.waitingForReplacement()) { |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 941 | return true; |
| 942 | } |
| 943 | } |
| 944 | return false; |
| 945 | } |
| 946 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 947 | void onWindowReplacementTimeout() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 948 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 949 | (mChildren.get(i)).onWindowReplacementTimeout(); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 950 | } |
| 951 | } |
| 952 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 953 | void reparent(Task task, int position) { |
Bryce Lee | 7fbeb8a | 2017-03-02 08:42:30 -0800 | [diff] [blame] | 954 | final Task currentTask = getTask(); |
| 955 | if (task == currentTask) { |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 956 | throw new IllegalArgumentException( |
Bryce Lee | 7fbeb8a | 2017-03-02 08:42:30 -0800 | [diff] [blame] | 957 | "window token=" + this + " already child of task=" + currentTask); |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 958 | } |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 959 | |
Bryce Lee | 7fbeb8a | 2017-03-02 08:42:30 -0800 | [diff] [blame] | 960 | if (currentTask.mStack != task.mStack) { |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 961 | throw new IllegalArgumentException( |
Bryce Lee | 7fbeb8a | 2017-03-02 08:42:30 -0800 | [diff] [blame] | 962 | "window token=" + this + " current task=" + currentTask |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 963 | + " belongs to a different stack than " + task); |
| 964 | } |
| 965 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 966 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this |
Bryce Lee | 7fbeb8a | 2017-03-02 08:42:30 -0800 | [diff] [blame] | 967 | + " from task=" + currentTask); |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 968 | final DisplayContent prevDisplayContent = getDisplayContent(); |
| 969 | |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 970 | mReparenting = true; |
| 971 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 972 | getParent().removeChild(this); |
| 973 | task.addChild(this, position); |
| 974 | |
Bryce Lee | 6d41026 | 2017-02-28 15:30:17 -0800 | [diff] [blame] | 975 | mReparenting = false; |
| 976 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 977 | // Relayout display(s). |
| 978 | final DisplayContent displayContent = task.getDisplayContent(); |
| 979 | displayContent.setLayoutNeeded(); |
| 980 | if (prevDisplayContent != displayContent) { |
| 981 | onDisplayChanged(displayContent); |
| 982 | prevDisplayContent.setLayoutNeeded(); |
| 983 | } |
| 984 | } |
| 985 | |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 986 | private boolean canFreezeBounds() { |
Bryce Lee | 7fbeb8a | 2017-03-02 08:42:30 -0800 | [diff] [blame] | 987 | final Task task = getTask(); |
| 988 | |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 989 | // For freeform windows, we can't freeze the bounds at the moment because this would make |
| 990 | // the resizing unresponsive. |
Bryce Lee | 7fbeb8a | 2017-03-02 08:42:30 -0800 | [diff] [blame] | 991 | return task != null && !task.inFreeformWorkspace(); |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 992 | } |
| 993 | |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 994 | /** |
| 995 | * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds |
| 996 | * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even |
| 997 | * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen |
| 998 | * with a queue. |
| 999 | */ |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 1000 | private void freezeBounds() { |
Bryce Lee | 7fbeb8a | 2017-03-02 08:42:30 -0800 | [diff] [blame] | 1001 | final Task task = getTask(); |
| 1002 | mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds)); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 1003 | |
Bryce Lee | 7fbeb8a | 2017-03-02 08:42:30 -0800 | [diff] [blame] | 1004 | if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) { |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 1005 | // We didn't call prepareFreezingBounds on the task, so use the current value. |
Bryce Lee | 7fbeb8a | 2017-03-02 08:42:30 -0800 | [diff] [blame] | 1006 | mFrozenMergedConfig.offer(new Configuration(task.getConfiguration())); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 1007 | } else { |
Bryce Lee | 7fbeb8a | 2017-03-02 08:42:30 -0800 | [diff] [blame] | 1008 | mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig)); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 1009 | } |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 1010 | // Calling unset() to make it equal to Configuration.EMPTY. |
Bryce Lee | 7fbeb8a | 2017-03-02 08:42:30 -0800 | [diff] [blame] | 1011 | task.mPreparedFrozenMergedConfig.unset(); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | /** |
| 1015 | * Unfreezes the previously frozen bounds. See {@link #freezeBounds}. |
| 1016 | */ |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 1017 | private void unfreezeBounds() { |
Wale Ogunwale | 37dbafc | 2016-06-27 10:15:20 -0700 | [diff] [blame] | 1018 | if (!mFrozenBounds.isEmpty()) { |
| 1019 | mFrozenBounds.remove(); |
| 1020 | } |
| 1021 | if (!mFrozenMergedConfig.isEmpty()) { |
| 1022 | mFrozenMergedConfig.remove(); |
| 1023 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1024 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1025 | final WindowState win = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1026 | win.onUnfreezeBounds(); |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1027 | } |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 1028 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 1029 | } |
| 1030 | |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1031 | void setAppLayoutChanges(int changes, String reason) { |
| 1032 | if (!mChildren.isEmpty()) { |
| 1033 | final DisplayContent dc = getDisplayContent(); |
| 1034 | dc.pendingLayoutChanges |= changes; |
| 1035 | if (DEBUG_LAYOUT_REPEATS) { |
| 1036 | mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1037 | } |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | void removeReplacedWindowIfNeeded(WindowState replacement) { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1042 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1043 | final WindowState win = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1044 | if (win.removeReplacedWindowIfNeeded(replacement)) { |
| 1045 | return; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1046 | } |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | void startFreezingScreen() { |
| 1051 | if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden=" |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1052 | + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested=" |
| 1053 | + hiddenRequested); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1054 | if (!hiddenRequested) { |
| 1055 | if (!mAppAnimator.freezingScreen) { |
| 1056 | mAppAnimator.freezingScreen = true; |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1057 | mService.registerAppFreezeListener(this); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1058 | mAppAnimator.lastFreezeDuration = 0; |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 1059 | mService.mAppsFreezingScreen++; |
| 1060 | if (mService.mAppsFreezingScreen == 1) { |
| 1061 | mService.startFreezingDisplayLocked(false, 0, 0); |
| 1062 | mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 1063 | mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1064 | } |
| 1065 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1066 | final int count = mChildren.size(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1067 | for (int i = 0; i < count; i++) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1068 | final WindowState w = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1069 | w.onStartFreezingScreen(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1070 | } |
| 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) { |
| 1075 | if (!mAppAnimator.freezingScreen) { |
| 1076 | return; |
| 1077 | } |
| 1078 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1079 | final int count = mChildren.size(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1080 | boolean unfrozeWindows = false; |
| 1081 | for (int i = 0; i < count; i++) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1082 | final WindowState w = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1083 | unfrozeWindows |= w.onStopFreezingScreen(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1084 | } |
| 1085 | if (force || unfrozeWindows) { |
| 1086 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this); |
| 1087 | mAppAnimator.freezingScreen = false; |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1088 | mService.unregisterAppFreezeListener(this); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1089 | mAppAnimator.lastFreezeDuration = |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 1090 | (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime); |
| 1091 | mService.mAppsFreezingScreen--; |
| 1092 | mService.mLastFinishedFreezeSource = this; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1093 | } |
| 1094 | if (unfreezeSurfaceNow) { |
| 1095 | if (unfrozeWindows) { |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 1096 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1097 | } |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 1098 | mService.stopFreezingDisplayLocked(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1099 | } |
| 1100 | } |
| 1101 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1102 | @Override |
| 1103 | public void onAppFreezeTimeout() { |
| 1104 | Slog.w(TAG_WM, "Force clearing freeze: " + this); |
| 1105 | stopFreezingScreen(true, true); |
| 1106 | } |
| 1107 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1108 | boolean transferStartingWindow(IBinder transferFrom) { |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1109 | final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1110 | if (fromToken == null) { |
| 1111 | return false; |
| 1112 | } |
| 1113 | |
| 1114 | final WindowState tStartingWindow = fromToken.startingWindow; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 1115 | if (tStartingWindow != null && fromToken.startingSurface != null) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1116 | // In this case, the starting icon has already been displayed, so start |
| 1117 | // letting windows get shown immediately without any more transitions. |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 1118 | mService.mSkipAppTransitionAnimation = true; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1119 | |
| 1120 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow |
| 1121 | + " from " + fromToken + " to " + this); |
| 1122 | |
| 1123 | final long origId = Binder.clearCallingIdentity(); |
| 1124 | |
| 1125 | // Transfer the starting window over to the new token. |
| 1126 | startingData = fromToken.startingData; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 1127 | startingSurface = fromToken.startingSurface; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1128 | startingDisplayed = fromToken.startingDisplayed; |
| 1129 | fromToken.startingDisplayed = false; |
| 1130 | startingWindow = tStartingWindow; |
| 1131 | reportedVisible = fromToken.reportedVisible; |
| 1132 | fromToken.startingData = null; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 1133 | fromToken.startingSurface = null; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1134 | fromToken.startingWindow = null; |
| 1135 | fromToken.startingMoved = true; |
| 1136 | tStartingWindow.mToken = this; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1137 | tStartingWindow.mAppToken = this; |
| 1138 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 1139 | if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1140 | "Removing starting " + tStartingWindow + " from " + fromToken); |
Wale Ogunwale | fa854eb | 2016-09-20 13:43:52 -0700 | [diff] [blame] | 1141 | fromToken.removeChild(tStartingWindow); |
| 1142 | fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow); |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 1143 | addWindow(tStartingWindow); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1144 | |
| 1145 | // Propagate other interesting state between the tokens. If the old token is displayed, |
| 1146 | // we should immediately force the new one to be displayed. If it is animating, we need |
| 1147 | // to move that animation to the new one. |
| 1148 | if (fromToken.allDrawn) { |
| 1149 | allDrawn = true; |
| 1150 | deferClearAllDrawn = fromToken.deferClearAllDrawn; |
| 1151 | } |
| 1152 | if (fromToken.firstWindowDrawn) { |
| 1153 | firstWindowDrawn = true; |
| 1154 | } |
| 1155 | if (!fromToken.hidden) { |
| 1156 | hidden = false; |
| 1157 | hiddenRequested = false; |
| 1158 | } |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame^] | 1159 | setClientHidden(fromToken.mClientHidden); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1160 | fromToken.mAppAnimator.transferCurrentAnimation( |
| 1161 | mAppAnimator, tStartingWindow.mWinAnimator); |
| 1162 | |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 1163 | mService.updateFocusedWindowLocked( |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1164 | UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 1165 | getDisplayContent().setLayoutNeeded(); |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 1166 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1167 | Binder.restoreCallingIdentity(origId); |
| 1168 | return true; |
| 1169 | } else if (fromToken.startingData != null) { |
| 1170 | // The previous app was getting ready to show a |
| 1171 | // starting window, but hasn't yet done so. Steal it! |
| 1172 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, |
| 1173 | "Moving pending starting from " + fromToken + " to " + this); |
| 1174 | startingData = fromToken.startingData; |
| 1175 | fromToken.startingData = null; |
| 1176 | fromToken.startingMoved = true; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 1177 | if (getController() != null) { |
| 1178 | getController().scheduleAddStartingWindow(); |
| 1179 | } |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1180 | return true; |
| 1181 | } |
| 1182 | |
| 1183 | final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator; |
| 1184 | final AppWindowAnimator wAppAnimator = mAppAnimator; |
| 1185 | if (tAppAnimator.thumbnail != null) { |
| 1186 | // The old token is animating with a thumbnail, transfer that to the new token. |
| 1187 | if (wAppAnimator.thumbnail != null) { |
| 1188 | wAppAnimator.thumbnail.destroy(); |
| 1189 | } |
| 1190 | wAppAnimator.thumbnail = tAppAnimator.thumbnail; |
| 1191 | wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer; |
| 1192 | wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation; |
| 1193 | tAppAnimator.thumbnail = null; |
| 1194 | } |
| 1195 | return false; |
| 1196 | } |
| 1197 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1198 | boolean isLastWindow(WindowState win) { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1199 | return mChildren.size() == 1 && mChildren.get(0) == win; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | void setAllAppWinAnimators() { |
| 1203 | final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators; |
| 1204 | allAppWinAnimators.clear(); |
| 1205 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1206 | final int windowsCount = mChildren.size(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1207 | for (int j = 0; j < windowsCount; j++) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1208 | (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1209 | } |
| 1210 | } |
| 1211 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1212 | @Override |
| 1213 | void onAppTransitionDone() { |
| 1214 | sendingToBottom = false; |
| 1215 | } |
| 1216 | |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1217 | /** |
| 1218 | * We override because this class doesn't want its children affecting its reported orientation |
| 1219 | * in anyway. |
| 1220 | */ |
| 1221 | @Override |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 1222 | int getOrientation(int candidate) { |
| 1223 | if (!fillsParent()) { |
| 1224 | // Can't specify orientation if app doesn't fill parent. |
| 1225 | return SCREEN_ORIENTATION_UNSET; |
| 1226 | } |
| 1227 | |
| 1228 | if (candidate == SCREEN_ORIENTATION_BEHIND) { |
| 1229 | // Allow app to specify orientation regardless of its visibility state if the current |
| 1230 | // candidate want us to use orientation behind. I.e. the visible app on-top of this one |
| 1231 | // wants us to use the orientation of the app behind it. |
| 1232 | return mOrientation; |
| 1233 | } |
| 1234 | |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 1235 | // The {@link AppWindowToken} should only specify an orientation when it is not closing or |
| 1236 | // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to |
| 1237 | // an Activity in another task being started in the wrong orientation during the transition. |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 1238 | if (!(sendingToBottom || mService.mClosingApps.contains(this)) |
Bryce Lee | 61fbcbc | 2017-03-10 14:14:03 -0800 | [diff] [blame] | 1239 | && (isVisible() || mService.mOpeningApps.contains(this))) { |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1240 | return mOrientation; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1241 | } |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1242 | |
| 1243 | return SCREEN_ORIENTATION_UNSET; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
Wale Ogunwale | b198b74 | 2016-12-01 08:44:09 -0800 | [diff] [blame] | 1246 | /** Returns the app's preferred orientation regardless of its currently visibility state. */ |
| 1247 | int getOrientationIgnoreVisibility() { |
| 1248 | return mOrientation; |
| 1249 | } |
| 1250 | |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 1251 | @Override |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1252 | void checkAppWindowsReadyToShow() { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1253 | if (allDrawn == mAppAnimator.allDrawn) { |
| 1254 | return; |
| 1255 | } |
| 1256 | |
| 1257 | mAppAnimator.allDrawn = allDrawn; |
| 1258 | if (!allDrawn) { |
| 1259 | return; |
| 1260 | } |
| 1261 | |
| 1262 | // The token has now changed state to having all windows shown... what to do, what to do? |
| 1263 | if (mAppAnimator.freezingScreen) { |
| 1264 | mAppAnimator.showAllWindowsLocked(); |
| 1265 | stopFreezingScreen(false, true); |
| 1266 | if (DEBUG_ORIENTATION) Slog.i(TAG, |
| 1267 | "Setting mOrientationChangeComplete=true because wtoken " + this |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1268 | + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1269 | // This will set mOrientationChangeComplete and cause a pass through layout. |
| 1270 | setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER, |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1271 | "checkAppWindowsReadyToShow: freezingScreen"); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1272 | } else { |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1273 | setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow"); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1274 | |
| 1275 | // We can now show all of the drawn windows! |
| 1276 | if (!mService.mOpeningApps.contains(this)) { |
| 1277 | mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked()); |
| 1278 | } |
| 1279 | } |
| 1280 | } |
| 1281 | |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1282 | void updateAllDrawn(DisplayContent dc) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1283 | if (!allDrawn) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1284 | final int numInteresting = mNumInterestingWindows; |
| 1285 | if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1286 | if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1287 | + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1288 | allDrawn = true; |
| 1289 | // Force an additional layout pass where |
| 1290 | // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked(). |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1291 | dc.setLayoutNeeded(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1292 | mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget(); |
Robert Carr | ecc06b3 | 2017-04-18 14:25:10 -0700 | [diff] [blame] | 1293 | |
| 1294 | final TaskStack s = getStack(); |
| 1295 | if (s != null) { |
| 1296 | s.onAllWindowsDrawn(); |
| 1297 | } |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1298 | } |
| 1299 | } |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1300 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1301 | if (!allDrawnExcludingSaved) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1302 | int numInteresting = mNumInterestingWindowsExcludingSaved; |
| 1303 | if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1304 | if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this |
| 1305 | + " interesting=" + numInteresting |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1306 | + " drawn=" + mNumDrawnWindowsExcludingSaved); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1307 | allDrawnExcludingSaved = true; |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1308 | dc.setLayoutNeeded(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1309 | if (isAnimatingInvisibleWithSavedSurface() |
| 1310 | && !mService.mFinishedEarlyAnim.contains(this)) { |
| 1311 | mService.mFinishedEarlyAnim.add(this); |
| 1312 | } |
| 1313 | } |
| 1314 | } |
| 1315 | } |
| 1316 | |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1317 | /** |
| 1318 | * Updated this app token tracking states for interesting and drawn windows based on the window. |
| 1319 | * |
| 1320 | * @return Returns true if the input window is considered interesting and drawn while all the |
| 1321 | * windows in this app token where not considered drawn as of the last pass. |
| 1322 | */ |
| 1323 | boolean updateDrawnWindowStates(WindowState w) { |
| 1324 | if (DEBUG_STARTING_WINDOW && w == startingWindow) { |
| 1325 | Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen() |
| 1326 | + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen); |
| 1327 | } |
| 1328 | |
| 1329 | if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) { |
| 1330 | return false; |
| 1331 | } |
| 1332 | |
| 1333 | if (mLastTransactionSequence != mService.mTransactionSequence) { |
| 1334 | mLastTransactionSequence = mService.mTransactionSequence; |
| 1335 | mNumInterestingWindows = mNumDrawnWindows = 0; |
| 1336 | mNumInterestingWindowsExcludingSaved = 0; |
| 1337 | mNumDrawnWindowsExcludingSaved = 0; |
| 1338 | startingDisplayed = false; |
| 1339 | } |
| 1340 | |
| 1341 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 1342 | |
| 1343 | boolean isInterestingAndDrawn = false; |
| 1344 | |
| 1345 | if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) { |
| 1346 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| 1347 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw() |
| 1348 | + ", isAnimationSet=" + winAnimator.isAnimationSet()); |
| 1349 | if (!w.isDrawnLw()) { |
| 1350 | Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController |
| 1351 | + " pv=" + w.mPolicyVisibility |
| 1352 | + " mDrawState=" + winAnimator.drawStateToString() |
| 1353 | + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested |
| 1354 | + " a=" + winAnimator.mAnimating); |
| 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | if (w != startingWindow) { |
| 1359 | if (w.isInteresting()) { |
| 1360 | mNumInterestingWindows++; |
| 1361 | if (w.isDrawnLw()) { |
| 1362 | mNumDrawnWindows++; |
| 1363 | |
| 1364 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: " |
| 1365 | + this + " w=" + w + " numInteresting=" + mNumInterestingWindows |
| 1366 | + " freezingScreen=" + mAppAnimator.freezingScreen |
| 1367 | + " mAppFreezing=" + w.mAppFreezing); |
| 1368 | |
| 1369 | isInterestingAndDrawn = true; |
| 1370 | } |
| 1371 | } |
| 1372 | } else if (w.isDrawnLw()) { |
Jorim Jaggi | 3878ca3 | 2017-02-02 17:13:05 -0800 | [diff] [blame] | 1373 | if (getController() != null) { |
| 1374 | getController().reportStartingWindowDrawn(); |
| 1375 | } |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1376 | startingDisplayed = true; |
| 1377 | } |
| 1378 | } |
| 1379 | |
| 1380 | if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) { |
| 1381 | if (w != startingWindow && w.isInteresting()) { |
| 1382 | mNumInterestingWindowsExcludingSaved++; |
| 1383 | if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) { |
| 1384 | mNumDrawnWindowsExcludingSaved++; |
| 1385 | |
| 1386 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
| 1387 | "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w |
| 1388 | + " numInteresting=" + mNumInterestingWindowsExcludingSaved |
| 1389 | + " freezingScreen=" + mAppAnimator.freezingScreen |
| 1390 | + " mAppFreezing=" + w.mAppFreezing); |
| 1391 | |
| 1392 | isInterestingAndDrawn = true; |
| 1393 | } |
| 1394 | } |
| 1395 | } |
| 1396 | |
| 1397 | return isInterestingAndDrawn; |
| 1398 | } |
| 1399 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1400 | @Override |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1401 | void stepAppWindowsAnimation(long currentTime) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1402 | mAppAnimator.wasAnimating = mAppAnimator.animating; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1403 | if (mAppAnimator.stepAnimationLocked(currentTime)) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1404 | mAppAnimator.animating = true; |
| 1405 | mService.mAnimator.setAnimating(true); |
| 1406 | mService.mAnimator.mAppWindowAnimating = true; |
| 1407 | } else if (mAppAnimator.wasAnimating) { |
| 1408 | // stopped animating, do one more pass through the layout |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 1409 | setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER, |
| 1410 | DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1411 | if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this); |
| 1412 | } |
| 1413 | } |
| 1414 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1415 | @Override |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 1416 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 1417 | // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent |
| 1418 | // before the non-exiting app tokens. So, we skip the exiting app tokens here. |
| 1419 | // TODO: Investigate if we need to continue to do this or if we can just process them |
| 1420 | // in-order. |
| 1421 | if (mIsExiting && !waitingForReplacement()) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 1422 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 1423 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 1424 | return forAllWindowsUnchecked(callback, traverseTopToBottom); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 1427 | boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback, |
| 1428 | boolean traverseTopToBottom) { |
| 1429 | return super.forAllWindows(callback, traverseTopToBottom); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | @Override |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 1433 | AppWindowToken asAppWindowToken() { |
| 1434 | // I am an app window token! |
| 1435 | return this; |
| 1436 | } |
| 1437 | |
| 1438 | @Override |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1439 | boolean fillsParent() { |
| 1440 | return mFillsParent; |
| 1441 | } |
| 1442 | |
| 1443 | void setFillsParent(boolean fillsParent) { |
| 1444 | mFillsParent = fillsParent; |
| 1445 | } |
| 1446 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1447 | boolean containsDismissKeyguardWindow() { |
| 1448 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 1449 | if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) { |
| 1450 | return true; |
| 1451 | } |
| 1452 | } |
| 1453 | return false; |
| 1454 | } |
| 1455 | |
| 1456 | boolean containsShowWhenLockedWindow() { |
| 1457 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 1458 | if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) { |
| 1459 | return true; |
| 1460 | } |
| 1461 | } |
| 1462 | return false; |
| 1463 | } |
| 1464 | |
| 1465 | void checkKeyguardFlagsChanged() { |
| 1466 | final boolean containsDismissKeyguard = containsDismissKeyguardWindow(); |
| 1467 | final boolean containsShowWhenLocked = containsShowWhenLockedWindow(); |
| 1468 | if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow |
| 1469 | || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) { |
| 1470 | mService.notifyKeyguardFlagsChanged(null /* callback */); |
| 1471 | } |
| 1472 | mLastContainsDismissKeyguardWindow = containsDismissKeyguard; |
| 1473 | mLastContainsShowWhenLockedWindow = containsShowWhenLocked; |
| 1474 | } |
| 1475 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 1476 | WindowState getImeTargetBelowWindow(WindowState w) { |
| 1477 | final int index = mChildren.indexOf(w); |
| 1478 | if (index > 0) { |
| 1479 | final WindowState target = mChildren.get(index - 1); |
| 1480 | if (target.canBeImeTarget()) { |
| 1481 | return target; |
| 1482 | } |
| 1483 | } |
| 1484 | return null; |
| 1485 | } |
| 1486 | |
| 1487 | WindowState getHighestAnimLayerWindow(WindowState currentTarget) { |
| 1488 | WindowState candidate = null; |
| 1489 | for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) { |
| 1490 | final WindowState w = mChildren.get(i); |
| 1491 | if (w.mRemoved) { |
| 1492 | continue; |
| 1493 | } |
| 1494 | if (candidate == null || w.mWinAnimator.mAnimLayer > |
| 1495 | candidate.mWinAnimator.mAnimLayer) { |
| 1496 | candidate = w; |
| 1497 | } |
| 1498 | } |
| 1499 | return candidate; |
| 1500 | } |
| 1501 | |
Jorim Jaggi | 0fe7ce96 | 2017-02-22 16:45:48 +0100 | [diff] [blame] | 1502 | void setDisablePreviewSnapshots(boolean disable) { |
| 1503 | mDisbalePreviewScreenshots = disable; |
| 1504 | } |
| 1505 | |
| 1506 | boolean shouldDisablePreviewScreenshots() { |
| 1507 | return mDisbalePreviewScreenshots; |
| 1508 | } |
| 1509 | |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1510 | @Override |
Robert Carr | dee1b3f | 2017-02-27 11:33:33 -0800 | [diff] [blame] | 1511 | int getAnimLayerAdjustment() { |
| 1512 | return mAppAnimator.animLayerAdjustment; |
| 1513 | } |
| 1514 | |
| 1515 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1516 | void dump(PrintWriter pw, String prefix) { |
| 1517 | super.dump(pw, prefix); |
| 1518 | if (appToken != null) { |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 1519 | pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1520 | } |
Bryce Lee | 7fbeb8a | 2017-03-02 08:42:30 -0800 | [diff] [blame] | 1521 | pw.print(prefix); pw.print("task="); pw.println(getTask()); |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1522 | pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent); |
| 1523 | pw.print(" mOrientation="); pw.println(mOrientation); |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame^] | 1524 | pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden |
| 1525 | + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "") |
| 1526 | + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1527 | if (paused) { |
| 1528 | pw.print(prefix); pw.print("paused="); pw.println(paused); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1529 | } |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 1530 | if (mAppStopped) { |
| 1531 | pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped); |
| 1532 | } |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1533 | if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0 |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1534 | || allDrawn || mAppAnimator.allDrawn) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1535 | pw.print(prefix); pw.print("mNumInterestingWindows="); |
| 1536 | pw.print(mNumInterestingWindows); |
| 1537 | pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1538 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1539 | pw.print(" allDrawn="); pw.print(allDrawn); |
| 1540 | pw.print(" (animator="); pw.print(mAppAnimator.allDrawn); |
| 1541 | pw.println(")"); |
| 1542 | } |
| 1543 | if (inPendingTransaction) { |
| 1544 | pw.print(prefix); pw.print("inPendingTransaction="); |
| 1545 | pw.println(inPendingTransaction); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1546 | } |
Craig Mautner | 799bc1d | 2015-01-14 10:33:48 -0800 | [diff] [blame] | 1547 | if (startingData != null || removed || firstWindowDrawn || mIsExiting) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1548 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 1549 | pw.print(" removed="); pw.print(removed); |
Craig Mautner | 3d7ca31 | 2015-01-08 10:56:00 -0800 | [diff] [blame] | 1550 | pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn); |
Craig Mautner | 799bc1d | 2015-01-14 10:33:48 -0800 | [diff] [blame] | 1551 | pw.print(" mIsExiting="); pw.println(mIsExiting); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1552 | } |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 1553 | if (startingWindow != null || startingSurface != null |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1554 | || startingDisplayed || startingMoved) { |
| 1555 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 1556 | pw.print(" startingSurface="); pw.print(startingSurface); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1557 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 1558 | pw.print(" startingMoved="); pw.println(startingMoved); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1559 | } |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 1560 | if (!mFrozenBounds.isEmpty()) { |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 1561 | pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 1562 | pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig); |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 1563 | } |
| 1564 | if (mPendingRelaunchCount != 0) { |
| 1565 | pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 1566 | } |
Wale Ogunwale | 9c64cb6 | 2017-04-12 13:39:59 -0700 | [diff] [blame] | 1567 | if (getController() != null) { |
| 1568 | pw.print(prefix); pw.print("controller="); pw.println(getController()); |
| 1569 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | @Override |
| 1573 | public String toString() { |
| 1574 | if (stringName == null) { |
| 1575 | StringBuilder sb = new StringBuilder(); |
| 1576 | sb.append("AppWindowToken{"); |
| 1577 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 1578 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 1579 | stringName = sb.toString(); |
| 1580 | } |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1581 | return stringName + ((mIsExiting) ? " mIsExiting=" : ""); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1582 | } |
Jeff Brown | e9bdb31 | 2012-04-05 15:30:10 -0700 | [diff] [blame] | 1583 | } |