From 401b9b661406516d6f64223e4dc5c3ec8a4e45e1 Mon Sep 17 00:00:00 2001 From: Arthur Hung Date: Tue, 16 Aug 2022 08:23:32 +0000 Subject: [PATCH 1/2] Refactor back navigation animtion (2/2) Use IBackAnimationRunner to receive the animation leashes. Use IRemoteAnimationFinishedCallback to callback when animation finished. Bug: 241808055 Test: atest BackNavigationControllerTests BackAnimationControllerTest Change-Id: I315df5079b30159fc0f6da2b568af334d14b32a0 --- .../LauncherBackAnimationController.java | 49 +++++++++++++++---- .../com/android/quickstep/SystemUiProxy.java | 25 +++------- 2 files changed, 47 insertions(+), 27 deletions(-) diff --git a/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java b/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java index 7a281dd2a7..c0c352df14 100644 --- a/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java +++ b/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java @@ -16,6 +16,8 @@ package com.android.quickstep; +import static android.view.RemoteAnimationTarget.MODE_CLOSING; + import static com.android.launcher3.AbstractFloatingView.TYPE_REBIND_SAFE; import static com.android.launcher3.BaseActivity.INVISIBLE_ALL; import static com.android.launcher3.BaseActivity.INVISIBLE_BY_PENDING_FLAGS; @@ -30,7 +32,11 @@ import android.graphics.PointF; import android.graphics.Rect; import android.graphics.RectF; import android.os.Handler; +import android.os.RemoteException; +import android.util.Log; import android.util.Pair; +import android.view.IRemoteAnimationFinishedCallback; +import android.view.IRemoteAnimationRunner; import android.view.RemoteAnimationTarget; import android.view.SurfaceControl; import android.view.animation.AnimationUtils; @@ -91,6 +97,7 @@ public class LauncherBackAnimationController { private float mBackProgress = 0; private boolean mBackInProgress = false; private IOnBackInvokedCallback mBackCallback; + private IRemoteAnimationFinishedCallback mAnimationFinishedCallback; public LauncherBackAnimationController( QuickstepLauncher launcher, @@ -136,15 +143,33 @@ public class LauncherBackAnimationController { - mBackProgress); if (!mBackInProgress) { startBack(backEvent); - } else { - updateBackProgress(mBackProgress, backEvent); } + updateBackProgress(mBackProgress, backEvent); } @Override public void onBackStarted() { } }; - SystemUiProxy.INSTANCE.get(mLauncher).setBackToLauncherCallback(mBackCallback); + + final IRemoteAnimationRunner runner = new IRemoteAnimationRunner.Stub() { + @Override + public void onAnimationStart(int transit, RemoteAnimationTarget[] apps, + RemoteAnimationTarget[] wallpapers, RemoteAnimationTarget[] nonApps, + IRemoteAnimationFinishedCallback finishedCallback) { + for (final RemoteAnimationTarget target : apps) { + if (MODE_CLOSING == target.mode) { + mBackTarget = new RemoteAnimationTargetCompat(target); + break; + } + } + mAnimationFinishedCallback = finishedCallback; + } + + @Override + public void onAnimationCancelled(boolean isKeyguardOccluded) {} + }; + + SystemUiProxy.INSTANCE.get(mLauncher).setBackToLauncherCallback(mBackCallback, runner); } private void resetPositionAnimated() { @@ -174,16 +199,13 @@ public class LauncherBackAnimationController { } private void startBack(BackEvent backEvent) { - mBackInProgress = true; - RemoteAnimationTarget appTarget = backEvent.getDepartingAnimationTarget(); - - if (appTarget == null) { + if (mBackTarget == null) { return; } - mTransaction.show(appTarget.leash).apply(); + mBackInProgress = true; + mTransaction.show(mBackTarget.leash).apply(); mTransaction.setAnimationTransaction(); - mBackTarget = new RemoteAnimationTargetCompat(appTarget); mInitialTouchPos.set(backEvent.getTouchX(), backEvent.getTouchY()); // TODO(b/218916755): Offset start rectangle in multiwindow mode. @@ -304,7 +326,14 @@ public class LauncherBackAnimationController { mInitialTouchPos.set(0, 0); mAnimatorSetInProgress = false; mSpringAnimationInProgress = false; - SystemUiProxy.INSTANCE.get(mLauncher).onBackToLauncherAnimationFinished(); + if (mAnimationFinishedCallback != null) { + try { + mAnimationFinishedCallback.onAnimationFinished(); + } catch (RemoteException e) { + Log.w("ShellBackPreview", "Failed call onBackAnimationFinished", e); + } + mAnimationFinishedCallback = null; + } } private void startTransitionAnimations(RectFSpringAnim springAnim, AnimatorSet anim) { diff --git a/quickstep/src/com/android/quickstep/SystemUiProxy.java b/quickstep/src/com/android/quickstep/SystemUiProxy.java index 30658e337f..591c1bd9f2 100644 --- a/quickstep/src/com/android/quickstep/SystemUiProxy.java +++ b/quickstep/src/com/android/quickstep/SystemUiProxy.java @@ -39,6 +39,7 @@ import android.os.Message; import android.os.RemoteException; import android.os.UserHandle; import android.util.Log; +import android.view.IRemoteAnimationRunner; import android.view.MotionEvent; import android.view.RemoteAnimationAdapter; import android.view.RemoteAnimationTarget; @@ -113,6 +114,7 @@ public class SystemUiProxy implements ISystemUiProxy { private final ArrayList mRemoteTransitions = new ArrayList<>(); private IBinder mOriginalTransactionToken = null; private IOnBackInvokedCallback mBackToLauncherCallback; + private IRemoteAnimationRunner mBackToLauncherRunner; // Used to dedupe calls to SystemUI private int mLastShelfHeight; @@ -207,7 +209,7 @@ public class SystemUiProxy implements ISystemUiProxy { registerRecentTasksListener(mRecentTasksListener); } if (mBackAnimation != null && mBackToLauncherCallback != null) { - setBackToLauncherCallback(mBackToLauncherCallback); + setBackToLauncherCallback(mBackToLauncherCallback, mBackToLauncherRunner); } } @@ -872,13 +874,15 @@ public class SystemUiProxy implements ISystemUiProxy { // /** Sets the launcher {@link android.window.IOnBackInvokedCallback} to shell */ - public void setBackToLauncherCallback(IOnBackInvokedCallback callback) { + public void setBackToLauncherCallback(IOnBackInvokedCallback callback, + IRemoteAnimationRunner runner) { mBackToLauncherCallback = callback; + mBackToLauncherRunner = runner; if (mBackAnimation == null) { return; } try { - mBackAnimation.setBackToLauncherCallback(callback); + mBackAnimation.setBackToLauncherCallback(callback, runner); } catch (RemoteException e) { Log.e(TAG, "Failed call setBackToLauncherCallback", e); } @@ -893,6 +897,7 @@ public class SystemUiProxy implements ISystemUiProxy { return; } mBackToLauncherCallback = null; + mBackToLauncherRunner = null; if (mBackAnimation == null) { return; } @@ -903,20 +908,6 @@ public class SystemUiProxy implements ISystemUiProxy { } } - /** - * Notifies shell that all back to launcher animations have finished (including the transition - * that plays after the gesture is committed and before the app is closed. - */ - public void onBackToLauncherAnimationFinished() { - if (mBackAnimation != null) { - try { - mBackAnimation.onBackToLauncherAnimationFinished(); - } catch (RemoteException e) { - Log.w(TAG, "Failed call onBackAnimationFinished", e); - } - } - } - public ArrayList getRecentTasks(int numTasks, int userId) { if (mRecentTasks != null) { try { From b759de4769a02811e2fffd977aefd160ee3341f4 Mon Sep 17 00:00:00 2001 From: Stefan Andonian Date: Wed, 28 Sep 2022 20:48:24 +0000 Subject: [PATCH 2/2] Fix ViewCapture NPE. The ViewPropertyRefs, when copied from 1 frame to another, where also transferring the same "next" reference. Sometimes, the recycled ViewPropertyRef would be the same ViewPropertyRef instance as one of the copied ViewPropertyRefs, which would caused an NPE, since the recycled VPR would have it's next value set to null. Bug: 249125402 Test: Repro steps are dragging and dropping around an item on the workspace to different locations. This consistently repro's the crash in about 10 seconds of doing this. Afte the fix, the crash stopped. Change-Id: Ia43d8f788eb4889c0890fea0bb839cb9fed78ada --- quickstep/src/com/android/quickstep/util/ViewCapture.java | 1 - 1 file changed, 1 deletion(-) diff --git a/quickstep/src/com/android/quickstep/util/ViewCapture.java b/quickstep/src/com/android/quickstep/util/ViewCapture.java index cfcfce0b6a..6171c5dbea 100644 --- a/quickstep/src/com/android/quickstep/util/ViewCapture.java +++ b/quickstep/src/com/android/quickstep/util/ViewCapture.java @@ -421,7 +421,6 @@ public class ViewCapture { out.visibility = this.visibility; out.willNotDraw = this.willNotDraw; out.clipChildren = this.clipChildren; - out.next = this.next; out.elevation = this.elevation; }