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