From e572c011feabf6319ba836cf5bc4c3baa0ba6a85 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Fri, 19 Sep 2014 15:10:04 -0700 Subject: AAPT: Continuation of public/private attribute fix XML files like layouts are now scanned and checked for v21 attributes. If those kinds of attributes are found, then we remove them in the original version and synthesize a new xml file under the v21 configuration. Bug:17520380 Change-Id: Icf984cb96134180a2e35349c1dbf2cef9a8f0bda --- tools/aapt/XMLNode.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'tools/aapt/XMLNode.cpp') diff --git a/tools/aapt/XMLNode.cpp b/tools/aapt/XMLNode.cpp index 607d419b2971..51a4154d5335 100644 --- a/tools/aapt/XMLNode.cpp +++ b/tools/aapt/XMLNode.cpp @@ -621,6 +621,12 @@ sp XMLNode::parse(const sp& file) return state.root; } +XMLNode::XMLNode() + : mNextAttributeIndex(0x80000000) + , mStartLineNumber(0) + , mEndLineNumber(0) + , mUTF8(false) {} + XMLNode::XMLNode(const String8& filename, const String16& s1, const String16& s2, bool isNamespace) : mNextAttributeIndex(0x80000000) , mFilename(filename) @@ -810,6 +816,32 @@ status_t XMLNode::addAttribute(const String16& ns, const String16& name, return NO_ERROR; } +status_t XMLNode::removeAttribute(size_t index) +{ + if (getType() == TYPE_CDATA) { + return UNKNOWN_ERROR; + } + + if (index >= mAttributes.size()) { + return UNKNOWN_ERROR; + } + + const attribute_entry& e = mAttributes[index]; + const uint32_t key = e.nameResId ? e.nameResId : e.index; + mAttributeOrder.removeItem(key); + mAttributes.removeAt(index); + + // Shift all the indices. + const size_t attrCount = mAttributeOrder.size(); + for (size_t i = 0; i < attrCount; i++) { + size_t attrIdx = mAttributeOrder[i]; + if (attrIdx > index) { + mAttributeOrder.replaceValueAt(i, attrIdx - 1); + } + } + return NO_ERROR; +} + void XMLNode::setAttributeResID(size_t attrIdx, uint32_t resId) { attribute_entry& e = mAttributes.editItemAt(attrIdx); @@ -999,6 +1031,30 @@ status_t XMLNode::assignResourceIds(const sp& assets, return hasErrors ? UNKNOWN_ERROR : NO_ERROR; } +sp XMLNode::clone() const { + sp copy = new XMLNode(); + copy->mNamespacePrefix = mNamespacePrefix; + copy->mNamespaceUri = mNamespaceUri; + copy->mElementName = mElementName; + + const size_t childCount = mChildren.size(); + for (size_t i = 0; i < childCount; i++) { + copy->mChildren.add(mChildren[i]->clone()); + } + + copy->mAttributes = mAttributes; + copy->mAttributeOrder = mAttributeOrder; + copy->mNextAttributeIndex = mNextAttributeIndex; + copy->mChars = mChars; + memcpy(©->mCharsValue, &mCharsValue, sizeof(mCharsValue)); + copy->mComment = mComment; + copy->mFilename = mFilename; + copy->mStartLineNumber = mStartLineNumber; + copy->mEndLineNumber = mEndLineNumber; + copy->mUTF8 = mUTF8; + return copy; +} + status_t XMLNode::flatten(const sp& dest, bool stripComments, bool stripRawValues) const { -- cgit v1.2.3