Fix package id calculation from resource identifier.
The aapt2 proto format for the resource table use the uppermost byte
of the resource identifier as an unsigned byte.
A corresponding fix in AGP is here:
http://ag/30321175
Bug: b/378470047
Change-Id: Ia4c0e832d3f501e57a36f2c1ae0a49627de23da1
diff --git a/src/resourceshrinker/java/com/android/build/shrinker/ResourceTableUtil.kt b/src/resourceshrinker/java/com/android/build/shrinker/ResourceTableUtil.kt
index 88bb5e4..e81c951 100644
--- a/src/resourceshrinker/java/com/android/build/shrinker/ResourceTableUtil.kt
+++ b/src/resourceshrinker/java/com/android/build/shrinker/ResourceTableUtil.kt
@@ -111,7 +111,7 @@
private fun packageIdFromIdentifier(
identifier: Int
): Int =
- identifier shr 24
+ identifier ushr 24
private fun typeIdFromIdentifier(
identifier: Int
diff --git a/src/test/java/com/android/tools/r8/androidresources/ResourceShrinkingWithFeatures.java b/src/test/java/com/android/tools/r8/androidresources/ResourceShrinkingWithFeatures.java
index 380dc25..e924ca6 100644
--- a/src/test/java/com/android/tools/r8/androidresources/ResourceShrinkingWithFeatures.java
+++ b/src/test/java/com/android/tools/r8/androidresources/ResourceShrinkingWithFeatures.java
@@ -43,6 +43,8 @@
return buildParameters(
getTestParameters().withDefaultDexRuntime().withAllApiLevels().build(),
BooleanUtils.values(),
+ // Ensure that we can handle resource ids both bigger and smaller than 127, see
+ // b/378470047
new Integer[] {0x7E, 0x80});
}
@@ -118,16 +120,9 @@
})
.inspectShrunkenResourcesForFeature(
resourceTableInspector -> {
- // TODO(b/378470047): Resource shrinker is currently not handling packageId>127
- // correctly
- if (featurePackageId > 127) {
- resourceTableInspector.assertContainsResourceWithName("string", "feature_used");
- resourceTableInspector.assertContainsResourceWithName("string", "feature_unused");
- } else {
resourceTableInspector.assertContainsResourceWithName("string", "feature_used");
resourceTableInspector.assertDoesNotContainResourceWithName(
"string", "feature_unused");
- }
},
FeatureSplit.class.getName())
.run(parameters.getRuntime(), Base.class)