Skip to content

Commit b1ce13c

Browse files
chunhtaichaselatta
authored andcommitted
Revert "support uri intent launcher in android (flutter#21275)" (flutter#22298)
1 parent 0533edd commit b1ce13c

File tree

4 files changed

+11
-83
lines changed

4 files changed

+11
-83
lines changed

shell/platform/android/io/flutter/embedding/android/FlutterActivity.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -774,18 +774,13 @@ public String getDartEntrypointFunctionName() {
774774
*
775775
* If both preferences are set, the {@code Intent} preference takes priority.
776776
*
777-
* <p>If none is set, the {@link FlutterActivityAndFragmentDelegate} retrieves the initial route
778-
* from the {@code Intent} through the Intent.getData() instead.
779-
*
780777
* <p>The reason that a {@code <meta-data>} preference is supported is because this {@code
781778
* Activity} might be the very first {@code Activity} launched, which means the developer won't
782779
* have control over the incoming {@code Intent}.
783780
*
784781
* <p>Subclasses may override this method to directly control the initial route.
785-
*
786-
* <p>If this method returns null, the {@link FlutterActivityAndFragmentDelegate} retrieves the
787-
* initial route from the {@code Intent} through the Intent.getData() instead.
788782
*/
783+
@NonNull
789784
public String getInitialRoute() {
790785
if (getIntent().hasExtra(EXTRA_INITIAL_ROUTE)) {
791786
return getIntent().getStringExtra(EXTRA_INITIAL_ROUTE);
@@ -797,9 +792,9 @@ public String getInitialRoute() {
797792
Bundle metadata = activityInfo.metaData;
798793
String desiredInitialRoute =
799794
metadata != null ? metadata.getString(INITIAL_ROUTE_META_DATA_KEY) : null;
800-
return desiredInitialRoute;
795+
return desiredInitialRoute != null ? desiredInitialRoute : DEFAULT_INITIAL_ROUTE;
801796
} catch (PackageManager.NameNotFoundException e) {
802-
return null;
797+
return DEFAULT_INITIAL_ROUTE;
803798
}
804799
}
805800

shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import android.app.Activity;
1010
import android.content.Context;
1111
import android.content.Intent;
12-
import android.net.Uri;
1312
import android.os.Build;
1413
import android.os.Bundle;
1514
import android.view.LayoutInflater;
@@ -363,21 +362,18 @@ private void doInitialFlutterViewRun() {
363362
// So this is expected behavior in many cases.
364363
return;
365364
}
366-
String initialRoute = host.getInitialRoute();
367-
if (initialRoute == null) {
368-
initialRoute = getInitialRouteFromIntent(host.getActivity().getIntent());
369-
}
365+
370366
Log.v(
371367
TAG,
372368
"Executing Dart entrypoint: "
373369
+ host.getDartEntrypointFunctionName()
374370
+ ", and sending initial route: "
375-
+ initialRoute);
371+
+ host.getInitialRoute());
376372

377373
// The engine needs to receive the Flutter app's initial route before executing any
378374
// Dart code to ensure that the initial route arrives in time to be applied.
379-
if (initialRoute != null) {
380-
flutterEngine.getNavigationChannel().setInitialRoute(initialRoute);
375+
if (host.getInitialRoute() != null) {
376+
flutterEngine.getNavigationChannel().setInitialRoute(host.getInitialRoute());
381377
}
382378

383379
String appBundlePathOverride = host.getAppBundlePath();
@@ -392,14 +388,6 @@ private void doInitialFlutterViewRun() {
392388
flutterEngine.getDartExecutor().executeDartEntrypoint(entrypoint);
393389
}
394390

395-
private String getInitialRouteFromIntent(Intent intent) {
396-
Uri data = intent.getData();
397-
if (data != null && !data.toString().isEmpty()) {
398-
return data.toString();
399-
}
400-
return null;
401-
}
402-
403391
/**
404392
* Invoke this from {@code Activity#onResume()} or {@code Fragment#onResume()}.
405393
*
@@ -634,12 +622,8 @@ void onRequestPermissionsResult(
634622
void onNewIntent(@NonNull Intent intent) {
635623
ensureAlive();
636624
if (flutterEngine != null) {
637-
Log.v(TAG, "Forwarding onNewIntent() to FlutterEngine and sending pushRoute message.");
625+
Log.v(TAG, "Forwarding onNewIntent() to FlutterEngine.");
638626
flutterEngine.getActivityControlSurface().onNewIntent(intent);
639-
String initialRoute = getInitialRouteFromIntent(intent);
640-
if (initialRoute != null && !initialRoute.isEmpty()) {
641-
flutterEngine.getNavigationChannel().pushRoute(initialRoute);
642-
}
643627
} else {
644628
Log.w(TAG, "onNewIntent() invoked before FlutterFragment was attached to an Activity.");
645629
}

shell/platform/android/io/flutter/embedding/android/FlutterFragmentActivity.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -646,18 +646,13 @@ public String getDartEntrypointFunctionName() {
646646
*
647647
* If both preferences are set, the {@code Intent} preference takes priority.
648648
*
649-
* <p>If none is set, the {@link FlutterActivityAndFragmentDelegate} retrieves the initial route
650-
* from the {@code Intent} through the Intent.getData() instead.
651-
*
652649
* <p>The reason that a {@code <meta-data>} preference is supported is because this {@code
653650
* Activity} might be the very first {@code Activity} launched, which means the developer won't
654651
* have control over the incoming {@code Intent}.
655652
*
656653
* <p>Subclasses may override this method to directly control the initial route.
657-
*
658-
* <p>If this method returns null, the {@link FlutterActivityAndFragmentDelegate} retrieves the
659-
* initial route from the {@code Intent} through the Intent.getData() instead.
660654
*/
655+
@NonNull
661656
protected String getInitialRoute() {
662657
if (getIntent().hasExtra(EXTRA_INITIAL_ROUTE)) {
663658
return getIntent().getStringExtra(EXTRA_INITIAL_ROUTE);
@@ -669,9 +664,9 @@ protected String getInitialRoute() {
669664
Bundle metadata = activityInfo.metaData;
670665
String desiredInitialRoute =
671666
metadata != null ? metadata.getString(INITIAL_ROUTE_META_DATA_KEY) : null;
672-
return desiredInitialRoute;
667+
return desiredInitialRoute != null ? desiredInitialRoute : DEFAULT_INITIAL_ROUTE;
673668
} catch (PackageManager.NameNotFoundException e) {
674-
return null;
669+
return DEFAULT_INITIAL_ROUTE;
675670
}
676671
}
677672

shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import android.app.Activity;
1616
import android.content.Context;
1717
import android.content.Intent;
18-
import android.net.Uri;
1918
import androidx.annotation.NonNull;
2019
import androidx.lifecycle.Lifecycle;
2120
import io.flutter.FlutterInjector;
@@ -44,7 +43,6 @@
4443
import org.robolectric.Robolectric;
4544
import org.robolectric.RobolectricTestRunner;
4645
import org.robolectric.RuntimeEnvironment;
47-
import org.robolectric.android.controller.ActivityController;
4846
import org.robolectric.annotation.Config;
4947

5048
@Config(manifest = Config.NONE)
@@ -428,50 +426,6 @@ public void itForwardsOnRequestPermissionsResultToFlutterEngine() {
428426
.onRequestPermissionsResult(any(Integer.class), any(String[].class), any(int[].class));
429427
}
430428

431-
@Test
432-
public void itSendsInitialRouteFromIntentOnStartIfnoInitialRouteFromActivity() {
433-
Intent intent = FlutterActivity.createDefaultIntent(RuntimeEnvironment.application);
434-
intent.setData(Uri.parse("http://myApp/custom/route"));
435-
436-
ActivityController<FlutterActivity> activityController =
437-
Robolectric.buildActivity(FlutterActivity.class, intent);
438-
FlutterActivity flutterActivity = activityController.get();
439-
440-
when(mockHost.getActivity()).thenReturn(flutterActivity);
441-
when(mockHost.getInitialRoute()).thenReturn(null);
442-
// Create the real object that we're testing.
443-
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost);
444-
445-
// --- Execute the behavior under test ---
446-
// The FlutterEngine is setup in onAttach().
447-
delegate.onAttach(RuntimeEnvironment.application);
448-
// Emulate app start.
449-
delegate.onStart();
450-
451-
// Verify that the navigation channel was given the initial route message.
452-
verify(mockFlutterEngine.getNavigationChannel(), times(1))
453-
.setInitialRoute("http://myApp/custom/route");
454-
}
455-
456-
@Test
457-
public void itSendsPushRouteMessageWhenOnNewIntent() {
458-
// Create the real object that we're testing.
459-
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost);
460-
461-
// --- Execute the behavior under test ---
462-
// The FlutterEngine is setup in onAttach().
463-
delegate.onAttach(RuntimeEnvironment.application);
464-
465-
Intent mockIntent = mock(Intent.class);
466-
when(mockIntent.getData()).thenReturn(Uri.parse("http://myApp/custom/route"));
467-
// Emulate the host and call the method that we expect to be forwarded.
468-
delegate.onNewIntent(mockIntent);
469-
470-
// Verify that the navigation channel was given the push route message.
471-
verify(mockFlutterEngine.getNavigationChannel(), times(1))
472-
.pushRoute("http://myApp/custom/route");
473-
}
474-
475429
@Test
476430
public void itForwardsOnNewIntentToFlutterEngine() {
477431
// Create the real object that we're testing.

0 commit comments

Comments
 (0)