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