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 | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 20 | import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION; |
| 21 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 22 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 23 | import static android.view.Display.DEFAULT_DISPLAY; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 24 | import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; |
| 25 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 26 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 29 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM; |
| 30 | import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 31 | import static com.android.server.wm.AppTransition.TRANSIT_UNSET; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 32 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 33 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
| 34 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS; |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 35 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 36 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS; |
| 37 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION; |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 38 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW; |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 39 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT; |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 40 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY; |
| 41 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT; |
| 42 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 43 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 44 | import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN; |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 45 | import static com.android.server.wm.WindowManagerService.H.NOTIFY_STARTING_WINDOW_DRAWN; |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 46 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 47 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 48 | import static com.android.server.wm.WindowManagerService.logWithStack; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 49 | |
Filip Gruszczynski | a590c99 | 2015-11-25 16:45:26 -0800 | [diff] [blame] | 50 | import android.annotation.NonNull; |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 51 | import android.content.res.Configuration; |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 52 | import android.graphics.Rect; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 53 | import android.os.Binder; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 54 | import android.os.Debug; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 55 | import android.os.IBinder; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 56 | import android.os.SystemClock; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 57 | import android.util.Slog; |
| 58 | import android.view.IApplicationToken; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 59 | import android.view.WindowManager; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 60 | import android.view.WindowManagerPolicy.StartingSurface; |
| 61 | |
| 62 | import com.android.internal.util.ToBooleanFunction; |
| 63 | import com.android.server.input.InputApplicationHandle; |
| 64 | import com.android.server.wm.WindowManagerService.H; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 65 | |
| 66 | import java.io.PrintWriter; |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 67 | import java.util.ArrayDeque; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 68 | import java.util.ArrayList; |
| 69 | |
| 70 | class AppTokenList extends ArrayList<AppWindowToken> { |
| 71 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * Version of WindowToken that is specifically for a particular application (or |
| 75 | * really activity) that is displaying windows. |
| 76 | */ |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 77 | class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 78 | private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM; |
| 79 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 80 | // Non-null only for application tokens. |
| 81 | final IApplicationToken appToken; |
| 82 | |
Filip Gruszczynski | a590c99 | 2015-11-25 16:45:26 -0800 | [diff] [blame] | 83 | @NonNull final AppWindowAnimator mAppAnimator; |
Craig Mautner | d09cc4b | 2012-04-04 10:23:31 -0700 | [diff] [blame] | 84 | |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 85 | final boolean mVoiceInteraction; |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 86 | |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 87 | // TODO: Use getParent instead? |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 88 | Task mTask; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 89 | /** @see WindowContainer#fillsParent() */ |
| 90 | private boolean mFillsParent; |
Craig Mautner | 4c5eb22 | 2013-11-18 12:59:05 -0800 | [diff] [blame] | 91 | boolean layoutConfigChanges; |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 92 | boolean mShowForAllUsers; |
| 93 | int mTargetSdk; |
Craig Mautner | a2c7705 | 2012-03-26 12:14:43 -0700 | [diff] [blame] | 94 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 95 | // The input dispatching timeout for this application token in nanoseconds. |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 96 | long mInputDispatchingTimeoutNanos; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 97 | |
| 98 | // These are used for determining when all windows associated with |
| 99 | // an activity have been drawn, so they can be made visible together |
| 100 | // at the same time. |
Craig Mautner | 764983d | 2012-03-22 11:37:36 -0700 | [diff] [blame] | 101 | // initialize so that it doesn't match mTransactionSequence which is an int. |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 102 | private long mLastTransactionSequence = Long.MIN_VALUE; |
| 103 | private int mNumInterestingWindows; |
| 104 | private int mNumDrawnWindows; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 105 | boolean inPendingTransaction; |
| 106 | boolean allDrawn; |
Craig Mautner | 7636dfb | 2012-11-16 15:24:11 -0800 | [diff] [blame] | 107 | // Set to true when this app creates a surface while in the middle of an animation. In that |
| 108 | // case do not clear allDrawn until the animation completes. |
| 109 | boolean deferClearAllDrawn; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 110 | |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 111 | /** |
| 112 | * These are to track the app's real drawing status if there were no saved surfaces. |
| 113 | * @see #updateDrawnWindowStates |
| 114 | */ |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 115 | boolean allDrawnExcludingSaved; |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 116 | private int mNumInterestingWindowsExcludingSaved; |
| 117 | private int mNumDrawnWindowsExcludingSaved; |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 118 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 119 | // Is this window's surface needed? This is almost like hidden, except |
| 120 | // it will sometimes be true a little earlier: when the token has |
| 121 | // been shown, but is still waiting for its app transition to execute |
| 122 | // before making its windows shown. |
| 123 | boolean hiddenRequested; |
| 124 | |
| 125 | // Have we told the window clients to hide themselves? |
| 126 | boolean clientHidden; |
| 127 | |
| 128 | // Last visibility state we reported to the app token. |
| 129 | boolean reportedVisible; |
| 130 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 131 | // Last drawn state we reported to the app token. |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 132 | private boolean reportedDrawn; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 133 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 134 | // Set to true when the token has been removed from the window mgr. |
| 135 | boolean removed; |
| 136 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 137 | // Information about an application starting window if displayed. |
| 138 | StartingData startingData; |
| 139 | WindowState startingWindow; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 140 | StartingSurface startingSurface; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 141 | boolean startingDisplayed; |
| 142 | boolean startingMoved; |
| 143 | boolean firstWindowDrawn; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 144 | private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults = |
| 145 | new WindowState.UpdateReportedVisibilityResults(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 146 | |
| 147 | // Input application handle used by the input dispatcher. |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 148 | final InputApplicationHandle mInputApplicationHandle; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 149 | |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 150 | // TODO: Have a WindowContainer state for tracking exiting/deferred removal. |
Craig Mautner | 799bc1d | 2015-01-14 10:33:48 -0800 | [diff] [blame] | 151 | boolean mIsExiting; |
Craig Mautner | 9ef471f | 2014-02-07 13:11:47 -0800 | [diff] [blame] | 152 | |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 153 | boolean mLaunchTaskBehind; |
Craig Mautner | 8746a47 | 2014-07-24 15:12:54 -0700 | [diff] [blame] | 154 | boolean mEnteringAnimation; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 155 | |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 156 | private boolean mAlwaysFocusable; |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 157 | |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 158 | boolean mAppStopped; |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 159 | int mRotationAnimationHint; |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 160 | private int mPendingRelaunchCount; |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 161 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 162 | private boolean mLastContainsShowWhenLockedWindow; |
| 163 | private boolean mLastContainsDismissKeyguardWindow; |
| 164 | |
Robert Carr | 91b22809 | 2016-06-28 17:32:37 -0700 | [diff] [blame] | 165 | private ArrayList<WindowSurfaceController.SurfaceControlWithBackground> mSurfaceViewBackgrounds = |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 166 | new ArrayList<>(); |
Robert Carr | 91b22809 | 2016-06-28 17:32:37 -0700 | [diff] [blame] | 167 | |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 168 | ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>(); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 169 | ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>(); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 170 | |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 171 | AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction, |
| 172 | DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen, |
| 173 | boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint, |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 174 | int configChanges, boolean launchTaskBehind, boolean alwaysFocusable, |
| 175 | AppWindowContainerController controller) { |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 176 | this(service, token, voiceInteraction, dc); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 177 | setController(controller); |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 178 | mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
| 179 | mFillsParent = fullscreen; |
| 180 | mShowForAllUsers = showForAllUsers; |
| 181 | mTargetSdk = targetSdk; |
| 182 | mOrientation = orientation; |
| 183 | layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0; |
| 184 | mLaunchTaskBehind = launchTaskBehind; |
| 185 | mAlwaysFocusable = alwaysFocusable; |
| 186 | mRotationAnimationHint = rotationAnimationHint; |
| 187 | |
| 188 | // Application tokens start out hidden. |
| 189 | hidden = true; |
| 190 | hiddenRequested = true; |
| 191 | } |
| 192 | |
| 193 | AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction, |
| 194 | DisplayContent dc) { |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame^] | 195 | super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc, |
| 196 | false /* ownerCanManageAppTokens */); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 197 | appToken = token; |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 198 | mVoiceInteraction = voiceInteraction; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 199 | mInputApplicationHandle = new InputApplicationHandle(this); |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 200 | mAppAnimator = new AppWindowAnimator(this, service); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 201 | } |
| 202 | |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 203 | void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) { |
| 204 | firstWindowDrawn = true; |
| 205 | |
| 206 | // We now have a good window to show, remove dead placeholders |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 207 | removeDeadWindows(); |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 208 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 209 | if (startingWindow != null) { |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 210 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting " |
| 211 | + win.mToken + ": first real window is shown, no animation"); |
| 212 | // If this initial window is animating, stop it -- we will do an animation to reveal |
| 213 | // it from behind the starting window, so there is no need for it to also be doing its |
| 214 | // own stuff. |
| 215 | winAnimator.clearAnimation(); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 216 | if (getController() != null) { |
| 217 | getController().removeStartingWindow(); |
| 218 | } |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 219 | } |
| 220 | updateReportedVisibilityLocked(); |
| 221 | } |
| 222 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 223 | void updateReportedVisibilityLocked() { |
| 224 | if (appToken == null) { |
| 225 | return; |
| 226 | } |
| 227 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 228 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 229 | final int count = mChildren.size(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 230 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 231 | mReportedVisibilityResults.reset(); |
| 232 | |
| 233 | for (int i = 0; i < count; i++) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 234 | final WindowState win = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 235 | win.updateReportedVisibility(mReportedVisibilityResults); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 236 | } |
| 237 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 238 | int numInteresting = mReportedVisibilityResults.numInteresting; |
| 239 | int numVisible = mReportedVisibilityResults.numVisible; |
| 240 | int numDrawn = mReportedVisibilityResults.numDrawn; |
| 241 | boolean nowGone = mReportedVisibilityResults.nowGone; |
| 242 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 243 | boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 244 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 245 | if (!nowGone) { |
| 246 | // If the app is not yet gone, then it can only become visible/drawn. |
| 247 | if (!nowDrawn) { |
| 248 | nowDrawn = reportedDrawn; |
| 249 | } |
| 250 | if (!nowVisible) { |
| 251 | nowVisible = reportedVisible; |
| 252 | } |
| 253 | } |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 254 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 255 | + numInteresting + " visible=" + numVisible); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 256 | final AppWindowContainerController controller = getController(); |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 257 | if (nowDrawn != reportedDrawn) { |
| 258 | if (nowDrawn) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 259 | if (controller != null) { |
| 260 | controller.reportWindowsDrawn(); |
| 261 | } |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 262 | } |
| 263 | reportedDrawn = nowDrawn; |
| 264 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 265 | if (nowVisible != reportedVisible) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 266 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 267 | "Visibility changed in " + this + ": vis=" + nowVisible); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 268 | reportedVisible = nowVisible; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 269 | if (controller != null) { |
| 270 | if (nowVisible) { |
| 271 | controller.reportWindowsVisible(); |
| 272 | } else { |
| 273 | controller.reportWindowsGone(); |
| 274 | } |
| 275 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 279 | boolean setVisibility(WindowManager.LayoutParams lp, |
| 280 | boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) { |
| 281 | |
| 282 | boolean delayed = false; |
| 283 | inPendingTransaction = false; |
| 284 | |
| 285 | if (clientHidden == visible) { |
| 286 | clientHidden = !visible; |
| 287 | sendAppVisibilityToClients(); |
| 288 | } |
| 289 | |
| 290 | // Allow for state changes and animation to be applied if: |
| 291 | // * token is transitioning visibility state |
| 292 | // * or the token was marked as hidden and is exiting before we had a chance to play the |
| 293 | // transition animation |
| 294 | // * or this is an opening app and windows are being replaced. |
| 295 | boolean visibilityChanged = false; |
| 296 | if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) { |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 297 | final AccessibilityController accessibilityController = mService.mAccessibilityController; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 298 | boolean changed = false; |
| 299 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, |
| 300 | "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout); |
| 301 | |
| 302 | boolean runningAppAnimation = false; |
| 303 | |
| 304 | if (transit != AppTransition.TRANSIT_UNSET) { |
| 305 | if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) { |
| 306 | mAppAnimator.setNullAnimation(); |
| 307 | } |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 308 | if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 309 | delayed = runningAppAnimation = true; |
| 310 | } |
| 311 | final WindowState window = findMainWindow(); |
| 312 | //TODO (multidisplay): Magnification is supported only for the default display. |
| 313 | if (window != null && accessibilityController != null |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 314 | && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 315 | accessibilityController.onAppWindowTransitionLocked(window, transit); |
| 316 | } |
| 317 | changed = true; |
| 318 | } |
| 319 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 320 | final int windowsCount = mChildren.size(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 321 | for (int i = 0; i < windowsCount; i++) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 322 | final WindowState win = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 323 | changed |= win.onAppVisibilityChanged(visible, runningAppAnimation); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | hidden = hiddenRequested = !visible; |
| 327 | visibilityChanged = true; |
| 328 | if (!visible) { |
| 329 | stopFreezingScreen(true, true); |
| 330 | } else { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 331 | // If we are being set visible, and the starting window is not yet displayed, |
| 332 | // then make sure it doesn't get displayed. |
| 333 | if (startingWindow != null && !startingWindow.isDrawnLw()) { |
| 334 | startingWindow.mPolicyVisibility = false; |
| 335 | startingWindow.mPolicyVisibilityAfterAnim = false; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | |
| 339 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this |
| 340 | + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested); |
| 341 | |
| 342 | if (changed) { |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 343 | mService.mInputMonitor.setUpdateInputWindowsNeededLw(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 344 | if (performLayout) { |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 345 | mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 346 | false /*updateInputWindows*/); |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 347 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 348 | } |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 349 | mService.mInputMonitor.updateInputWindowsLw(false /*force*/); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | |
| 353 | if (mAppAnimator.animation != null) { |
| 354 | delayed = true; |
| 355 | } |
| 356 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 357 | for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 358 | if ((mChildren.get(i)).isWindowAnimationSet()) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 359 | delayed = true; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | if (visibilityChanged) { |
| 364 | if (visible && !delayed) { |
| 365 | // The token was made immediately visible, there will be no entrance animation. |
| 366 | // We need to inform the client the enter animation was finished. |
| 367 | mEnteringAnimation = true; |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 368 | mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 371 | if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 372 | // The token is not closing nor opening, so even if there is an animation set, that |
| 373 | // doesn't mean that it goes through the normal app transition cycle so we have |
| 374 | // to inform the docked controller about visibility change. |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 375 | // TODO(multi-display): notify docked divider on all displays where visibility was |
| 376 | // affected. |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 377 | mService.getDefaultDisplayContentLocked().getDockedDividerController() |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 378 | .notifyAppVisibilityChanged(); |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 379 | mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | |
| 383 | return delayed; |
| 384 | } |
| 385 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 386 | WindowState findMainWindow() { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 387 | WindowState candidate = null; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 388 | int j = mChildren.size(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 389 | while (j > 0) { |
| 390 | j--; |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 391 | final WindowState win = mChildren.get(j); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 392 | final int type = win.mAttrs.type; |
| 393 | // No need to loop through child window as base application and starting types can't be |
| 394 | // child windows. |
| 395 | if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 396 | // 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] | 397 | // happens for example when replacing windows during an activity relaunch. When |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 398 | // constructing the animation, we want the new window, not the exiting one. |
Wale Ogunwale | c48a354 | 2016-02-19 15:18:45 -0800 | [diff] [blame] | 399 | if (win.mAnimatingExit) { |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 400 | candidate = win; |
| 401 | } else { |
| 402 | return win; |
| 403 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 404 | } |
| 405 | } |
Filip Gruszczynski | 55a309f | 2015-09-04 17:15:01 -0700 | [diff] [blame] | 406 | return candidate; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 407 | } |
| 408 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 409 | boolean windowsAreFocusable() { |
| 410 | return StackId.canReceiveKeys(mTask.mStack.mStackId) || mAlwaysFocusable; |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 411 | } |
| 412 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 413 | AppWindowContainerController getController() { |
| 414 | final WindowContainerController controller = super.getController(); |
| 415 | return controller != null ? (AppWindowContainerController) controller : null; |
| 416 | } |
| 417 | |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 418 | @Override |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 419 | boolean isVisible() { |
Wale Ogunwale | e471be6 | 2016-10-03 07:53:55 -0700 | [diff] [blame] | 420 | // If the app token isn't hidden then it is considered visible and there is no need to check |
| 421 | // its children windows to see if they are visible. |
| 422 | return !hidden; |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | @Override |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 426 | void removeIfPossible() { |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 427 | mIsExiting = false; |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 428 | removeAllWindowsIfPossible(); |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 429 | if (mTask != null) { |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 430 | mTask.mStack.mExitingAppTokens.remove(this); |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 431 | removeImmediately(); |
Craig Mautner | e3119b7 | 2015-01-20 15:02:36 -0800 | [diff] [blame] | 432 | } |
| 433 | } |
| 434 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 435 | @Override |
| 436 | boolean checkCompleteDeferredRemoval() { |
| 437 | if (mIsExiting) { |
| 438 | removeIfPossible(); |
| 439 | } |
| 440 | return super.checkCompleteDeferredRemoval(); |
| 441 | } |
| 442 | |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 443 | void onRemovedFromDisplay() { |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 444 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this); |
| 445 | |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 446 | boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction); |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 447 | |
| 448 | mService.mOpeningApps.remove(this); |
Jorim Jaggi | 1b4b23e | 2016-11-15 16:30:12 -0800 | [diff] [blame] | 449 | mService.mUnknownAppVisibilityController.appRemoved(this); |
Jorim Jaggi | 10abe2f | 2017-01-03 16:44:46 +0100 | [diff] [blame] | 450 | mService.mTaskSnapshotController.onAppRemoved(this); |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 451 | waitingToShow = false; |
| 452 | if (mService.mClosingApps.contains(this)) { |
| 453 | delayed = true; |
| 454 | } else if (mService.mAppTransition.isTransitionSet()) { |
| 455 | mService.mClosingApps.add(this); |
| 456 | delayed = true; |
| 457 | } |
| 458 | |
| 459 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed |
| 460 | + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating); |
| 461 | |
| 462 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: " |
| 463 | + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4)); |
| 464 | |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 465 | if (startingData != null && getController() != null) { |
| 466 | getController().removeStartingWindow(); |
| 467 | } |
| 468 | |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 469 | final TaskStack stack = mTask.mStack; |
| 470 | if (delayed && !isEmpty()) { |
| 471 | // set the token aside because it has an active animation to be finished |
| 472 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, |
| 473 | "removeAppToken make exiting: " + this); |
| 474 | stack.mExitingAppTokens.add(this); |
| 475 | mIsExiting = true; |
| 476 | } else { |
| 477 | // Make sure there is no animation running on this token, so any windows associated |
| 478 | // with it will be removed as soon as their animations are complete |
| 479 | mAppAnimator.clearAnimation(); |
| 480 | mAppAnimator.animating = false; |
| 481 | removeIfPossible(); |
| 482 | } |
| 483 | |
| 484 | removed = true; |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 485 | stopFreezingScreen(true, true); |
| 486 | if (mService.mFocusedApp == this) { |
| 487 | if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this); |
| 488 | mService.mFocusedApp = null; |
| 489 | mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
| 490 | mService.mInputMonitor.setFocusedAppLw(null); |
| 491 | } |
| 492 | |
| 493 | if (!delayed) { |
| 494 | updateReportedVisibilityLocked(); |
| 495 | } |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Chong Zhang | e05bcb1 | 2016-07-26 17:47:29 -0700 | [diff] [blame] | 498 | void clearAnimatingFlags() { |
Chong Zhang | b0d2670 | 2016-08-12 16:03:29 -0700 | [diff] [blame] | 499 | boolean wallpaperMightChange = false; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 500 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 501 | final WindowState win = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 502 | wallpaperMightChange |= win.clearAnimatingFlags(); |
Chong Zhang | e05bcb1 | 2016-07-26 17:47:29 -0700 | [diff] [blame] | 503 | } |
Chong Zhang | b0d2670 | 2016-08-12 16:03:29 -0700 | [diff] [blame] | 504 | if (wallpaperMightChange) { |
| 505 | requestUpdateWallpaperIfNeeded(); |
| 506 | } |
Chong Zhang | e05bcb1 | 2016-07-26 17:47:29 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 509 | void destroySurfaces() { |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 510 | destroySurfaces(false /*cleanupOnResume*/); |
| 511 | } |
| 512 | |
| 513 | /** |
| 514 | * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure |
| 515 | * the client has finished with them. |
| 516 | * |
| 517 | * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If |
| 518 | * set to true, destroy only surfaces of removed windows, and clear relevant flags of the |
| 519 | * others so that they are ready to be reused. If set to false (common case), destroy all |
| 520 | * surfaces that's eligible, if the app is already stopped. |
| 521 | */ |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 522 | private void destroySurfaces(boolean cleanupOnResume) { |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 523 | boolean destroyedSomething = false; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 524 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 525 | final WindowState win = mChildren.get(i); |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 526 | destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped); |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 527 | } |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 528 | if (destroyedSomething) { |
| 529 | final DisplayContent dc = getDisplayContent(); |
Wale Ogunwale | c69694a | 2016-10-18 13:51:15 -0700 | [diff] [blame] | 530 | dc.assignWindowLayers(true /*setLayoutNeeded*/); |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 534 | /** |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 535 | * Notify that the app is now resumed, and it was not stopped before, perform a clean |
| 536 | * up of the surfaces |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 537 | */ |
Chong Zhang | ad24f96 | 2016-08-25 12:12:33 -0700 | [diff] [blame] | 538 | void notifyAppResumed(boolean wasStopped, boolean allowSavedSurface) { |
| 539 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped |
| 540 | + " allowSavedSurface=" + allowSavedSurface + " " + this); |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 541 | mAppStopped = false; |
| 542 | if (!wasStopped) { |
| 543 | destroySurfaces(true /*cleanupOnResume*/); |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 544 | } |
Chong Zhang | ad24f96 | 2016-08-25 12:12:33 -0700 | [diff] [blame] | 545 | if (!allowSavedSurface) { |
| 546 | destroySavedSurfaces(); |
| 547 | } |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 548 | } |
| 549 | |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 550 | /** |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 551 | * Notify that the app has stopped, and it is okay to destroy any surfaces which were |
| 552 | * keeping alive in case they were still being used. |
| 553 | */ |
| 554 | void notifyAppStopped() { |
| 555 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this); |
| 556 | mAppStopped = true; |
| 557 | destroySurfaces(); |
| 558 | // Remove any starting window that was added for this app if they are still around. |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 559 | if (getController() != null) { |
| 560 | getController().removeStartingWindow(); |
| 561 | } |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | /** |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 565 | * Checks whether we should save surfaces for this app. |
| 566 | * |
| 567 | * @return true if the surfaces should be saved, false otherwise. |
| 568 | */ |
| 569 | boolean shouldSaveSurface() { |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 570 | // We want to save surface if the app's windows are "allDrawn". |
| 571 | // (If we started entering animation early with saved surfaces, allDrawn |
| 572 | // should have been restored to true. So we'll save again in that case |
| 573 | // even if app didn't actually finish drawing.) |
| 574 | return allDrawn; |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 575 | } |
| 576 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 577 | private boolean canRestoreSurfaces() { |
| 578 | for (int i = mChildren.size() -1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 579 | final WindowState w = mChildren.get(i); |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 580 | if (w.canRestoreSurface()) { |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 581 | return true; |
| 582 | } |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 583 | } |
| 584 | return false; |
| 585 | } |
| 586 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 587 | private void clearWasVisibleBeforeClientHidden() { |
| 588 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 589 | final WindowState w = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 590 | w.clearWasVisibleBeforeClientHidden(); |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 594 | /** |
| 595 | * Whether the app has some window that is invisible in layout, but |
| 596 | * animating with saved surface. |
| 597 | */ |
| 598 | boolean isAnimatingInvisibleWithSavedSurface() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 599 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 600 | final WindowState w = mChildren.get(i); |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 601 | if (w.isAnimatingInvisibleWithSavedSurface()) { |
| 602 | return true; |
| 603 | } |
| 604 | } |
| 605 | return false; |
| 606 | } |
| 607 | |
| 608 | /** |
| 609 | * Hide all window surfaces that's still invisible in layout but animating |
| 610 | * with a saved surface, and mark them destroying. |
| 611 | */ |
| 612 | void stopUsingSavedSurfaceLocked() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 613 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 614 | final WindowState w = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 615 | w.stopUsingSavedSurface(); |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 616 | } |
| 617 | destroySurfaces(); |
| 618 | } |
| 619 | |
Chong Zhang | f58631a | 2016-05-24 16:02:10 -0700 | [diff] [blame] | 620 | void markSavedSurfaceExiting() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 621 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 622 | final WindowState w = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 623 | w.markSavedSurfaceExiting(); |
Chong Zhang | f58631a | 2016-05-24 16:02:10 -0700 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 627 | void restoreSavedSurfaceForInterestingWindows() { |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 628 | if (!canRestoreSurfaces()) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 629 | clearWasVisibleBeforeClientHidden(); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 630 | return; |
| 631 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 632 | |
| 633 | // Check if all interesting windows are drawn and we can mark allDrawn=true. |
| 634 | int interestingNotDrawn = -1; |
| 635 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 636 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 637 | final WindowState w = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 638 | interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow(); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 639 | } |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 640 | |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 641 | if (!allDrawn) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 642 | allDrawn = (interestingNotDrawn == 0); |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 643 | if (allDrawn) { |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 644 | mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget(); |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 645 | } |
| 646 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 647 | clearWasVisibleBeforeClientHidden(); |
Chong Zhang | bfc2f8f | 2016-01-29 15:50:34 -0800 | [diff] [blame] | 648 | |
| 649 | if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 650 | "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn |
| 651 | + " interestingNotDrawn=" + interestingNotDrawn); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | void destroySavedSurfaces() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 655 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 656 | final WindowState win = mChildren.get(i); |
Robert Carr | 13f7be9e | 2015-12-02 18:39:45 -0800 | [diff] [blame] | 657 | win.destroySavedSurface(); |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 658 | } |
Chong Zhang | 9214704 | 2016-05-09 12:47:11 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | void clearAllDrawn() { |
| 662 | allDrawn = false; |
| 663 | deferClearAllDrawn = false; |
Chong Zhang | 8e4bda9 | 2016-05-04 15:08:18 -0700 | [diff] [blame] | 664 | allDrawnExcludingSaved = false; |
Chong Zhang | bef461f | 2015-10-27 11:38:24 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Wale Ogunwale | fa854eb | 2016-09-20 13:43:52 -0700 | [diff] [blame] | 667 | void postWindowRemoveStartingWindowCleanup(WindowState win) { |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 668 | // TODO: Something smells about the code below...Is there a better way? |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 669 | if (startingWindow == win) { |
| 670 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 671 | if (getController() != null) { |
| 672 | getController().removeStartingWindow(); |
| 673 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 674 | } else if (mChildren.size() == 0 && startingData != null) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 675 | // If this is the last window and we had requested a starting transition window, |
| 676 | // well there is no point now. |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 677 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData"); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 678 | startingData = null; |
Jorim Jaggi | 829b9cd | 2017-01-23 16:20:53 +0100 | [diff] [blame] | 679 | } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 680 | // If this is the last window except for a starting transition window, |
| 681 | // we need to get rid of the starting transition. |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 682 | if (getController() != null) { |
| 683 | getController().removeStartingWindow(); |
| 684 | } |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 688 | void removeDeadWindows() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 689 | for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 690 | WindowState win = mChildren.get(winNdx); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 691 | if (win.mAppDied) { |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 692 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG, |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 693 | "removeDeadWindows: " + win); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 694 | // Set mDestroying, we don't want any animation or delayed removal here. |
| 695 | win.mDestroying = true; |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 696 | // Also removes child windows. |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 697 | win.removeIfPossible(); |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | } |
| 701 | |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 702 | boolean hasWindowsAlive() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 703 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 704 | // No need to loop through child windows as the answer should be the same as that of the |
| 705 | // parent window. |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 706 | if (!(mChildren.get(i)).mAppDied) { |
Wale Ogunwale | e42d0e1 | 2016-05-02 16:40:59 -0700 | [diff] [blame] | 707 | return true; |
| 708 | } |
| 709 | } |
| 710 | return false; |
| 711 | } |
| 712 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 713 | void setWillReplaceWindows(boolean animate) { |
Wale Ogunwale | 455fac5 | 2016-07-21 07:24:49 -0700 | [diff] [blame] | 714 | if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, |
| 715 | "Marking app token " + this + " with replacing windows."); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 716 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 717 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 718 | final WindowState w = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 719 | w.setWillReplaceWindow(animate); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 720 | } |
| 721 | if (animate) { |
| 722 | // Set-up dummy animation so we can start treating windows associated with this |
| 723 | // token like they are in transition before the new app window is ready for us to |
| 724 | // run the real transition animation. |
| 725 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 726 | "setWillReplaceWindow() Setting dummy animation on: " + this); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 727 | mAppAnimator.setDummyAnimation(); |
| 728 | } |
| 729 | } |
| 730 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 731 | void setWillReplaceChildWindows() { |
Wale Ogunwale | 455fac5 | 2016-07-21 07:24:49 -0700 | [diff] [blame] | 732 | if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 733 | + " with replacing child windows."); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 734 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 735 | final WindowState w = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 736 | w.setWillReplaceChildWindows(); |
Robert Carr | 23fa16b | 2016-01-13 13:19:58 -0800 | [diff] [blame] | 737 | } |
| 738 | } |
| 739 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 740 | void clearWillReplaceWindows() { |
Wale Ogunwale | 455fac5 | 2016-07-21 07:24:49 -0700 | [diff] [blame] | 741 | if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, |
| 742 | "Resetting app token " + this + " of replacing window marks."); |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 743 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 744 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 745 | final WindowState w = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 746 | w.clearWillReplaceWindow(); |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 750 | void requestUpdateWallpaperIfNeeded() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 751 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 752 | final WindowState w = mChildren.get(i); |
Chong Zhang | 4d7369a | 2016-04-25 16:09:14 -0700 | [diff] [blame] | 753 | w.requestUpdateWallpaperIfNeeded(); |
| 754 | } |
| 755 | } |
| 756 | |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 757 | boolean isRelaunching() { |
| 758 | return mPendingRelaunchCount > 0; |
| 759 | } |
| 760 | |
| 761 | void startRelaunching() { |
| 762 | if (canFreezeBounds()) { |
| 763 | freezeBounds(); |
| 764 | } |
| 765 | mPendingRelaunchCount++; |
| 766 | } |
| 767 | |
| 768 | void finishRelaunching() { |
| 769 | if (canFreezeBounds()) { |
| 770 | unfreezeBounds(); |
| 771 | } |
| 772 | if (mPendingRelaunchCount > 0) { |
| 773 | mPendingRelaunchCount--; |
| 774 | } |
| 775 | } |
| 776 | |
Wale Ogunwale | 8fd7542 | 2016-06-24 14:20:37 -0700 | [diff] [blame] | 777 | void clearRelaunching() { |
Wale Ogunwale | 37dbafc | 2016-06-27 10:15:20 -0700 | [diff] [blame] | 778 | if (mPendingRelaunchCount == 0) { |
| 779 | return; |
| 780 | } |
Wale Ogunwale | 8fd7542 | 2016-06-24 14:20:37 -0700 | [diff] [blame] | 781 | if (canFreezeBounds()) { |
| 782 | unfreezeBounds(); |
| 783 | } |
| 784 | mPendingRelaunchCount = 0; |
| 785 | } |
| 786 | |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 787 | /** |
| 788 | * Returns true if the new child window we are adding to this token is considered greater than |
| 789 | * the existing child window in this token in terms of z-order. |
| 790 | */ |
| 791 | @Override |
| 792 | protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow, |
| 793 | WindowState existingWindow) { |
| 794 | final int type1 = newWindow.mAttrs.type; |
| 795 | final int type2 = existingWindow.mAttrs.type; |
| 796 | |
| 797 | // Base application windows should be z-ordered BELOW all other windows in the app token. |
| 798 | if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) { |
| 799 | return false; |
| 800 | } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) { |
| 801 | return true; |
| 802 | } |
| 803 | |
| 804 | // Starting windows should be z-ordered ABOVE all other windows in the app token. |
| 805 | if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) { |
| 806 | return true; |
| 807 | } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) { |
| 808 | return false; |
| 809 | } |
| 810 | |
| 811 | // Otherwise the new window is greater than the existing window. |
| 812 | return true; |
| 813 | } |
| 814 | |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 815 | @Override |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 816 | void addWindow(WindowState w) { |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 817 | super.addWindow(w); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 818 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 819 | boolean gotReplacementWindow = false; |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 820 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 821 | final WindowState candidate = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 822 | gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w); |
| 823 | } |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 824 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 825 | // if we got a replacement window, reset the timeout to give drawing more time |
| 826 | if (gotReplacementWindow) { |
| 827 | mService.scheduleWindowReplacementTimeouts(this); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 828 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 829 | checkKeyguardFlagsChanged(); |
| 830 | } |
| 831 | |
| 832 | @Override |
| 833 | void removeChild(WindowState child) { |
| 834 | super.removeChild(child); |
| 835 | checkKeyguardFlagsChanged(); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 836 | } |
| 837 | |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 838 | private boolean waitingForReplacement() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 839 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 840 | final WindowState candidate = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 841 | if (candidate.waitingForReplacement()) { |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 842 | return true; |
| 843 | } |
| 844 | } |
| 845 | return false; |
| 846 | } |
| 847 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 848 | void onWindowReplacementTimeout() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 849 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 850 | (mChildren.get(i)).onWindowReplacementTimeout(); |
Robert Carr | a1eb439 | 2015-12-10 12:43:51 -0800 | [diff] [blame] | 851 | } |
| 852 | } |
| 853 | |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 854 | void reparent(Task task, int position) { |
| 855 | if (task == mTask) { |
| 856 | throw new IllegalArgumentException( |
| 857 | "window token=" + this + " already child of task=" + mTask); |
| 858 | } |
| 859 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this |
| 860 | + " from task=" + mTask); |
| 861 | final DisplayContent prevDisplayContent = getDisplayContent(); |
| 862 | |
| 863 | getParent().removeChild(this); |
| 864 | task.addChild(this, position); |
| 865 | |
| 866 | // Relayout display(s). |
| 867 | final DisplayContent displayContent = task.getDisplayContent(); |
| 868 | displayContent.setLayoutNeeded(); |
| 869 | if (prevDisplayContent != displayContent) { |
| 870 | onDisplayChanged(displayContent); |
| 871 | prevDisplayContent.setLayoutNeeded(); |
| 872 | } |
| 873 | } |
| 874 | |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 875 | private boolean canFreezeBounds() { |
| 876 | // For freeform windows, we can't freeze the bounds at the moment because this would make |
| 877 | // the resizing unresponsive. |
| 878 | return mTask != null && !mTask.inFreeformWorkspace(); |
| 879 | } |
| 880 | |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 881 | /** |
| 882 | * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds |
| 883 | * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even |
| 884 | * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen |
| 885 | * with a queue. |
| 886 | */ |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 887 | private void freezeBounds() { |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 888 | mFrozenBounds.offer(new Rect(mTask.mPreparedFrozenBounds)); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 889 | |
| 890 | if (mTask.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) { |
| 891 | // We didn't call prepareFreezingBounds on the task, so use the current value. |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 892 | mFrozenMergedConfig.offer(new Configuration(mTask.getConfiguration())); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 893 | } else { |
| 894 | mFrozenMergedConfig.offer(new Configuration(mTask.mPreparedFrozenMergedConfig)); |
| 895 | } |
Andrii Kulian | b10330d | 2016-09-16 13:51:46 -0700 | [diff] [blame] | 896 | // Calling unset() to make it equal to Configuration.EMPTY. |
| 897 | mTask.mPreparedFrozenMergedConfig.unset(); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | /** |
| 901 | * Unfreezes the previously frozen bounds. See {@link #freezeBounds}. |
| 902 | */ |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 903 | private void unfreezeBounds() { |
Wale Ogunwale | 37dbafc | 2016-06-27 10:15:20 -0700 | [diff] [blame] | 904 | if (!mFrozenBounds.isEmpty()) { |
| 905 | mFrozenBounds.remove(); |
| 906 | } |
| 907 | if (!mFrozenMergedConfig.isEmpty()) { |
| 908 | mFrozenMergedConfig.remove(); |
| 909 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 910 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 911 | final WindowState win = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 912 | win.onUnfreezeBounds(); |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 913 | } |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 914 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 915 | } |
| 916 | |
Robert Carr | 91b22809 | 2016-06-28 17:32:37 -0700 | [diff] [blame] | 917 | void addSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) { |
| 918 | mSurfaceViewBackgrounds.add(background); |
| 919 | } |
| 920 | |
| 921 | void removeSurfaceViewBackground(WindowSurfaceController.SurfaceControlWithBackground background) { |
| 922 | mSurfaceViewBackgrounds.remove(background); |
| 923 | updateSurfaceViewBackgroundVisibilities(); |
| 924 | } |
| 925 | |
| 926 | // We use DimLayers behind SurfaceViews to prevent holes while resizing and creating. |
| 927 | // However, we need to ensure one SurfaceView doesn't cover another when they are both placed |
| 928 | // below the main app window (as traditionally a SurfaceView which is never drawn |
| 929 | // to is totally translucent). So we look at all our SurfaceView backgrounds and only enable |
| 930 | // the background for the SurfaceView with lowest Z order |
| 931 | void updateSurfaceViewBackgroundVisibilities() { |
| 932 | WindowSurfaceController.SurfaceControlWithBackground bottom = null; |
| 933 | int bottomLayer = Integer.MAX_VALUE; |
| 934 | for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) { |
| 935 | WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i); |
| 936 | if (sc.mVisible && sc.mLayer < bottomLayer) { |
| 937 | bottomLayer = sc.mLayer; |
| 938 | bottom = sc; |
| 939 | } |
| 940 | } |
| 941 | for (int i = 0; i < mSurfaceViewBackgrounds.size(); i++) { |
| 942 | WindowSurfaceController.SurfaceControlWithBackground sc = mSurfaceViewBackgrounds.get(i); |
| 943 | sc.updateBackgroundVisibility(sc != bottom); |
| 944 | } |
| 945 | } |
| 946 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 947 | void resetJustMovedInStack() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 948 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 949 | (mChildren.get(i)).resetJustMovedInStack(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 950 | } |
| 951 | } |
| 952 | |
| 953 | void notifyMovedInStack() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 954 | for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 955 | final WindowState win = mChildren.get(winNdx); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 956 | win.notifyMovedInStack(); |
| 957 | } |
| 958 | } |
| 959 | |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 960 | void setAppLayoutChanges(int changes, String reason) { |
| 961 | if (!mChildren.isEmpty()) { |
| 962 | final DisplayContent dc = getDisplayContent(); |
| 963 | dc.pendingLayoutChanges |= changes; |
| 964 | if (DEBUG_LAYOUT_REPEATS) { |
| 965 | mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 966 | } |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | void removeReplacedWindowIfNeeded(WindowState replacement) { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 971 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 972 | final WindowState win = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 973 | if (win.removeReplacedWindowIfNeeded(replacement)) { |
| 974 | return; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | void startFreezingScreen() { |
| 980 | if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden=" |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 981 | + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested=" |
| 982 | + hiddenRequested); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 983 | if (!hiddenRequested) { |
| 984 | if (!mAppAnimator.freezingScreen) { |
| 985 | mAppAnimator.freezingScreen = true; |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 986 | mService.registerAppFreezeListener(this); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 987 | mAppAnimator.lastFreezeDuration = 0; |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 988 | mService.mAppsFreezingScreen++; |
| 989 | if (mService.mAppsFreezingScreen == 1) { |
| 990 | mService.startFreezingDisplayLocked(false, 0, 0); |
| 991 | mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 992 | mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 993 | } |
| 994 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 995 | final int count = mChildren.size(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 996 | for (int i = 0; i < count; i++) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 997 | final WindowState w = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 998 | w.onStartFreezingScreen(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) { |
| 1004 | if (!mAppAnimator.freezingScreen) { |
| 1005 | return; |
| 1006 | } |
| 1007 | 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] | 1008 | final int count = mChildren.size(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1009 | boolean unfrozeWindows = false; |
| 1010 | for (int i = 0; i < count; i++) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1011 | final WindowState w = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1012 | unfrozeWindows |= w.onStopFreezingScreen(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1013 | } |
| 1014 | if (force || unfrozeWindows) { |
| 1015 | if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this); |
| 1016 | mAppAnimator.freezingScreen = false; |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1017 | mService.unregisterAppFreezeListener(this); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1018 | mAppAnimator.lastFreezeDuration = |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 1019 | (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime); |
| 1020 | mService.mAppsFreezingScreen--; |
| 1021 | mService.mLastFinishedFreezeSource = this; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1022 | } |
| 1023 | if (unfreezeSurfaceNow) { |
| 1024 | if (unfrozeWindows) { |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 1025 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1026 | } |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 1027 | mService.stopFreezingDisplayLocked(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1028 | } |
| 1029 | } |
| 1030 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1031 | @Override |
| 1032 | public void onAppFreezeTimeout() { |
| 1033 | Slog.w(TAG_WM, "Force clearing freeze: " + this); |
| 1034 | stopFreezingScreen(true, true); |
| 1035 | } |
| 1036 | |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1037 | boolean transferStartingWindow(IBinder transferFrom) { |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 1038 | final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1039 | if (fromToken == null) { |
| 1040 | return false; |
| 1041 | } |
| 1042 | |
| 1043 | final WindowState tStartingWindow = fromToken.startingWindow; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 1044 | if (tStartingWindow != null && fromToken.startingSurface != null) { |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1045 | // In this case, the starting icon has already been displayed, so start |
| 1046 | // letting windows get shown immediately without any more transitions. |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 1047 | mService.mSkipAppTransitionAnimation = true; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1048 | |
| 1049 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow |
| 1050 | + " from " + fromToken + " to " + this); |
| 1051 | |
| 1052 | final long origId = Binder.clearCallingIdentity(); |
| 1053 | |
| 1054 | // Transfer the starting window over to the new token. |
| 1055 | startingData = fromToken.startingData; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 1056 | startingSurface = fromToken.startingSurface; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1057 | startingDisplayed = fromToken.startingDisplayed; |
| 1058 | fromToken.startingDisplayed = false; |
| 1059 | startingWindow = tStartingWindow; |
| 1060 | reportedVisible = fromToken.reportedVisible; |
| 1061 | fromToken.startingData = null; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 1062 | fromToken.startingSurface = null; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1063 | fromToken.startingWindow = null; |
| 1064 | fromToken.startingMoved = true; |
| 1065 | tStartingWindow.mToken = this; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1066 | tStartingWindow.mAppToken = this; |
| 1067 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 1068 | if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1069 | "Removing starting " + tStartingWindow + " from " + fromToken); |
Wale Ogunwale | fa854eb | 2016-09-20 13:43:52 -0700 | [diff] [blame] | 1070 | fromToken.removeChild(tStartingWindow); |
| 1071 | fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow); |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 1072 | addWindow(tStartingWindow); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1073 | |
| 1074 | // Propagate other interesting state between the tokens. If the old token is displayed, |
| 1075 | // we should immediately force the new one to be displayed. If it is animating, we need |
| 1076 | // to move that animation to the new one. |
| 1077 | if (fromToken.allDrawn) { |
| 1078 | allDrawn = true; |
| 1079 | deferClearAllDrawn = fromToken.deferClearAllDrawn; |
| 1080 | } |
| 1081 | if (fromToken.firstWindowDrawn) { |
| 1082 | firstWindowDrawn = true; |
| 1083 | } |
| 1084 | if (!fromToken.hidden) { |
| 1085 | hidden = false; |
| 1086 | hiddenRequested = false; |
| 1087 | } |
| 1088 | if (clientHidden != fromToken.clientHidden) { |
| 1089 | clientHidden = fromToken.clientHidden; |
| 1090 | sendAppVisibilityToClients(); |
| 1091 | } |
| 1092 | fromToken.mAppAnimator.transferCurrentAnimation( |
| 1093 | mAppAnimator, tStartingWindow.mWinAnimator); |
| 1094 | |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 1095 | mService.updateFocusedWindowLocked( |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1096 | UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 1097 | getDisplayContent().setLayoutNeeded(); |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 1098 | mService.mWindowPlacerLocked.performSurfacePlacement(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1099 | Binder.restoreCallingIdentity(origId); |
| 1100 | return true; |
| 1101 | } else if (fromToken.startingData != null) { |
| 1102 | // The previous app was getting ready to show a |
| 1103 | // starting window, but hasn't yet done so. Steal it! |
| 1104 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, |
| 1105 | "Moving pending starting from " + fromToken + " to " + this); |
| 1106 | startingData = fromToken.startingData; |
| 1107 | fromToken.startingData = null; |
| 1108 | fromToken.startingMoved = true; |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 1109 | if (getController() != null) { |
| 1110 | getController().scheduleAddStartingWindow(); |
| 1111 | } |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1112 | return true; |
| 1113 | } |
| 1114 | |
| 1115 | final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator; |
| 1116 | final AppWindowAnimator wAppAnimator = mAppAnimator; |
| 1117 | if (tAppAnimator.thumbnail != null) { |
| 1118 | // The old token is animating with a thumbnail, transfer that to the new token. |
| 1119 | if (wAppAnimator.thumbnail != null) { |
| 1120 | wAppAnimator.thumbnail.destroy(); |
| 1121 | } |
| 1122 | wAppAnimator.thumbnail = tAppAnimator.thumbnail; |
| 1123 | wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer; |
| 1124 | wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation; |
| 1125 | tAppAnimator.thumbnail = null; |
| 1126 | } |
| 1127 | return false; |
| 1128 | } |
| 1129 | |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 1130 | boolean isLastWindow(WindowState win) { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1131 | return mChildren.size() == 1 && mChildren.get(0) == win; |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | void setAllAppWinAnimators() { |
| 1135 | final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators; |
| 1136 | allAppWinAnimators.clear(); |
| 1137 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 1138 | final int windowsCount = mChildren.size(); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1139 | for (int j = 0; j < windowsCount; j++) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 1140 | (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators); |
Wale Ogunwale | 9f25bee | 2016-08-02 07:23:47 -0700 | [diff] [blame] | 1141 | } |
| 1142 | } |
| 1143 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1144 | @Override |
| 1145 | void onAppTransitionDone() { |
| 1146 | sendingToBottom = false; |
| 1147 | } |
| 1148 | |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1149 | /** |
| 1150 | * We override because this class doesn't want its children affecting its reported orientation |
| 1151 | * in anyway. |
| 1152 | */ |
| 1153 | @Override |
| 1154 | int getOrientation() { |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1155 | if (fillsParent() && (isVisible() || mService.mOpeningApps.contains(this))) { |
| 1156 | return mOrientation; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1157 | } |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1158 | |
| 1159 | return SCREEN_ORIENTATION_UNSET; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1160 | } |
| 1161 | |
Wale Ogunwale | b198b74 | 2016-12-01 08:44:09 -0800 | [diff] [blame] | 1162 | /** Returns the app's preferred orientation regardless of its currently visibility state. */ |
| 1163 | int getOrientationIgnoreVisibility() { |
| 1164 | return mOrientation; |
| 1165 | } |
| 1166 | |
Craig Mautner | dbb7991 | 2012-03-01 18:59:14 -0800 | [diff] [blame] | 1167 | @Override |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1168 | void checkAppWindowsReadyToShow() { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1169 | if (allDrawn == mAppAnimator.allDrawn) { |
| 1170 | return; |
| 1171 | } |
| 1172 | |
| 1173 | mAppAnimator.allDrawn = allDrawn; |
| 1174 | if (!allDrawn) { |
| 1175 | return; |
| 1176 | } |
| 1177 | |
| 1178 | // The token has now changed state to having all windows shown... what to do, what to do? |
| 1179 | if (mAppAnimator.freezingScreen) { |
| 1180 | mAppAnimator.showAllWindowsLocked(); |
| 1181 | stopFreezingScreen(false, true); |
| 1182 | if (DEBUG_ORIENTATION) Slog.i(TAG, |
| 1183 | "Setting mOrientationChangeComplete=true because wtoken " + this |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1184 | + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1185 | // This will set mOrientationChangeComplete and cause a pass through layout. |
| 1186 | setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER, |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1187 | "checkAppWindowsReadyToShow: freezingScreen"); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1188 | } else { |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1189 | setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow"); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1190 | |
| 1191 | // We can now show all of the drawn windows! |
| 1192 | if (!mService.mOpeningApps.contains(this)) { |
| 1193 | mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked()); |
| 1194 | } |
| 1195 | } |
| 1196 | } |
| 1197 | |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1198 | void updateAllDrawn(DisplayContent dc) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1199 | if (!allDrawn) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1200 | final int numInteresting = mNumInterestingWindows; |
| 1201 | if (numInteresting > 0 && mNumDrawnWindows >= numInteresting) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1202 | if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1203 | + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1204 | allDrawn = true; |
| 1205 | // Force an additional layout pass where |
| 1206 | // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked(). |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1207 | dc.setLayoutNeeded(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1208 | mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget(); |
| 1209 | } |
| 1210 | } |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1211 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1212 | if (!allDrawnExcludingSaved) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1213 | int numInteresting = mNumInterestingWindowsExcludingSaved; |
| 1214 | if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1215 | if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this |
| 1216 | + " interesting=" + numInteresting |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1217 | + " drawn=" + mNumDrawnWindowsExcludingSaved); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1218 | allDrawnExcludingSaved = true; |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1219 | dc.setLayoutNeeded(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1220 | if (isAnimatingInvisibleWithSavedSurface() |
| 1221 | && !mService.mFinishedEarlyAnim.contains(this)) { |
| 1222 | mService.mFinishedEarlyAnim.add(this); |
| 1223 | } |
| 1224 | } |
| 1225 | } |
| 1226 | } |
| 1227 | |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1228 | /** |
| 1229 | * Updated this app token tracking states for interesting and drawn windows based on the window. |
| 1230 | * |
| 1231 | * @return Returns true if the input window is considered interesting and drawn while all the |
| 1232 | * windows in this app token where not considered drawn as of the last pass. |
| 1233 | */ |
| 1234 | boolean updateDrawnWindowStates(WindowState w) { |
| 1235 | if (DEBUG_STARTING_WINDOW && w == startingWindow) { |
| 1236 | Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen() |
| 1237 | + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen); |
| 1238 | } |
| 1239 | |
| 1240 | if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) { |
| 1241 | return false; |
| 1242 | } |
| 1243 | |
| 1244 | if (mLastTransactionSequence != mService.mTransactionSequence) { |
| 1245 | mLastTransactionSequence = mService.mTransactionSequence; |
| 1246 | mNumInterestingWindows = mNumDrawnWindows = 0; |
| 1247 | mNumInterestingWindowsExcludingSaved = 0; |
| 1248 | mNumDrawnWindowsExcludingSaved = 0; |
| 1249 | startingDisplayed = false; |
| 1250 | } |
| 1251 | |
| 1252 | final WindowStateAnimator winAnimator = w.mWinAnimator; |
| 1253 | |
| 1254 | boolean isInterestingAndDrawn = false; |
| 1255 | |
| 1256 | if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) { |
| 1257 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| 1258 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw() |
| 1259 | + ", isAnimationSet=" + winAnimator.isAnimationSet()); |
| 1260 | if (!w.isDrawnLw()) { |
| 1261 | Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController |
| 1262 | + " pv=" + w.mPolicyVisibility |
| 1263 | + " mDrawState=" + winAnimator.drawStateToString() |
| 1264 | + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested |
| 1265 | + " a=" + winAnimator.mAnimating); |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | if (w != startingWindow) { |
| 1270 | if (w.isInteresting()) { |
| 1271 | mNumInterestingWindows++; |
| 1272 | if (w.isDrawnLw()) { |
| 1273 | mNumDrawnWindows++; |
| 1274 | |
| 1275 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: " |
| 1276 | + this + " w=" + w + " numInteresting=" + mNumInterestingWindows |
| 1277 | + " freezingScreen=" + mAppAnimator.freezingScreen |
| 1278 | + " mAppFreezing=" + w.mAppFreezing); |
| 1279 | |
| 1280 | isInterestingAndDrawn = true; |
| 1281 | } |
| 1282 | } |
| 1283 | } else if (w.isDrawnLw()) { |
| 1284 | mService.mH.sendEmptyMessage(NOTIFY_STARTING_WINDOW_DRAWN); |
| 1285 | startingDisplayed = true; |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) { |
| 1290 | if (w != startingWindow && w.isInteresting()) { |
| 1291 | mNumInterestingWindowsExcludingSaved++; |
| 1292 | if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) { |
| 1293 | mNumDrawnWindowsExcludingSaved++; |
| 1294 | |
| 1295 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
| 1296 | "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w |
| 1297 | + " numInteresting=" + mNumInterestingWindowsExcludingSaved |
| 1298 | + " freezingScreen=" + mAppAnimator.freezingScreen |
| 1299 | + " mAppFreezing=" + w.mAppFreezing); |
| 1300 | |
| 1301 | isInterestingAndDrawn = true; |
| 1302 | } |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | return isInterestingAndDrawn; |
| 1307 | } |
| 1308 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1309 | @Override |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1310 | void stepAppWindowsAnimation(long currentTime) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1311 | mAppAnimator.wasAnimating = mAppAnimator.animating; |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 1312 | if (mAppAnimator.stepAnimationLocked(currentTime)) { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1313 | mAppAnimator.animating = true; |
| 1314 | mService.mAnimator.setAnimating(true); |
| 1315 | mService.mAnimator.mAppWindowAnimating = true; |
| 1316 | } else if (mAppAnimator.wasAnimating) { |
| 1317 | // stopped animating, do one more pass through the layout |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 1318 | setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER, |
| 1319 | DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 1320 | if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this); |
| 1321 | } |
| 1322 | } |
| 1323 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1324 | @Override |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 1325 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 1326 | // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent |
| 1327 | // before the non-exiting app tokens. So, we skip the exiting app tokens here. |
| 1328 | // TODO: Investigate if we need to continue to do this or if we can just process them |
| 1329 | // in-order. |
| 1330 | if (mIsExiting && !waitingForReplacement()) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 1331 | return false; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 1332 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 1333 | return forAllWindowsUnchecked(callback, traverseTopToBottom); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 1334 | } |
| 1335 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 1336 | boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback, |
| 1337 | boolean traverseTopToBottom) { |
| 1338 | return super.forAllWindows(callback, traverseTopToBottom); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | @Override |
Wale Ogunwale | 2049dbf | 2016-08-02 21:05:23 -0700 | [diff] [blame] | 1342 | AppWindowToken asAppWindowToken() { |
| 1343 | // I am an app window token! |
| 1344 | return this; |
| 1345 | } |
| 1346 | |
| 1347 | @Override |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1348 | boolean fillsParent() { |
| 1349 | return mFillsParent; |
| 1350 | } |
| 1351 | |
| 1352 | void setFillsParent(boolean fillsParent) { |
| 1353 | mFillsParent = fillsParent; |
| 1354 | } |
| 1355 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1356 | boolean containsDismissKeyguardWindow() { |
| 1357 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 1358 | if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) { |
| 1359 | return true; |
| 1360 | } |
| 1361 | } |
| 1362 | return false; |
| 1363 | } |
| 1364 | |
| 1365 | boolean containsShowWhenLockedWindow() { |
| 1366 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 1367 | if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) { |
| 1368 | return true; |
| 1369 | } |
| 1370 | } |
| 1371 | return false; |
| 1372 | } |
| 1373 | |
| 1374 | void checkKeyguardFlagsChanged() { |
| 1375 | final boolean containsDismissKeyguard = containsDismissKeyguardWindow(); |
| 1376 | final boolean containsShowWhenLocked = containsShowWhenLockedWindow(); |
| 1377 | if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow |
| 1378 | || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) { |
| 1379 | mService.notifyKeyguardFlagsChanged(null /* callback */); |
| 1380 | } |
| 1381 | mLastContainsDismissKeyguardWindow = containsDismissKeyguard; |
| 1382 | mLastContainsShowWhenLockedWindow = containsShowWhenLocked; |
| 1383 | } |
| 1384 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 1385 | WindowState getImeTargetBelowWindow(WindowState w) { |
| 1386 | final int index = mChildren.indexOf(w); |
| 1387 | if (index > 0) { |
| 1388 | final WindowState target = mChildren.get(index - 1); |
| 1389 | if (target.canBeImeTarget()) { |
| 1390 | return target; |
| 1391 | } |
| 1392 | } |
| 1393 | return null; |
| 1394 | } |
| 1395 | |
| 1396 | WindowState getHighestAnimLayerWindow(WindowState currentTarget) { |
| 1397 | WindowState candidate = null; |
| 1398 | for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) { |
| 1399 | final WindowState w = mChildren.get(i); |
| 1400 | if (w.mRemoved) { |
| 1401 | continue; |
| 1402 | } |
| 1403 | if (candidate == null || w.mWinAnimator.mAnimLayer > |
| 1404 | candidate.mWinAnimator.mAnimLayer) { |
| 1405 | candidate = w; |
| 1406 | } |
| 1407 | } |
| 1408 | return candidate; |
| 1409 | } |
| 1410 | |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1411 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1412 | void dump(PrintWriter pw, String prefix) { |
| 1413 | super.dump(pw, prefix); |
| 1414 | if (appToken != null) { |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 1415 | pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1416 | } |
Craig Mautner | 83162a9 | 2015-01-26 14:43:30 -0800 | [diff] [blame] | 1417 | pw.print(prefix); pw.print("task="); pw.println(mTask); |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1418 | pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent); |
| 1419 | pw.print(" mOrientation="); pw.println(mOrientation); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1420 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 1421 | pw.print(" clientHidden="); pw.print(clientHidden); |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 1422 | pw.print(" reportedDrawn="); pw.print(reportedDrawn); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1423 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
Craig Mautner | 5943163 | 2012-04-04 11:56:44 -0700 | [diff] [blame] | 1424 | if (paused) { |
| 1425 | pw.print(prefix); pw.print("paused="); pw.println(paused); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1426 | } |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 1427 | if (mAppStopped) { |
| 1428 | pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped); |
| 1429 | } |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1430 | if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0 |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1431 | || allDrawn || mAppAnimator.allDrawn) { |
Wale Ogunwale | 9d9d8f1 | 2016-09-28 15:29:59 -0700 | [diff] [blame] | 1432 | pw.print(prefix); pw.print("mNumInterestingWindows="); |
| 1433 | pw.print(mNumInterestingWindows); |
| 1434 | pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1435 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1436 | pw.print(" allDrawn="); pw.print(allDrawn); |
| 1437 | pw.print(" (animator="); pw.print(mAppAnimator.allDrawn); |
| 1438 | pw.println(")"); |
| 1439 | } |
| 1440 | if (inPendingTransaction) { |
| 1441 | pw.print(prefix); pw.print("inPendingTransaction="); |
| 1442 | pw.println(inPendingTransaction); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1443 | } |
Craig Mautner | 799bc1d | 2015-01-14 10:33:48 -0800 | [diff] [blame] | 1444 | if (startingData != null || removed || firstWindowDrawn || mIsExiting) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1445 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 1446 | pw.print(" removed="); pw.print(removed); |
Craig Mautner | 3d7ca31 | 2015-01-08 10:56:00 -0800 | [diff] [blame] | 1447 | pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn); |
Craig Mautner | 799bc1d | 2015-01-14 10:33:48 -0800 | [diff] [blame] | 1448 | pw.print(" mIsExiting="); pw.println(mIsExiting); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1449 | } |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 1450 | if (startingWindow != null || startingSurface != null |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1451 | || startingDisplayed || startingMoved) { |
| 1452 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
Jorim Jaggi | ba41f4b | 2016-12-14 17:43:07 -0800 | [diff] [blame] | 1453 | pw.print(" startingSurface="); pw.print(startingSurface); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1454 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
Wale Ogunwale | 9017ec0 | 2016-02-25 08:55:25 -0800 | [diff] [blame] | 1455 | pw.print(" startingMoved="); pw.println(startingMoved); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1456 | } |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 1457 | if (!mFrozenBounds.isEmpty()) { |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 1458 | pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds); |
Jorim Jaggi | 26c8c42 | 2016-05-09 19:57:25 -0700 | [diff] [blame] | 1459 | pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig); |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 1460 | } |
| 1461 | if (mPendingRelaunchCount != 0) { |
| 1462 | pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount); |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 1463 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | @Override |
| 1467 | public String toString() { |
| 1468 | if (stringName == null) { |
| 1469 | StringBuilder sb = new StringBuilder(); |
| 1470 | sb.append("AppWindowToken{"); |
| 1471 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 1472 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 1473 | stringName = sb.toString(); |
| 1474 | } |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 1475 | return stringName + ((mIsExiting) ? " mIsExiting=" : ""); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1476 | } |
Jeff Brown | e9bdb31 | 2012-04-05 15:30:10 -0700 | [diff] [blame] | 1477 | } |