Set deep linking flag to true by default (flutter/engine#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
This commit is contained in:
hangyu 2024-08-01 12:58:12 -07:00 committed by GitHub
parent 555c2ff92a
commit 5f18f2ebfd
7 changed files with 39 additions and 16 deletions

View File

@ -18,9 +18,9 @@ import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_DA
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_DESTROY_ENGINE_WITH_ACTIVITY; 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_ENABLE_STATE_RESTORATION;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_INITIAL_ROUTE; 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.INITIAL_ROUTE_META_DATA_KEY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.NORMAL_THEME_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.annotation.TargetApi;
import android.app.Activity; import android.app.Activity;
@ -1404,9 +1404,7 @@ public class FlutterActivity extends Activity
public boolean shouldHandleDeeplinking() { public boolean shouldHandleDeeplinking() {
try { try {
Bundle metaData = getMetaData(); Bundle metaData = getMetaData();
boolean shouldHandleDeeplinking = return deepLinkEnabled(metaData);
metaData != null ? metaData.getBoolean(HANDLE_DEEPLINKING_META_DATA_KEY) : false;
return shouldHandleDeeplinking;
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
return false; return false;
} }

View File

@ -4,6 +4,8 @@
package io.flutter.embedding.android; package io.flutter.embedding.android;
import android.os.Bundle;
/** Collection of Flutter launch configuration options. */ /** Collection of Flutter launch configuration options. */
// This class is public so that Flutter app developers can reference // This class is public so that Flutter app developers can reference
// BackgroundMode // BackgroundMode
@ -41,5 +43,24 @@ public class FlutterActivityLaunchConfigs {
transparent 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() {} private FlutterActivityLaunchConfigs() {}
} }

View File

@ -16,9 +16,9 @@ import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_DA
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_DART_ENTRYPOINT_ARGS; 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_DESTROY_ENGINE_WITH_ACTIVITY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.EXTRA_INITIAL_ROUTE; 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.INITIAL_ROUTE_META_DATA_KEY;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.NORMAL_THEME_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.Context;
import android.content.Intent; import android.content.Intent;
@ -695,9 +695,7 @@ public class FlutterFragmentActivity extends FragmentActivity
protected boolean shouldHandleDeeplinking() { protected boolean shouldHandleDeeplinking() {
try { try {
Bundle metaData = getMetaData(); Bundle metaData = getMetaData();
boolean shouldHandleDeeplinking = return deepLinkEnabled(metaData);
metaData != null ? metaData.getBoolean(HANDLE_DEEPLINKING_META_DATA_KEY) : false;
return shouldHandleDeeplinking;
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
return false; return false;
} }

View File

@ -332,8 +332,8 @@ public class FlutterActivityTest {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
FlutterActivity spyFlutterActivity = spy(flutterActivity); FlutterActivity spyFlutterActivity = spy(flutterActivity);
when(spyFlutterActivity.getMetaData()).thenReturn(bundle); when(spyFlutterActivity.getMetaData()).thenReturn(bundle);
// Empty bundle should return false. // Empty bundle should return true.
assertFalse(spyFlutterActivity.shouldHandleDeeplinking()); assertTrue(spyFlutterActivity.shouldHandleDeeplinking());
} }
@Test @Test

View File

@ -180,8 +180,8 @@ public class FlutterFragmentActivityTest {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
FlutterFragmentActivity spyFlutterActivity = spy(activity); FlutterFragmentActivity spyFlutterActivity = spy(activity);
when(spyFlutterActivity.getMetaData()).thenReturn(bundle); when(spyFlutterActivity.getMetaData()).thenReturn(bundle);
// Empty bundle should return false. // Empty bundle should return true.
assertFalse(spyFlutterActivity.shouldHandleDeeplinking()); assertTrue(spyFlutterActivity.shouldHandleDeeplinking());
} }
@Test @Test

View File

@ -137,8 +137,8 @@ static NSString* const kRestorationStateAppModificationKey = @"mod-date";
- (BOOL)isFlutterDeepLinkingEnabled { - (BOOL)isFlutterDeepLinkingEnabled {
NSNumber* isDeepLinkingEnabled = NSNumber* isDeepLinkingEnabled =
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"FlutterDeepLinkingEnabled"]; [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FlutterDeepLinkingEnabled"];
// if not set, return NO // if not set, return YES
return isDeepLinkingEnabled ? [isDeepLinkingEnabled boolValue] : NO; return isDeepLinkingEnabled ? [isDeepLinkingEnabled boolValue] : YES;
} }
// This method is called when opening an URL with custom schemes. // This method is called when opening an URL with custom schemes.

View File

@ -80,12 +80,18 @@ FLUTTER_ASSERT_ARC
OCMStub([self.mockMainBundle objectForInfoDictionaryKey:@"FlutterDeepLinkingEnabled"]) OCMStub([self.mockMainBundle objectForInfoDictionaryKey:@"FlutterDeepLinkingEnabled"])
.andReturn(nil); .andReturn(nil);
OCMStub([self.mockNavigationChannel
invokeMethod:@"pushRouteInformation"
arguments:@{@"location" : @"http://myApp/custom/route?query=test"}])
.andReturn(@YES);
BOOL result = BOOL result =
[self.appDelegate application:[UIApplication sharedApplication] [self.appDelegate application:[UIApplication sharedApplication]
openURL:[NSURL URLWithString:@"http://myApp/custom/route?query=test"] openURL:[NSURL URLWithString:@"http://myApp/custom/route?query=test"]
options:@{}]; options:@{}];
XCTAssertFalse(result);
OCMReject([self.mockNavigationChannel invokeMethod:OCMOCK_ANY arguments:OCMOCK_ANY]); XCTAssertTrue(result);
OCMVerifyAll(self.mockNavigationChannel);
} }
- (void)testLaunchUrlWithDeepLinkingDisabled { - (void)testLaunchUrlWithDeepLinkingDisabled {