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