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