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