From 7d2d5142abdc80bae796a1cc76e7704d168c1155 Mon Sep 17 00:00:00 2001 From: Chun-Heng Tai Date: Mon, 8 May 2023 16:37:09 -0700 Subject: [PATCH 1/3] Makes android embedding to send full uri --- .../FlutterActivityAndFragmentDelegate.java | 11 +----- .../android/io/flutter/view/FlutterView.java | 4 --- ...lutterActivityAndFragmentDelegateTest.java | 34 +++++++++---------- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java b/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java index 359eca9514125..327671139e281 100644 --- a/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java +++ b/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java @@ -525,16 +525,7 @@ private String maybeGetInitialRouteFromIntent(Intent intent) { if (host.shouldHandleDeeplinking()) { Uri data = intent.getData(); if (data != null) { - String fullRoute = data.getPath(); - if (fullRoute != null && !fullRoute.isEmpty()) { - if (data.getQuery() != null && !data.getQuery().isEmpty()) { - fullRoute += "?" + data.getQuery(); - } - if (data.getFragment() != null && !data.getFragment().isEmpty()) { - fullRoute += "#" + data.getFragment(); - } - return fullRoute; - } + return data.toString(); } } return null; diff --git a/shell/platform/android/io/flutter/view/FlutterView.java b/shell/platform/android/io/flutter/view/FlutterView.java index 4f20e75250c64..7e945f1659c8a 100644 --- a/shell/platform/android/io/flutter/view/FlutterView.java +++ b/shell/platform/android/io/flutter/view/FlutterView.java @@ -367,10 +367,6 @@ public void setInitialRoute(String route) { navigationChannel.setInitialRoute(route); } - public void pushRoute(String route) { - navigationChannel.pushRoute(route); - } - public void popRoute() { navigationChannel.popRoute(); } diff --git a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java index 8c459861cd900..765cd4cc3f020 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java @@ -688,7 +688,7 @@ public void itForwardsOnRequestPermissionsResultToFlutterEngine() { // Verify that the navigation channel was given the initial route message. verify(mockFlutterEngine.getNavigationChannel(), times(1)) - .setInitialRoute("/custom/route?query=test"); + .setInitialRoute("http://myApp/custom/route?query=test"); } @Test @@ -716,7 +716,7 @@ public void itForwardsOnRequestPermissionsResultToFlutterEngine() { // Verify that the navigation channel was given the initial route message. verify(mockFlutterEngine.getNavigationChannel(), times(1)) - .setInitialRoute("/custom/route?query=test#fragment"); + .setInitialRoute("http://myApp/custom/route?query=test#fragment"); } @Test @@ -744,7 +744,7 @@ public void itForwardsOnRequestPermissionsResultToFlutterEngine() { // Verify that the navigation channel was given the initial route message. verify(mockFlutterEngine.getNavigationChannel(), times(1)) - .setInitialRoute("/custom/route#fragment"); + .setInitialRoute("http://myApp/custom/route#fragment"); } @Test @@ -771,7 +771,8 @@ public void itForwardsOnRequestPermissionsResultToFlutterEngine() { 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("http://myApp/custom/route"); } @Test @@ -809,15 +810,15 @@ public void itSendsPushRouteInformationMessageWhenOnNewIntent() { // --- Execute the behavior under test --- // The FlutterEngine is set up in onAttach(). delegate.onAttach(ctx); + String expected = "http://myApp/custom/route?query=test"; Intent mockIntent = mock(Intent.class); - when(mockIntent.getData()).thenReturn(Uri.parse("http://myApp/custom/route?query=test")); + when(mockIntent.getData()).thenReturn(Uri.parse(expected)); // 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)) - .pushRouteInformation("/custom/route?query=test"); + verify(mockFlutterEngine.getNavigationChannel(), times(1)).pushRouteInformation(expected); } @Test @@ -852,16 +853,15 @@ public void itSendsPushRouteInformationMessageWhenOnNewIntentWithQueryParameterA // --- Execute the behavior under test --- // The FlutterEngine is set up in onAttach(). delegate.onAttach(ctx); + String expected = "http://myApp/custom/route?query=test#fragment"; Intent mockIntent = mock(Intent.class); - when(mockIntent.getData()) - .thenReturn(Uri.parse("http://myApp/custom/route?query=test#fragment")); + when(mockIntent.getData()).thenReturn(Uri.parse(expected)); // 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)) - .pushRouteInformation("/custom/route?query=test#fragment"); + verify(mockFlutterEngine.getNavigationChannel(), times(1)).pushRouteInformation(expected); } @Test @@ -873,15 +873,15 @@ public void itSendsPushRouteInformationMessageWhenOnNewIntentWithFragmentNoQuery // --- Execute the behavior under test --- // The FlutterEngine is set up in onAttach(). delegate.onAttach(ctx); + String expected = "http://myApp/custom/route#fragment"; Intent mockIntent = mock(Intent.class); - when(mockIntent.getData()).thenReturn(Uri.parse("http://myApp/custom/route#fragment")); + when(mockIntent.getData()).thenReturn(Uri.parse(expected)); // 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)) - .pushRouteInformation("/custom/route#fragment"); + verify(mockFlutterEngine.getNavigationChannel(), times(1)).pushRouteInformation(expected); } @Test @@ -893,15 +893,15 @@ public void itSendsPushRouteInformationMessageWhenOnNewIntentNoQueryParameter() // --- Execute the behavior under test --- // The FlutterEngine is set up in onAttach(). delegate.onAttach(ctx); + String expected = "http://myApp/custom/route#fragment"; Intent mockIntent = mock(Intent.class); - when(mockIntent.getData()).thenReturn(Uri.parse("http://myApp/custom/route")); + when(mockIntent.getData()).thenReturn(Uri.parse(expected)); // 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)) - .pushRouteInformation("/custom/route"); + verify(mockFlutterEngine.getNavigationChannel(), times(1)).pushRouteInformation(expected); } @Test From 480a119a5b9b3ea5be58acf8c17cabafeb1f5691 Mon Sep 17 00:00:00 2001 From: Chun-Heng Tai Date: Tue, 9 May 2023 12:12:48 -0700 Subject: [PATCH 2/3] fix test --- .../android/FlutterActivityAndFragmentDelegateTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java index 765cd4cc3f020..91669d276f254 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java @@ -309,7 +309,7 @@ public void flutterEngineGroupGetsInitialRouteFromIntent() { ArgumentCaptor optionsCaptor = ArgumentCaptor.forClass(FlutterEngineGroup.Options.class); verify(flutterEngineGroup, times(1)).createAndRunEngine(optionsCaptor.capture()); - assertEquals("/initial_route", optionsCaptor.getValue().getInitialRoute()); + assertEquals("foo://example.com/initial_route", optionsCaptor.getValue().getInitialRoute()); } @Test @@ -822,7 +822,7 @@ public void itSendsPushRouteInformationMessageWhenOnNewIntent() { } @Test - public void itDoesNotSendPushRouteInformationMessageWhenOnNewIntentIsNonHierarchicalUri() { + public void itDoesSendPushRouteInformationMessageWhenOnNewIntentIsNonHierarchicalUri() { when(mockHost.shouldHandleDeeplinking()).thenReturn(true); // Create the real object that we're testing. FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost); @@ -840,7 +840,7 @@ public void itDoesNotSendPushRouteInformationMessageWhenOnNewIntentIsNonHierarch delegate.onNewIntent(mockIntent); // Verify that the navigation channel was not given a push route message. - verify(mockFlutterEngine.getNavigationChannel(), times(0)) + verify(mockFlutterEngine.getNavigationChannel(), times(1)) .pushRouteInformation("mailto:test@test.com"); } From 67be28d047b578ef9d1f77e0d3130af07c13f7ed Mon Sep 17 00:00:00 2001 From: Chun-Heng Tai Date: Thu, 18 May 2023 16:02:52 -0700 Subject: [PATCH 3/3] update --- shell/platform/android/io/flutter/view/FlutterView.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shell/platform/android/io/flutter/view/FlutterView.java b/shell/platform/android/io/flutter/view/FlutterView.java index 7e945f1659c8a..4f20e75250c64 100644 --- a/shell/platform/android/io/flutter/view/FlutterView.java +++ b/shell/platform/android/io/flutter/view/FlutterView.java @@ -367,6 +367,10 @@ public void setInitialRoute(String route) { navigationChannel.setInitialRoute(route); } + public void pushRoute(String route) { + navigationChannel.pushRoute(route); + } + public void popRoute() { navigationChannel.popRoute(); }