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