Skip to content

Commit 789773e

Browse files
committed
[Mono.Android] Add pathSuffix and pathAdvancedPattern to [IntentFilter]
1 parent 0c5b60d commit 789773e

File tree

7 files changed

+89
-5
lines changed

7 files changed

+89
-5
lines changed

build-tools/manifest-attribute-codegen/manifest-definition.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@
345345
<a name='sspPrefix' format='string' api-level='19' />
346346
<a name='sspPattern' format='string' api-level='19' />
347347
<a name='pathAdvancedPattern' api-level='26' />
348+
<a name='pathSuffix' api-level='31' />
348349
</e>
349350
<e name='category'>
350351
<parent>intent-filter</parent>

src/Mono.Android/Android.App/IntentFilterAttribute.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ public IntentFilterAttribute (string[] actions)
4242
#endif
4343
#if ANDROID_25
4444
public string? RoundIcon {get; set;}
45+
#endif
46+
#if ANDROID_26
47+
public string? DataPathAdvancedPattern {get; set;}
48+
public string[]? DataPathAdvancedPatterns {get; set;}
49+
#endif
50+
#if ANDROID_31
51+
public string? DataPathSuffix {get; set;}
52+
public string[]? DataPathSuffixes {get; set;}
4553
#endif
4654
}
4755
}

src/Mono.Android/PublicAPI/API-34/PublicAPI.Unshipped.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5215,6 +5215,10 @@ Android.App.IntentFilterAttribute.DataMimeTypes.get -> string![]?
52155215
Android.App.IntentFilterAttribute.DataMimeTypes.set -> void
52165216
Android.App.IntentFilterAttribute.DataPath.get -> string?
52175217
Android.App.IntentFilterAttribute.DataPath.set -> void
5218+
Android.App.IntentFilterAttribute.DataPathAdvancedPattern.get -> string?
5219+
Android.App.IntentFilterAttribute.DataPathAdvancedPattern.set -> void
5220+
Android.App.IntentFilterAttribute.DataPathAdvancedPatterns.get -> string![]?
5221+
Android.App.IntentFilterAttribute.DataPathAdvancedPatterns.set -> void
52185222
Android.App.IntentFilterAttribute.DataPathPattern.get -> string?
52195223
Android.App.IntentFilterAttribute.DataPathPattern.set -> void
52205224
Android.App.IntentFilterAttribute.DataPathPatterns.get -> string![]?
@@ -5225,6 +5229,10 @@ Android.App.IntentFilterAttribute.DataPathPrefixes.get -> string![]?
52255229
Android.App.IntentFilterAttribute.DataPathPrefixes.set -> void
52265230
Android.App.IntentFilterAttribute.DataPaths.get -> string![]?
52275231
Android.App.IntentFilterAttribute.DataPaths.set -> void
5232+
Android.App.IntentFilterAttribute.DataPathSuffix.get -> string?
5233+
Android.App.IntentFilterAttribute.DataPathSuffix.set -> void
5234+
Android.App.IntentFilterAttribute.DataPathSuffixes.get -> string![]?
5235+
Android.App.IntentFilterAttribute.DataPathSuffixes.set -> void
52285236
Android.App.IntentFilterAttribute.DataPort.get -> string?
52295237
Android.App.IntentFilterAttribute.DataPort.set -> void
52305238
Android.App.IntentFilterAttribute.DataPorts.get -> string![]?

src/Xamarin.Android.Build.Tasks/Mono.Android/IntentFilterAttribute.Partial.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ partial class IntentFilterAttribute {
2727
{ "DataPort", "port" },
2828
{ "DataScheme", "scheme" },
2929
{ "AutoVerify", "autoVerify" },
30+
{ "DataPathSuffix", "pathSuffix" },
31+
{ "DataPathAdvancedPattern", "pathAdvancedPattern" },
3032
};
3133

