Skip to content

Commit

Permalink
[Android] Prevent FlutterRenderer listener from calling JNI after det…
Browse files Browse the repository at this point in the history
…ach (flutter#19558)
  • Loading branch information
GaryQian authored Jul 13, 2020
1 parent 617bd88 commit 8d241e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ final class SurfaceTextureRegistryEntry implements TextureRegistry.SurfaceTextur
new SurfaceTexture.OnFrameAvailableListener() {
@Override
public void onFrameAvailable(@NonNull SurfaceTexture texture) {
if (released) {
// Even though we make sure to unregister the callback before releasing, as of Android
// O
// SurfaceTexture has a data race when accessing the callback, so the callback may
// still be called by a stale reference after released==true and mNativeView==null.
if (released || !flutterJNI.isAttached()) {
// Even though we make sure to unregister the callback before releasing, as of
// Android O, SurfaceTexture has a data race when accessing the callback, so the
// callback may still be called by a stale reference after released==true and
// mNativeView==null.
return;
}
markTextureFrameAvailable(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,23 @@ public void itStopsRenderingToSurfaceWhenRequested() {
// Verify behavior under test.
verify(fakeFlutterJNI, times(1)).onSurfaceDestroyed();
}

@Test
public void itStopsSurfaceTextureCallbackWhenDetached() {
// Setup the test.
FlutterRenderer flutterRenderer = new FlutterRenderer(fakeFlutterJNI);

fakeFlutterJNI.detachFromNativeAndReleaseResources();

FlutterRenderer.SurfaceTextureRegistryEntry entry =
(FlutterRenderer.SurfaceTextureRegistryEntry) flutterRenderer.createSurfaceTexture();

flutterRenderer.startRenderingToSurface(fakeSurface);

// Execute the behavior under test.
flutterRenderer.stopRenderingToSurface();

// Verify behavior under test.
verify(fakeFlutterJNI, times(0)).markTextureFrameAvailable(eq(entry.id()));
}
}

0 comments on commit 8d241e4

Please sign in to comment.