Merge "Don't continue rendering preview screen when binder is dead" into ub-launcher3-rvc-dev
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user