Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wm; |
| 18 | |
Charles Chen | 4bff5be | 2020-03-11 10:17:19 +0800 | [diff] [blame] | 19 | import static android.os.Process.INVALID_UID; |
Andrii Kulian | 02c0e4d | 2020-01-27 22:17:31 -0800 | [diff] [blame] | 20 | import static android.view.Display.INVALID_DISPLAY; |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 21 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
Riddle Hsu | d490c57 | 2020-04-17 01:39:27 +0800 | [diff] [blame] | 22 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 23 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
Robert Carr | 683e05d | 2018-04-18 15:11:04 -0700 | [diff] [blame] | 24 | import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; |
Louis Chang | 7501e33 | 2018-08-20 13:08:39 +0800 | [diff] [blame] | 25 | |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 26 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_ADD_REMOVE; |
| 27 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_FOCUS; |
| 28 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_WINDOW_MOVEMENT; |
Andrii Kulian | 02c0e4d | 2020-01-27 22:17:31 -0800 | [diff] [blame] | 29 | import static com.android.server.wm.ProtoLogGroup.WM_ERROR; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 30 | import static com.android.server.wm.WindowContainer.AnimationFlags.CHILDREN; |
| 31 | import static com.android.server.wm.WindowContainer.AnimationFlags.PARENTS; |
| 32 | import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION; |
Vishnu Nair | dddc9f5 | 2020-03-09 09:37:27 -0700 | [diff] [blame] | 33 | import static com.android.server.wm.WindowContainerChildProto.WINDOW_TOKEN; |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 34 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 35 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
| 36 | import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 37 | import static com.android.server.wm.WindowTokenProto.HASH_CODE; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 38 | import static com.android.server.wm.WindowTokenProto.PAUSED; |
| 39 | import static com.android.server.wm.WindowTokenProto.WAITING_TO_SHOW; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 40 | import static com.android.server.wm.WindowTokenProto.WINDOW_CONTAINER; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 41 | |
Vishnu Nair | 04ab439 | 2018-01-10 11:00:06 -0800 | [diff] [blame] | 42 | import android.annotation.CallSuper; |
Andrii Kulian | 02c0e4d | 2020-01-27 22:17:31 -0800 | [diff] [blame] | 43 | import android.app.IWindowToken; |
Riddle Hsu | d490c57 | 2020-04-17 01:39:27 +0800 | [diff] [blame] | 44 | import android.app.servertransaction.FixedRotationAdjustmentsItem; |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 45 | import android.content.res.Configuration; |
| 46 | import android.graphics.Rect; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 47 | import android.os.Debug; |
| 48 | import android.os.IBinder; |
Andrii Kulian | 02c0e4d | 2020-01-27 22:17:31 -0800 | [diff] [blame] | 49 | import android.os.RemoteException; |
Charles Chen | 4bff5be | 2020-03-11 10:17:19 +0800 | [diff] [blame] | 50 | import android.util.Slog; |
Vishnu Nair | 04ab439 | 2018-01-10 11:00:06 -0800 | [diff] [blame] | 51 | import android.util.proto.ProtoOutputStream; |
Riddle Hsu | d490c57 | 2020-04-17 01:39:27 +0800 | [diff] [blame] | 52 | import android.view.DisplayAdjustments.FixedRotationAdjustments; |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 53 | import android.view.DisplayInfo; |
| 54 | import android.view.InsetsState; |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 55 | import android.view.SurfaceControl; |
Vadim Caen | b46f923 | 2020-02-14 17:54:39 +0100 | [diff] [blame] | 56 | import android.view.WindowManager; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 57 | |
Charles Chen | 525e1e7 | 2020-03-02 15:40:25 +0800 | [diff] [blame] | 58 | import com.android.internal.annotations.VisibleForTesting; |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 59 | import com.android.server.policy.WindowManagerPolicy; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 60 | import com.android.server.protolog.common.ProtoLog; |
| 61 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 62 | import java.io.PrintWriter; |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 63 | import java.util.ArrayList; |
Vishnu Nair | 04ab439 | 2018-01-10 11:00:06 -0800 | [diff] [blame] | 64 | import java.util.Comparator; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 65 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 66 | /** |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 67 | * Container of a set of related windows in the window manager. Often this is an AppWindowToken, |
| 68 | * which is the handle for an Activity that it uses to display windows. For nested windows, there is |
| 69 | * a WindowToken created for the parent window to manage its children. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 70 | */ |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 71 | class WindowToken extends WindowContainer<WindowState> { |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 72 | private static final String TAG = TAG_WITH_CLASS_NAME ? "WindowToken" : TAG_WM; |
| 73 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 74 | // The actual token. |
| 75 | final IBinder token; |
| 76 | |
| 77 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 78 | final int windowType; |
| 79 | |
Adrian Roos | 4bef62e | 2018-03-21 19:52:09 +0100 | [diff] [blame] | 80 | /** {@code true} if this holds the rounded corner overlay */ |
| 81 | final boolean mRoundedCornerOverlay; |
| 82 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 83 | // Set if this token was explicitly added by a client, so should |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 84 | // persist (not be removed) when all windows are removed. |
| 85 | boolean mPersistOnEmpty; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 86 | |
| 87 | // For printing. |
| 88 | String stringName; |
| 89 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 90 | // Is key dispatching paused for this token? |
| 91 | boolean paused = false; |
| 92 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 93 | // Temporary for finding which tokens no longer have visible windows. |
| 94 | boolean hasVisible; |
| 95 | |
| 96 | // Set to true when this token is in a pending transaction where it |
| 97 | // will be shown. |
| 98 | boolean waitingToShow; |
| 99 | |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 100 | /** The owner has {@link android.Manifest.permission#MANAGE_APP_TOKENS} */ |
| 101 | final boolean mOwnerCanManageAppTokens; |
| 102 | |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 103 | private FixedRotationTransformState mFixedRotationTransformState; |
| 104 | |
Andrii Kulian | 02c0e4d | 2020-01-27 22:17:31 -0800 | [diff] [blame] | 105 | private Configuration mLastReportedConfig; |
| 106 | private int mLastReportedDisplay = INVALID_DISPLAY; |
| 107 | |
wilsonshih | 07cb272 | 2020-03-16 23:19:24 +0800 | [diff] [blame] | 108 | /** |
| 109 | * When set to {@code true}, this window token is created from {@link android.app.WindowContext} |
| 110 | */ |
Charles Chen | 525e1e7 | 2020-03-02 15:40:25 +0800 | [diff] [blame] | 111 | @VisibleForTesting |
| 112 | final boolean mFromClientToken; |
Andrii Kulian | 02c0e4d | 2020-01-27 22:17:31 -0800 | [diff] [blame] | 113 | |
Charles Chen | 4bff5be | 2020-03-11 10:17:19 +0800 | [diff] [blame] | 114 | private DeathRecipient mDeathRecipient; |
| 115 | private boolean mBinderDied = false; |
| 116 | |
| 117 | private final int mOwnerUid; |
| 118 | |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 119 | /** |
| 120 | * Used to fix the transform of the token to be rotated to a rotation different than it's |
| 121 | * display. The window frames and surfaces corresponding to this token will be layouted and |
| 122 | * rotated by the given rotated display info, frames and insets. |
| 123 | */ |
| 124 | private static class FixedRotationTransformState { |
| 125 | final DisplayInfo mDisplayInfo; |
| 126 | final DisplayFrames mDisplayFrames; |
| 127 | final InsetsState mInsetsState; |
| 128 | final Configuration mRotatedOverrideConfiguration; |
| 129 | final SeamlessRotator mRotator; |
Riddle Hsu | 6393ad1 | 2020-03-02 23:56:32 +0800 | [diff] [blame] | 130 | /** |
| 131 | * The tokens that share the same transform. Their end time of transform are the same as |
| 132 | * {@link #mOwner}. |
| 133 | */ |
| 134 | final ArrayList<WindowToken> mAssociatedTokens = new ArrayList<>(1); |
| 135 | final ArrayList<WindowContainer<?>> mRotatedContainers = new ArrayList<>(3); |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 136 | boolean mIsTransforming = true; |
| 137 | |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 138 | FixedRotationTransformState(DisplayInfo rotatedDisplayInfo, |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 139 | DisplayFrames rotatedDisplayFrames, InsetsState rotatedInsetsState, |
| 140 | Configuration rotatedConfig, int currentRotation) { |
| 141 | mDisplayInfo = rotatedDisplayInfo; |
| 142 | mDisplayFrames = rotatedDisplayFrames; |
| 143 | mInsetsState = rotatedInsetsState; |
| 144 | mRotatedOverrideConfiguration = rotatedConfig; |
| 145 | // This will use unrotate as rotate, so the new and old rotation are inverted. |
| 146 | mRotator = new SeamlessRotator(rotatedDisplayInfo.rotation, currentRotation, |
Vishnu Nair | eb53e52 | 2020-05-08 18:03:12 -0700 | [diff] [blame] | 147 | rotatedDisplayInfo, true /* applyFixedTransformationHint */); |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Transforms the window container from the next rotation to the current rotation for |
| 152 | * showing the window in a display with different rotation. |
| 153 | */ |
| 154 | void transform(WindowContainer<?> container) { |
| 155 | mRotator.unrotate(container.getPendingTransaction(), container); |
| 156 | if (!mRotatedContainers.contains(container)) { |
| 157 | mRotatedContainers.add(container); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Resets the transformation of the window containers which have been rotated. This should |
| 163 | * be called when the window has the same rotation as display. |
| 164 | */ |
| 165 | void resetTransform() { |
| 166 | for (int i = mRotatedContainers.size() - 1; i >= 0; i--) { |
| 167 | final WindowContainer<?> c = mRotatedContainers.get(i); |
Riddle Hsu | f41034c | 2020-03-19 13:10:46 +0800 | [diff] [blame] | 168 | // If the window is detached (no parent), its surface may have been released. |
| 169 | if (c.getParent() != null) { |
| 170 | mRotator.finish(c.getPendingTransaction(), c); |
| 171 | } |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
Charles Chen | 4bff5be | 2020-03-11 10:17:19 +0800 | [diff] [blame] | 176 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 177 | private boolean mHasUnlinkToDeath = false; |
| 178 | |
| 179 | @Override |
| 180 | public void binderDied() { |
| 181 | synchronized (mWmService.mGlobalLock) { |
| 182 | mBinderDied = true; |
| 183 | removeImmediately(); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | void linkToDeath() throws RemoteException { |
| 188 | token.linkToDeath(DeathRecipient.this, 0); |
| 189 | } |
| 190 | |
| 191 | void unlinkToDeath() { |
| 192 | if (mHasUnlinkToDeath) { |
| 193 | return; |
| 194 | } |
| 195 | token.unlinkToDeath(DeathRecipient.this, 0); |
| 196 | mHasUnlinkToDeath = true; |
| 197 | } |
| 198 | } |
| 199 | |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 200 | /** |
| 201 | * Compares two child window of this token and returns -1 if the first is lesser than the |
| 202 | * second in terms of z-order and 1 otherwise. |
| 203 | */ |
| 204 | private final Comparator<WindowState> mWindowComparator = |
| 205 | (WindowState newWindow, WindowState existingWindow) -> { |
| 206 | final WindowToken token = WindowToken.this; |
| 207 | if (newWindow.mToken != token) { |
| 208 | throw new IllegalArgumentException("newWindow=" + newWindow |
| 209 | + " is not a child of token=" + token); |
| 210 | } |
| 211 | |
| 212 | if (existingWindow.mToken != token) { |
| 213 | throw new IllegalArgumentException("existingWindow=" + existingWindow |
| 214 | + " is not a child of token=" + token); |
| 215 | } |
| 216 | |
| 217 | return isFirstChildWindowGreaterThanSecond(newWindow, existingWindow) ? 1 : -1; |
| 218 | }; |
| 219 | |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 220 | WindowToken(WindowManagerService service, IBinder _token, int type, boolean persistOnEmpty, |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 221 | DisplayContent dc, boolean ownerCanManageAppTokens) { |
Adrian Roos | 4bef62e | 2018-03-21 19:52:09 +0100 | [diff] [blame] | 222 | this(service, _token, type, persistOnEmpty, dc, ownerCanManageAppTokens, |
Charles Chen | 525e1e7 | 2020-03-02 15:40:25 +0800 | [diff] [blame] | 223 | false /* roundedCornerOverlay */); |
Adrian Roos | 4bef62e | 2018-03-21 19:52:09 +0100 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | WindowToken(WindowManagerService service, IBinder _token, int type, boolean persistOnEmpty, |
Charles Chen | 525e1e7 | 2020-03-02 15:40:25 +0800 | [diff] [blame] | 227 | DisplayContent dc, boolean ownerCanManageAppTokens, boolean roundedCornerOverlay) { |
Charles Chen | 4bff5be | 2020-03-11 10:17:19 +0800 | [diff] [blame] | 228 | this(service, _token, type, persistOnEmpty, dc, ownerCanManageAppTokens, INVALID_UID, |
Charles Chen | 525e1e7 | 2020-03-02 15:40:25 +0800 | [diff] [blame] | 229 | roundedCornerOverlay, false /* fromClientToken */); |
Andrii Kulian | 02c0e4d | 2020-01-27 22:17:31 -0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | WindowToken(WindowManagerService service, IBinder _token, int type, boolean persistOnEmpty, |
Charles Chen | 4bff5be | 2020-03-11 10:17:19 +0800 | [diff] [blame] | 233 | DisplayContent dc, boolean ownerCanManageAppTokens, int ownerUid, |
| 234 | boolean roundedCornerOverlay, boolean fromClientToken) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 235 | super(service); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 236 | token = _token; |
| 237 | windowType = type; |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 238 | mPersistOnEmpty = persistOnEmpty; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 239 | mOwnerCanManageAppTokens = ownerCanManageAppTokens; |
Charles Chen | 4bff5be | 2020-03-11 10:17:19 +0800 | [diff] [blame] | 240 | mOwnerUid = ownerUid; |
Adrian Roos | 4bef62e | 2018-03-21 19:52:09 +0100 | [diff] [blame] | 241 | mRoundedCornerOverlay = roundedCornerOverlay; |
Andrii Kulian | 02c0e4d | 2020-01-27 22:17:31 -0800 | [diff] [blame] | 242 | mFromClientToken = fromClientToken; |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 243 | if (dc != null) { |
lumark | bde1513 | 2019-12-18 22:29:43 +0800 | [diff] [blame] | 244 | dc.addWindowToken(token, this); |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 245 | } |
Charles Chen | 4bff5be | 2020-03-11 10:17:19 +0800 | [diff] [blame] | 246 | if (shouldReportToClient()) { |
| 247 | try { |
| 248 | mDeathRecipient = new DeathRecipient(); |
| 249 | mDeathRecipient.linkToDeath(); |
| 250 | } catch (RemoteException e) { |
| 251 | Slog.e(TAG, "Unable to add window token with type " + windowType + " on " |
| 252 | + "display " + dc.getDisplayId(), e); |
| 253 | mDeathRecipient = null; |
| 254 | return; |
| 255 | } |
| 256 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 257 | } |
| 258 | |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 259 | void removeAllWindowsIfPossible() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 260 | for (int i = mChildren.size() - 1; i >= 0; --i) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 261 | final WindowState win = mChildren.get(i); |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 262 | ProtoLog.w(WM_DEBUG_WINDOW_MOVEMENT, |
| 263 | "removeAllWindowsIfPossible: removing win=%s", win); |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 264 | win.removeIfPossible(); |
Svetoslav | 3a5c721 | 2014-10-14 09:54:26 -0700 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 268 | void setExiting() { |
Charles Chen | 4bff5be | 2020-03-11 10:17:19 +0800 | [diff] [blame] | 269 | if (isEmpty()) { |
chaviw | aec55ff5 | 2017-12-04 18:39:34 -0800 | [diff] [blame] | 270 | super.removeImmediately(); |
| 271 | return; |
| 272 | } |
| 273 | |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 274 | // This token is exiting, so allow it to be removed when it no longer contains any windows. |
| 275 | mPersistOnEmpty = false; |
| 276 | |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 277 | if (!isVisible()) { |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 278 | return; |
| 279 | } |
| 280 | |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 281 | final int count = mChildren.size(); |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 282 | boolean changed = false; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 283 | final boolean delayed = isAnimating(TRANSITION | PARENTS | CHILDREN); |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 284 | |
| 285 | for (int i = 0; i < count; i++) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 286 | final WindowState win = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 287 | changed |= win.onSetAppExiting(); |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Issei Suzuki | f2f6c91 | 2019-11-08 11:24:18 +0100 | [diff] [blame] | 290 | final ActivityRecord app = asActivityRecord(); |
| 291 | if (app != null) { |
| 292 | app.setVisible(false); |
| 293 | } |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 294 | |
| 295 | if (changed) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 296 | mWmService.mWindowPlacerLocked.performSurfacePlacement(); |
| 297 | mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /*updateInputWindows*/); |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Wale Ogunwale | b0f3b83 | 2016-10-17 10:13:07 -0700 | [diff] [blame] | 300 | if (delayed) { |
| 301 | mDisplayContent.mExitingTokens.add(this); |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 305 | /** |
Riddle Hsu | b398da3 | 2019-01-21 21:48:16 +0800 | [diff] [blame] | 306 | * @return The scale for applications running in compatibility mode. Multiply the size in the |
| 307 | * application by this scale will be the size in the screen. |
| 308 | */ |
| 309 | float getSizeCompatScale() { |
| 310 | return mDisplayContent.mCompatibleScreenScale; |
| 311 | } |
| 312 | |
| 313 | /** |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 314 | * Returns true if the new window is considered greater than the existing window in terms of |
| 315 | * z-order. |
| 316 | */ |
| 317 | protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow, |
| 318 | WindowState existingWindow) { |
Wale Ogunwale | b783fd8 | 2016-11-04 09:51:54 -0700 | [diff] [blame] | 319 | // New window is considered greater if it has a higher or equal base layer. |
| 320 | return newWindow.mBaseLayer >= existingWindow.mBaseLayer; |
Wale Ogunwale | 07bcab7 | 2016-10-14 15:30:09 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 323 | void addWindow(final WindowState win) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 324 | ProtoLog.d(WM_DEBUG_FOCUS, |
| 325 | "addWindow: win=%s Callers=%s", win, Debug.getCallers(5)); |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 326 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 327 | if (win.isChildWindow()) { |
| 328 | // Child windows are added to their parent windows. |
Wale Ogunwale | b9a07c3 | 2016-10-12 14:55:56 -0700 | [diff] [blame] | 329 | return; |
| 330 | } |
wilsonshih | 07cb272 | 2020-03-16 23:19:24 +0800 | [diff] [blame] | 331 | // This token is created from WindowContext and the client requests to addView now, create a |
| 332 | // surface for this token. |
| 333 | if (mSurfaceControl == null) { |
| 334 | createSurfaceControl(true /* force */); |
| 335 | } |
Wale Ogunwale | b9a07c3 | 2016-10-12 14:55:56 -0700 | [diff] [blame] | 336 | if (!mChildren.contains(win)) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 337 | ProtoLog.v(WM_DEBUG_ADD_REMOVE, "Adding %s to %s", win, this); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 338 | addChild(win, mWindowComparator); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 339 | mWmService.mWindowsChanged = true; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 340 | // TODO: Should we also be setting layout needed here and other places? |
Wale Ogunwale | b9a07c3 | 2016-10-12 14:55:56 -0700 | [diff] [blame] | 341 | } |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 342 | } |
| 343 | |
wilsonshih | 07cb272 | 2020-03-16 23:19:24 +0800 | [diff] [blame] | 344 | @Override |
| 345 | void createSurfaceControl(boolean force) { |
| 346 | if (!mFromClientToken || force) { |
| 347 | super.createSurfaceControl(force); |
| 348 | } |
| 349 | } |
| 350 | |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 351 | /** Returns true if the token windows list is empty. */ |
| 352 | boolean isEmpty() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 353 | return mChildren.isEmpty(); |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | WindowState getReplacingWindow() { |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 357 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
Wale Ogunwale | d90546a | 2016-09-09 23:28:03 -0700 | [diff] [blame] | 358 | final WindowState win = mChildren.get(i); |
Wale Ogunwale | 9bc4773 | 2016-08-10 14:44:22 -0700 | [diff] [blame] | 359 | final WindowState replacing = win.getReplacingWindow(); |
| 360 | if (replacing != null) { |
| 361 | return replacing; |
Wale Ogunwale | e4da0c1 | 2016-07-29 12:47:02 -0700 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | return null; |
| 365 | } |
| 366 | |
Wale Ogunwale | 0c4a40ef | 2016-10-07 07:06:40 -0700 | [diff] [blame] | 367 | /** Return true if this token has a window that wants the wallpaper displayed behind it. */ |
| 368 | boolean windowsCanBeWallpaperTarget() { |
| 369 | for (int j = mChildren.size() - 1; j >= 0; j--) { |
| 370 | final WindowState w = mChildren.get(j); |
| 371 | if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) { |
| 372 | return true; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | return false; |
| 377 | } |
| 378 | |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 379 | @Override |
| 380 | void removeImmediately() { |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 381 | if (mDisplayContent != null) { |
| 382 | mDisplayContent.removeWindowToken(token); |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 383 | } |
Wale Ogunwale | cfca258 | 2016-10-19 09:53:25 -0700 | [diff] [blame] | 384 | // Needs to occur after the token is removed from the display above to avoid attempt at |
| 385 | // duplicate removal of this window container from it's parent. |
| 386 | super.removeImmediately(); |
Charles Chen | 4bff5be | 2020-03-11 10:17:19 +0800 | [diff] [blame] | 387 | |
| 388 | reportWindowTokenRemovedToClient(); |
| 389 | } |
| 390 | |
| 391 | private void reportWindowTokenRemovedToClient() { |
| 392 | if (!shouldReportToClient()) { |
| 393 | return; |
| 394 | } |
| 395 | mDeathRecipient.unlinkToDeath(); |
| 396 | IWindowToken windowTokenClient = IWindowToken.Stub.asInterface(token); |
| 397 | try { |
| 398 | windowTokenClient.onWindowTokenRemoved(); |
| 399 | } catch (RemoteException e) { |
| 400 | ProtoLog.w(WM_ERROR, "Could not report token removal to the window token client."); |
| 401 | } |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 404 | @Override |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 405 | void onDisplayChanged(DisplayContent dc) { |
Wale Ogunwale | 3d0bfd9 | 2016-12-05 11:38:02 -0800 | [diff] [blame] | 406 | dc.reParentWindowToken(this); |
Robert Carr | da61ba9 | 2017-03-29 15:52:23 -0700 | [diff] [blame] | 407 | |
| 408 | // TODO(b/36740756): One day this should perhaps be hooked |
| 409 | // up with goodToGo, so we don't move a window |
| 410 | // to another display before the window behind |
| 411 | // it is ready. |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 412 | super.onDisplayChanged(dc); |
Andrii Kulian | 02c0e4d | 2020-01-27 22:17:31 -0800 | [diff] [blame] | 413 | reportConfigToWindowTokenClient(); |
| 414 | } |
| 415 | |
| 416 | @Override |
| 417 | public void onConfigurationChanged(Configuration newParentConfig) { |
| 418 | super.onConfigurationChanged(newParentConfig); |
| 419 | reportConfigToWindowTokenClient(); |
| 420 | } |
| 421 | |
| 422 | void reportConfigToWindowTokenClient() { |
Charles Chen | 4bff5be | 2020-03-11 10:17:19 +0800 | [diff] [blame] | 423 | if (!shouldReportToClient()) { |
Andrii Kulian | 02c0e4d | 2020-01-27 22:17:31 -0800 | [diff] [blame] | 424 | return; |
| 425 | } |
Charles Chen | 7ba8e26 | 2020-03-27 16:42:29 +0800 | [diff] [blame] | 426 | if (mLastReportedConfig == null) { |
| 427 | mLastReportedConfig = new Configuration(); |
| 428 | } |
Andrii Kulian | 02c0e4d | 2020-01-27 22:17:31 -0800 | [diff] [blame] | 429 | final Configuration config = getConfiguration(); |
| 430 | final int displayId = getDisplayContent().getDisplayId(); |
Charles Chen | 7ba8e26 | 2020-03-27 16:42:29 +0800 | [diff] [blame] | 431 | if (config.diff(mLastReportedConfig) == 0 && displayId == mLastReportedDisplay) { |
Andrii Kulian | 02c0e4d | 2020-01-27 22:17:31 -0800 | [diff] [blame] | 432 | // No changes since last reported time. |
| 433 | return; |
| 434 | } |
| 435 | |
Charles Chen | 7ba8e26 | 2020-03-27 16:42:29 +0800 | [diff] [blame] | 436 | mLastReportedConfig.setTo(config); |
Andrii Kulian | 02c0e4d | 2020-01-27 22:17:31 -0800 | [diff] [blame] | 437 | mLastReportedDisplay = displayId; |
| 438 | |
| 439 | IWindowToken windowTokenClient = IWindowToken.Stub.asInterface(token); |
Charles Chen | 4bff5be | 2020-03-11 10:17:19 +0800 | [diff] [blame] | 440 | try { |
| 441 | windowTokenClient.onConfigurationChanged(config, displayId); |
| 442 | } catch (RemoteException e) { |
| 443 | ProtoLog.w(WM_ERROR, |
| 444 | "Could not report config changes to the window token client."); |
Andrii Kulian | 02c0e4d | 2020-01-27 22:17:31 -0800 | [diff] [blame] | 445 | } |
Wale Ogunwale | 02319a6 | 2016-09-26 15:21:22 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Charles Chen | 4bff5be | 2020-03-11 10:17:19 +0800 | [diff] [blame] | 448 | /** |
| 449 | * @return {@code true} if this {@link WindowToken} is not an {@link ActivityRecord} and |
| 450 | * registered from client side. |
| 451 | */ |
| 452 | private boolean shouldReportToClient() { |
| 453 | // Only report to client for WindowToken because Activities are updated through ATM |
| 454 | // callbacks. |
| 455 | return asActivityRecord() == null |
| 456 | // Report to {@link android.view.WindowTokenClient} if this token was registered from it. |
| 457 | && mFromClientToken && !mBinderDied; |
| 458 | } |
| 459 | |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 460 | @Override |
| 461 | void assignLayer(SurfaceControl.Transaction t, int layer) { |
| 462 | if (windowType == TYPE_DOCK_DIVIDER) { |
| 463 | // See {@link DisplayContent#mSplitScreenDividerAnchor} |
Andrii Kulian | 4c0fd0d | 2020-03-29 13:32:14 -0700 | [diff] [blame] | 464 | super.assignRelativeLayer(t, |
| 465 | mDisplayContent.getDefaultTaskDisplayArea().getSplitScreenDividerAnchor(), 1); |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 466 | } else if (mRoundedCornerOverlay) { |
| 467 | super.assignLayer(t, WindowManagerPolicy.COLOR_FADE_LAYER + 1); |
| 468 | } else { |
| 469 | super.assignLayer(t, layer); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | @Override |
| 474 | SurfaceControl.Builder makeSurface() { |
| 475 | final SurfaceControl.Builder builder = super.makeSurface(); |
| 476 | if (mRoundedCornerOverlay) { |
| 477 | builder.setParent(null); |
| 478 | } |
| 479 | return builder; |
| 480 | } |
| 481 | |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 482 | boolean hasFixedRotationTransform() { |
| 483 | return mFixedRotationTransformState != null; |
| 484 | } |
| 485 | |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 486 | /** Returns {@code true} if the given token shares the same transform. */ |
| 487 | boolean hasFixedRotationTransform(WindowToken token) { |
| 488 | if (mFixedRotationTransformState == null || token == null) { |
| 489 | return false; |
| 490 | } |
| 491 | return this == token || mFixedRotationTransformState == token.mFixedRotationTransformState; |
| 492 | } |
| 493 | |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 494 | boolean isFinishingFixedRotationTransform() { |
| 495 | return mFixedRotationTransformState != null |
| 496 | && !mFixedRotationTransformState.mIsTransforming; |
| 497 | } |
| 498 | |
| 499 | boolean isFixedRotationTransforming() { |
| 500 | return mFixedRotationTransformState != null |
| 501 | && mFixedRotationTransformState.mIsTransforming; |
| 502 | } |
| 503 | |
| 504 | DisplayInfo getFixedRotationTransformDisplayInfo() { |
| 505 | return isFixedRotationTransforming() ? mFixedRotationTransformState.mDisplayInfo : null; |
| 506 | } |
| 507 | |
| 508 | DisplayFrames getFixedRotationTransformDisplayFrames() { |
| 509 | return isFixedRotationTransforming() ? mFixedRotationTransformState.mDisplayFrames : null; |
| 510 | } |
| 511 | |
| 512 | Rect getFixedRotationTransformDisplayBounds() { |
| 513 | return isFixedRotationTransforming() |
| 514 | ? mFixedRotationTransformState.mRotatedOverrideConfiguration.windowConfiguration |
| 515 | .getBounds() |
| 516 | : null; |
| 517 | } |
| 518 | |
| 519 | InsetsState getFixedRotationTransformInsetsState() { |
| 520 | return isFixedRotationTransforming() ? mFixedRotationTransformState.mInsetsState : null; |
| 521 | } |
| 522 | |
| 523 | /** Applies the rotated layout environment to this token in the simulated rotated display. */ |
| 524 | void applyFixedRotationTransform(DisplayInfo info, DisplayFrames displayFrames, |
| 525 | Configuration config) { |
| 526 | if (mFixedRotationTransformState != null) { |
| 527 | return; |
| 528 | } |
| 529 | final InsetsState insetsState = new InsetsState(); |
| 530 | mDisplayContent.getDisplayPolicy().simulateLayoutDisplay(displayFrames, insetsState, |
| 531 | mDisplayContent.getConfiguration().uiMode); |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 532 | mFixedRotationTransformState = new FixedRotationTransformState(info, displayFrames, |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 533 | insetsState, new Configuration(config), mDisplayContent.getRotation()); |
| 534 | onConfigurationChanged(getParent().getConfiguration()); |
Riddle Hsu | d490c57 | 2020-04-17 01:39:27 +0800 | [diff] [blame] | 535 | notifyFixedRotationTransform(true /* enabled */); |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 536 | } |
| 537 | |
Vadim Caen | 2a9ccc9 | 2020-01-29 12:21:41 +0100 | [diff] [blame] | 538 | /** |
Riddle Hsu | 6393ad1 | 2020-03-02 23:56:32 +0800 | [diff] [blame] | 539 | * Reuses the {@link FixedRotationTransformState} (if any) from the other WindowToken to this |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 540 | * one. This takes the same effect as {@link #applyFixedRotationTransform}. |
Vadim Caen | 2a9ccc9 | 2020-01-29 12:21:41 +0100 | [diff] [blame] | 541 | */ |
Riddle Hsu | 6393ad1 | 2020-03-02 23:56:32 +0800 | [diff] [blame] | 542 | void linkFixedRotationTransform(WindowToken other) { |
| 543 | if (mFixedRotationTransformState != null) { |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 544 | return; |
| 545 | } |
Riddle Hsu | 6393ad1 | 2020-03-02 23:56:32 +0800 | [diff] [blame] | 546 | final FixedRotationTransformState fixedRotationState = other.mFixedRotationTransformState; |
| 547 | if (fixedRotationState == null) { |
| 548 | return; |
| 549 | } |
| 550 | mFixedRotationTransformState = fixedRotationState; |
| 551 | fixedRotationState.mAssociatedTokens.add(this); |
| 552 | onConfigurationChanged(getParent().getConfiguration()); |
Riddle Hsu | d490c57 | 2020-04-17 01:39:27 +0800 | [diff] [blame] | 553 | notifyFixedRotationTransform(true /* enabled */); |
Riddle Hsu | 6393ad1 | 2020-03-02 23:56:32 +0800 | [diff] [blame] | 554 | } |
| 555 | |
Riddle Hsu | 06aeb06 | 2020-03-24 23:38:40 +0800 | [diff] [blame] | 556 | void finishFixedRotationTransform() { |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 557 | finishFixedRotationTransform(null /* applyDisplayRotation */); |
Riddle Hsu | 06aeb06 | 2020-03-24 23:38:40 +0800 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | /** |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 561 | * Finishes the transform and apply display rotation if the action is given. If the display will |
Riddle Hsu | 522029a | 2020-04-10 21:21:24 +0800 | [diff] [blame] | 562 | * not rotate, the transformed containers are restored to their original states. |
Riddle Hsu | 06aeb06 | 2020-03-24 23:38:40 +0800 | [diff] [blame] | 563 | */ |
Riddle Hsu | d495743 | 2020-04-24 22:06:29 +0800 | [diff] [blame] | 564 | void finishFixedRotationTransform(Runnable applyDisplayRotation) { |
Riddle Hsu | 06aeb06 | 2020-03-24 23:38:40 +0800 | [diff] [blame] | 565 | final FixedRotationTransformState state = mFixedRotationTransformState; |
| 566 | if (state == null) { |
| 567 | return; |
| 568 | } |
| 569 | |
| 570 | state.resetTransform(); |
| 571 | // Clear the flag so if the display will be updated to the same orientation, the transform |
| 572 | // won't take effect. |
| 573 | state.mIsTransforming = false; |
| 574 | if (applyDisplayRotation != null) { |
| 575 | applyDisplayRotation.run(); |
Riddle Hsu | 522029a | 2020-04-10 21:21:24 +0800 | [diff] [blame] | 576 | } else { |
| 577 | // The display will not rotate to the rotation of this container, let's cancel them. |
| 578 | for (int i = state.mAssociatedTokens.size() - 1; i >= 0; i--) { |
| 579 | state.mAssociatedTokens.get(i).cancelFixedRotationTransform(); |
| 580 | } |
| 581 | cancelFixedRotationTransform(); |
Riddle Hsu | 06aeb06 | 2020-03-24 23:38:40 +0800 | [diff] [blame] | 582 | } |
| 583 | // The state is cleared at the end, because it is used to indicate that other windows can |
| 584 | // use seamless rotation when applying rotation to display. |
Riddle Hsu | 6393ad1 | 2020-03-02 23:56:32 +0800 | [diff] [blame] | 585 | for (int i = state.mAssociatedTokens.size() - 1; i >= 0; i--) { |
Riddle Hsu | d490c57 | 2020-04-17 01:39:27 +0800 | [diff] [blame] | 586 | state.mAssociatedTokens.get(i).cleanUpFixedRotationTransformState(); |
Riddle Hsu | 6393ad1 | 2020-03-02 23:56:32 +0800 | [diff] [blame] | 587 | } |
Riddle Hsu | d490c57 | 2020-04-17 01:39:27 +0800 | [diff] [blame] | 588 | cleanUpFixedRotationTransformState(); |
| 589 | } |
| 590 | |
| 591 | private void cleanUpFixedRotationTransformState() { |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 592 | mFixedRotationTransformState = null; |
Riddle Hsu | d490c57 | 2020-04-17 01:39:27 +0800 | [diff] [blame] | 593 | notifyFixedRotationTransform(false /* enabled */); |
| 594 | } |
| 595 | |
| 596 | /** Notifies application side to enable or disable the rotation adjustment of display info. */ |
| 597 | private void notifyFixedRotationTransform(boolean enabled) { |
| 598 | FixedRotationAdjustments adjustments = null; |
| 599 | // A token may contain windows of the same processes or different processes. The list is |
| 600 | // used to avoid sending the same adjustments to a process multiple times. |
| 601 | ArrayList<WindowProcessController> notifiedProcesses = null; |
| 602 | for (int i = mChildren.size() - 1; i >= 0; i--) { |
| 603 | final WindowState w = mChildren.get(i); |
| 604 | final WindowProcessController app; |
| 605 | if (w.mAttrs.type == TYPE_APPLICATION_STARTING) { |
| 606 | // Use the host activity because starting window is controlled by window manager. |
| 607 | final ActivityRecord r = asActivityRecord(); |
| 608 | if (r == null) { |
| 609 | continue; |
| 610 | } |
| 611 | app = r.app; |
| 612 | } else { |
| 613 | app = mWmService.mAtmService.mProcessMap.getProcess(w.mSession.mPid); |
| 614 | } |
| 615 | if (app == null || !app.hasThread()) { |
| 616 | continue; |
| 617 | } |
| 618 | if (notifiedProcesses == null) { |
| 619 | notifiedProcesses = new ArrayList<>(2); |
| 620 | adjustments = enabled ? createFixedRotationAdjustmentsIfNeeded() : null; |
| 621 | } else if (notifiedProcesses.contains(app)) { |
| 622 | continue; |
| 623 | } |
| 624 | notifiedProcesses.add(app); |
| 625 | try { |
| 626 | mWmService.mAtmService.getLifecycleManager().scheduleTransaction( |
| 627 | app.getThread(), FixedRotationAdjustmentsItem.obtain(token, adjustments)); |
| 628 | } catch (RemoteException e) { |
| 629 | Slog.w(TAG, "Failed to schedule DisplayAdjustmentsItem to " + app, e); |
| 630 | } |
| 631 | } |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 632 | } |
| 633 | |
Riddle Hsu | 522029a | 2020-04-10 21:21:24 +0800 | [diff] [blame] | 634 | /** Restores the changes that applies to this container. */ |
| 635 | private void cancelFixedRotationTransform() { |
| 636 | final WindowContainer<?> parent = getParent(); |
| 637 | if (parent == null) { |
| 638 | // The window may be detached or detaching. |
| 639 | return; |
| 640 | } |
Riddle Hsu | d490c57 | 2020-04-17 01:39:27 +0800 | [diff] [blame] | 641 | notifyFixedRotationTransform(false /* enabled */); |
Riddle Hsu | d16620e | 2020-04-06 20:48:06 +0800 | [diff] [blame] | 642 | final int originalRotation = getWindowConfiguration().getRotation(); |
Riddle Hsu | 522029a | 2020-04-10 21:21:24 +0800 | [diff] [blame] | 643 | onConfigurationChanged(parent.getConfiguration()); |
Riddle Hsu | d16620e | 2020-04-06 20:48:06 +0800 | [diff] [blame] | 644 | onCancelFixedRotationTransform(originalRotation); |
| 645 | } |
| 646 | |
| 647 | /** |
| 648 | * It is called when the window is using fixed rotation transform, and before display applies |
| 649 | * the same rotation, the rotation change for display is canceled, e.g. the orientation from |
| 650 | * sensor is updated to previous direction. |
| 651 | */ |
| 652 | void onCancelFixedRotationTransform(int originalDisplayRotation) { |
Riddle Hsu | 522029a | 2020-04-10 21:21:24 +0800 | [diff] [blame] | 653 | } |
| 654 | |
Riddle Hsu | d490c57 | 2020-04-17 01:39:27 +0800 | [diff] [blame] | 655 | FixedRotationAdjustments createFixedRotationAdjustmentsIfNeeded() { |
| 656 | if (!isFixedRotationTransforming()) { |
| 657 | return null; |
| 658 | } |
| 659 | return new FixedRotationAdjustments(mFixedRotationTransformState.mDisplayInfo.rotation, |
| 660 | mFixedRotationTransformState.mDisplayInfo.displayCutout); |
| 661 | } |
| 662 | |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 663 | @Override |
| 664 | void resolveOverrideConfiguration(Configuration newParentConfig) { |
| 665 | super.resolveOverrideConfiguration(newParentConfig); |
| 666 | if (isFixedRotationTransforming()) { |
| 667 | // Apply the rotated configuration to current resolved configuration, so the merged |
| 668 | // override configuration can update to the same state. |
| 669 | getResolvedOverrideConfiguration().updateFrom( |
| 670 | mFixedRotationTransformState.mRotatedOverrideConfiguration); |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | @Override |
Evan Rosky | 0ad8d2c | 2020-03-16 12:09:58 -0700 | [diff] [blame] | 675 | void updateSurfacePosition(SurfaceControl.Transaction t) { |
| 676 | super.updateSurfacePosition(t); |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 677 | if (isFixedRotationTransforming()) { |
| 678 | // The window is layouted in a simulated rotated display but the real display hasn't |
| 679 | // rotated, so here transforms its surface to fit in the real display. |
| 680 | mFixedRotationTransformState.transform(this); |
| 681 | } |
| 682 | } |
| 683 | |
Riddle Hsu | 3d0aa4f | 2020-04-09 17:58:50 +0800 | [diff] [blame] | 684 | @Override |
| 685 | void resetSurfacePositionForAnimationLeash(SurfaceControl.Transaction t) { |
| 686 | // Keep the transformed position to animate because the surface will show in different |
| 687 | // rotation than the animator of leash. |
| 688 | if (!isFixedRotationTransforming()) { |
| 689 | super.resetSurfacePositionForAnimationLeash(t); |
| 690 | } |
| 691 | } |
| 692 | |
Riddle Hsu | 6f548e9 | 2020-01-13 13:34:09 +0800 | [diff] [blame] | 693 | /** |
Vadim Caen | b46f923 | 2020-02-14 17:54:39 +0100 | [diff] [blame] | 694 | * Gives a chance to this {@link WindowToken} to adjust the {@link |
| 695 | * android.view.WindowManager.LayoutParams} of its windows. |
| 696 | */ |
| 697 | void adjustWindowParams(WindowState win, WindowManager.LayoutParams attrs) { |
| 698 | } |
| 699 | |
| 700 | |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 701 | @CallSuper |
| 702 | @Override |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 703 | public void dumpDebug(ProtoOutputStream proto, long fieldId, |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 704 | @WindowTraceLogLevel int logLevel) { |
| 705 | if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible()) { |
| 706 | return; |
| 707 | } |
| 708 | |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 709 | final long token = proto.start(fieldId); |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 710 | super.dumpDebug(proto, WINDOW_CONTAINER, logLevel); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 711 | proto.write(HASH_CODE, System.identityHashCode(this)); |
Vishnu Nair | 04ab439 | 2018-01-10 11:00:06 -0800 | [diff] [blame] | 712 | proto.write(WAITING_TO_SHOW, waitingToShow); |
| 713 | proto.write(PAUSED, paused); |
Steven Timotius | af03df6 | 2017-07-18 16:56:43 -0700 | [diff] [blame] | 714 | proto.end(token); |
| 715 | } |
| 716 | |
Vishnu Nair | dddc9f5 | 2020-03-09 09:37:27 -0700 | [diff] [blame] | 717 | @Override |
| 718 | long getProtoFieldId() { |
| 719 | return WINDOW_TOKEN; |
| 720 | } |
| 721 | |
Jorim Jaggi | f5f9e12 | 2017-10-24 18:21:09 +0200 | [diff] [blame] | 722 | void dump(PrintWriter pw, String prefix, boolean dumpAll) { |
| 723 | super.dump(pw, prefix, dumpAll); |
Wale Ogunwale | d1c3791 | 2016-08-16 03:19:39 -0700 | [diff] [blame] | 724 | pw.print(prefix); pw.print("windows="); pw.println(mChildren); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 725 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
Riddle Hsu | d8bdc45 | 2019-12-06 21:36:32 +0800 | [diff] [blame] | 726 | pw.print(" hasVisible="); pw.print(hasVisible); |
Wale Ogunwale | 7a8889a | 2019-11-16 08:23:42 -0800 | [diff] [blame] | 727 | if (waitingToShow) { |
Riddle Hsu | d8bdc45 | 2019-12-06 21:36:32 +0800 | [diff] [blame] | 728 | pw.print(" waitingToShow=true"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 729 | } |
Riddle Hsu | d8bdc45 | 2019-12-06 21:36:32 +0800 | [diff] [blame] | 730 | pw.println(); |
Riddle Hsu | 70a920c | 2020-05-05 17:20:32 +0800 | [diff] [blame] | 731 | if (hasFixedRotationTransform()) { |
| 732 | pw.print(prefix); |
| 733 | pw.print("fixedRotationConfig="); |
| 734 | pw.println(mFixedRotationTransformState.mRotatedOverrideConfiguration); |
| 735 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | @Override |
| 739 | public String toString() { |
| 740 | if (stringName == null) { |
| 741 | StringBuilder sb = new StringBuilder(); |
| 742 | sb.append("WindowToken{"); |
| 743 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
Dianne Hackborn | ef03a7f | 2012-10-29 18:46:52 -0700 | [diff] [blame] | 744 | sb.append(" "); sb.append(token); sb.append('}'); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 745 | stringName = sb.toString(); |
| 746 | } |
| 747 | return stringName; |
| 748 | } |
Wale Ogunwale | 9adfe57 | 2016-09-08 20:43:58 -0700 | [diff] [blame] | 749 | |
| 750 | @Override |
| 751 | String getName() { |
| 752 | return toString(); |
| 753 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 754 | |
Robert Carr | 683e05d | 2018-04-18 15:11:04 -0700 | [diff] [blame] | 755 | /** |
| 756 | * Return whether windows from this token can layer above the |
| 757 | * system bars, or in other words extend outside of the "Decor Frame" |
| 758 | */ |
| 759 | boolean canLayerAboveSystemBars() { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 760 | int layer = mWmService.mPolicy.getWindowLayerFromTypeLw(windowType, |
Robert Carr | 683e05d | 2018-04-18 15:11:04 -0700 | [diff] [blame] | 761 | mOwnerCanManageAppTokens); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 762 | int navLayer = mWmService.mPolicy.getWindowLayerFromTypeLw(TYPE_NAVIGATION_BAR, |
Robert Carr | 683e05d | 2018-04-18 15:11:04 -0700 | [diff] [blame] | 763 | mOwnerCanManageAppTokens); |
| 764 | return mOwnerCanManageAppTokens && (layer > navLayer); |
| 765 | } |
Adrian Roos | efa4070 | 2020-01-08 17:58:45 +0100 | [diff] [blame] | 766 | |
| 767 | int getWindowLayerFromType() { |
| 768 | return mWmService.mPolicy.getWindowLayerFromTypeLw(windowType, mOwnerCanManageAppTokens); |
| 769 | } |
Charles Chen | 4bff5be | 2020-03-11 10:17:19 +0800 | [diff] [blame] | 770 | |
| 771 | int getOwnerUid() { |
| 772 | return mOwnerUid; |
| 773 | } |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 774 | } |