Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@
<a name='sspPrefix' format='string' api-level='19' />
<a name='sspPattern' format='string' api-level='19' />
<a name='pathAdvancedPattern' api-level='26' />
<a name='pathSuffix' api-level='31' />
</e>
<e name='category'>
<parent>intent-filter</parent>
Expand Down
8 changes: 8 additions & 0 deletions src/Mono.Android/Android.App/IntentFilterAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ public IntentFilterAttribute (string[] actions)
#endif
#if ANDROID_25
public string? RoundIcon {get; set;}
#endif
#if ANDROID_26
public string? DataPathAdvancedPattern {get; set;}
public string[]? DataPathAdvancedPatterns {get; set;}
#endif
#if ANDROID_31
public string? DataPathSuffix {get; set;}
public string[]? DataPathSuffixes {get; set;}
#endif
}
}
8 changes: 8 additions & 0 deletions src/Mono.Android/PublicAPI/API-34/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5215,6 +5215,10 @@ Android.App.IntentFilterAttribute.DataMimeTypes.get -> string![]?
Android.App.IntentFilterAttribute.DataMimeTypes.set -> void
Android.App.IntentFilterAttribute.DataPath.get -> string?
Android.App.IntentFilterAttribute.DataPath.set -> void
Android.App.IntentFilterAttribute.DataPathAdvancedPattern.get -> string?
Android.App.IntentFilterAttribute.DataPathAdvancedPattern.set -> void
Android.App.IntentFilterAttribute.DataPathAdvancedPatterns.get -> string![]?
Android.App.IntentFilterAttribute.DataPathAdvancedPatterns.set -> void
Android.App.IntentFilterAttribute.DataPathPattern.get -> string?
Android.App.IntentFilterAttribute.DataPathPattern.set -> void
Android.App.IntentFilterAttribute.DataPathPatterns.get -> string![]?
Expand All @@ -5225,6 +5229,10 @@ Android.App.IntentFilterAttribute.DataPathPrefixes.get -> string![]?
Android.App.IntentFilterAttribute.DataPathPrefixes.set -> void
Android.App.IntentFilterAttribute.DataPaths.get -> string![]?
Android.App.IntentFilterAttribute.DataPaths.set -> void
Android.App.IntentFilterAttribute.DataPathSuffix.get -> string?
Android.App.IntentFilterAttribute.DataPathSuffix.set -> void
Android.App.IntentFilterAttribute.DataPathSuffixes.get -> string![]?
Android.App.IntentFilterAttribute.DataPathSuffixes.set -> void
Android.App.IntentFilterAttribute.DataPort.get -> string?
Android.App.IntentFilterAttribute.DataPort.set -> void
Android.App.IntentFilterAttribute.DataPorts.get -> string![]?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ partial class IntentFilterAttribute {
{ "DataPort", "port" },
{ "DataScheme", "scheme" },
{ "AutoVerify", "autoVerify" },
{ "DataPathSuffix", "pathSuffix" },
{ "DataPathAdvancedPattern", "pathAdvancedPattern" },
};

static readonly Dictionary<string, Action<IntentFilterAttribute, object>> setters = new Dictionary<string, Action<IntentFilterAttribute, object>> () {
Expand All @@ -50,6 +52,10 @@ partial class IntentFilterAttribute {
{ "DataSchemes", (self, value) => self.DataSchemes = ToStringArray (value) },
{ "AutoVerify", (self, value) => self._AutoVerify = (bool) value },
{ "RoundIcon", (self, value) => self._RoundIcon = (string) value },
{ "DataPathSuffix", (self, value) => self.DataPathSuffix = (string) value },
{ "DataPathSuffixes", (self, value) => self.DataPathSuffixes = ToStringArray (value) },
{ "DataPathAdvancedPattern", (self, value) => self.DataPathAdvancedPattern = (string) value },
{ "DataPathAdvancedPatterns", (self, value) => self.DataPathAdvancedPatterns = ToStringArray (value) },
};

static string[] ToStringArray (object value)
Expand Down Expand Up @@ -126,6 +132,8 @@ IEnumerable<XElement> GetData (string packageName)
Func<string,XAttribute> toPathPrefix = v => ToAttribute ("DataPathPrefix", ReplacePackage (v, packageName));
Func<string,XAttribute> toPort = v => ToAttribute ("DataPort", ReplacePackage (v, packageName));
Func<string,XAttribute> toScheme = v => ToAttribute ("DataScheme", ReplacePackage (v, packageName));
Func<string,XAttribute> toPathSuffix = v => ToAttribute ("DataPathSuffix", ReplacePackage (v, packageName));
Func<string,XAttribute> toPathAdvancedPattern = v => ToAttribute ("DataPathAdvancedPattern", ReplacePackage (v, packageName));
Func<Func<string,XAttribute>, string, XElement> toData = (f, s) => string.IsNullOrEmpty (s) ? null : new XElement ("data", f (s));
var empty = Array.Empty<string> ();
var dataList = Enumerable.Empty<XElement> ()
Expand All @@ -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
Contributor

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.

.Concat ((DataPathAdvancedPatterns ?? empty).Select (p => toData (toPathAdvancedPattern, p)));
if (string.IsNullOrEmpty (DataHost) && string.IsNullOrEmpty (DataMimeType) &&
string.IsNullOrEmpty (DataPath) && string.IsNullOrEmpty (DataPathPattern) && string.IsNullOrEmpty (DataPathPrefix) &&
string.IsNullOrEmpty (DataPort) && string.IsNullOrEmpty (DataScheme) &&
!dataList.Any ())
string.IsNullOrEmpty (DataPort) && string.IsNullOrEmpty (DataScheme) && string.IsNullOrEmpty (DataPathSuffix) &&
string.IsNullOrEmpty (DataPathAdvancedPattern) && !dataList.Any ())
return null;
return new XElement [] {
toData (toHost, DataHost),
Expand All @@ -148,7 +158,9 @@ IEnumerable<XElement> GetData (string packageName)
toData (toPathPattern, DataPathPattern),
toData (toPathPrefix, DataPathPrefix),
toData (toPort, DataPort),
toData (toScheme, DataScheme) }
toData (toScheme, DataScheme),
toData (toPathSuffix, DataPathSuffix),
toData (toPathAdvancedPattern, DataPathAdvancedPattern)}
.Concat (dataList).Where (x => x != null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
using System.Collections.Generic;
using Xamarin.Android.Tasks;
using Xamarin.Android.Tools;
using Android.App;
using Mono.Cecil;
using System.Reflection;

namespace Xamarin.Android.Build.Tests
{
Expand Down Expand Up @@ -1118,5 +1121,53 @@ public void SupportedOSPlatformVersionErrors (string minSdkVersion, string suppo
}
}

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

public class IntentFilterAttributeDataPathTestClass { }

[Test]
public void IntentFilterDataPathTest ()
{
var asm = AssemblyDefinition.ReadAssembly (typeof (IntentFilterAttributeDataPathTestClass).Assembly.Location);
var type = asm.MainModule.GetType ("Xamarin.Android.Build.Tests.ManifestTest/IntentFilterAttributeDataPathTestClass");

var intent = IntentFilterAttribute.FromTypeDefinition (type).Single (f => f.Actions.Contains ("singularAction"));
var xml = intent.ToElement ("dummy.packageid").ToString ();

var expected =
@"<intent-filter>
<action p2:name=""singularAction"" xmlns:p2=""http://schemas.android.com/apk/res/android"" />
<data p2:pathSuffix=""singularSuffix"" xmlns:p2=""http://schemas.android.com/apk/res/android"" />
<data p2:pathAdvancedPattern=""singularPattern"" xmlns:p2=""http://schemas.android.com/apk/res/android"" />
</intent-filter>";

StringAssertEx.AreMultiLineEqual (expected, xml);
}

[Test]
public void IntentFilterDataPathsTest ()
{
var asm = AssemblyDefinition.ReadAssembly (typeof (IntentFilterAttributeDataPathTestClass).Assembly.Location);
var type = asm.MainModule.GetType ("Xamarin.Android.Build.Tests.ManifestTest/IntentFilterAttributeDataPathTestClass");

var intent = IntentFilterAttribute.FromTypeDefinition (type).Single (f => f.Actions.Contains ("pluralAction"));
var xml = intent.ToElement ("dummy.packageid").ToString ();

var expected =
@"<intent-filter>
<action p2:name=""pluralAction"" xmlns:p2=""http://schemas.android.com/apk/res/android"" />
<data p2:pathSuffix=""pluralSuffix1"" xmlns:p2=""http://schemas.android.com/apk/res/android"" />
<data p2:pathSuffix=""pluralSuffix2"" xmlns:p2=""http://schemas.android.com/apk/res/android"" />
<data p2:pathAdvancedPattern=""pluralPattern1"" xmlns:p2=""http://schemas.android.com/apk/res/android"" />
<data p2:pathAdvancedPattern=""pluralPattern2"" xmlns:p2=""http://schemas.android.com/apk/res/android"" />
</intent-filter>";

StringAssertEx.AreMultiLineEqual (expected, xml);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ public static bool ContainsOccurances (this IEnumerable<string> collection, stri
}
return found == count;
}

// Checks if two string are equal after normalizing string line endings
public static void AreMultiLineEqual (string expected, string actual)
{
expected = expected.ReplaceLineEndings ();
actual = actual.ReplaceLineEndings ();

Assert.AreEqual (expected, actual);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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.

<DefineConstants>$(DefineConstants);TRACE;HAVE_CECIL;MSBUILD;ANDROID_24;ANDROID_26;ANDROID_31</DefineConstants>
<AndroidGeneratedClassDirectory Condition=" '$(AndroidGeneratedClassDirectory)' == '' ">..\..\src\Mono.Android\obj\$(Configuration)\$(DotNetTargetFramework)\android-$(AndroidLatestStablePlatformId)\mcw</AndroidGeneratedClassDirectory>
<NoWarn>8632</NoWarn>
<SignAssembly>false</SignAssembly>
Expand Down