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