From 7087a7bd91c8c136722b6b515568f1c9f0aa1f46 Mon Sep 17 00:00:00 2001 From: Tracy Zhou Date: Tue, 12 May 2020 21:34:13 -0700 Subject: [PATCH] Don't continue rendering preview screen when binder is dead Fixes: 155365052 Test: manually quick switches between different grid options Change-Id: I31dc14b0a50b5e3a5c81272b693303034fcf8b40 --- .../graphics/PreviewSurfaceRenderer.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java index c62f308367..350f221c97 100644 --- a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java +++ b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java @@ -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) { - mSurfaceControlViewHost.release(); - mSurfaceControlViewHost = null; + MAIN_EXECUTOR.execute(() -> { + mSurfaceControlViewHost.release(); + mSurfaceControlViewHost = null; + }); } mHostToken.unlinkToDeath(this, 0); }