Skip to content

Commit 3ab04df

Browse files
authored
[AndroidManifest] Add Android.App.PropertyAttribute (#9016)
Fixes: #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
1 parent 8c4b353 commit 3ab04df

File tree

11 files changed

+312
-13
lines changed

11 files changed

+312
-13
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
<a name='resetEnabledSettingsOnAppDataCleared' format='boolean' api-level='33' />
9696
<a name='knownActivityEmbeddingCerts' api-level='33' />
9797
<a name='enableOnBackInvokedCallback' format='boolean' api-level='33' />
98+
<a name='allowCrossUidActivitySwitchFromBelow' format='boolean' api-level='35' />
9899
</e>
99100
<e name='permission' api-level='10'>
100101
<parent>manifest</parent>
@@ -219,6 +220,7 @@
219220
<a name='splitName' api-level='26' />
220221
<a name='forceUriPermissions' api-level='29' />
221222
<a name='attributionTags' api-level='31' />
223+
<a name='systemUserOnly' format='boolean' api-level='35' />
222224
</e>
223225
<e name='grant-uri-permission' api-level='10'>
224226
<parent>provider</parent>
@@ -263,6 +265,7 @@
263265
<a name='foregroundServiceType' api-level='29' />
264266
<a name='attributionTags' api-level='31' />
265267
<a name='allowSharedIsolatedProcess' format='boolean' api-level='34' />
268+
<a name='systemUserOnly' format='boolean' api-level='35' />
266269
</e>
267270
<e name='receiver' api-level='10'>
268271
<parent>application</parent>
@@ -350,6 +353,7 @@
350353
<a name='knownActivityEmbeddingCerts' api-level='33' />
351354
<a name='requiredDisplayCategory' format='string' api-level='34' />
352355
<a name='enableOnBackInvokedCallback' format='boolean' api-level='34' />
356+
<a name='requireContentUriPermissionFromCaller' format='string' api-level='35' />
353357
</e>
354358
<e name='activity-alias' api-level='10'>
355359
<parent>application</parent>
@@ -416,6 +420,16 @@
416420
<a name='sspAdvancedPattern' format='string' api-level='31' />
417421
<a name='sspSuffix' format='string' api-level='31' />
418422
<a name='pathSuffix' api-level='31' />
423+
<a name='query' format='string' api-level='35' />
424+
<a name='queryPrefix' format='string' api-level='35' />
425+
<a name='queryPattern' format='string' api-level='35' />
426+
<a name='queryAdvancedPattern' format='string' api-level='35' />
427+
<a name='querySuffix' format='string' api-level='35' />
428+
<a name='fragment' format='string' api-level='35' />
429+
<a name='fragmentPrefix' format='string' api-level='35' />
430+
<a name='fragmentPattern' format='string' api-level='35' />
431+
<a name='fragmentAdvancedPattern' format='string' api-level='35' />
432+
<a name='fragmentSuffix' format='string' api-level='35' />
419433
</e>
420434
<e name='category' api-level='10'>
421435
<parent>intent-filter</parent>
@@ -580,6 +594,7 @@
580594
<a name='memtagMode' api-level='31' />
581595
<a name='nativeHeapZeroInitialized' api-level='31' />
582596
<a name='name' api-level='33' />
597+
<a name='useEmbeddedDex' api-level='35' />
583598
</e>
584599
<e name='deny-permission' api-level='30'>
585600
<parent>processes</parent>
@@ -620,6 +635,7 @@
620635
<a name='name' api-level='33' />
621636
<a name='versionMajor' format='integer' api-level='33' />
622637
<a name='certDigest' format='string' api-level='33' />
638+
<a name='optional' format='boolean' api-level='35' />
623639
</e>
624640
<e name='apex-system-service' api-level='33'>
625641
<parent>application</parent>
@@ -636,4 +652,8 @@
636652
<parent>install-constraints</parent>
637653
<a name='value' api-level='34' />
638654
</e>
655+
<e name='uri-relative-filter-group' api-level='35'>
656+
<parent>intent-filter</parent>
657+
<a name='allow' format='boolean' api-level='35' />
658+
</e>
639659
</m>

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<type name="permission" namespace="Android.App" outputFile="src\Mono.Android\Android.App\PermissionAttribute.cs" usage="AttributeTargets.Assembly" allowMultiple="true" />
1717
<type name="permission-group" namespace="Android.App" outputFile="src\Mono.Android\Android.App\PermissionGroupAttribute.cs" usage="AttributeTargets.Assembly" allowMultiple="true" />
1818
<type name="permission-tree" namespace="Android.App" outputFile="src\Mono.Android\Android.App\PermissionTreeAttribute.cs" usage="AttributeTargets.Assembly" />
19+
<type name="property" namespace="Android.App" outputFile="src\Mono.Android\Android.App\PropertyAttribute.cs" usage="AttributeTargets.Assembly | AttributeTargets.Class" allowMultiple="true" defaultConstructor="false" />
1920
<type name="uses-configuration" namespace="Android.App" outputFile="src\Mono.Android\Android.App\UsesConfigurationAttribute.cs" usage="AttributeTargets.Assembly" allowMultiple="true" />
2021
<type name="uses-feature" namespace="Android.App" outputFile="src\Mono.Android\Android.App\UsesFeatureAttribute.cs" usage="AttributeTargets.Assembly" allowMultiple="true" />
2122
<type name="uses-library" namespace="Android.App" outputFile="src\Mono.Android\Android.App\UsesLibraryAttribute.cs" usage="AttributeTargets.Assembly | AttributeTargets.Class" allowMultiple="true" />
@@ -49,7 +50,6 @@
4950
<type name="process" ignore="true" />
5051
<type name="processes" ignore="true" />
5152
<type name="profileable" ignore="true" />
52-
<type name="property" ignore="true" />
5353
<type name="protected-broadcast" ignore="true" />
5454
<type name="public-key" ignore="true" />
5555
<type name="queries" ignore="true" />
@@ -65,6 +65,7 @@
6565
<type name="supports-input-input-type" ignore="true" />
6666
<type name="supports-screens" ignore="true" />
6767
<type name="upgrade-key-set" ignore="true" />
68+
<type name="uri-relative-filter-group" ignore="true" />
6869
<type name="uses-native-library" ignore="true" />
6970
<type name="uses-package" ignore="true" />
7071
<type name="uses-sdk" ignore="true" />
@@ -121,6 +122,7 @@
121122
<element path="activity.requiredDisplayCategory" visible="false" />
122123
<element path="activity.recreateOnConfigChanges" type="Android.Content.PM.ConfigChanges" />
123124
<element path="activity.relinquishTaskIdentity" type="bool" />
125+
<element path="activity.requireContentUriPermissionFromCaller" visible="false" />
124126
<element path="activity.resizeableActivity" type="bool" />
125127
<element path="activity.resumeWhilePausing" type="bool" />
126128
<element path="activity.rotationAnimation" type="Android.Views.WindowRotationAnimation" />
@@ -147,6 +149,7 @@
147149
<element path="application.allowBackup" type="bool" />
148150
<element path="application.allowClearUserData" type="bool" />
149151
<element path="application.allowClearUserDataOnFailedRestore" visible="false" />
152+
<element path="application.allowCrossUidActivitySwitchFromBelow" visible="false" />
150153
<element path="application.allowNativeHeapPointerTagging" visible="false" />
151154
<element path="application.allowTaskReparenting" type="bool" />
152155
<element path="application.appCategory" visible="false" />
@@ -303,6 +306,11 @@
303306
<element path="permission-tree.name" visible="true" />
304307
<element path="permission-tree.roundIcon" visible="true" />
305308

309+
<!-- <property> -->
310+
<element path="property.name" type="string" readonly="true" />
311+
<element path="property.resource" visible="true" />
312+
<element path="property.value" visible="true" />
313+
306314
<!-- <provider> -->
307315
<element path="provider.attributionTags" visible="false" />
308316
<element path="provider.authorities" type="string[]" readonly="true" manualMap="true" />
@@ -326,6 +334,7 @@
326334
<element path="provider.singleUser" visible="false" />
327335
<element path="provider.splitName" visible="false" />
328336
<element path="provider.syncable" type="bool" />
337+
<element path="provider.systemUserOnly" visible="false" />
329338
<element path="provider.visibleToInstantApps" visible="false" />
330339
<element path="provider.writePermission" visible="true" />
331340

@@ -366,6 +375,7 @@
366375
<element path="service.singleUser" visible="false" />
367376
<element path="service.splitName" visible="false" />
368377
<element path="service.stopWithTask" visible="false" />
378+
<element path="service.systemUserOnly" visible="false" />
369379
<element path="service.useAppZygote" visible="false" />
370380
<element path="service.visibleToInstantApps" visible="false" />
371381

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace Android.App;
4+
5+
public sealed partial class PropertyAttribute
6+
{
7+
public PropertyAttribute (string name)
8+
{
9+
Name = name;
10+
}
11+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by 'manifest-attribute-codegen'.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
#nullable enable
11+
12+
using System;
13+
14+
namespace Android.App;
15+
16+
[Serializable]
17+
[AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
18+
public sealed partial class PropertyAttribute : Attribute {
19+
public string Name { get; private set; }
20+
21+
public string? Resource { get; set; }
22+
23+
public string? Value { get; set; }
24+
25+
#if XABT_MANIFEST_EXTENSIONS
26+
static Xamarin.Android.Manifest.ManifestDocumentElement<PropertyAttribute> mapping = new ("property");
27+
28+
static PropertyAttribute ()
29+
{
30+
mapping.Add (
31+
member: "Name",
32+
attributeName: "name",
33+
getter: self => self.Name,
34+
setter: null
35+
);
36+
mapping.Add (
37+
member: "Resource",
38+
attributeName: "resource",
39+
getter: self => self.Resource,
40+
setter: (self, value) => self.Resource = (string?) value
41+
);
42+
mapping.Add (
43+
member: "Value",
44+
attributeName: "value",
45+
getter: self => self.Value,
46+
setter: (self, value) => self.Value = (string?) value
47+
);
48+
49+
AddManualMapping ();
50+
}
51+
52+
static partial void AddManualMapping ();
53+
#endif // XABT_MANIFEST_EXTENSIONS
54+
}

src/Mono.Android/Mono.Android.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
</Compile>
8282
<Compile Include="Android.App\IntentFilterAttribute.Partial.cs" />
8383
<Compile Include="Android.App\MetaDataAttribute.Partial.cs" />
84+
<Compile Include="Android.App\PropertyAttribute.Partial.cs" />
8485
<Compile Include="Android.App\UsesFeatureAttribute.Partial.cs" />
8586
<Compile Include="Android.App\UsesLibraryAttribute.Partial.cs" />
8687
<Compile Include="Android.App\UsesPermissionAttribute.Partial.cs" />
@@ -152,6 +153,7 @@
152153
<Compile Include="Android.App\PermissionGroupAttribute.cs" />
153154
<Compile Include="Android.App\PermissionTreeAttribute.cs" />
154155
<Compile Include="Android.App\ProgressDialog.cs" />
156+
<Compile Include="Android.App\PropertyAttribute.cs" />
155157
<Compile Include="Android.App\SearchManager.cs" />
156158
<Compile Include="Android.App\SupportsGLTextureAttribute.cs" />
157159
<Compile Include="Android.App\SyncContext.cs" />

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,13 @@ Android.App.Notification.TvExtender.TvExtender(Android.App.Notification! notif)
728728
Android.App.NotificationChannel.VibrationEffect.get -> Android.OS.VibrationEffect?
729729
Android.App.NotificationChannel.VibrationEffect.set -> void
730730
Android.App.PictureInPictureUiState.IsTransitioningToPip.get -> bool
731+
Android.App.PropertyAttribute
732+
Android.App.PropertyAttribute.Name.get -> string!
733+
Android.App.PropertyAttribute.PropertyAttribute(string! name) -> void
734+
Android.App.PropertyAttribute.Resource.get -> string?
735+
Android.App.PropertyAttribute.Resource.set -> void
736+
Android.App.PropertyAttribute.Value.get -> string?
737+
Android.App.PropertyAttribute.Value.set -> void
731738
Android.App.SdkSandbox.AppOwnedSdkSandboxInterface
732739
Android.App.SdkSandbox.AppOwnedSdkSandboxInterface.AppOwnedSdkSandboxInterface(string! name, long version, Android.OS.IBinder! binder) -> void
733740
Android.App.SdkSandbox.AppOwnedSdkSandboxInterface.DescribeContents() -> int
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Xml.Linq;
5+
using Mono.Cecil;
6+
7+
using Java.Interop.Tools.Cecil;
8+
9+
using Xamarin.Android.Manifest;
10+
11+
namespace Android.App {
12+
13+
partial class PropertyAttribute {
14+
15+
ICollection<string> specified;
16+
17+
public static IEnumerable<PropertyAttribute> FromCustomAttributeProvider (ICustomAttributeProvider type, TypeDefinitionCache cache)
18+
{
19+
IEnumerable<CustomAttribute> attrs = type.GetCustomAttributes ("Android.App.PropertyAttribute");
20+
if (!attrs.Any ())
21+
yield break;
22+
foreach (CustomAttribute attr in attrs) {
23+
var self = new PropertyAttribute ((string) attr.ConstructorArguments [0].Value);
24+
self.specified = mapping.Load (self, attr, cache);
25+
self.specified.Add ("Name");
26+
yield return self;
27+
}
28+
}
29+
30+
public XElement ToElement (string packageName, TypeDefinitionCache cache)
31+
{
32+
return mapping.ToElement (this, specified, packageName, cache);
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)