Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Set deep linking flag to true by default #52350

Merged
merged 12 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_DESTROY_ENGINE_WITH_ACTIVITY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_ENABLE_STATE_RESTORATION;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_INITIAL_ROUTE;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.HANDLE_DEEPLINKING_META_DATA_KEY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.INITIAL_ROUTE_META_DATA_KEY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.NORMAL_THEME_META_DATA_KEY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.deepLinkEnabled;

import android.annotation.TargetApi;
import android.app.Activity;
Expand Down Expand Up @@ -1404,9 +1404,7 @@ public boolean shouldAttachEngineToActivity() {
public boolean shouldHandleDeeplinking() {
try {
Bundle metaData = getMetaData();
boolean shouldHandleDeeplinking =
metaData != null ? metaData.getBoolean(HANDLE_DEEPLINKING_META_DATA_KEY) : false;
return shouldHandleDeeplinking;
return deepLinkEnabled(metaData);
} catch (PackageManager.NameNotFoundException e) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package io.flutter.embedding.android;

import android.os.Bundle;

/** Collection of Flutter launch configuration options. */
// This class is public so that Flutter app developers can reference
// BackgroundMode
Expand Down Expand Up @@ -41,5 +43,24 @@ public enum BackgroundMode {
transparent
}

/**
* Whether to handle the deeplinking.
*
* <p>The default implementation looks {@code <meta-data>} called {@link
* FlutterActivityLaunchConfigs#HANDLE_DEEPLINKING_META_DATA_KEY} within the Android manifest
* definition for this {@code FlutterActivity}.
*
* <p>Defaults to {@code true}.
*/
public static boolean deepLinkEnabled(Bundle metaData) {
// Check if metadata is not null and contains the HANDLE_DEEPLINKING_META_DATA_KEY.
if (metaData != null && metaData.containsKey(HANDLE_DEEPLINKING_META_DATA_KEY)) {
return metaData.getBoolean(HANDLE_DEEPLINKING_META_DATA_KEY);
} else {
// Return true if the deep linking flag is not found in metadata.
return true;
}
}

private FlutterActivityLaunchConfigs() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_DART_ENTRYPOINT_ARGS;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_DESTROY_ENGINE_WITH_ACTIVITY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_INITIAL_ROUTE;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.HANDLE_DEEPLINKING_META_DATA_KEY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.INITIAL_ROUTE_META_DATA_KEY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.NORMAL_THEME_META_DATA_KEY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.deepLinkEnabled;

import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -695,9 +695,7 @@ protected boolean shouldAttachEngineToActivity() {
protected boolean shouldHandleDeeplinking() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this code go into a shared location since it is identical?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there half of the functions in FlutterActivity.java and FlutterFragmentActivity.java are identical, so I was just following the pattern. Maybe FlutterActivity and FlutterFragmentActivity need a refactor to move all identical code into a shared location?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think this code should not be duplicated

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fair, i moved shared code into [FlutterActivityLaunchConfigs.java]

try {
Bundle metaData = getMetaData();
boolean shouldHandleDeeplinking =
metaData != null ? metaData.getBoolean(HANDLE_DEEPLINKING_META_DATA_KEY) : false;
return shouldHandleDeeplinking;
return deepLinkEnabled(metaData);
} catch (PackageManager.NameNotFoundException e) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ public void itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase3()
Bundle bundle = new Bundle();
FlutterActivity spyFlutterActivity = spy(flutterActivity);
when(spyFlutterActivity.getMetaData()).thenReturn(bundle);
// Empty bundle should return false.
assertFalse(spyFlutterActivity.shouldHandleDeeplinking());
// Empty bundle should return true.
assertTrue(spyFlutterActivity.shouldHandleDeeplinking());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ public void itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase3()
Bundle bundle = new Bundle();
FlutterFragmentActivity spyFlutterActivity = spy(activity);
when(spyFlutterActivity.getMetaData()).thenReturn(bundle);
// Empty bundle should return false.
assertFalse(spyFlutterActivity.shouldHandleDeeplinking());
// Empty bundle should return true.
assertTrue(spyFlutterActivity.shouldHandleDeeplinking());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ - (void)userNotificationCenter:(UNUserNotificationCenter*)center
- (BOOL)isFlutterDeepLinkingEnabled {
NSNumber* isDeepLinkingEnabled =
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"FlutterDeepLinkingEnabled"];
// if not set, return NO
return isDeepLinkingEnabled ? [isDeepLinkingEnabled boolValue] : NO;
// if not set, return YES
return isDeepLinkingEnabled ? [isDeepLinkingEnabled boolValue] : YES;
}

// This method is called when opening an URL with custom schemes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,18 @@ - (void)testLaunchUrlWithDeepLinkingNotSet {
OCMStub([self.mockMainBundle objectForInfoDictionaryKey:@"FlutterDeepLinkingEnabled"])
.andReturn(nil);

OCMStub([self.mockNavigationChannel
invokeMethod:@"pushRouteInformation"
arguments:@{@"location" : @"http://myApp/custom/route?query=test"}])
.andReturn(@YES);

BOOL result =
[self.appDelegate application:[UIApplication sharedApplication]
openURL:[NSURL URLWithString:@"http://myApp/custom/route?query=test"]
options:@{}];
XCTAssertFalse(result);
OCMReject([self.mockNavigationChannel invokeMethod:OCMOCK_ANY arguments:OCMOCK_ANY]);

XCTAssertTrue(result);
OCMVerifyAll(self.mockNavigationChannel);
}

- (void)testLaunchUrlWithDeepLinkingDisabled {
Expand Down