Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mono.Android] Add pathSuffix and pathAdvancedPattern to [IntentFilter] #8261

Merged
merged 2 commits into from
Aug 18, 2023

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Aug 10, 2023

Fixes: #8235

Adds the following properties to [IntentFilter] to allow the specified AndroidManifest.xml attributes to be generated:

  • DataPathSuffix -> pathSuffix
  • DataPathSuffixes -> pathSuffix
  • DataPathAdvancedPattern -> pathAdvancedPattern
  • DataPathAdvancedPatterns -> pathAdvancedPattern

Note that while we have a script to detect new elements added to AndroidManifest.xml, the code must be written manually. Filed #8272 because we really should automate this code generation.

@jpobst jpobst force-pushed the intent-manifest branch 2 times, most recently from 6add33f to 028dd6c Compare August 10, 2023 20:34
@@ -13,7 +13,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputPath>$(MicrosoftAndroidSdkOutDir)</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<DefineConstants>$(DefineConstants);TRACE;HAVE_CECIL;MSBUILD;ANDROID_24</DefineConstants>
Copy link
Member

@jonathanpeppers jonathanpeppers Aug 14, 2023

Choose a reason for hiding this comment

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

There is a block above like:

#if ANDROID_25
		public string?    RoundIcon       {get; set;}
#endif

Is it possible RoundIcon doesn't actually work? Do we need to define all of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -135,11 +143,13 @@ IEnumerable<XElement> GetData (string packageName)
.Concat ((DataPathPatterns ?? empty).Select (p => toData (toPathPattern, p)))
.Concat ((DataPathPrefixes ?? empty).Select (p => toData (toPathPrefix, p)))
.Concat ((DataPorts ?? empty).Select (p => toData (toPort, p)))
.Concat ((DataSchemes ?? empty).Select (p => toData (toScheme, p)));
.Concat ((DataSchemes ?? empty).Select (p => toData (toScheme, p)))
.Concat ((DataPathSuffixes ?? empty).Select (p => toData (toPathSuffix, p)))
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't "feel" right to me, in that we're adding both DataPathSuffix and DataPathSuffixes, but this code only deals with DataPathSuffixes, not DataPathSuffix. Ditto the following line, which appears to deal only with DataPathAdvancedPatterns, and not DataPathAdvancedPattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This class felt like maybe the code was trying to be too "clever", hindering readability. It would likely get rewritten to something a little more straightforward if/when we do this: #8272.

@@ -1118,5 +1121,48 @@ public void SupportedOSPlatformVersionErrors (string minSdkVersion, string suppo
}
}

[IntentFilter (new [] { "myaction" }, DataPathSuffix = "mysuffix", DataPathAdvancedPattern = "mypattern")]
Copy link
Member

Choose a reason for hiding this comment

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

I think this test is providing a false sense of security, as the "singular" DataPathSuffix + DataPathAdvancedPattern attribute uses the same values as the "plural" DataPathSuffixes and DataPathAdvancedPatterns form on the following line.

These should use different values, so that we can more easily verify that both are working.

That said, based on the current expected, I think my previous feeling is wrong, because the test method uses .First(), which will be the "singular' data, and that's working. Yay! (But I don't understand how or why it's working…)

Please update this and the following line so that unique values are used, a'la:

[IntentFilter (new [] { "singularAction" },
    DataPathSuffix = "singularSuffix",
    DataPathAdvancedPattern = "singularPattern")]
[IntentFilter (new [] { "pluralAction" },
    DataPathSuffixes = new [] { "pluralSuffix1", "pluralSuffix2" },
    DataPathAdvancedPatterns = new [] { "pluralPattern1", "pluralPattern2" })]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, tests are much clearer now.

@jonpryor
Copy link
Member

draft commit message:

Fixes: https://github.com/xamarin/xamarin-android/issues/8235

Context: https://github.com/xamarin/xamarin-android/issues/8272

Add the following properties to `IntentFilterAttribute` to allow
the various `AndroidManifest.xml` [`<data/>`][0] attributes to
be generated:

  - `IntentFilterAttribute.DataPathSuffix` generates
    [`//intent-filter/data/@pathSuffix`][1].
  - `IntentFilterAttribute.DataPathSuffixes` generates
    [`//intent-filter/data/@pathSuffix`][1].
  - `IntentFilterAttribute.DataPathAdvancedPattern` generates
    [`//intent-filter/data/@pathAdvancedPattern`][1].
  - `IntentFilterAttribute.DataPathAdvancedPatterns` generates
    [`//intent-filter/data/@pathAdvancedPattern`][1].

Note that while we have a script to detect new elements added to
`AndroidManifest.xml`, the code must be written manually.

TODO: Issue #8272 to automate this code generation.

