Skip to content

Commit

Permalink
Make DartExecutor.isExecutingDart account for spawned engines (flutte…
Browse files Browse the repository at this point in the history
  • Loading branch information
xster authored Mar 23, 2021
1 parent 0fc579f commit bc8a52d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public DartExecutor(@NonNull FlutterJNI flutterJNI, @NonNull AssetManager assetM
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;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,23 @@ public void itDoesNotAttachAgainWhenBuiltWithAnAttachedJNI() throws NameNotFound

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());
}
}

0 comments on commit bc8a52d

Please sign in to comment.