From ea4e5ecc27793b5c1dd2eda291f752b3f900ee6c Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Wed, 10 Dec 2014 15:46:51 -0800 Subject: AAPT: attributes showing up after v21 attributes would be removed for pre-21 devices There was an inconsistency in the indexing when removing attributes in layouts. Now we account for that shift that happens when you delete an attribute. Bug:18707321 Change-Id: I656eee3fb614168fa8ceeff379e8594708961dad --- tools/aapt/ResourceTable.cpp | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) (limited to 'tools') diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp index 6d03311..e87138c 100644 --- a/tools/aapt/ResourceTable.cpp +++ b/tools/aapt/ResourceTable.cpp @@ -4527,7 +4527,7 @@ status_t ResourceTable::modifyForCompat(const Bundle* bundle, return NO_ERROR; } - Vector, size_t> > attrsToRemove; + sp newRoot = NULL; Vector > nodesToVisit; nodesToVisit.push(root); @@ -4536,11 +4536,23 @@ status_t ResourceTable::modifyForCompat(const Bundle* bundle, nodesToVisit.pop(); const Vector& attrs = node->getAttributes(); - const size_t attrCount = attrs.size(); - for (size_t i = 0; i < attrCount; i++) { + for (size_t i = 0; i < attrs.size(); i++) { const XMLNode::attribute_entry& attr = attrs[i]; if (isAttributeFromL(attr.nameResId)) { - attrsToRemove.add(key_value_pair_t, size_t>(node, i)); + if (newRoot == NULL) { + newRoot = root->clone(); + } + + if (bundle->getVerbose()) { + SourcePos(node->getFilename(), node->getStartLineNumber()).printf( + "removing attribute %s%s%s from <%s>", + String8(attr.ns).string(), + (attr.ns.size() == 0 ? "" : ":"), + String8(attr.name).string(), + String8(node->getElementName()).string()); + } + node->removeAttribute(i); + i--; } } @@ -4552,7 +4564,7 @@ status_t ResourceTable::modifyForCompat(const Bundle* bundle, } } - if (attrsToRemove.isEmpty()) { + if (newRoot == NULL) { return NO_ERROR; } @@ -4562,12 +4574,8 @@ status_t ResourceTable::modifyForCompat(const Bundle* bundle, // Look to see if we already have an overriding v21 configuration. sp cl = getConfigList(String16(mAssets->getPackage()), String16(target->getResourceType()), resourceName); - //if (cl == NULL) { - // fprintf(stderr, "fuuuuck\n"); - //} if (cl->getEntries().indexOfKey(newConfig) < 0) { // We don't have an overriding entry for v21, so we must duplicate this one. - sp newRoot = root->clone(); sp newFile = new AaptFile(target->getSourceFile(), AaptGroupEntry(newConfig), target->getResourceType()); String8 resPath = String8::format("res/%s/%s", @@ -4602,22 +4610,6 @@ status_t ResourceTable::modifyForCompat(const Bundle* bundle, mWorkQueue.push(item); } - const size_t removeCount = attrsToRemove.size(); - for (size_t i = 0; i < removeCount; i++) { - sp node = attrsToRemove[i].key; - size_t attrIndex = attrsToRemove[i].value; - const XMLNode::attribute_entry& ae = node->getAttributes()[attrIndex]; - if (bundle->getVerbose()) { - SourcePos(node->getFilename(), node->getStartLineNumber()).printf( - "removing attribute %s%s%s from <%s>", - String8(ae.ns).string(), - (ae.ns.size() == 0 ? "" : ":"), - String8(ae.name).string(), - String8(node->getElementName()).string()); - } - node->removeAttribute(attrIndex); - } - return NO_ERROR; } -- cgit v1.1