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