Fix deserialization of @id aliases
I didn't realize that this was actually a thing, but:
<resources>
<item name="id1" type="id"></item>
<item name="id2" type="id">@id/id1</item>
</resources>
leads to a resource table which 'aapt dump resources' will render as:
resource 0x7f030000 com.pkg:id/id1: t=0x03 d=0x00000001 (s=0x0008 r=0x00)
resource 0x7f030001 com.pkg:id/id2: t=0x01 d=0x7f030000 (s=0x0008 r=0x00)
while 'aapt2 dump resources' printed:
type id id=03 entryCount=2
resource 0x7f030000 id/id1
() (id)
resource 0x7f030001 id/id2
() (id)
After this change, it prints:
type id id=03 entryCount=2
resource 0x7f030000 id/id1
() (id)
resource 0x7f030001 id/id2
() @id/id1
Bug: 69445910
Change-Id: I0001ff09345434577ac4c1d32f96a781f4190d8d
Tested: manual, see above
diff --git a/tools/aapt2/ResourceUtils.cpp b/tools/aapt2/ResourceUtils.cpp
index bd2ab53..03009aa 100644
--- a/tools/aapt2/ResourceUtils.cpp
+++ b/tools/aapt2/ResourceUtils.cpp
@@ -738,7 +738,13 @@
const android::Res_value& res_value,
StringPool* dst_pool) {
if (type == ResourceType::kId) {
- return util::make_unique<Id>();
+ if (res_value.dataType != android::Res_value::TYPE_REFERENCE &&
+ res_value.dataType != android::Res_value::TYPE_DYNAMIC_REFERENCE) {
+ // plain "id" resources are actually encoded as dummy values (aapt1 uses an empty string,
+ // while aapt2 uses a false boolean).
+ return util::make_unique<Id>();
+ }
+ // fall through to regular reference deserialization logic
}
const uint32_t data = util::DeviceToHost32(res_value.data);