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() { |
| 343 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 344 | final WindowState win = allAppWindows.get(i); |
| 345 | // We don't want to clear it out for windows that get replaced, because the |
| 346 | // animation depends on the flag to remove the replaced window. |
| 347 | // |
| 348 | // We also don't clear the mAnimatingExit flag for windows which have the |
| 349 | // mRemoveOnExit flag. This indicates an explicit remove request has been issued |
| 350 | // by the client. We should let animation proceed and not clear this flag or |
| 351 | // they won't eventually be removed by WindowStateAnimator#finishExit. |
| 352 | if (!win.mWillReplaceWindow && !win.mRemoveOnExit) { |
| 353 | win.mAnimatingExit = false; |
| 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. |
| 361 | win.mWinAnimator.mAnimating = false; |
Chong Zhang | f96cb3c | 2016-08-15 11:09:29 -0700 | [diff] [blame] | 362 | |
| 363 | if (win.mDestroying) { |
| 364 | win.mDestroying = false; |
| 365 | service.mDestroySurface.remove(win); |
| 366 | } |
Chong Zhang | e05bcb1 | 2016-07-26 17:47:29 -0700 | [diff] [blame] | 367 | } |
| 368 | } |
Chong Zhang | f96cb3c | 2016-08-15 11:09:29 -0700 | [diff] [blame] | 369 | requestUpdateWallpaperIfNeeded(); |
Chong Zhang | e05bcb1 | 2016-07-26 17:47:29 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 372 | void destroySurfaces() { |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 373 | destroySurfaces(false /*cleanupOnResume*/); |
| 374 | } |
| 375 | |
| 376 | /** |
| 377 | * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure |
| 378 | * the client has finished with them. |
| 379 | * |
| 380 | * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If |
| 381 | * set to true, destroy only surfaces of removed windows, and clear relevant flags of the |
| 382 | * others so that they are ready to be reused. If set to false (common case), destroy all |
| 383 | * surfaces that's eligible, if the app is already stopped. |
| 384 | */ |
| 385 | |
| 386 | private void destroySurfaces(boolean cleanupOnResume) { |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 387 | final ArrayList<WindowState> allWindows = (ArrayList<WindowState>) allAppWindows.clone(); |
| 388 | final DisplayContentList displayList = new DisplayContentList(); |
| 389 | for (int i = allWindows.size() - 1; i >= 0; i--) { |
| 390 | final WindowState win = allWindows.get(i); |
Chong Zhang | eb66557 | 2016-05-09 18:28:27 -0700 | [diff] [blame] | 391 | |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 392 | if (!(mAppStopped || win.mWindowRemovalAllowed || cleanupOnResume)) { |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 393 | continue; |
| 394 | } |
| 395 | |
Chong Zhang | eb66557 | 2016-05-09 18:28:27 -0700 | [diff] [blame] | 396 | win.mWinAnimator.destroyPreservedSurfaceLocked(); |
| 397 | |
| 398 | if (!win.mDestroying) { |
Chong Zhang | 5471e90 | 2016-02-12 15:34:10 -0800 | [diff] [blame] | 399 | continue; |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 400 | } |
| 401 | |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 402 | if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + win |
| 403 | + " destroySurfaces: mAppStopped=" + mAppStopped |
| 404 | + " win.mWindowRemovalAllowed=" + win.mWindowRemovalAllowed |
| 405 | + " win.mRemoveOnExit=" + win.mRemoveOnExit); |
| 406 | |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 407 | if (!cleanupOnResume || win.mRemoveOnExit) { |
| 408 | win.destroyOrSaveSurface(); |
| 409 | } |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 410 | if (win.mRemoveOnExit) { |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 411 | service.removeWindowInnerLocked(win); |
| 412 | } |
| 413 | final DisplayContent displayContent = win.getDisplayContent(); |
| 414 | if (displayContent != null && !displayList.contains(displayContent)) { |
| 415 | displayList.add(displayContent); |
| 416 | } |
Chong Zhang | f96cb3c | 2016-08-15 11:09:29 -0700 | [diff] [blame] | 417 | if (cleanupOnResume) { |
| 418 | win.requestUpdateWallpaperIfNeeded(); |
| 419 | } |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 420 | win.mDestroying = false; |
| 421 | } |
| 422 | for (int i = 0; i < displayList.size(); i++) { |
| 423 | final DisplayContent displayContent = displayList.get(i); |
| 424 | service.mLayersController.assignLayersLocked(displayContent.getWindowList()); |
| 425 | displayContent.layoutNeeded = true; |
| 426 | } |
| 427 | } |
| 428 | |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 429 | /** |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 430 | * Notify that the app is now resumed, and it was not stopped before, perform a clean |
| 431 | * up of the surfaces |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 432 | */ |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 433 | void notifyAppResumed(boolean wasStopped) { |
| 434 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped + " " + this); |
| 435 | mAppStopped = false; |
| 436 | if (!wasStopped) { |
| 437 | destroySurfaces(true /*cleanupOnResume*/); |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 438 | } |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 439 | } |
| 440 | |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 441 | /** |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 442 | * Notify that the app has stopped, and it is okay to destroy any surfaces which were |
| 443 | * keeping alive in case they were still being used. |
| 444 | */ |
| 445 | void notifyAppStopped() { |
| 446 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this); |
| 447 | mAppStopped = true; |
| 448 | destroySurfaces(); |
| 449 | // Remove any starting window that was added for this app if they are still around. |
| 450 | mTask.mService.scheduleRemoveStartingWindowLocked(this); |
| 451 | } |
| 452 | |
| 453 | /** |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 454 | * Checks whether we should save surfaces for this app. |
| 455 | * |
| 456 | * @return true if the surfaces should be saved, false otherwise. |
| 457 | */ |
| 458 | boolean shouldSaveSurface() { |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 459 | // We want to save surface if the app's windows are "allDrawn". |
| 460 | // (If we started entering animation early with saved surfaces, allDrawn |
| 461 | // should have been restored to true. So we'll save again in that case |
| 462 | // even if app didn't actually finish drawing.) |
| 463 | return allDrawn; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 464 | } |
| 465 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 466 | boolean canRestoreSurfaces() { |
Chong Zhang | b7b4a56 | 2016-04-28 15:30:33 -0700 | [diff] [blame] | 467 | for (int i = allAppWindows.size() -1; i >= 0; i--) { |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 468 | final WindowState w = allAppWindows.get(i); |
| 469 | if (w.canRestoreSurface()) { |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 470 | return true; |
| 471 | } |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 472 | } |
| 473 | return false; |
| 474 | } |
| 475 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 476 | void clearVisibleBeforeClientHidden() { |
| 477 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 478 | final WindowState w = allAppWindows.get(i); |
| 479 | w.clearVisibleBeforeClientHidden(); |
| 480 | } |
| 481 | } |
| 482 | |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 483 | /** |
| 484 | * Whether the app has some window that is invisible in layout, but |
| 485 | * animating with saved surface. |
| 486 | */ |
| 487 | boolean isAnimatingInvisibleWithSavedSurface() { |
| 488 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 489 | final WindowState w = allAppWindows.get(i); |
| 490 | if (w.isAnimatingInvisibleWithSavedSurface()) { |
| 491 | return true; |
| 492 | } |
| 493 | } |
| 494 | return false; |
| 495 | } |
| 496 | |
| 497 | /** |
| 498 | * Hide all window surfaces that's still invisible in layout but animating |
| 499 | * with a saved surface, and mark them destroying. |
| 500 | */ |
| 501 | void stopUsingSavedSurfaceLocked() { |
| 502 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 503 | final WindowState w = allAppWindows.get(i); |
| 504 | if (w.isAnimatingInvisibleWithSavedSurface()) { |
| 505 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, |
| 506 | "stopUsingSavedSurfaceLocked: " + w); |
| 507 | w.clearAnimatingWithSavedSurface(); |
| 508 | w.mDestroying = true; |
| 509 | w.mWinAnimator.hide("stopUsingSavedSurfaceLocked"); |
| 510 | w.mWinAnimator.mWallpaperControllerLocked.hideWallpapers(w); |
| 511 | } |
| 512 | } |
| 513 | destroySurfaces(); |
| 514 | } |
| 515 | |
Chong Zhang | f58631a | 2016-05-24 16:02:10 -0700 | [diff] [blame] | 516 | void markSavedSurfaceExiting() { |
| 517 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 518 | final WindowState w = allAppWindows.get(i); |
| 519 | if (w.isAnimatingInvisibleWithSavedSurface()) { |
| 520 | w.mAnimatingExit = true; |
| 521 | w.mWinAnimator.mAnimating = true; |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 526 | void restoreSavedSurfaces() { |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 527 | if (!canRestoreSurfaces()) { |
| 528 | clearVisibleBeforeClientHidden(); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 529 | return; |
| 530 | } |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 531 | // Check if we have enough drawn windows to mark allDrawn= true. |
| 532 | int numInteresting = 0; |
| 533 | int numDrawn = 0; |
Chong Zhang | b7b4a56 | 2016-04-28 15:30:33 -0700 | [diff] [blame] | 534 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 535 | WindowState w = allAppWindows.get(i); |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 536 | if (w != startingWindow && !w.mAppDied && w.wasVisibleBeforeClientHidden() |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 537 | && (!mAppAnimator.freezingScreen || !w.mAppFreezing)) { |
| 538 | numInteresting++; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 539 | if (w.hasSavedSurface()) { |
| 540 | w.restoreSavedSurface(); |
| 541 | } |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 542 | if (w.isDrawnLw()) { |
| 543 | numDrawn++; |
| 544 | } |
| 545 | } |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 546 | } |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 547 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 548 | if (!allDrawn) { |
| 549 | allDrawn = (numInteresting > 0) && (numInteresting == numDrawn); |
| 550 | if (allDrawn) { |
| 551 | service.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget(); |
| 552 | } |
| 553 | } |
| 554 | clearVisibleBeforeClientHidden(); |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 555 | |
| 556 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 557 | "restoreSavedSurfaces: " + appWindowToken + " allDrawn=" + allDrawn |
| 558 | + " numInteresting=" + numInteresting + " numDrawn=" + numDrawn); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | void destroySavedSurfaces() { |
Chong Zhang | b7b4a56 | 2016-04-28 15:30:33 -0700 | [diff] [blame] | 562 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 563 | WindowState win = allAppWindows.get(i); |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 564 | win.destroySavedSurface(); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 565 | } |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | void clearAllDrawn() { |
| 569 | allDrawn = false; |
| 570 | deferClearAllDrawn = false; |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 571 | allDrawnExcludingSaved = false; |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Wale Ogunwale | 98e70d0 | 2014-11-10 12:12:27 -0800 | [diff] [blame] | 574 | @Override |
Craig Mautner | 7c9ee19 | 2014-08-14 16:08:26 -0700 | [diff] [blame] | 575 | void removeAllWindows() { |
Craig Mautner | 7b4655d | 2014-11-20 12:13:22 -0800 | [diff] [blame] | 576 | for (int winNdx = allAppWindows.size() - 1; winNdx >= 0; |
| 577 | // removeWindowLocked at bottom of loop may remove multiple entries from |
| 578 | // allAppWindows if the window to be removed has child windows. It also may |
| 579 | // not remove any windows from allAppWindows at all if win is exiting and |
| 580 | // currently animating away. This ensures that winNdx is monotonically decreasing |
| 581 | // and never beyond allAppWindows bounds. |
| 582 | winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) { |
| 583 | WindowState win = allAppWindows.get(winNdx); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 584 | if (DEBUG_WINDOW_MOVEMENT) { |
| 585 | Slog.w(TAG, "removeAllWindows: removing win=" + win); |
Wale Ogunwale | 98e70d0 | 2014-11-10 12:12:27 -0800 | [diff] [blame] | 586 | } |
| 587 | |
Wale Ogunwale | a6ab5c4 | 2015-04-24 09:00:25 -0700 | [diff] [blame] | 588 | service.removeWindowLocked(win); |
Craig Mautner | 7c9ee19 | 2014-08-14 16:08:26 -0700 | [diff] [blame] | 589 | } |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 590 | allAppWindows.clear(); |
| 591 | windows.clear(); |
Craig Mautner | 7c9ee19 | 2014-08-14 16:08:26 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 594 | void removeAllDeadWindows() { |
| 595 | for (int winNdx = allAppWindows.size() - 1; winNdx >= 0; |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 596 | // removeWindowLocked at bottom of loop may remove multiple entries from |
| 597 | // allAppWindows if the window to be removed has child windows. It also may |
| 598 | // not remove any windows from allAppWindows at all if win is exiting and |
| 599 | // currently animating away. This ensures that winNdx is monotonically decreasing |
| 600 | // and never beyond allAppWindows bounds. |
| 601 | winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) { |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 602 | WindowState win = allAppWindows.get(winNdx); |
| 603 | if (win.mAppDied) { |
Wale Ogunwale | 2728bf4 | 2016-03-03 11:03:26 -0800 | [diff] [blame] | 604 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 605 | Slog.w(TAG, "removeAllDeadWindows: " + win); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 606 | } |
| 607 | // Set mDestroying, we don't want any animation or delayed removal here. |
| 608 | win.mDestroying = true; |
| 609 | service.removeWindowLocked(win); |
| 610 | } |
| 611 | } |
| 612 | } |
| 613 | |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 614 | boolean hasWindowsAlive() { |
| 615 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 616 | if (!allAppWindows.get(i).mAppDied) { |
| 617 | return true; |
| 618 | } |
| 619 | } |
| 620 | return false; |
| 621 | } |
| 622 | |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 623 | void setReplacingWindows(boolean animate) { |
| 624 | if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + appWindowToken |
| 625 | + " with replacing windows."); |
| 626 | |
| 627 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 628 | final WindowState w = allAppWindows.get(i); |
| 629 | w.setReplacing(animate); |
| 630 | } |
| 631 | if (animate) { |
| 632 | // Set-up dummy animation so we can start treating windows associated with this |
| 633 | // token like they are in transition before the new app window is ready for us to |
| 634 | // run the real transition animation. |
| 635 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, |
| 636 | "setReplacingWindow() Setting dummy animation on: " + this); |
| 637 | mAppAnimator.setDummyAnimation(); |
| 638 | } |
| 639 | } |
| 640 | |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 641 | void setReplacingChildren() { |
| 642 | if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + appWindowToken |
| 643 | + " with replacing child windows."); |
| 644 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 645 | final WindowState w = allAppWindows.get(i); |
Robert Carr | d1a010f | 2016-04-07 22:36:22 -0700 | [diff] [blame] | 646 | if (w.shouldBeReplacedWithChildren()) { |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 647 | w.setReplacing(false /* animate */); |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 652 | void resetReplacingWindows() { |
| 653 | if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Resetting app token " + appWindowToken |
| 654 | + " of replacing window marks."); |
| 655 | |
| 656 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 657 | final WindowState w = allAppWindows.get(i); |
| 658 | w.resetReplacing(); |
| 659 | } |
| 660 | } |
| 661 | |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 662 | void requestUpdateWallpaperIfNeeded() { |
| 663 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 664 | final WindowState w = allAppWindows.get(i); |
| 665 | w.requestUpdateWallpaperIfNeeded(); |
| 666 | } |
| 667 | } |
| 668 | |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 669 | boolean isRelaunching() { |
| 670 | return mPendingRelaunchCount > 0; |
| 671 | } |
| 672 | |
| 673 | void startRelaunching() { |
| 674 | if (canFreezeBounds()) { |
| 675 | freezeBounds(); |
| 676 | } |
| 677 | mPendingRelaunchCount++; |
| 678 | } |
| 679 | |
| 680 | void finishRelaunching() { |
| 681 | if (canFreezeBounds()) { |
| 682 | unfreezeBounds(); |
| 683 | } |
| 684 | if (mPendingRelaunchCount > 0) { |
| 685 | mPendingRelaunchCount--; |
| 686 | } |
| 687 | } |
| 688 | |
Wale Ogunwale | 8fd7542 | 2016-06-24 14:20:37 -0700 | [diff] [blame] | 689 | void clearRelaunching() { |
Wale Ogunwale | 37dbafc | 2016-06-27 10:15:20 -0700 | [diff] [blame] | 690 | if (mPendingRelaunchCount == 0) { |
| 691 | return; |
| 692 | } |
Wale Ogunwale | 8fd7542 | 2016-06-24 14:20:37 -0700 | [diff] [blame] | 693 | if (canFreezeBounds()) { |
| 694 | unfreezeBounds(); |
| 695 | } |
| 696 | mPendingRelaunchCount = 0; |
| 697 | } |
| 698 | |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 699 | void addWindow(WindowState w) { |
| 700 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 701 | WindowState candidate = allAppWindows.get(i); |
| 702 | if (candidate.mWillReplaceWindow && candidate.mReplacingWindow == null && |
Robert Carr | 8bc8907 | 2016-04-08 13:29:59 -0700 | [diff] [blame] | 703 | candidate.getWindowTag().toString().equals(w.getWindowTag().toString())) { |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 704 | candidate.mReplacingWindow = w; |
Robert Carr | b439a63 | 2016-04-07 22:52:10 -0700 | [diff] [blame] | 705 | w.mSkipEnterAnimationForSeamlessReplacement = !candidate.mAnimateReplacingWindow; |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 706 | |
| 707 | // 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] | 708 | service.scheduleReplacingWindowTimeouts(this); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 709 | } |
| 710 | } |
| 711 | allAppWindows.add(w); |
| 712 | } |
| 713 | |
| 714 | boolean waitingForReplacement() { |
| 715 | for (int i = allAppWindows.size() -1; i >= 0; i--) { |
| 716 | WindowState candidate = allAppWindows.get(i); |
| 717 | if (candidate.mWillReplaceWindow) { |
| 718 | return true; |
| 719 | } |
| 720 | } |
| 721 | return false; |
| 722 | } |
| 723 | |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 724 | void clearTimedoutReplacesLocked() { |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 725 | for (int i = allAppWindows.size() - 1; i >= 0; |
| 726 | // removeWindowLocked at bottom of loop may remove multiple entries from |
| 727 | // allAppWindows if the window to be removed has child windows. It also may |
| 728 | // not remove any windows from allAppWindows at all if win is exiting and |
| 729 | // currently animating away. This ensures that winNdx is monotonically decreasing |
| 730 | // and never beyond allAppWindows bounds. |
| 731 | i = Math.min(i - 1, allAppWindows.size() - 1)) { |
| 732 | WindowState candidate = allAppWindows.get(i); |
| 733 | if (candidate.mWillReplaceWindow == false) { |
| 734 | continue; |
| 735 | } |
| 736 | candidate.mWillReplaceWindow = false; |
Robert Carr | b439a63 | 2016-04-07 22:52:10 -0700 | [diff] [blame] | 737 | if (candidate.mReplacingWindow != null) { |
| 738 | candidate.mReplacingWindow.mSkipEnterAnimationForSeamlessReplacement = false; |
| 739 | } |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 740 | // Since the window already timed out, remove it immediately now. |
| 741 | // Use removeWindowInnerLocked() instead of removeWindowLocked(), as the latter |
| 742 | // delays removal on certain conditions, which will leave the stale window in the |
| 743 | // stack and marked mWillReplaceWindow=false, so the window will never be removed. |
| 744 | service.removeWindowInnerLocked(candidate); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 748 | private boolean canFreezeBounds() { |
| 749 | // For freeform windows, we can't freeze the bounds at the moment because this would make |
| 750 | // the resizing unresponsive. |
| 751 | return mTask != null && !mTask.inFreeformWorkspace(); |
| 752 | } |
| 753 | |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 754 | /** |
| 755 | * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds |
| 756 | * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even |
| 757 | * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen |
| 758 | * with a queue. |
| 759 | */ |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 760 | private void freezeBounds() { |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 761 | mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds)); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 762 | |
| 763 | if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) { |
| 764 | // We didn't call prepareFreezingBounds on the task, so use the current value. |
| 765 | final Configuration config = new Configuration(service.mCurConfiguration); |
| 766 | config.updateFrom(mTask.mOverrideConfig); |
| 767 | mFrozenMergedConfig.offer(config); |
| 768 | } else { |
| 769 | mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig)); |
| 770 | } |
| 771 | mTask.mPreparedFrozenMergedConfig.setToDefaults(); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | /** |
| 775 | * Unfreezes the previously frozen bounds. See {@link #freezeBounds}. |
| 776 | */ |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 777 | private void unfreezeBounds() { |
Wale Ogunwale | 37dbafc | 2016-06-27 10:15:20 -0700 | [diff] [blame] | 778 | if (!mFrozenBounds.isEmpty()) { |
| 779 | mFrozenBounds.remove(); |
| 780 | } |
| 781 | if (!mFrozenMergedConfig.isEmpty()) { |
| 782 | mFrozenMergedConfig.remove(); |
| 783 | } |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 784 | for (int i = windows.size() - 1; i >= 0; i--) { |
| 785 | final WindowState win = windows.get(i); |
Jorim Jaggi | 69abc19 | 2016-02-04 19:34:00 -0800 | [diff] [blame] | 786 | if (!win.mHasSurface) { |
| 787 | continue; |
| 788 | } |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 789 | win.mLayoutNeeded = true; |
| 790 | win.setDisplayLayoutNeeded(); |
| 791 | if (!service.mResizingWindows.contains(win)) { |
| 792 | service.mResizingWindows.add(win); |
| 793 | } |
| 794 | } |
| 795 | service.mWindowPlacerLocked.performSurfacePlacement(); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 796 | } |
| 797 | |
Robert Carr | 91b22809 | 2016-06-28 17:32:37 -0700 | [diff] [blame] | 798 | void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) { |
| 799 | mSurfaceViewBackgrounds.add(background); |
| 800 | } |
| 801 | |
| 802 | void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) { |
| 803 | mSurfaceViewBackgrounds.remove(background); |
| 804 | updateSurfaceViewBackgroundVisibilities(); |
| 805 | } |
| 806 | |
| 807 | // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating. |
| 808 | // However, we need to ensure one SurfaceView doesn't cover another when they are both placed |
| 809 | // below the main app window (as traditionally a SurfaceView which is never drawn |
| 810 | // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable |
| 811 | // the background for the SurfaceView with lowest Z order |
| 812 | void updateSurfaceViewBackgroundVisibilities() { |
| 813 | WindowSurfaceController.SurfaceControlWithBackground bottom = null; |
| 814 | int bottomLayer = Integer.MAX_VALUE; |
| 815 | for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) { |
| 816 | WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i); |
| 817 | if (sc.mVisible && sc.mLayer < bottomLayer) { |
| 818 | bottomLayer = sc.mLayer; |
| 819 | bottom = sc; |
| 820 | } |
| 821 | } |
| 822 | for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) { |
| 823 | WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i); |
| 824 | sc.updateBackgroundVisibility(sc != bottom); |
| 825 | } |
| 826 | } |
| 827 | |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 828 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 829 | void dump(PrintWriter pw, String prefix) { |
| 830 | super.dump(pw, prefix); |
| 831 | if (appToken != null) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 832 | pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 833 | } |
| 834 | if (allAppWindows.size() > 0) { |
| 835 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 836 | } |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 837 | pw.print(prefix); pw.print("task="); pw.println(mTask); |
| 838 | pw.print(prefix); pw.print(" appFullscreen="); pw.print(appFullscreen); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 839 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 840 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 841 | pw.print(" clientHidden="); pw.print(clientHidden); |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 842 | pw.print(" reportedDrawn="); pw.print(reportedDrawn); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 843 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 844 | if (paused) { |
| 845 | pw.print(prefix); pw.print("paused="); pw.println(paused); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 846 | } |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 847 | if (mAppStopped) { |
| 848 | pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped); |
| 849 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 850 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 851 | || allDrawn || mAppAnimator.allDrawn) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 852 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 853 | pw.print(numInterestingWindows); |
| 854 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 855 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 856 | pw.print(" allDrawn="); pw.print(allDrawn); |
| 857 | pw.print(" (animator="); pw.print(mAppAnimator.allDrawn); |
| 858 | pw.println(")"); |
| 859 | } |
| 860 | if (inPendingTransaction) { |
| 861 | pw.print(prefix); pw.print("inPendingTransaction="); |
| 862 | pw.println(inPendingTransaction); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 863 | } |
Craig Mautner | 799bc1d | 2015-01-14 10:33:48 -0800 | [diff] [blame] | 864 | if (startingData != null || removed || firstWindowDrawn || mIsExiting) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 865 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 866 | pw.print(" removed="); pw.print(removed); |
Craig Mautner | 3d7ca31 | 2015-01-08 10:56:00 -0800 | [diff] [blame] | 867 | pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn); |
Craig Mautner | 799bc1d | 2015-01-14 10:33:48 -0800 | [diff] [blame] | 868 | pw.print(" mIsExiting="); pw.println(mIsExiting); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 869 | } |
| 870 | if (startingWindow != null || startingView != null |
| 871 | || startingDisplayed || startingMoved) { |
| 872 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 873 | pw.print(" startingView="); pw.print(startingView); |
| 874 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 875 | pw.print(" startingMoved="); pw.println(startingMoved); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 876 | } |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 877 | if (!mFrozenBounds.isEmpty()) { |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 878 | pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 879 | pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig); |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 880 | } |
| 881 | if (mPendingRelaunchCount != 0) { |
| 882 | pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 883 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | @Override |
| 887 | public String toString() { |
| 888 | if (stringName == null) { |
| 889 | StringBuilder sb = new StringBuilder(); |
| 890 | sb.append("AppWindowToken{"); |
| 891 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 892 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 893 | stringName = sb.toString(); |
| 894 | } |
| 895 | return stringName; |
| 896 | } |
Jeff Brown | e9bdb31 | 2012-04-05 15:30:10 -0700 | [diff] [blame] | 897 | } |