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