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