Skip to content

feat: resolve resource references in component labels#1369

Merged
lihenggui merged 5 commits into
mainfrom
feature/resolve-label-resources
Nov 8, 2025
Merged

feat: resolve resource references in component labels#1369
lihenggui merged 5 commits into
mainfrom
feature/resolve-label-resources

Conversation

@lihenggui

Copy link
Copy Markdown
Owner

Enhance ManifestParser to resolve @string/xxx and @0x7fxxxxxx resource references to actual localized strings using Android Resources API.

Changes:

  • Create Resources instance from APK's AssetManager
  • Add resolveLabel() method to parse resource references
  • Add resolveComponentName() helper to extract simple names
  • Update all component parsers (Activity, Service, Receiver, Provider)
  • Fall back to component simple name when resolution fails
  • Support localization based on device configuration

The Resources constructor is deprecated but remains the only viable approach for reading resources from uninstalled APK files.

Enhance ManifestParser to resolve @string/xxx and @0x7fxxxxxx resource
references to actual localized strings using Android Resources API.

Changes:
- Create Resources instance from APK's AssetManager
- Add resolveLabel() method to parse resource references
- Add resolveComponentName() helper to extract simple names
- Update all component parsers (Activity, Service, Receiver, Provider)
- Fall back to component simple name when resolution fails
- Support localization based on device configuration

The Resources constructor is deprecated but remains the only viable
approach for reading resources from uninstalled APK files.

Change-Id: I4920ac4b57898eb17080d756f286c451fa19eea0
Add test cases to verify that component labels are properly resolved:
- Ensure resource references are resolved, not raw hex IDs
- Verify all component types (Activity/Service/Receiver/Provider)
- Check labels are not empty when present
- Validate fallback behavior for failed resolution

Change-Id: Ib75521ceb98d37396d37eb0a50109b60be25c26f
…-resources

Change-Id: Ic60415b85ac908d1b81844556604ccba8c403288
Remove PackageManager-based label resolution and use labels already
parsed by ManifestParser from APK resources. This eliminates redundant
pm calls and leverages the resource resolution implemented in
ManifestParser.

Changes:
- Remove resolveActivityLabel() method that used pm.getActivityInfo()
- Use manifestActivity.label directly for displayName
- Remove unused ComponentName import
- Fallback to simpleName when label is null

Change-Id: I07eebc6a843cb94463d866b00b2190df1c38ef53
Android stores resource IDs in binary XML as decimal numbers (e.g.,
@2132018028) rather than hexadecimal. Update resolveLabel() to parse
decimal resource IDs in addition to hex and symbolic references.

Supported formats:
- Decimal: @2132018028
- Hexadecimal: @0x7f0c001c
- Symbolic: @string/app_name
- Plain text: "My Activity"

Also update tests to verify all resource reference formats are
properly resolved (not left as raw @ references).

Change-Id: Ic62c965753c45238af319cdd3e49289b1fdf6dde
rawLabel.startsWith("@0x") -> rawLabel.substring(1).toLong(16).toInt()
rawLabel.contains("/") -> {
val (type, name) = rawLabel.substring(1).split("/", limit = 2)
resources.getIdentifier(name, type, null)

Check warning

Code scanning / Android Lint

Using discouraged APIs Warning

Use of this function is discouraged because resource reflection makes it harder to perform build optimizations and compile-time verification of code. It is much more efficient to retrieve resources by identifier (e.g. R.foo.bar) than by name (e.g. getIdentifier("bar", "foo", null)).
@lihenggui lihenggui merged commit 414d9ff into main Nov 8, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants