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 | |
| 19 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 20 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
| 21 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 22 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 23 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
| 24 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT; |
| 25 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 26 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 27 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 28 | import com.android.server.input.InputApplicationHandle; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 29 | import com.android.server.wm.WindowManagerService.H; |
| 30 | |
Filip Gruszczynski | a590c99 | 2015-11-25 16:45:26 -0800 | [diff] [blame] | 31 | import android.annotation.NonNull; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 32 | import android.content.pm.ActivityInfo; |
| 33 | import android.os.Message; |
| 34 | import android.os.RemoteException; |
| 35 | import android.util.Slog; |
| 36 | import android.view.IApplicationToken; |
| 37 | import android.view.View; |
| 38 | import android.view.WindowManager; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 39 | |
| 40 | import java.io.PrintWriter; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 41 | import java.util.ArrayList; |
| 42 | |
| 43 | class AppTokenList extends ArrayList<AppWindowToken> { |
| 44 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * Version of WindowToken that is specifically for a particular application (or |
| 48 | * really activity) that is displaying windows. |
| 49 | */ |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 50 | class AppWindowToken extends WindowToken { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 51 | private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM; |
| 52 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 53 | // Non-null only for application tokens. |
| 54 | final IApplicationToken appToken; |
| 55 | |
| 56 | // All of the windows and child windows that are included in this |
| 57 | // application token. Note this list is NOT sorted! |
Craig Mautner | 9686833 | 2012-12-04 14:29:11 -0800 | [diff] [blame] | 58 | final WindowList allAppWindows = new WindowList(); |
Filip Gruszczynski | a590c99 | 2015-11-25 16:45:26 -0800 | [diff] [blame] | 59 | @NonNull final AppWindowAnimator mAppAnimator; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 60 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 61 | final boolean voiceInteraction; |
| 62 | |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 63 | // Whether we're performing an entering animation with a saved surface. |
| 64 | boolean mAnimatingWithSavedSurface; |
| 65 | |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 66 | Task mTask; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 67 | boolean appFullscreen; |
| 68 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Craig Mautner | 4c5eb22 | 2013-11-18 12:59:05 -0800 | [diff] [blame] | 69 | boolean layoutConfigChanges; |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 70 | boolean showForAllUsers; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 71 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 72 | // The input dispatching timeout for this application token in nanoseconds. |
| 73 | long inputDispatchingTimeoutNanos; |
| 74 | |
| 75 | // These are used for determining when all windows associated with |
| 76 | // an activity have been drawn, so they can be made visible together |
| 77 | // at the same time. |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 78 | // initialize so that it doesn't match mTransactionSequence which is an int. |
| 79 | long lastTransactionSequence = Long.MIN_VALUE; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 80 | int numInterestingWindows; |
| 81 | int numDrawnWindows; |
| 82 | boolean inPendingTransaction; |
| 83 | boolean allDrawn; |
Craig Mautner | 7636dfb | 2012-11-16 15:24:11 -0800 | [diff] [blame] | 84 | // Set to true when this app creates a surface while in the middle of an animation. In that |
| 85 | // case do not clear allDrawn until the animation completes. |
| 86 | boolean deferClearAllDrawn; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 87 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 88 | // Is this window's surface needed? This is almost like hidden, except |
| 89 | // it will sometimes be true a little earlier: when the token has |
| 90 | // been shown, but is still waiting for its app transition to execute |
| 91 | // before making its windows shown. |
| 92 | boolean hiddenRequested; |
| 93 | |
| 94 | // Have we told the window clients to hide themselves? |
| 95 | boolean clientHidden; |
| 96 | |
| 97 | // Last visibility state we reported to the app token. |
| 98 | boolean reportedVisible; |
| 99 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 100 | // Last drawn state we reported to the app token. |
| 101 | boolean reportedDrawn; |
| 102 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 103 | // Set to true when the token has been removed from the window mgr. |
| 104 | boolean removed; |
| 105 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 106 | boolean appDied; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 107 | // Information about an application starting window if displayed. |
| 108 | StartingData startingData; |
| 109 | WindowState startingWindow; |
| 110 | View startingView; |
| 111 | boolean startingDisplayed; |
| 112 | boolean startingMoved; |
| 113 | boolean firstWindowDrawn; |
| 114 | |
| 115 | // Input application handle used by the input dispatcher. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 116 | final InputApplicationHandle mInputApplicationHandle; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 117 | |
Craig Mautner | 799bc1d | 2015-01-14 10:33:48 -0800 | [diff] [blame] | 118 | boolean mIsExiting; |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 119 | |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 120 | boolean mLaunchTaskBehind; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 121 | boolean mEnteringAnimation; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 122 | |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 123 | // True if the windows associated with this token should be cropped to their stack bounds. |
| 124 | boolean mCropWindowsToStack; |
| 125 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 126 | AppWindowToken(WindowManagerService _service, IApplicationToken _token, |
| 127 | boolean _voiceInteraction) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 128 | super(_service, _token.asBinder(), |
| 129 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 130 | appWindowToken = this; |
| 131 | appToken = _token; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 132 | voiceInteraction = _voiceInteraction; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 133 | mInputApplicationHandle = new InputApplicationHandle(this); |
Craig Mautner | 322e403 | 2012-07-13 13:35:20 -0700 | [diff] [blame] | 134 | mAppAnimator = new AppWindowAnimator(this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | void sendAppVisibilityToClients() { |
| 138 | final int N = allAppWindows.size(); |
| 139 | for (int i=0; i<N; i++) { |
| 140 | WindowState win = allAppWindows.get(i); |
| 141 | if (win == startingWindow && clientHidden) { |
| 142 | // Don't hide the starting window. |
| 143 | continue; |
| 144 | } |
| 145 | try { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 146 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 147 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 148 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 149 | } catch (RemoteException e) { |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 154 | void updateReportedVisibilityLocked() { |
| 155 | if (appToken == null) { |
| 156 | return; |
| 157 | } |
| 158 | |
| 159 | int numInteresting = 0; |
| 160 | int numVisible = 0; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 161 | int numDrawn = 0; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 162 | boolean nowGone = true; |
| 163 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 164 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
Craig Mautner | c8bc97e | 2012-04-02 12:54:54 -0700 | [diff] [blame] | 165 | "Update reported visibility: " + this); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 166 | final int N = allAppWindows.size(); |
| 167 | for (int i=0; i<N; i++) { |
| 168 | WindowState win = allAppWindows.get(i); |
| 169 | if (win == startingWindow || win.mAppFreezing |
| 170 | || win.mViewVisibility != View.VISIBLE |
| 171 | || win.mAttrs.type == TYPE_APPLICATION_STARTING |
| 172 | || win.mDestroying) { |
| 173 | continue; |
| 174 | } |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 175 | if (DEBUG_VISIBILITY) { |
| 176 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 177 | + win.isDrawnLw() |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 178 | + ", isAnimating=" + win.mWinAnimator.isAnimating()); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 179 | if (!win.isDrawnLw()) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 180 | Slog.v(TAG, "Not displayed: s=" + |
Robert Carr | e6a8351 | 2015-11-03 16:09:21 -0800 | [diff] [blame] | 181 | win.mWinAnimator.mSurfaceController |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 182 | + " pv=" + win.mPolicyVisibility |
Craig Mautner | 749a7bb | 2012-04-02 13:49:53 -0700 | [diff] [blame] | 183 | + " mDrawState=" + win.mWinAnimator.mDrawState |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 184 | + " ah=" + win.mAttachedHidden |
| 185 | + " th=" |
| 186 | + (win.mAppToken != null |
| 187 | ? win.mAppToken.hiddenRequested : false) |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 188 | + " a=" + win.mWinAnimator.mAnimating); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | numInteresting++; |
| 192 | if (win.isDrawnLw()) { |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 193 | numDrawn++; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 194 | if (!win.mWinAnimator.isAnimating()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 195 | numVisible++; |
| 196 | } |
| 197 | nowGone = false; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 198 | } else if (win.mWinAnimator.isAnimating()) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 199 | nowGone = false; |
| 200 | } |
| 201 | } |
| 202 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 203 | boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 204 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 205 | if (!nowGone) { |
| 206 | // If the app is not yet gone, then it can only become visible/drawn. |
| 207 | if (!nowDrawn) { |
| 208 | nowDrawn = reportedDrawn; |
| 209 | } |
| 210 | if (!nowVisible) { |
| 211 | nowVisible = reportedVisible; |
| 212 | } |
| 213 | } |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 214 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 215 | + numInteresting + " visible=" + numVisible); |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 216 | if (nowDrawn != reportedDrawn) { |
| 217 | if (nowDrawn) { |
| 218 | Message m = service.mH.obtainMessage( |
| 219 | H.REPORT_APPLICATION_TOKEN_DRAWN, this); |
| 220 | service.mH.sendMessage(m); |
| 221 | } |
| 222 | reportedDrawn = nowDrawn; |
| 223 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 224 | if (nowVisible != reportedVisible) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 225 | if (DEBUG_VISIBILITY) Slog.v( |
| 226 | TAG, "Visibility changed in " + this |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 227 | + ": vis=" + nowVisible); |
| 228 | reportedVisible = nowVisible; |
| 229 | Message m = service.mH.obtainMessage( |
| 230 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 231 | nowVisible ? 1 : 0, |
| 232 | nowGone ? 1 : 0, |
| 233 | this); |
| 234 | service.mH.sendMessage(m); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | WindowState findMainWindow() { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 239 | WindowState candidate = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 240 | int j = windows.size(); |
| 241 | while (j > 0) { |
| 242 | j--; |
| 243 | WindowState win = windows.get(j); |
| 244 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 245 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 246 | // 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] | 247 | // happens for example when replacing windows during an activity relaunch. When |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 248 | // constructing the animation, we want the new window, not the exiting one. |
| 249 | if (win.mExiting) { |
| 250 | candidate = win; |
| 251 | } else { |
| 252 | return win; |
| 253 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 254 | } |
| 255 | } |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 256 | return candidate; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 257 | } |
| 258 | |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 259 | boolean stackCanReceiveKeys() { |
| 260 | return (windows.size() > 0) ? windows.get(windows.size() - 1).stackCanReceiveKeys() : false; |
| 261 | } |
| 262 | |
Craig Mautner | 72669d1 | 2012-12-18 17:23:54 -0800 | [diff] [blame] | 263 | boolean isVisible() { |
| 264 | final int N = allAppWindows.size(); |
Craig Mautner | 72669d1 | 2012-12-18 17:23:54 -0800 | [diff] [blame] | 265 | for (int i=0; i<N; i++) { |
| 266 | WindowState win = allAppWindows.get(i); |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 267 | // If we're animating with a saved surface, we're already visible. |
| 268 | // Return true so that the alpha doesn't get cleared. |
Craig Mautner | 72669d1 | 2012-12-18 17:23:54 -0800 | [diff] [blame] | 269 | if (!win.mAppFreezing |
Filip Gruszczynski | 57f76f1 | 2015-11-04 16:10:54 -0800 | [diff] [blame] | 270 | && (win.mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface |
| 271 | || (win.mWinAnimator.isAnimating() |
| 272 | && !service.mAppTransition.isTransitionSet())) |
| 273 | && !win.mDestroying |
| 274 | && win.isDrawnLw()) { |
Craig Mautner | 72669d1 | 2012-12-18 17:23:54 -0800 | [diff] [blame] | 275 | return true; |
| 276 | } |
| 277 | } |
| 278 | return false; |
| 279 | } |
| 280 | |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 281 | void removeAppFromTaskLocked() { |
| 282 | mIsExiting = false; |
| 283 | removeAllWindows(); |
| 284 | |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 285 | // Use local variable because removeAppToken will null out mTask. |
| 286 | final Task task = mTask; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 287 | if (task != null) { |
| 288 | if (!task.removeAppToken(this)) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 289 | Slog.e(TAG, "removeAppFromTaskLocked: token=" + this |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 290 | + " not found."); |
| 291 | } |
| 292 | task.mStack.mExitingAppTokens.remove(this); |
| 293 | } |
| 294 | } |
| 295 | |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 296 | /** |
| 297 | * Checks whether we should save surfaces for this app. |
| 298 | * |
| 299 | * @return true if the surfaces should be saved, false otherwise. |
| 300 | */ |
| 301 | boolean shouldSaveSurface() { |
| 302 | // We want to save surface if the app's windows are "allDrawn", or if we're |
| 303 | // currently animating with save surfaces. (If the app didn't even finish |
| 304 | // drawing when the user exits, but we have a saved surface from last time, |
| 305 | // we still want to keep that surface.) |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 306 | return allDrawn || mAnimatingWithSavedSurface; |
| 307 | } |
| 308 | |
| 309 | boolean hasSavedSurface() { |
| 310 | for (int i = windows.size() -1; i >= 0; i--) { |
| 311 | final WindowState ws = windows.get(i); |
| 312 | if (ws.hasSavedSurface()) { |
| 313 | return true; |
| 314 | } |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 315 | } |
| 316 | return false; |
| 317 | } |
| 318 | |
| 319 | void restoreSavedSurfaces() { |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 320 | if (!hasSavedSurface()) { |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 321 | return; |
| 322 | } |
| 323 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 324 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM, |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 325 | "Restoring saved surfaces: " + this + ", allDrawn=" + allDrawn); |
| 326 | |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 327 | mAnimatingWithSavedSurface = true; |
| 328 | for (int i = windows.size() - 1; i >= 0; i--) { |
| 329 | WindowState ws = windows.get(i); |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 330 | ws.restoreSavedSurface(); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | |
| 334 | void destroySavedSurfaces() { |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 335 | for (int i = windows.size() - 1; i >= 0; i--) { |
| 336 | WindowState win = windows.get(i); |
| 337 | win.destroySavedSurface(); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | |
Wale Ogunwale | 98e70d0 | 2014-11-10 12:12:27 -0800 | [diff] [blame] | 341 | @Override |
Craig Mautner | 7c9ee19 | 2014-08-14 16:08:26 -0700 | [diff] [blame] | 342 | void removeAllWindows() { |
Craig Mautner | 7b4655d | 2014-11-20 12:13:22 -0800 | [diff] [blame] | 343 | for (int winNdx = allAppWindows.size() - 1; winNdx >= 0; |
| 344 | // removeWindowLocked at bottom of loop may remove multiple entries from |
| 345 | // allAppWindows if the window to be removed has child windows. It also may |
| 346 | // not remove any windows from allAppWindows at all if win is exiting and |
| 347 | // currently animating away. This ensures that winNdx is monotonically decreasing |
| 348 | // and never beyond allAppWindows bounds. |
| 349 | winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) { |
| 350 | WindowState win = allAppWindows.get(winNdx); |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 351 | if (DEBUG_WINDOW_MOVEMENT) { |
| 352 | Slog.w(TAG, "removeAllWindows: removing win=" + win); |
Wale Ogunwale | 98e70d0 | 2014-11-10 12:12:27 -0800 | [diff] [blame] | 353 | } |
| 354 | |
Wale Ogunwale | a6ab5c4 | 2015-04-24 09:00:25 -0700 | [diff] [blame] | 355 | service.removeWindowLocked(win); |
Craig Mautner | 7c9ee19 | 2014-08-14 16:08:26 -0700 | [diff] [blame] | 356 | } |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 357 | allAppWindows.clear(); |
| 358 | windows.clear(); |
Craig Mautner | 7c9ee19 | 2014-08-14 16:08:26 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 361 | void removeAllDeadWindows() { |
| 362 | for (int winNdx = allAppWindows.size() - 1; winNdx >= 0; |
| 363 | // removeWindowLocked at bottom of loop may remove multiple entries from |
| 364 | // allAppWindows if the window to be removed has child windows. It also may |
| 365 | // not remove any windows from allAppWindows at all if win is exiting and |
| 366 | // currently animating away. This ensures that winNdx is monotonically decreasing |
| 367 | // and never beyond allAppWindows bounds. |
| 368 | winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) { |
| 369 | WindowState win = allAppWindows.get(winNdx); |
| 370 | if (win.mAppDied) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 371 | if (DEBUG_WINDOW_MOVEMENT) { |
| 372 | Slog.w(TAG, "removeAllDeadWindows: " + win); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 373 | } |
| 374 | // Set mDestroying, we don't want any animation or delayed removal here. |
| 375 | win.mDestroying = true; |
| 376 | service.removeWindowLocked(win); |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 381 | void setReplacingWindows(boolean animate) { |
| 382 | if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + appWindowToken |
| 383 | + " with replacing windows."); |
| 384 | |
| 385 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 386 | final WindowState w = allAppWindows.get(i); |
| 387 | w.setReplacing(animate); |
| 388 | } |
| 389 | if (animate) { |
| 390 | // Set-up dummy animation so we can start treating windows associated with this |
| 391 | // token like they are in transition before the new app window is ready for us to |
| 392 | // run the real transition animation. |
| 393 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, |
| 394 | "setReplacingWindow() Setting dummy animation on: " + this); |
| 395 | mAppAnimator.setDummyAnimation(); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | void addWindow(WindowState w) { |
| 400 | for (int i = allAppWindows.size() - 1; i >= 0; i--) { |
| 401 | WindowState candidate = allAppWindows.get(i); |
| 402 | if (candidate.mWillReplaceWindow && candidate.mReplacingWindow == null && |
| 403 | candidate.getWindowTag().equals(w.getWindowTag().toString())) { |
| 404 | candidate.mReplacingWindow = w; |
| 405 | } |
| 406 | } |
| 407 | allAppWindows.add(w); |
| 408 | } |
| 409 | |
| 410 | boolean waitingForReplacement() { |
| 411 | for (int i = allAppWindows.size() -1; i >= 0; i--) { |
| 412 | WindowState candidate = allAppWindows.get(i); |
| 413 | if (candidate.mWillReplaceWindow) { |
| 414 | return true; |
| 415 | } |
| 416 | } |
| 417 | return false; |
| 418 | } |
| 419 | |
| 420 | void clearTimedoutReplaceesLocked() { |
| 421 | for (int i = allAppWindows.size() - 1; i >= 0; |
| 422 | // removeWindowLocked at bottom of loop may remove multiple entries from |
| 423 | // allAppWindows if the window to be removed has child windows. It also may |
| 424 | // not remove any windows from allAppWindows at all if win is exiting and |
| 425 | // currently animating away. This ensures that winNdx is monotonically decreasing |
| 426 | // and never beyond allAppWindows bounds. |
| 427 | i = Math.min(i - 1, allAppWindows.size() - 1)) { |
| 428 | WindowState candidate = allAppWindows.get(i); |
| 429 | if (candidate.mWillReplaceWindow == false) { |
| 430 | continue; |
| 431 | } |
| 432 | candidate.mWillReplaceWindow = false; |
| 433 | service.removeWindowLocked(candidate); |
| 434 | } |
| 435 | } |
| 436 | |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 437 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 438 | void dump(PrintWriter pw, String prefix) { |
| 439 | super.dump(pw, prefix); |
| 440 | if (appToken != null) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 441 | pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 442 | } |
| 443 | if (allAppWindows.size() > 0) { |
| 444 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 445 | } |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 446 | pw.print(prefix); pw.print("task="); pw.println(mTask); |
| 447 | pw.print(prefix); pw.print(" appFullscreen="); pw.print(appFullscreen); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 448 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 449 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 450 | pw.print(" clientHidden="); pw.print(clientHidden); |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 451 | pw.print(" reportedDrawn="); pw.print(reportedDrawn); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 452 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 453 | if (paused) { |
| 454 | pw.print(prefix); pw.print("paused="); pw.println(paused); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 455 | } |
| 456 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 457 | || allDrawn || mAppAnimator.allDrawn) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 458 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 459 | pw.print(numInterestingWindows); |
| 460 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 461 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 462 | pw.print(" allDrawn="); pw.print(allDrawn); |
| 463 | pw.print(" (animator="); pw.print(mAppAnimator.allDrawn); |
| 464 | pw.println(")"); |
| 465 | } |
| 466 | if (inPendingTransaction) { |
| 467 | pw.print(prefix); pw.print("inPendingTransaction="); |
| 468 | pw.println(inPendingTransaction); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 469 | } |
Craig Mautner | 799bc1d | 2015-01-14 10:33:48 -0800 | [diff] [blame] | 470 | if (startingData != null || removed || firstWindowDrawn || mIsExiting) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 471 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 472 | pw.print(" removed="); pw.print(removed); |
Craig Mautner | 3d7ca31 | 2015-01-08 10:56:00 -0800 | [diff] [blame] | 473 | pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn); |
Craig Mautner | 799bc1d | 2015-01-14 10:33:48 -0800 | [diff] [blame] | 474 | pw.print(" mIsExiting="); pw.println(mIsExiting); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 475 | } |
| 476 | if (startingWindow != null || startingView != null |
| 477 | || startingDisplayed || startingMoved) { |
| 478 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 479 | pw.print(" startingView="); pw.print(startingView); |
| 480 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 481 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 482 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | @Override |
| 486 | public String toString() { |
| 487 | if (stringName == null) { |
| 488 | StringBuilder sb = new StringBuilder(); |
| 489 | sb.append("AppWindowToken{"); |
| 490 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 491 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 492 | stringName = sb.toString(); |
| 493 | } |
| 494 | return stringName; |
| 495 | } |
Jeff Brown | e9bdb31 | 2012-04-05 15:30:10 -0700 | [diff] [blame] | 496 | } |