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