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