Make DartExecutor.isExecutingDart account for spawned engines (flutter/engine#25171)

This commit is contained in:
xster
2021-03-23 09:50:03 -07:00
committed by GitHub
parent c16e3a3e5b
commit 708d427d93
2 changed files with 24 additions and 0 deletions

View File

@@ -61,6 +61,11 @@ public class DartExecutor implements BinaryMessenger {
this.dartMessenger = new DartMessenger(flutterJNI);
dartMessenger.setMessageHandler("flutter/isolate", isolateChannelMessageHandler);
this.binaryMessenger = new DefaultBinaryMessenger(dartMessenger);
// The JNI might already be attached if coming from a spawned engine. If so, correctly report
// that this DartExecutor is already running.
if (flutterJNI.isAttached()) {
isApplicationRunning = true;
}
}
/**

View File

@@ -232,4 +232,23 @@ public class FlutterEngineTest {
verify(flutterJNI, never()).attachToNative(false);
}
@Test
public void itComesWithARunningDartExecutorIfJNIIsAlreadyAttached() throws NameNotFoundException {
Context context = mock(Context.class);
Context packageContext = mock(Context.class);
when(context.createPackageContext(any(), anyInt())).thenReturn(packageContext);
when(flutterJNI.isAttached()).thenReturn(true);
FlutterEngine engineUnderTest =
new FlutterEngine(
context,
mock(FlutterLoader.class),
flutterJNI,
/*dartVmArgs=*/ new String[] {},
/*automaticallyRegisterPlugins=*/ false);
assertTrue(engineUnderTest.getDartExecutor().isExecutingDart());
}
}