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; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 20 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 21 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
| 22 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 23 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 24 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 25 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
| 26 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT; |
| 27 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 28 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 29 | import static com.android.server.wm.WindowManagerService.WINDOW_REPLACEMENT_TIMEOUT_DURATION; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 30 | import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 31 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 32 | import com.android.server.input.InputApplicationHandle; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 33 | import com.android.server.wm.WindowManagerService.H; |
| 34 | |
Filip Gruszczynski | a590c99 | 2015-11-25 16:45:26 -0800 | [diff] [blame] | 35 | import android.annotation.NonNull; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 36 | import android.content.pm.ActivityInfo; |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 37 | import android.content.res.Configuration; |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 38 | import android.graphics.Rect; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 39 | import android.os.Message; |
| 40 | import android.os.RemoteException; |
| 41 | import android.util.Slog; |
| 42 | import android.view.IApplicationToken; |
| 43 | import android.view.View; |
| 44 | import android.view.WindowManager; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 45 | |
| 46 | import java.io.PrintWriter; |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 47 | import java.util.ArrayDeque; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 48 | import java.util.ArrayList; |
| 49 | |
| 50 | class AppTokenList extends ArrayList<AppWindowToken> { |
| 51 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * Version of WindowToken that is specifically for a particular application (or |
| 55 | * really activity) that is displaying windows. |
| 56 | */ |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 57 | class AppWindowToken extends WindowToken { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 58 | private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM; |
| 59 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 60 | // Non-null only for application tokens. |
| 61 | final IApplicationToken appToken; |
| 62 | |
| 63 | // All of the windows and child windows that are included in this |
| 64 | // application token. Note this list is NOT sorted! |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 65 | final WindowList allAppWindows = new WindowList(); |
Filip Gruszczynski | a590c99 | 2015-11-25 16:45:26 -0800 | [diff] [blame] | 66 | @NonNull final AppWindowAnimator mAppAnimator; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 67 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 68 | final boolean voiceInteraction; |
| 69 | |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 70 | Task mTask; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 71 | boolean appFullscreen; |
| 72 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Craig Mautner | 4c5eb22 | 2013-11-18 12:59:05 -0800 | [diff] [blame] | 73 | boolean layoutConfigChanges; |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 74 | boolean showForAllUsers; |
Yorke Lee | 0e85247 | 2016-06-15 10:03:18 -0700 | [diff] [blame] | 75 | int targetSdk; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 76 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 77 | // The input dispatching timeout for this application token in nanoseconds. |
| 78 | long inputDispatchingTimeoutNanos; |
| 79 | |
| 80 | // These are used for determining when all windows associated with |
| 81 | // an activity have been drawn, so they can be made visible together |
| 82 | // at the same time. |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 83 | // initialize so that it doesn't match mTransactionSequence which is an int. |
| 84 | long lastTransactionSequence = Long.MIN_VALUE; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 85 | int numInterestingWindows; |
| 86 | int numDrawnWindows; |
| 87 | boolean inPendingTransaction; |
| 88 | boolean allDrawn; |
Craig Mautner | 7636dfb | 2012-11-16 15:24:11 -0800 | [diff] [blame] | 89 | // Set to true when this app creates a surface while in the middle of an animation. In that |
| 90 | // case do not clear allDrawn until the animation completes. |
| 91 | boolean deferClearAllDrawn; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 92 | |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 93 | // These are to track the app's real drawing status if there were no saved surfaces. |
| 94 | boolean allDrawnExcludingSaved; |
| 95 | int numInterestingWindowsExcludingSaved; |
| 96 | int numDrawnWindowsExclusingSaved; |
| 97 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 98 | // Is this window's surface needed? This is almost like hidden, except |
| 99 | // it will sometimes be true a little earlier: when the token has |
| 100 | // been shown, but is still waiting for its app transition to execute |
| 101 | // before making its windows shown. |
| 102 | boolean hiddenRequested; |
| 103 | |
| 104 | // Have we told the window clients to hide themselves? |
| 105 | boolean clientHidden; |
| 106 | |
| 107 | // Last visibility state we reported to the app token. |
| 108 | boolean reportedVisible; |
| 109 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 110 | // Last drawn state we reported to the app token. |
| 111 | boolean reportedDrawn; |
| 112 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 113 | // Set to true when the token has been removed from the window mgr. |
| 114 | boolean removed; |
| 115 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 116 | // Information about an application starting window if displayed. |
| 117 | StartingData startingData; |
| 118 | WindowState startingWindow; |
| 119 | View startingView; |
| 120 | boolean startingDisplayed; |
| 121 | boolean startingMoved; |
| 122 | boolean firstWindowDrawn; |
| 123 | |
| 124 | // Input application handle used by the input dispatcher. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 125 | final InputApplicationHandle mInputApplicationHandle; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 126 | |
Craig Mautner | 799bc1d | 2015-01-14 10:33:48 -0800 | [diff] [blame] | 127 | boolean mIsExiting; |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 128 | |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 129 | boolean mLaunchTaskBehind; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 130 | boolean mEnteringAnimation; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 131 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 132 | boolean mAlwaysFocusable; |
| 133 | |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 134 | boolean mAppStopped; |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 135 | int mRotationAnimationHint; |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 136 | int mPendingRelaunchCount; |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 137 | |
Robert Carr | 91b22809 | 2016-06-28 17:32:37 -0700 | [diff] [blame] | 138 | private ArrayList<WindowSurfaceController.SurfaceControlWithBackground> mSurfaceViewBackgrounds = |
| 139 | new ArrayList<WindowSurfaceController.SurfaceControlWithBackground>(); |
| 140 | |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 141 | ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>(); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 142 | ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>(); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 143 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 144 | AppWindowToken(WindowManagerService _service, IApplicationToken _token, |
| 145 | boolean _voiceInteraction) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 146 | super(_service, _token.asBinder(), |
| 147 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 148 | appWindowToken = this; |
| 149 | appToken = _token; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 150 | voiceInteraction = _voiceInteraction; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 151 | mInputApplicationHandle = new InputApplicationHandle(this); |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 152 | mAppAnimator = new AppWindowAnimator(this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | void sendAppVisibilityToClients() { |
| 156 | final int N = allAppWindows.size(); |
| 157 | for (int i=0; i<N; i++) { |
| 158 | WindowState win = allAppWindows.get(i); |
| 159 | if (win == startingWindow && clientHidden) { |
| 160 | // Don't hide the starting window. |
| 161 | continue; |
| 162 | } |
| 163 | try { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 164 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 165 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 166 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 167 | } catch (RemoteException e) { |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 172 | void setVisibleBeforeClientHidden() { |
| 173 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 174 | final WindowState w = allAppWindows.get(i); |
| 175 | w.setVisibleBeforeClientHidden(); |
| 176 | } |
| 177 | } |
| 178 | |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 179 | void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) { |
| 180 | firstWindowDrawn = true; |
| 181 | |
| 182 | // We now have a good window to show, remove dead placeholders |
| 183 | removeAllDeadWindows(); |
| 184 | |
| 185 | if (startingData != null) { |
| 186 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting " |
| 187 | + win.mToken + ": first real window is shown, no animation"); |
| 188 | // If this initial window is animating, stop it -- we will do an animation to reveal |
| 189 | // it from behind the starting window, so there is no need for it to also be doing its |
| 190 | // own stuff. |
| 191 | winAnimator.clearAnimation(); |
| 192 | winAnimator.mService.mFinishedStarting.add(this); |
| 193 | winAnimator.mService.mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 194 | } |
| 195 | updateReportedVisibilityLocked(); |
| 196 | } |
| 197 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 198 | void updateReportedVisibilityLocked() { |
| 199 | if (appToken == null) { |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | int numInteresting = 0; |
| 204 | int numVisible = 0; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 205 | int numDrawn = 0; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 206 | boolean nowGone = true; |
| 207 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 208 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 209 | "Update reported visibility: " + this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 210 | final int N = allAppWindows.size(); |
| 211 | for (int i=0; i<N; i++) { |
| 212 | WindowState win = allAppWindows.get(i); |
| 213 | if (win == startingWindow || win.mAppFreezing |
| 214 | || win.mViewVisibility != View.VISIBLE |
| 215 | || win.mAttrs.type == TYPE_APPLICATION_STARTING |
| 216 | || win.mDestroying) { |
| 217 | continue; |
| 218 | } |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 219 | if (DEBUG_VISIBILITY) { |
| 220 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 221 | + win.isDrawnLw() |
Jorim Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 222 | + ", isAnimationSet=" + win.mWinAnimator.isAnimationSet()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 223 | if (!win.isDrawnLw()) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 224 | Slog.v(TAG, "Not displayed: s=" + |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 225 | win.mWinAnimator.mSurfaceController |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 226 | + " pv=" + win.mPolicyVisibility |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 227 | + " mDrawState=" + win.mWinAnimator.mDrawState |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 228 | + " ah=" + win.mAttachedHidden |
| 229 | + " th=" |
| 230 | + (win.mAppToken != null |
| 231 | ? win.mAppToken.hiddenRequested : false) |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 232 | + " a=" + win.mWinAnimator.mAnimating); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | numInteresting++; |
| 236 | if (win.isDrawnLw()) { |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 237 | numDrawn++; |
Jorim Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 238 | if (!win.mWinAnimator.isAnimationSet()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 239 | numVisible++; |
| 240 | } |
| 241 | nowGone = false; |
Jorim Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 242 | } else if (win.mWinAnimator.isAnimationSet()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 243 | nowGone = false; |
| 244 | } |
| 245 | } |
| 246 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 247 | boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 248 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 249 | if (!nowGone) { |
| 250 | // If the app is not yet gone, then it can only become visible/drawn. |
| 251 | if (!nowDrawn) { |
| 252 | nowDrawn = reportedDrawn; |
| 253 | } |
| 254 | if (!nowVisible) { |
| 255 | nowVisible = reportedVisible; |
| 256 | } |
| 257 | } |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 258 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 259 | + numInteresting + " visible=" + numVisible); |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 260 | if (nowDrawn != reportedDrawn) { |
| 261 | if (nowDrawn) { |
| 262 | Message m = service.mH.obtainMessage( |
| 263 | H.REPORT_APPLICATION_TOKEN_DRAWN, this); |
| 264 | service.mH.sendMessage(m); |
| 265 | } |
| 266 | reportedDrawn = nowDrawn; |
| 267 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 268 | if (nowVisible != reportedVisible) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 269 | if (DEBUG_VISIBILITY) Slog.v( |
| 270 | TAG, "Visibility changed in " + this |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 271 | + ": vis=" + nowVisible); |
| 272 | reportedVisible = nowVisible; |
| 273 | Message m = service.mH.obtainMessage( |
| 274 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 275 | nowVisible ? 1 : 0, |
| 276 | nowGone ? 1 : 0, |
| 277 | this); |
| 278 | service.mH.sendMessage(m); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | WindowState findMainWindow() { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 283 | WindowState candidate = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 284 | int j = windows.size(); |
| 285 | while (j > 0) { |
| 286 | j--; |
| 287 | WindowState win = windows.get(j); |
| 288 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 289 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 290 | // 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] | 291 | // happens for example when replacing windows during an activity relaunch. When |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 292 | // constructing the animation, we want the new window, not the exiting one. |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 293 | if (win.mAnimatingExit) { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 294 | candidate = win; |
| 295 | } else { |
| 296 | return win; |
| 297 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 298 | } |
| 299 | } |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 300 | return candidate; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 301 | } |
| 302 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 303 | boolean windowsAreFocusable() { |
| 304 | return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable; |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 305 | } |
| 306 | |
Craig Mautner | 72669d1 | 2012-12-18 17:23:54 -0800 | [diff] [blame] | 307 | boolean isVisible() { |
| 308 | final int N = allAppWindows.size(); |
Craig Mautner | 72669d1 | 2012-12-18 17:23:54 -0800 | [diff] [blame] | 309 | for (int i=0; i<N; i++) { |
| 310 | WindowState win = allAppWindows.get(i); |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 311 | // If we're animating with a saved surface, we're already visible. |
| 312 | // Return true so that the alpha doesn't get cleared. |
Craig Mautner | 72669d1 | 2012-12-18 17:23:54 -0800 | [diff] [blame] | 313 | if (!win.mAppFreezing |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 314 | && (win.mViewVisibility == View.VISIBLE || win.isAnimatingWithSavedSurface() |
Jorim Jaggi | 5c80c41 | 2016-04-19 20:03:47 -0700 | [diff] [blame] | 315 | || (win.mWinAnimator.isAnimationSet() |
Filip Gruszczynski | 57f76f1 | 2015-11-04 16:10:54 -0800 | [diff] [blame] | 316 | && !service.mAppTransition.isTransitionSet())) |
| 317 | && !win.mDestroying |
| 318 | && win.isDrawnLw()) { |
Craig Mautner | 72669d1 | 2012-12-18 17:23:54 -0800 | [diff] [blame] | 319 | return true; |
| 320 | } |
| 321 | } |
| 322 | return false; |
| 323 | } |
| 324 | |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 325 | void removeAppFromTaskLocked() { |
| 326 | mIsExiting = false; |
| 327 | removeAllWindows(); |
| 328 | |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 329 | // Use local variable because removeAppToken will null out mTask. |
| 330 | final Task task = mTask; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 331 | if (task != null) { |
| 332 | if (!task.removeAppToken(this)) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 333 | Slog.e(TAG, "removeAppFromTaskLocked: token=" + this |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 334 | + " not found."); |
| 335 | } |
| 336 | task.mStack.mExitingAppTokens.remove(this); |
| 337 | } |
| 338 | } |
| 339 | |
Chong Zhang | e05bcb1 | 2016-07-26 17:47:29 -0700 | [diff] [blame^] | 340 | void clearAnimatingFlags() { |
| 341 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 342 | final WindowState win = allAppWindows.get(i); |
| 343 | // We don't want to clear it out for windows that get replaced, because the |
| 344 | // animation depends on the flag to remove the replaced window. |
| 345 | // |
| 346 | // We also don't clear the mAnimatingExit flag for windows which have the |
| 347 | // mRemoveOnExit flag. This indicates an explicit remove request has been issued |
| 348 | // by the client. We should let animation proceed and not clear this flag or |
| 349 | // they won't eventually be removed by WindowStateAnimator#finishExit. |
| 350 | if (!win.mWillReplaceWindow && !win.mRemoveOnExit) { |
| 351 | win.mAnimatingExit = false; |
| 352 | // Clear mAnimating flag together with mAnimatingExit. When animation |
| 353 | // changes from exiting to entering, we need to clear this flag until the |
| 354 | // new animation gets applied, so that isAnimationStarting() becomes true |
| 355 | // until then. |
| 356 | // Otherwise applySurfaceChangesTransaction will faill to skip surface |
| 357 | // placement for this window during this period, one or more frame will |
| 358 | // show up with wrong position or scale. |
| 359 | win.mWinAnimator.mAnimating = false; |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 364 | void destroySurfaces() { |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 365 | destroySurfaces(false /*cleanupOnResume*/); |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure |
| 370 | * the client has finished with them. |
| 371 | * |
| 372 | * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If |
| 373 | * set to true, destroy only surfaces of removed windows, and clear relevant flags of the |
| 374 | * others so that they are ready to be reused. If set to false (common case), destroy all |
| 375 | * surfaces that's eligible, if the app is already stopped. |
| 376 | */ |
| 377 | |
| 378 | private void destroySurfaces(boolean cleanupOnResume) { |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 379 | final ArrayList<WindowState> allWindows = (ArrayList<WindowState>) allAppWindows.clone(); |
| 380 | final DisplayContentList displayList = new DisplayContentList(); |
| 381 | for (int i = allWindows.size() - 1; i >= 0; i--) { |
| 382 | final WindowState win = allWindows.get(i); |
Chong Zhang | eb66557 | 2016-05-09 18:28:27 -0700 | [diff] [blame] | 383 | |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 384 | if (!(mAppStopped || win.mWindowRemovalAllowed || cleanupOnResume)) { |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 385 | continue; |
| 386 | } |
| 387 | |
Chong Zhang | eb66557 | 2016-05-09 18:28:27 -0700 | [diff] [blame] | 388 | win.mWinAnimator.destroyPreservedSurfaceLocked(); |
| 389 | |
| 390 | if (!win.mDestroying) { |
Chong Zhang | 5471e90 | 2016-02-12 15:34:10 -0800 | [diff] [blame] | 391 | continue; |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 392 | } |
| 393 | |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 394 | if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + win |
| 395 | + " destroySurfaces: mAppStopped=" + mAppStopped |
| 396 | + " win.mWindowRemovalAllowed=" + win.mWindowRemovalAllowed |
| 397 | + " win.mRemoveOnExit=" + win.mRemoveOnExit); |
| 398 | |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 399 | if (!cleanupOnResume || win.mRemoveOnExit) { |
| 400 | win.destroyOrSaveSurface(); |
| 401 | } |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 402 | if (win.mRemoveOnExit) { |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 403 | service.removeWindowInnerLocked(win); |
| 404 | } |
| 405 | final DisplayContent displayContent = win.getDisplayContent(); |
| 406 | if (displayContent != null && !displayList.contains(displayContent)) { |
| 407 | displayList.add(displayContent); |
| 408 | } |
| 409 | win.mDestroying = false; |
| 410 | } |
| 411 | for (int i = 0; i < displayList.size(); i++) { |
| 412 | final DisplayContent displayContent = displayList.get(i); |
| 413 | service.mLayersController.assignLayersLocked(displayContent.getWindowList()); |
| 414 | displayContent.layoutNeeded = true; |
| 415 | } |
| 416 | } |
| 417 | |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 418 | /** |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 419 | * Notify that the app is now resumed, and it was not stopped before, perform a clean |
| 420 | * up of the surfaces |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 421 | */ |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 422 | void notifyAppResumed(boolean wasStopped) { |
| 423 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped + " " + this); |
| 424 | mAppStopped = false; |
| 425 | if (!wasStopped) { |
| 426 | destroySurfaces(true /*cleanupOnResume*/); |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 427 | } |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 428 | } |
| 429 | |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 430 | /** |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 431 | * Notify that the app has stopped, and it is okay to destroy any surfaces which were |
| 432 | * keeping alive in case they were still being used. |
| 433 | */ |
| 434 | void notifyAppStopped() { |
| 435 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this); |
| 436 | mAppStopped = true; |
| 437 | destroySurfaces(); |
| 438 | // Remove any starting window that was added for this app if they are still around. |
| 439 | mTask.mService.scheduleRemoveStartingWindowLocked(this); |
| 440 | } |
| 441 | |
| 442 | /** |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 443 | * Checks whether we should save surfaces for this app. |
| 444 | * |
| 445 | * @return true if the surfaces should be saved, false otherwise. |
| 446 | */ |
| 447 | boolean shouldSaveSurface() { |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 448 | // We want to save surface if the app's windows are "allDrawn". |
| 449 | // (If we started entering animation early with saved surfaces, allDrawn |
| 450 | // should have been restored to true. So we'll save again in that case |
| 451 | // even if app didn't actually finish drawing.) |
| 452 | return allDrawn; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 453 | } |
| 454 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 455 | boolean canRestoreSurfaces() { |
Chong Zhang | b7b4a56 | 2016-04-28 15:30:33 -0700 | [diff] [blame] | 456 | for (int i = allAppWindows.size() -1; i >= 0; i--) { |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 457 | final WindowState w = allAppWindows.get(i); |
| 458 | if (w.canRestoreSurface()) { |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 459 | return true; |
| 460 | } |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 461 | } |
| 462 | return false; |
| 463 | } |
| 464 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 465 | void clearVisibleBeforeClientHidden() { |
| 466 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 467 | final WindowState w = allAppWindows.get(i); |
| 468 | w.clearVisibleBeforeClientHidden(); |
| 469 | } |
| 470 | } |
| 471 | |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 472 | /** |
| 473 | * Whether the app has some window that is invisible in layout, but |
| 474 | * animating with saved surface. |
| 475 | */ |
| 476 | boolean isAnimatingInvisibleWithSavedSurface() { |
| 477 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 478 | final WindowState w = allAppWindows.get(i); |
| 479 | if (w.isAnimatingInvisibleWithSavedSurface()) { |
| 480 | return true; |
| 481 | } |
| 482 | } |
| 483 | return false; |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * Hide all window surfaces that's still invisible in layout but animating |
| 488 | * with a saved surface, and mark them destroying. |
| 489 | */ |
| 490 | void stopUsingSavedSurfaceLocked() { |
| 491 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 492 | final WindowState w = allAppWindows.get(i); |
| 493 | if (w.isAnimatingInvisibleWithSavedSurface()) { |
| 494 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, |
| 495 | "stopUsingSavedSurfaceLocked: " + w); |
| 496 | w.clearAnimatingWithSavedSurface(); |
| 497 | w.mDestroying = true; |
| 498 | w.mWinAnimator.hide("stopUsingSavedSurfaceLocked"); |
| 499 | w.mWinAnimator.mWallpaperControllerLocked.hideWallpapers(w); |
| 500 | } |
| 501 | } |
| 502 | destroySurfaces(); |
| 503 | } |
| 504 | |
Chong Zhang | f58631a | 2016-05-24 16:02:10 -0700 | [diff] [blame] | 505 | void markSavedSurfaceExiting() { |
| 506 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 507 | final WindowState w = allAppWindows.get(i); |
| 508 | if (w.isAnimatingInvisibleWithSavedSurface()) { |
| 509 | w.mAnimatingExit = true; |
| 510 | w.mWinAnimator.mAnimating = true; |
| 511 | } |
| 512 | } |
| 513 | } |
| 514 | |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 515 | void restoreSavedSurfaces() { |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 516 | if (!canRestoreSurfaces()) { |
| 517 | clearVisibleBeforeClientHidden(); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 518 | return; |
| 519 | } |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 520 | // Check if we have enough drawn windows to mark allDrawn= true. |
| 521 | int numInteresting = 0; |
| 522 | int numDrawn = 0; |
Chong Zhang | b7b4a56 | 2016-04-28 15:30:33 -0700 | [diff] [blame] | 523 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 524 | WindowState w = allAppWindows.get(i); |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 525 | if (w != startingWindow && !w.mAppDied && w.wasVisibleBeforeClientHidden() |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 526 | && (!mAppAnimator.freezingScreen || !w.mAppFreezing)) { |
| 527 | numInteresting++; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 528 | if (w.hasSavedSurface()) { |
| 529 | w.restoreSavedSurface(); |
| 530 | } |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 531 | if (w.isDrawnLw()) { |
| 532 | numDrawn++; |
| 533 | } |
| 534 | } |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 535 | } |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 536 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 537 | if (!allDrawn) { |
| 538 | allDrawn = (numInteresting > 0) && (numInteresting == numDrawn); |
| 539 | if (allDrawn) { |
| 540 | service.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget(); |
| 541 | } |
| 542 | } |
| 543 | clearVisibleBeforeClientHidden(); |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 544 | |
| 545 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 546 | "restoreSavedSurfaces: " + appWindowToken + " allDrawn=" + allDrawn |
| 547 | + " numInteresting=" + numInteresting + " numDrawn=" + numDrawn); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | void destroySavedSurfaces() { |
Chong Zhang | b7b4a56 | 2016-04-28 15:30:33 -0700 | [diff] [blame] | 551 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 552 | WindowState win = allAppWindows.get(i); |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 553 | win.destroySavedSurface(); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 554 | } |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | void clearAllDrawn() { |
| 558 | allDrawn = false; |
| 559 | deferClearAllDrawn = false; |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 560 | allDrawnExcludingSaved = false; |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Wale Ogunwale | 98e70d0 | 2014-11-10 12:12:27 -0800 | [diff] [blame] | 563 | @Override |
Craig Mautner | 7c9ee19 | 2014-08-14 16:08:26 -0700 | [diff] [blame] | 564 | void removeAllWindows() { |
Craig Mautner | 7b4655d | 2014-11-20 12:13:22 -0800 | [diff] [blame] | 565 | for (int winNdx = allAppWindows.size() - 1; winNdx >= 0; |
| 566 | // removeWindowLocked at bottom of loop may remove multiple entries from |
| 567 | // allAppWindows if the window to be removed has child windows. It also may |
| 568 | // not remove any windows from allAppWindows at all if win is exiting and |
| 569 | // currently animating away. This ensures that winNdx is monotonically decreasing |
| 570 | // and never beyond allAppWindows bounds. |
| 571 | winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) { |
| 572 | WindowState win = allAppWindows.get(winNdx); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 573 | if (DEBUG_WINDOW_MOVEMENT) { |
| 574 | Slog.w(TAG, "removeAllWindows: removing win=" + win); |
Wale Ogunwale | 98e70d0 | 2014-11-10 12:12:27 -0800 | [diff] [blame] | 575 | } |
| 576 | |
Wale Ogunwale | a6ab5c4 | 2015-04-24 09:00:25 -0700 | [diff] [blame] | 577 | service.removeWindowLocked(win); |
Craig Mautner | 7c9ee19 | 2014-08-14 16:08:26 -0700 | [diff] [blame] | 578 | } |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 579 | allAppWindows.clear(); |
| 580 | windows.clear(); |
Craig Mautner | 7c9ee19 | 2014-08-14 16:08:26 -0700 | [diff] [blame] | 581 | } |
| 582 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 583 | void removeAllDeadWindows() { |
| 584 | for (int winNdx = allAppWindows.size() - 1; winNdx >= 0; |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 585 | // removeWindowLocked at bottom of loop may remove multiple entries from |
| 586 | // allAppWindows if the window to be removed has child windows. It also may |
| 587 | // not remove any windows from allAppWindows at all if win is exiting and |
| 588 | // currently animating away. This ensures that winNdx is monotonically decreasing |
| 589 | // and never beyond allAppWindows bounds. |
| 590 | winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 591 | WindowState win = allAppWindows.get(winNdx); |
| 592 | if (win.mAppDied) { |
Wale Ogunwale | 2728bf4 | 2016-03-03 11:03:26 -0800 | [diff] [blame] | 593 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 594 | Slog.w(TAG, "removeAllDeadWindows: " + win); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 595 | } |
| 596 | // Set mDestroying, we don't want any animation or delayed removal here. |
| 597 | win.mDestroying = true; |
| 598 | service.removeWindowLocked(win); |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 603 | boolean hasWindowsAlive() { |
| 604 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 605 | if (!allAppWindows.get(i).mAppDied) { |
| 606 | return true; |
| 607 | } |
| 608 | } |
| 609 | return false; |
| 610 | } |
| 611 | |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 612 | void setReplacingWindows(boolean animate) { |
| 613 | if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + appWindowToken |
| 614 | + " with replacing windows."); |
| 615 | |
| 616 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 617 | final WindowState w = allAppWindows.get(i); |
| 618 | w.setReplacing(animate); |
| 619 | } |
| 620 | if (animate) { |
| 621 | // Set-up dummy animation so we can start treating windows associated with this |
| 622 | // token like they are in transition before the new app window is ready for us to |
| 623 | // run the real transition animation. |
| 624 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, |
| 625 | "setReplacingWindow() Setting dummy animation on: " + this); |
| 626 | mAppAnimator.setDummyAnimation(); |
| 627 | } |
| 628 | } |
| 629 | |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 630 | void setReplacingChildren() { |
| 631 | if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + appWindowToken |
| 632 | + " with replacing child windows."); |
| 633 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 634 | final WindowState w = allAppWindows.get(i); |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 635 | if (w.shouldBeReplacedWithChildren()) { |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 636 | w.setReplacing(false /* animate */); |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 641 | void resetReplacingWindows() { |
| 642 | if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Resetting app token " + appWindowToken |
| 643 | + " of replacing window marks."); |
| 644 | |
| 645 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 646 | final WindowState w = allAppWindows.get(i); |
| 647 | w.resetReplacing(); |
| 648 | } |
| 649 | } |
| 650 | |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 651 | void requestUpdateWallpaperIfNeeded() { |
| 652 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 653 | final WindowState w = allAppWindows.get(i); |
| 654 | w.requestUpdateWallpaperIfNeeded(); |
| 655 | } |
| 656 | } |
| 657 | |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 658 | boolean isRelaunching() { |
| 659 | return mPendingRelaunchCount > 0; |
| 660 | } |
| 661 | |
| 662 | void startRelaunching() { |
| 663 | if (canFreezeBounds()) { |
| 664 | freezeBounds(); |
| 665 | } |
| 666 | mPendingRelaunchCount++; |
| 667 | } |
| 668 | |
| 669 | void finishRelaunching() { |
| 670 | if (canFreezeBounds()) { |
| 671 | unfreezeBounds(); |
| 672 | } |
| 673 | if (mPendingRelaunchCount > 0) { |
| 674 | mPendingRelaunchCount--; |
| 675 | } |
| 676 | } |
| 677 | |
Wale Ogunwale | 8fd7542 | 2016-06-24 14:20:37 -0700 | [diff] [blame] | 678 | void clearRelaunching() { |
Wale Ogunwale | 37dbafc | 2016-06-27 10:15:20 -0700 | [diff] [blame] | 679 | if (mPendingRelaunchCount == 0) { |
| 680 | return; |
| 681 | } |
Wale Ogunwale | 8fd7542 | 2016-06-24 14:20:37 -0700 | [diff] [blame] | 682 | if (canFreezeBounds()) { |
| 683 | unfreezeBounds(); |
| 684 | } |
| 685 | mPendingRelaunchCount = 0; |
| 686 | } |
| 687 | |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 688 | void addWindow(WindowState w) { |
| 689 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 690 | WindowState candidate = allAppWindows.get(i); |
| 691 | if (candidate.mWillReplaceWindow && candidate.mReplacingWindow == null && |
Robert Carr | 8bc8907 | 2016-04-08 13:29:59 -0700 | [diff] [blame] | 692 | candidate.getWindowTag().toString().equals(w.getWindowTag().toString())) { |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 693 | candidate.mReplacingWindow = w; |
Robert Carr | b439a63 | 2016-04-07 22:52:10 -0700 | [diff] [blame] | 694 | w.mSkipEnterAnimationForSeamlessReplacement = !candidate.mAnimateReplacingWindow; |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 695 | |
| 696 | // if we got a replacement window, reset the timeout to give drawing more time |
Chong Zhang | 32de365 | 2016-05-12 16:00:01 -0700 | [diff] [blame] | 697 | service.scheduleReplacingWindowTimeouts(this); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | allAppWindows.add(w); |
| 701 | } |
| 702 | |
| 703 | boolean waitingForReplacement() { |
| 704 | for (int i = allAppWindows.size() -1; i >= 0; i--) { |
| 705 | WindowState candidate = allAppWindows.get(i); |
| 706 | if (candidate.mWillReplaceWindow) { |
| 707 | return true; |
| 708 | } |
| 709 | } |
| 710 | return false; |
| 711 | } |
| 712 | |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 713 | void clearTimedoutReplacesLocked() { |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 714 | for (int i = allAppWindows.size() - 1; i >= 0; |
| 715 | // removeWindowLocked at bottom of loop may remove multiple entries from |
| 716 | // allAppWindows if the window to be removed has child windows. It also may |
| 717 | // not remove any windows from allAppWindows at all if win is exiting and |
| 718 | // currently animating away. This ensures that winNdx is monotonically decreasing |
| 719 | // and never beyond allAppWindows bounds. |
| 720 | i = Math.min(i - 1, allAppWindows.size() - 1)) { |
| 721 | WindowState candidate = allAppWindows.get(i); |
| 722 | if (candidate.mWillReplaceWindow == false) { |
| 723 | continue; |
| 724 | } |
| 725 | candidate.mWillReplaceWindow = false; |
Robert Carr | b439a63 | 2016-04-07 22:52:10 -0700 | [diff] [blame] | 726 | if (candidate.mReplacingWindow != null) { |
| 727 | candidate.mReplacingWindow.mSkipEnterAnimationForSeamlessReplacement = false; |
| 728 | } |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 729 | // Since the window already timed out, remove it immediately now. |
| 730 | // Use removeWindowInnerLocked() instead of removeWindowLocked(), as the latter |
| 731 | // delays removal on certain conditions, which will leave the stale window in the |
| 732 | // stack and marked mWillReplaceWindow=false, so the window will never be removed. |
| 733 | service.removeWindowInnerLocked(candidate); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 734 | } |
| 735 | } |
| 736 | |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 737 | private boolean canFreezeBounds() { |
| 738 | // For freeform windows, we can't freeze the bounds at the moment because this would make |
| 739 | // the resizing unresponsive. |
| 740 | return mTask != null && !mTask.inFreeformWorkspace(); |
| 741 | } |
| 742 | |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 743 | /** |
| 744 | * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds |
| 745 | * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even |
| 746 | * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen |
| 747 | * with a queue. |
| 748 | */ |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 749 | private void freezeBounds() { |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 750 | mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds)); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 751 | |
| 752 | if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) { |
| 753 | // We didn't call prepareFreezingBounds on the task, so use the current value. |
| 754 | final Configuration config = new Configuration(service.mCurConfiguration); |
| 755 | config.updateFrom(mTask.mOverrideConfig); |
| 756 | mFrozenMergedConfig.offer(config); |
| 757 | } else { |
| 758 | mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig)); |
| 759 | } |
| 760 | mTask.mPreparedFrozenMergedConfig.setToDefaults(); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | /** |
| 764 | * Unfreezes the previously frozen bounds. See {@link #freezeBounds}. |
| 765 | */ |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 766 | private void unfreezeBounds() { |
Wale Ogunwale | 37dbafc | 2016-06-27 10:15:20 -0700 | [diff] [blame] | 767 | if (!mFrozenBounds.isEmpty()) { |
| 768 | mFrozenBounds.remove(); |
| 769 | } |
| 770 | if (!mFrozenMergedConfig.isEmpty()) { |
| 771 | mFrozenMergedConfig.remove(); |
| 772 | } |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 773 | for (int i = windows.size() - 1; i >= 0; i--) { |
| 774 | final WindowState win = windows.get(i); |
Jorim Jaggi | 69abc19 | 2016-02-04 19:34:00 -0800 | [diff] [blame] | 775 | if (!win.mHasSurface) { |
| 776 | continue; |
| 777 | } |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 778 | win.mLayoutNeeded = true; |
| 779 | win.setDisplayLayoutNeeded(); |
| 780 | if (!service.mResizingWindows.contains(win)) { |
| 781 | service.mResizingWindows.add(win); |
| 782 | } |
| 783 | } |
| 784 | service.mWindowPlacerLocked.performSurfacePlacement(); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 785 | } |
| 786 | |
Robert Carr | 91b22809 | 2016-06-28 17:32:37 -0700 | [diff] [blame] | 787 | void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) { |
| 788 | mSurfaceViewBackgrounds.add(background); |
| 789 | } |
| 790 | |
| 791 | void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) { |
| 792 | mSurfaceViewBackgrounds.remove(background); |
| 793 | updateSurfaceViewBackgroundVisibilities(); |
| 794 | } |
| 795 | |
| 796 | // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating. |
| 797 | // However, we need to ensure one SurfaceView doesn't cover another when they are both placed |
| 798 | // below the main app window (as traditionally a SurfaceView which is never drawn |
| 799 | // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable |
| 800 | // the background for the SurfaceView with lowest Z order |
| 801 | void updateSurfaceViewBackgroundVisibilities() { |
| 802 | WindowSurfaceController.SurfaceControlWithBackground bottom = null; |
| 803 | int bottomLayer = Integer.MAX_VALUE; |
| 804 | for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) { |
| 805 | WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i); |
| 806 | if (sc.mVisible && sc.mLayer < bottomLayer) { |
| 807 | bottomLayer = sc.mLayer; |
| 808 | bottom = sc; |
| 809 | } |
| 810 | } |
| 811 | for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) { |
| 812 | WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i); |
| 813 | sc.updateBackgroundVisibility(sc != bottom); |
| 814 | } |
| 815 | } |
| 816 | |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 817 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 818 | void dump(PrintWriter pw, String prefix) { |
| 819 | super.dump(pw, prefix); |
| 820 | if (appToken != null) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 821 | pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 822 | } |
| 823 | if (allAppWindows.size() > 0) { |
| 824 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 825 | } |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 826 | pw.print(prefix); pw.print("task="); pw.println(mTask); |
| 827 | pw.print(prefix); pw.print(" appFullscreen="); pw.print(appFullscreen); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 828 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 829 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 830 | pw.print(" clientHidden="); pw.print(clientHidden); |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 831 | pw.print(" reportedDrawn="); pw.print(reportedDrawn); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 832 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 833 | if (paused) { |
| 834 | pw.print(prefix); pw.print("paused="); pw.println(paused); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 835 | } |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 836 | if (mAppStopped) { |
| 837 | pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped); |
| 838 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 839 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 840 | || allDrawn || mAppAnimator.allDrawn) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 841 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 842 | pw.print(numInterestingWindows); |
| 843 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 844 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 845 | pw.print(" allDrawn="); pw.print(allDrawn); |
| 846 | pw.print(" (animator="); pw.print(mAppAnimator.allDrawn); |
| 847 | pw.println(")"); |
| 848 | } |
| 849 | if (inPendingTransaction) { |
| 850 | pw.print(prefix); pw.print("inPendingTransaction="); |
| 851 | pw.println(inPendingTransaction); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 852 | } |
Craig Mautner | 799bc1d | 2015-01-14 10:33:48 -0800 | [diff] [blame] | 853 | if (startingData != null || removed || firstWindowDrawn || mIsExiting) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 854 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 855 | pw.print(" removed="); pw.print(removed); |
Craig Mautner | 3d7ca31 | 2015-01-08 10:56:00 -0800 | [diff] [blame] | 856 | pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn); |
Craig Mautner | 799bc1d | 2015-01-14 10:33:48 -0800 | [diff] [blame] | 857 | pw.print(" mIsExiting="); pw.println(mIsExiting); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 858 | } |
| 859 | if (startingWindow != null || startingView != null |
| 860 | || startingDisplayed || startingMoved) { |
| 861 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 862 | pw.print(" startingView="); pw.print(startingView); |
| 863 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 864 | pw.print(" startingMoved="); pw.println(startingMoved); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 865 | } |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 866 | if (!mFrozenBounds.isEmpty()) { |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 867 | pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 868 | pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig); |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 869 | } |
| 870 | if (mPendingRelaunchCount != 0) { |
| 871 | pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 872 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | @Override |
| 876 | public String toString() { |
| 877 | if (stringName == null) { |
| 878 | StringBuilder sb = new StringBuilder(); |
| 879 | sb.append("AppWindowToken{"); |
| 880 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 881 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 882 | stringName = sb.toString(); |
| 883 | } |
| 884 | return stringName; |
| 885 | } |
Jeff Brown | e9bdb31 | 2012-04-05 15:30:10 -0700 | [diff] [blame] | 886 | } |