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