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