[0]: https://developer.android.com/guide/topics/manifest/data-element
[1]: https://developer.android.com/guide/topics/manifest/data-element#path

@jonpryor jonpryor merged commit f3a2233 into main Aug 18, 2023
@jonpryor jonpryor deleted the intent-manifest branch August 18, 2023 17:47
jonathanpeppers pushed a commit that referenced this pull request Aug 22, 2023
Fixes: #8235

Context: #8272

Add the following properties to `IntentFilterAttribute` to allow
the various `AndroidManifest.xml` [`<data/>`][0] attributes to
be generated:

  - `IntentFilterAttribute.DataPathSuffix` generates
    [`//intent-filter/data/@pathSuffix`][1].
  - `IntentFilterAttribute.DataPathSuffixes` generates
    [`//intent-filter/data/@pathSuffix`][1].
  - `IntentFilterAttribute.DataPathAdvancedPattern` generates
    [`//intent-filter/data/@pathAdvancedPattern`][1].
  - `IntentFilterAttribute.DataPathAdvancedPatterns` generates
    [`//intent-filter/data/@pathAdvancedPattern`][1].

Note that while we have a script to detect new elements added to
`AndroidManifest.xml`, the code must be written manually.

TODO: Issue #8272 to automate this code generation.

[0]: https://developer.android.com/guide/topics/manifest/data-element
[1]: https://developer.android.com/guide/topics/manifest/data-element#path
grendello added a commit to grendello/xamarin-android that referenced this pull request Sep 4, 2023
* main: (57 commits)
  Bump to dotnet/installer@2809943e7a 8.0.100-rc.2.23431.5 (dotnet#8317)
  [build] Use Microsoft OpenJDK 17.0.8 (dotnet#8309)
  [Mono.Android] Add missing `[Flags]` attribute for generated enums. (dotnet#8310)
  Bump to dotnet/installer@c5e45fd659 8.0.100-rc.2.23427.4 (dotnet#8305)
  [xaprepare] Improve dotnet-install script logging (dotnet#8312)
  [xaprepare] Fix dotnet-install script size check (dotnet#8311)
  [Xamarin.Android.Build.Tasks] improve net6.0 "out of support" message (dotnet#8307)
  [monodroid] Fix the EnableNativeAnalyzers build (dotnet#8293)
  Bump to dotnet/installer@56d8c6497c 8.0.100-rc.2.23422.31 (dotnet#8291)
  [Xamarin.Android.Build.Tasks] Fix APT2264 error on Windows. (dotnet#8289)
  [Mono.Android] Marshal .NET stack trace to Throwable.getStackTrace() (dotnet#8185)
  [tests] Skip sign check when installing MAUI (dotnet#8288)
  Bump to xamarin/monodroid@057b17fe (dotnet#8286)
  [Xamarin.Android.Build.Tasks] add $(AndroidStripILAfterAOT) (dotnet#8172)
  Bump to dotnet/installer@ec2c1ec1b1 8.0.100-rc.2.23420.6 (dotnet#8281)
  Bump to dotnet/installer@001d8e4465 8.0.100-rc.2.23417.14 (dotnet#8276)
  [Mono.Android] [IntentFilter] pathSuffix & pathAdvancedPattern  (dotnet#8261)
  $(AndroidPackVersionSuffix)=rc.2; net8 is 34.0.0-rc.2 (dotnet#8278)
  Bump to xamarin/xamarin-android-tools/main@52f0866 (dotnet#8241)
  [build] set file extension for common `ToolExe` values (dotnet#8267)
  ...
grendello added a commit to grendello/xamarin-android that referenced this pull request Sep 4, 2023
* main: (102 commits)
  Bump to dotnet/installer@2809943e7a 8.0.100-rc.2.23431.5 (dotnet#8317)
  [build] Use Microsoft OpenJDK 17.0.8 (dotnet#8309)
  [Mono.Android] Add missing `[Flags]` attribute for generated enums. (dotnet#8310)
  Bump to dotnet/installer@c5e45fd659 8.0.100-rc.2.23427.4 (dotnet#8305)
  [xaprepare] Improve dotnet-install script logging (dotnet#8312)
  [xaprepare] Fix dotnet-install script size check (dotnet#8311)
  [Xamarin.Android.Build.Tasks] improve net6.0 "out of support" message (dotnet#8307)
  [monodroid] Fix the EnableNativeAnalyzers build (dotnet#8293)
  Bump to dotnet/installer@56d8c6497c 8.0.100-rc.2.23422.31 (dotnet#8291)
  [Xamarin.Android.Build.Tasks] Fix APT2264 error on Windows. (dotnet#8289)
  [Mono.Android] Marshal .NET stack trace to Throwable.getStackTrace() (dotnet#8185)
  [tests] Skip sign check when installing MAUI (dotnet#8288)
  Bump to xamarin/monodroid@057b17fe (dotnet#8286)
  [Xamarin.Android.Build.Tasks] add $(AndroidStripILAfterAOT) (dotnet#8172)
  Bump to dotnet/installer@ec2c1ec1b1 8.0.100-rc.2.23420.6 (dotnet#8281)
  Bump to dotnet/installer@001d8e4465 8.0.100-rc.2.23417.14 (dotnet#8276)
  [Mono.Android] [IntentFilter] pathSuffix & pathAdvancedPattern  (dotnet#8261)
  $(AndroidPackVersionSuffix)=rc.2; net8 is 34.0.0-rc.2 (dotnet#8278)
  Bump to xamarin/xamarin-android-tools/main@52f0866 (dotnet#8241)
  [build] set file extension for common `ToolExe` values (dotnet#8267)
  ...
grendello added a commit to grendello/xamarin-android that referenced this pull request Sep 4, 2023
* main: (68 commits)
  Bump to dotnet/installer@2809943e7a 8.0.100-rc.2.23431.5 (dotnet#8317)
  [build] Use Microsoft OpenJDK 17.0.8 (dotnet#8309)
  [Mono.Android] Add missing `[Flags]` attribute for generated enums. (dotnet#8310)
  Bump to dotnet/installer@c5e45fd659 8.0.100-rc.2.23427.4 (dotnet#8305)
  [xaprepare] Improve dotnet-install script logging (dotnet#8312)
  [xaprepare] Fix dotnet-install script size check (dotnet#8311)
  [Xamarin.Android.Build.Tasks] improve net6.0 "out of support" message (dotnet#8307)
  [monodroid] Fix the EnableNativeAnalyzers build (dotnet#8293)
  Bump to dotnet/installer@56d8c6497c 8.0.100-rc.2.23422.31 (dotnet#8291)
  [Xamarin.Android.Build.Tasks] Fix APT2264 error on Windows. (dotnet#8289)
  [Mono.Android] Marshal .NET stack trace to Throwable.getStackTrace() (dotnet#8185)
  [tests] Skip sign check when installing MAUI (dotnet#8288)
  Bump to xamarin/monodroid@057b17fe (dotnet#8286)
  [Xamarin.Android.Build.Tasks] add $(AndroidStripILAfterAOT) (dotnet#8172)
  Bump to dotnet/installer@ec2c1ec1b1 8.0.100-rc.2.23420.6 (dotnet#8281)
  Bump to dotnet/installer@001d8e4465 8.0.100-rc.2.23417.14 (dotnet#8276)
  [Mono.Android] [IntentFilter] pathSuffix & pathAdvancedPattern  (dotnet#8261)
  $(AndroidPackVersionSuffix)=rc.2; net8 is 34.0.0-rc.2 (dotnet#8278)
  Bump to xamarin/xamarin-android-tools/main@52f0866 (dotnet#8241)
  [build] set file extension for common `ToolExe` values (dotnet#8267)
  ...
grendello added a commit to grendello/xamarin-android that referenced this pull request Sep 4, 2023
* main: (53 commits)
  Bump to dotnet/installer@2809943e7a 8.0.100-rc.2.23431.5 (dotnet#8317)
  [build] Use Microsoft OpenJDK 17.0.8 (dotnet#8309)
  [Mono.Android] Add missing `[Flags]` attribute for generated enums. (dotnet#8310)
  Bump to dotnet/installer@c5e45fd659 8.0.100-rc.2.23427.4 (dotnet#8305)
  [xaprepare] Improve dotnet-install script logging (dotnet#8312)
  [xaprepare] Fix dotnet-install script size check (dotnet#8311)
  [Xamarin.Android.Build.Tasks] improve net6.0 "out of support" message (dotnet#8307)
  [monodroid] Fix the EnableNativeAnalyzers build (dotnet#8293)
  Bump to dotnet/installer@56d8c6497c 8.0.100-rc.2.23422.31 (dotnet#8291)
  [Xamarin.Android.Build.Tasks] Fix APT2264 error on Windows. (dotnet#8289)
  [Mono.Android] Marshal .NET stack trace to Throwable.getStackTrace() (dotnet#8185)
  [tests] Skip sign check when installing MAUI (dotnet#8288)
  Bump to xamarin/monodroid@057b17fe (dotnet#8286)
  [Xamarin.Android.Build.Tasks] add $(AndroidStripILAfterAOT) (dotnet#8172)
  Bump to dotnet/installer@ec2c1ec1b1 8.0.100-rc.2.23420.6 (dotnet#8281)
  Bump to dotnet/installer@001d8e4465 8.0.100-rc.2.23417.14 (dotnet#8276)
  [Mono.Android] [IntentFilter] pathSuffix & pathAdvancedPattern  (dotnet#8261)
  $(AndroidPackVersionSuffix)=rc.2; net8 is 34.0.0-rc.2 (dotnet#8278)
  Bump to xamarin/xamarin-android-tools/main@52f0866 (dotnet#8241)
  [build] set file extension for common `ToolExe` values (dotnet#8267)
  ...
grendello added a commit to grendello/xamarin-android that referenced this pull request Sep 4, 2023
* main: (25 commits)
  Bump to dotnet/installer@2809943e7a 8.0.100-rc.2.23431.5 (dotnet#8317)
  [build] Use Microsoft OpenJDK 17.0.8 (dotnet#8309)
  [Mono.Android] Add missing `[Flags]` attribute for generated enums. (dotnet#8310)
  Bump to dotnet/installer@c5e45fd659 8.0.100-rc.2.23427.4 (dotnet#8305)
  [xaprepare] Improve dotnet-install script logging (dotnet#8312)
  [xaprepare] Fix dotnet-install script size check (dotnet#8311)
  [Xamarin.Android.Build.Tasks] improve net6.0 "out of support" message (dotnet#8307)
  [monodroid] Fix the EnableNativeAnalyzers build (dotnet#8293)
  Bump to dotnet/installer@56d8c6497c 8.0.100-rc.2.23422.31 (dotnet#8291)
  [Xamarin.Android.Build.Tasks] Fix APT2264 error on Windows. (dotnet#8289)
  [Mono.Android] Marshal .NET stack trace to Throwable.getStackTrace() (dotnet#8185)
  [tests] Skip sign check when installing MAUI (dotnet#8288)
  Bump to xamarin/monodroid@057b17fe (dotnet#8286)
  [Xamarin.Android.Build.Tasks] add $(AndroidStripILAfterAOT) (dotnet#8172)
  Bump to dotnet/installer@ec2c1ec1b1 8.0.100-rc.2.23420.6 (dotnet#8281)
  Bump to dotnet/installer@001d8e4465 8.0.100-rc.2.23417.14 (dotnet#8276)
  [Mono.Android] [IntentFilter] pathSuffix & pathAdvancedPattern  (dotnet#8261)
  $(AndroidPackVersionSuffix)=rc.2; net8 is 34.0.0-rc.2 (dotnet#8278)
  Bump to xamarin/xamarin-android-tools/main@52f0866 (dotnet#8241)
  [build] set file extension for common `ToolExe` values (dotnet#8267)
  ...
grendello added a commit to grendello/xamarin-android that referenced this pull request Sep 4, 2023
* main: (38 commits)
  Bump to dotnet/installer@2809943e7a 8.0.100-rc.2.23431.5 (dotnet#8317)
  [build] Use Microsoft OpenJDK 17.0.8 (dotnet#8309)
  [Mono.Android] Add missing `[Flags]` attribute for generated enums. (dotnet#8310)
  Bump to dotnet/installer@c5e45fd659 8.0.100-rc.2.23427.4 (dotnet#8305)
  [xaprepare] Improve dotnet-install script logging (dotnet#8312)
  [xaprepare] Fix dotnet-install script size check (dotnet#8311)
  [Xamarin.Android.Build.Tasks] improve net6.0 "out of support" message (dotnet#8307)
  [monodroid] Fix the EnableNativeAnalyzers build (dotnet#8293)
  Bump to dotnet/installer@56d8c6497c 8.0.100-rc.2.23422.31 (dotnet#8291)
  [Xamarin.Android.Build.Tasks] Fix APT2264 error on Windows. (dotnet#8289)
  [Mono.Android] Marshal .NET stack trace to Throwable.getStackTrace() (dotnet#8185)
  [tests] Skip sign check when installing MAUI (dotnet#8288)
  Bump to xamarin/monodroid@057b17fe (dotnet#8286)
  [Xamarin.Android.Build.Tasks] add $(AndroidStripILAfterAOT) (dotnet#8172)
  Bump to dotnet/installer@ec2c1ec1b1 8.0.100-rc.2.23420.6 (dotnet#8281)
  Bump to dotnet/installer@001d8e4465 8.0.100-rc.2.23417.14 (dotnet#8276)
  [Mono.Android] [IntentFilter] pathSuffix & pathAdvancedPattern  (dotnet#8261)
  $(AndroidPackVersionSuffix)=rc.2; net8 is 34.0.0-rc.2 (dotnet#8278)
  Bump to xamarin/xamarin-android-tools/main@52f0866 (dotnet#8241)
  [build] set file extension for common `ToolExe` values (dotnet#8267)
  ...
@github-actions github-actions bot locked and limited conversation to collaborators Jan 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IntentFilterAttribute is missing PathSuffix and PathAdvancePattern
4 participants