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