Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 578
[TrimmableTypeMap] Fix manifest builder gaps: SupportsGLTexture, UsesPermissionFlags, RoundIcon, dedup#11044
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1d9e4fb
Address remaining gaps vs old manifest path
simonrozsival 6f8f1f1
Add dedup, perf guard, and cleanup for assembly-level builder
simonrozsival 01e30ec
Resolve BackupAgent and ManageSpaceActivity to JNI names
simonrozsival 2b54030
Address Copilot review: dispose scanner, fix dedup, remove dead params
simonrozsival 9e35e01
Warn when BackupAgent/ManageSpaceActivity type cannot be resolved
simonrozsival File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
72 changes: 64 additions & 8 deletions
72 src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/AssemblyLevelElementBuilder.cs
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| #nullable enable | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Globalization; | ||
| @@ -21,63 +19,73 @@ internal static void AddAssemblyLevelElements (XElement manifest, XElement app, | ||
| { | ||
| var existingPermissions = new HashSet<string> ( | ||
| manifest.Elements ("permission").Select (e => (string?)e.Attribute (AttName)).OfType<string> ()); | ||
| var existingPermissionGroups = new HashSet<string> ( | ||
| manifest.Elements ("permission-group").Select (e => (string?)e.Attribute (AttName)).OfType<string> ()); | ||
| var existingPermissionTrees = new HashSet<string> ( | ||
| manifest.Elements ("permission-tree").Select (e => (string?)e.Attribute (AttName)).OfType<string> ()); | ||
| var existingUsesPermissions = new HashSet<string> ( | ||
| manifest.Elements ("uses-permission").Select (e => (string?)e.Attribute (AttName)).OfType<string> ()); | ||
| // <permission> elements | ||
| foreach (var perm in info.Permissions) { | ||
| if (string.IsNullOrEmpty (perm.Name) || existingPermissions.Contains (perm.Name)) { | ||
| if (string.IsNullOrEmpty (perm.Name) || !existingPermissions.Add (perm.Name)) { | ||
| continue; | ||
| } | ||
| var element = new XElement ("permission", new XAttribute (AttName, perm.Name)); | ||
| PropertyMapper.MapDictionaryProperties (element, perm.Properties, "Label", "label"); | ||
| PropertyMapper.MapDictionaryProperties (element, perm.Properties, "Description", "description"); | ||
| PropertyMapper.MapDictionaryProperties (element, perm.Properties, "Icon", "icon"); | ||
| PropertyMapper.MapDictionaryProperties (element, perm.Properties, "RoundIcon", "roundIcon"); | ||
| PropertyMapper.MapDictionaryProperties (element, perm.Properties, "PermissionGroup", "permissionGroup"); | ||
| PropertyMapper.MapDictionaryEnumProperty (element, perm.Properties, "ProtectionLevel", "protectionLevel", AndroidEnumConverter.ProtectionToString); | ||
| manifest.Add (element); | ||
| } | ||
| // <permission-group> elements | ||
| foreach (var pg in info.PermissionGroups) { | ||
| if (string.IsNullOrEmpty (pg.Name)) { | ||
| if (string.IsNullOrEmpty (pg.Name) || !existingPermissionGroups.Add (pg.Name)) { | ||
| continue; | ||
| } | ||
| var element = new XElement ("permission-group", new XAttribute (AttName, pg.Name)); | ||
| PropertyMapper.MapDictionaryProperties (element, pg.Properties, "Label", "label"); | ||
| PropertyMapper.MapDictionaryProperties (element, pg.Properties, "Description", "description"); | ||
| PropertyMapper.MapDictionaryProperties (element, pg.Properties, "Icon", "icon"); | ||
| PropertyMapper.MapDictionaryProperties (element, pg.Properties, "RoundIcon", "roundIcon"); | ||
| manifest.Add (element); | ||
| } | ||
| // <permission-tree> elements | ||
| foreach (var pt in info.PermissionTrees) { | ||
| if (string.IsNullOrEmpty (pt.Name)) { | ||
| if (string.IsNullOrEmpty (pt.Name) || !existingPermissionTrees.Add (pt.Name)) { | ||
| continue; | ||
| } | ||
| var element = new XElement ("permission-tree", new XAttribute (AttName, pt.Name)); | ||
| PropertyMapper.MapDictionaryProperties (element, pt.Properties, "Label", "label"); | ||
| PropertyMapper.MapDictionaryProperties (element, pt.Properties, "Icon", "icon"); | ||
| PropertyMapper.MapDictionaryProperties (element, pt.Properties, "RoundIcon", "roundIcon"); | ||
| manifest.Add (element); | ||
| } | ||
| // <uses-permission> elements | ||
| foreach (var up in info.UsesPermissions) { | ||
| if (string.IsNullOrEmpty (up.Name) || existingUsesPermissions.Contains (up.Name)) { | ||
| if (string.IsNullOrEmpty (up.Name) || !existingUsesPermissions.Add (up.Name)) { | ||
| continue; | ||
| } | ||
| var element = new XElement ("uses-permission", new XAttribute (AttName, up.Name)); | ||
| if (up.MaxSdkVersion.HasValue) { | ||
| element.SetAttributeValue (AndroidNs + "maxSdkVersion", up.MaxSdkVersion.Value.ToString (CultureInfo.InvariantCulture)); | ||
| } | ||
| if (!string.IsNullOrEmpty (up.UsesPermissionFlags)) { | ||
| element.SetAttributeValue (AndroidNs + "usesPermissionFlags", up.UsesPermissionFlags); | ||
| } | ||
| manifest.Add (element); | ||
| } | ||
| // <uses-feature> elements | ||
| var existingFeatures = new HashSet<string> ( | ||
| manifest.Elements ("uses-feature").Select (e => (string?)e.Attribute (AttName)).OfType<string> ()); | ||
| foreach (var uf in info.UsesFeatures) { | ||
| if (uf.Name is not null && !existingFeatures.Contains (uf.Name)) { | ||
| if (uf.Name is not null && existingFeatures.Add (uf.Name)) { | ||
| var element = new XElement ("uses-feature", | ||
| new XAttribute (AttName, uf.Name), | ||
| new XAttribute (AndroidNs + "required", uf.Required ? "true" : "false")); | ||
| @@ -153,11 +161,59 @@ internal static void AddAssemblyLevelElements (XElement manifest, XElement app, | ||
| } | ||
| manifest.Add (element); | ||
| } | ||
| // <supports-gl-texture> elements | ||
| var existingGLTextures = new HashSet<string> ( | ||
| manifest.Elements ("supports-gl-texture").Select (e => (string?)e.Attribute (AttName)).OfType<string> ()); | ||
| foreach (var gl in info.SupportsGLTextures) { | ||
| if (existingGLTextures.Add (gl.Name)) { | ||
| manifest.Add (new XElement ("supports-gl-texture", new XAttribute (AttName, gl.Name))); | ||
| } | ||
| } | ||
| } | ||
| internal static void ApplyApplicationProperties (XElement app, Dictionary<string, object?> properties) | ||
| internal static void ApplyApplicationProperties ( | ||
| XElement app, | ||
| Dictionary<string, object?> properties, | ||
| IReadOnlyList<JavaPeerInfo> allPeers, | ||
| Action<string>? warn = null) | ||
| { | ||
| PropertyMapper.ApplyMappings (app, properties, PropertyMapper.ApplicationPropertyMappings, skipExisting: true); | ||
| // BackupAgent and ManageSpaceActivity are Type properties — resolve managed type names to JNI names | ||
| ApplyTypeProperty (app, properties, allPeers, "BackupAgent", "backupAgent", warn); | ||
| ApplyTypeProperty (app, properties, allPeers, "ManageSpaceActivity", "manageSpaceActivity", warn); | ||
| } | ||
| static void ApplyTypeProperty ( | ||
| XElement app, | ||
| Dictionary<string, object?> properties, | ||
| IReadOnlyList<JavaPeerInfo> allPeers, | ||
| string propertyName, | ||
| string xmlAttrName, | ||
| Action<string>? warn) | ||
| { | ||
| if (app.Attribute (AndroidNs + xmlAttrName) is not null) { | ||
| return; | ||
| } | ||
| if (!properties.TryGetValue (propertyName, out var value) || value is not string managedName || managedName.Length == 0) { | ||
| return; | ||
| } | ||
| // Strip assembly qualification if present (e.g., "MyApp.MyAgent, MyAssembly") | ||
| var commaIndex = managedName.IndexOf (','); | ||
| if (commaIndex > 0) { | ||
| managedName = managedName.Substring (0, commaIndex).Trim (); | ||
| } | ||
| foreach (var peer in allPeers) { | ||
| if (peer.ManagedTypeName == managedName) { | ||
| app.SetAttributeValue (AndroidNs + xmlAttrName, peer.JavaName.Replace ('/', '.')); | ||
| return; | ||
| } | ||
| } | ||
jonathanpeppers marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| warn?.Invoke ($"Could not resolve {propertyName} type '{managedName}' to a Java peer for android:{xmlAttrName}."); | ||
| } | ||
| internal static void AddInternetPermission (XElement manifest) | ||
3 changes: 2 additions & 1 deletion
3 src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/ManifestGenerator.cs
This file contains hidden or 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
24 changes: 22 additions & 2 deletions
24 src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/AssemblyIndex.cs
This file contains hidden or 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
1 change: 1 addition & 0 deletions
1 src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/AssemblyManifestInfo.cs
This file contains hidden or 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
4 changes: 2 additions & 2 deletions
4 src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/JavaPeerScanner.cs
This file contains hidden or 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
6 changes: 6 additions & 0 deletions
6 src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/SupportsGLTextureInfo.cs
This file contains hidden or 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,6 @@ | ||
| namespace Microsoft.Android.Sdk.TrimmableTypeMap; | ||
| internal sealed record SupportsGLTextureInfo | ||
| { | ||
| public required string Name { get; init; } | ||
| } |
1 change: 1 addition & 0 deletions
1 src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/UsesPermissionInfo.cs
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2 tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/FixtureTestBase.cs
This file contains hidden or 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
99 changes: 99 additions & 0 deletions
99 tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/ManifestGeneratorTests.cs
This file contains hidden or 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
17 changes: 17 additions & 0 deletions
17 tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Scanner/AssemblyAttributeScanningTests.cs
This file contains hidden or 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
2 changes: 2 additions & 0 deletions
2 tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/TestFixtures/AssemblyAttributes.cs
This file contains hidden or 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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.