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

Commit 4ed2c9db authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Make app-controlled animations more robust

- Sometimes the system decides to destroy our surface before we
have finished animating. While this is a bug in the system, we
need to protect ourselves against any crashes in this case by
checking getNextFrameNumber() != -1 with the new SystemUI lib.
- Apply position of animation target for multi-window open
animation.

Test: Open Drive multiple times, observe no crash
Fixes: 72301120

Change-Id: I47520cea0d11cab109bf6190ea0cc828efc62275
parent 599752ed
Loading
Loading
Loading
Loading
+93 B (101 KiB)

File changed.

No diff preview for this file type.

+13 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.Log;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
@@ -49,6 +50,7 @@ import com.android.systemui.shared.system.TransactionCompat;
 */
public class LauncherAppTransitionManager {

    private static final String TAG = "LauncherTransition";
    private static final int REFRESH_RATE_MS = 16;

    private final DragLayer mDragLayer;
@@ -228,6 +230,13 @@ public class LauncherAppTransitionManager {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                final Surface surface = getSurface(mFloatingView);
                final long frameNumber = surface != null ? getNextFrameNumber(surface) : -1;
                if (frameNumber == -1) {
                    // Booo, not cool! Our surface got destroyed, so no reason to animate anything.
                    Log.w(TAG, "Failed to animate, surface got destroyed.");
                    return;
                }
                final float percent = animation.getAnimatedFraction();
                final float easePercent = Interpolators.AGGRESSIVE_EASE.getInterpolation(percent);

@@ -273,9 +282,12 @@ public class LauncherAppTransitionManager {
                for (RemoteAnimationTargetCompat target : targets) {
                    if (target.mode == RemoteAnimationTargetCompat.MODE_OPENING) {
                        t.setAlpha(target.leash, alpha);

                        // TODO: This isn't correct at the beginning of the animation, but better
                        // than nothing.
                        matrix.postTranslate(target.position.x, target.position.y);
                        t.setMatrix(target.leash, matrix);
                        t.setWindowCrop(target.leash, crop);
                        Surface surface = getSurface(mFloatingView);
                        t.deferTransactionUntil(target.leash, surface, getNextFrameNumber(surface));
                    }
                    if (isFirstFrame) {