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; |
| 20 | import static com.android.server.wm.RemoteAnimationAdapterWrapperProto.TARGET; |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 21 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS; |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 22 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_REMOTE_ANIMATIONS; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 23 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 24 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
| 25 | |
| 26 | import android.graphics.Point; |
| 27 | import android.graphics.Rect; |
Jorim Jaggi | ab20e16 | 2018-03-27 13:06:09 +0200 | [diff] [blame] | 28 | import android.os.Binder; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 29 | import android.os.Handler; |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 30 | import android.os.IBinder.DeathRecipient; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 31 | import android.os.RemoteException; |
| 32 | import android.os.SystemClock; |
| 33 | import android.util.Slog; |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 34 | import android.util.proto.ProtoOutputStream; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 35 | import android.view.IRemoteAnimationFinishedCallback; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 36 | import android.view.RemoteAnimationAdapter; |
| 37 | import android.view.RemoteAnimationTarget; |
| 38 | import android.view.SurfaceControl; |
| 39 | import android.view.SurfaceControl.Transaction; |
| 40 | |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 41 | import com.android.internal.util.FastPrintWriter; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 42 | import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback; |
Jorim Jaggi | 817ebdd | 2018-03-26 15:46:01 +0200 | [diff] [blame] | 43 | import com.android.server.wm.utils.InsetUtils; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 44 | |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 45 | import java.io.PrintWriter; |
| 46 | import java.io.StringWriter; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 47 | import java.util.ArrayList; |
| 48 | |
| 49 | /** |
| 50 | * Helper class to run app animations in a remote process. |
| 51 | */ |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 52 | class RemoteAnimationController implements DeathRecipient { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 53 | private static final String TAG = TAG_WITH_CLASS_NAME |
| 54 | || (DEBUG_REMOTE_ANIMATIONS && !DEBUG_APP_TRANSITIONS) |
| 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; |
| 60 | private final ArrayList<RemoteAnimationAdapterWrapper> mPendingAnimations = new ArrayList<>(); |
| 61 | private final Rect mTmpRect = new Rect(); |
| 62 | private final Handler mHandler; |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 63 | private final Runnable mTimeoutRunnable = () -> cancelAnimation("timeoutRunnable"); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 64 | |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 65 | private FinishedCallback mFinishedCallback; |
| 66 | private boolean mCanceled; |
Adrian Roos | 653c6c1 | 2018-04-09 14:12:46 -0700 | [diff] [blame] | 67 | private boolean mLinkedToDeathOfRunner; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 68 | |
| 69 | RemoteAnimationController(WindowManagerService service, |
| 70 | RemoteAnimationAdapter remoteAnimationAdapter, Handler handler) { |
| 71 | mService = service; |
| 72 | mRemoteAnimationAdapter = remoteAnimationAdapter; |
| 73 | mHandler = handler; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Creates an animation for each individual {@link AppWindowToken}. |
| 78 | * |
| 79 | * @param appWindowToken The app to animate. |
| 80 | * @param position The position app bounds, in screen coordinates. |
| 81 | * @param stackBounds The stack bounds of the app. |
| 82 | * @return The adapter to be run on the app. |
| 83 | */ |
| 84 | AnimationAdapter createAnimationAdapter(AppWindowToken appWindowToken, Point position, |
| 85 | Rect stackBounds) { |
Winson Chung | 703719b | 2018-04-18 17:53:15 -0700 | [diff] [blame] | 86 | if (DEBUG_REMOTE_ANIMATIONS) Slog.d(TAG, "createAnimationAdapter(): token=" |
| 87 | + appWindowToken); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 88 | final RemoteAnimationAdapterWrapper adapter = new RemoteAnimationAdapterWrapper( |
| 89 | appWindowToken, position, stackBounds); |
| 90 | mPendingAnimations.add(adapter); |
| 91 | return adapter; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Called when the transition is ready to be started, and all leashes have been set up. |
| 96 | */ |
| 97 | void goodToGo() { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 98 | if (DEBUG_REMOTE_ANIMATIONS) Slog.d(TAG, "goodToGo()"); |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 99 | if (mPendingAnimations.isEmpty() || mCanceled) { |
Winson Chung | 703719b | 2018-04-18 17:53:15 -0700 | [diff] [blame] | 100 | if (DEBUG_REMOTE_ANIMATIONS) Slog.d(TAG, "goodToGo(): Animation finished already," |
| 101 | + " canceled=" + mCanceled |
| 102 | + " mPendingAnimations=" + mPendingAnimations.size()); |
Jorim Jaggi | 93f9fe3 | 2018-01-25 15:06:13 +0100 | [diff] [blame] | 103 | onAnimationFinished(); |
| 104 | return; |
| 105 | } |
Jorim Jaggi | a19d781 | 2018-02-01 15:03:59 +0100 | [diff] [blame] | 106 | |
| 107 | // Scale the timeout with the animator scale the controlling app is using. |
| 108 | mHandler.postDelayed(mTimeoutRunnable, |
| 109 | (long) (TIMEOUT_MS * mService.getCurrentAnimatorScale())); |
Jorim Jaggi | 91f9f348 | 2018-02-14 10:58:26 -0800 | [diff] [blame] | 110 | mFinishedCallback = new FinishedCallback(this); |
Chavi Weingarten | 16d0d07 | 2018-02-12 23:50:28 +0000 | [diff] [blame] | 111 | |
| 112 | final RemoteAnimationTarget[] animations = createAnimations(); |
Jorim Jaggi | c4d29f2 | 2018-03-22 16:30:56 +0100 | [diff] [blame] | 113 | if (animations.length == 0) { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 114 | if (DEBUG_REMOTE_ANIMATIONS) Slog.d(TAG, "goodToGo(): No apps to animate"); |
Jorim Jaggi | c4d29f2 | 2018-03-22 16:30:56 +0100 | [diff] [blame] | 115 | onAnimationFinished(); |
| 116 | return; |
| 117 | } |
Chavi Weingarten | 16d0d07 | 2018-02-12 23:50:28 +0000 | [diff] [blame] | 118 | mService.mAnimator.addAfterPrepareSurfacesRunnable(() -> { |
| 119 | try { |
Adrian Roos | 653c6c1 | 2018-04-09 14:12:46 -0700 | [diff] [blame] | 120 | linkToDeathOfRunner(); |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 121 | mRemoteAnimationAdapter.getRunner().onAnimationStart(animations, mFinishedCallback); |
Chavi Weingarten | 16d0d07 | 2018-02-12 23:50:28 +0000 | [diff] [blame] | 122 | } catch (RemoteException e) { |
| 123 | Slog.e(TAG, "Failed to start remote animation", e); |
| 124 | onAnimationFinished(); |
| 125 | } |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 126 | if (DEBUG_REMOTE_ANIMATIONS) { |
| 127 | Slog.d(TAG, "startAnimation(): Notify animation start:"); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 128 | writeStartDebugStatement(); |
| 129 | } |
Chavi Weingarten | 16d0d07 | 2018-02-12 23:50:28 +0000 | [diff] [blame] | 130 | }); |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 131 | sendRunningRemoteAnimation(true); |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 132 | } |
| 133 | |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 134 | private void cancelAnimation(String reason) { |
| 135 | if (DEBUG_REMOTE_ANIMATIONS) Slog.d(TAG, "cancelAnimation(): reason=" + reason); |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 136 | synchronized (mService.getWindowManagerLock()) { |
| 137 | if (mCanceled) { |
| 138 | return; |
| 139 | } |
| 140 | mCanceled = true; |
| 141 | } |
| 142 | onAnimationFinished(); |
| 143 | invokeAnimationCancelled(); |
| 144 | } |
| 145 | |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 146 | private void writeStartDebugStatement() { |
| 147 | Slog.i(TAG, "Starting remote animation"); |
| 148 | final StringWriter sw = new StringWriter(); |
| 149 | final FastPrintWriter pw = new FastPrintWriter(sw); |
| 150 | for (int i = mPendingAnimations.size() - 1; i >= 0; i--) { |
| 151 | mPendingAnimations.get(i).dump(pw, ""); |
| 152 | } |
| 153 | pw.close(); |
| 154 | Slog.i(TAG, sw.toString()); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | private RemoteAnimationTarget[] createAnimations() { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 158 | if (DEBUG_REMOTE_ANIMATIONS) Slog.d(TAG, "createAnimations()"); |
Jorim Jaggi | 1777021 | 2018-01-22 20:01:21 +0100 | [diff] [blame] | 159 | final ArrayList<RemoteAnimationTarget> targets = new ArrayList<>(); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 160 | for (int i = mPendingAnimations.size() - 1; i >= 0; i--) { |
Jorim Jaggi | b8a9cbe | 2018-03-27 18:02:18 +0200 | [diff] [blame] | 161 | final RemoteAnimationAdapterWrapper wrapper = mPendingAnimations.get(i); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 162 | final RemoteAnimationTarget target = wrapper.createRemoteAppAnimation(); |
Jorim Jaggi | 1777021 | 2018-01-22 20:01:21 +0100 | [diff] [blame] | 163 | if (target != null) { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 164 | if (DEBUG_REMOTE_ANIMATIONS) Slog.d(TAG, "\tAdd token=" + wrapper.mAppWindowToken); |
Jorim Jaggi | 1777021 | 2018-01-22 20:01:21 +0100 | [diff] [blame] | 165 | targets.add(target); |
Jorim Jaggi | c4d29f2 | 2018-03-22 16:30:56 +0100 | [diff] [blame] | 166 | } else { |
Winson Chung | 703719b | 2018-04-18 17:53:15 -0700 | [diff] [blame] | 167 | if (DEBUG_REMOTE_ANIMATIONS) Slog.d(TAG, "\tRemove token=" |
| 168 | + wrapper.mAppWindowToken); |
Jorim Jaggi | b8a9cbe | 2018-03-27 18:02:18 +0200 | [diff] [blame] | 169 | |
| 170 | // We can't really start an animation but we still need to make sure to finish the |
| 171 | // pending animation that was started by SurfaceAnimator |
| 172 | if (wrapper.mCapturedFinishCallback != null) { |
| 173 | wrapper.mCapturedFinishCallback.onAnimationFinished(wrapper); |
| 174 | } |
Jorim Jaggi | c4d29f2 | 2018-03-22 16:30:56 +0100 | [diff] [blame] | 175 | mPendingAnimations.remove(i); |
Jorim Jaggi | 1777021 | 2018-01-22 20:01:21 +0100 | [diff] [blame] | 176 | } |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 177 | } |
Jorim Jaggi | 1777021 | 2018-01-22 20:01:21 +0100 | [diff] [blame] | 178 | return targets.toArray(new RemoteAnimationTarget[targets.size()]); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | private void onAnimationFinished() { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 182 | if (DEBUG_REMOTE_ANIMATIONS) Slog.d(TAG, "onAnimationFinished(): mPendingAnimations=" |
| 183 | + mPendingAnimations.size()); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 184 | mHandler.removeCallbacks(mTimeoutRunnable); |
| 185 | synchronized (mService.mWindowMap) { |
Adrian Roos | 653c6c1 | 2018-04-09 14:12:46 -0700 | [diff] [blame] | 186 | unlinkToDeathOfRunner(); |
Jorim Jaggi | 91f9f348 | 2018-02-14 10:58:26 -0800 | [diff] [blame] | 187 | releaseFinishedCallback(); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 188 | mService.openSurfaceTransaction(); |
| 189 | try { |
Winson Chung | 703719b | 2018-04-18 17:53:15 -0700 | [diff] [blame] | 190 | if (DEBUG_REMOTE_ANIMATIONS) Slog.d(TAG, |
| 191 | "onAnimationFinished(): Notify animation finished:"); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 192 | for (int i = mPendingAnimations.size() - 1; i >= 0; i--) { |
| 193 | final RemoteAnimationAdapterWrapper adapter = mPendingAnimations.get(i); |
| 194 | adapter.mCapturedFinishCallback.onAnimationFinished(adapter); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 195 | if (DEBUG_REMOTE_ANIMATIONS) Slog.d(TAG, "\t" + adapter.mAppWindowToken); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 196 | } |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 197 | } catch (Exception e) { |
| 198 | Slog.e(TAG, "Failed to finish remote animation", e); |
| 199 | throw e; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 200 | } finally { |
| 201 | mService.closeSurfaceTransaction("RemoteAnimationController#finished"); |
| 202 | } |
| 203 | } |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 204 | sendRunningRemoteAnimation(false); |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 205 | if (DEBUG_REMOTE_ANIMATIONS) Slog.i(TAG, "Finishing remote animation"); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | private void invokeAnimationCancelled() { |
| 209 | try { |
| 210 | mRemoteAnimationAdapter.getRunner().onAnimationCancelled(); |
| 211 | } catch (RemoteException e) { |
| 212 | Slog.e(TAG, "Failed to notify cancel", e); |
| 213 | } |
| 214 | } |
| 215 | |
Jorim Jaggi | 91f9f348 | 2018-02-14 10:58:26 -0800 | [diff] [blame] | 216 | private void releaseFinishedCallback() { |
| 217 | if (mFinishedCallback != null) { |
| 218 | mFinishedCallback.release(); |
| 219 | mFinishedCallback = null; |
| 220 | } |
| 221 | } |
| 222 | |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 223 | private void sendRunningRemoteAnimation(boolean running) { |
| 224 | final int pid = mRemoteAnimationAdapter.getCallingPid(); |
| 225 | if (pid == 0) { |
| 226 | throw new RuntimeException("Calling pid of remote animation was null"); |
| 227 | } |
| 228 | mService.sendSetRunningRemoteAnimation(pid, running); |
| 229 | } |
| 230 | |
Adrian Roos | 653c6c1 | 2018-04-09 14:12:46 -0700 | [diff] [blame] | 231 | private void linkToDeathOfRunner() throws RemoteException { |
| 232 | if (!mLinkedToDeathOfRunner) { |
| 233 | mRemoteAnimationAdapter.getRunner().asBinder().linkToDeath(this, 0); |
| 234 | mLinkedToDeathOfRunner = true; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | private void unlinkToDeathOfRunner() { |
| 239 | if (mLinkedToDeathOfRunner) { |
| 240 | mRemoteAnimationAdapter.getRunner().asBinder().unlinkToDeath(this, 0); |
| 241 | mLinkedToDeathOfRunner = false; |
| 242 | } |
| 243 | } |
| 244 | |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 245 | @Override |
| 246 | public void binderDied() { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 247 | cancelAnimation("binderDied"); |
Adrian Roos | 842e788 | 2018-03-26 17:34:06 +0200 | [diff] [blame] | 248 | } |
| 249 | |
Jorim Jaggi | 91f9f348 | 2018-02-14 10:58:26 -0800 | [diff] [blame] | 250 | private static final class FinishedCallback extends IRemoteAnimationFinishedCallback.Stub { |
| 251 | |
| 252 | RemoteAnimationController mOuter; |
| 253 | |
| 254 | FinishedCallback(RemoteAnimationController outer) { |
| 255 | mOuter = outer; |
| 256 | } |
| 257 | |
| 258 | @Override |
| 259 | public void onAnimationFinished() throws RemoteException { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 260 | if (DEBUG_REMOTE_ANIMATIONS) Slog.d(TAG, "app-onAnimationFinished(): mOuter=" + mOuter); |
Jorim Jaggi | ab20e16 | 2018-03-27 13:06:09 +0200 | [diff] [blame] | 261 | final long token = Binder.clearCallingIdentity(); |
| 262 | try { |
| 263 | if (mOuter != null) { |
| 264 | mOuter.onAnimationFinished(); |
Jorim Jaggi | 91f9f348 | 2018-02-14 10:58:26 -0800 | [diff] [blame] | 265 | |
Jorim Jaggi | ab20e16 | 2018-03-27 13:06:09 +0200 | [diff] [blame] | 266 | // In case the client holds on to the finish callback, make sure we don't leak |
| 267 | // RemoteAnimationController which in turn would leak the runner on the client. |
| 268 | mOuter = null; |
| 269 | } |
| 270 | } finally { |
| 271 | Binder.restoreCallingIdentity(token); |
Jorim Jaggi | 91f9f348 | 2018-02-14 10:58:26 -0800 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Marks this callback as not be used anymore by releasing the reference to the outer class |
| 277 | * to prevent memory leak. |
| 278 | */ |
| 279 | void release() { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 280 | if (DEBUG_REMOTE_ANIMATIONS) Slog.d(TAG, "app-release(): mOuter=" + mOuter); |
Jorim Jaggi | 91f9f348 | 2018-02-14 10:58:26 -0800 | [diff] [blame] | 281 | mOuter = null; |
| 282 | } |
| 283 | }; |
| 284 | |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 285 | private class RemoteAnimationAdapterWrapper implements AnimationAdapter { |
| 286 | |
| 287 | private final AppWindowToken mAppWindowToken; |
| 288 | private SurfaceControl mCapturedLeash; |
| 289 | private OnAnimationFinishedCallback mCapturedFinishCallback; |
| 290 | private final Point mPosition = new Point(); |
| 291 | private final Rect mStackBounds = new Rect(); |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 292 | private RemoteAnimationTarget mTarget; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 293 | |
| 294 | RemoteAnimationAdapterWrapper(AppWindowToken appWindowToken, Point position, |
| 295 | Rect stackBounds) { |
| 296 | mAppWindowToken = appWindowToken; |
| 297 | mPosition.set(position.x, position.y); |
| 298 | mStackBounds.set(stackBounds); |
| 299 | } |
| 300 | |
| 301 | RemoteAnimationTarget createRemoteAppAnimation() { |
Jorim Jaggi | 1777021 | 2018-01-22 20:01:21 +0100 | [diff] [blame] | 302 | final Task task = mAppWindowToken.getTask(); |
| 303 | final WindowState mainWindow = mAppWindowToken.findMainWindow(); |
Jorim Jaggi | c4d29f2 | 2018-03-22 16:30:56 +0100 | [diff] [blame] | 304 | if (task == null || mainWindow == null || mCapturedFinishCallback == null |
| 305 | || mCapturedLeash == null) { |
Jorim Jaggi | 1777021 | 2018-01-22 20:01:21 +0100 | [diff] [blame] | 306 | return null; |
| 307 | } |
Jorim Jaggi | 817ebdd | 2018-03-26 15:46:01 +0200 | [diff] [blame] | 308 | final Rect insets = new Rect(mainWindow.mContentInsets); |
| 309 | InsetUtils.addInsets(insets, mAppWindowToken.getLetterboxInsets()); |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 310 | mTarget = new RemoteAnimationTarget(task.mTaskId, getMode(), |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 311 | mCapturedLeash, !mAppWindowToken.fillsParent(), |
Jorim Jaggi | 817ebdd | 2018-03-26 15:46:01 +0200 | [diff] [blame] | 312 | mainWindow.mWinAnimator.mLastClipRect, insets, |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 313 | mAppWindowToken.getPrefixOrderIndex(), mPosition, mStackBounds, |
Vadim Tryshev | 593e956 | 2018-03-08 17:15:45 -0800 | [diff] [blame] | 314 | task.getWindowConfiguration(), false /*isNotInRecents*/); |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 315 | return mTarget; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | private int getMode() { |
| 319 | if (mService.mOpeningApps.contains(mAppWindowToken)) { |
| 320 | return RemoteAnimationTarget.MODE_OPENING; |
| 321 | } else { |
| 322 | return RemoteAnimationTarget.MODE_CLOSING; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | @Override |
| 327 | public boolean getDetachWallpaper() { |
| 328 | return false; |
| 329 | } |
| 330 | |
| 331 | @Override |
Jorim Jaggi | 82c1786 | 2018-02-21 17:50:18 +0100 | [diff] [blame] | 332 | public boolean getShowWallpaper() { |
| 333 | return false; |
| 334 | } |
| 335 | |
| 336 | @Override |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 337 | public int getBackgroundColor() { |
| 338 | return 0; |
| 339 | } |
| 340 | |
| 341 | @Override |
| 342 | public void startAnimation(SurfaceControl animationLeash, Transaction t, |
| 343 | OnAnimationFinishedCallback finishCallback) { |
Winson Chung | c6c3f85 | 2018-04-09 15:41:03 -0700 | [diff] [blame] | 344 | if (DEBUG_REMOTE_ANIMATIONS) Slog.d(TAG, "startAnimation"); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 345 | |
| 346 | // Restore z-layering, position and stack crop until client has a chance to modify it. |
| 347 | t.setLayer(animationLeash, mAppWindowToken.getPrefixOrderIndex()); |
| 348 | t.setPosition(animationLeash, mPosition.x, mPosition.y); |
| 349 | mTmpRect.set(mStackBounds); |
| 350 | mTmpRect.offsetTo(0, 0); |
| 351 | t.setWindowCrop(animationLeash, mTmpRect); |
| 352 | mCapturedLeash = animationLeash; |
| 353 | mCapturedFinishCallback = finishCallback; |
| 354 | } |
| 355 | |
| 356 | @Override |
| 357 | public void onAnimationCancelled(SurfaceControl animationLeash) { |
| 358 | mPendingAnimations.remove(this); |
| 359 | if (mPendingAnimations.isEmpty()) { |
| 360 | mHandler.removeCallbacks(mTimeoutRunnable); |
Jorim Jaggi | 91f9f348 | 2018-02-14 10:58:26 -0800 | [diff] [blame] | 361 | releaseFinishedCallback(); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 362 | invokeAnimationCancelled(); |
Jorim Jaggi | bc2aabe | 2018-03-08 17:27:43 +0100 | [diff] [blame] | 363 | sendRunningRemoteAnimation(false); |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | |
| 367 | @Override |
| 368 | public long getDurationHint() { |
| 369 | return mRemoteAnimationAdapter.getDuration(); |
| 370 | } |
| 371 | |
| 372 | @Override |
| 373 | public long getStatusBarTransitionsStartTime() { |
| 374 | return SystemClock.uptimeMillis() |
| 375 | + mRemoteAnimationAdapter.getStatusBarTransitionDelay(); |
| 376 | } |
Jorim Jaggi | f75d161 | 2018-02-27 15:05:21 +0100 | [diff] [blame] | 377 | |
| 378 | @Override |
| 379 | public void dump(PrintWriter pw, String prefix) { |
| 380 | pw.print(prefix); pw.print("token="); pw.println(mAppWindowToken); |
| 381 | if (mTarget != null) { |
| 382 | pw.print(prefix); pw.println("Target:"); |
| 383 | mTarget.dump(pw, prefix + " "); |
| 384 | } else { |
| 385 | pw.print(prefix); pw.println("Target: null"); |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | @Override |
| 390 | public void writeToProto(ProtoOutputStream proto) { |
| 391 | final long token = proto.start(REMOTE); |
| 392 | if (mTarget != null) { |
| 393 | mTarget.writeToProto(proto, TARGET); |
| 394 | } |
| 395 | proto.end(token); |
| 396 | } |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 397 | } |
| 398 | } |