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

Commit 388090fb authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Check for surface validity to avoid native crash

If the surface gets destroyed, return -1 to indicate such that
the client can abort the animation, instead of crashing.

Test: With Launcher in multi-window
Change-Id: I4ab11557c40ed843a4c2e985a53cc2247b18b5fd
parent 77dad606
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -283,6 +283,7 @@ public class Surface implements Parcelable {
     */
    public long getNextFrameNumber() {
        synchronized (mLock) {
            checkNotReleasedLocked();
            return nativeGetNextFrameNumber(mNativeObject);
        }
    }
+14 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.RectEvaluator;
import android.annotation.FloatRange;
import android.annotation.Nullable;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
@@ -39,6 +40,7 @@ import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.ViewRootImpl;
import android.view.ViewStub;

import java.util.ArrayList;
@@ -294,17 +296,25 @@ public class Utilities {
    }

    /**
     * @return The next frame name for the specified surface.
     * @return The next frame name for the specified surface or -1 if the surface is no longer
     *         valid.
     */
    public static long getNextFrameNumber(Surface s) {
        return s.getNextFrameNumber();
        return s != null && s.isValid()
                ? s.getNextFrameNumber()
                : -1;

    }

    /**
     * @return The surface for the specified view.
     */
    public static Surface getSurface(View v) {
        return v.getViewRootImpl().mSurface;
    public static @Nullable Surface getSurface(View v) {
        ViewRootImpl viewRoot = v.getViewRootImpl();
        if (viewRoot == null) {
            return null;
        }
        return viewRoot.mSurface;
    }

    /**