From bab4ef56d7803f3a50ccfaca2729509338fcbb23 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Thu, 1 Jun 2017 15:22:57 -0700 Subject: AAPT2: Allow undefined resources (placeholders) A resource defined like so: should be assigned the value @null. The only exception is for resources, which are given the empty string value (since is ambiguous). The decision to use "" is based off the fact that old AAPT used to assign "" to all undefined resources, even non-string ones. Bug: 38425050 Test: make aapt2_tests Change-Id: Ib3e0f6f83d16ddd8b279c9fd44a07a37867b85e9 --- tools/aapt2/ResourceValues.cpp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'tools/aapt2/ResourceValues.cpp') diff --git a/tools/aapt2/ResourceValues.cpp b/tools/aapt2/ResourceValues.cpp index abfdec48df67..e808984c75f5 100644 --- a/tools/aapt2/ResourceValues.cpp +++ b/tools/aapt2/ResourceValues.cpp @@ -94,8 +94,8 @@ bool Reference::Equals(const Value* value) const { bool Reference::Flatten(android::Res_value* out_value) const { const ResourceId resid = id.value_or_default(ResourceId(0)); - const bool dynamic = - (resid.package_id() != kFrameworkPackageId && resid.package_id() != kAppPackageId); + const bool dynamic = resid.is_valid_dynamic() && resid.package_id() != kFrameworkPackageId && + resid.package_id() != kAppPackageId; if (reference_type == Reference::Type::kResource) { if (dynamic) { @@ -119,22 +119,29 @@ Reference* Reference::Clone(StringPool* /*new_pool*/) const { } void Reference::Print(std::ostream* out) const { - *out << "(reference) "; - if (reference_type == Reference::Type::kResource) { - *out << "@"; - if (private_reference) { - *out << "*"; + if (reference_type == Type::kResource) { + *out << "(reference) @"; + if (!name && !id) { + *out << "null"; + return; } } else { - *out << "?"; + *out << "(attr-reference) ?"; + } + + if (private_reference) { + *out << "*"; } if (name) { *out << name.value(); } - if (id && !Res_INTERNALID(id.value().id)) { - *out << " " << id.value(); + if (id && id.value().is_valid_dynamic()) { + if (name) { + *out << " "; + } + *out << id.value(); } } @@ -314,7 +321,11 @@ BinaryPrimitive* BinaryPrimitive::Clone(StringPool* /*new_pool*/) const { void BinaryPrimitive::Print(std::ostream* out) const { switch (value.dataType) { case android::Res_value::TYPE_NULL: - *out << "(null)"; + if (value.data == android::Res_value::DATA_NULL_EMPTY) { + *out << "(empty)"; + } else { + *out << "(null)"; + } break; case android::Res_value::TYPE_INT_DEC: *out << "(integer) " << static_cast(value.data); -- cgit v1.2.3-59-g8ed1b