From 52f6451203bd25c0f556d373ff9fc8134664b948 Mon Sep 17 00:00:00 2001 From: Evan Rosky Date: Thu, 22 Apr 2021 16:22:08 -0700 Subject: [PATCH] Fix surface release race when using Shell Transitions Shell Transitions operates on the leashes both before and after the animation in order to adapt shell transit to the legacy transit impls in launcher. This means we can't release the surfaces before the finish callback. Since the finish callback provides a convenient place to release the surfaces anyways, we can effectively disable the release here. Bug: 186158221 Test: enable shell transit, physically rotate to landscape, launch messages and then close it (back-gesture) repeatedly and observe that launcher doesn't crash. Change-Id: Ibdc958b1fd18d66a013d94b70772ce49409fb4c1 --- .../system/RemoteAnimationAdapterCompat.java | 7 +++++++ .../shared/system/RemoteTransitionCompat.java | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteAnimationAdapterCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteAnimationAdapterCompat.java index 4e0204b75d2c2..22d934edf661e 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteAnimationAdapterCompat.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteAnimationAdapterCompat.java @@ -25,6 +25,7 @@ import static android.view.WindowManager.TRANSIT_TO_FRONT; import static android.view.WindowManager.TransitionOldType; import static android.window.TransitionInfo.FLAG_IS_WALLPAPER; +import android.annotation.SuppressLint; import android.os.IBinder; import android.os.RemoteException; import android.util.Log; @@ -241,10 +242,16 @@ public class RemoteAnimationAdapterCompat { final Runnable animationFinishedCallback = new Runnable() { @Override + @SuppressLint("NewApi") public void run() { try { counterLauncher.cleanUp(info.getRootLeash()); counterWallpaper.cleanUp(info.getRootLeash()); + // Release surface references now. This is apparently to free GPU + // memory while doing quick operations (eg. during CTS). + for (int i = 0; i < info.getChanges().size(); ++i) { + info.getChanges().get(i).getLeash().release(); + } finishCallback.onTransitionFinished(null /* wct */); } catch (RemoteException e) { Log.e("ActivityOptionsCompat", "Failed to call app controlled animation" diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteTransitionCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteTransitionCompat.java index 88d9d68b44581..b5f2edeaad1b7 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteTransitionCompat.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/RemoteTransitionCompat.java @@ -24,6 +24,7 @@ import static android.view.WindowManager.TRANSIT_TO_FRONT; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.SuppressLint; import android.graphics.Rect; import android.os.IBinder; import android.os.Parcelable; @@ -127,7 +128,7 @@ public class RemoteTransitionCompat implements Parcelable { } t.apply(); final RecentsAnimationControllerCompat wrapControl = - new RecentsControllerWrap(controller, finishedCallback, pausingTask); + new RecentsControllerWrap(controller, info, finishedCallback, pausingTask); recents.onAnimationStart(wrapControl, apps, wallpapers, new Rect(0, 0, 0, 0), new Rect()); } @@ -161,10 +162,12 @@ public class RemoteTransitionCompat implements Parcelable { private final RecentsAnimationControllerCompat mWrapped; private final IRemoteTransitionFinishedCallback mFinishCB; private final WindowContainerToken mPausingTask; + private final TransitionInfo mInfo; - RecentsControllerWrap(RecentsAnimationControllerCompat wrapped, + RecentsControllerWrap(RecentsAnimationControllerCompat wrapped, TransitionInfo info, IRemoteTransitionFinishedCallback finishCB, WindowContainerToken pausingTask) { mWrapped = wrapped; + mInfo = info; mFinishCB = finishCB; mPausingTask = pausingTask; } @@ -192,7 +195,9 @@ public class RemoteTransitionCompat implements Parcelable { } } - @Override public void finish(boolean toHome, boolean sendUserLeaveHint) { + @Override + @SuppressLint("NewApi") + public void finish(boolean toHome, boolean sendUserLeaveHint) { try { if (!toHome && mPausingTask != null) { // The gesture went back to opening the app rather than continuing with @@ -207,6 +212,11 @@ public class RemoteTransitionCompat implements Parcelable { Log.e("RemoteTransitionCompat", "Failed to call animation finish callback", e); } if (mWrapped != null) mWrapped.finish(toHome, sendUserLeaveHint); + // Release surface references now. This is apparently to free GPU + // memory while doing quick operations (eg. during CTS). + for (int i = 0; i < mInfo.getChanges().size(); ++i) { + mInfo.getChanges().get(i).getLeash().release(); + } } @Override public void setDeferCancelUntilNextTransition(boolean defer, boolean screenshot) {