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