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