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; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 20 | import static android.view.Display.DEFAULT_DISPLAY; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 21 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 22 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 23 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 24 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
| 25 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS; |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 26 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 27 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; |
| 28 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 29 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 30 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
| 31 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT; |
| 32 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 33 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 34 | import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN; |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 35 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_NONE; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 36 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 37 | import static com.android.server.wm.WindowManagerService.logWithStack; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 38 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 39 | import com.android.server.input.InputApplicationHandle; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 40 | import com.android.server.wm.WindowManagerService.H; |
| 41 | |
Filip Gruszczynski | a590c99 | 2015-11-25 16:45:26 -0800 | [diff] [blame] | 42 | import android.annotation.NonNull; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 43 | import android.content.pm.ActivityInfo; |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 44 | import android.content.res.Configuration; |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 45 | import android.graphics.Rect; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 46 | import android.os.Binder; |
| 47 | import android.os.IBinder; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 48 | import android.os.Message; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 49 | import android.os.SystemClock; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 50 | import android.util.Slog; |
| 51 | import android.view.IApplicationToken; |
| 52 | import android.view.View; |
| 53 | import android.view.WindowManager; |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 54 | import android.view.animation.Animation; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 55 | |
| 56 | import java.io.PrintWriter; |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 57 | import java.util.ArrayDeque; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 58 | import java.util.ArrayList; |
| 59 | |
| 60 | class AppTokenList extends ArrayList<AppWindowToken> { |
| 61 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * Version of WindowToken that is specifically for a particular application (or |
| 65 | * really activity) that is displaying windows. |
| 66 | */ |
Craig Mautner | e32c307 | 2012-03-12 15:25:35 -0700 | [diff] [blame] | 67 | class AppWindowToken extends WindowToken { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 68 | private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM; |
| 69 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 70 | // Non-null only for application tokens. |
| 71 | final IApplicationToken appToken; |
| 72 | |
Filip Gruszczynski | a590c99 | 2015-11-25 16:45:26 -0800 | [diff] [blame] | 73 | @NonNull final AppWindowAnimator mAppAnimator; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 74 | |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 75 | final boolean voiceInteraction; |
| 76 | |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 77 | Task mTask; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 78 | boolean appFullscreen; |
| 79 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Craig Mautner | 4c5eb22 | 2013-11-18 12:59:05 -0800 | [diff] [blame] | 80 | boolean layoutConfigChanges; |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 81 | boolean showForAllUsers; |
Yorke Lee | 0e85247 | 2016-06-15 10:03:18 -0700 | [diff] [blame] | 82 | int targetSdk; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 83 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 84 | // The input dispatching timeout for this application token in nanoseconds. |
| 85 | long inputDispatchingTimeoutNanos; |
| 86 | |
| 87 | // These are used for determining when all windows associated with |
| 88 | // an activity have been drawn, so they can be made visible together |
| 89 | // at the same time. |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 90 | // initialize so that it doesn't match mTransactionSequence which is an int. |
| 91 | long lastTransactionSequence = Long.MIN_VALUE; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 92 | int numInterestingWindows; |
| 93 | int numDrawnWindows; |
| 94 | boolean inPendingTransaction; |
| 95 | boolean allDrawn; |
Craig Mautner | 7636dfb | 2012-11-16 15:24:11 -0800 | [diff] [blame] | 96 | // Set to true when this app creates a surface while in the middle of an animation. In that |
| 97 | // case do not clear allDrawn until the animation completes. |
| 98 | boolean deferClearAllDrawn; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 99 | |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 100 | // These are to track the app's real drawing status if there were no saved surfaces. |
| 101 | boolean allDrawnExcludingSaved; |
| 102 | int numInterestingWindowsExcludingSaved; |
| 103 | int numDrawnWindowsExclusingSaved; |
| 104 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 105 | // Is this window's surface needed? This is almost like hidden, except |
| 106 | // it will sometimes be true a little earlier: when the token has |
| 107 | // been shown, but is still waiting for its app transition to execute |
| 108 | // before making its windows shown. |
| 109 | boolean hiddenRequested; |
| 110 | |
| 111 | // Have we told the window clients to hide themselves? |
| 112 | boolean clientHidden; |
| 113 | |
| 114 | // Last visibility state we reported to the app token. |
| 115 | boolean reportedVisible; |
| 116 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 117 | // Last drawn state we reported to the app token. |
| 118 | boolean reportedDrawn; |
| 119 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 120 | // Set to true when the token has been removed from the window mgr. |
| 121 | boolean removed; |
| 122 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 123 | // Information about an application starting window if displayed. |
| 124 | StartingData startingData; |
| 125 | WindowState startingWindow; |
| 126 | View startingView; |
| 127 | boolean startingDisplayed; |
| 128 | boolean startingMoved; |
| 129 | boolean firstWindowDrawn; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 130 | private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults = |
| 131 | new WindowState.UpdateReportedVisibilityResults(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 132 | |
| 133 | // Input application handle used by the input dispatcher. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 134 | final InputApplicationHandle mInputApplicationHandle; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 135 | |
Craig Mautner | 799bc1d | 2015-01-14 10:33:48 -0800 | [diff] [blame] | 136 | boolean mIsExiting; |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 137 | |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 138 | boolean mLaunchTaskBehind; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 139 | boolean mEnteringAnimation; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 140 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 141 | boolean mAlwaysFocusable; |
| 142 | |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 143 | boolean mAppStopped; |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 144 | int mRotationAnimationHint; |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 145 | int mPendingRelaunchCount; |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 146 | |
Robert Carr | 91b22809 | 2016-06-28 17:32:37 -0700 | [diff] [blame] | 147 | private ArrayList<WindowSurfaceController.SurfaceControlWithBackground> mSurfaceViewBackgrounds = |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 148 | new ArrayList<>(); |
Robert Carr | 91b22809 | 2016-06-28 17:32:37 -0700 | [diff] [blame] | 149 | |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 150 | ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>(); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 151 | ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>(); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 152 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 153 | AppWindowToken(WindowManagerService service, IApplicationToken token, boolean _voiceInteraction) { |
| 154 | super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true); |
| 155 | appToken = token; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 156 | voiceInteraction = _voiceInteraction; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 157 | mInputApplicationHandle = new InputApplicationHandle(this); |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 158 | mAppAnimator = new AppWindowAnimator(this, service); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 159 | } |
| 160 | |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 161 | void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) { |
| 162 | firstWindowDrawn = true; |
| 163 | |
| 164 | // We now have a good window to show, remove dead placeholders |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 165 | removeDeadWindows(); |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 166 | |
| 167 | if (startingData != null) { |
| 168 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting " |
| 169 | + win.mToken + ": first real window is shown, no animation"); |
| 170 | // If this initial window is animating, stop it -- we will do an animation to reveal |
| 171 | // it from behind the starting window, so there is no need for it to also be doing its |
| 172 | // own stuff. |
| 173 | winAnimator.clearAnimation(); |
| 174 | winAnimator.mService.mFinishedStarting.add(this); |
| 175 | winAnimator.mService.mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 176 | } |
| 177 | updateReportedVisibilityLocked(); |
| 178 | } |
| 179 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 180 | void updateReportedVisibilityLocked() { |
| 181 | if (appToken == null) { |
| 182 | return; |
| 183 | } |
| 184 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 185 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 186 | final int count = mChildren.size(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 187 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 188 | mReportedVisibilityResults.reset(); |
| 189 | |
| 190 | for (int i = 0; i < count; i++) { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 191 | final WindowState win = (WindowState) mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 192 | win.updateReportedVisibility(mReportedVisibilityResults); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 193 | } |
| 194 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 195 | int numInteresting = mReportedVisibilityResults.numInteresting; |
| 196 | int numVisible = mReportedVisibilityResults.numVisible; |
| 197 | int numDrawn = mReportedVisibilityResults.numDrawn; |
| 198 | boolean nowGone = mReportedVisibilityResults.nowGone; |
| 199 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 200 | boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 201 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 202 | if (!nowGone) { |
| 203 | // If the app is not yet gone, then it can only become visible/drawn. |
| 204 | if (!nowDrawn) { |
| 205 | nowDrawn = reportedDrawn; |
| 206 | } |
| 207 | if (!nowVisible) { |
| 208 | nowVisible = reportedVisible; |
| 209 | } |
| 210 | } |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 211 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 212 | + numInteresting + " visible=" + numVisible); |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 213 | if (nowDrawn != reportedDrawn) { |
| 214 | if (nowDrawn) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 215 | mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_DRAWN, this).sendToTarget(); |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 216 | } |
| 217 | reportedDrawn = nowDrawn; |
| 218 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 219 | if (nowVisible != reportedVisible) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 220 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 221 | "Visibility changed in " + this + ": vis=" + nowVisible); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 222 | reportedVisible = nowVisible; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 223 | mService.mH.obtainMessage(H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 224 | nowVisible ? 1 : 0, nowGone ? 1 : 0, this).sendToTarget(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 228 | boolean setVisibility(WindowManager.LayoutParams lp, |
| 229 | boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) { |
| 230 | |
| 231 | boolean delayed = false; |
| 232 | inPendingTransaction = false; |
| 233 | |
| 234 | if (clientHidden == visible) { |
| 235 | clientHidden = !visible; |
| 236 | sendAppVisibilityToClients(); |
| 237 | } |
| 238 | |
| 239 | // Allow for state changes and animation to be applied if: |
| 240 | // * token is transitioning visibility state |
| 241 | // * or the token was marked as hidden and is exiting before we had a chance to play the |
| 242 | // transition animation |
| 243 | // * or this is an opening app and windows are being replaced. |
| 244 | boolean visibilityChanged = false; |
| 245 | if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) { |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 246 | final AccessibilityController accessibilityController = mService.mAccessibilityController; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 247 | boolean changed = false; |
| 248 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, |
| 249 | "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout); |
| 250 | |
| 251 | boolean runningAppAnimation = false; |
| 252 | |
| 253 | if (transit != AppTransition.TRANSIT_UNSET) { |
| 254 | if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) { |
| 255 | mAppAnimator.setNullAnimation(); |
| 256 | } |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 257 | if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 258 | delayed = runningAppAnimation = true; |
| 259 | } |
| 260 | final WindowState window = findMainWindow(); |
| 261 | //TODO (multidisplay): Magnification is supported only for the default display. |
| 262 | if (window != null && accessibilityController != null |
| 263 | && window.getDisplayId() == DEFAULT_DISPLAY) { |
| 264 | accessibilityController.onAppWindowTransitionLocked(window, transit); |
| 265 | } |
| 266 | changed = true; |
| 267 | } |
| 268 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 269 | final int windowsCount = mChildren.size(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 270 | for (int i = 0; i < windowsCount; i++) { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 271 | final WindowState win = (WindowState) mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 272 | changed |= win.onAppVisibilityChanged(visible, runningAppAnimation); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | hidden = hiddenRequested = !visible; |
| 276 | visibilityChanged = true; |
| 277 | if (!visible) { |
| 278 | stopFreezingScreen(true, true); |
| 279 | } else { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 280 | // If we are being set visible, and the starting window is not yet displayed, |
| 281 | // then make sure it doesn't get displayed. |
| 282 | if (startingWindow != null && !startingWindow.isDrawnLw()) { |
| 283 | startingWindow.mPolicyVisibility = false; |
| 284 | startingWindow.mPolicyVisibilityAfterAnim = false; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
| 288 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this |
| 289 | + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested); |
| 290 | |
| 291 | if (changed) { |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 292 | mService.mInputMonitor.setUpdateInputWindowsNeededLw(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 293 | if (performLayout) { |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 294 | mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 295 | false /*updateInputWindows*/); |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 296 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 297 | } |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 298 | mService.mInputMonitor.updateInputWindowsLw(false /*force*/); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
| 302 | if (mAppAnimator.animation != null) { |
| 303 | delayed = true; |
| 304 | } |
| 305 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 306 | for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) { |
| 307 | if (((WindowState) mChildren.get(i)).isWindowAnimationSet()) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 308 | delayed = true; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | if (visibilityChanged) { |
| 313 | if (visible && !delayed) { |
| 314 | // The token was made immediately visible, there will be no entrance animation. |
| 315 | // We need to inform the client the enter animation was finished. |
| 316 | mEnteringAnimation = true; |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 317 | mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 320 | if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 321 | // The token is not closing nor opening, so even if there is an animation set, that |
| 322 | // doesn't mean that it goes through the normal app transition cycle so we have |
| 323 | // to inform the docked controller about visibility change. |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 324 | mService.getDefaultDisplayContentLocked().getDockedDividerController() |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 325 | .notifyAppVisibilityChanged(); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | return delayed; |
| 330 | } |
| 331 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 332 | WindowState findMainWindow() { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 333 | WindowState candidate = null; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 334 | int j = mChildren.size(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 335 | while (j > 0) { |
| 336 | j--; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 337 | final WindowState win = (WindowState) mChildren.get(j); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 338 | final int type = win.mAttrs.type; |
| 339 | // No need to loop through child window as base application and starting types can't be |
| 340 | // child windows. |
| 341 | if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 342 | // 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] | 343 | // happens for example when replacing windows during an activity relaunch. When |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 344 | // constructing the animation, we want the new window, not the exiting one. |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 345 | if (win.mAnimatingExit) { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 346 | candidate = win; |
| 347 | } else { |
| 348 | return win; |
| 349 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 350 | } |
| 351 | } |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 352 | return candidate; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 353 | } |
| 354 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 355 | boolean windowsAreFocusable() { |
| 356 | return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable; |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 357 | } |
| 358 | |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 359 | void removeAppFromTaskLocked() { |
| 360 | mIsExiting = false; |
| 361 | removeAllWindows(); |
| 362 | |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 363 | // Use local variable because removeAppToken will null out mTask. |
| 364 | final Task task = mTask; |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 365 | if (task != null) { |
| 366 | if (!task.removeAppToken(this)) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 367 | Slog.e(TAG, "removeAppFromTaskLocked: token=" + this |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 368 | + " not found."); |
| 369 | } |
| 370 | task.mStack.mExitingAppTokens.remove(this); |
| 371 | } |
| 372 | } |
| 373 | |
Chong Zhang | e05bcb1 | 2016-07-26 17:47:29 -0700 | [diff] [blame] | 374 | void clearAnimatingFlags() { |
Chong Zhang | b0d2670 | 2016-08-12 16:03:29 -0700 | [diff] [blame] | 375 | boolean wallpaperMightChange = false; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 376 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 377 | final WindowState win = (WindowState) mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 378 | wallpaperMightChange |= win.clearAnimatingFlags(); |
Chong Zhang | e05bcb1 | 2016-07-26 17:47:29 -0700 | [diff] [blame] | 379 | } |
Chong Zhang | b0d2670 | 2016-08-12 16:03:29 -0700 | [diff] [blame] | 380 | if (wallpaperMightChange) { |
| 381 | requestUpdateWallpaperIfNeeded(); |
| 382 | } |
Chong Zhang | e05bcb1 | 2016-07-26 17:47:29 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 385 | void destroySurfaces() { |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 386 | destroySurfaces(false /*cleanupOnResume*/); |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure |
| 391 | * the client has finished with them. |
| 392 | * |
| 393 | * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If |
| 394 | * set to true, destroy only surfaces of removed windows, and clear relevant flags of the |
| 395 | * others so that they are ready to be reused. If set to false (common case), destroy all |
| 396 | * surfaces that's eligible, if the app is already stopped. |
| 397 | */ |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 398 | private void destroySurfaces(boolean cleanupOnResume) { |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 399 | final DisplayContentList displayList = new DisplayContentList(); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 400 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 401 | final WindowState win = (WindowState) mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 402 | final boolean destroyed = win.destroySurface(cleanupOnResume, mAppStopped); |
Chong Zhang | eb66557 | 2016-05-09 18:28:27 -0700 | [diff] [blame] | 403 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 404 | if (destroyed) { |
| 405 | final DisplayContent displayContent = win.getDisplayContent(); |
| 406 | if (displayContent != null && !displayList.contains(displayContent)) { |
| 407 | displayList.add(displayContent); |
| 408 | } |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 409 | } |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 410 | } |
| 411 | for (int i = 0; i < displayList.size(); i++) { |
| 412 | final DisplayContent displayContent = displayList.get(i); |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 413 | mService.mLayersController.assignLayersLocked(displayContent.getWindowList()); |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 414 | displayContent.layoutNeeded = true; |
| 415 | } |
| 416 | } |
| 417 | |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 418 | /** |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 419 | * Notify that the app is now resumed, and it was not stopped before, perform a clean |
| 420 | * up of the surfaces |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 421 | */ |
Chong Zhang | ad24f96 | 2016-08-25 12:12:33 -0700 | [diff] [blame] | 422 | void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) { |
| 423 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped |
| 424 | + " allowSavedSurface=" + allowSavedSurface + " " + this); |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 425 | mAppStopped = false; |
| 426 | if (!wasStopped) { |
| 427 | destroySurfaces(true /*cleanupOnResume*/); |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 428 | } |
Chong Zhang | ad24f96 | 2016-08-25 12:12:33 -0700 | [diff] [blame] | 429 | if (!allowSavedSurface) { |
| 430 | destroySavedSurfaces(); |
| 431 | } |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 432 | } |
| 433 | |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 434 | /** |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 435 | * Notify that the app has stopped, and it is okay to destroy any surfaces which were |
| 436 | * keeping alive in case they were still being used. |
| 437 | */ |
| 438 | void notifyAppStopped() { |
| 439 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this); |
| 440 | mAppStopped = true; |
| 441 | destroySurfaces(); |
| 442 | // Remove any starting window that was added for this app if they are still around. |
| 443 | mTask.mService.scheduleRemoveStartingWindowLocked(this); |
| 444 | } |
| 445 | |
| 446 | /** |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 447 | * Checks whether we should save surfaces for this app. |
| 448 | * |
| 449 | * @return true if the surfaces should be saved, false otherwise. |
| 450 | */ |
| 451 | boolean shouldSaveSurface() { |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 452 | // We want to save surface if the app's windows are "allDrawn". |
| 453 | // (If we started entering animation early with saved surfaces, allDrawn |
| 454 | // should have been restored to true. So we'll save again in that case |
| 455 | // even if app didn't actually finish drawing.) |
| 456 | return allDrawn; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 457 | } |
| 458 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 459 | private boolean canRestoreSurfaces() { |
| 460 | for (int i = mChildren.size() -1; i >= 0; i--) { |
| 461 | final WindowState w = (WindowState) mChildren.get(i); |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 462 | if (w.canRestoreSurface()) { |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 463 | return true; |
| 464 | } |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 465 | } |
| 466 | return false; |
| 467 | } |
| 468 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 469 | private void clearWasVisibleBeforeClientHidden() { |
| 470 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 471 | final WindowState w = (WindowState) mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 472 | w.clearWasVisibleBeforeClientHidden(); |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 476 | /** |
| 477 | * Whether the app has some window that is invisible in layout, but |
| 478 | * animating with saved surface. |
| 479 | */ |
| 480 | boolean isAnimatingInvisibleWithSavedSurface() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 481 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 482 | final WindowState w = (WindowState) mChildren.get(i); |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 483 | if (w.isAnimatingInvisibleWithSavedSurface()) { |
| 484 | return true; |
| 485 | } |
| 486 | } |
| 487 | return false; |
| 488 | } |
| 489 | |
| 490 | /** |
| 491 | * Hide all window surfaces that's still invisible in layout but animating |
| 492 | * with a saved surface, and mark them destroying. |
| 493 | */ |
| 494 | void stopUsingSavedSurfaceLocked() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 495 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 496 | final WindowState w = (WindowState) mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 497 | w.stopUsingSavedSurface(); |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 498 | } |
| 499 | destroySurfaces(); |
| 500 | } |
| 501 | |
Chong Zhang | f58631a | 2016-05-24 16:02:10 -0700 | [diff] [blame] | 502 | void markSavedSurfaceExiting() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 503 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 504 | final WindowState w = (WindowState) mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 505 | w.markSavedSurfaceExiting(); |
Chong Zhang | f58631a | 2016-05-24 16:02:10 -0700 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 509 | void restoreSavedSurfaceForInterestingWindows() { |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 510 | if (!canRestoreSurfaces()) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 511 | clearWasVisibleBeforeClientHidden(); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 512 | return; |
| 513 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 514 | |
| 515 | // Check if all interesting windows are drawn and we can mark allDrawn=true. |
| 516 | int interestingNotDrawn = -1; |
| 517 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 518 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 519 | final WindowState w = (WindowState) mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 520 | interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow(); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 521 | } |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 522 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 523 | if (!allDrawn) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 524 | allDrawn = (interestingNotDrawn == 0); |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 525 | if (allDrawn) { |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 526 | mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget(); |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 527 | } |
| 528 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 529 | clearWasVisibleBeforeClientHidden(); |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 530 | |
| 531 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 532 | "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn |
| 533 | + " interestingNotDrawn=" + interestingNotDrawn); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | void destroySavedSurfaces() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 537 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 538 | final WindowState win = (WindowState) mChildren.get(i); |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 539 | win.destroySavedSurface(); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 540 | } |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | void clearAllDrawn() { |
| 544 | allDrawn = false; |
| 545 | deferClearAllDrawn = false; |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 546 | allDrawnExcludingSaved = false; |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Wale Ogunwale | 98e70d0 | 2014-11-10 12:12:27 -0800 | [diff] [blame] | 549 | @Override |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 550 | void removeWindow(WindowState win) { |
| 551 | super.removeWindow(win); |
| 552 | |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 553 | // TODO: Something smells about the code below...Is there a better way? |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 554 | if (startingWindow == win) { |
| 555 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win); |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 556 | mService.scheduleRemoveStartingWindowLocked(this); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 557 | } else if (mChildren.size() == 0 && startingData != null) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 558 | // If this is the last window and we had requested a starting transition window, |
| 559 | // well there is no point now. |
| 560 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingWindow"); |
| 561 | startingData = null; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 562 | } else if (mChildren.size() == 1 && startingView != null) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 563 | // If this is the last window except for a starting transition window, |
| 564 | // we need to get rid of the starting transition. |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 565 | mService.scheduleRemoveStartingWindowLocked(this); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 566 | } |
| 567 | } |
| 568 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 569 | void removeDeadWindows() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 570 | for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) { |
| 571 | WindowState win = (WindowState) mChildren.get(winNdx); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 572 | if (win.mAppDied) { |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 573 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG, |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 574 | "removeDeadWindows: " + win); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 575 | // Set mDestroying, we don't want any animation or delayed removal here. |
| 576 | win.mDestroying = true; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 577 | // Also removes child windows. |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 578 | win.removeIfPossible(); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | } |
| 582 | |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 583 | boolean hasWindowsAlive() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 584 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 585 | // No need to loop through child windows as the answer should be the same as that of the |
| 586 | // parent window. |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 587 | if (!((WindowState) mChildren.get(i)).mAppDied) { |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 588 | return true; |
| 589 | } |
| 590 | } |
| 591 | return false; |
| 592 | } |
| 593 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 594 | void setWillReplaceWindows(boolean animate) { |
Wale Ogunwale | 455fac5 | 2016-07-21 07:24:49 -0700 | [diff] [blame] | 595 | if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, |
| 596 | "Marking app token " + this + " with replacing windows."); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 597 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 598 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 599 | final WindowState w = (WindowState) mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 600 | w.setWillReplaceWindow(animate); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 601 | } |
| 602 | if (animate) { |
| 603 | // Set-up dummy animation so we can start treating windows associated with this |
| 604 | // token like they are in transition before the new app window is ready for us to |
| 605 | // run the real transition animation. |
| 606 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 607 | "setWillReplaceWindow() Setting dummy animation on: " + this); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 608 | mAppAnimator.setDummyAnimation(); |
| 609 | } |
| 610 | } |
| 611 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 612 | void setWillReplaceChildWindows() { |
Wale Ogunwale | 455fac5 | 2016-07-21 07:24:49 -0700 | [diff] [blame] | 613 | if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 614 | + " with replacing child windows."); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 615 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 616 | final WindowState w = (WindowState) mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 617 | w.setWillReplaceChildWindows(); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 621 | void clearWillReplaceWindows() { |
Wale Ogunwale | 455fac5 | 2016-07-21 07:24:49 -0700 | [diff] [blame] | 622 | if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, |
| 623 | "Resetting app token " + this + " of replacing window marks."); |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 624 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 625 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 626 | final WindowState w = (WindowState) mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 627 | w.clearWillReplaceWindow(); |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 628 | } |
| 629 | } |
| 630 | |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 631 | void requestUpdateWallpaperIfNeeded() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 632 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 633 | final WindowState w = (WindowState) mChildren.get(i); |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 634 | w.requestUpdateWallpaperIfNeeded(); |
| 635 | } |
| 636 | } |
| 637 | |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 638 | boolean isRelaunching() { |
| 639 | return mPendingRelaunchCount > 0; |
| 640 | } |
| 641 | |
| 642 | void startRelaunching() { |
| 643 | if (canFreezeBounds()) { |
| 644 | freezeBounds(); |
| 645 | } |
| 646 | mPendingRelaunchCount++; |
| 647 | } |
| 648 | |
| 649 | void finishRelaunching() { |
| 650 | if (canFreezeBounds()) { |
| 651 | unfreezeBounds(); |
| 652 | } |
| 653 | if (mPendingRelaunchCount > 0) { |
| 654 | mPendingRelaunchCount--; |
| 655 | } |
| 656 | } |
| 657 | |
Wale Ogunwale | 8fd7542 | 2016-06-24 14:20:37 -0700 | [diff] [blame] | 658 | void clearRelaunching() { |
Wale Ogunwale | 37dbafc | 2016-06-27 10:15:20 -0700 | [diff] [blame] | 659 | if (mPendingRelaunchCount == 0) { |
| 660 | return; |
| 661 | } |
Wale Ogunwale | 8fd7542 | 2016-06-24 14:20:37 -0700 | [diff] [blame] | 662 | if (canFreezeBounds()) { |
| 663 | unfreezeBounds(); |
| 664 | } |
| 665 | mPendingRelaunchCount = 0; |
| 666 | } |
| 667 | |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 668 | @Override |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 669 | void addWindow(WindowState w) { |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 670 | super.addWindow(w); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 671 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 672 | boolean gotReplacementWindow = false; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 673 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 674 | final WindowState candidate = (WindowState) mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 675 | gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w); |
| 676 | } |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 677 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 678 | // if we got a replacement window, reset the timeout to give drawing more time |
| 679 | if (gotReplacementWindow) { |
| 680 | mService.scheduleWindowReplacementTimeouts(this); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 681 | } |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | boolean waitingForReplacement() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 685 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 686 | final WindowState candidate = (WindowState) mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 687 | if (candidate.waitingForReplacement()) { |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 688 | return true; |
| 689 | } |
| 690 | } |
| 691 | return false; |
| 692 | } |
| 693 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 694 | void onWindowReplacementTimeout() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 695 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 696 | ((WindowState) mChildren.get(i)).onWindowReplacementTimeout(); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 697 | } |
| 698 | } |
| 699 | |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 700 | private boolean canFreezeBounds() { |
| 701 | // For freeform windows, we can't freeze the bounds at the moment because this would make |
| 702 | // the resizing unresponsive. |
| 703 | return mTask != null && !mTask.inFreeformWorkspace(); |
| 704 | } |
| 705 | |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 706 | /** |
| 707 | * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds |
| 708 | * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even |
| 709 | * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen |
| 710 | * with a queue. |
| 711 | */ |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 712 | private void freezeBounds() { |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 713 | mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds)); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 714 | |
| 715 | if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) { |
| 716 | // We didn't call prepareFreezingBounds on the task, so use the current value. |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 717 | final Configuration config = new Configuration(mService.mCurConfiguration); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 718 | config.updateFrom(mTask.mOverrideConfig); |
| 719 | mFrozenMergedConfig.offer(config); |
| 720 | } else { |
| 721 | mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig)); |
| 722 | } |
| 723 | mTask.mPreparedFrozenMergedConfig.setToDefaults(); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | /** |
| 727 | * Unfreezes the previously frozen bounds. See {@link #freezeBounds}. |
| 728 | */ |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 729 | private void unfreezeBounds() { |
Wale Ogunwale | 37dbafc | 2016-06-27 10:15:20 -0700 | [diff] [blame] | 730 | if (!mFrozenBounds.isEmpty()) { |
| 731 | mFrozenBounds.remove(); |
| 732 | } |
| 733 | if (!mFrozenMergedConfig.isEmpty()) { |
| 734 | mFrozenMergedConfig.remove(); |
| 735 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 736 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 737 | final WindowState win = (WindowState) mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 738 | win.onUnfreezeBounds(); |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 739 | } |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 740 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 741 | } |
| 742 | |
Robert Carr | 91b22809 | 2016-06-28 17:32:37 -0700 | [diff] [blame] | 743 | void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) { |
| 744 | mSurfaceViewBackgrounds.add(background); |
| 745 | } |
| 746 | |
| 747 | void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) { |
| 748 | mSurfaceViewBackgrounds.remove(background); |
| 749 | updateSurfaceViewBackgroundVisibilities(); |
| 750 | } |
| 751 | |
| 752 | // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating. |
| 753 | // However, we need to ensure one SurfaceView doesn't cover another when they are both placed |
| 754 | // below the main app window (as traditionally a SurfaceView which is never drawn |
| 755 | // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable |
| 756 | // the background for the SurfaceView with lowest Z order |
| 757 | void updateSurfaceViewBackgroundVisibilities() { |
| 758 | WindowSurfaceController.SurfaceControlWithBackground bottom = null; |
| 759 | int bottomLayer = Integer.MAX_VALUE; |
| 760 | for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) { |
| 761 | WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i); |
| 762 | if (sc.mVisible && sc.mLayer < bottomLayer) { |
| 763 | bottomLayer = sc.mLayer; |
| 764 | bottom = sc; |
| 765 | } |
| 766 | } |
| 767 | for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) { |
| 768 | WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i); |
| 769 | sc.updateBackgroundVisibility(sc != bottom); |
| 770 | } |
| 771 | } |
| 772 | |
Jorim Jaggi | 6626f54 | 2016-08-22 13:08:44 -0700 | [diff] [blame] | 773 | /** |
| 774 | * See {@link WindowManagerService#overridePlayingAppAnimationsLw} |
| 775 | */ |
| 776 | void overridePlayingAppAnimations(Animation a) { |
| 777 | if (mAppAnimator.isAnimating()) { |
| 778 | final WindowState win = findMainWindow(); |
| 779 | final int width = win.mContainingFrame.width(); |
| 780 | final int height = win.mContainingFrame.height(); |
| 781 | mAppAnimator.setAnimation(a, width, height, false, STACK_CLIP_NONE); |
| 782 | } |
| 783 | } |
| 784 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 785 | void resetJustMovedInStack() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 786 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 787 | ((WindowState) mChildren.get(i)).resetJustMovedInStack(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 788 | } |
| 789 | } |
| 790 | |
| 791 | void notifyMovedInStack() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 792 | for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) { |
| 793 | final WindowState win = (WindowState) mChildren.get(winNdx); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 794 | win.notifyMovedInStack(); |
| 795 | } |
| 796 | } |
| 797 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 798 | void setAppLayoutChanges(int changes, String reason, int displayId) { |
| 799 | final WindowAnimator windowAnimator = mAppAnimator.mAnimator; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 800 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 801 | // Child windows will be on the same display as their parents. |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 802 | if (displayId == ((WindowState) mChildren.get(i)).getDisplayId()) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 803 | windowAnimator.setPendingLayoutChanges(displayId, changes); |
| 804 | if (DEBUG_LAYOUT_REPEATS) { |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 805 | mService.mWindowPlacerLocked.debugLayoutRepeats( |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 806 | reason, windowAnimator.getPendingLayoutChanges(displayId)); |
| 807 | } |
| 808 | break; |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | void removeReplacedWindowIfNeeded(WindowState replacement) { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 814 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 815 | final WindowState win = (WindowState) mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 816 | if (win.removeReplacedWindowIfNeeded(replacement)) { |
| 817 | return; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 818 | } |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | void startFreezingScreen() { |
| 823 | if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden=" |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 824 | + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested=" |
| 825 | + hiddenRequested); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 826 | if (!hiddenRequested) { |
| 827 | if (!mAppAnimator.freezingScreen) { |
| 828 | mAppAnimator.freezingScreen = true; |
| 829 | mAppAnimator.lastFreezeDuration = 0; |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 830 | mService.mAppsFreezingScreen++; |
| 831 | if (mService.mAppsFreezingScreen == 1) { |
| 832 | mService.startFreezingDisplayLocked(false, 0, 0); |
| 833 | mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 834 | mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 835 | } |
| 836 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 837 | final int count = mChildren.size(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 838 | for (int i = 0; i < count; i++) { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 839 | final WindowState w = (WindowState) mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 840 | w.onStartFreezingScreen(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 841 | } |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) { |
| 846 | if (!mAppAnimator.freezingScreen) { |
| 847 | return; |
| 848 | } |
| 849 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 850 | final int count = mChildren.size(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 851 | boolean unfrozeWindows = false; |
| 852 | for (int i = 0; i < count; i++) { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 853 | final WindowState w = (WindowState) mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 854 | unfrozeWindows |= w.onStopFreezingScreen(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 855 | } |
| 856 | if (force || unfrozeWindows) { |
| 857 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this); |
| 858 | mAppAnimator.freezingScreen = false; |
| 859 | mAppAnimator.lastFreezeDuration = |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 860 | (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime); |
| 861 | mService.mAppsFreezingScreen--; |
| 862 | mService.mLastFinishedFreezeSource = this; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 863 | } |
| 864 | if (unfreezeSurfaceNow) { |
| 865 | if (unfrozeWindows) { |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 866 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 867 | } |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 868 | mService.stopFreezingDisplayLocked(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 869 | } |
| 870 | } |
| 871 | |
| 872 | boolean transferStartingWindow(IBinder transferFrom) { |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 873 | final AppWindowToken fromToken = mService.findAppWindowToken(transferFrom); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 874 | if (fromToken == null) { |
| 875 | return false; |
| 876 | } |
| 877 | |
| 878 | final WindowState tStartingWindow = fromToken.startingWindow; |
| 879 | if (tStartingWindow != null && fromToken.startingView != null) { |
| 880 | // In this case, the starting icon has already been displayed, so start |
| 881 | // letting windows get shown immediately without any more transitions. |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 882 | mService.mSkipAppTransitionAnimation = true; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 883 | |
| 884 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow |
| 885 | + " from " + fromToken + " to " + this); |
| 886 | |
| 887 | final long origId = Binder.clearCallingIdentity(); |
| 888 | |
| 889 | // Transfer the starting window over to the new token. |
| 890 | startingData = fromToken.startingData; |
| 891 | startingView = fromToken.startingView; |
| 892 | startingDisplayed = fromToken.startingDisplayed; |
| 893 | fromToken.startingDisplayed = false; |
| 894 | startingWindow = tStartingWindow; |
| 895 | reportedVisible = fromToken.reportedVisible; |
| 896 | fromToken.startingData = null; |
| 897 | fromToken.startingView = null; |
| 898 | fromToken.startingWindow = null; |
| 899 | fromToken.startingMoved = true; |
| 900 | tStartingWindow.mToken = this; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 901 | tStartingWindow.mAppToken = this; |
| 902 | |
| 903 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, |
| 904 | "Removing starting window: " + tStartingWindow); |
| 905 | tStartingWindow.getWindowList().remove(tStartingWindow); |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 906 | mService.mWindowsChanged = true; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 907 | if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, |
| 908 | "Removing starting " + tStartingWindow + " from " + fromToken); |
| 909 | fromToken.removeWindow(tStartingWindow); |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 910 | addWindow(tStartingWindow); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 911 | |
| 912 | // Propagate other interesting state between the tokens. If the old token is displayed, |
| 913 | // we should immediately force the new one to be displayed. If it is animating, we need |
| 914 | // to move that animation to the new one. |
| 915 | if (fromToken.allDrawn) { |
| 916 | allDrawn = true; |
| 917 | deferClearAllDrawn = fromToken.deferClearAllDrawn; |
| 918 | } |
| 919 | if (fromToken.firstWindowDrawn) { |
| 920 | firstWindowDrawn = true; |
| 921 | } |
| 922 | if (!fromToken.hidden) { |
| 923 | hidden = false; |
| 924 | hiddenRequested = false; |
| 925 | } |
| 926 | if (clientHidden != fromToken.clientHidden) { |
| 927 | clientHidden = fromToken.clientHidden; |
| 928 | sendAppVisibilityToClients(); |
| 929 | } |
| 930 | fromToken.mAppAnimator.transferCurrentAnimation( |
| 931 | mAppAnimator, tStartingWindow.mWinAnimator); |
| 932 | |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 933 | mService.updateFocusedWindowLocked( |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 934 | UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/); |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 935 | mService.getDefaultDisplayContentLocked().layoutNeeded = true; |
| 936 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 937 | Binder.restoreCallingIdentity(origId); |
| 938 | return true; |
| 939 | } else if (fromToken.startingData != null) { |
| 940 | // The previous app was getting ready to show a |
| 941 | // starting window, but hasn't yet done so. Steal it! |
| 942 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, |
| 943 | "Moving pending starting from " + fromToken + " to " + this); |
| 944 | startingData = fromToken.startingData; |
| 945 | fromToken.startingData = null; |
| 946 | fromToken.startingMoved = true; |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 947 | final Message m = mService.mH.obtainMessage(H.ADD_STARTING, this); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 948 | // Note: we really want to do sendMessageAtFrontOfQueue() because we want to process the |
| 949 | // message ASAP, before any other queued messages. |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 950 | mService.mH.sendMessageAtFrontOfQueue(m); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 951 | return true; |
| 952 | } |
| 953 | |
| 954 | final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator; |
| 955 | final AppWindowAnimator wAppAnimator = mAppAnimator; |
| 956 | if (tAppAnimator.thumbnail != null) { |
| 957 | // The old token is animating with a thumbnail, transfer that to the new token. |
| 958 | if (wAppAnimator.thumbnail != null) { |
| 959 | wAppAnimator.thumbnail.destroy(); |
| 960 | } |
| 961 | wAppAnimator.thumbnail = tAppAnimator.thumbnail; |
| 962 | wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer; |
| 963 | wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation; |
| 964 | tAppAnimator.thumbnail = null; |
| 965 | } |
| 966 | return false; |
| 967 | } |
| 968 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 969 | boolean isLastWindow(WindowState win) { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 970 | return mChildren.size() == 1 && mChildren.get(0) == win; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | void setAllAppWinAnimators() { |
| 974 | final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators; |
| 975 | allAppWinAnimators.clear(); |
| 976 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 977 | final int windowsCount = mChildren.size(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 978 | for (int j = 0; j < windowsCount; j++) { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 979 | ((WindowState) mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 980 | } |
| 981 | } |
| 982 | |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 983 | @Override |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 984 | AppWindowToken asAppWindowToken() { |
| 985 | // I am an app window token! |
| 986 | return this; |
| 987 | } |
| 988 | |
| 989 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 990 | void dump(PrintWriter pw, String prefix) { |
| 991 | super.dump(pw, prefix); |
| 992 | if (appToken != null) { |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 993 | pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 994 | } |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 995 | pw.print(prefix); pw.print("task="); pw.println(mTask); |
| 996 | pw.print(prefix); pw.print(" appFullscreen="); pw.print(appFullscreen); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 997 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 998 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 999 | pw.print(" clientHidden="); pw.print(clientHidden); |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 1000 | pw.print(" reportedDrawn="); pw.print(reportedDrawn); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1001 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1002 | if (paused) { |
| 1003 | pw.print(prefix); pw.print("paused="); pw.println(paused); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1004 | } |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 1005 | if (mAppStopped) { |
| 1006 | pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped); |
| 1007 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1008 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1009 | || allDrawn || mAppAnimator.allDrawn) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1010 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 1011 | pw.print(numInterestingWindows); |
| 1012 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 1013 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1014 | pw.print(" allDrawn="); pw.print(allDrawn); |
| 1015 | pw.print(" (animator="); pw.print(mAppAnimator.allDrawn); |
| 1016 | pw.println(")"); |
| 1017 | } |
| 1018 | if (inPendingTransaction) { |
| 1019 | pw.print(prefix); pw.print("inPendingTransaction="); |
| 1020 | pw.println(inPendingTransaction); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1021 | } |
Craig Mautner | 799bc1d | 2015-01-14 10:33:48 -0800 | [diff] [blame] | 1022 | if (startingData != null || removed || firstWindowDrawn || mIsExiting) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1023 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 1024 | pw.print(" removed="); pw.print(removed); |
Craig Mautner | 3d7ca31 | 2015-01-08 10:56:00 -0800 | [diff] [blame] | 1025 | pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn); |
Craig Mautner | 799bc1d | 2015-01-14 10:33:48 -0800 | [diff] [blame] | 1026 | pw.print(" mIsExiting="); pw.println(mIsExiting); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1027 | } |
| 1028 | if (startingWindow != null || startingView != null |
| 1029 | || startingDisplayed || startingMoved) { |
| 1030 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 1031 | pw.print(" startingView="); pw.print(startingView); |
| 1032 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 1033 | pw.print(" startingMoved="); pw.println(startingMoved); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1034 | } |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 1035 | if (!mFrozenBounds.isEmpty()) { |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 1036 | pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 1037 | pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig); |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 1038 | } |
| 1039 | if (mPendingRelaunchCount != 0) { |
| 1040 | pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 1041 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | @Override |
| 1045 | public String toString() { |
| 1046 | if (stringName == null) { |
| 1047 | StringBuilder sb = new StringBuilder(); |
| 1048 | sb.append("AppWindowToken{"); |
| 1049 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 1050 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 1051 | stringName = sb.toString(); |
| 1052 | } |
| 1053 | return stringName; |
| 1054 | } |
Jeff Brown | e9bdb31 | 2012-04-05 15:30:10 -0700 | [diff] [blame] | 1055 | } |