Skip to content

Commit 07f3103

Browse files
authored
Update the gradle task to add fallback scheme and host if needed when retrieving deep links. (#146470)
This is to support feature: flutter/devtools#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]. <!-- 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 [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
1 parent 5bc3de9 commit 07f3103

2 files changed

Lines changed: 62 additions & 8 deletions

File tree

packages/flutter_tools/gradle/src/main/groovy/flutter.groovy

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,12 @@ class FlutterPlugin implements Plugin<Project> {
570570
}
571571
}
572572
}
573-
schemes.each { scheme ->
574-
hosts.each { host ->
575-
if (!paths) {
576-
appLinkSettings.deeplinks.add(new Deeplink(scheme: scheme, host: host, path: ".*", intentFilterCheck: intentFilterCheck))
577-
} else {
573+
if(!hosts.isEmpty() || !paths.isEmpty()){
574+
if(schemes.isEmpty()){schemes.add(null)}
575+
if(hosts.isEmpty()){hosts.add(null)}
576+
if(paths.isEmpty()){paths.add('.*')}
577+
schemes.each { scheme ->
578+
hosts.each { host ->
578579
paths.each { path ->
579580
appLinkSettings.deeplinks.add(new Deeplink(scheme: scheme, host: host, path: path, intentFilterCheck: intentFilterCheck))
580581
}

packages/flutter_tools/test/integration.shard/android_gradle_outputs_app_link_settings_test.dart

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,55 @@ final XmlElement nonBrowsableCategoryIntentFilter = XmlElement(
192192
),
193193
],
194194
);
195+
final XmlElement nonSchemeCategoryIntentFilter = XmlElement(
196+
XmlName('intent-filter'),
197+
<XmlAttribute>[XmlAttribute(XmlName('autoVerify', 'android'), 'true')],
198+
<XmlElement>[
199+
XmlElement(
200+
XmlName('action'),
201+
<XmlAttribute>[XmlAttribute(XmlName('name', 'android'), 'android.intent.action.VIEW')],
202+
),
203+
XmlElement(
204+
XmlName('category'),
205+
<XmlAttribute>[XmlAttribute(XmlName('name', 'android'), 'android.intent.category.DEFAULT')],
206+
),
207+
XmlElement(
208+
XmlName('category'),
209+
<XmlAttribute>[XmlAttribute(XmlName('name', 'android'), 'android.intent.category.BROWSABLE')],
210+
),
211+
XmlElement(
212+
XmlName('data'),
213+
<XmlAttribute>[
214+
XmlAttribute(XmlName('host', 'android'), 'non-browsable-category.com'),
215+
],
216+
),
217+
],
218+
);
219+
final XmlElement nonHostCategoryIntentFilter = XmlElement(
220+
XmlName('intent-filter'),
221+
<XmlAttribute>[XmlAttribute(XmlName('autoVerify', 'android'), 'true')],
222+
<XmlElement>[
223+
XmlElement(
224+
XmlName('action'),
225+
<XmlAttribute>[XmlAttribute(XmlName('name', 'android'), 'android.intent.action.VIEW')],
226+
),
227+
XmlElement(
228+
XmlName('category'),
229+
<XmlAttribute>[XmlAttribute(XmlName('name', 'android'), 'android.intent.category.DEFAULT')],
230+
),
231+
XmlElement(
232+
XmlName('category'),
233+
<XmlAttribute>[XmlAttribute(XmlName('name', 'android'), 'android.intent.category.BROWSABLE')],
234+
),
235+
XmlElement(
236+
XmlName('data'),
237+
<XmlAttribute>[
238+
XmlAttribute(XmlName('scheme', 'android'), 'http'),
239+
XmlAttribute(XmlName('path', 'android'), '/path1'),
240+
],
241+
),
242+
],
243+
);
195244

196245
void main() {
197246
late Directory tempDir;
@@ -206,8 +255,8 @@ void main() {
206255

207256
void testDeeplink(
208257
dynamic deeplink,
209-
String scheme,
210-
String host,
258+
String? scheme,
259+
String? host,
211260
String path, {
212261
required bool hasAutoVerify,
213262
required bool hasActionView,
@@ -251,6 +300,8 @@ void main() {
251300
activity.children.add(nonActionIntentFilter);
252301
activity.children.add(nonDefaultCategoryIntentFilter);
253302
activity.children.add(nonBrowsableCategoryIntentFilter);
303+
activity.children.add(nonSchemeCategoryIntentFilter);
304+
activity.children.add(nonHostCategoryIntentFilter);
254305
androidManifestFile.writeAsStringSync(androidManifest.toString(), flush: true);
255306

256307
// Ensure that gradle files exists from templates.
@@ -278,7 +329,7 @@ void main() {
278329
expect(json['applicationId'], 'com.example.testapp');
279330
expect(json['deeplinkingFlagEnabled'], true);
280331
final List<dynamic> deeplinks = json['deeplinks']! as List<dynamic>;
281-
expect(deeplinks.length, 8);
332+
expect(deeplinks.length, 10);
282333
testDeeplink(deeplinks[0], 'http', 'pure-http.com', '.*', hasAutoVerify:true, hasActionView: true, hasDefaultCategory:true, hasBrowsableCategory: true);
283334
testDeeplink(deeplinks[1], 'custom', 'custom.com', '.*', hasAutoVerify:true, hasActionView: true, hasDefaultCategory:true, hasBrowsableCategory: true);
284335
testDeeplink(deeplinks[2], 'custom', 'hybrid.com', '.*', hasAutoVerify:true, hasActionView: true, hasDefaultCategory:true, hasBrowsableCategory: true);
@@ -287,6 +338,8 @@ void main() {
287338
testDeeplink(deeplinks[5], 'http', 'non-action.com', '.*', hasAutoVerify:true, hasActionView: false, hasDefaultCategory:true, hasBrowsableCategory: true);
288339
testDeeplink(deeplinks[6], 'http', 'non-default-category.com', '.*', hasAutoVerify:true, hasActionView: true, hasDefaultCategory:false, hasBrowsableCategory: true);
289340
testDeeplink(deeplinks[7], 'http', 'non-browsable-category.com', '.*', hasAutoVerify:true, hasActionView: true, hasDefaultCategory:true, hasBrowsableCategory: false);
341+
testDeeplink(deeplinks[8], null, 'non-browsable-category.com', '.*', hasAutoVerify:true, hasActionView: true, hasDefaultCategory:true, hasBrowsableCategory: true);
342+
testDeeplink(deeplinks[9], 'http', null, '/path1', hasAutoVerify:true, hasActionView: true, hasDefaultCategory:true, hasBrowsableCategory: true);
290343
});
291344

292345
testWithoutContext(

0 commit comments

Comments
 (0)