From fbd0f1df95050be208b80a325c762c25d5611a60 Mon Sep 17 00:00:00 2001 From: Sarbagya Dhaubanjar Date: Wed, 13 Jan 2021 05:47:08 +0545 Subject: [PATCH] Android deeplink sends "path + query" instead of just path (flutter/engine#23561) * added .cpid & .gclient to gitignore * updated tests * minor change * fixed formating * compact concatenation * minor change * Revert "added .cpid & .gclient to gitignore" * cleanup --- .../android/FlutterActivityAndFragmentDelegate.java | 6 +++++- .../FlutterActivityAndFragmentDelegateTest.java | 10 ++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java index 4d5cfcac0d..0990604b9b 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java @@ -399,7 +399,11 @@ import java.util.Arrays; if (host.shouldHandleDeeplinking()) { Uri data = intent.getData(); if (data != null && !data.getPath().isEmpty()) { - return data.getPath(); + String pathAndQuery = data.getPath(); + if (!data.getQuery().isEmpty()) { + pathAndQuery += "?" + data.getQuery(); + } + return pathAndQuery; } } return null; diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java index e4c02d7492..509b97791c 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java @@ -433,7 +433,7 @@ public class FlutterActivityAndFragmentDelegateTest { public void itSendsInitialRouteFromIntentOnStartIfNoInitialRouteFromActivityAndShouldHandleDeeplinking() { Intent intent = FlutterActivity.createDefaultIntent(RuntimeEnvironment.application); - intent.setData(Uri.parse("http://myApp/custom/route")); + intent.setData(Uri.parse("http://myApp/custom/route?query=test")); ActivityController activityController = Robolectric.buildActivity(FlutterActivity.class, intent); @@ -452,7 +452,8 @@ public class FlutterActivityAndFragmentDelegateTest { delegate.onStart(); // Verify that the navigation channel was given the initial route message. - verify(mockFlutterEngine.getNavigationChannel(), times(1)).setInitialRoute("/custom/route"); + verify(mockFlutterEngine.getNavigationChannel(), times(1)) + .setInitialRoute("/custom/route?query=test"); } @Test @@ -491,12 +492,13 @@ public class FlutterActivityAndFragmentDelegateTest { delegate.onAttach(RuntimeEnvironment.application); Intent mockIntent = mock(Intent.class); - when(mockIntent.getData()).thenReturn(Uri.parse("http://myApp/custom/route")); + when(mockIntent.getData()).thenReturn(Uri.parse("http://myApp/custom/route?query=test")); // 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"); + verify(mockFlutterEngine.getNavigationChannel(), times(1)) + .pushRoute("/custom/route?query=test"); } @Test