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