summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceValues.cpp
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2017-06-01 15:22:57 -0700
committerAdam Lesinski <adamlesinski@google.com>2017-06-02 16:48:38 -0700
commitbab4ef56d7803f3a50ccfaca2729509338fcbb23 (patch)
tree3d3c1ad103f88f6ca60c46fc31872dee40244b3e /tools/aapt2/ResourceValues.cpp
parentd6fb3081d9ddd6384d7e764308e2967ce672d3e5 (diff)
AAPT2: Allow undefined resources (placeholders)
A resource defined like so: <item type="drawable" name="foo" /> should be assigned the value @null. The only exception is for <string> resources, which are given the empty string value (since <string></string> 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
Diffstat (limited to 'tools/aapt2/ResourceValues.cpp')
-rw-r--r--tools/aapt2/ResourceValues.cpp33
1 files changed, 22 insertions, 11 deletions
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<int32_t>(value.data);