fixes android deeplink query paremeter null crashes (flutter/engine#24146)

This commit is contained in:
chunhtai 2021-02-02 17:01:03 -08:00 committed by GitHub
parent 0561c75b4d
commit 56c0a73e02
2 changed files with 46 additions and 1 deletions

View File

@ -400,7 +400,7 @@ import java.util.Arrays;
Uri data = intent.getData();
if (data != null && !data.getPath().isEmpty()) {
String pathAndQuery = data.getPath();
if (!data.getQuery().isEmpty()) {
if (data.getQuery() != null && !data.getQuery().isEmpty()) {
pathAndQuery += "?" + data.getQuery();
}
return pathAndQuery;

View File

@ -456,6 +456,32 @@ public class FlutterActivityAndFragmentDelegateTest {
.setInitialRoute("/custom/route?query=test");
}
@Test
public void
itSendsInitialRouteFromIntentOnStartIfNoInitialRouteFromActivityAndShouldHandleDeeplinkingNoQueryParameter() {
Intent intent = FlutterActivity.createDefaultIntent(RuntimeEnvironment.application);
intent.setData(Uri.parse("http://myApp/custom/route"));
ActivityController<FlutterActivity> activityController =
Robolectric.buildActivity(FlutterActivity.class, intent);
FlutterActivity flutterActivity = activityController.get();
when(mockHost.getActivity()).thenReturn(flutterActivity);
when(mockHost.getInitialRoute()).thenReturn(null);
when(mockHost.shouldHandleDeeplinking()).thenReturn(true);
// Create the real object that we're testing.
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost);
// --- Execute the behavior under test ---
// The FlutterEngine is setup in onAttach().
delegate.onAttach(RuntimeEnvironment.application);
// Emulate app start.
delegate.onStart();
// Verify that the navigation channel was given the initial route message.
verify(mockFlutterEngine.getNavigationChannel(), times(1)).setInitialRoute("/custom/route");
}
@Test
public void itSendsdefaultInitialRouteOnStartIfNotDeepLinkingFromIntent() {
// Creates an empty intent without launch uri.
@ -501,6 +527,25 @@ public class FlutterActivityAndFragmentDelegateTest {
.pushRoute("/custom/route?query=test");
}
@Test
public void itSendsPushRouteMessageWhenOnNewIntentNoQueryParameter() {
when(mockHost.shouldHandleDeeplinking()).thenReturn(true);
// Create the real object that we're testing.
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost);
// --- Execute the behavior under test ---
// The FlutterEngine is setup in onAttach().
delegate.onAttach(RuntimeEnvironment.application);
Intent mockIntent = mock(Intent.class);
when(mockIntent.getData()).thenReturn(Uri.parse("http://myApp/custom/route"));
// Emulate the host and call the method that we expect to be forwarded.
delegate.onNewIntent(mockIntent);
// Verify that the navigation channel was given the push route message.
verify(mockFlutterEngine.getNavigationChannel(), times(1)).pushRoute("/custom/route");
}
@Test
public void itForwardsOnNewIntentToFlutterEngine() {
// Create the real object that we're testing.