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

Commit 30ffe6e

Browse files
authored
Set deep linking flag to true by default (#52350)
doc: flutter.dev/go/deep-link-flag-migration Action item: make sure customers are aware of this change before merging this PR. ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I signed the [CLA]. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
1 parent cc1b681 commit 30ffe6e

File tree

7 files changed

+39
-16
lines changed

7 files changed

+39
-16
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_DESTROY_ENGINE_WITH_ACTIVITY;
1919
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_ENABLE_STATE_RESTORATION;
2020
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_INITIAL_ROUTE;
21-
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.HANDLE_DEEPLINKING_META_DATA_KEY;
2221
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.INITIAL_ROUTE_META_DATA_KEY;
2322
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.NORMAL_THEME_META_DATA_KEY;
23+
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.deepLinkEnabled;
2424

2525
import android.annotation.TargetApi;
2626
import android.app.Activity;
@@ -1404,9 +1404,7 @@ public boolean shouldAttachEngineToActivity() {
14041404
public boolean shouldHandleDeeplinking() {
14051405
try {
14061406
Bundle metaData = getMetaData();
1407-
boolean shouldHandleDeeplinking =
1408-
metaData != null ? metaData.getBoolean(HANDLE_DEEPLINKING_META_DATA_KEY) : false;
1409-
return shouldHandleDeeplinking;
1407+
return deepLinkEnabled(metaData);
14101408
} catch (PackageManager.NameNotFoundException e) {
14111409
return false;
14121410
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
package io.flutter.embedding.android;
66

7+
import android.os.Bundle;
8+
79
/** Collection of Flutter launch configuration options. */
810
// This class is public so that Flutter app developers can reference
911
// BackgroundMode
@@ -41,5 +43,24 @@ public enum BackgroundMode {
4143
transparent
4244
}
4345

46+
/**
47+
* Whether to handle the deeplinking.
48+
*
49+
* <p>The default implementation looks {@code <meta-data>} called {@link
50+
* FlutterActivityLaunchConfigs#HANDLE_DEEPLINKING_META_DATA_KEY} within the Android manifest
51+
* definition for this {@code FlutterActivity}.
52+
*
53+
* <p>Defaults to {@code true}.
54+
*/
55+
public static boolean deepLinkEnabled(Bundle metaData) {
56+
// Check if metadata is not null and contains the HANDLE_DEEPLINKING_META_DATA_KEY.
57+
if (metaData != null && metaData.containsKey(HANDLE_DEEPLINKING_META_DATA_KEY)) {
58+
return metaData.getBoolean(HANDLE_DEEPLINKING_META_DATA_KEY);
59+
} else {
60+
// Return true if the deep linking flag is not found in metadata.
61+
return true;
62+
}
63+
}
64+
4465
private FlutterActivityLaunchConfigs() {}
4566
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_DART_ENTRYPOINT_ARGS;
1717
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_DESTROY_ENGINE_WITH_ACTIVITY;
1818
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_INITIAL_ROUTE;
19-
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.HANDLE_DEEPLINKING_META_DATA_KEY;
2019
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.INITIAL_ROUTE_META_DATA_KEY;
2120
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.NORMAL_THEME_META_DATA_KEY;
21+
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.deepLinkEnabled;
2222

2323
import android.content.Context;
2424
import android.content.Intent;
@@ -695,9 +695,7 @@ protected boolean shouldAttachEngineToActivity() {
695695
protected boolean shouldHandleDeeplinking() {
696696
try {
697697
Bundle metaData = getMetaData();
698-
boolean shouldHandleDeeplinking =
699-
metaData != null ? metaData.getBoolean(HANDLE_DEEPLINKING_META_DATA_KEY) : false;
700-
return shouldHandleDeeplinking;
698+
return deepLinkEnabled(metaData);
701699
} catch (PackageManager.NameNotFoundException e) {
702700
return false;
703701
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ public void itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase3()
332332
Bundle bundle = new Bundle();
333333
FlutterActivity spyFlutterActivity = spy(flutterActivity);
334334
when(spyFlutterActivity.getMetaData()).thenReturn(bundle);
335-
// Empty bundle should return false.
336-
assertFalse(spyFlutterActivity.shouldHandleDeeplinking());
335+
// Empty bundle should return true.
336+
assertTrue(spyFlutterActivity.shouldHandleDeeplinking());
337337
}
338338

339339
@Test

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ public void itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase3()
180180
Bundle bundle = new Bundle();
181181
FlutterFragmentActivity spyFlutterActivity = spy(activity);
182182
when(spyFlutterActivity.getMetaData()).thenReturn(bundle);
183-
// Empty bundle should return false.
184-
assertFalse(spyFlutterActivity.shouldHandleDeeplinking());
183+
// Empty bundle should return true.
184+
assertTrue(spyFlutterActivity.shouldHandleDeeplinking());
185185
}
186186

187187
@Test

shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ - (void)userNotificationCenter:(UNUserNotificationCenter*)center
137137
- (BOOL)isFlutterDeepLinkingEnabled {
138138
NSNumber* isDeepLinkingEnabled =
139139
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"FlutterDeepLinkingEnabled"];
140-
// if not set, return NO
141-
return isDeepLinkingEnabled ? [isDeepLinkingEnabled boolValue] : NO;
140+
// if not set, return YES
141+
return isDeepLinkingEnabled ? [isDeepLinkingEnabled boolValue] : YES;
142142
}
143143

144144
// This method is called when opening an URL with custom schemes.

shell/platform/darwin/ios/framework/Source/FlutterAppDelegateTest.mm

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,18 @@ - (void)testLaunchUrlWithDeepLinkingNotSet {
8080
OCMStub([self.mockMainBundle objectForInfoDictionaryKey:@"FlutterDeepLinkingEnabled"])
8181
.andReturn(nil);
8282

83+
OCMStub([self.mockNavigationChannel
84+
invokeMethod:@"pushRouteInformation"
85+
arguments:@{@"location" : @"http://myApp/custom/route?query=test"}])
86+
.andReturn(@YES);
87+
8388
BOOL result =
8489
[self.appDelegate application:[UIApplication sharedApplication]
8590
openURL:[NSURL URLWithString:@"http://myApp/custom/route?query=test"]
8691
options:@{}];
87-
XCTAssertFalse(result);
88-
OCMReject([self.mockNavigationChannel invokeMethod:OCMOCK_ANY arguments:OCMOCK_ANY]);
92+
93+
XCTAssertTrue(result);
94+
OCMVerifyAll(self.mockNavigationChannel);
8995
}
9096

9197
- (void)testLaunchUrlWithDeepLinkingDisabled {

0 commit comments

Comments
 (0)