Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | ab20e16 | 2018-03-27 13:06:09 +0200 | [diff] [blame] | 19 | import static com.android.server.wm.AnimationAdapterProto.REMOTE; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 20 | import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_REMOTE_ANIMATIONS; |
Jorim Jaggi | ab20e16 | 2018-03-27 13:06:09 +0200 | [diff] [blame] | 21 | import static com.android.server.wm.RemoteAnimationAdapterWrapperProto.TARGET; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 22 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 23 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
| 24 | |
| 25 | import android.graphics.Point; |
| 26 | import android.graphics.Rect; |
Jorim Jaggi | ab20e16 | 2018-03-27 13:06:09 +0200 | [diff] [blame] | 27 | import android.os.Binder; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 28 | import android.os.Handler; |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 29 | import android.os.IBinder.DeathRecipient; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 30 | import android.os.RemoteException; |
| 31 | import android.os.SystemClock; |
| 32 | import android.util.Slog; |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 33 | import android.util.proto.ProtoOutputStream; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 34 | import android.view.IRemoteAnimationFinishedCallback; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 35 | import android.view.RemoteAnimationAdapter; |
| 36 | import android.view.RemoteAnimationTarget; |
| 37 | import android.view.SurfaceControl; |
| 38 | import android.view.SurfaceControl.Transaction; |
| 39 | |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 40 | import com.android.internal.util.FastPrintWriter; |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 41 | import com.android.server.protolog.ProtoLogImpl; |
| 42 | import com.android.server.protolog.common.ProtoLog; |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 43 | import com.android.server.wm.SurfaceAnimator.AnimationType; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 44 | import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback; |
| 45 | |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 46 | import java.io.PrintWriter; |
| 47 | import java.io.StringWriter; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 48 | import java.util.ArrayList; |
| 49 | |
| 50 | /** |
| 51 | * Helper class to run app animations in a remote process. |
| 52 | */ |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 53 | class RemoteAnimationController implements DeathRecipient { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 54 | private static final String TAG = TAG_WITH_CLASS_NAME |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 55 | ? "RemoteAnimationController" : TAG_WM; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 56 | private static final long TIMEOUT_MS = 2000; |
| 57 | |
| 58 | private final WindowManagerService mService; |
| 59 | private final RemoteAnimationAdapter mRemoteAnimationAdapter; |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 60 | private final ArrayList<RemoteAnimationRecord> mPendingAnimations = new ArrayList<>(); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 61 | private final ArrayList<WallpaperAnimationAdapter> mPendingWallpaperAnimations = |
| 62 | new ArrayList<>(); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 63 | private final Rect mTmpRect = new Rect(); |
| 64 | private final Handler mHandler; |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 65 | private final Runnable mTimeoutRunnable = () -> cancelAnimation("timeoutRunnable"); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 66 | |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 67 | private FinishedCallback mFinishedCallback; |
| 68 | private boolean mCanceled; |
Adrian Roos | 653c6c1 | 2018-04-09 14:12:46 -0700 | [diff] [blame] | 69 | private boolean mLinkedToDeathOfRunner; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 70 | |
| 71 | RemoteAnimationController(WindowManagerService service, |
| 72 | RemoteAnimationAdapter remoteAnimationAdapter, Handler handler) { |
| 73 | mService = service; |
| 74 | mRemoteAnimationAdapter = remoteAnimationAdapter; |
| 75 | mHandler = handler; |
| 76 | } |
| 77 | |
| 78 | /** |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 79 | * Creates an animation record for each individual {@link WindowContainer}. |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 80 | * |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 81 | * @param windowContainer The windows to animate. |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 82 | * @param position The position app bounds, in screen coordinates. |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 83 | * @param localBounds The bounds of the app relative to its parent. |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 84 | * @param stackBounds The stack bounds of the app relative to position. |
| 85 | * @param startBounds The stack bounds before the transition, in screen coordinates |
| 86 | * @return The record representing animation(s) to run on the app. |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 87 | */ |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 88 | RemoteAnimationRecord createRemoteAnimationRecord(WindowContainer windowContainer, |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 89 | Point position, Rect localBounds, Rect stackBounds, Rect startBounds) { |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 90 | ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "createAnimationAdapter(): container=%s", |
| 91 | windowContainer); |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 92 | final RemoteAnimationRecord adapters = new RemoteAnimationRecord(windowContainer, position, |
| 93 | localBounds, stackBounds, startBounds); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 94 | mPendingAnimations.add(adapters); |
| 95 | return adapters; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Called when the transition is ready to be started, and all leashes have been set up. |
| 100 | */ |
| 101 | void goodToGo() { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 102 | ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "goodToGo()"); |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 103 | if (mPendingAnimations.isEmpty() || mCanceled) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 104 | ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, |
| 105 | "goodToGo(): Animation finished already, canceled=%s mPendingAnimations=%d", |
| 106 | mCanceled, mPendingAnimations.size()); |
Jorim Jaggi | 93f9fe3 | 2018-01-25 15:06:13 +0100 | [diff] [blame] | 107 | onAnimationFinished(); |
| 108 | return; |
| 109 | } |
Jorim Jaggi | a19d781 | 2018-02-01 15:03:59 +0100 | [diff] [blame] | 110 | |
| 111 | // Scale the timeout with the animator scale the controlling app is using. |
| 112 | mHandler.postDelayed(mTimeoutRunnable, |
| 113 | (long) (TIMEOUT_MS * mService.getCurrentAnimatorScale())); |
Jorim Jaggi | 91f9f348 | 2018-02-14 10:58:26 -0800 | [diff] [blame] | 114 | mFinishedCallback = new FinishedCallback(this); |
Chavi Weingarten | 16d0d07 | 2018-02-12 23:50:28 +0000 | [diff] [blame] | 115 | |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 116 | // Create the app targets |
| 117 | final RemoteAnimationTarget[] appTargets = createAppAnimations(); |
| 118 | if (appTargets.length == 0) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 119 | ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "goodToGo(): No apps to animate"); |
Jorim Jaggi | c4d29f2 | 2018-03-22 16:30:56 +0100 | [diff] [blame] | 120 | onAnimationFinished(); |
| 121 | return; |
| 122 | } |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 123 | |
| 124 | // Create the remote wallpaper animation targets (if any) |
| 125 | final RemoteAnimationTarget[] wallpaperTargets = createWallpaperAnimations(); |
Chavi Weingarten | 16d0d07 | 2018-02-12 23:50:28 +0000 | [diff] [blame] | 126 | mService.mAnimator.addAfterPrepareSurfacesRunnable(() -> { |
| 127 | try { |
Adrian Roos | 653c6c1 | 2018-04-09 14:12:46 -0700 | [diff] [blame] | 128 | linkToDeathOfRunner(); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 129 | mRemoteAnimationAdapter.getRunner().onAnimationStart(appTargets, wallpaperTargets, |
| 130 | mFinishedCallback); |
Chavi Weingarten | 16d0d07 | 2018-02-12 23:50:28 +0000 | [diff] [blame] | 131 | } catch (RemoteException e) { |
| 132 | Slog.e(TAG, "Failed to start remote animation", e); |
| 133 | onAnimationFinished(); |
| 134 | } |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 135 | if (ProtoLogImpl.isEnabled(WM_DEBUG_REMOTE_ANIMATIONS)) { |
| 136 | ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "startAnimation(): Notify animation start:"); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 137 | writeStartDebugStatement(); |
| 138 | } |
Chavi Weingarten | 16d0d07 | 2018-02-12 23:50:28 +0000 | [diff] [blame] | 139 | }); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 140 | setRunningRemoteAnimation(true); |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 141 | } |
| 142 | |
Arthur Hung | 442aff2 | 2019-05-07 19:49:31 +0800 | [diff] [blame] | 143 | void cancelAnimation(String reason) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 144 | ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "cancelAnimation(): reason=%s", reason); |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 145 | synchronized (mService.getWindowManagerLock()) { |
| 146 | if (mCanceled) { |
| 147 | return; |
| 148 | } |
| 149 | mCanceled = true; |
| 150 | } |
| 151 | onAnimationFinished(); |
| 152 | invokeAnimationCancelled(); |
| 153 | } |
| 154 | |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 155 | private void writeStartDebugStatement() { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 156 | ProtoLog.i(WM_DEBUG_REMOTE_ANIMATIONS, "Starting remote animation"); |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 157 | final StringWriter sw = new StringWriter(); |
| 158 | final FastPrintWriter pw = new FastPrintWriter(sw); |
| 159 | for (int i = mPendingAnimations.size() - 1; i >= 0; i--) { |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 160 | mPendingAnimations.get(i).mAdapter.dump(pw, ""); |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 161 | } |
| 162 | pw.close(); |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 163 | ProtoLog.i(WM_DEBUG_REMOTE_ANIMATIONS, "%s", sw.toString()); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 164 | } |
| 165 | |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 166 | private RemoteAnimationTarget[] createAppAnimations() { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 167 | ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "createAppAnimations()"); |
Jorim Jaggi | 1777021 | 2018-01-22 20:01:21 +0100 | [diff] [blame] | 168 | final ArrayList<RemoteAnimationTarget> targets = new ArrayList<>(); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 169 | for (int i = mPendingAnimations.size() - 1; i >= 0; i--) { |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 170 | final RemoteAnimationRecord wrappers = mPendingAnimations.get(i); |
| 171 | final RemoteAnimationTarget target = wrappers.createRemoteAnimationTarget(); |
Jorim Jaggi | 1777021 | 2018-01-22 20:01:21 +0100 | [diff] [blame] | 172 | if (target != null) { |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 173 | ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "\tAdd container=%s", |
| 174 | wrappers.mWindowContainer); |
Jorim Jaggi | 1777021 | 2018-01-22 20:01:21 +0100 | [diff] [blame] | 175 | targets.add(target); |
Jorim Jaggi | c4d29f2 | 2018-03-22 16:30:56 +0100 | [diff] [blame] | 176 | } else { |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 177 | ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "\tRemove container=%s", |
| 178 | wrappers.mWindowContainer); |
Jorim Jaggi | b8a9cbe | 2018-03-27 18:02:18 +0200 | [diff] [blame] | 179 | |
| 180 | // We can't really start an animation but we still need to make sure to finish the |
| 181 | // pending animation that was started by SurfaceAnimator |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 182 | if (wrappers.mAdapter != null |
| 183 | && wrappers.mAdapter.mCapturedFinishCallback != null) { |
| 184 | wrappers.mAdapter.mCapturedFinishCallback |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 185 | .onAnimationFinished(wrappers.mAdapter.mAnimationType, |
| 186 | wrappers.mAdapter); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 187 | } |
| 188 | if (wrappers.mThumbnailAdapter != null |
| 189 | && wrappers.mThumbnailAdapter.mCapturedFinishCallback != null) { |
| 190 | wrappers.mThumbnailAdapter.mCapturedFinishCallback |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 191 | .onAnimationFinished(wrappers.mAdapter.mAnimationType, |
| 192 | wrappers.mThumbnailAdapter); |
Jorim Jaggi | b8a9cbe | 2018-03-27 18:02:18 +0200 | [diff] [blame] | 193 | } |
Jorim Jaggi | c4d29f2 | 2018-03-22 16:30:56 +0100 | [diff] [blame] | 194 | mPendingAnimations.remove(i); |
Jorim Jaggi | 1777021 | 2018-01-22 20:01:21 +0100 | [diff] [blame] | 195 | } |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 196 | } |
Jorim Jaggi | 1777021 | 2018-01-22 20:01:21 +0100 | [diff] [blame] | 197 | return targets.toArray(new RemoteAnimationTarget[targets.size()]); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 198 | } |
| 199 | |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 200 | private RemoteAnimationTarget[] createWallpaperAnimations() { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 201 | ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "createWallpaperAnimations()"); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 202 | return WallpaperAnimationAdapter.startWallpaperAnimations(mService, |
| 203 | mRemoteAnimationAdapter.getDuration(), |
| 204 | mRemoteAnimationAdapter.getStatusBarTransitionDelay(), |
| 205 | adapter -> { |
| 206 | synchronized (mService.mGlobalLock) { |
| 207 | // If the wallpaper animation is canceled, continue with the app animation |
| 208 | mPendingWallpaperAnimations.remove(adapter); |
| 209 | } |
| 210 | }, mPendingWallpaperAnimations); |
| 211 | } |
| 212 | |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 213 | private void onAnimationFinished() { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 214 | ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "onAnimationFinished(): mPendingAnimations=%d", |
| 215 | mPendingAnimations.size()); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 216 | mHandler.removeCallbacks(mTimeoutRunnable); |
Wale Ogunwale | db485de | 2018-10-29 09:47:07 -0700 | [diff] [blame] | 217 | synchronized (mService.mGlobalLock) { |
Adrian Roos | 653c6c1 | 2018-04-09 14:12:46 -0700 | [diff] [blame] | 218 | unlinkToDeathOfRunner(); |
Jorim Jaggi | 91f9f348 | 2018-02-14 10:58:26 -0800 | [diff] [blame] | 219 | releaseFinishedCallback(); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 220 | mService.openSurfaceTransaction(); |
| 221 | try { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 222 | ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, |
Winson Chung | 703719b | 2018-04-18 17:53:15 -0700 | [diff] [blame] | 223 | "onAnimationFinished(): Notify animation finished:"); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 224 | for (int i = mPendingAnimations.size() - 1; i >= 0; i--) { |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 225 | final RemoteAnimationRecord adapters = mPendingAnimations.get(i); |
| 226 | if (adapters.mAdapter != null) { |
| 227 | adapters.mAdapter.mCapturedFinishCallback |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 228 | .onAnimationFinished(adapters.mAdapter.mAnimationType, |
| 229 | adapters.mAdapter); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 230 | } |
| 231 | if (adapters.mThumbnailAdapter != null) { |
| 232 | adapters.mThumbnailAdapter.mCapturedFinishCallback |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 233 | .onAnimationFinished(adapters.mAdapter.mAnimationType, |
| 234 | adapters.mThumbnailAdapter); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 235 | } |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 236 | mPendingAnimations.remove(i); |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 237 | ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "\tcontainer=%s", |
| 238 | adapters.mWindowContainer); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | for (int i = mPendingWallpaperAnimations.size() - 1; i >= 0; i--) { |
| 242 | final WallpaperAnimationAdapter adapter = mPendingWallpaperAnimations.get(i); |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 243 | adapter.getLeashFinishedCallback().onAnimationFinished( |
| 244 | adapter.getLastAnimationType(), adapter); |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 245 | mPendingWallpaperAnimations.remove(i); |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 246 | ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "\twallpaper=%s", adapter.getToken()); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 247 | } |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 248 | } catch (Exception e) { |
| 249 | Slog.e(TAG, "Failed to finish remote animation", e); |
| 250 | throw e; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 251 | } finally { |
| 252 | mService.closeSurfaceTransaction("RemoteAnimationController#finished"); |
| 253 | } |
| 254 | } |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 255 | setRunningRemoteAnimation(false); |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 256 | ProtoLog.i(WM_DEBUG_REMOTE_ANIMATIONS, "Finishing remote animation"); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | private void invokeAnimationCancelled() { |
| 260 | try { |
| 261 | mRemoteAnimationAdapter.getRunner().onAnimationCancelled(); |
| 262 | } catch (RemoteException e) { |
| 263 | Slog.e(TAG, "Failed to notify cancel", e); |
| 264 | } |
| 265 | } |
| 266 | |
Jorim Jaggi | 91f9f348 | 2018-02-14 10:58:26 -0800 | [diff] [blame] | 267 | private void releaseFinishedCallback() { |
| 268 | if (mFinishedCallback != null) { |
| 269 | mFinishedCallback.release(); |
| 270 | mFinishedCallback = null; |
| 271 | } |
| 272 | } |
| 273 | |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 274 | private void setRunningRemoteAnimation(boolean running) { |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 275 | final int pid = mRemoteAnimationAdapter.getCallingPid(); |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 276 | final int uid = mRemoteAnimationAdapter.getCallingUid(); |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 277 | if (pid == 0) { |
| 278 | throw new RuntimeException("Calling pid of remote animation was null"); |
| 279 | } |
Jorim Jaggi | 589c5ba | 2019-07-30 16:50:13 +0200 | [diff] [blame] | 280 | final WindowProcessController wpc = mService.mAtmService.getProcessController(pid, uid); |
| 281 | if (wpc == null) { |
| 282 | Slog.w(TAG, "Unable to find process with pid=" + pid + " uid=" + uid); |
| 283 | return; |
| 284 | } |
| 285 | wpc.setRunningRemoteAnimation(running); |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 286 | } |
| 287 | |
Adrian Roos | 653c6c1 | 2018-04-09 14:12:46 -0700 | [diff] [blame] | 288 | private void linkToDeathOfRunner() throws RemoteException { |
| 289 | if (!mLinkedToDeathOfRunner) { |
| 290 | mRemoteAnimationAdapter.getRunner().asBinder().linkToDeath(this, 0); |
| 291 | mLinkedToDeathOfRunner = true; |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | private void unlinkToDeathOfRunner() { |
| 296 | if (mLinkedToDeathOfRunner) { |
| 297 | mRemoteAnimationAdapter.getRunner().asBinder().unlinkToDeath(this, 0); |
| 298 | mLinkedToDeathOfRunner = false; |
| 299 | } |
| 300 | } |
| 301 | |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 302 | @Override |
| 303 | public void binderDied() { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 304 | cancelAnimation("binderDied"); |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 305 | } |
| 306 | |
Jorim Jaggi | 91f9f348 | 2018-02-14 10:58:26 -0800 | [diff] [blame] | 307 | private static final class FinishedCallback extends IRemoteAnimationFinishedCallback.Stub { |
| 308 | |
| 309 | RemoteAnimationController mOuter; |
| 310 | |
| 311 | FinishedCallback(RemoteAnimationController outer) { |
| 312 | mOuter = outer; |
| 313 | } |
| 314 | |
| 315 | @Override |
| 316 | public void onAnimationFinished() throws RemoteException { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 317 | ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "app-onAnimationFinished(): mOuter=%s", mOuter); |
Jorim Jaggi | ab20e16 | 2018-03-27 13:06:09 +0200 | [diff] [blame] | 318 | final long token = Binder.clearCallingIdentity(); |
| 319 | try { |
| 320 | if (mOuter != null) { |
| 321 | mOuter.onAnimationFinished(); |
Jorim Jaggi | 91f9f348 | 2018-02-14 10:58:26 -0800 | [diff] [blame] | 322 | |
Jorim Jaggi | ab20e16 | 2018-03-27 13:06:09 +0200 | [diff] [blame] | 323 | // In case the client holds on to the finish callback, make sure we don't leak |
| 324 | // RemoteAnimationController which in turn would leak the runner on the client. |
| 325 | mOuter = null; |
| 326 | } |
| 327 | } finally { |
| 328 | Binder.restoreCallingIdentity(token); |
Jorim Jaggi | 91f9f348 | 2018-02-14 10:58:26 -0800 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Marks this callback as not be used anymore by releasing the reference to the outer class |
| 334 | * to prevent memory leak. |
| 335 | */ |
| 336 | void release() { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 337 | ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "app-release(): mOuter=%s", mOuter); |
Jorim Jaggi | 91f9f348 | 2018-02-14 10:58:26 -0800 | [diff] [blame] | 338 | mOuter = null; |
| 339 | } |
| 340 | }; |
| 341 | |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 342 | /** |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 343 | * Contains information about a remote-animation for one WindowContainer. This keeps track of, |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 344 | * potentially, multiple animating surfaces (AdapterWrappers) associated with one |
| 345 | * Window/Transition. For example, a change transition has an adapter controller for the |
| 346 | * main window and an adapter controlling the start-state snapshot. |
| 347 | * <p> |
| 348 | * This can be thought of as a bridge between the information that the remote animator sees (via |
| 349 | * {@link RemoteAnimationTarget}) and what the server sees (the |
| 350 | * {@link RemoteAnimationAdapterWrapper}(s) interfacing with the moving surfaces). |
| 351 | */ |
| 352 | public class RemoteAnimationRecord { |
| 353 | RemoteAnimationAdapterWrapper mAdapter; |
| 354 | RemoteAnimationAdapterWrapper mThumbnailAdapter = null; |
| 355 | RemoteAnimationTarget mTarget; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 356 | final WindowContainer mWindowContainer; |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 357 | final Rect mStartBounds; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 358 | |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 359 | RemoteAnimationRecord(WindowContainer windowContainer, Point endPos, Rect localBounds, |
| 360 | Rect endBounds, Rect startBounds) { |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 361 | mWindowContainer = windowContainer; |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 362 | mAdapter = new RemoteAnimationAdapterWrapper(this, endPos, localBounds, endBounds); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 363 | if (startBounds != null) { |
| 364 | mStartBounds = new Rect(startBounds); |
| 365 | mTmpRect.set(startBounds); |
| 366 | mTmpRect.offsetTo(0, 0); |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 367 | if (mRemoteAnimationAdapter.getChangeNeedsSnapshot()) { |
| 368 | mThumbnailAdapter = |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 369 | new RemoteAnimationAdapterWrapper(this, new Point(0, 0), localBounds, |
| 370 | mTmpRect); |
Evan Rosky | 966759f | 2019-01-15 10:33:58 -0800 | [diff] [blame] | 371 | } |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 372 | } else { |
| 373 | mStartBounds = null; |
| 374 | } |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 375 | } |
| 376 | |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 377 | RemoteAnimationTarget createRemoteAnimationTarget() { |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 378 | if (mAdapter == null |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 379 | || mAdapter.mCapturedFinishCallback == null |
| 380 | || mAdapter.mCapturedLeash == null) { |
Jorim Jaggi | 1777021 | 2018-01-22 20:01:21 +0100 | [diff] [blame] | 381 | return null; |
| 382 | } |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 383 | mTarget = mWindowContainer.createRemoteAnimationTarget(this); |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 384 | return mTarget; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 385 | } |
| 386 | |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 387 | int getMode() { |
| 388 | final DisplayContent dc = mWindowContainer.getDisplayContent(); |
lumark | 5341d1c | 2019-12-14 01:54:02 +0800 | [diff] [blame] | 389 | final ActivityRecord topActivity = mWindowContainer.getTopMostActivity(); |
| 390 | if (dc.mOpeningApps.contains(topActivity)) { |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 391 | return RemoteAnimationTarget.MODE_OPENING; |
Evan Rosky | 55bddd8 | 2020-01-29 13:07:18 -0800 | [diff] [blame] | 392 | } else if (dc.mChangingContainers.contains(topActivity)) { |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 393 | return RemoteAnimationTarget.MODE_CHANGING; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 394 | } else { |
| 395 | return RemoteAnimationTarget.MODE_CLOSING; |
| 396 | } |
| 397 | } |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 398 | } |
| 399 | |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 400 | class RemoteAnimationAdapterWrapper implements AnimationAdapter { |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 401 | private final RemoteAnimationRecord mRecord; |
| 402 | SurfaceControl mCapturedLeash; |
| 403 | private OnAnimationFinishedCallback mCapturedFinishCallback; |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 404 | private @AnimationType int mAnimationType; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 405 | final Point mPosition = new Point(); |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 406 | final Rect mLocalBounds; |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 407 | final Rect mStackBounds = new Rect(); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 408 | |
| 409 | RemoteAnimationAdapterWrapper(RemoteAnimationRecord record, Point position, |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 410 | Rect localBounds, Rect stackBounds) { |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 411 | mRecord = record; |
| 412 | mPosition.set(position.x, position.y); |
lumark | 2ec1912 | 2020-01-23 00:09:04 +0800 | [diff] [blame] | 413 | mLocalBounds = localBounds; |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 414 | mStackBounds.set(stackBounds); |
| 415 | } |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 416 | |
| 417 | @Override |
Jorim Jaggi | 82c1786 | 2018-02-21 17:50:18 +0100 | [diff] [blame] | 418 | public boolean getShowWallpaper() { |
| 419 | return false; |
| 420 | } |
| 421 | |
| 422 | @Override |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 423 | public void startAnimation(SurfaceControl animationLeash, Transaction t, |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 424 | @AnimationType int type, OnAnimationFinishedCallback finishCallback) { |
Adrian Roos | b125e0b | 2019-10-02 14:55:14 +0200 | [diff] [blame] | 425 | ProtoLog.d(WM_DEBUG_REMOTE_ANIMATIONS, "startAnimation"); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 426 | |
| 427 | // Restore z-layering, position and stack crop until client has a chance to modify it. |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 428 | t.setLayer(animationLeash, mRecord.mWindowContainer.getPrefixOrderIndex()); |
Evan Rosky | b96326e | 2019-07-01 09:59:17 -0700 | [diff] [blame] | 429 | if (mRecord.mStartBounds != null) { |
| 430 | t.setPosition(animationLeash, mRecord.mStartBounds.left, mRecord.mStartBounds.top); |
| 431 | t.setWindowCrop(animationLeash, mRecord.mStartBounds.width(), |
| 432 | mRecord.mStartBounds.height()); |
| 433 | } else { |
| 434 | t.setPosition(animationLeash, mPosition.x, mPosition.y); |
| 435 | t.setWindowCrop(animationLeash, mStackBounds.width(), mStackBounds.height()); |
| 436 | } |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 437 | mCapturedLeash = animationLeash; |
| 438 | mCapturedFinishCallback = finishCallback; |
Issei Suzuki | 8b995df | 2020-01-08 12:23:04 +0100 | [diff] [blame] | 439 | mAnimationType = type; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | @Override |
| 443 | public void onAnimationCancelled(SurfaceControl animationLeash) { |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 444 | if (mRecord.mAdapter == this) { |
| 445 | mRecord.mAdapter = null; |
| 446 | } else { |
| 447 | mRecord.mThumbnailAdapter = null; |
| 448 | } |
| 449 | if (mRecord.mAdapter == null && mRecord.mThumbnailAdapter == null) { |
| 450 | mPendingAnimations.remove(mRecord); |
| 451 | } |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 452 | if (mPendingAnimations.isEmpty()) { |
Winson Chung | d585219 | 2019-09-06 17:20:28 -0700 | [diff] [blame] | 453 | cancelAnimation("allAppAnimationsCanceled"); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 454 | } |
| 455 | } |
| 456 | |
| 457 | @Override |
| 458 | public long getDurationHint() { |
| 459 | return mRemoteAnimationAdapter.getDuration(); |
| 460 | } |
| 461 | |
| 462 | @Override |
| 463 | public long getStatusBarTransitionsStartTime() { |
| 464 | return SystemClock.uptimeMillis() |
| 465 | + mRemoteAnimationAdapter.getStatusBarTransitionDelay(); |
| 466 | } |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 467 | |
| 468 | @Override |
| 469 | public void dump(PrintWriter pw, String prefix) { |
lumark | 19a5d2e | 2019-10-11 16:19:30 +0800 | [diff] [blame] | 470 | pw.print(prefix); pw.print("container="); pw.println(mRecord.mWindowContainer); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 471 | if (mRecord.mTarget != null) { |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 472 | pw.print(prefix); pw.println("Target:"); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 473 | mRecord.mTarget.dump(pw, prefix + " "); |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 474 | } else { |
| 475 | pw.print(prefix); pw.println("Target: null"); |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | @Override |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 480 | public void dumpDebug(ProtoOutputStream proto) { |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 481 | final long token = proto.start(REMOTE); |
Evan Rosky | 2289ba1 | 2018-11-19 18:28:18 -0800 | [diff] [blame] | 482 | if (mRecord.mTarget != null) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 483 | mRecord.mTarget.dumpDebug(proto, TARGET); |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 484 | } |
| 485 | proto.end(token); |
| 486 | } |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 487 | } |
| 488 | } |