3234
static readonly Dictionary<string, Action<IntentFilterAttribute, object>> setters = new Dictionary<string, Action<IntentFilterAttribute, object>> () {
@@ -50,6 +52,10 @@ partial class IntentFilterAttribute {
5052
{ "DataSchemes", (self, value) => self.DataSchemes = ToStringArray (value) },
5153
{ "AutoVerify", (self, value) => self._AutoVerify = (bool) value },
5254
{ "RoundIcon", (self, value) => self._RoundIcon = (string) value },
55+
{ "DataPathSuffix", (self, value) => self.DataPathSuffix = (string) value },
56+
{ "DataPathSuffixes", (self, value) => self.DataPathSuffixes = ToStringArray (value) },
57+
{ "DataPathAdvancedPattern", (self, value) => self.DataPathAdvancedPattern = (string) value },
58+
{ "DataPathAdvancedPatterns", (self, value) => self.DataPathAdvancedPatterns = ToStringArray (value) },
5359
};
5460

5561
static string[] ToStringArray (object value)
@@ -126,6 +132,8 @@ IEnumerable<XElement> GetData (string packageName)
126132
Func<string,XAttribute> toPathPrefix = v => ToAttribute ("DataPathPrefix", ReplacePackage (v, packageName));
127133
Func<string,XAttribute> toPort = v => ToAttribute ("DataPort", ReplacePackage (v, packageName));
128134
Func<string,XAttribute> toScheme = v => ToAttribute ("DataScheme", ReplacePackage (v, packageName));
135+
Func<string,XAttribute> toPathSuffix = v => ToAttribute ("DataPathSuffix", ReplacePackage (v, packageName));
136+
Func<string,XAttribute> toPathAdvancedPattern = v => ToAttribute ("DataPathAdvancedPattern", ReplacePackage (v, packageName));
129137
Func<Func<string,XAttribute>, string, XElement> toData = (f, s) => string.IsNullOrEmpty (s) ? null : new XElement ("data", f (s));
130138
var empty = Array.Empty<string> ();
131139
var dataList = Enumerable.Empty<XElement> ()
@@ -135,11 +143,13 @@ IEnumerable<XElement> GetData (string packageName)
135143
.Concat ((DataPathPatterns ?? empty).Select (p => toData (toPathPattern, p)))
136144
.Concat ((DataPathPrefixes ?? empty).Select (p => toData (toPathPrefix, p)))
137145
.Concat ((DataPorts ?? empty).Select (p => toData (toPort, p)))
138-
.Concat ((DataSchemes ?? empty).Select (p => toData (toScheme, p)));
146+
.Concat ((DataSchemes ?? empty).Select (p => toData (toScheme, p)))
147+
.Concat ((DataPathSuffixes ?? empty).Select (p => toData (toPathSuffix, p)))
148+
.Concat ((DataPathAdvancedPatterns ?? empty).Select (p => toData (toPathAdvancedPattern, p)));
139149
if (string.IsNullOrEmpty (DataHost) && string.IsNullOrEmpty (DataMimeType) &&
140150
string.IsNullOrEmpty (DataPath) && string.IsNullOrEmpty (DataPathPattern) && string.IsNullOrEmpty (DataPathPrefix) &&
141-
string.IsNullOrEmpty (DataPort) && string.IsNullOrEmpty (DataScheme) &&
142-
!dataList.Any ())
151+
string.IsNullOrEmpty (DataPort) && string.IsNullOrEmpty (DataScheme) && string.IsNullOrEmpty (DataPathSuffix) &&
152+
string.IsNullOrEmpty (DataPathAdvancedPattern) && !dataList.Any ())
143153
return null;
144154
return new XElement [] {
145155
toData (toHost, DataHost),
@@ -148,7 +158,9 @@ IEnumerable<XElement> GetData (string packageName)
148158
toData (toPathPattern, DataPathPattern),
149159
toData (toPathPrefix, DataPathPrefix),
150160
toData (toPort, DataPort),
151-
toData (toScheme, DataScheme) }
161+
toData (toScheme, DataScheme),
162+
toData (toPathSuffix, DataPathSuffix),
163+
toData (toPathAdvancedPattern, DataPathAdvancedPattern)}
152164
.Concat (dataList).Where (x => x != null);
153165
}
154166
}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManifestTest.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
using System.Collections.Generic;
1111
using Xamarin.Android.Tasks;
1212
using Xamarin.Android.Tools;
13+
using Android.App;
14+
using Mono.Cecil;
15+
using System.Reflection;
1316

1417
namespace Xamarin.Android.Build.Tests
1518
{
@@ -1118,5 +1121,48 @@ public void SupportedOSPlatformVersionErrors (string minSdkVersion, string suppo
11181121
}
11191122
}
11201123

