From 07f3103c67564bf22bd0574baaf5e96c7d074336 Mon Sep 17 00:00:00 2001 From: hangyu Date: Thu, 11 Apr 2024 14:24:51 -0700 Subject: [PATCH] Update the gradle task to add fallback scheme and host if needed when retrieving deep links. (#146470) This is to support feature: https://github.com/flutter/devtools/issues/7541 before behavior: do not show this link in the dev tool if there's no scheme or host target behavior: show the link in the dev tool with a error text : ( missing scheme/ missing domain) ## 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], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. [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 [Features we expect every widget to implement]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement [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 [Data Driven Fixes]: https://github.com/flutter/flutter/wiki/Data-driven-Fixes --- .../gradle/src/main/groovy/flutter.groovy | 11 ++-- ...gradle_outputs_app_link_settings_test.dart | 59 ++++++++++++++++++- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy b/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy index 5f191fe8b0..1e9d4c6392 100644 --- a/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy +++ b/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy @@ -570,11 +570,12 @@ class FlutterPlugin implements Plugin { } } } - schemes.each { scheme -> - hosts.each { host -> - if (!paths) { - appLinkSettings.deeplinks.add(new Deeplink(scheme: scheme, host: host, path: ".*", intentFilterCheck: intentFilterCheck)) - } else { + if(!hosts.isEmpty() || !paths.isEmpty()){ + if(schemes.isEmpty()){schemes.add(null)} + if(hosts.isEmpty()){hosts.add(null)} + if(paths.isEmpty()){paths.add('.*')} + schemes.each { scheme -> + hosts.each { host -> paths.each { path -> appLinkSettings.deeplinks.add(new Deeplink(scheme: scheme, host: host, path: path, intentFilterCheck: intentFilterCheck)) } diff --git a/packages/flutter_tools/test/integration.shard/android_gradle_outputs_app_link_settings_test.dart b/packages/flutter_tools/test/integration.shard/android_gradle_outputs_app_link_settings_test.dart index d33eda5115..60788ae9dc 100644 --- a/packages/flutter_tools/test/integration.shard/android_gradle_outputs_app_link_settings_test.dart +++ b/packages/flutter_tools/test/integration.shard/android_gradle_outputs_app_link_settings_test.dart @@ -192,6 +192,55 @@ final XmlElement nonBrowsableCategoryIntentFilter = XmlElement( ), ], ); +final XmlElement nonSchemeCategoryIntentFilter = XmlElement( + XmlName('intent-filter'), + [XmlAttribute(XmlName('autoVerify', 'android'), 'true')], + [ + XmlElement( + XmlName('action'), + [XmlAttribute(XmlName('name', 'android'), 'android.intent.action.VIEW')], + ), + XmlElement( + XmlName('category'), + [XmlAttribute(XmlName('name', 'android'), 'android.intent.category.DEFAULT')], + ), + XmlElement( + XmlName('category'), + [XmlAttribute(XmlName('name', 'android'), 'android.intent.category.BROWSABLE')], + ), + XmlElement( + XmlName('data'), + [ + XmlAttribute(XmlName('host', 'android'), 'non-browsable-category.com'), + ], + ), + ], +); +final XmlElement nonHostCategoryIntentFilter = XmlElement( + XmlName('intent-filter'), + [XmlAttribute(XmlName('autoVerify', 'android'), 'true')], + [ + XmlElement( + XmlName('action'), + [XmlAttribute(XmlName('name', 'android'), 'android.intent.action.VIEW')], + ), + XmlElement( + XmlName('category'), + [XmlAttribute(XmlName('name', 'android'), 'android.intent.category.DEFAULT')], + ), + XmlElement( + XmlName('category'), + [XmlAttribute(XmlName('name', 'android'), 'android.intent.category.BROWSABLE')], + ), + XmlElement( + XmlName('data'), + [ + XmlAttribute(XmlName('scheme', 'android'), 'http'), + XmlAttribute(XmlName('path', 'android'), '/path1'), + ], + ), + ], +); void main() { late Directory tempDir; @@ -206,8 +255,8 @@ void main() { void testDeeplink( dynamic deeplink, - String scheme, - String host, + String? scheme, + String? host, String path, { required bool hasAutoVerify, required bool hasActionView, @@ -251,6 +300,8 @@ void main() { activity.children.add(nonActionIntentFilter); activity.children.add(nonDefaultCategoryIntentFilter); activity.children.add(nonBrowsableCategoryIntentFilter); + activity.children.add(nonSchemeCategoryIntentFilter); + activity.children.add(nonHostCategoryIntentFilter); androidManifestFile.writeAsStringSync(androidManifest.toString(), flush: true); // Ensure that gradle files exists from templates. @@ -278,7 +329,7 @@ void main() { expect(json['applicationId'], 'com.example.testapp'); expect(json['deeplinkingFlagEnabled'], true); final List deeplinks = json['deeplinks']! as List; - expect(deeplinks.length, 8); + expect(deeplinks.length, 10); testDeeplink(deeplinks[0], 'http', 'pure-http.com', '.*', hasAutoVerify:true, hasActionView: true, hasDefaultCategory:true, hasBrowsableCategory: true); testDeeplink(deeplinks[1], 'custom', 'custom.com', '.*', hasAutoVerify:true, hasActionView: true, hasDefaultCategory:true, hasBrowsableCategory: true); testDeeplink(deeplinks[2], 'custom', 'hybrid.com', '.*', hasAutoVerify:true, hasActionView: true, hasDefaultCategory:true, hasBrowsableCategory: true); @@ -287,6 +338,8 @@ void main() { testDeeplink(deeplinks[5], 'http', 'non-action.com', '.*', hasAutoVerify:true, hasActionView: false, hasDefaultCategory:true, hasBrowsableCategory: true); testDeeplink(deeplinks[6], 'http', 'non-default-category.com', '.*', hasAutoVerify:true, hasActionView: true, hasDefaultCategory:false, hasBrowsableCategory: true); testDeeplink(deeplinks[7], 'http', 'non-browsable-category.com', '.*', hasAutoVerify:true, hasActionView: true, hasDefaultCategory:true, hasBrowsableCategory: false); + testDeeplink(deeplinks[8], null, 'non-browsable-category.com', '.*', hasAutoVerify:true, hasActionView: true, hasDefaultCategory:true, hasBrowsableCategory: true); + testDeeplink(deeplinks[9], 'http', null, '/path1', hasAutoVerify:true, hasActionView: true, hasDefaultCategory:true, hasBrowsableCategory: true); }); testWithoutContext(