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