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

Commit 7087a7bd authored by Tracy Zhou's avatar Tracy Zhou
Browse files

Don't continue rendering preview screen when binder is dead

Fixes: 155365052
Test: manually quick switches between different grid options
Change-Id: I31dc14b0a50b5e3a5c81272b693303034fcf8b40
parent 794ca4db
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -81,10 +81,12 @@ public class PreviewSurfaceRenderer implements IBinder.DeathRecipient {
            binderDied();
        }

        SurfaceControlViewHost.SurfacePackage surfacePackage;
        try {
            mSurfaceControlViewHost = MAIN_EXECUTOR
                    .submit(() -> new SurfaceControlViewHost(mContext, mDisplay, mHostToken))
                    .get(5, TimeUnit.SECONDS);
            surfacePackage = mSurfaceControlViewHost.getSurfacePackage();
            mHostToken.linkToDeath(this, 0);
        } catch (Exception e) {
            e.printStackTrace();
@@ -92,6 +94,14 @@ public class PreviewSurfaceRenderer implements IBinder.DeathRecipient {
        }

        MAIN_EXECUTOR.execute(() -> {
            // If mSurfaceControlViewHost is null due to any reason (e.g. binder died,
            // happening when user leaves the preview screen before preview rendering finishes),
            // we should return here.
            SurfaceControlViewHost host = mSurfaceControlViewHost;
            if (host == null) {
                return;
            }

            View view = new LauncherPreviewRenderer(mContext, mIdp).getRenderedView();
            // This aspect scales the view to fit in the surface and centers it
            final float scale = Math.min(mWidth / (float) view.getMeasuredWidth(),
@@ -107,14 +117,14 @@ public class PreviewSurfaceRenderer implements IBinder.DeathRecipient {
                    .setInterpolator(new AccelerateDecelerateInterpolator())
                    .setDuration(FADE_IN_ANIMATION_DURATION)
                    .start();
            mSurfaceControlViewHost.setView(view, view.getMeasuredWidth(),
            host.setView(view, view.getMeasuredWidth(),
                    view.getMeasuredHeight());
        });

        Bundle result = new Bundle();
        result.putParcelable(KEY_SURFACE_PACKAGE, mSurfaceControlViewHost.getSurfacePackage());
        result.putParcelable(KEY_SURFACE_PACKAGE, surfacePackage);

        Handler handler = new Handler(Looper.getMainLooper(), Loopermessage -> {
        Handler handler = new Handler(Looper.getMainLooper(), message -> {
            binderDied();
            return true;
        });
@@ -128,8 +138,10 @@ public class PreviewSurfaceRenderer implements IBinder.DeathRecipient {
    @Override
    public void binderDied() {
        if (mSurfaceControlViewHost != null) {
            MAIN_EXECUTOR.execute(() -> {
                mSurfaceControlViewHost.release();
                mSurfaceControlViewHost = null;
            });
        }
        mHostToken.unlinkToDeath(this, 0);
    }