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