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