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