forked from dotnet/android
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AndroidManifest] Add
Android.App.PropertyAttribute
(dotnet#9016)
Fixes: dotnet#8729 API-31 added support for a [`<property/>`][0] element within `AndroidManifest.xml`, which can be contained within `<activity/>`, `<application/>`, `<provider/>`, `<receiver/>`, and `<service/>` elements. Add a new `Android.App.PropertyAttribute` custom attribute which will emit `<property/>` within `AndroidManifest.xml`: [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class, AllowMultiple = true, Inherited = false)] public partial class PropertyAttribute : Attribute { public string Name {get;} public string? Resource {get;} public string? Value {get;} public PropertyAttribute (string name); } Semantics otherwise appear to be identical to `<meta-data/>`/`MetaDataAttribute`: only `Resource` or `Value` can be specified, etc. (This is checked by `aapt2`.) Using `[assembly:Property(…)]` will result in `<property/>` being emitted within the `<application/>` element. For example: [Service (Name = "fooService", ForegroundServiceType = Android.Content.PM.ForegroundService.TypeSpecialUse)] [Property ("android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE", Value = "explanation_for_special_use")] public partial class FooService : Service { } will emit the `AndroidManifest.xml` fragment: <service android:name="fooService" android:foregroundServiceType="specialUse"> <property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE" android:value="explanation_for_special_use" /> </service> [0]: https://developer.android.com/guide/topics/manifest/property-element
- Loading branch information
Showing
11 changed files
with
312 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace Android.App; | ||
|
||
public sealed partial class PropertyAttribute | ||
{ | ||
public PropertyAttribute (string name) | ||
{ | ||
Name = name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by 'manifest-attribute-codegen'. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
#nullable enable | ||
|
||
using System; | ||
|
||
namespace Android.App; | ||
|
||
[Serializable] | ||
[AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Class, AllowMultiple = true, Inherited = false)] | ||
public sealed partial class PropertyAttribute : Attribute { | ||
public string Name { get; private set; } | ||
|
||
public string? Resource { get; set; } | ||
|
||
public string? Value { get; set; } | ||
|
||
#if XABT_MANIFEST_EXTENSIONS | ||
static Xamarin.Android.Manifest.ManifestDocumentElement<PropertyAttribute> mapping = new ("property"); | ||
|
||
static PropertyAttribute () | ||
{ | ||
mapping.Add ( | ||
member: "Name", | ||
attributeName: "name", | ||
getter: self => self.Name, | ||
setter: null | ||
); | ||
mapping.Add ( | ||
member: "Resource", | ||
attributeName: "resource", | ||
getter: self => self.Resource, | ||
setter: (self, value) => self.Resource = (string?) value | ||
); | ||
mapping.Add ( | ||
member: "Value", | ||
attributeName: "value", | ||
getter: self => self.Value, | ||
setter: (self, value) => self.Value = (string?) value | ||
); | ||
|
||
AddManualMapping (); | ||
} | ||
|
||
static partial void AddManualMapping (); | ||
#endif // XABT_MANIFEST_EXTENSIONS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/Xamarin.Android.Build.Tasks/Mono.Android/PropertyAttribute.Partial.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Xml.Linq; | ||
using Mono.Cecil; | ||
|
||
using Java.Interop.Tools.Cecil; | ||
|
||
using Xamarin.Android.Manifest; | ||
|
||
namespace Android.App { | ||
|
||
partial class PropertyAttribute { | ||
|
||
ICollection<string> specified; | ||
|
||
public static IEnumerable<PropertyAttribute> FromCustomAttributeProvider (ICustomAttributeProvider type, TypeDefinitionCache cache) | ||
{ | ||
IEnumerable<CustomAttribute> attrs = type.GetCustomAttributes ("Android.App.PropertyAttribute"); | ||
if (!attrs.Any ()) | ||
yield break; | ||
foreach (CustomAttribute attr in attrs) { | ||
var self = new PropertyAttribute ((string) attr.ConstructorArguments [0].Value); | ||
self.specified = mapping.Load (self, attr, cache); | ||
self.specified.Add ("Name"); | ||
yield return self; | ||
} | ||
} | ||
|
||
public XElement ToElement (string packageName, TypeDefinitionCache cache) | ||
{ | ||
return mapping.ToElement (this, specified, packageName, cache); | ||
} | ||
} | ||
} |
Oops, something went wrong.