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