Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
Jorim Jaggi | 612bb88 | 2017-05-16 17:11:18 +0200 | [diff] [blame] | 19 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; |
| 20 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; |
| 21 | import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 22 | import static android.content.pm.ActivityInfo.isFixedOrientationLandscape; |
| 23 | import static android.content.pm.ActivityInfo.isFixedOrientationPortrait; |
| 24 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
| 25 | import static android.content.res.Configuration.ORIENTATION_PORTRAIT; |
| 26 | import static android.content.res.Configuration.ORIENTATION_UNDEFINED; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 27 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 28 | import static android.os.UserHandle.USER_NULL; |
Vishnu Nair | 04ab439 | 2018-01-10 11:00:06 -0800 | [diff] [blame] | 29 | import static android.view.SurfaceControl.Transaction; |
Louis Chang | 7501e33 | 2018-08-20 13:08:39 +0800 | [diff] [blame] | 30 | |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 31 | import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; |
lumark | 8669ef3 | 2020-02-10 18:41:57 +0800 | [diff] [blame] | 32 | import static com.android.server.wm.AppTransition.MAX_APP_TRANSITION_DURATION; |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 33 | import static com.android.server.wm.IdentifierProto.HASH_CODE; |
| 34 | import static com.android.server.wm.IdentifierProto.TITLE; |
| 35 | import static com.android.server.wm.IdentifierProto.USER_ID; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 36 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS; |
| 37 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_APP_TRANSITIONS_ANIM; |
Vadim Caen | 1096f11 | 2019-12-18 11:44:26 +0100 | [diff] [blame] | 38 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ORIENTATION; |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 39 | import static com.android.server.wm.SurfaceAnimator.ANIMATION_TYPE_APP_TRANSITION; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 40 | import static com.android.server.wm.WindowContainer.AnimationFlags.CHILDREN; |
| 41 | import static com.android.server.wm.WindowContainer.AnimationFlags.PARENTS; |
| 42 | import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 43 | import static com.android.server.wm.WindowContainerProto.CONFIGURATION_CONTAINER; |
| 44 | import static com.android.server.wm.WindowContainerProto.ORIENTATION; |
| 45 | import static com.android.server.wm.WindowContainerProto.SURFACE_ANIMATOR; |
| 46 | import static com.android.server.wm.WindowContainerProto.VISIBLE; |
Louis Chang | 7501e33 | 2018-08-20 13:08:39 +0800 | [diff] [blame] | 47 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM; |
| 48 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 49 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 50 | import static com.android.server.wm.WindowManagerService.logWithStack; |
lumark | 8571866 | 2019-12-26 22:05:12 +0800 | [diff] [blame] | 51 | import static com.android.server.wm.WindowManagerService.sHierarchicalAnimations; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 52 | import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM; |
Jorim Jaggi | 612bb88 | 2017-05-16 17:11:18 +0200 | [diff] [blame] | 53 | |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 54 | import android.annotation.CallSuper; |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 55 | import android.annotation.IntDef; |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 56 | import android.annotation.Nullable; |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 57 | import android.app.WindowConfiguration; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 58 | import android.content.pm.ActivityInfo; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 59 | import android.content.res.Configuration; |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 60 | import android.graphics.Point; |
| 61 | import android.graphics.Rect; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 62 | import android.os.Debug; |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 63 | import android.os.IBinder; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 64 | import android.os.Trace; |
| 65 | import android.util.Pair; |
Vishnu Nair | 04ab439 | 2018-01-10 11:00:06 -0800 | [diff] [blame] | 66 | import android.util.Pools; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 67 | import android.util.Slog; |
Vishnu Nair | 04ab439 | 2018-01-10 11:00:06 -0800 | [diff] [blame] | 68 | import android.util.proto.ProtoOutputStream; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 69 | import android.view.DisplayInfo; |
Evan Rosky | a80f11c | 2020-01-23 19:17:10 -0800 | [diff] [blame] | 70 | import android.view.IWindowContainer; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 71 | import android.view.MagnificationSpec; |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 72 | import android.view.RemoteAnimationDefinition; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 73 | import android.view.RemoteAnimationTarget; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 74 | import android.view.SurfaceControl; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 75 | import android.view.SurfaceControl.Builder; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 76 | import android.view.SurfaceSession; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 77 | import android.view.WindowManager; |
| 78 | import android.view.animation.Animation; |
Garfield Tan | 2f145f2 | 2018-11-01 15:27:03 -0700 | [diff] [blame] | 79 | |
Evan Rosky | 65dffa6 | 2019-02-04 14:09:53 -0800 | [diff] [blame] | 80 | import com.android.internal.annotations.VisibleForTesting; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 81 | import com.android.internal.util.ToBooleanFunction; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 82 | import com.android.server.protolog.common.ProtoLog; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 83 | import com.android.server.wm.SurfaceAnimator.Animatable; |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 84 | import com.android.server.wm.SurfaceAnimator.AnimationType; |
| 85 | import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback; |
Garfield Tan | 2f145f2 | 2018-11-01 15:27:03 -0700 | [diff] [blame] | 86 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 87 | import java.io.PrintWriter; |
Evan Rosky | a80f11c | 2020-01-23 19:17:10 -0800 | [diff] [blame] | 88 | import java.lang.ref.WeakReference; |
Yunfan Chen | 87b5a24 | 2019-10-01 17:53:59 +0900 | [diff] [blame] | 89 | import java.util.ArrayList; |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 90 | import java.util.Comparator; |
| 91 | import java.util.LinkedList; |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 92 | import java.util.function.Consumer; |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 93 | import java.util.function.Function; |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 94 | import java.util.function.Predicate; |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * Defines common functionality for classes that can hold windows directly or through their |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 98 | * children in a hierarchy form. |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 99 | * The test class is {@link WindowContainerTests} which must be kept up-to-date and ran anytime |
| 100 | * changes are made to this class. |
| 101 | */ |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 102 | class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<E> |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 103 | implements Comparable<WindowContainer>, Animatable, SurfaceFreezer.Freezable, |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 104 | BLASTSyncEngine.TransactionReadyListener { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 105 | |
| 106 | private static final String TAG = TAG_WITH_CLASS_NAME ? "WindowContainer" : TAG_WM; |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 107 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 108 | /** Animation layer that happens above all animating {@link ActivityStack}s. */ |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 109 | static final int ANIMATION_LAYER_STANDARD = 0; |
| 110 | |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 111 | /** Animation layer that happens above all {@link ActivityStack}s. */ |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 112 | static final int ANIMATION_LAYER_BOOSTED = 1; |
| 113 | |
| 114 | /** |
| 115 | * Animation layer that is reserved for {@link WindowConfiguration#ACTIVITY_TYPE_HOME} |
Winson Chung | 732446a | 2018-09-19 13:15:17 -0700 | [diff] [blame] | 116 | * activities and all activities that are being controlled by the recents animation. This |
Louis Chang | dc07727 | 2019-11-12 16:52:56 +0800 | [diff] [blame] | 117 | * layer is generally below all {@link ActivityStack}s. |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 118 | */ |
| 119 | static final int ANIMATION_LAYER_HOME = 2; |
| 120 | |
| 121 | @IntDef(prefix = { "ANIMATION_LAYER_" }, value = { |
| 122 | ANIMATION_LAYER_STANDARD, |
| 123 | ANIMATION_LAYER_BOOSTED, |
| 124 | ANIMATION_LAYER_HOME, |
| 125 | }) |
| 126 | @interface AnimationLayer {} |
| 127 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 128 | static final int POSITION_TOP = Integer.MAX_VALUE; |
| 129 | static final int POSITION_BOTTOM = Integer.MIN_VALUE; |
| 130 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 131 | /** |
| 132 | * The parent of this window container. |
| 133 | * For removing or setting new parent {@link #setParent} should be used, because it also |
| 134 | * performs configuration updates based on new parent's settings. |
| 135 | */ |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 136 | private WindowContainer<WindowContainer> mParent = null; |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 137 | |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 138 | // Set to true when we are performing a reparenting operation so we only send one |
| 139 | // onParentChanged() notification. |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 140 | boolean mReparenting; |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 141 | |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 142 | // List of children for this window container. List is in z-order as the children appear on |
| 143 | // screen with the top-most window container at the tail of the list. |
Jorim Jaggi | 612bb88 | 2017-05-16 17:11:18 +0200 | [diff] [blame] | 144 | protected final WindowList<E> mChildren = new WindowList<E>(); |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 145 | |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 146 | // The specified orientation for this window container. |
Vadim Caen | 1096f11 | 2019-12-18 11:44:26 +0100 | [diff] [blame] | 147 | @ActivityInfo.ScreenOrientation |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 148 | protected int mOrientation = SCREEN_ORIENTATION_UNSPECIFIED; |
| 149 | |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 150 | /** |
| 151 | * The window container which decides its orientation since the last time |
| 152 | * {@link #getOrientation(int) was called. |
| 153 | */ |
| 154 | protected WindowContainer mLastOrientationSource; |
| 155 | |
Wale Ogunwale | ee41d4a | 2016-11-21 08:41:10 -0800 | [diff] [blame] | 156 | private final Pools.SynchronizedPool<ForAllWindowsConsumerWrapper> mConsumerWrapperPool = |
| 157 | new Pools.SynchronizedPool<>(3); |
| 158 | |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 159 | // The display this window container is on. |
| 160 | protected DisplayContent mDisplayContent; |
| 161 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 162 | protected SurfaceControl mSurfaceControl; |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 163 | private int mLastLayer = 0; |
| 164 | private SurfaceControl mLastRelativeToLayer = null; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 165 | |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 166 | // TODO(b/132320879): Remove this from WindowContainers except DisplayContent. |
| 167 | private final Transaction mPendingTransaction; |
| 168 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 169 | /** |
Yunfan Chen | 87b5a24 | 2019-10-01 17:53:59 +0900 | [diff] [blame] | 170 | * Windows that clients are waiting to have drawn. |
| 171 | */ |
| 172 | final ArrayList<WindowState> mWaitingForDrawn = new ArrayList<>(); |
| 173 | |
| 174 | /** |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 175 | * Applied as part of the animation pass in "prepareSurfaces". |
| 176 | */ |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 177 | protected final SurfaceAnimator mSurfaceAnimator; |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 178 | final SurfaceFreezer mSurfaceFreezer; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 179 | protected final WindowManagerService mWmService; |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 180 | |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 181 | private final Point mTmpPos = new Point(); |
chaviw | 3e751af | 2018-01-11 11:22:39 -0800 | [diff] [blame] | 182 | protected final Point mLastSurfacePosition = new Point(); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 183 | |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 184 | /** Total number of elements in this subtree, including our own hierarchy element. */ |
| 185 | private int mTreeWeight = 1; |
| 186 | |
chaviw | 7f1fa99 | 2018-01-10 13:52:12 -0800 | [diff] [blame] | 187 | /** |
Vishnu Nair | ddd8074 | 2018-08-21 14:12:46 -0700 | [diff] [blame] | 188 | * Indicates whether we are animating and have committed the transaction to reparent our |
chaviw | 7f1fa99 | 2018-01-10 13:52:12 -0800 | [diff] [blame] | 189 | * surface to the animation leash |
| 190 | */ |
| 191 | private boolean mCommittedReparentToAnimationLeash; |
| 192 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 193 | private final Configuration mTmpConfig = new Configuration(); |
| 194 | |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 195 | /** Interface for {@link #isAnimating} to check which cases for the container is animating. */ |
| 196 | public interface AnimationFlags { |
| 197 | /** |
| 198 | * A bit flag indicates that {@link #isAnimating} should also return {@code true} |
| 199 | * even though the container is not yet animating, but the window container or its |
| 200 | * relatives as specified by PARENTS or CHILDREN are part of an {@link AppTransition} |
| 201 | * that is pending so an animation starts soon. |
| 202 | */ |
| 203 | int TRANSITION = 1; |
| 204 | |
| 205 | /** |
| 206 | * A bit flag indicates that {@link #isAnimating} should also check if one of the |
| 207 | * ancestors of the container are animating in addition to the container itself. |
| 208 | */ |
| 209 | int PARENTS = 2; |
| 210 | |
| 211 | /** |
| 212 | * A bit flag indicates that {@link #isAnimating} should also check if one of the |
| 213 | * descendants of the container are animating in addition to the container itself. |
| 214 | */ |
| 215 | int CHILDREN = 4; |
| 216 | } |
| 217 | |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 218 | /** |
| 219 | * Callback which is triggered while changing the parent, after setting up the surface but |
| 220 | * before asking the parent to assign child layers. |
| 221 | */ |
| 222 | interface PreAssignChildLayersCallback { |
| 223 | void onPreAssignChildLayers(); |
| 224 | } |
| 225 | |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 226 | /** |
| 227 | * True if this an AppWindowToken and the activity which created this was launched with |
| 228 | * ActivityOptions.setLaunchTaskBehind. |
| 229 | * |
| 230 | * TODO(b/142617871): We run a special animation when the activity was launched with that |
| 231 | * flag, but it's not necessary anymore. Keep the window invisible until the task is explicitly |
| 232 | * selected to suppress an animation, and remove this flag. |
| 233 | */ |
| 234 | boolean mLaunchTaskBehind; |
| 235 | |
| 236 | /** |
| 237 | * If we are running an animation, this determines the transition type. Must be one of |
| 238 | * {@link AppTransition#TransitionFlags}. |
| 239 | */ |
| 240 | int mTransit; |
| 241 | |
| 242 | /** |
| 243 | * If we are running an animation, this determines the flags during this animation. Must be a |
| 244 | * bitwise combination of AppTransition.TRANSIT_FLAG_* constants. |
| 245 | */ |
| 246 | int mTransitFlags; |
| 247 | |
| 248 | /** Whether this container should be boosted at the top of all its siblings. */ |
| 249 | @VisibleForTesting boolean mNeedsZBoost; |
| 250 | |
| 251 | /** Layer used to constrain the animation to a container's stack bounds. */ |
| 252 | SurfaceControl mAnimationBoundsLayer; |
| 253 | |
| 254 | /** Whether this container needs to create mAnimationBoundsLayer for cropping animations. */ |
| 255 | boolean mNeedsAnimationBoundsLayer; |
| 256 | |
| 257 | /** |
| 258 | * This gets used during some open/close transitions as well as during a change transition |
| 259 | * where it represents the starting-state snapshot. |
| 260 | */ |
lumark | bc0032a | 2019-11-01 21:38:13 +0800 | [diff] [blame] | 261 | WindowContainerThumbnail mThumbnail; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 262 | final Point mTmpPoint = new Point(); |
| 263 | protected final Rect mTmpRect = new Rect(); |
| 264 | final Rect mTmpPrevBounds = new Rect(); |
| 265 | |
Robert Carr | 7603dea | 2019-07-17 13:16:21 -0700 | [diff] [blame] | 266 | private MagnificationSpec mLastMagnificationSpec; |
| 267 | |
Evan Rosky | 226de13 | 2020-01-03 18:00:29 -0800 | [diff] [blame] | 268 | private boolean mIsFocusable = true; |
| 269 | |
Evan Rosky | a80f11c | 2020-01-23 19:17:10 -0800 | [diff] [blame] | 270 | /** |
| 271 | * Used as a unique, cross-process identifier for this Container. It also serves a minimal |
| 272 | * interface to other processes. |
| 273 | */ |
| 274 | RemoteToken mRemoteToken = null; |
| 275 | |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 276 | BLASTSyncEngine mBLASTSyncEngine = new BLASTSyncEngine(); |
| 277 | SurfaceControl.Transaction mBLASTSyncTransaction = new SurfaceControl.Transaction(); |
| 278 | boolean mUsingBLASTSyncTransaction = false; |
| 279 | BLASTSyncEngine.TransactionReadyListener mWaitingListener; |
| 280 | int mWaitingSyncId; |
| 281 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 282 | WindowContainer(WindowManagerService wms) { |
| 283 | mWmService = wms; |
Vishnu Nair | 3319739 | 2019-08-30 10:29:37 -0700 | [diff] [blame] | 284 | mPendingTransaction = wms.mTransactionFactory.get(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 285 | mSurfaceAnimator = new SurfaceAnimator(this, this::onAnimationFinished, wms); |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 286 | mSurfaceFreezer = new SurfaceFreezer(this, wms); |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 287 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 288 | |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 289 | @Override |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 290 | final protected WindowContainer getParent() { |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 291 | return mParent; |
| 292 | } |
| 293 | |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 294 | @Override |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 295 | protected int getChildCount() { |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 296 | return mChildren.size(); |
| 297 | } |
| 298 | |
| 299 | @Override |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 300 | protected E getChildAt(int index) { |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 301 | return mChildren.get(index); |
| 302 | } |
| 303 | |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 304 | @Override |
| 305 | public void onConfigurationChanged(Configuration newParentConfig) { |
| 306 | super.onConfigurationChanged(newParentConfig); |
chaviw | 2f0567b | 2018-01-29 16:22:02 -0800 | [diff] [blame] | 307 | updateSurfacePosition(); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 308 | scheduleAnimation(); |
| 309 | } |
| 310 | |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 311 | void reparent(WindowContainer newParent, int position) { |
| 312 | if (newParent == null) { |
| 313 | throw new IllegalArgumentException("reparent: can't reparent to null " + this); |
| 314 | } |
| 315 | |
| 316 | final WindowContainer oldParent = mParent; |
| 317 | if (mParent == newParent) { |
| 318 | throw new IllegalArgumentException("WC=" + this + " already child of " + mParent); |
| 319 | } |
| 320 | |
| 321 | // The display object before reparenting as that might lead to old parent getting removed |
| 322 | // from the display if it no longer has any child. |
| 323 | final DisplayContent prevDc = oldParent.getDisplayContent(); |
| 324 | final DisplayContent dc = newParent.getDisplayContent(); |
| 325 | |
| 326 | mReparenting = true; |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 327 | oldParent.removeChild(this); |
Louis Chang | 2453d06 | 2019-11-19 22:30:48 +0800 | [diff] [blame] | 328 | newParent.addChild(this, position); |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 329 | mReparenting = false; |
| 330 | |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 331 | // Relayout display(s) |
| 332 | dc.setLayoutNeeded(); |
| 333 | if (prevDc != dc) { |
| 334 | onDisplayChanged(dc); |
| 335 | prevDc.setLayoutNeeded(); |
| 336 | } |
| 337 | getDisplayContent().layoutAndAssignWindowLayersIfNeeded(); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 338 | |
| 339 | // Send onParentChanged notification here is we disabled sending it in setParent for |
| 340 | // reparenting case. |
| 341 | onParentChanged(newParent, oldParent); |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 342 | } |
| 343 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 344 | final protected void setParent(WindowContainer<WindowContainer> parent) { |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 345 | final WindowContainer oldParent = mParent; |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 346 | mParent = parent; |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 347 | |
| 348 | if (mParent != null) { |
| 349 | mParent.onChildAdded(this); |
| 350 | } |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 351 | if (!mReparenting) { |
lumark | bde1513 | 2019-12-18 22:29:43 +0800 | [diff] [blame] | 352 | if (mParent != null && mParent.mDisplayContent != null |
| 353 | && mDisplayContent != mParent.mDisplayContent) { |
| 354 | onDisplayChanged(mParent.mDisplayContent); |
| 355 | } |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 356 | onParentChanged(mParent, oldParent); |
| 357 | } |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | /** |
| 361 | * Callback that is triggered when @link WindowContainer#setParent(WindowContainer)} was called. |
| 362 | * Supposed to be overridden and contain actions that should be executed after parent was set. |
| 363 | */ |
Riddle Hsu | 3a4bb61 | 2019-01-31 00:02:22 +0800 | [diff] [blame] | 364 | @Override |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 365 | void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent) { |
| 366 | onParentChanged(newParent, oldParent, null); |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 367 | } |
| 368 | |
Wale Ogunwale | c17418e | 2019-10-13 23:00:40 +0200 | [diff] [blame] | 369 | void onParentChanged(ConfigurationContainer newParent, ConfigurationContainer oldParent, |
| 370 | PreAssignChildLayersCallback callback) { |
| 371 | super.onParentChanged(newParent, oldParent); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 372 | if (mParent == null) { |
| 373 | return; |
| 374 | } |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 375 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 376 | if (mSurfaceControl == null) { |
| 377 | // If we don't yet have a surface, but we now have a parent, we should |
| 378 | // build a surface. |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 379 | setSurfaceControl(makeSurface().build()); |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 380 | getPendingTransaction().show(mSurfaceControl); |
Vishnu Nair | fd6fb67 | 2020-02-14 12:56:37 -0800 | [diff] [blame] | 381 | onSurfaceShown(getPendingTransaction()); |
Evan Rosky | b1ea7ca | 2018-04-05 17:17:35 -0700 | [diff] [blame] | 382 | updateSurfacePosition(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 383 | } else { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 384 | // If we have a surface but a new parent, we just need to perform a reparent. Go through |
| 385 | // surface animator such that hierarchy is preserved when animating, i.e. |
| 386 | // mSurfaceControl stays attached to the leash and we just reparent the leash to the |
| 387 | // new parent. |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 388 | reparentSurfaceControl(getPendingTransaction(), mParent.mSurfaceControl); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Issei Suzuki | 25a9e2b | 2019-08-14 16:46:26 +0200 | [diff] [blame] | 391 | if (callback != null) { |
| 392 | callback.onPreAssignChildLayers(); |
| 393 | } |
| 394 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 395 | // Either way we need to ask the parent to assign us a Z-order. |
| 396 | mParent.assignChildLayers(); |
| 397 | scheduleAnimation(); |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Vishnu Nair | fd6fb67 | 2020-02-14 12:56:37 -0800 | [diff] [blame] | 400 | /** |
| 401 | * Called when the surface is shown for the first time. |
| 402 | */ |
| 403 | void onSurfaceShown(Transaction t) { |
| 404 | // do nothing |
| 405 | } |
| 406 | |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 407 | // Temp. holders for a chain of containers we are currently processing. |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 408 | private final LinkedList<WindowContainer> mTmpChain1 = new LinkedList<>(); |
| 409 | private final LinkedList<WindowContainer> mTmpChain2 = new LinkedList<>(); |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 410 | |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 411 | /** |
| 412 | * Adds the input window container has a child of this container in order based on the input |
| 413 | * comparator. |
| 414 | * @param child The window container to add as a child of this window container. |
| 415 | * @param comparator Comparator to use in determining the position the child should be added to. |
| 416 | * If null, the child will be added to the top. |
| 417 | */ |
| 418 | @CallSuper |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 419 | protected void addChild(E child, Comparator<E> comparator) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 420 | if (!child.mReparenting && child.getParent() != null) { |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 421 | throw new IllegalArgumentException("addChild: container=" + child.getName() |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 422 | + " is already a child of container=" + child.getParent().getName() |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 423 | + " can't add to container=" + getName()); |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 424 | } |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 425 | |
Andrii Kulian | b94292e | 2016-10-19 13:30:58 -0700 | [diff] [blame] | 426 | int positionToAdd = -1; |
| 427 | if (comparator != null) { |
| 428 | final int count = mChildren.size(); |
| 429 | for (int i = 0; i < count; i++) { |
| 430 | if (comparator.compare(child, mChildren.get(i)) < 0) { |
| 431 | positionToAdd = i; |
| 432 | break; |
| 433 | } |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 434 | } |
| 435 | } |
| 436 | |
Andrii Kulian | b94292e | 2016-10-19 13:30:58 -0700 | [diff] [blame] | 437 | if (positionToAdd == -1) { |
| 438 | mChildren.add(child); |
| 439 | } else { |
| 440 | mChildren.add(positionToAdd, child); |
| 441 | } |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 442 | |
Andrii Kulian | b94292e | 2016-10-19 13:30:58 -0700 | [diff] [blame] | 443 | // Set the parent after we've actually added a child in case a subclass depends on this. |
| 444 | child.setParent(this); |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 447 | /** Adds the input window container has a child of this container at the input index. */ |
| 448 | @CallSuper |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 449 | void addChild(E child, int index) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 450 | if (!child.mReparenting && child.getParent() != null) { |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 451 | throw new IllegalArgumentException("addChild: container=" + child.getName() |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 452 | + " is already a child of container=" + child.getParent().getName() |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 453 | + " can't add to container=" + getName() |
| 454 | + "\n callers=" + Debug.getCallers(15, "\n")); |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 455 | } |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 456 | |
| 457 | if ((index < 0 && index != POSITION_BOTTOM) |
| 458 | || (index > mChildren.size() && index != POSITION_TOP)) { |
| 459 | throw new IllegalArgumentException("addChild: invalid position=" + index |
| 460 | + ", children number=" + mChildren.size()); |
| 461 | } |
| 462 | |
| 463 | if (index == POSITION_TOP) { |
| 464 | index = mChildren.size(); |
| 465 | } else if (index == POSITION_BOTTOM) { |
| 466 | index = 0; |
| 467 | } |
| 468 | |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 469 | mChildren.add(index, child); |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 470 | |
Andrii Kulian | b94292e | 2016-10-19 13:30:58 -0700 | [diff] [blame] | 471 | // Set the parent after we've actually added a child in case a subclass depends on this. |
| 472 | child.setParent(this); |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 475 | private void onChildAdded(WindowContainer child) { |
| 476 | mTreeWeight += child.mTreeWeight; |
| 477 | WindowContainer parent = getParent(); |
| 478 | while (parent != null) { |
| 479 | parent.mTreeWeight += child.mTreeWeight; |
| 480 | parent = parent.getParent(); |
| 481 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 482 | onChildPositionChanged(child); |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 483 | } |
| 484 | |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 485 | /** |
| 486 | * Removes the input child container from this container which is its parent. |
| 487 | * |
| 488 | * @return True if the container did contain the input child and it was detached. |
| 489 | */ |
| 490 | @CallSuper |
| 491 | void removeChild(E child) { |
| 492 | if (mChildren.remove(child)) { |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 493 | onChildRemoved(child); |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 494 | if (!child.mReparenting) { |
| 495 | child.setParent(null); |
| 496 | } |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 497 | } else { |
Wale Ogunwale | ba51ca2 | 2016-09-23 06:06:54 -0700 | [diff] [blame] | 498 | throw new IllegalArgumentException("removeChild: container=" + child.getName() |
| 499 | + " is not a child of container=" + getName()); |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 503 | private void onChildRemoved(WindowContainer child) { |
| 504 | mTreeWeight -= child.mTreeWeight; |
| 505 | WindowContainer parent = getParent(); |
| 506 | while (parent != null) { |
| 507 | parent.mTreeWeight -= child.mTreeWeight; |
| 508 | parent = parent.getParent(); |
| 509 | } |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 510 | onChildPositionChanged(child); |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 511 | } |
| 512 | |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 513 | /** |
| 514 | * Removes this window container and its children with no regard for what else might be going on |
| 515 | * in the system. For example, the container will be removed during animation if this method is |
| 516 | * called which isn't desirable. For most cases you want to call {@link #removeIfPossible()} |
| 517 | * which allows the system to defer removal until a suitable time. |
| 518 | */ |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 519 | @CallSuper |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 520 | void removeImmediately() { |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 521 | while (!mChildren.isEmpty()) { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 522 | final E child = mChildren.peekLast(); |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 523 | child.removeImmediately(); |
| 524 | // Need to do this after calling remove on the child because the child might try to |
| 525 | // remove/detach itself from its parent which will cause an exception if we remove |
| 526 | // it before calling remove on the child. |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 527 | if (mChildren.remove(child)) { |
| 528 | onChildRemoved(child); |
| 529 | } |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 532 | if (mSurfaceControl != null) { |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 533 | getPendingTransaction().remove(mSurfaceControl); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 534 | setSurfaceControl(null); |
Garfield Tan | 265ab91a | 2019-11-12 16:30:49 -0800 | [diff] [blame] | 535 | mLastSurfacePosition.set(0, 0); |
Chavi Weingarten | b736e32 | 2018-02-23 00:27:54 +0000 | [diff] [blame] | 536 | scheduleAnimation(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 539 | if (mParent != null) { |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 540 | mParent.removeChild(this); |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 541 | } |
| 542 | } |
| 543 | |
| 544 | /** |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 545 | * @return The index of this element in the hierarchy tree in prefix order. |
| 546 | */ |
| 547 | int getPrefixOrderIndex() { |
| 548 | if (mParent == null) { |
| 549 | return 0; |
| 550 | } |
| 551 | return mParent.getPrefixOrderIndex(this); |
| 552 | } |
| 553 | |
| 554 | private int getPrefixOrderIndex(WindowContainer child) { |
| 555 | int order = 0; |
| 556 | for (int i = 0; i < mChildren.size(); i++) { |
| 557 | final WindowContainer childI = mChildren.get(i); |
| 558 | if (child == childI) { |
| 559 | break; |
| 560 | } |
| 561 | order += childI.mTreeWeight; |
| 562 | } |
| 563 | if (mParent != null) { |
| 564 | order += mParent.getPrefixOrderIndex(this); |
| 565 | } |
| 566 | |
| 567 | // We also need to count ourselves. |
| 568 | order++; |
| 569 | return order; |
| 570 | } |
| 571 | |
| 572 | /** |
Wale Ogunwale | 571771c | 2016-08-26 13:18:50 -0700 | [diff] [blame] | 573 | * Removes this window container and its children taking care not to remove them during a |
| 574 | * critical stage in the system. For example, some containers will not be removed during |
| 575 | * animation if this method is called. |
| 576 | */ |
| 577 | // TODO: figure-out implementation that works best for this. |
| 578 | // E.g. when do we remove from parent list? maybe not... |
| 579 | void removeIfPossible() { |
| 580 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 581 | final WindowContainer wc = mChildren.get(i); |
| 582 | wc.removeIfPossible(); |
| 583 | } |
| 584 | } |
| 585 | |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 586 | /** Returns true if this window container has the input child. */ |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 587 | boolean hasChild(E child) { |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 588 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 589 | final E current = mChildren.get(i); |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 590 | if (current == child || current.hasChild(child)) { |
| 591 | return true; |
| 592 | } |
| 593 | } |
| 594 | return false; |
| 595 | } |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 596 | |
Issei Suzuki | 2f54184 | 2020-01-09 20:18:29 +0100 | [diff] [blame] | 597 | /** @return true if this window container is a descendant of the input container. */ |
| 598 | boolean isDescendantOf(WindowContainer ancestor) { |
| 599 | final WindowContainer parent = getParent(); |
| 600 | if (parent == ancestor) return true; |
| 601 | return (parent != null) && parent.isDescendantOf(ancestor); |
| 602 | } |
| 603 | |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 604 | /** |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 605 | * Move a child from it's current place in siblings list to the specified position, |
| 606 | * with an option to move all its parents to top. |
| 607 | * @param position Target position to move the child to. |
| 608 | * @param child Child to move to selected position. |
| 609 | * @param includingParents Flag indicating whether we need to move the entire branch of the |
| 610 | * hierarchy when we're moving a child to {@link #POSITION_TOP} or |
| 611 | * {@link #POSITION_BOTTOM}. When moving to other intermediate positions |
| 612 | * this flag will do nothing. |
| 613 | */ |
| 614 | @CallSuper |
| 615 | void positionChildAt(int position, E child, boolean includingParents) { |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 616 | |
| 617 | if (child.getParent() != this) { |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 618 | throw new IllegalArgumentException("positionChildAt: container=" + child.getName() |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 619 | + " is not a child of container=" + getName() |
| 620 | + " current parent=" + child.getParent()); |
| 621 | } |
| 622 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 623 | if (position >= mChildren.size() - 1) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 624 | position = POSITION_TOP; |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 625 | } else if (position <= 0) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 626 | position = POSITION_BOTTOM; |
| 627 | } |
| 628 | |
| 629 | switch (position) { |
| 630 | case POSITION_TOP: |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 631 | if (mChildren.peekLast() != child) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 632 | mChildren.remove(child); |
Jorim Jaggi | 612bb88 | 2017-05-16 17:11:18 +0200 | [diff] [blame] | 633 | mChildren.add(child); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 634 | onChildPositionChanged(child); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 635 | } |
| 636 | if (includingParents && getParent() != null) { |
| 637 | getParent().positionChildAt(POSITION_TOP, this /* child */, |
| 638 | true /* includingParents */); |
| 639 | } |
| 640 | break; |
| 641 | case POSITION_BOTTOM: |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 642 | if (mChildren.peekFirst() != child) { |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 643 | mChildren.remove(child); |
| 644 | mChildren.addFirst(child); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 645 | onChildPositionChanged(child); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 646 | } |
| 647 | if (includingParents && getParent() != null) { |
| 648 | getParent().positionChildAt(POSITION_BOTTOM, this /* child */, |
| 649 | true /* includingParents */); |
| 650 | } |
| 651 | break; |
| 652 | default: |
Winson Chung | 123e07a | 2018-02-27 11:47:16 -0800 | [diff] [blame] | 653 | // TODO: Removing the child before reinserting requires the caller to provide a |
| 654 | // position that takes into account the removed child (if the index of the |
| 655 | // child < position, then the position should be adjusted). We should consider |
| 656 | // doing this adjustment here and remove any adjustments in the callers. |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 657 | mChildren.remove(child); |
| 658 | mChildren.add(position, child); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 659 | onChildPositionChanged(child); |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 660 | } |
| 661 | } |
| 662 | |
| 663 | /** |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 664 | * Notify that a child's position has changed. Possible changes are adding or removing a child. |
| 665 | */ |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 666 | void onChildPositionChanged(WindowContainer child) { } |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 667 | |
| 668 | /** |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 669 | * Update override configuration and recalculate full config. |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 670 | * @see #mRequestedOverrideConfiguration |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 671 | * @see #mFullConfiguration |
| 672 | */ |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 673 | @Override |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 674 | public void onRequestedOverrideConfigurationChanged(Configuration overrideConfiguration) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 675 | // We must diff before the configuration is applied so that we can capture the change |
| 676 | // against the existing bounds. |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 677 | final int diff = diffRequestedOverrideBounds( |
| 678 | overrideConfiguration.windowConfiguration.getBounds()); |
| 679 | super.onRequestedOverrideConfigurationChanged(overrideConfiguration); |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 680 | if (mParent != null) { |
| 681 | mParent.onDescendantOverrideConfigurationChanged(); |
| 682 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 683 | |
| 684 | if (diff == BOUNDS_CHANGE_NONE) { |
| 685 | return; |
| 686 | } |
| 687 | |
| 688 | if ((diff & BOUNDS_CHANGE_SIZE) == BOUNDS_CHANGE_SIZE) { |
| 689 | onResize(); |
| 690 | } else { |
| 691 | onMovedByResize(); |
| 692 | } |
Wale Ogunwale | 55ddf8f | 2017-03-20 08:56:38 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | /** |
| 696 | * Notify that a descendant's overrideConfiguration has changed. |
| 697 | */ |
| 698 | void onDescendantOverrideConfigurationChanged() { |
| 699 | if (mParent != null) { |
| 700 | mParent.onDescendantOverrideConfigurationChanged(); |
| 701 | } |
Andrii Kulian | 441e449 | 2016-09-29 15:25:00 -0700 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | /** |
Garfield Tan | 2f145f2 | 2018-11-01 15:27:03 -0700 | [diff] [blame] | 705 | * Notify that the display this container is on has changed. This could be either this container |
| 706 | * is moved to a new display, or some configurations on the display it is on changes. |
| 707 | * |
| 708 | * @param dc The display this container is on after changes. |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 709 | */ |
| 710 | void onDisplayChanged(DisplayContent dc) { |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 711 | mDisplayContent = dc; |
| 712 | if (dc != null && dc != this) { |
| 713 | dc.getPendingTransaction().merge(mPendingTransaction); |
| 714 | } |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 715 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 716 | final WindowContainer child = mChildren.get(i); |
| 717 | child.onDisplayChanged(dc); |
| 718 | } |
| 719 | } |
| 720 | |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 721 | DisplayContent getDisplayContent() { |
| 722 | return mDisplayContent; |
| 723 | } |
| 724 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 725 | void setWaitingForDrawnIfResizingChanged() { |
| 726 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 727 | final WindowContainer wc = mChildren.get(i); |
| 728 | wc.setWaitingForDrawnIfResizingChanged(); |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | void onResize() { |
| 733 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 734 | final WindowContainer wc = mChildren.get(i); |
Bryce Lee | d92ae48 | 2018-01-22 13:56:23 -0800 | [diff] [blame] | 735 | wc.onParentResize(); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 736 | } |
| 737 | } |
| 738 | |
Bryce Lee | d92ae48 | 2018-01-22 13:56:23 -0800 | [diff] [blame] | 739 | void onParentResize() { |
| 740 | // In the case this container has specified its own bounds, a parent resize will not |
| 741 | // affect its bounds. Any relevant changes will be propagated through changes to the |
| 742 | // Configuration override. |
| 743 | if (hasOverrideBounds()) { |
| 744 | return; |
| 745 | } |
| 746 | |
| 747 | // Default implementation is to treat as resize on self. |
| 748 | onResize(); |
| 749 | } |
| 750 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 751 | void onMovedByResize() { |
| 752 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 753 | final WindowContainer wc = mChildren.get(i); |
| 754 | wc.onMovedByResize(); |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | void resetDragResizingChangeReported() { |
| 759 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 760 | final WindowContainer wc = mChildren.get(i); |
| 761 | wc.resetDragResizingChangeReported(); |
| 762 | } |
| 763 | } |
| 764 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 765 | void forceWindowsScaleableInTransaction(boolean force) { |
| 766 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 767 | final WindowContainer wc = mChildren.get(i); |
| 768 | wc.forceWindowsScaleableInTransaction(force); |
| 769 | } |
| 770 | } |
| 771 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 772 | /** |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 773 | * @return {@code true} when this container or its related containers are running an |
| 774 | * animation, {@code false} otherwise. |
| 775 | * |
| 776 | * By default this predicate only checks if this container itself is actually running an |
| 777 | * animation, but you can extend the check target over its relatives, or relax the condition |
| 778 | * so that this can return {@code true} if an animation starts soon by giving a combination |
| 779 | * of {@link #AnimationFlags}. |
| 780 | * |
| 781 | * Note that you can give a combination of bitmask flags to specify targets and condition for |
| 782 | * checking animating status. |
| 783 | * e.g. {@code isAnimating(TRANSITION | PARENT)} returns {@code true} if either this |
| 784 | * container itself or one of its parents is running an animation or waiting for an app |
| 785 | * transition. |
| 786 | * |
| 787 | * Note that TRANSITION propagates to parents and children as well. |
| 788 | * |
| 789 | * {@see AnimationFlags#TRANSITION} |
| 790 | * {@see AnimationFlags#PARENTS} |
| 791 | * {@see AnimationFlags#CHILDREN} |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 792 | */ |
Jorim Jaggi | 924ef75 | 2020-01-29 17:26:55 +0100 | [diff] [blame] | 793 | boolean isAnimating(int flags) { |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 794 | if (mSurfaceAnimator.isAnimating()) { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 795 | return true; |
| 796 | } |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 797 | if ((flags & TRANSITION) != 0 && isWaitingForTransitionStart()) { |
| 798 | return true; |
| 799 | } |
| 800 | if ((flags & PARENTS) != 0) { |
| 801 | final WindowContainer parent = getParent(); |
| 802 | if (parent != null && parent.isAnimating(flags & ~CHILDREN)) { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 803 | return true; |
| 804 | } |
| 805 | } |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 806 | if ((flags & CHILDREN) != 0) { |
| 807 | for (int i = 0; i < mChildren.size(); ++i) { |
| 808 | final WindowContainer wc = mChildren.get(i); |
| 809 | if (wc.isAnimating(flags & ~PARENTS)) { |
| 810 | return true; |
| 811 | } |
| 812 | } |
| 813 | } |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 814 | return false; |
| 815 | } |
| 816 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 817 | /** |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 818 | * @return {@code true} when the container is waiting the app transition start, {@code false} |
| 819 | * otherwise. |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 820 | */ |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 821 | boolean isWaitingForTransitionStart() { |
lumark | 52d5f42 | 2020-01-06 16:17:55 +0800 | [diff] [blame] | 822 | return false; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | /** |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 826 | * @return {@code true} if in this subtree of the hierarchy we have an |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 827 | * {@code ActivityRecord#isAnimating(TRANSITION)}, {@code false} otherwise. |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 828 | */ |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 829 | boolean isAppTransitioning() { |
lumark | 5341d1c | 2019-12-14 01:54:02 +0800 | [diff] [blame] | 830 | return getActivity(app -> app.isAnimating(PARENTS | TRANSITION)) != null; |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /** |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 834 | * @return Whether our own container running an animation at the moment. |
| 835 | */ |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 836 | final boolean isAnimating() { |
| 837 | return isAnimating(0 /* self only */); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 838 | } |
| 839 | |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 840 | /** |
| 841 | * @return {@code true} if the container is in changing app transition. |
| 842 | */ |
| 843 | boolean isChangingAppTransition() { |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 844 | return mDisplayContent != null && mDisplayContent.mChangingContainers.contains(this); |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 845 | } |
| 846 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 847 | void sendAppVisibilityToClients() { |
| 848 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 849 | final WindowContainer wc = mChildren.get(i); |
| 850 | wc.sendAppVisibilityToClients(); |
| 851 | } |
| 852 | } |
| 853 | |
Wale Ogunwale | 44f2180 | 2016-09-02 12:49:48 -0700 | [diff] [blame] | 854 | /** |
| 855 | * Returns true if the container or one of its children as some content it can display or wants |
| 856 | * to display (e.g. app views or saved surface). |
| 857 | * |
| 858 | * NOTE: While this method will return true if the there is some content to display, it doesn't |
| 859 | * mean the container is visible. Use {@link #isVisible()} to determine if the container is |
| 860 | * visible. |
| 861 | */ |
| 862 | boolean hasContentToDisplay() { |
| 863 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 864 | final WindowContainer wc = mChildren.get(i); |
| 865 | if (wc.hasContentToDisplay()) { |
| 866 | return true; |
| 867 | } |
| 868 | } |
| 869 | return false; |
| 870 | } |
| 871 | |
| 872 | /** |
| 873 | * Returns true if the container or one of its children is considered visible from the |
| 874 | * WindowManager perspective which usually means valid surface and some other internal state |
| 875 | * are true. |
| 876 | * |
| 877 | * NOTE: While this method will return true if the surface is visible, it doesn't mean the |
| 878 | * client has actually displayed any content. Use {@link #hasContentToDisplay()} to determine if |
| 879 | * the container has any content to display. |
| 880 | */ |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 881 | boolean isVisible() { |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 882 | // TODO: Will this be more correct if it checks the visibility of its parents? |
| 883 | // It depends...For example, Tasks and Stacks are only visible if there children are visible |
| 884 | // but, WindowState are not visible if there parent are not visible. Maybe have the |
Andrii Kulian | cd5dcb8b | 2017-01-03 17:09:45 -0800 | [diff] [blame] | 885 | // container specify which direction to traverse for visibility? |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 886 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 887 | final WindowContainer wc = mChildren.get(i); |
| 888 | if (wc.isVisible()) { |
| 889 | return true; |
| 890 | } |
| 891 | } |
| 892 | return false; |
| 893 | } |
| 894 | |
Evan Rosky | a80f11c | 2020-01-23 19:17:10 -0800 | [diff] [blame] | 895 | /** |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 896 | * Called when the visibility of a child is asked to change. This is before visibility actually |
| 897 | * changes (eg. a transition animation might play out first). |
| 898 | */ |
| 899 | void onChildVisibilityRequested(boolean visible) { |
| 900 | // If we are changing visibility, then a snapshot isn't necessary and we are no-longer |
| 901 | // part of a change transition. |
| 902 | mSurfaceFreezer.unfreeze(getPendingTransaction()); |
| 903 | if (mDisplayContent != null) { |
| 904 | mDisplayContent.mChangingContainers.remove(this); |
| 905 | } |
| 906 | WindowContainer parent = getParent(); |
| 907 | if (parent != null) { |
| 908 | parent.onChildVisibilityRequested(visible); |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) { |
| 913 | final long token = proto.start(fieldId); |
| 914 | proto.write(HASH_CODE, System.identityHashCode(this)); |
| 915 | proto.write(USER_ID, USER_NULL); |
| 916 | proto.write(TITLE, "WindowContainer"); |
| 917 | proto.end(token); |
| 918 | } |
| 919 | |
| 920 | /** |
Evan Rosky | a80f11c | 2020-01-23 19:17:10 -0800 | [diff] [blame] | 921 | * Returns {@code true} if this container is focusable. Generally, if a parent is not focusable, |
| 922 | * this will not be focusable either. |
| 923 | */ |
Evan Rosky | 226de13 | 2020-01-03 18:00:29 -0800 | [diff] [blame] | 924 | boolean isFocusable() { |
Evan Rosky | a80f11c | 2020-01-23 19:17:10 -0800 | [diff] [blame] | 925 | final WindowContainer parent = getParent(); |
| 926 | return (parent == null || parent.isFocusable()) && mIsFocusable; |
Evan Rosky | 226de13 | 2020-01-03 18:00:29 -0800 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | /** Set whether this container or its children can be focusable */ |
Evan Rosky | 226de13 | 2020-01-03 18:00:29 -0800 | [diff] [blame] | 930 | boolean setFocusable(boolean focusable) { |
| 931 | if (mIsFocusable == focusable) { |
| 932 | return false; |
| 933 | } |
| 934 | mIsFocusable = focusable; |
| 935 | return true; |
| 936 | } |
| 937 | |
Bryce Lee | 00d586d | 2017-07-28 20:48:43 -0700 | [diff] [blame] | 938 | /** |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 939 | * @return Whether this child is on top of the window hierarchy. |
Bryce Lee | 00d586d | 2017-07-28 20:48:43 -0700 | [diff] [blame] | 940 | */ |
| 941 | boolean isOnTop() { |
| 942 | return getParent().getTopChild() == this && getParent().isOnTop(); |
| 943 | } |
| 944 | |
Jorim Jaggi | 10abe2f | 2017-01-03 16:44:46 +0100 | [diff] [blame] | 945 | /** Returns the top child container. */ |
| 946 | E getTopChild() { |
| 947 | return mChildren.peekLast(); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 948 | } |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 949 | |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 950 | /** Returns true if there is still a removal being deferred */ |
| 951 | boolean checkCompleteDeferredRemoval() { |
| 952 | boolean stillDeferringRemoval = false; |
| 953 | |
| 954 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 955 | final WindowContainer wc = mChildren.get(i); |
| 956 | stillDeferringRemoval |= wc.checkCompleteDeferredRemoval(); |
| 957 | } |
| 958 | |
| 959 | return stillDeferringRemoval; |
| 960 | } |
| 961 | |
| 962 | /** Checks if all windows in an app are all drawn and shows them if needed. */ |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 963 | void checkAppWindowsReadyToShow() { |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 964 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 965 | final WindowContainer wc = mChildren.get(i); |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 966 | wc.checkAppWindowsReadyToShow(); |
Wale Ogunwale | 3f4433d | 2016-08-18 20:42:42 -0700 | [diff] [blame] | 967 | } |
| 968 | } |
| 969 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 970 | void onAppTransitionDone() { |
| 971 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 972 | final WindowContainer wc = mChildren.get(i); |
| 973 | wc.onAppTransitionDone(); |
| 974 | } |
| 975 | } |
| 976 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 977 | /** |
| 978 | * Called when this container or one of its descendants changed its requested orientation, and |
| 979 | * wants this container to handle it or pass it to its parent. |
| 980 | * |
| 981 | * @param freezeDisplayToken freeze this app window token if display needs to freeze |
| 982 | * @param requestingContainer the container which orientation request has changed |
| 983 | * @return {@code true} if handled; {@code false} otherwise. |
| 984 | */ |
| 985 | boolean onDescendantOrientationChanged(@Nullable IBinder freezeDisplayToken, |
| 986 | @Nullable ConfigurationContainer requestingContainer) { |
| 987 | final WindowContainer parent = getParent(); |
| 988 | if (parent == null) { |
| 989 | return false; |
| 990 | } |
| 991 | return parent.onDescendantOrientationChanged(freezeDisplayToken, |
| 992 | requestingContainer); |
| 993 | } |
| 994 | |
| 995 | /** |
Garfield Tan | 49dae10 | 2019-02-04 09:51:59 -0800 | [diff] [blame] | 996 | * Check if this container or its parent will handle orientation changes from descendants. It's |
| 997 | * different from the return value of {@link #onDescendantOrientationChanged(IBinder, |
| 998 | * ConfigurationContainer)} in the sense that the return value of this method tells if this |
| 999 | * container or its parent will handle the request eventually, while the return value of the |
| 1000 | * other method is if it handled the request synchronously. |
| 1001 | * |
| 1002 | * @return {@code true} if it handles or will handle orientation change in the future; {@code |
| 1003 | * false} if it won't handle the change at anytime. |
| 1004 | */ |
| 1005 | boolean handlesOrientationChangeFromDescendant() { |
| 1006 | final WindowContainer parent = getParent(); |
| 1007 | return parent != null && parent.handlesOrientationChangeFromDescendant(); |
| 1008 | } |
| 1009 | |
| 1010 | /** |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1011 | * Get the configuration orientation by the requested screen orientation |
| 1012 | * ({@link ActivityInfo.ScreenOrientation}) of this activity. |
| 1013 | * |
| 1014 | * @return orientation in ({@link Configuration#ORIENTATION_LANDSCAPE}, |
| 1015 | * {@link Configuration#ORIENTATION_PORTRAIT}, |
| 1016 | * {@link Configuration#ORIENTATION_UNDEFINED}). |
| 1017 | */ |
| 1018 | int getRequestedConfigurationOrientation() { |
| 1019 | if (mOrientation == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 1020 | // NOSENSOR means the display's "natural" orientation, so return that. |
| 1021 | if (mDisplayContent != null) { |
| 1022 | return mDisplayContent.getNaturalOrientation(); |
| 1023 | } |
| 1024 | } else if (mOrientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 1025 | // LOCKED means the activity's orientation remains unchanged, so return existing value. |
| 1026 | return getConfiguration().orientation; |
| 1027 | } else if (isFixedOrientationLandscape(mOrientation)) { |
| 1028 | return ORIENTATION_LANDSCAPE; |
| 1029 | } else if (isFixedOrientationPortrait(mOrientation)) { |
| 1030 | return ORIENTATION_PORTRAIT; |
| 1031 | } |
| 1032 | return ORIENTATION_UNDEFINED; |
| 1033 | } |
| 1034 | |
| 1035 | /** |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1036 | * Calls {@link #setOrientation(int, IBinder, ActivityRecord)} with {@code null} to the last 2 |
| 1037 | * parameters. |
| 1038 | * |
| 1039 | * @param orientation the specified orientation. |
| 1040 | */ |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1041 | void setOrientation(int orientation) { |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1042 | setOrientation(orientation, null /* freezeDisplayToken */, |
| 1043 | null /* ActivityRecord */); |
| 1044 | } |
| 1045 | |
| 1046 | /** |
| 1047 | * Sets the specified orientation of this container. It percolates this change upward along the |
| 1048 | * hierarchy to let each level of the hierarchy a chance to respond to it. |
| 1049 | * |
| 1050 | * @param orientation the specified orientation. Needs to be one of {@link |
| 1051 | * android.content.pm.ActivityInfo.ScreenOrientation}. |
| 1052 | * @param freezeDisplayToken uses this token to freeze display if orientation change is not |
| 1053 | * done. Display will not be frozen if this is {@code null}, which |
| 1054 | * should only happen in tests. |
| 1055 | * @param requestingContainer the container which orientation request has changed. Mostly used |
| 1056 | * to ensure it gets correct configuration. |
| 1057 | */ |
| 1058 | void setOrientation(int orientation, @Nullable IBinder freezeDisplayToken, |
| 1059 | @Nullable ConfigurationContainer requestingContainer) { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 1060 | if (mOrientation == orientation) { |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1061 | return; |
| 1062 | } |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 1063 | |
| 1064 | mOrientation = orientation; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 1065 | final int configOrientation = getRequestedConfigurationOrientation(); |
| 1066 | if (getRequestedOverrideConfiguration().orientation != configOrientation) { |
| 1067 | mTmpConfig.setTo(getRequestedOverrideConfiguration()); |
| 1068 | mTmpConfig.orientation = configOrientation; |
| 1069 | onRequestedOverrideConfigurationChanged(mTmpConfig); |
| 1070 | } |
| 1071 | |
Garfield Tan | 90b0428 | 2018-12-11 14:04:42 -0800 | [diff] [blame] | 1072 | final WindowContainer parent = getParent(); |
| 1073 | if (parent != null) { |
| 1074 | onDescendantOrientationChanged(freezeDisplayToken, requestingContainer); |
| 1075 | } |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
Vadim Caen | 1096f11 | 2019-12-18 11:44:26 +0100 | [diff] [blame] | 1078 | @ActivityInfo.ScreenOrientation |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 1079 | int getOrientation() { |
| 1080 | return getOrientation(mOrientation); |
| 1081 | } |
| 1082 | |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1083 | /** |
| 1084 | * Returns the specified orientation for this window container or one of its children is there |
| 1085 | * is one set, or {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSET} if no |
| 1086 | * specification is set. |
| 1087 | * NOTE: {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED} is a |
| 1088 | * specification... |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 1089 | * |
| 1090 | * @param candidate The current orientation candidate that will be returned if we don't find a |
| 1091 | * better match. |
| 1092 | * @return The orientation as specified by this branch or the window hierarchy. |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1093 | */ |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 1094 | int getOrientation(int candidate) { |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1095 | mLastOrientationSource = null; |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1096 | if (!fillsParent()) { |
| 1097 | // Ignore containers that don't completely fill their parents. |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1098 | return SCREEN_ORIENTATION_UNSET; |
| 1099 | } |
| 1100 | |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1101 | // The container fills its parent so we can use it orientation if it has one |
| 1102 | // specified; otherwise we prefer to use the orientation of its topmost child that has one |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1103 | // specified and fall back on this container's unset or unspecified value as a candidate |
| 1104 | // if none of the children have a better candidate for the orientation. |
| 1105 | if (mOrientation != SCREEN_ORIENTATION_UNSET |
| 1106 | && mOrientation != SCREEN_ORIENTATION_UNSPECIFIED) { |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1107 | mLastOrientationSource = this; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1108 | return mOrientation; |
| 1109 | } |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1110 | |
| 1111 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1112 | final WindowContainer wc = mChildren.get(i); |
| 1113 | |
Wale Ogunwale | 5e5a68d | 2017-03-24 17:36:38 -0700 | [diff] [blame] | 1114 | // TODO: Maybe mOrientation should default to SCREEN_ORIENTATION_UNSET vs. |
| 1115 | // SCREEN_ORIENTATION_UNSPECIFIED? |
| 1116 | final int orientation = wc.getOrientation(candidate == SCREEN_ORIENTATION_BEHIND |
| 1117 | ? SCREEN_ORIENTATION_BEHIND : SCREEN_ORIENTATION_UNSET); |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1118 | if (orientation == SCREEN_ORIENTATION_BEHIND) { |
| 1119 | // container wants us to use the orientation of the container behind it. See if we |
| 1120 | // can find one. Else return SCREEN_ORIENTATION_BEHIND so the caller can choose to |
| 1121 | // look behind this container. |
| 1122 | candidate = orientation; |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1123 | mLastOrientationSource = wc; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1124 | continue; |
| 1125 | } |
| 1126 | |
| 1127 | if (orientation == SCREEN_ORIENTATION_UNSET) { |
| 1128 | continue; |
| 1129 | } |
| 1130 | |
| 1131 | if (wc.fillsParent() || orientation != SCREEN_ORIENTATION_UNSPECIFIED) { |
| 1132 | // Use the orientation if the container fills its parent or requested an explicit |
| 1133 | // orientation that isn't SCREEN_ORIENTATION_UNSPECIFIED. |
Vadim Caen | fc14c66 | 2020-01-20 16:00:31 +0100 | [diff] [blame] | 1134 | ProtoLog.v(WM_DEBUG_ORIENTATION, "%s is requesting orientation %d (%s)", |
| 1135 | wc.toString(), orientation, |
| 1136 | ActivityInfo.screenOrientationToString(orientation)); |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1137 | mLastOrientationSource = wc; |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1138 | return orientation; |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | return candidate; |
| 1143 | } |
| 1144 | |
| 1145 | /** |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 1146 | * @return The deepest source which decides the orientation of this window container since the |
| 1147 | * last time {@link #getOrientation(int) was called. |
| 1148 | */ |
| 1149 | @Nullable |
| 1150 | WindowContainer getLastOrientationSource() { |
| 1151 | final WindowContainer source = mLastOrientationSource; |
| 1152 | if (source != null && source != this) { |
| 1153 | final WindowContainer nextSource = source.getLastOrientationSource(); |
| 1154 | if (nextSource != null) { |
| 1155 | return nextSource; |
| 1156 | } |
| 1157 | } |
| 1158 | return source; |
| 1159 | } |
| 1160 | |
| 1161 | /** |
Wale Ogunwale | 5136249 | 2016-09-08 17:49:17 -0700 | [diff] [blame] | 1162 | * Returns true if this container is opaque and fills all the space made available by its parent |
| 1163 | * container. |
| 1164 | * |
| 1165 | * NOTE: It is possible for this container to occupy more space than the parent has (or less), |
| 1166 | * this is just a signal from the client to window manager stating its intent, but not what it |
| 1167 | * actually does. |
| 1168 | */ |
| 1169 | boolean fillsParent() { |
| 1170 | return false; |
| 1171 | } |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1172 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 1173 | // TODO: Users would have their own window containers under the display container? |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 1174 | void switchUser(int userId) { |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 1175 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 1176 | mChildren.get(i).switchUser(userId); |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1177 | } |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
Wale Ogunwale | 9bb1a1e | 2019-12-30 11:29:52 -0800 | [diff] [blame] | 1180 | boolean showToCurrentUser() { |
| 1181 | return true; |
| 1182 | } |
| 1183 | |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 1184 | /** |
| 1185 | * For all windows at or below this container call the callback. |
| 1186 | * @param callback Calls the {@link ToBooleanFunction#apply} method for each window found and |
| 1187 | * stops the search if {@link ToBooleanFunction#apply} returns true. |
| 1188 | * @param traverseTopToBottom If true traverses the hierarchy from top-to-bottom in terms of |
| 1189 | * z-order, else from bottom-to-top. |
| 1190 | * @return True if the search ended before we reached the end of the hierarchy due to |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 1191 | * {@link ToBooleanFunction#apply} returning true. |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 1192 | */ |
| 1193 | boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 1194 | if (traverseTopToBottom) { |
| 1195 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 1196 | if (mChildren.get(i).forAllWindows(callback, traverseTopToBottom)) { |
| 1197 | return true; |
| 1198 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 1199 | } |
| 1200 | } else { |
| 1201 | final int count = mChildren.size(); |
| 1202 | for (int i = 0; i < count; i++) { |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 1203 | if (mChildren.get(i).forAllWindows(callback, traverseTopToBottom)) { |
| 1204 | return true; |
| 1205 | } |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 1206 | } |
| 1207 | } |
Wale Ogunwale | f4ebe2e | 2016-11-09 13:24:43 -0800 | [diff] [blame] | 1208 | return false; |
| 1209 | } |
| 1210 | |
| 1211 | void forAllWindows(Consumer<WindowState> callback, boolean traverseTopToBottom) { |
Wale Ogunwale | ee41d4a | 2016-11-21 08:41:10 -0800 | [diff] [blame] | 1212 | ForAllWindowsConsumerWrapper wrapper = obtainConsumerWrapper(callback); |
| 1213 | forAllWindows(wrapper, traverseTopToBottom); |
| 1214 | wrapper.release(); |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 1217 | boolean forAllActivities(Function<ActivityRecord, Boolean> callback) { |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 1218 | return forAllActivities(callback, true /*traverseTopToBottom*/); |
| 1219 | } |
| 1220 | |
| 1221 | boolean forAllActivities( |
| 1222 | Function<ActivityRecord, Boolean> callback, boolean traverseTopToBottom) { |
| 1223 | if (traverseTopToBottom) { |
| 1224 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1225 | if (mChildren.get(i).forAllActivities(callback, traverseTopToBottom)) return true; |
| 1226 | } |
| 1227 | } else { |
| 1228 | final int count = mChildren.size(); |
| 1229 | for (int i = 0; i < count; i++) { |
| 1230 | if (mChildren.get(i).forAllActivities(callback, traverseTopToBottom)) return true; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 1231 | } |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1232 | } |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 1233 | |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 1234 | return false; |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1235 | } |
| 1236 | |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 1237 | void forAllActivities(Consumer<ActivityRecord> callback) { |
| 1238 | forAllActivities(callback, true /*traverseTopToBottom*/); |
| 1239 | } |
| 1240 | |
| 1241 | void forAllActivities(Consumer<ActivityRecord> callback, boolean traverseTopToBottom) { |
| 1242 | if (traverseTopToBottom) { |
| 1243 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1244 | mChildren.get(i).forAllActivities(callback, traverseTopToBottom); |
| 1245 | } |
| 1246 | } else { |
| 1247 | final int count = mChildren.size(); |
| 1248 | for (int i = 0; i < count; i++) { |
| 1249 | mChildren.get(i).forAllActivities(callback, traverseTopToBottom); |
| 1250 | } |
| 1251 | } |
| 1252 | } |
| 1253 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 1254 | /** |
| 1255 | * Process all activities in this branch of the tree. |
| 1256 | * |
| 1257 | * @param callback Called for each activity found. |
| 1258 | * @param boundary We don't return activities via {@param callback} until we get to this node in |
| 1259 | * the tree. |
| 1260 | * @param includeBoundary If the boundary from be processed to return activities. |
| 1261 | * @param traverseTopToBottom direction to traverse the tree. |
| 1262 | * @return {@code true} if we ended the search before reaching the end of the tree. |
| 1263 | */ |
| 1264 | final boolean forAllActivities(Function<ActivityRecord, Boolean> callback, |
| 1265 | WindowContainer boundary, boolean includeBoundary, boolean traverseTopToBottom) { |
| 1266 | return forAllActivities( |
| 1267 | callback, boundary, includeBoundary, traverseTopToBottom, new boolean[1]); |
| 1268 | } |
| 1269 | |
| 1270 | private boolean forAllActivities(Function<ActivityRecord, Boolean> callback, |
| 1271 | WindowContainer boundary, boolean includeBoundary, boolean traverseTopToBottom, |
| 1272 | boolean[] boundaryFound) { |
| 1273 | if (traverseTopToBottom) { |
| 1274 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1275 | if (processForAllActivitiesWithBoundary(callback, boundary, includeBoundary, |
| 1276 | traverseTopToBottom, boundaryFound, mChildren.get(i))) { |
| 1277 | return true; |
| 1278 | } |
| 1279 | } |
| 1280 | } else { |
| 1281 | final int count = mChildren.size(); |
| 1282 | for (int i = 0; i < count; i++) { |
| 1283 | if (processForAllActivitiesWithBoundary(callback, boundary, includeBoundary, |
| 1284 | traverseTopToBottom, boundaryFound, mChildren.get(i))) { |
| 1285 | return true; |
| 1286 | } |
| 1287 | } |
| 1288 | } |
| 1289 | |
| 1290 | return false; |
| 1291 | } |
| 1292 | |
| 1293 | private boolean processForAllActivitiesWithBoundary(Function<ActivityRecord, Boolean> callback, |
| 1294 | WindowContainer boundary, boolean includeBoundary, boolean traverseTopToBottom, |
| 1295 | boolean[] boundaryFound, WindowContainer wc) { |
| 1296 | if (wc == boundary) { |
| 1297 | boundaryFound[0] = true; |
| 1298 | if (!includeBoundary) return false; |
| 1299 | } |
| 1300 | |
| 1301 | if (boundaryFound[0]) { |
| 1302 | return wc.forAllActivities(callback, traverseTopToBottom); |
| 1303 | } |
| 1304 | |
| 1305 | return wc.forAllActivities( |
| 1306 | callback, boundary, includeBoundary, traverseTopToBottom, boundaryFound); |
| 1307 | } |
| 1308 | |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 1309 | /** @return {@code true} if this node or any of its children contains an activity. */ |
| 1310 | boolean hasActivity() { |
| 1311 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1312 | if (mChildren.get(i).hasActivity()) { |
| 1313 | return true; |
| 1314 | } |
| 1315 | } |
| 1316 | return false; |
| 1317 | } |
| 1318 | |
| 1319 | ActivityRecord getActivity(Predicate<ActivityRecord> callback) { |
| 1320 | return getActivity(callback, true /*traverseTopToBottom*/); |
| 1321 | } |
| 1322 | |
| 1323 | ActivityRecord getActivity(Predicate<ActivityRecord> callback, boolean traverseTopToBottom) { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1324 | return getActivity(callback, traverseTopToBottom, null /*boundary*/); |
| 1325 | } |
| 1326 | |
| 1327 | ActivityRecord getActivity(Predicate<ActivityRecord> callback, boolean traverseTopToBottom, |
| 1328 | WindowContainer boundary) { |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 1329 | if (traverseTopToBottom) { |
| 1330 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1331 | final WindowContainer wc = mChildren.get(i); |
| 1332 | if (wc == boundary) return null; |
| 1333 | |
| 1334 | final ActivityRecord r = wc.getActivity(callback, traverseTopToBottom, boundary); |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 1335 | if (r != null) { |
| 1336 | return r; |
| 1337 | } |
| 1338 | } |
| 1339 | } else { |
| 1340 | final int count = mChildren.size(); |
| 1341 | for (int i = 0; i < count; i++) { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1342 | final WindowContainer wc = mChildren.get(i); |
| 1343 | if (wc == boundary) return null; |
| 1344 | |
| 1345 | final ActivityRecord r = wc.getActivity(callback, traverseTopToBottom, boundary); |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 1346 | if (r != null) { |
| 1347 | return r; |
| 1348 | } |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | return null; |
| 1353 | } |
| 1354 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 1355 | /** |
| 1356 | * Gets an activity in a branch of the tree. |
| 1357 | * |
| 1358 | * @param callback called to test if this is the activity that should be returned. |
| 1359 | * @param boundary We don't return activities via {@param callback} until we get to this node in |
| 1360 | * the tree. |
| 1361 | * @param includeBoundary If the boundary from be processed to return activities. |
| 1362 | * @param traverseTopToBottom direction to traverse the tree. |
| 1363 | * @return The activity if found or null. |
| 1364 | */ |
| 1365 | final ActivityRecord getActivity(Predicate<ActivityRecord> callback, |
| 1366 | WindowContainer boundary, boolean includeBoundary, boolean traverseTopToBottom) { |
| 1367 | return getActivity( |
| 1368 | callback, boundary, includeBoundary, traverseTopToBottom, new boolean[1]); |
| 1369 | } |
| 1370 | |
| 1371 | private ActivityRecord getActivity(Predicate<ActivityRecord> callback, |
| 1372 | WindowContainer boundary, boolean includeBoundary, boolean traverseTopToBottom, |
| 1373 | boolean[] boundaryFound) { |
| 1374 | if (traverseTopToBottom) { |
| 1375 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1376 | final ActivityRecord r = processGetActivityWithBoundary(callback, boundary, |
| 1377 | includeBoundary, traverseTopToBottom, boundaryFound, mChildren.get(i)); |
| 1378 | if (r != null) { |
| 1379 | return r; |
| 1380 | } |
| 1381 | } |
| 1382 | } else { |
| 1383 | final int count = mChildren.size(); |
| 1384 | for (int i = 0; i < count; i++) { |
| 1385 | final ActivityRecord r = processGetActivityWithBoundary(callback, boundary, |
| 1386 | includeBoundary, traverseTopToBottom, boundaryFound, mChildren.get(i)); |
| 1387 | if (r != null) { |
| 1388 | return r; |
| 1389 | } |
| 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | return null; |
| 1394 | } |
| 1395 | |
| 1396 | private ActivityRecord processGetActivityWithBoundary(Predicate<ActivityRecord> callback, |
| 1397 | WindowContainer boundary, boolean includeBoundary, boolean traverseTopToBottom, |
| 1398 | boolean[] boundaryFound, WindowContainer wc) { |
| 1399 | if (wc == boundary || boundary == null) { |
| 1400 | boundaryFound[0] = true; |
| 1401 | if (!includeBoundary) return null; |
| 1402 | } |
| 1403 | |
| 1404 | if (boundaryFound[0]) { |
| 1405 | return wc.getActivity(callback, traverseTopToBottom); |
| 1406 | } |
| 1407 | |
| 1408 | return wc.getActivity( |
| 1409 | callback, boundary, includeBoundary, traverseTopToBottom, boundaryFound); |
| 1410 | } |
| 1411 | |
| 1412 | ActivityRecord getActivityAbove(ActivityRecord r) { |
| 1413 | return getActivity((above) -> true, r, |
| 1414 | false /*includeBoundary*/, false /*traverseTopToBottom*/); |
| 1415 | } |
| 1416 | |
| 1417 | ActivityRecord getActivityBelow(ActivityRecord r) { |
| 1418 | return getActivity((below) -> true, r, |
| 1419 | false /*includeBoundary*/, true /*traverseTopToBottom*/); |
| 1420 | } |
| 1421 | |
| 1422 | ActivityRecord getBottomMostActivity() { |
| 1423 | return getActivity((r) -> true, false /*traverseTopToBottom*/); |
| 1424 | } |
| 1425 | |
| 1426 | ActivityRecord getTopMostActivity() { |
| 1427 | return getActivity((r) -> true, true /*traverseTopToBottom*/); |
| 1428 | } |
| 1429 | |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 1430 | ActivityRecord getTopActivity(boolean includeFinishing, boolean includeOverlays) { |
| 1431 | // Break down into 4 calls to avoid object creation due to capturing input params. |
| 1432 | if (includeFinishing) { |
| 1433 | if (includeOverlays) { |
| 1434 | return getActivity((r) -> true); |
| 1435 | } |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 1436 | return getActivity((r) -> !r.isTaskOverlay()); |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 1437 | } else if (includeOverlays) { |
| 1438 | return getActivity((r) -> !r.finishing); |
| 1439 | } |
| 1440 | |
Wale Ogunwale | 0b3d292 | 2019-12-30 08:55:07 -0800 | [diff] [blame] | 1441 | return getActivity((r) -> !r.finishing && !r.isTaskOverlay()); |
Wale Ogunwale | dfbeed7 | 2019-11-20 08:57:39 -0800 | [diff] [blame] | 1442 | } |
| 1443 | |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 1444 | void forAllWallpaperWindows(Consumer<WallpaperWindowToken> callback) { |
| 1445 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1446 | mChildren.get(i).forAllWallpaperWindows(callback); |
| 1447 | } |
| 1448 | } |
| 1449 | |
Jorim Jaggi | 51304d7 | 2017-05-17 17:25:32 +0200 | [diff] [blame] | 1450 | /** |
| 1451 | * For all tasks at or below this container call the callback. |
| 1452 | * |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1453 | * @param callback Calls the {@link ToBooleanFunction#apply} method for each task found and |
| 1454 | * stops the search if {@link ToBooleanFunction#apply} returns {@code true}. |
| 1455 | */ |
| 1456 | boolean forAllTasks(Function<Task, Boolean> callback) { |
| 1457 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1458 | if (mChildren.get(i).forAllTasks(callback)) { |
| 1459 | return true; |
| 1460 | } |
| 1461 | } |
| 1462 | return false; |
| 1463 | } |
| 1464 | |
| 1465 | /** |
| 1466 | * For all tasks at or below this container call the callback. |
| 1467 | * |
Jorim Jaggi | 51304d7 | 2017-05-17 17:25:32 +0200 | [diff] [blame] | 1468 | * @param callback Callback to be called for every task. |
| 1469 | */ |
| 1470 | void forAllTasks(Consumer<Task> callback) { |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1471 | forAllTasks(callback, true /*traverseTopToBottom*/); |
| 1472 | } |
| 1473 | |
| 1474 | void forAllTasks(Consumer<Task> callback, boolean traverseTopToBottom) { |
| 1475 | final int count = mChildren.size(); |
| 1476 | if (traverseTopToBottom) { |
| 1477 | for (int i = count - 1; i >= 0; --i) { |
| 1478 | mChildren.get(i).forAllTasks(callback, traverseTopToBottom); |
| 1479 | } |
| 1480 | } else { |
| 1481 | for (int i = 0; i < count; i++) { |
| 1482 | mChildren.get(i).forAllTasks(callback, traverseTopToBottom); |
| 1483 | } |
Jorim Jaggi | 51304d7 | 2017-05-17 17:25:32 +0200 | [diff] [blame] | 1484 | } |
| 1485 | } |
| 1486 | |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 1487 | void forAllLeafTasks(Consumer<Task> callback, boolean traverseTopToBottom) { |
Jeff Chang | dc9c1d4 | 2020-02-11 14:57:34 +0800 | [diff] [blame] | 1488 | final int count = mChildren.size(); |
| 1489 | if (traverseTopToBottom) { |
| 1490 | for (int i = count - 1; i >= 0; --i) { |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 1491 | mChildren.get(i).forAllLeafTasks(callback, traverseTopToBottom); |
Jeff Chang | dc9c1d4 | 2020-02-11 14:57:34 +0800 | [diff] [blame] | 1492 | } |
| 1493 | } else { |
| 1494 | for (int i = 0; i < count; i++) { |
Wale Ogunwale | 0d46519 | 2020-01-23 19:14:44 -0800 | [diff] [blame] | 1495 | mChildren.get(i).forAllLeafTasks(callback, traverseTopToBottom); |
Jeff Chang | dc9c1d4 | 2020-02-11 14:57:34 +0800 | [diff] [blame] | 1496 | } |
| 1497 | } |
| 1498 | } |
| 1499 | |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1500 | Task getTaskAbove(Task t) { |
| 1501 | return getTask( |
| 1502 | (above) -> true, t, false /*includeBoundary*/, false /*traverseTopToBottom*/); |
| 1503 | } |
| 1504 | |
| 1505 | Task getTaskBelow(Task t) { |
| 1506 | return getTask((below) -> true, t, false /*includeBoundary*/, true /*traverseTopToBottom*/); |
| 1507 | } |
| 1508 | |
| 1509 | Task getBottomMostTask() { |
| 1510 | return getTask((t) -> true, false /*traverseTopToBottom*/); |
| 1511 | } |
| 1512 | |
| 1513 | Task getTopMostTask() { |
| 1514 | return getTask((t) -> true, true /*traverseTopToBottom*/); |
| 1515 | } |
| 1516 | |
Wale Ogunwale | a38654f | 2019-11-17 20:37:15 -0800 | [diff] [blame] | 1517 | Task getTask(Predicate<Task> callback) { |
| 1518 | return getTask(callback, true /*traverseTopToBottom*/); |
| 1519 | } |
| 1520 | |
| 1521 | Task getTask(Predicate<Task> callback, boolean traverseTopToBottom) { |
| 1522 | if (traverseTopToBottom) { |
| 1523 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1524 | final Task t = mChildren.get(i).getTask(callback, traverseTopToBottom); |
| 1525 | if (t != null) { |
| 1526 | return t; |
| 1527 | } |
| 1528 | } |
| 1529 | } else { |
| 1530 | final int count = mChildren.size(); |
| 1531 | for (int i = 0; i < count; i++) { |
| 1532 | final Task t = mChildren.get(i).getTask(callback, traverseTopToBottom); |
| 1533 | if (t != null) { |
| 1534 | return t; |
| 1535 | } |
| 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | return null; |
| 1540 | } |
| 1541 | |
lumark | bc0032a | 2019-11-01 21:38:13 +0800 | [diff] [blame] | 1542 | /** |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1543 | * Gets an task in a branch of the tree. |
lumark | bc0032a | 2019-11-01 21:38:13 +0800 | [diff] [blame] | 1544 | * |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1545 | * @param callback called to test if this is the task that should be returned. |
| 1546 | * @param boundary We don't return tasks via {@param callback} until we get to this node in |
| 1547 | * the tree. |
| 1548 | * @param includeBoundary If the boundary from be processed to return tasks. |
| 1549 | * @param traverseTopToBottom direction to traverse the tree. |
| 1550 | * @return The task if found or null. |
lumark | bc0032a | 2019-11-01 21:38:13 +0800 | [diff] [blame] | 1551 | */ |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1552 | final Task getTask(Predicate<Task> callback, WindowContainer boundary, boolean includeBoundary, |
| 1553 | boolean traverseTopToBottom) { |
| 1554 | return getTask(callback, boundary, includeBoundary, traverseTopToBottom, new boolean[1]); |
| 1555 | } |
| 1556 | |
| 1557 | private Task getTask(Predicate<Task> callback, |
| 1558 | WindowContainer boundary, boolean includeBoundary, boolean traverseTopToBottom, |
| 1559 | boolean[] boundaryFound) { |
| 1560 | if (traverseTopToBottom) { |
| 1561 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1562 | final Task t = processGetTaskWithBoundary(callback, boundary, |
| 1563 | includeBoundary, traverseTopToBottom, boundaryFound, mChildren.get(i)); |
| 1564 | if (t != null) { |
| 1565 | return t; |
| 1566 | } |
| 1567 | } |
| 1568 | } else { |
| 1569 | final int count = mChildren.size(); |
| 1570 | for (int i = 0; i < count; i++) { |
| 1571 | final Task t = processGetTaskWithBoundary(callback, boundary, |
| 1572 | includeBoundary, traverseTopToBottom, boundaryFound, mChildren.get(i)); |
| 1573 | if (t != null) { |
| 1574 | return t; |
| 1575 | } |
lumark | bc0032a | 2019-11-01 21:38:13 +0800 | [diff] [blame] | 1576 | } |
| 1577 | } |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 1578 | |
| 1579 | return null; |
| 1580 | } |
| 1581 | |
| 1582 | private Task processGetTaskWithBoundary(Predicate<Task> callback, |
| 1583 | WindowContainer boundary, boolean includeBoundary, boolean traverseTopToBottom, |
| 1584 | boolean[] boundaryFound, WindowContainer wc) { |
| 1585 | if (wc == boundary || boundary == null) { |
| 1586 | boundaryFound[0] = true; |
| 1587 | if (!includeBoundary) return null; |
| 1588 | } |
| 1589 | |
| 1590 | if (boundaryFound[0]) { |
| 1591 | return wc.getTask(callback, traverseTopToBottom); |
| 1592 | } |
| 1593 | |
| 1594 | return wc.getTask( |
| 1595 | callback, boundary, includeBoundary, traverseTopToBottom, boundaryFound); |
lumark | bc0032a | 2019-11-01 21:38:13 +0800 | [diff] [blame] | 1596 | } |
| 1597 | |
Wale Ogunwale | d188096 | 2016-11-08 10:31:59 -0800 | [diff] [blame] | 1598 | WindowState getWindow(Predicate<WindowState> callback) { |
| 1599 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
| 1600 | final WindowState w = mChildren.get(i).getWindow(callback); |
| 1601 | if (w != null) { |
| 1602 | return w; |
| 1603 | } |
| 1604 | } |
| 1605 | |
| 1606 | return null; |
| 1607 | } |
| 1608 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1609 | /** |
Wale Ogunwale | f619286 | 2016-09-10 13:42:30 -0700 | [diff] [blame] | 1610 | * Returns 1, 0, or -1 depending on if this container is greater than, equal to, or lesser than |
| 1611 | * the input container in terms of z-order. |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1612 | */ |
| 1613 | @Override |
| 1614 | public int compareTo(WindowContainer other) { |
| 1615 | if (this == other) { |
| 1616 | return 0; |
| 1617 | } |
| 1618 | |
| 1619 | if (mParent != null && mParent == other.mParent) { |
Jorim Jaggi | 612bb88 | 2017-05-16 17:11:18 +0200 | [diff] [blame] | 1620 | final WindowList<WindowContainer> list = mParent.mChildren; |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1621 | return list.indexOf(this) > list.indexOf(other) ? 1 : -1; |
| 1622 | } |
| 1623 | |
| 1624 | final LinkedList<WindowContainer> thisParentChain = mTmpChain1; |
| 1625 | final LinkedList<WindowContainer> otherParentChain = mTmpChain2; |
Jorim Jaggi | 4448e1e | 2017-05-16 22:26:02 +0200 | [diff] [blame] | 1626 | try { |
| 1627 | getParents(thisParentChain); |
| 1628 | other.getParents(otherParentChain); |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1629 | |
Jorim Jaggi | 4448e1e | 2017-05-16 22:26:02 +0200 | [diff] [blame] | 1630 | // Find the common ancestor of both containers. |
| 1631 | WindowContainer commonAncestor = null; |
| 1632 | WindowContainer thisTop = thisParentChain.peekLast(); |
| 1633 | WindowContainer otherTop = otherParentChain.peekLast(); |
| 1634 | while (thisTop != null && otherTop != null && thisTop == otherTop) { |
| 1635 | commonAncestor = thisParentChain.removeLast(); |
| 1636 | otherParentChain.removeLast(); |
| 1637 | thisTop = thisParentChain.peekLast(); |
| 1638 | otherTop = otherParentChain.peekLast(); |
| 1639 | } |
| 1640 | |
| 1641 | // Containers don't belong to the same hierarchy??? |
| 1642 | if (commonAncestor == null) { |
| 1643 | throw new IllegalArgumentException("No in the same hierarchy this=" |
| 1644 | + thisParentChain + " other=" + otherParentChain); |
| 1645 | } |
| 1646 | |
| 1647 | // Children are always considered greater than their parents, so if one of the containers |
| 1648 | // we are comparing it the parent of the other then whichever is the child is greater. |
| 1649 | if (commonAncestor == this) { |
| 1650 | return -1; |
| 1651 | } else if (commonAncestor == other) { |
| 1652 | return 1; |
| 1653 | } |
| 1654 | |
| 1655 | // The position of the first non-common ancestor in the common ancestor list determines |
| 1656 | // which is greater the which. |
| 1657 | final WindowList<WindowContainer> list = commonAncestor.mChildren; |
| 1658 | return list.indexOf(thisParentChain.peekLast()) > list.indexOf(otherParentChain.peekLast()) |
| 1659 | ? 1 : -1; |
| 1660 | } finally { |
| 1661 | mTmpChain1.clear(); |
| 1662 | mTmpChain2.clear(); |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1663 | } |
Wale Ogunwale | 63d4ecc | 2016-09-08 18:48:26 -0700 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | private void getParents(LinkedList<WindowContainer> parents) { |
| 1667 | parents.clear(); |
| 1668 | WindowContainer current = this; |
| 1669 | do { |
| 1670 | parents.addLast(current); |
| 1671 | current = current.mParent; |
| 1672 | } while (current != null); |
| 1673 | } |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1674 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1675 | SurfaceControl.Builder makeSurface() { |
| 1676 | final WindowContainer p = getParent(); |
| 1677 | return p.makeChildSurface(this); |
| 1678 | } |
| 1679 | |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 1680 | /** |
| 1681 | * @param child The WindowContainer this child surface is for, or null if the Surface |
| 1682 | * is not assosciated with a WindowContainer (e.g. a surface used for Dimming). |
| 1683 | */ |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1684 | SurfaceControl.Builder makeChildSurface(WindowContainer child) { |
| 1685 | final WindowContainer p = getParent(); |
| 1686 | // Give the parent a chance to set properties. In hierarchy v1 we rely |
| 1687 | // on this to set full-screen dimensions on all our Surface-less Layers. |
Robert Carr | ee4d4b9 | 2017-11-22 12:21:46 -0800 | [diff] [blame] | 1688 | return p.makeChildSurface(child) |
| 1689 | .setParent(mSurfaceControl); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1690 | } |
Robert Carr | dea7bf4 | 2019-04-04 12:02:51 -0700 | [diff] [blame] | 1691 | /* |
| 1692 | * @return The SurfaceControl parent for this containers SurfaceControl. |
| 1693 | * The SurfaceControl must be valid if non-null. |
| 1694 | */ |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1695 | @Override |
| 1696 | public SurfaceControl getParentSurfaceControl() { |
| 1697 | final WindowContainer parent = getParent(); |
| 1698 | if (parent == null) { |
| 1699 | return null; |
| 1700 | } |
| 1701 | return parent.getSurfaceControl(); |
| 1702 | } |
| 1703 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1704 | /** |
| 1705 | * @return Whether this WindowContainer should be magnified by the accessibility magnifier. |
| 1706 | */ |
| 1707 | boolean shouldMagnify() { |
Yuki Awano | 4c36b55 | 2018-04-24 17:27:50 +0900 | [diff] [blame] | 1708 | if (mSurfaceControl == null) { |
| 1709 | return false; |
| 1710 | } |
| 1711 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1712 | for (int i = 0; i < mChildren.size(); i++) { |
| 1713 | if (!mChildren.get(i).shouldMagnify()) { |
| 1714 | return false; |
| 1715 | } |
| 1716 | } |
| 1717 | return true; |
| 1718 | } |
| 1719 | |
| 1720 | SurfaceSession getSession() { |
| 1721 | if (getParent() != null) { |
| 1722 | return getParent().getSession(); |
| 1723 | } |
| 1724 | return null; |
| 1725 | } |
| 1726 | |
| 1727 | void assignLayer(Transaction t, int layer) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1728 | final boolean changed = layer != mLastLayer || mLastRelativeToLayer != null; |
| 1729 | if (mSurfaceControl != null && changed) { |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 1730 | setLayer(t, layer); |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1731 | mLastLayer = layer; |
| 1732 | mLastRelativeToLayer = null; |
| 1733 | } |
| 1734 | } |
| 1735 | |
| 1736 | void assignRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) { |
| 1737 | final boolean changed = layer != mLastLayer || mLastRelativeToLayer != relativeTo; |
| 1738 | if (mSurfaceControl != null && changed) { |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 1739 | setRelativeLayer(t, relativeTo, layer); |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1740 | mLastLayer = layer; |
| 1741 | mLastRelativeToLayer = relativeTo; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1742 | } |
| 1743 | } |
| 1744 | |
Jorim Jaggi | 619c9f7 | 2017-12-19 18:04:29 +0100 | [diff] [blame] | 1745 | protected void setLayer(Transaction t, int layer) { |
| 1746 | |
| 1747 | // Route through surface animator to accommodate that our surface control might be |
| 1748 | // attached to the leash, and leash is attached to parent container. |
| 1749 | mSurfaceAnimator.setLayer(t, layer); |
| 1750 | } |
| 1751 | |
| 1752 | protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) { |
| 1753 | |
| 1754 | // Route through surface animator to accommodate that our surface control might be |
| 1755 | // attached to the leash, and leash is attached to parent container. |
| 1756 | mSurfaceAnimator.setRelativeLayer(t, relativeTo, layer); |
| 1757 | } |
| 1758 | |
| 1759 | protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) { |
| 1760 | mSurfaceAnimator.reparent(t, newParent); |
| 1761 | } |
| 1762 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1763 | void assignChildLayers(Transaction t) { |
| 1764 | int layer = 0; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1765 | |
| 1766 | // We use two passes as a way to promote children which |
| 1767 | // need Z-boosting to the end of the list. |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1768 | for (int j = 0; j < mChildren.size(); ++j) { |
| 1769 | final WindowContainer wc = mChildren.get(j); |
| 1770 | wc.assignChildLayers(t); |
| 1771 | if (!wc.needsZBoost()) { |
| 1772 | wc.assignLayer(t, layer++); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1773 | } |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1774 | } |
| 1775 | for (int j = 0; j < mChildren.size(); ++j) { |
| 1776 | final WindowContainer wc = mChildren.get(j); |
| 1777 | if (wc.needsZBoost()) { |
| 1778 | wc.assignLayer(t, layer++); |
| 1779 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1780 | } |
| 1781 | } |
| 1782 | |
| 1783 | void assignChildLayers() { |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 1784 | assignChildLayers(getPendingTransaction()); |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1785 | scheduleAnimation(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | boolean needsZBoost() { |
| 1789 | for (int i = 0; i < mChildren.size(); i++) { |
| 1790 | if (mChildren.get(i).needsZBoost()) { |
| 1791 | return true; |
| 1792 | } |
| 1793 | } |
| 1794 | return false; |
| 1795 | } |
| 1796 | |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 1797 | /** |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1798 | * Write to a protocol buffer output stream. Protocol buffer message definition is at |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 1799 | * {@link com.android.server.wm.WindowContainerProto}. |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1800 | * |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 1801 | * @param proto Stream to write the WindowContainer object to. |
| 1802 | * @param fieldId Field Id of the WindowContainer as defined in the parent message. |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1803 | * @param logLevel Determines the amount of data to be written to the Protobuf. |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1804 | * @hide |
| 1805 | */ |
| 1806 | @CallSuper |
| 1807 | @Override |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 1808 | public void dumpDebug(ProtoOutputStream proto, long fieldId, |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1809 | @WindowTraceLogLevel int logLevel) { |
| 1810 | boolean isVisible = isVisible(); |
| 1811 | if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible) { |
| 1812 | return; |
| 1813 | } |
| 1814 | |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 1815 | final long token = proto.start(fieldId); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 1816 | super.dumpDebug(proto, CONFIGURATION_CONTAINER, logLevel); |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 1817 | proto.write(ORIENTATION, mOrientation); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1818 | proto.write(VISIBLE, isVisible); |
| 1819 | if (mSurfaceAnimator.isAnimating()) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 1820 | mSurfaceAnimator.dumpDebug(proto, SURFACE_ANIMATOR); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 1821 | } |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 1822 | proto.end(token); |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
Wale Ogunwale | ee41d4a | 2016-11-21 08:41:10 -0800 | [diff] [blame] | 1825 | private ForAllWindowsConsumerWrapper obtainConsumerWrapper(Consumer<WindowState> consumer) { |
| 1826 | ForAllWindowsConsumerWrapper wrapper = mConsumerWrapperPool.acquire(); |
| 1827 | if (wrapper == null) { |
| 1828 | wrapper = new ForAllWindowsConsumerWrapper(); |
| 1829 | } |
| 1830 | wrapper.setConsumer(consumer); |
| 1831 | return wrapper; |
| 1832 | } |
| 1833 | |
| 1834 | private final class ForAllWindowsConsumerWrapper implements ToBooleanFunction<WindowState> { |
| 1835 | |
| 1836 | private Consumer<WindowState> mConsumer; |
| 1837 | |
| 1838 | void setConsumer(Consumer<WindowState> consumer) { |
| 1839 | mConsumer = consumer; |
| 1840 | } |
| 1841 | |
| 1842 | @Override |
| 1843 | public boolean apply(WindowState w) { |
| 1844 | mConsumer.accept(w); |
| 1845 | return false; |
| 1846 | } |
| 1847 | |
| 1848 | void release() { |
| 1849 | mConsumer = null; |
| 1850 | mConsumerWrapperPool.release(this); |
| 1851 | } |
| 1852 | } |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1853 | |
| 1854 | // TODO(b/68336570): Should this really be on WindowContainer since it |
| 1855 | // can only be used on the top-level nodes that aren't animated? |
| 1856 | // (otherwise we would be fighting other callers of setMatrix). |
| 1857 | void applyMagnificationSpec(Transaction t, MagnificationSpec spec) { |
| 1858 | if (shouldMagnify()) { |
| 1859 | t.setMatrix(mSurfaceControl, spec.scale, 0, 0, spec.scale) |
| 1860 | .setPosition(mSurfaceControl, spec.offsetX, spec.offsetY); |
Robert Carr | 7603dea | 2019-07-17 13:16:21 -0700 | [diff] [blame] | 1861 | mLastMagnificationSpec = spec; |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1862 | } else { |
Jackal Guo | a8b3a27 | 2019-12-16 15:24:58 +0800 | [diff] [blame] | 1863 | clearMagnificationSpec(t); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1864 | for (int i = 0; i < mChildren.size(); i++) { |
| 1865 | mChildren.get(i).applyMagnificationSpec(t, spec); |
| 1866 | } |
| 1867 | } |
| 1868 | } |
| 1869 | |
Robert Carr | 7603dea | 2019-07-17 13:16:21 -0700 | [diff] [blame] | 1870 | void clearMagnificationSpec(Transaction t) { |
| 1871 | if (mLastMagnificationSpec != null) { |
| 1872 | t.setMatrix(mSurfaceControl, 1, 0, 0, 1) |
| 1873 | .setPosition(mSurfaceControl, 0, 0); |
| 1874 | } |
| 1875 | mLastMagnificationSpec = null; |
| 1876 | for (int i = 0; i < mChildren.size(); i++) { |
| 1877 | mChildren.get(i).clearMagnificationSpec(t); |
| 1878 | } |
| 1879 | } |
| 1880 | |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1881 | void prepareSurfaces() { |
chaviw | 7f1fa99 | 2018-01-10 13:52:12 -0800 | [diff] [blame] | 1882 | // If a leash has been set when the transaction was committed, then the leash reparent has |
| 1883 | // been committed. |
| 1884 | mCommittedReparentToAnimationLeash = mSurfaceAnimator.hasLeash(); |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1885 | for (int i = 0; i < mChildren.size(); i++) { |
| 1886 | mChildren.get(i).prepareSurfaces(); |
| 1887 | } |
| 1888 | } |
| 1889 | |
| 1890 | /** |
chaviw | 7f1fa99 | 2018-01-10 13:52:12 -0800 | [diff] [blame] | 1891 | * @return true if the reparent to animation leash transaction has been committed, false |
| 1892 | * otherwise. |
| 1893 | */ |
| 1894 | boolean hasCommittedReparentToAnimationLeash() { |
| 1895 | return mCommittedReparentToAnimationLeash; |
| 1896 | } |
| 1897 | |
| 1898 | /** |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 1899 | * Trigger a call to prepareSurfaces from the animation thread, such that pending transactions |
| 1900 | * will be applied. |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1901 | */ |
| 1902 | void scheduleAnimation() { |
| 1903 | if (mParent != null) { |
| 1904 | mParent.scheduleAnimation(); |
| 1905 | } |
| 1906 | } |
| 1907 | |
Robert Carr | dea7bf4 | 2019-04-04 12:02:51 -0700 | [diff] [blame] | 1908 | /** |
| 1909 | * @return The SurfaceControl for this container. |
| 1910 | * The SurfaceControl must be valid if non-null. |
| 1911 | */ |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1912 | @Override |
| 1913 | public SurfaceControl getSurfaceControl() { |
Robert Carr | b1579c8 | 2017-09-05 14:54:47 -0700 | [diff] [blame] | 1914 | return mSurfaceControl; |
| 1915 | } |
| 1916 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1917 | @Override |
| 1918 | public Transaction getPendingTransaction() { |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 1919 | if (mUsingBLASTSyncTransaction) { |
| 1920 | return mBLASTSyncTransaction; |
| 1921 | } |
| 1922 | |
Tiger Huang | ed6794e | 2019-05-07 20:07:59 +0800 | [diff] [blame] | 1923 | final DisplayContent displayContent = getDisplayContent(); |
| 1924 | if (displayContent != null && displayContent != this) { |
| 1925 | return displayContent.getPendingTransaction(); |
| 1926 | } |
| 1927 | // This WindowContainer has not attached to a display yet or this is a DisplayContent, so we |
| 1928 | // let the caller to save the surface operations within the local mPendingTransaction. |
| 1929 | // If this is not a DisplayContent, we will merge it to the pending transaction of its |
| 1930 | // display once it attaches to it. |
Robert Carr | f59b8dd | 2017-10-02 18:58:36 -0700 | [diff] [blame] | 1931 | return mPendingTransaction; |
| 1932 | } |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1933 | |
| 1934 | /** |
| 1935 | * Starts an animation on the container. |
| 1936 | * |
| 1937 | * @param anim The animation to run. |
| 1938 | * @param hidden Whether our container is currently hidden. TODO This should use isVisible at |
| 1939 | * some point but the meaning is too weird to work for all containers. |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 1940 | * @param type The type of animation defined as {@link AnimationType}. |
Issei Suzuki | 2f54184 | 2020-01-09 20:18:29 +0100 | [diff] [blame] | 1941 | * @param animationFinishedCallback The callback being triggered when the animation finishes. |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1942 | */ |
Issei Suzuki | 2f54184 | 2020-01-09 20:18:29 +0100 | [diff] [blame] | 1943 | void startAnimation(Transaction t, AnimationAdapter anim, boolean hidden, |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 1944 | @AnimationType int type, |
| 1945 | @Nullable OnAnimationFinishedCallback animationFinishedCallback) { |
| 1946 | if (DEBUG_ANIM) { |
| 1947 | Slog.v(TAG, "Starting animation on " + this + ": type=" + type + ", anim=" + anim); |
| 1948 | } |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1949 | |
| 1950 | // TODO: This should use isVisible() but because isVisible has a really weird meaning at |
| 1951 | // the moment this doesn't work for all animatable window containers. |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 1952 | mSurfaceAnimator.startAnimation(t, anim, hidden, type, animationFinishedCallback, |
| 1953 | mSurfaceFreezer); |
Issei Suzuki | 2f54184 | 2020-01-09 20:18:29 +0100 | [diff] [blame] | 1954 | } |
| 1955 | |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 1956 | void startAnimation(Transaction t, AnimationAdapter anim, boolean hidden, |
| 1957 | @AnimationType int type) { |
| 1958 | startAnimation(t, anim, hidden, type, null /* animationFinishedCallback */); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1959 | } |
| 1960 | |
Jorim Jaggi | 980c9de | 2017-11-17 01:41:37 +0100 | [diff] [blame] | 1961 | void transferAnimation(WindowContainer from) { |
| 1962 | mSurfaceAnimator.transferAnimation(from.mSurfaceAnimator); |
| 1963 | } |
| 1964 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1965 | void cancelAnimation() { |
| 1966 | mSurfaceAnimator.cancelAnimation(); |
| 1967 | } |
| 1968 | |
| 1969 | @Override |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 1970 | public SurfaceControl getFreezeSnapshotTarget() { |
| 1971 | return null; |
| 1972 | } |
| 1973 | |
| 1974 | @Override |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1975 | public Builder makeAnimationLeash() { |
Vishnu Nair | fd6fb67 | 2020-02-14 12:56:37 -0800 | [diff] [blame] | 1976 | return makeSurface().setContainerLayer(); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 1977 | } |
| 1978 | |
Jorim Jaggi | 596a199 | 2017-12-29 14:48:02 +0100 | [diff] [blame] | 1979 | @Override |
| 1980 | public SurfaceControl getAnimationLeashParent() { |
| 1981 | return getParentSurfaceControl(); |
| 1982 | } |
| 1983 | |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 1984 | /** |
| 1985 | * @return The layer on which all app animations are happening. |
| 1986 | */ |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 1987 | SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) { |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 1988 | final WindowContainer parent = getParent(); |
| 1989 | if (parent != null) { |
Jorim Jaggi | 39179062 | 2018-04-18 15:30:44 +0200 | [diff] [blame] | 1990 | return parent.getAppAnimationLayer(animationLayer); |
chaviw | 23ee71c | 2017-12-18 11:29:41 -0800 | [diff] [blame] | 1991 | } |
| 1992 | return null; |
| 1993 | } |
| 1994 | |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 1995 | // TODO: Remove this and use #getBounds() instead once we set an app transition animation |
| 1996 | // on TaskStack. |
| 1997 | Rect getAnimationBounds(int appStackClipMode) { |
lumark | 8571866 | 2019-12-26 22:05:12 +0800 | [diff] [blame] | 1998 | return getDisplayedBounds(); |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | /** |
| 2002 | * Applies the app transition animation according the given the layout properties in the |
| 2003 | * window hierarchy. |
| 2004 | * |
| 2005 | * @param lp The layout parameters of the window. |
| 2006 | * @param transit The app transition type indicates what kind of transition to be applied. |
| 2007 | * @param enter Whether the app transition is entering transition or not. |
| 2008 | * @param isVoiceInteraction Whether the container is participating in voice interaction or not. |
| 2009 | * |
| 2010 | * @return {@code true} when the container applied the app transition, {@code false} if the |
| 2011 | * app transition is disabled or skipped. |
| 2012 | * |
| 2013 | * @see #getAnimationAdapter |
| 2014 | */ |
| 2015 | boolean applyAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 2016 | boolean isVoiceInteraction, |
| 2017 | @Nullable OnAnimationFinishedCallback animationFinishedCallback) { |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 2018 | if (mWmService.mDisableTransitionAnimation) { |
| 2019 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS_ANIM, |
| 2020 | "applyAnimation: transition animation is disabled or skipped. " |
| 2021 | + "container=%s", this); |
| 2022 | cancelAnimation(); |
| 2023 | return false; |
| 2024 | } |
| 2025 | |
| 2026 | // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason |
| 2027 | // to animate and it can cause strange artifacts when we unfreeze the display if some |
| 2028 | // different animation is running. |
| 2029 | try { |
| 2030 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "WC#applyAnimation"); |
| 2031 | if (okToAnimate()) { |
lumark | bc0032a | 2019-11-01 21:38:13 +0800 | [diff] [blame] | 2032 | final Pair<AnimationAdapter, AnimationAdapter> adapters = getAnimationAdapter(lp, |
| 2033 | transit, enter, isVoiceInteraction); |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 2034 | AnimationAdapter adapter = adapters.first; |
| 2035 | AnimationAdapter thumbnailAdapter = adapters.second; |
| 2036 | if (adapter != null) { |
Issei Suzuki | 2f54184 | 2020-01-09 20:18:29 +0100 | [diff] [blame] | 2037 | startAnimation(getPendingTransaction(), adapter, !isVisible(), |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 2038 | ANIMATION_TYPE_APP_TRANSITION, animationFinishedCallback); |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 2039 | if (adapter.getShowWallpaper()) { |
lumark | 5341d1c | 2019-12-14 01:54:02 +0800 | [diff] [blame] | 2040 | getDisplayContent().pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 2041 | } |
| 2042 | if (thumbnailAdapter != null) { |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 2043 | mSurfaceFreezer.mSnapshot.startAnimation(getPendingTransaction(), |
| 2044 | thumbnailAdapter, ANIMATION_TYPE_APP_TRANSITION, |
| 2045 | (type, anim) -> { }); |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 2046 | } |
| 2047 | } |
| 2048 | } else { |
| 2049 | cancelAnimation(); |
| 2050 | } |
| 2051 | } finally { |
| 2052 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
| 2053 | } |
| 2054 | |
| 2055 | return isAnimating(); |
| 2056 | } |
| 2057 | |
| 2058 | /** |
| 2059 | * Gets the {@link AnimationAdapter} according the given window layout properties in the window |
| 2060 | * hierarchy. |
| 2061 | * |
| 2062 | * @return The return value will always contain two elements, one for normal animations and the |
| 2063 | * other for thumbnail animation, both can be {@code null}. |
| 2064 | * |
| 2065 | * @See com.android.server.wm.RemoteAnimationController.RemoteAnimationRecord |
| 2066 | * @See LocalAnimationAdapter |
| 2067 | */ |
| 2068 | Pair<AnimationAdapter, AnimationAdapter> getAnimationAdapter(WindowManager.LayoutParams lp, |
| 2069 | int transit, boolean enter, boolean isVoiceInteraction) { |
| 2070 | final Pair<AnimationAdapter, AnimationAdapter> resultAdapters; |
| 2071 | final int appStackClipMode = getDisplayContent().mAppTransition.getAppStackClipMode(); |
| 2072 | |
| 2073 | // Separate position and size for use in animators. |
| 2074 | mTmpRect.set(getAnimationBounds(appStackClipMode)); |
lumark | 8571866 | 2019-12-26 22:05:12 +0800 | [diff] [blame] | 2075 | if (sHierarchicalAnimations) { |
| 2076 | getRelativeDisplayedPosition(mTmpPoint); |
| 2077 | } else { |
| 2078 | mTmpPoint.set(mTmpRect.left, mTmpRect.top); |
| 2079 | } |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 2080 | mTmpRect.offsetTo(0, 0); |
| 2081 | |
| 2082 | final RemoteAnimationController controller = |
| 2083 | getDisplayContent().mAppTransition.getRemoteAnimationController(); |
| 2084 | final boolean isChanging = AppTransition.isChangeTransit(transit) && enter |
| 2085 | && isChangingAppTransition(); |
| 2086 | |
| 2087 | // Delaying animation start isn't compatible with remote animations at all. |
| 2088 | if (controller != null && !mSurfaceAnimator.isAnimationStartDelayed()) { |
| 2089 | final RemoteAnimationController.RemoteAnimationRecord adapters = |
| 2090 | controller.createRemoteAnimationRecord(this, mTmpPoint, mTmpRect, |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 2091 | (isChanging ? mSurfaceFreezer.mFreezeBounds : null)); |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 2092 | resultAdapters = new Pair<>(adapters.mAdapter, adapters.mThumbnailAdapter); |
| 2093 | } else if (isChanging) { |
| 2094 | final float durationScale = mWmService.getTransitionAnimationScaleLocked(); |
| 2095 | final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo(); |
| 2096 | mTmpRect.offsetTo(mTmpPoint.x, mTmpPoint.y); |
| 2097 | |
lumark | bc0032a | 2019-11-01 21:38:13 +0800 | [diff] [blame] | 2098 | final AnimationAdapter adapter = new LocalAnimationAdapter( |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 2099 | new WindowChangeAnimationSpec(mSurfaceFreezer.mFreezeBounds, mTmpRect, |
| 2100 | displayInfo, durationScale, true /* isAppAnimation */, |
| 2101 | false /* isThumbnail */), |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 2102 | getSurfaceAnimationRunner()); |
| 2103 | |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 2104 | final AnimationAdapter thumbnailAdapter = mSurfaceFreezer.mSnapshot != null |
| 2105 | ? new LocalAnimationAdapter(new WindowChangeAnimationSpec( |
| 2106 | mSurfaceFreezer.mFreezeBounds, mTmpRect, displayInfo, durationScale, |
| 2107 | true /* isAppAnimation */, true /* isThumbnail */), getSurfaceAnimationRunner()) |
lumark | bc0032a | 2019-11-01 21:38:13 +0800 | [diff] [blame] | 2108 | : null; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 2109 | resultAdapters = new Pair<>(adapter, thumbnailAdapter); |
| 2110 | mTransit = transit; |
| 2111 | mTransitFlags = getDisplayContent().mAppTransition.getTransitFlags(); |
| 2112 | } else { |
| 2113 | mNeedsAnimationBoundsLayer = (appStackClipMode == STACK_CLIP_AFTER_ANIM); |
| 2114 | final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction); |
| 2115 | |
| 2116 | if (a != null) { |
| 2117 | // Only apply corner radius to animation if we're not in multi window mode. |
| 2118 | // We don't want rounded corners when in pip or split screen. |
| 2119 | final float windowCornerRadius = !inMultiWindowMode() |
| 2120 | ? getDisplayContent().getWindowCornerRadius() |
| 2121 | : 0; |
| 2122 | AnimationAdapter adapter = new LocalAnimationAdapter( |
| 2123 | new WindowAnimationSpec(a, mTmpPoint, mTmpRect, |
| 2124 | getDisplayContent().mAppTransition.canSkipFirstFrame(), |
| 2125 | appStackClipMode, true /* isAppAnimation */, windowCornerRadius), |
| 2126 | getSurfaceAnimationRunner()); |
| 2127 | |
| 2128 | resultAdapters = new Pair<>(adapter, null); |
| 2129 | mNeedsZBoost = a.getZAdjustment() == Animation.ZORDER_TOP; |
| 2130 | mTransit = transit; |
| 2131 | mTransitFlags = getDisplayContent().mAppTransition.getTransitFlags(); |
| 2132 | } else { |
| 2133 | resultAdapters = new Pair<>(null, null); |
| 2134 | } |
| 2135 | } |
| 2136 | return resultAdapters; |
| 2137 | } |
| 2138 | |
| 2139 | final SurfaceAnimationRunner getSurfaceAnimationRunner() { |
| 2140 | return mWmService.mSurfaceAnimationRunner; |
| 2141 | } |
| 2142 | |
| 2143 | private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter, |
| 2144 | boolean isVoiceInteraction) { |
| 2145 | final DisplayContent displayContent = getDisplayContent(); |
| 2146 | final DisplayInfo displayInfo = displayContent.getDisplayInfo(); |
| 2147 | final int width = displayInfo.appWidth; |
| 2148 | final int height = displayInfo.appHeight; |
| 2149 | ProtoLog.v(WM_DEBUG_APP_TRANSITIONS_ANIM, "applyAnimation: container=%s", this); |
| 2150 | |
| 2151 | // Determine the visible rect to calculate the thumbnail clip with |
| 2152 | // getAnimationFrames. |
| 2153 | final Rect frame = new Rect(0, 0, width, height); |
| 2154 | final Rect displayFrame = new Rect(0, 0, |
| 2155 | displayInfo.logicalWidth, displayInfo.logicalHeight); |
| 2156 | final Rect insets = new Rect(); |
| 2157 | final Rect stableInsets = new Rect(); |
| 2158 | final Rect surfaceInsets = new Rect(); |
| 2159 | getAnimationFrames(frame, insets, stableInsets, surfaceInsets); |
| 2160 | |
| 2161 | if (mLaunchTaskBehind) { |
| 2162 | // Differentiate the two animations. This one which is briefly on the screen |
| 2163 | // gets the !enter animation, and the other one which remains on the |
| 2164 | // screen gets the enter animation. Both appear in the mOpeningApps set. |
| 2165 | enter = false; |
| 2166 | } |
| 2167 | ProtoLog.d(WM_DEBUG_APP_TRANSITIONS, |
| 2168 | "Loading animation for app transition. transit=%s enter=%b frame=%s insets=%s " |
| 2169 | + "surfaceInsets=%s", |
| 2170 | AppTransition.appTransitionToString(transit), enter, frame, insets, surfaceInsets); |
| 2171 | final Configuration displayConfig = displayContent.getConfiguration(); |
| 2172 | final Animation a = getDisplayContent().mAppTransition.loadAnimation(lp, transit, enter, |
| 2173 | displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets, |
| 2174 | surfaceInsets, stableInsets, isVoiceInteraction, inFreeformWindowingMode(), this); |
| 2175 | if (a != null) { |
lumark | 8669ef3 | 2020-02-10 18:41:57 +0800 | [diff] [blame] | 2176 | if (a != null) { |
| 2177 | // Setup the maximum app transition duration to prevent malicious app may set a long |
| 2178 | // animation duration or infinite repeat counts for the app transition through |
| 2179 | // ActivityOption#makeCustomAnimation or WindowManager#overridePendingTransition. |
| 2180 | a.restrictDuration(MAX_APP_TRANSITION_DURATION); |
| 2181 | } |
| 2182 | if (DEBUG_ANIM) { |
| 2183 | logWithStack(TAG, "Loaded animation " + a + " for " + this |
| 2184 | + ", duration: " + ((a != null) ? a.getDuration() : 0)); |
| 2185 | } |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 2186 | final int containingWidth = frame.width(); |
| 2187 | final int containingHeight = frame.height(); |
| 2188 | a.initialize(containingWidth, containingHeight, width, height); |
| 2189 | a.scaleCurrentDuration(mWmService.getTransitionAnimationScaleLocked()); |
| 2190 | } |
| 2191 | return a; |
| 2192 | } |
| 2193 | |
| 2194 | RemoteAnimationTarget createRemoteAnimationTarget( |
| 2195 | RemoteAnimationController.RemoteAnimationRecord record) { |
| 2196 | return null; |
| 2197 | } |
| 2198 | |
| 2199 | boolean okToDisplay() { |
lumark | 5341d1c | 2019-12-14 01:54:02 +0800 | [diff] [blame] | 2200 | final DisplayContent dc = getDisplayContent(); |
| 2201 | return dc != null && dc.okToDisplay(); |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | boolean okToAnimate() { |
lumark | 3b8bbc8 | 2019-12-02 16:22:08 +0800 | [diff] [blame] | 2205 | return okToAnimate(false /* ignoreFrozen */); |
| 2206 | } |
| 2207 | |
| 2208 | boolean okToAnimate(boolean ignoreFrozen) { |
lumark | 5341d1c | 2019-12-14 01:54:02 +0800 | [diff] [blame] | 2209 | final DisplayContent dc = getDisplayContent(); |
| 2210 | return dc != null && dc.okToAnimate(ignoreFrozen); |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 2211 | } |
| 2212 | |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 2213 | @Override |
| 2214 | public void commitPendingTransaction() { |
| 2215 | scheduleAnimation(); |
| 2216 | } |
| 2217 | |
Robert Carr | 2f8aa39 | 2018-01-31 14:46:51 -0800 | [diff] [blame] | 2218 | void reassignLayer(Transaction t) { |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 2219 | final WindowContainer parent = getParent(); |
| 2220 | if (parent != null) { |
| 2221 | parent.assignChildLayers(t); |
| 2222 | } |
| 2223 | } |
| 2224 | |
| 2225 | @Override |
| 2226 | public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) { |
Robert Carr | f12f9d3 | 2018-03-01 15:24:36 -0800 | [diff] [blame] | 2227 | mLastLayer = -1; |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 2228 | reassignLayer(t); |
| 2229 | } |
| 2230 | |
| 2231 | @Override |
lumark | f6f3494 | 2019-04-29 16:56:50 +0800 | [diff] [blame] | 2232 | public void onAnimationLeashLost(Transaction t) { |
Robert Carr | f12f9d3 | 2018-03-01 15:24:36 -0800 | [diff] [blame] | 2233 | mLastLayer = -1; |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 2234 | mSurfaceFreezer.unfreeze(t); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 2235 | reassignLayer(t); |
| 2236 | } |
| 2237 | |
| 2238 | /** |
| 2239 | * Called when an animation has finished running. |
| 2240 | */ |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 2241 | protected void onAnimationFinished(@AnimationType int type, AnimationAdapter anim) { |
chaviw | ccd5d50 | 2019-02-22 13:30:31 -0800 | [diff] [blame] | 2242 | mWmService.onAnimationFinished(); |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 2243 | } |
| 2244 | |
| 2245 | /** |
| 2246 | * @return The currently running animation, if any, or {@code null} otherwise. |
| 2247 | */ |
| 2248 | AnimationAdapter getAnimation() { |
| 2249 | return mSurfaceAnimator.getAnimation(); |
| 2250 | } |
| 2251 | |
| 2252 | /** |
lumark | 5bd11af | 2019-12-21 01:52:28 +0800 | [diff] [blame] | 2253 | * @return The {@link WindowContainer} which is running an animation. |
| 2254 | * |
| 2255 | * It traverses from the current container to its parents recursively. If nothing is animating, |
| 2256 | * it will return {@code null}. |
| 2257 | */ |
| 2258 | @Nullable |
| 2259 | WindowContainer getAnimatingContainer() { |
| 2260 | if (isAnimating()) { |
| 2261 | return this; |
| 2262 | } |
| 2263 | final WindowContainer parent = getParent(); |
| 2264 | return (parent != null) ? parent.getAnimatingContainer() : null; |
| 2265 | } |
| 2266 | |
| 2267 | /** |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 2268 | * @see SurfaceAnimator#startDelayingAnimationStart |
| 2269 | */ |
| 2270 | void startDelayingAnimationStart() { |
| 2271 | mSurfaceAnimator.startDelayingAnimationStart(); |
| 2272 | } |
| 2273 | |
| 2274 | /** |
| 2275 | * @see SurfaceAnimator#endDelayingAnimationStart |
| 2276 | */ |
| 2277 | void endDelayingAnimationStart() { |
| 2278 | mSurfaceAnimator.endDelayingAnimationStart(); |
| 2279 | } |
| 2280 | |
| 2281 | @Override |
| 2282 | public int getSurfaceWidth() { |
| 2283 | return mSurfaceControl.getWidth(); |
| 2284 | } |
| 2285 | |
| 2286 | @Override |
| 2287 | public int getSurfaceHeight() { |
| 2288 | return mSurfaceControl.getHeight(); |
| 2289 | } |
| 2290 | |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 2291 | @CallSuper |
Jorim Jaggi | a5e1057 | 2017-11-15 14:36:26 +0100 | [diff] [blame] | 2292 | void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
| 2293 | if (mSurfaceAnimator.isAnimating()) { |
| 2294 | pw.print(prefix); pw.println("ContainerAnimator:"); |
| 2295 | mSurfaceAnimator.dump(pw, prefix + " "); |
| 2296 | } |
| 2297 | } |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 2298 | |
chaviw | 2f0567b | 2018-01-29 16:22:02 -0800 | [diff] [blame] | 2299 | void updateSurfacePosition() { |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 2300 | if (mSurfaceControl == null) { |
| 2301 | return; |
| 2302 | } |
| 2303 | |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 2304 | getRelativeDisplayedPosition(mTmpPos); |
chaviw | 3e751af | 2018-01-11 11:22:39 -0800 | [diff] [blame] | 2305 | if (mTmpPos.equals(mLastSurfacePosition)) { |
| 2306 | return; |
| 2307 | } |
| 2308 | |
chaviw | 2f0567b | 2018-01-29 16:22:02 -0800 | [diff] [blame] | 2309 | getPendingTransaction().setPosition(mSurfaceControl, mTmpPos.x, mTmpPos.y); |
chaviw | 3e751af | 2018-01-11 11:22:39 -0800 | [diff] [blame] | 2310 | mLastSurfacePosition.set(mTmpPos.x, mTmpPos.y); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 2311 | } |
| 2312 | |
Evan Rosky | 65dffa6 | 2019-02-04 14:09:53 -0800 | [diff] [blame] | 2313 | @VisibleForTesting |
Evan Rosky | 89f5c1d | 2019-01-29 10:04:05 -0800 | [diff] [blame] | 2314 | Point getLastSurfacePosition() { |
| 2315 | return mLastSurfacePosition; |
| 2316 | } |
| 2317 | |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 2318 | /** |
| 2319 | * Displayed bounds specify where to display this container at. It differs from bounds during |
| 2320 | * certain operations (like animation or interactive dragging). |
| 2321 | * |
| 2322 | * @return the bounds to display this container at. |
| 2323 | */ |
| 2324 | Rect getDisplayedBounds() { |
| 2325 | return getBounds(); |
| 2326 | } |
| 2327 | |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 2328 | /** |
| 2329 | * The {@code outFrame} retrieved by this method specifies where the animation will finish |
| 2330 | * the entrance animation, as the next frame will display the window at these coordinates. In |
| 2331 | * case of exit animation, this is where the animation will start, as the frame before the |
| 2332 | * animation is displaying the window at these bounds. |
| 2333 | * |
| 2334 | * @param outFrame The bounds where entrance animation finishes or exit animation starts. |
| 2335 | * @param outInsets Insets that are covered by system windows. |
| 2336 | * @param outStableInsets Insets that determine the area covered by the stable system windows. |
| 2337 | * @param outSurfaceInsets Positive insets between the drawing surface and window content. |
| 2338 | */ |
| 2339 | void getAnimationFrames(Rect outFrame, Rect outInsets, Rect outStableInsets, |
| 2340 | Rect outSurfaceInsets) { |
| 2341 | final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo(); |
| 2342 | outFrame.set(0, 0, displayInfo.appWidth, displayInfo.appHeight); |
| 2343 | outInsets.setEmpty(); |
| 2344 | outStableInsets.setEmpty(); |
| 2345 | outSurfaceInsets.setEmpty(); |
| 2346 | } |
| 2347 | |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 2348 | void getRelativeDisplayedPosition(Point outPos) { |
| 2349 | final Rect dispBounds = getDisplayedBounds(); |
| 2350 | outPos.set(dispBounds.left, dispBounds.top); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 2351 | final WindowContainer parent = getParent(); |
| 2352 | if (parent != null) { |
Evan Rosky | ed6767f | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 2353 | final Rect parentBounds = parent.getDisplayedBounds(); |
chaviw | e07246a | 2017-12-12 16:18:29 -0800 | [diff] [blame] | 2354 | outPos.offset(-parentBounds.left, -parentBounds.top); |
| 2355 | } |
| 2356 | } |
chaviw | 2fb06bc | 2018-01-19 17:09:15 -0800 | [diff] [blame] | 2357 | |
Yunfan Chen | 87b5a24 | 2019-10-01 17:53:59 +0900 | [diff] [blame] | 2358 | void waitForAllWindowsDrawn() { |
Yunfan Chen | 87b5a24 | 2019-10-01 17:53:59 +0900 | [diff] [blame] | 2359 | forAllWindows(w -> { |
Riddle Hsu | 5df3b75 | 2019-12-16 13:27:37 -0600 | [diff] [blame] | 2360 | w.requestDrawIfNeeded(mWaitingForDrawn); |
Yunfan Chen | 87b5a24 | 2019-10-01 17:53:59 +0900 | [diff] [blame] | 2361 | }, true /* traverseTopToBottom */); |
| 2362 | } |
| 2363 | |
chaviw | 2fb06bc | 2018-01-19 17:09:15 -0800 | [diff] [blame] | 2364 | Dimmer getDimmer() { |
| 2365 | if (mParent == null) { |
| 2366 | return null; |
| 2367 | } |
| 2368 | return mParent.getDimmer(); |
| 2369 | } |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 2370 | |
| 2371 | void setSurfaceControl(SurfaceControl sc) { |
| 2372 | mSurfaceControl = sc; |
| 2373 | } |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 2374 | |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 2375 | RemoteAnimationDefinition getRemoteAnimationDefinition() { |
| 2376 | return null; |
| 2377 | } |
| 2378 | |
Wale Ogunwale | 8f93b64 | 2019-12-26 12:10:52 -0800 | [diff] [blame] | 2379 | /** Cheap way of doing cast and instanceof. */ |
| 2380 | Task asTask() { |
| 2381 | return null; |
| 2382 | } |
| 2383 | |
| 2384 | /** Cheap way of doing cast and instanceof. */ |
| 2385 | ActivityRecord asActivityRecord() { |
| 2386 | return null; |
| 2387 | } |
Evan Rosky | a80f11c | 2020-01-23 19:17:10 -0800 | [diff] [blame] | 2388 | |
| 2389 | RemoteToken getRemoteToken() { |
| 2390 | return mRemoteToken; |
| 2391 | } |
| 2392 | |
Evan Rosky | a8fde15 | 2020-01-07 19:09:13 -0800 | [diff] [blame] | 2393 | static WindowContainer fromBinder(IBinder binder) { |
| 2394 | return RemoteToken.fromBinder(binder).getContainer(); |
| 2395 | } |
| 2396 | |
Evan Rosky | a80f11c | 2020-01-23 19:17:10 -0800 | [diff] [blame] | 2397 | static class RemoteToken extends IWindowContainer.Stub { |
| 2398 | final WeakReference<WindowContainer> mWeakRef; |
| 2399 | |
| 2400 | RemoteToken(WindowContainer container) { |
| 2401 | mWeakRef = new WeakReference<>(container); |
| 2402 | } |
| 2403 | |
| 2404 | WindowContainer getContainer() { |
| 2405 | return mWeakRef.get(); |
| 2406 | } |
| 2407 | |
| 2408 | static RemoteToken fromBinder(IBinder binder) { |
| 2409 | return (RemoteToken) binder; |
| 2410 | } |
| 2411 | |
| 2412 | @Override |
| 2413 | public SurfaceControl getLeash() { |
| 2414 | throw new RuntimeException("Not implemented"); |
| 2415 | } |
| 2416 | |
| 2417 | @Override |
| 2418 | public String toString() { |
| 2419 | StringBuilder sb = new StringBuilder(128); |
| 2420 | sb.append("RemoteToken{"); |
| 2421 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 2422 | sb.append(' '); |
| 2423 | sb.append(mWeakRef.get()); |
| 2424 | sb.append('}'); |
| 2425 | return sb.toString(); |
| 2426 | } |
| 2427 | } |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 2428 | |
| 2429 | @Override |
| 2430 | public void transactionReady(int mSyncId, SurfaceControl.Transaction mergedTransaction) { |
| 2431 | mergedTransaction.merge(mBLASTSyncTransaction); |
| 2432 | mUsingBLASTSyncTransaction = false; |
| 2433 | |
| 2434 | mWaitingListener.transactionReady(mWaitingSyncId, mergedTransaction); |
| 2435 | |
| 2436 | mWaitingListener = null; |
| 2437 | mWaitingSyncId = -1; |
| 2438 | } |
| 2439 | |
| 2440 | boolean prepareForSync(BLASTSyncEngine.TransactionReadyListener waitingListener, |
| 2441 | int waitingId) { |
| 2442 | boolean willSync = false; |
| 2443 | if (!isVisible()) { |
| 2444 | return willSync; |
| 2445 | } |
| 2446 | mUsingBLASTSyncTransaction = true; |
| 2447 | |
| 2448 | int localId = mBLASTSyncEngine.startSyncSet(this); |
| 2449 | for (int i = 0; i < mChildren.size(); i++) { |
| 2450 | final WindowContainer child = mChildren.get(i); |
| 2451 | willSync = mBLASTSyncEngine.addToSyncSet(localId, child) | willSync; |
| 2452 | } |
| 2453 | |
| 2454 | // Make sure to set these before we call setReady in case the sync was a no-op |
| 2455 | mWaitingSyncId = waitingId; |
| 2456 | mWaitingListener = waitingListener; |
| 2457 | |
| 2458 | mBLASTSyncEngine.setReady(localId); |
| 2459 | |
| 2460 | return willSync; |
| 2461 | } |
Wale Ogunwale | d63594a | 2016-07-18 07:48:30 -0700 | [diff] [blame] | 2462 | } |