1124+
[IntentFilter (new [] { "myaction" }, DataPathSuffix = "mysuffix", DataPathAdvancedPattern = "mypattern")]
1125+
[IntentFilter (new [] { "myaction" }, DataPathSuffixes = new [] { "mysuffix", "mysuffix2" }, DataPathAdvancedPatterns = new [] { "mypattern", "mypattern2" })]
1126+
public class IntentFilterAttributeDataPathTestClass { }
1127+
1128+
[Test]
1129+
public void IntentFilterDataPathTest ()
1130+
{
1131+
var asm = AssemblyDefinition.ReadAssembly (typeof (IntentFilterAttributeDataPathTestClass).Assembly.Location);
1132+
var type = asm.MainModule.GetType ("Xamarin.Android.Build.Tests.ManifestTest/IntentFilterAttributeDataPathTestClass");
1133+
1134+
var intent = IntentFilterAttribute.FromTypeDefinition (type).First ();
1135+
var xml = intent.ToElement ("blah").ToString ();
1136+
1137+
var expected =
1138+
@"<intent-filter>
1139+
<action p2:name=""myaction"" xmlns:p2=""http://schemas.android.com/apk/res/android"" />
1140+
<data p2:pathSuffix=""mysuffix"" xmlns:p2=""http://schemas.android.com/apk/res/android"" />
1141+
<data p2:pathAdvancedPattern=""mypattern"" xmlns:p2=""http://schemas.android.com/apk/res/android"" />
1142+
</intent-filter>";
1143+
1144+
StringAssertEx.AreMultiLineEqual (expected, xml);
1145+
}
1146+
1147+
[Test]
1148+
public void IntentFilterDataPathsTest ()
1149+
{
1150+
var asm = AssemblyDefinition.ReadAssembly (typeof (IntentFilterAttributeDataPathTestClass).Assembly.Location);
1151+
var type = asm.MainModule.GetType ("Xamarin.Android.Build.Tests.ManifestTest/IntentFilterAttributeDataPathTestClass");
1152+
1153+
var intent = IntentFilterAttribute.FromTypeDefinition (type).ElementAt (1);
1154+
var xml = intent.ToElement ("blah").ToString ();
1155+
1156+
var expected =
1157+
@"<intent-filter>
1158+
<action p2:name=""myaction"" xmlns:p2=""http://schemas.android.com/apk/res/android"" />
1159+
<data p2:pathSuffix=""mysuffix"" xmlns:p2=""http://schemas.android.com/apk/res/android"" />
1160+
<data p2:pathSuffix=""mysuffix2"" xmlns:p2=""http://schemas.android.com/apk/res/android"" />
1161+
<data p2:pathAdvancedPattern=""mypattern"" xmlns:p2=""http://schemas.android.com/apk/res/android"" />
1162+
<data p2:pathAdvancedPattern=""mypattern2"" xmlns:p2=""http://schemas.android.com/apk/res/android"" />
1163+
</intent-filter>";
1164+
1165+
StringAssertEx.AreMultiLineEqual (expected, xml);
1166+
}
11211167
}
11221168
}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BuildHelper.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ public static bool ContainsOccurances (this IEnumerable<string> collection, stri
9393
}
9494
return found == count;
9595
}
96+
97+
// Checks if two string are equal after normalizing string line endings
98+
public static void AreMultiLineEqual (string expected, string actual)
99+
{
100+
expected = expected.ReplaceLineEndings ();
101+
actual = actual.ReplaceLineEndings ();
102+
103+
Assert.AreEqual (expected, actual);
104+
}
96105
}
97106
}
98107

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1414
<OutputPath>$(MicrosoftAndroidSdkOutDir)</OutputPath>
1515
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
16-
<DefineConstants>$(DefineConstants);TRACE;HAVE_CECIL;MSBUILD;ANDROID_24</DefineConstants>
16+
<DefineConstants>$(DefineConstants);TRACE;HAVE_CECIL;MSBUILD;ANDROID_24;ANDROID_26;ANDROID_31</DefineConstants>
1717
<AndroidGeneratedClassDirectory Condition=" '$(AndroidGeneratedClassDirectory)' == '' ">..\..\src\Mono.Android\obj\$(Configuration)\$(DotNetTargetFramework)\android-$(AndroidLatestStablePlatformId)\mcw</AndroidGeneratedClassDirectory>
1818
<NoWarn>8632</NoWarn>
1919
<SignAssembly>false</SignAssembly>

0 commit comments

Comments
 (0)