blob: 345cc95cfb29b4f29d22e1a59340209ab900546a [file] [log] [blame]
Adam Lesinski1ab598f2015-08-14 14:26:04 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Adam Lesinski46708052017-09-29 14:49:15 -070017#include "format/binary/XmlFlattener.h"
Adam Lesinskice5e56e22016-10-21 17:56:45 -070018
19#include <algorithm>
20#include <map>
21#include <vector>
22
23#include "android-base/logging.h"
24#include "android-base/macros.h"
25#include "androidfw/ResourceTypes.h"
26#include "utils/misc.h"
27
Adam Lesinski1ab598f2015-08-14 14:26:04 -070028#include "SdkConstants.h"
Adam Lesinski46708052017-09-29 14:49:15 -070029#include "format/binary/ChunkWriter.h"
30#include "format/binary/ResourceTypeExtensions.h"
Adam Lesinski467f1712015-11-16 17:35:44 -080031#include "xml/XmlDom.h"
Adam Lesinski1ab598f2015-08-14 14:26:04 -070032
Adam Lesinski1ab598f2015-08-14 14:26:04 -070033using namespace android;
34
35namespace aapt {
36
37namespace {
38
39constexpr uint32_t kLowPriority = 0xffffffffu;
40
Adam Lesinski6b372992017-08-09 10:54:23 -070041static bool cmp_xml_attribute_by_id(const xml::Attribute* a, const xml::Attribute* b) {
Adam Lesinskice5e56e22016-10-21 17:56:45 -070042 if (a->compiled_attribute && a->compiled_attribute.value().id) {
43 if (b->compiled_attribute && b->compiled_attribute.value().id) {
Adam Lesinski6b372992017-08-09 10:54:23 -070044 return a->compiled_attribute.value().id.value() < b->compiled_attribute.value().id.value();
Adam Lesinskice5e56e22016-10-21 17:56:45 -070045 }
46 return true;
47 } else if (!b->compiled_attribute) {
48 int diff = a->namespace_uri.compare(b->namespace_uri);
49 if (diff < 0) {
50 return true;
51 } else if (diff > 0) {
52 return false;
53 }
54 return a->name < b->name;
55 }
56 return false;
57}
Adam Lesinski1ab598f2015-08-14 14:26:04 -070058
Adam Lesinskie59f0d82017-10-13 09:36:53 -070059class XmlFlattenerVisitor : public xml::ConstVisitor {
Adam Lesinskice5e56e22016-10-21 17:56:45 -070060 public:
Adam Lesinskie59f0d82017-10-13 09:36:53 -070061 using xml::ConstVisitor::Visit;
Adam Lesinskice5e56e22016-10-21 17:56:45 -070062
63 StringPool pool;
64 std::map<uint8_t, StringPool> package_pools;
Adam Lesinski1ab598f2015-08-14 14:26:04 -070065
Adam Lesinskicacb28f2016-10-19 12:18:14 -070066 struct StringFlattenDest {
67 StringPool::Ref ref;
68 ResStringPool_ref* dest;
69 };
Adam Lesinski1ab598f2015-08-14 14:26:04 -070070
Adam Lesinskice5e56e22016-10-21 17:56:45 -070071 std::vector<StringFlattenDest> string_refs;
Adam Lesinski1ab598f2015-08-14 14:26:04 -070072
Adam Lesinskicacb28f2016-10-19 12:18:14 -070073 XmlFlattenerVisitor(BigBuffer* buffer, XmlFlattenerOptions options)
Adam Lesinski46708052017-09-29 14:49:15 -070074 : buffer_(buffer), options_(options) {
75 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -070076
Adam Lesinskie59f0d82017-10-13 09:36:53 -070077 void Visit(const xml::Text* node) override {
Adam Lesinskice5e56e22016-10-21 17:56:45 -070078 if (util::TrimWhitespace(node->text).empty()) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070079 // Skip whitespace only text nodes.
80 return;
Adam Lesinski1ab598f2015-08-14 14:26:04 -070081 }
82
Adam Lesinskice5e56e22016-10-21 17:56:45 -070083 ChunkWriter writer(buffer_);
Adam Lesinski6b372992017-08-09 10:54:23 -070084 ResXMLTree_node* flat_node = writer.StartChunk<ResXMLTree_node>(RES_XML_CDATA_TYPE);
Adam Lesinskice5e56e22016-10-21 17:56:45 -070085 flat_node->lineNumber = util::HostToDevice32(node->line_number);
86 flat_node->comment.index = util::HostToDevice32(-1);
Adam Lesinskicacb28f2016-10-19 12:18:14 -070087
Adam Lesinskice5e56e22016-10-21 17:56:45 -070088 ResXMLTree_cdataExt* flat_text = writer.NextBlock<ResXMLTree_cdataExt>();
Adam Lesinski48448e82017-04-26 15:13:52 -070089
90 // Process plain strings to make sure they get properly escaped.
91 util::StringBuilder builder;
92 builder.Append(node->text);
93 AddString(builder.ToString(), kLowPriority, &flat_text->data);
Adam Lesinskicacb28f2016-10-19 12:18:14 -070094
Adam Lesinskice5e56e22016-10-21 17:56:45 -070095 writer.Finish();
Adam Lesinskicacb28f2016-10-19 12:18:14 -070096 }
97
Adam Lesinskie59f0d82017-10-13 09:36:53 -070098 void Visit(const xml::Element* node) override {
Adam Lesinski6b372992017-08-09 10:54:23 -070099 for (const xml::NamespaceDecl& decl : node->namespace_decls) {
100 // Skip dedicated tools namespace.
101 if (decl.uri != xml::kSchemaTools) {
102 WriteNamespace(decl, android::RES_XML_START_NAMESPACE_TYPE);
103 }
104 }
105
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700106 {
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700107 ChunkWriter start_writer(buffer_);
108 ResXMLTree_node* flat_node =
109 start_writer.StartChunk<ResXMLTree_node>(RES_XML_START_ELEMENT_TYPE);
110 flat_node->lineNumber = util::HostToDevice32(node->line_number);
111 flat_node->comment.index = util::HostToDevice32(-1);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700112
Adam Lesinski6b372992017-08-09 10:54:23 -0700113 ResXMLTree_attrExt* flat_elem = start_writer.NextBlock<ResXMLTree_attrExt>();
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700114
Adam Lesinski6b372992017-08-09 10:54:23 -0700115 // A missing namespace must be null, not an empty string. Otherwise the runtime complains.
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700116 AddString(node->namespace_uri, kLowPriority, &flat_elem->ns,
117 true /* treat_empty_string_as_null */);
Adam Lesinski6b372992017-08-09 10:54:23 -0700118 AddString(node->name, kLowPriority, &flat_elem->name, true /* treat_empty_string_as_null */);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700119
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700120 flat_elem->attributeStart = util::HostToDevice16(sizeof(*flat_elem));
Adam Lesinski6b372992017-08-09 10:54:23 -0700121 flat_elem->attributeSize = util::HostToDevice16(sizeof(ResXMLTree_attribute));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700122
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700123 WriteAttributes(node, flat_elem, &start_writer);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700124
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700125 start_writer.Finish();
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700126 }
127
Adam Lesinskie59f0d82017-10-13 09:36:53 -0700128 xml::ConstVisitor::Visit(node);
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700129
130 {
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700131 ChunkWriter end_writer(buffer_);
132 ResXMLTree_node* flat_end_node =
133 end_writer.StartChunk<ResXMLTree_node>(RES_XML_END_ELEMENT_TYPE);
134 flat_end_node->lineNumber = util::HostToDevice32(node->line_number);
135 flat_end_node->comment.index = util::HostToDevice32(-1);
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700136
Adam Lesinski6b372992017-08-09 10:54:23 -0700137 ResXMLTree_endElementExt* flat_end_elem = end_writer.NextBlock<ResXMLTree_endElementExt>();
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700138 AddString(node->namespace_uri, kLowPriority, &flat_end_elem->ns,
139 true /* treat_empty_string_as_null */);
140 AddString(node->name, kLowPriority, &flat_end_elem->name);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700141
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700142 end_writer.Finish();
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700143 }
Adam Lesinski6b372992017-08-09 10:54:23 -0700144
145 for (auto iter = node->namespace_decls.rbegin(); iter != node->namespace_decls.rend(); ++iter) {
146 // Skip dedicated tools namespace.
147 if (iter->uri != xml::kSchemaTools) {
148 WriteNamespace(*iter, android::RES_XML_END_NAMESPACE_TYPE);
149 }
150 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700151 }
152
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700153 private:
154 DISALLOW_COPY_AND_ASSIGN(XmlFlattenerVisitor);
155
Adam Lesinski46708052017-09-29 14:49:15 -0700156 void AddString(const StringPiece& str, uint32_t priority, android::ResStringPool_ref* dest,
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700157 bool treat_empty_string_as_null = false) {
158 if (str.empty() && treat_empty_string_as_null) {
159 // Some parts of the runtime treat null differently than empty string.
160 dest->index = util::DeviceToHost32(-1);
161 } else {
Adam Lesinski46708052017-09-29 14:49:15 -0700162 string_refs.push_back(
163 StringFlattenDest{pool.MakeRef(str, StringPool::Context(priority)), dest});
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700164 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700165 }
166
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700167 void AddString(const StringPool::Ref& ref, android::ResStringPool_ref* dest) {
168 string_refs.push_back(StringFlattenDest{ref, dest});
169 }
170
Adam Lesinski6b372992017-08-09 10:54:23 -0700171 void WriteNamespace(const xml::NamespaceDecl& decl, uint16_t type) {
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700172 ChunkWriter writer(buffer_);
173
174 ResXMLTree_node* flatNode = writer.StartChunk<ResXMLTree_node>(type);
Adam Lesinski6b372992017-08-09 10:54:23 -0700175 flatNode->lineNumber = util::HostToDevice32(decl.line_number);
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700176 flatNode->comment.index = util::HostToDevice32(-1);
177
Adam Lesinski060b53d2017-07-28 17:10:35 -0700178 ResXMLTree_namespaceExt* flat_ns = writer.NextBlock<ResXMLTree_namespaceExt>();
Adam Lesinski6b372992017-08-09 10:54:23 -0700179 AddString(decl.prefix, kLowPriority, &flat_ns->prefix);
180 AddString(decl.uri, kLowPriority, &flat_ns->uri);
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700181
182 writer.Finish();
183 }
184
Adam Lesinskie59f0d82017-10-13 09:36:53 -0700185 void WriteAttributes(const xml::Element* node, ResXMLTree_attrExt* flat_elem,
186 ChunkWriter* writer) {
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700187 filtered_attrs_.clear();
188 filtered_attrs_.reserve(node->attributes.size());
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700189
190 // Filter the attributes.
Adam Lesinskie59f0d82017-10-13 09:36:53 -0700191 for (const xml::Attribute& attr : node->attributes) {
Adam Lesinskic744ae82017-05-17 19:28:38 -0700192 if (attr.namespace_uri != xml::kSchemaTools) {
193 filtered_attrs_.push_back(&attr);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700194 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700195 }
196
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700197 if (filtered_attrs_.empty()) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700198 return;
199 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700200
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700201 const ResourceId kIdAttr(0x010100d0);
202
Adam Lesinski48448e82017-04-26 15:13:52 -0700203 std::sort(filtered_attrs_.begin(), filtered_attrs_.end(), cmp_xml_attribute_by_id);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700204
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700205 flat_elem->attributeCount = util::HostToDevice16(filtered_attrs_.size());
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700206
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700207 ResXMLTree_attribute* flat_attr =
208 writer->NextBlock<ResXMLTree_attribute>(filtered_attrs_.size());
209 uint16_t attribute_index = 1;
210 for (const xml::Attribute* xml_attr : filtered_attrs_) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700211 // Assign the indices for specific attributes.
Adam Lesinski46708052017-09-29 14:49:15 -0700212 if (xml_attr->compiled_attribute && xml_attr->compiled_attribute.value().id &&
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700213 xml_attr->compiled_attribute.value().id.value() == kIdAttr) {
214 flat_elem->idIndex = util::HostToDevice16(attribute_index);
215 } else if (xml_attr->namespace_uri.empty()) {
216 if (xml_attr->name == "class") {
217 flat_elem->classIndex = util::HostToDevice16(attribute_index);
218 } else if (xml_attr->name == "style") {
219 flat_elem->styleIndex = util::HostToDevice16(attribute_index);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700220 }
221 }
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700222 attribute_index++;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700223
Adam Lesinski48448e82017-04-26 15:13:52 -0700224 // Add the namespaceUri to the list of StringRefs to encode. Use null if the namespace
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700225 // is empty (doesn't exist).
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700226 AddString(xml_attr->namespace_uri, kLowPriority, &flat_attr->ns,
227 true /* treat_empty_string_as_null */);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700228
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700229 flat_attr->rawValue.index = util::HostToDevice32(-1);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700230
Adam Lesinski48448e82017-04-26 15:13:52 -0700231 if (!xml_attr->compiled_attribute || !xml_attr->compiled_attribute.value().id) {
232 // The attribute has no associated ResourceID, so the string order doesn't matter.
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700233 AddString(xml_attr->name, kLowPriority, &flat_attr->name);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700234 } else {
235 // Attribute names are stored without packages, but we use
236 // their StringPool index to lookup their resource IDs.
237 // This will cause collisions, so we can't dedupe
238 // attribute names from different packages. We use separate
239 // pools that we later combine.
240 //
241 // Lookup the StringPool for this package and make the reference there.
Adam Lesinski48448e82017-04-26 15:13:52 -0700242 const xml::AaptAttribute& aapt_attr = xml_attr->compiled_attribute.value();
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700243
Adam Lesinski46708052017-09-29 14:49:15 -0700244 StringPool::Ref name_ref = package_pools[aapt_attr.id.value().package_id()].MakeRef(
245 xml_attr->name, StringPool::Context(aapt_attr.id.value().id));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700246
247 // Add it to the list of strings to flatten.
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700248 AddString(name_ref, &flat_attr->name);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700249 }
250
Adam Lesinski48448e82017-04-26 15:13:52 -0700251 // Process plain strings to make sure they get properly escaped.
252 StringPiece raw_value = xml_attr->value;
Adam Lesinskifba0cf22017-06-29 17:53:36 -0700253
254 util::StringBuilder str_builder(true /*preserve_spaces*/);
255 str_builder.Append(xml_attr->value);
256
Adam Lesinski48448e82017-04-26 15:13:52 -0700257 if (!options_.keep_raw_values) {
Adam Lesinski48448e82017-04-26 15:13:52 -0700258 raw_value = str_builder.ToString();
259 }
260
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700261 if (options_.keep_raw_values || !xml_attr->compiled_value) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700262 // Keep raw values if the value is not compiled or
263 // if we're building a static library (need symbols).
Adam Lesinski48448e82017-04-26 15:13:52 -0700264 AddString(raw_value, kLowPriority, &flat_attr->rawValue);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700265 }
266
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700267 if (xml_attr->compiled_value) {
268 CHECK(xml_attr->compiled_value->Flatten(&flat_attr->typedValue));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700269 } else {
270 // Flatten as a regular string type.
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700271 flat_attr->typedValue.dataType = android::Res_value::TYPE_STRING;
Adam Lesinski48448e82017-04-26 15:13:52 -0700272
273 AddString(str_builder.ToString(), kLowPriority,
Adam Lesinski46708052017-09-29 14:49:15 -0700274 (ResStringPool_ref*)&flat_attr->typedValue.data);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700275 }
276
Adam Lesinski48448e82017-04-26 15:13:52 -0700277 flat_attr->typedValue.size = util::HostToDevice16(sizeof(flat_attr->typedValue));
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700278 flat_attr++;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700279 }
280 }
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700281
282 BigBuffer* buffer_;
283 XmlFlattenerOptions options_;
284
Adam Lesinski060b53d2017-07-28 17:10:35 -0700285 // Scratch vector to filter attributes. We avoid allocations making this a member.
Adam Lesinskie59f0d82017-10-13 09:36:53 -0700286 std::vector<const xml::Attribute*> filtered_attrs_;
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700287};
288
289} // namespace
290
Adam Lesinskie59f0d82017-10-13 09:36:53 -0700291bool XmlFlattener::Flatten(IAaptContext* context, const xml::Node* node) {
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700292 BigBuffer node_buffer(1024);
293 XmlFlattenerVisitor visitor(&node_buffer, options_);
294 node->Accept(&visitor);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700295
296 // Merge the package pools into the main pool.
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700297 for (auto& package_pool_entry : visitor.package_pools) {
298 visitor.pool.Merge(std::move(package_pool_entry.second));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700299 }
300
301 // Sort the string pool so that attribute resource IDs show up first.
Adam Lesinski060b53d2017-07-28 17:10:35 -0700302 visitor.pool.Sort([](const StringPool::Context& a, const StringPool::Context& b) -> int {
303 return util::compare(a.priority, b.priority);
304 });
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700305
306 // Now we flatten the string pool references into the correct places.
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700307 for (const auto& ref_entry : visitor.string_refs) {
308 ref_entry.dest->index = util::HostToDevice32(ref_entry.ref.index());
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700309 }
310
311 // Write the XML header.
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700312 ChunkWriter xml_header_writer(buffer_);
313 xml_header_writer.StartChunk<ResXMLTree_header>(RES_XML_TYPE);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700314
315 // Flatten the StringPool.
Adam Lesinskiea13c1a2017-10-13 12:40:37 -0700316 if (options_.use_utf16) {
317 StringPool::FlattenUtf16(buffer_, visitor.pool);
318 } else {
319 StringPool::FlattenUtf8(buffer_, visitor.pool);
320 }
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700321
322 {
323 // Write the array of resource IDs, indexed by StringPool order.
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700324 ChunkWriter res_id_map_writer(buffer_);
325 res_id_map_writer.StartChunk<ResChunk_header>(RES_XML_RESOURCE_MAP_TYPE);
Adam Lesinski060b53d2017-07-28 17:10:35 -0700326 for (const auto& str : visitor.pool.strings()) {
327 ResourceId id(str->context.priority);
328 if (str->context.priority == kLowPriority || !id.is_valid()) {
329 // When we see the first non-resource ID, we're done.
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700330 break;
331 }
Adam Lesinski060b53d2017-07-28 17:10:35 -0700332 *res_id_map_writer.NextBlock<uint32_t>() = util::HostToDevice32(id.id);
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700333 }
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700334 res_id_map_writer.Finish();
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700335 }
336
337 // Move the nodeBuffer and append it to the out buffer.
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700338 buffer_->AppendBuffer(std::move(node_buffer));
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700339
340 // Finish the xml header.
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700341 xml_header_writer.Finish();
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700342 return true;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700343}
344
Adam Lesinskie59f0d82017-10-13 09:36:53 -0700345bool XmlFlattener::Consume(IAaptContext* context, const xml::XmlResource* resource) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700346 if (!resource->root) {
347 return false;
348 }
Adam Lesinskice5e56e22016-10-21 17:56:45 -0700349 return Flatten(context, resource->root.get());
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700350}
351
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700352} // namespace aapt