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