Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 52f64512 authored by Evan Rosky's avatar Evan Rosky
Browse files

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
parent 75beeaee
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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"
+13 −3
Original line number Diff line number Diff line
@@ -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) {