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