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