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