AAPT2: Move format related files under same directory
Test: make aapt2_tests
Change-Id: Id72cdfc12ba3add294048e60c55f2461344464bf
diff --git a/tools/aapt2/Android.bp b/tools/aapt2/Android.bp
index 7a8a4ee..ff51d51 100644
--- a/tools/aapt2/Android.bp
+++ b/tools/aapt2/Android.bp
@@ -83,9 +83,13 @@
"configuration/ConfigurationParser.cpp",
"filter/AbiFilter.cpp",
"filter/ConfigFilter.cpp",
- "flatten/Archive.cpp",
- "flatten/TableFlattener.cpp",
- "flatten/XmlFlattener.cpp",
+ "format/Archive.cpp",
+ "format/binary/BinaryResourceParser.cpp",
+ "format/binary/ResChunkPullParser.cpp",
+ "format/binary/TableFlattener.cpp",
+ "format/binary/XmlFlattener.cpp",
+ "format/proto/ProtoDeserialize.cpp",
+ "format/proto/ProtoSerialize.cpp",
"io/BigBufferStreams.cpp",
"io/File.cpp",
"io/FileInputStream.cpp",
@@ -106,13 +110,9 @@
"optimize/ResourceDeduper.cpp",
"optimize/VersionCollapser.cpp",
"process/SymbolTable.cpp",
- "proto/ProtoDeserialize.cpp",
- "proto/ProtoSerialize.cpp",
"split/TableSplitter.cpp",
"text/Unicode.cpp",
"text/Utf8Iterator.cpp",
- "unflatten/BinaryResourceParser.cpp",
- "unflatten/ResChunkPullParser.cpp",
"util/BigBuffer.cpp",
"util/Files.cpp",
"util/Util.cpp",
diff --git a/tools/aapt2/LoadedApk.cpp b/tools/aapt2/LoadedApk.cpp
index 6f2b865..c1815c8 100644
--- a/tools/aapt2/LoadedApk.cpp
+++ b/tools/aapt2/LoadedApk.cpp
@@ -18,9 +18,9 @@
#include "ResourceValues.h"
#include "ValueVisitor.h"
-#include "flatten/Archive.h"
-#include "flatten/TableFlattener.h"
-#include "flatten/XmlFlattener.h"
+#include "format/Archive.h"
+#include "format/binary/TableFlattener.h"
+#include "format/binary/XmlFlattener.h"
#include "io/BigBufferInputStream.h"
#include "io/Util.h"
#include "xml/XmlDom.h"
diff --git a/tools/aapt2/LoadedApk.h b/tools/aapt2/LoadedApk.h
index d779b7e..d2dd5cf 100644
--- a/tools/aapt2/LoadedApk.h
+++ b/tools/aapt2/LoadedApk.h
@@ -21,27 +21,35 @@
#include "ResourceTable.h"
#include "filter/Filter.h"
-#include "flatten/Archive.h"
-#include "flatten/TableFlattener.h"
+#include "format/Archive.h"
+#include "format/binary/BinaryResourceParser.h"
+#include "format/binary/TableFlattener.h"
#include "io/ZipArchive.h"
-#include "unflatten/BinaryResourceParser.h"
#include "xml/XmlDom.h"
namespace aapt {
-/** Info about an APK loaded in memory. */
+// Info about an APK loaded in memory.
class LoadedApk {
public:
- LoadedApk(const Source& source, std::unique_ptr<io::IFileCollection> apk,
- std::unique_ptr<ResourceTable> table)
- : source_(source), apk_(std::move(apk)), table_(std::move(table)) {
+ LoadedApk(
+ const Source& source,
+ std::unique_ptr<io::IFileCollection> apk,
+ std::unique_ptr<ResourceTable> table)
+ : source_(source), apk_(std::move(apk)), table_(std::move(table)) {}
+ virtual ~LoadedApk() = default;
+
+ io::IFileCollection* GetFileCollection() {
+ return apk_.get();
}
- io::IFileCollection* GetFileCollection() { return apk_.get(); }
+ ResourceTable* GetResourceTable() {
+ return table_.get();
+ }
- ResourceTable* GetResourceTable() { return table_.get(); }
-
- const Source& GetSource() { return source_; }
+ const Source& GetSource() {
+ return source_;
+ }
/**
* Writes the APK on disk at the given path, while also removing the resource
@@ -70,11 +78,11 @@
const android::StringPiece& path);
private:
+ DISALLOW_COPY_AND_ASSIGN(LoadedApk);
+
Source source_;
std::unique_ptr<io::IFileCollection> apk_;
std::unique_ptr<ResourceTable> table_;
-
- DISALLOW_COPY_AND_ASSIGN(LoadedApk);
};
} // namespace aapt
diff --git a/tools/aapt2/ResourceUtils.cpp b/tools/aapt2/ResourceUtils.cpp
index f193fe0..6fac6e9 100644
--- a/tools/aapt2/ResourceUtils.cpp
+++ b/tools/aapt2/ResourceUtils.cpp
@@ -23,12 +23,12 @@
#include "NameMangler.h"
#include "SdkConstants.h"
-#include "flatten/ResourceTypeExtensions.h"
+#include "format/binary/ResourceTypeExtensions.h"
#include "util/Files.h"
#include "util/Util.h"
-using android::StringPiece;
-using android::StringPiece16;
+using ::android::StringPiece;
+using ::android::StringPiece16;
namespace aapt {
namespace ResourceUtils {
diff --git a/tools/aapt2/cmd/Compile.cpp b/tools/aapt2/cmd/Compile.cpp
index 0690dc1..a5e6aefd1 100644
--- a/tools/aapt2/cmd/Compile.cpp
+++ b/tools/aapt2/cmd/Compile.cpp
@@ -35,12 +35,12 @@
#include "compile/Png.h"
#include "compile/PseudolocaleGenerator.h"
#include "compile/XmlIdCollector.h"
-#include "flatten/Archive.h"
-#include "flatten/XmlFlattener.h"
+#include "format/Archive.h"
+#include "format/binary/XmlFlattener.h"
+#include "format/proto/ProtoSerialize.h"
#include "io/BigBufferOutputStream.h"
#include "io/FileInputStream.h"
#include "io/Util.h"
-#include "proto/ProtoSerialize.h"
#include "util/Files.h"
#include "util/Maybe.h"
#include "util/Util.h"
diff --git a/tools/aapt2/cmd/Dump.cpp b/tools/aapt2/cmd/Dump.cpp
index 0dedc91..44032f6 100644
--- a/tools/aapt2/cmd/Dump.cpp
+++ b/tools/aapt2/cmd/Dump.cpp
@@ -21,10 +21,10 @@
#include "Debug.h"
#include "Diagnostics.h"
#include "Flags.h"
+#include "format/binary/BinaryResourceParser.h"
+#include "format/proto/ProtoDeserialize.h"
#include "io/ZipArchive.h"
#include "process/IResourceTableConsumer.h"
-#include "proto/ProtoDeserialize.h"
-#include "unflatten/BinaryResourceParser.h"
#include "util/Files.h"
using ::android::StringPiece;
diff --git a/tools/aapt2/cmd/Link.cpp b/tools/aapt2/cmd/Link.cpp
index f72069c..88e0f69 100644
--- a/tools/aapt2/cmd/Link.cpp
+++ b/tools/aapt2/cmd/Link.cpp
@@ -38,9 +38,12 @@
#include "cmd/Util.h"
#include "compile/IdAssigner.h"
#include "filter/ConfigFilter.h"
-#include "flatten/Archive.h"
-#include "flatten/TableFlattener.h"
-#include "flatten/XmlFlattener.h"
+#include "format/Archive.h"
+#include "format/binary/BinaryResourceParser.h"
+#include "format/binary/TableFlattener.h"
+#include "format/binary/XmlFlattener.h"
+#include "format/proto/ProtoDeserialize.h"
+#include "format/proto/ProtoSerialize.h"
#include "io/BigBufferInputStream.h"
#include "io/FileInputStream.h"
#include "io/FileSystem.h"
@@ -58,10 +61,7 @@
#include "optimize/VersionCollapser.h"
#include "process/IResourceTableConsumer.h"
#include "process/SymbolTable.h"
-#include "proto/ProtoDeserialize.h"
-#include "proto/ProtoSerialize.h"
#include "split/TableSplitter.h"
-#include "unflatten/BinaryResourceParser.h"
#include "util/Files.h"
#include "xml/XmlDom.h"
diff --git a/tools/aapt2/cmd/Optimize.cpp b/tools/aapt2/cmd/Optimize.cpp
index 56b61d0..67ac67a 100644
--- a/tools/aapt2/cmd/Optimize.cpp
+++ b/tools/aapt2/cmd/Optimize.cpp
@@ -31,8 +31,8 @@
#include "cmd/Util.h"
#include "configuration/ConfigurationParser.h"
#include "filter/AbiFilter.h"
-#include "flatten/TableFlattener.h"
-#include "flatten/XmlFlattener.h"
+#include "format/binary/TableFlattener.h"
+#include "format/binary/XmlFlattener.h"
#include "io/BigBufferInputStream.h"
#include "io/Util.h"
#include "optimize/MultiApkGenerator.h"
diff --git a/tools/aapt2/compile/PngChunkFilter.cpp b/tools/aapt2/compile/PngChunkFilter.cpp
index 5af91fd..bc2e699 100644
--- a/tools/aapt2/compile/PngChunkFilter.cpp
+++ b/tools/aapt2/compile/PngChunkFilter.cpp
@@ -21,8 +21,8 @@
#include "io/Io.h"
-using android::StringPiece;
-using android::base::StringPrintf;
+using ::android::StringPiece;
+using ::android::base::StringPrintf;
namespace aapt {
diff --git a/tools/aapt2/flatten/Archive.cpp b/tools/aapt2/format/Archive.cpp
similarity index 95%
rename from tools/aapt2/flatten/Archive.cpp
rename to tools/aapt2/format/Archive.cpp
index 5f8bd06..d152a9c 100644
--- a/tools/aapt2/flatten/Archive.cpp
+++ b/tools/aapt2/format/Archive.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "flatten/Archive.h"
+#include "format/Archive.h"
#include <cstdio>
#include <memory>
@@ -106,9 +106,13 @@
return !in->HadError();
}
- bool HadError() const override { return !error_.empty(); }
+ bool HadError() const override {
+ return !error_.empty();
+ }
- std::string GetError() const override { return error_; }
+ std::string GetError() const override {
+ return error_;
+ }
private:
DISALLOW_COPY_AND_ASSIGN(DirectoryWriter);
@@ -221,9 +225,13 @@
}
}
- bool HadError() const override { return !error_.empty(); }
+ bool HadError() const override {
+ return !error_.empty();
+ }
- std::string GetError() const override { return error_; }
+ std::string GetError() const override {
+ return error_;
+ }
virtual ~ZipFileWriter() {
if (writer_) {
diff --git a/tools/aapt2/flatten/Archive.h b/tools/aapt2/format/Archive.h
similarity index 96%
rename from tools/aapt2/flatten/Archive.h
rename to tools/aapt2/format/Archive.h
index 4ee4ce7..4e8a39d 100644
--- a/tools/aapt2/flatten/Archive.h
+++ b/tools/aapt2/format/Archive.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef AAPT_FLATTEN_ARCHIVE_H
-#define AAPT_FLATTEN_ARCHIVE_H
+#ifndef AAPT_FORMAT_ARCHIVE_H
+#define AAPT_FORMAT_ARCHIVE_H
#include <fstream>
#include <memory>
@@ -78,4 +78,4 @@
} // namespace aapt
-#endif /* AAPT_FLATTEN_ARCHIVE_H */
+#endif /* AAPT_FORMAT_ARCHIVE_H */
diff --git a/tools/aapt2/unflatten/BinaryResourceParser.cpp b/tools/aapt2/format/binary/BinaryResourceParser.cpp
similarity index 76%
rename from tools/aapt2/unflatten/BinaryResourceParser.cpp
rename to tools/aapt2/format/binary/BinaryResourceParser.cpp
index b87278b..95eec4a 100644
--- a/tools/aapt2/unflatten/BinaryResourceParser.cpp
+++ b/tools/aapt2/format/binary/BinaryResourceParser.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "unflatten/BinaryResourceParser.h"
+#include "format/binary/BinaryResourceParser.h"
#include <algorithm>
#include <map>
@@ -31,15 +31,15 @@
#include "ResourceValues.h"
#include "Source.h"
#include "ValueVisitor.h"
-#include "unflatten/ResChunkPullParser.h"
+#include "format/binary/ResChunkPullParser.h"
#include "util/Util.h"
-namespace aapt {
-
using namespace android;
using ::android::base::StringPrintf;
+namespace aapt {
+
namespace {
// Visitor that converts a reference's resource ID to a resource name, given a mapping from
@@ -118,15 +118,11 @@
return true;
}
-/**
- * Parses the resource table, which contains all the packages, types, and
- * entries.
- */
+// Parses the resource table, which contains all the packages, types, and entries.
bool BinaryResourceParser::ParseTable(const ResChunk_header* chunk) {
const ResTable_header* table_header = ConvertTo<ResTable_header>(chunk);
if (!table_header) {
- context_->GetDiagnostics()->Error(DiagMessage(source_)
- << "corrupt ResTable_header chunk");
+ context_->GetDiagnostics()->Error(DiagMessage(source_) << "corrupt ResTable_header chunk");
return false;
}
@@ -136,21 +132,20 @@
switch (util::DeviceToHost16(parser.chunk()->type)) {
case android::RES_STRING_POOL_TYPE:
if (value_pool_.getError() == NO_INIT) {
- status_t err = value_pool_.setTo(
- parser.chunk(), util::DeviceToHost32(parser.chunk()->size));
+ status_t err =
+ value_pool_.setTo(parser.chunk(), util::DeviceToHost32(parser.chunk()->size));
if (err != NO_ERROR) {
- context_->GetDiagnostics()->Error(
- DiagMessage(source_) << "corrupt string pool in ResTable: "
- << value_pool_.getError());
+ context_->GetDiagnostics()->Error(DiagMessage(source_)
+ << "corrupt string pool in ResTable: "
+ << value_pool_.getError());
return false;
}
// Reserve some space for the strings we are going to add.
- table_->string_pool.HintWillAdd(value_pool_.size(),
- value_pool_.styleCount());
+ table_->string_pool.HintWillAdd(value_pool_.size(), value_pool_.styleCount());
} else {
- context_->GetDiagnostics()->Warn(
- DiagMessage(source_) << "unexpected string pool in ResTable");
+ context_->GetDiagnostics()->Warn(DiagMessage(source_)
+ << "unexpected string pool in ResTable");
}
break;
@@ -169,8 +164,8 @@
}
if (parser.event() == ResChunkPullParser::Event::kBadDocument) {
- context_->GetDiagnostics()->Error(
- DiagMessage(source_) << "corrupt resource table: " << parser.error());
+ context_->GetDiagnostics()->Error(DiagMessage(source_)
+ << "corrupt resource table: " << parser.error());
return false;
}
return true;
@@ -187,26 +182,25 @@
uint32_t package_id = util::DeviceToHost32(package_header->id);
if (package_id > std::numeric_limits<uint8_t>::max()) {
- context_->GetDiagnostics()->Error(
- DiagMessage(source_) << "package ID is too big (" << package_id << ")");
+ context_->GetDiagnostics()->Error(DiagMessage(source_)
+ << "package ID is too big (" << package_id << ")");
return false;
}
// Extract the package name.
- size_t len = strnlen16((const char16_t*)package_header->name,
- arraysize(package_header->name));
+ size_t len = strnlen16((const char16_t*)package_header->name, arraysize(package_header->name));
std::u16string package_name;
package_name.resize(len);
for (size_t i = 0; i < len; i++) {
package_name[i] = util::DeviceToHost16(package_header->name[i]);
}
- ResourceTablePackage* package = table_->CreatePackage(
- util::Utf16ToUtf8(package_name), static_cast<uint8_t>(package_id));
+ ResourceTablePackage* package =
+ table_->CreatePackage(util::Utf16ToUtf8(package_name), static_cast<uint8_t>(package_id));
if (!package) {
- context_->GetDiagnostics()->Error(
- DiagMessage(source_) << "incompatible package '" << package_name
- << "' with ID " << package_id);
+ context_->GetDiagnostics()->Error(DiagMessage(source_)
+ << "incompatible package '" << package_name << "' with ID "
+ << package_id);
return false;
}
@@ -221,23 +215,21 @@
switch (util::DeviceToHost16(parser.chunk()->type)) {
case android::RES_STRING_POOL_TYPE:
if (type_pool_.getError() == NO_INIT) {
- status_t err = type_pool_.setTo(
- parser.chunk(), util::DeviceToHost32(parser.chunk()->size));
+ status_t err =
+ type_pool_.setTo(parser.chunk(), util::DeviceToHost32(parser.chunk()->size));
if (err != NO_ERROR) {
context_->GetDiagnostics()->Error(DiagMessage(source_)
<< "corrupt type string pool in "
- << "ResTable_package: "
- << type_pool_.getError());
+ << "ResTable_package: " << type_pool_.getError());
return false;
}
} else if (key_pool_.getError() == NO_INIT) {
- status_t err = key_pool_.setTo(
- parser.chunk(), util::DeviceToHost32(parser.chunk()->size));
+ status_t err =
+ key_pool_.setTo(parser.chunk(), util::DeviceToHost32(parser.chunk()->size));
if (err != NO_ERROR) {
context_->GetDiagnostics()->Error(DiagMessage(source_)
<< "corrupt key string pool in "
- << "ResTable_package: "
- << key_pool_.getError());
+ << "ResTable_package: " << key_pool_.getError());
return false;
}
} else {
@@ -272,8 +264,8 @@
}
if (parser.event() == ResChunkPullParser::Event::kBadDocument) {
- context_->GetDiagnostics()->Error(
- DiagMessage(source_) << "corrupt ResTable_package: " << parser.error());
+ context_->GetDiagnostics()->Error(DiagMessage(source_)
+ << "corrupt ResTable_package: " << parser.error());
return false;
}
@@ -286,22 +278,19 @@
bool BinaryResourceParser::ParseTypeSpec(const ResChunk_header* chunk) {
if (type_pool_.getError() != NO_ERROR) {
- context_->GetDiagnostics()->Error(DiagMessage(source_)
- << "missing type string pool");
+ context_->GetDiagnostics()->Error(DiagMessage(source_) << "missing type string pool");
return false;
}
const ResTable_typeSpec* type_spec = ConvertTo<ResTable_typeSpec>(chunk);
if (!type_spec) {
- context_->GetDiagnostics()->Error(DiagMessage(source_)
- << "corrupt ResTable_typeSpec chunk");
+ context_->GetDiagnostics()->Error(DiagMessage(source_) << "corrupt ResTable_typeSpec chunk");
return false;
}
if (type_spec->id == 0) {
context_->GetDiagnostics()->Error(DiagMessage(source_)
- << "ResTable_typeSpec has invalid id: "
- << type_spec->id);
+ << "ResTable_typeSpec has invalid id: " << type_spec->id);
return false;
}
return true;
@@ -310,14 +299,12 @@
bool BinaryResourceParser::ParseType(const ResourceTablePackage* package,
const ResChunk_header* chunk) {
if (type_pool_.getError() != NO_ERROR) {
- context_->GetDiagnostics()->Error(DiagMessage(source_)
- << "missing type string pool");
+ context_->GetDiagnostics()->Error(DiagMessage(source_) << "missing type string pool");
return false;
}
if (key_pool_.getError() != NO_ERROR) {
- context_->GetDiagnostics()->Error(DiagMessage(source_)
- << "missing key string pool");
+ context_->GetDiagnostics()->Error(DiagMessage(source_) << "missing key string pool");
return false;
}
@@ -325,15 +312,13 @@
// a lot and has its own code to handle variable size.
const ResTable_type* type = ConvertTo<ResTable_type, kResTableTypeMinSize>(chunk);
if (!type) {
- context_->GetDiagnostics()->Error(DiagMessage(source_)
- << "corrupt ResTable_type chunk");
+ context_->GetDiagnostics()->Error(DiagMessage(source_) << "corrupt ResTable_type chunk");
return false;
}
if (type->id == 0) {
context_->GetDiagnostics()->Error(DiagMessage(source_)
- << "ResTable_type has invalid id: "
- << (int)type->id);
+ << "ResTable_type has invalid id: " << (int)type->id);
return false;
}
@@ -344,9 +329,9 @@
const ResourceType* parsed_type = ParseResourceType(type_str);
if (!parsed_type) {
- context_->GetDiagnostics()->Error(
- DiagMessage(source_) << "invalid type name '" << type_str
- << "' for type with ID " << (int)type->id);
+ context_->GetDiagnostics()->Error(DiagMessage(source_)
+ << "invalid type name '" << type_str << "' for type with ID "
+ << (int)type->id);
return false;
}
@@ -357,12 +342,10 @@
continue;
}
- const ResourceName name(
- package->name, *parsed_type,
- util::GetString(key_pool_, util::DeviceToHost32(entry->key.index)));
+ const ResourceName name(package->name, *parsed_type,
+ util::GetString(key_pool_, util::DeviceToHost32(entry->key.index)));
- const ResourceId res_id(package->id.value(), type->id,
- static_cast<uint16_t>(it.index()));
+ const ResourceId res_id(package->id.value(), type->id, static_cast<uint16_t>(it.index()));
std::unique_ptr<Value> resource_value;
if (entry->flags & ResTable_entry::FLAG_COMPLEX) {
@@ -377,10 +360,9 @@
}
if (!resource_value) {
- context_->GetDiagnostics()->Error(
- DiagMessage(source_) << "failed to parse value for resource " << name
- << " (" << res_id << ") with configuration '"
- << config << "'");
+ context_->GetDiagnostics()->Error(DiagMessage(source_)
+ << "failed to parse value for resource " << name << " ("
+ << res_id << ") with configuration '" << config << "'");
return false;
}
@@ -433,19 +415,19 @@
if (file_ref != nullptr) {
file_ref->file = files_->FindFile(*file_ref->path);
if (file_ref->file == nullptr) {
- context_->GetDiagnostics()->Warn(DiagMessage() << "resource " << name << " for config '"
- << config << "' is a file reference to '"
- << *file_ref->path
- << "' but no such path exists");
+ context_->GetDiagnostics()->Warn(DiagMessage()
+ << "resource " << name << " for config '" << config
+ << "' is a file reference to '" << *file_ref->path
+ << "' but no such path exists");
}
}
}
return item;
}
-std::unique_ptr<Value> BinaryResourceParser::ParseMapEntry(
- const ResourceNameRef& name, const ConfigDescription& config,
- const ResTable_map_entry* map) {
+std::unique_ptr<Value> BinaryResourceParser::ParseMapEntry(const ResourceNameRef& name,
+ const ConfigDescription& config,
+ const ResTable_map_entry* map) {
switch (name.type) {
case ResourceType::kStyle:
return ParseStyle(name, config, map);
@@ -470,9 +452,9 @@
return {};
}
-std::unique_ptr<Style> BinaryResourceParser::ParseStyle(
- const ResourceNameRef& name, const ConfigDescription& config,
- const ResTable_map_entry* map) {
+std::unique_ptr<Style> BinaryResourceParser::ParseStyle(const ResourceNameRef& name,
+ const ConfigDescription& config,
+ const ResTable_map_entry* map) {
std::unique_ptr<Style> style = util::make_unique<Style>();
if (util::DeviceToHost32(map->parent.ident) != 0) {
// The parent is a regular reference to a resource.
@@ -495,19 +477,16 @@
return style;
}
-std::unique_ptr<Attribute> BinaryResourceParser::ParseAttr(
- const ResourceNameRef& name, const ConfigDescription& config,
- const ResTable_map_entry* map) {
- const bool is_weak =
- (util::DeviceToHost16(map->flags) & ResTable_entry::FLAG_WEAK) != 0;
+std::unique_ptr<Attribute> BinaryResourceParser::ParseAttr(const ResourceNameRef& name,
+ const ConfigDescription& config,
+ const ResTable_map_entry* map) {
+ const bool is_weak = (util::DeviceToHost16(map->flags) & ResTable_entry::FLAG_WEAK) != 0;
std::unique_ptr<Attribute> attr = util::make_unique<Attribute>(is_weak);
// First we must discover what type of attribute this is. Find the type mask.
- auto type_mask_iter =
- std::find_if(begin(map), end(map), [](const ResTable_map& entry) -> bool {
- return util::DeviceToHost32(entry.name.ident) ==
- ResTable_map::ATTR_TYPE;
- });
+ auto type_mask_iter = std::find_if(begin(map), end(map), [](const ResTable_map& entry) -> bool {
+ return util::DeviceToHost32(entry.name.ident) == ResTable_map::ATTR_TYPE;
+ });
if (type_mask_iter != end(map)) {
attr->type_mask = util::DeviceToHost32(type_mask_iter->value.data);
@@ -526,8 +505,7 @@
continue;
}
- if (attr->type_mask &
- (ResTable_map::TYPE_ENUM | ResTable_map::TYPE_FLAGS)) {
+ if (attr->type_mask & (ResTable_map::TYPE_ENUM | ResTable_map::TYPE_FLAGS)) {
Attribute::Symbol symbol;
symbol.value = util::DeviceToHost32(map_entry.value.data);
symbol.symbol = Reference(util::DeviceToHost32(map_entry.name.ident));
@@ -539,9 +517,9 @@
return attr;
}
-std::unique_ptr<Array> BinaryResourceParser::ParseArray(
- const ResourceNameRef& name, const ConfigDescription& config,
- const ResTable_map_entry* map) {
+std::unique_ptr<Array> BinaryResourceParser::ParseArray(const ResourceNameRef& name,
+ const ConfigDescription& config,
+ const ResTable_map_entry* map) {
std::unique_ptr<Array> array = util::make_unique<Array>();
for (const ResTable_map& map_entry : map) {
array->elements.push_back(ParseValue(name, config, map_entry.value));
@@ -549,9 +527,9 @@
return array;
}
-std::unique_ptr<Plural> BinaryResourceParser::ParsePlural(
- const ResourceNameRef& name, const ConfigDescription& config,
- const ResTable_map_entry* map) {
+std::unique_ptr<Plural> BinaryResourceParser::ParsePlural(const ResourceNameRef& name,
+ const ConfigDescription& config,
+ const ResTable_map_entry* map) {
std::unique_ptr<Plural> plural = util::make_unique<Plural>();
for (const ResTable_map& map_entry : map) {
std::unique_ptr<Item> item = ParseValue(name, config, map_entry.value);
diff --git a/tools/aapt2/unflatten/BinaryResourceParser.h b/tools/aapt2/format/binary/BinaryResourceParser.h
similarity index 73%
rename from tools/aapt2/unflatten/BinaryResourceParser.h
rename to tools/aapt2/format/binary/BinaryResourceParser.h
index c41ada0..dc9a384 100644
--- a/tools/aapt2/unflatten/BinaryResourceParser.h
+++ b/tools/aapt2/format/binary/BinaryResourceParser.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef AAPT_BINARY_RESOURCE_PARSER_H
-#define AAPT_BINARY_RESOURCE_PARSER_H
+#ifndef AAPT_FORMAT_BINARY_RESOURCEPARSER_H
+#define AAPT_FORMAT_BINARY_RESOURCEPARSER_H
#include <string>
@@ -32,25 +32,17 @@
struct SymbolTable_entry;
-/*
- * Parses a binary resource table (resources.arsc) and adds the entries
- * to a ResourceTable. This is different than the libandroidfw ResTable
- * in that it scans the table from top to bottom and doesn't require
- * support for random access. It is also able to parse non-runtime
- * chunks and types.
- */
+// Parses a binary resource table (resources.arsc) and adds the entries to a ResourceTable.
+// This is different than the libandroidfw ResTable in that it scans the table from top to bottom
+// and doesn't require support for random access.
class BinaryResourceParser {
public:
- /*
- * Creates a parser, which will read `len` bytes from `data`, and
- * add any resources parsed to `table`. `source` is for logging purposes.
- */
+ // Creates a parser, which will read `len` bytes from `data`, and add any resources parsed to
+ // `table`. `source` is for logging purposes.
BinaryResourceParser(IAaptContext* context, ResourceTable* table, const Source& source,
const void* data, size_t data_len, io::IFileCollection* files = nullptr);
- /*
- * Parses the binary resource table and returns true if successful.
- */
+ // Parses the binary resource table and returns true if successful.
bool Parse();
private:
@@ -59,31 +51,25 @@
bool ParseTable(const android::ResChunk_header* chunk);
bool ParsePackage(const android::ResChunk_header* chunk);
bool ParseTypeSpec(const android::ResChunk_header* chunk);
- bool ParseType(const ResourceTablePackage* package,
- const android::ResChunk_header* chunk);
+ bool ParseType(const ResourceTablePackage* package, const android::ResChunk_header* chunk);
bool ParseLibrary(const android::ResChunk_header* chunk);
std::unique_ptr<Item> ParseValue(const ResourceNameRef& name, const ConfigDescription& config,
const android::Res_value& value);
- std::unique_ptr<Value> ParseMapEntry(const ResourceNameRef& name,
- const ConfigDescription& config,
+ std::unique_ptr<Value> ParseMapEntry(const ResourceNameRef& name, const ConfigDescription& config,
const android::ResTable_map_entry* map);
- std::unique_ptr<Style> ParseStyle(const ResourceNameRef& name,
- const ConfigDescription& config,
+ std::unique_ptr<Style> ParseStyle(const ResourceNameRef& name, const ConfigDescription& config,
const android::ResTable_map_entry* map);
- std::unique_ptr<Attribute> ParseAttr(const ResourceNameRef& name,
- const ConfigDescription& config,
+ std::unique_ptr<Attribute> ParseAttr(const ResourceNameRef& name, const ConfigDescription& config,
const android::ResTable_map_entry* map);
- std::unique_ptr<Array> ParseArray(const ResourceNameRef& name,
- const ConfigDescription& config,
+ std::unique_ptr<Array> ParseArray(const ResourceNameRef& name, const ConfigDescription& config,
const android::ResTable_map_entry* map);
- std::unique_ptr<Plural> ParsePlural(const ResourceNameRef& name,
- const ConfigDescription& config,
+ std::unique_ptr<Plural> ParsePlural(const ResourceNameRef& name, const ConfigDescription& config,
const android::ResTable_map_entry* map);
/**
@@ -125,13 +111,10 @@
namespace android {
-/**
- * Iterator functionality for ResTable_map_entry.
- */
+// Iterator functionality for ResTable_map_entry.
inline const ResTable_map* begin(const ResTable_map_entry* map) {
- return (const ResTable_map*)((const uint8_t*)map +
- aapt::util::DeviceToHost32(map->size));
+ return (const ResTable_map*)((const uint8_t*)map + ::aapt::util::DeviceToHost32(map->size));
}
inline const ResTable_map* end(const ResTable_map_entry* map) {
@@ -140,4 +123,4 @@
} // namespace android
-#endif // AAPT_BINARY_RESOURCE_PARSER_H
+#endif // AAPT_FORMAT_BINARY_RESOURCEPARSER_H
diff --git a/tools/aapt2/flatten/ChunkWriter.h b/tools/aapt2/format/binary/ChunkWriter.h
similarity index 85%
rename from tools/aapt2/flatten/ChunkWriter.h
rename to tools/aapt2/format/binary/ChunkWriter.h
index 968d3ee..1892a29 100644
--- a/tools/aapt2/flatten/ChunkWriter.h
+++ b/tools/aapt2/format/binary/ChunkWriter.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef AAPT_FLATTEN_CHUNKWRITER_H
-#define AAPT_FLATTEN_CHUNKWRITER_H
+#ifndef AAPT_FORMAT_BINARY_CHUNKWRITER_H
+#define AAPT_FORMAT_BINARY_CHUNKWRITER_H
#include "android-base/macros.h"
#include "androidfw/ResourceTypes.h"
@@ -27,7 +27,8 @@
class ChunkWriter {
public:
- explicit inline ChunkWriter(BigBuffer* buffer) : buffer_(buffer) {}
+ explicit inline ChunkWriter(BigBuffer* buffer) : buffer_(buffer) {
+ }
ChunkWriter(ChunkWriter&&) = default;
ChunkWriter& operator=(ChunkWriter&&) = default;
@@ -46,11 +47,17 @@
return buffer_->NextBlock<T>(count);
}
- inline BigBuffer* buffer() { return buffer_; }
+ inline BigBuffer* buffer() {
+ return buffer_;
+ }
- inline android::ResChunk_header* chunk_header() { return header_; }
+ inline android::ResChunk_header* chunk_header() {
+ return header_;
+ }
- inline size_t size() { return buffer_->size() - start_size_; }
+ inline size_t size() {
+ return buffer_->size() - start_size_;
+ }
inline android::ResChunk_header* Finish() {
buffer_->Align4();
@@ -77,4 +84,4 @@
} // namespace aapt
-#endif /* AAPT_FLATTEN_CHUNKWRITER_H */
+#endif /* AAPT_FORMAT_BINARY_CHUNKWRITER_H */
diff --git a/tools/aapt2/unflatten/ResChunkPullParser.cpp b/tools/aapt2/format/binary/ResChunkPullParser.cpp
similarity index 92%
rename from tools/aapt2/unflatten/ResChunkPullParser.cpp
rename to tools/aapt2/format/binary/ResChunkPullParser.cpp
index 8d92bd9..fd6919d 100644
--- a/tools/aapt2/unflatten/ResChunkPullParser.cpp
+++ b/tools/aapt2/format/binary/ResChunkPullParser.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "unflatten/ResChunkPullParser.h"
+#include "format/binary/ResChunkPullParser.h"
#include <inttypes.h>
#include <cstddef>
@@ -44,9 +44,8 @@
if (event_ == Event::kStartDocument) {
current_chunk_ = data_;
} else {
- current_chunk_ =
- (const ResChunk_header*)(((const char*)current_chunk_) +
- util::DeviceToHost32(current_chunk_->size));
+ current_chunk_ = (const ResChunk_header*)(((const char*)current_chunk_) +
+ util::DeviceToHost32(current_chunk_->size));
}
const std::ptrdiff_t diff = (const char*)current_chunk_ - (const char*)data_;
diff --git a/tools/aapt2/unflatten/ResChunkPullParser.h b/tools/aapt2/format/binary/ResChunkPullParser.h
similarity index 64%
rename from tools/aapt2/unflatten/ResChunkPullParser.h
rename to tools/aapt2/format/binary/ResChunkPullParser.h
index 5827753..5ff1359 100644
--- a/tools/aapt2/unflatten/ResChunkPullParser.h
+++ b/tools/aapt2/format/binary/ResChunkPullParser.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef AAPT_RES_CHUNK_PULL_PARSER_H
-#define AAPT_RES_CHUNK_PULL_PARSER_H
+#ifndef AAPT_FORMAT_BINARY_RESCHUNKPULLPARSER_H
+#define AAPT_FORMAT_BINARY_RESCHUNKPULLPARSER_H
#include <string>
@@ -26,18 +26,13 @@
namespace aapt {
-/**
- * A pull parser, modeled after XmlPullParser, that reads
- * android::ResChunk_header structs from a block of data.
- *
- * An android::ResChunk_header specifies a type, headerSize,
- * and size. The pull parser will verify that the chunk's size
- * doesn't extend beyond the available data, and will iterate
- * over each chunk in the given block of data.
- *
- * Processing nested chunks is done by creating a new ResChunkPullParser
- * pointing to the data portion of a chunk.
- */
+// A pull parser, modeled after XmlPullParser, that reads android::ResChunk_header structs from a
+// block of data.
+// An android::ResChunk_header specifies a type, headerSize, and size. The pull parser will verify
+// that the chunk's size doesn't extend beyond the available data, and will iterate over each chunk
+// in the given block of data.
+// Processing nested chunks is done by creating a new ResChunkPullParser pointing to the data
+// portion of a chunk.
class ResChunkPullParser {
public:
enum class Event {
@@ -48,24 +43,18 @@
kChunk,
};
- /**
- * Returns false if the event is EndDocument or BadDocument.
- */
+ // Returns false if the event is EndDocument or BadDocument.
static bool IsGoodEvent(Event event);
- /**
- * Create a ResChunkPullParser to read android::ResChunk_headers
- * from the memory pointed to by data, of len bytes.
- */
+ // Create a ResChunkPullParser to read android::ResChunk_headers from the memory pointed to by
+ // data, of len bytes.
ResChunkPullParser(const void* data, size_t len);
Event event() const;
const std::string& error() const;
const android::ResChunk_header* chunk() const;
- /**
- * Move to the next android::ResChunk_header.
- */
+ // Move to the next android::ResChunk_header.
Event Next();
private:
@@ -86,15 +75,12 @@
return reinterpret_cast<const T*>(chunk);
}
-inline static const uint8_t* GetChunkData(
- const android::ResChunk_header* chunk) {
- return reinterpret_cast<const uint8_t*>(chunk) +
- util::DeviceToHost16(chunk->headerSize);
+inline static const uint8_t* GetChunkData(const android::ResChunk_header* chunk) {
+ return reinterpret_cast<const uint8_t*>(chunk) + util::DeviceToHost16(chunk->headerSize);
}
inline static uint32_t GetChunkDataLen(const android::ResChunk_header* chunk) {
- return util::DeviceToHost32(chunk->size) -
- util::DeviceToHost16(chunk->headerSize);
+ return util::DeviceToHost32(chunk->size) - util::DeviceToHost16(chunk->headerSize);
}
//
@@ -109,13 +95,16 @@
: event_(Event::kStartDocument),
data_(reinterpret_cast<const android::ResChunk_header*>(data)),
len_(len),
- current_chunk_(nullptr) {}
+ current_chunk_(nullptr) {
+}
inline ResChunkPullParser::Event ResChunkPullParser::event() const {
return event_;
}
-inline const std::string& ResChunkPullParser::error() const { return error_; }
+inline const std::string& ResChunkPullParser::error() const {
+ return error_;
+}
inline const android::ResChunk_header* ResChunkPullParser::chunk() const {
return current_chunk_;
@@ -123,4 +112,4 @@
} // namespace aapt
-#endif // AAPT_RES_CHUNK_PULL_PARSER_H
+#endif // AAPT_FORMAT_BINARY_RESCHUNKPULLPARSER_H
diff --git a/tools/aapt2/flatten/ResourceTypeExtensions.h b/tools/aapt2/format/binary/ResourceTypeExtensions.h
similarity index 75%
rename from tools/aapt2/flatten/ResourceTypeExtensions.h
rename to tools/aapt2/format/binary/ResourceTypeExtensions.h
index 6359b41..7f58df80 100644
--- a/tools/aapt2/flatten/ResourceTypeExtensions.h
+++ b/tools/aapt2/format/binary/ResourceTypeExtensions.h
@@ -14,18 +14,14 @@
* limitations under the License.
*/
-#ifndef AAPT_RESOURCE_TYPE_EXTENSIONS_H
-#define AAPT_RESOURCE_TYPE_EXTENSIONS_H
+#ifndef AAPT_FORMAT_BINARY_RESOURCETYPEEXTENSIONS_H
+#define AAPT_FORMAT_BINARY_RESOURCETYPEEXTENSIONS_H
#include "androidfw/ResourceTypes.h"
namespace aapt {
-/**
- * An alternative struct to use instead of ResTable_map_entry. This one is a
- * standard_layout
- * struct.
- */
+// An alternative struct to use instead of ResTable_map_entry. This one is a standard_layout struct.
struct ResTable_entry_ext {
android::ResTable_entry entry;
android::ResTable_ref parent;
@@ -34,4 +30,4 @@
} // namespace aapt
-#endif // AAPT_RESOURCE_TYPE_EXTENSIONS_H
+#endif // AAPT_FORMAT_BINARY_RESOURCETYPEEXTENSIONS_H
diff --git a/tools/aapt2/flatten/TableFlattener.cpp b/tools/aapt2/format/binary/TableFlattener.cpp
similarity index 93%
rename from tools/aapt2/flatten/TableFlattener.cpp
rename to tools/aapt2/format/binary/TableFlattener.cpp
index 097727c..57565a5 100644
--- a/tools/aapt2/flatten/TableFlattener.cpp
+++ b/tools/aapt2/format/binary/TableFlattener.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "flatten/TableFlattener.h"
+#include "format/binary/TableFlattener.h"
#include <algorithm>
#include <numeric>
@@ -28,8 +28,8 @@
#include "ResourceValues.h"
#include "SdkConstants.h"
#include "ValueVisitor.h"
-#include "flatten/ChunkWriter.h"
-#include "flatten/ResourceTypeExtensions.h"
+#include "format/binary/ChunkWriter.h"
+#include "format/binary/ResourceTypeExtensions.h"
#include "util/BigBuffer.h"
using namespace android;
@@ -81,7 +81,8 @@
using ValueVisitor::Visit;
MapFlattenVisitor(ResTable_entry_ext* out_entry, BigBuffer* buffer)
- : out_entry_(out_entry), buffer_(buffer) {}
+ : out_entry_(out_entry), buffer_(buffer) {
+ }
void Visit(Attribute* attr) override {
{
@@ -92,15 +93,13 @@
if (attr->min_int != std::numeric_limits<int32_t>::min()) {
Reference key = Reference(ResourceId(ResTable_map::ATTR_MIN));
- BinaryPrimitive val(Res_value::TYPE_INT_DEC,
- static_cast<uint32_t>(attr->min_int));
+ BinaryPrimitive val(Res_value::TYPE_INT_DEC, static_cast<uint32_t>(attr->min_int));
FlattenEntry(&key, &val);
}
if (attr->max_int != std::numeric_limits<int32_t>::max()) {
Reference key = Reference(ResourceId(ResTable_map::ATTR_MAX));
- BinaryPrimitive val(Res_value::TYPE_INT_DEC,
- static_cast<uint32_t>(attr->max_int));
+ BinaryPrimitive val(Res_value::TYPE_INT_DEC, static_cast<uint32_t>(attr->max_int));
FlattenEntry(&key, &val);
}
@@ -188,7 +187,9 @@
* Call this after visiting a Value. This will finish any work that
* needs to be done to prepare the entry.
*/
- void Finish() { out_entry_->count = util::HostToDevice32(entry_count_); }
+ void Finish() {
+ out_entry_->count = util::HostToDevice32(entry_count_);
+ }
private:
DISALLOW_COPY_AND_ASSIGN(MapFlattenVisitor);
@@ -223,7 +224,8 @@
diag_(context->GetDiagnostics()),
package_(package),
shared_libs_(shared_libs),
- use_sparse_entries_(use_sparse_entries) {}
+ use_sparse_entries_(use_sparse_entries) {
+ }
bool FlattenPackage(BigBuffer* buffer) {
ChunkWriter pkg_writer(buffer);
@@ -271,9 +273,9 @@
template <typename T, bool IsItem>
T* WriteEntry(FlatEntry* entry, BigBuffer* buffer) {
- static_assert(std::is_same<ResTable_entry, T>::value ||
- std::is_same<ResTable_entry_ext, T>::value,
- "T must be ResTable_entry or ResTable_entry_ext");
+ static_assert(
+ std::is_same<ResTable_entry, T>::value || std::is_same<ResTable_entry_ext, T>::value,
+ "T must be ResTable_entry or ResTable_entry_ext");
T* result = buffer->NextBlock<T>();
ResTable_entry* out_entry = (ResTable_entry*)result;
@@ -302,8 +304,7 @@
CHECK(item->Flatten(outValue)) << "flatten failed";
outValue->size = util::HostToDevice16(sizeof(*outValue));
} else {
- ResTable_entry_ext* out_entry =
- WriteEntry<ResTable_entry_ext, false>(entry, buffer);
+ ResTable_entry_ext* out_entry = WriteEntry<ResTable_entry_ext, false>(entry, buffer);
MapFlattenVisitor visitor(out_entry, buffer);
entry->value->Accept(&visitor);
visitor.Finish();
@@ -318,8 +319,7 @@
CHECK(num_total_entries <= std::numeric_limits<uint16_t>::max());
ChunkWriter type_writer(buffer);
- ResTable_type* type_header =
- type_writer.StartChunk<ResTable_type>(RES_TABLE_TYPE_TYPE);
+ ResTable_type* type_header = type_writer.StartChunk<ResTable_type>(RES_TABLE_TYPE_TYPE);
type_header->id = type->id.value();
type_header->config = config;
type_header->config.swapHtoD();
@@ -395,8 +395,7 @@
sorted_types.push_back(type.get());
}
- std::sort(sorted_types.begin(), sorted_types.end(),
- cmp_ids<ResourceTableType>);
+ std::sort(sorted_types.begin(), sorted_types.end(), cmp_ids<ResourceTableType>);
return sorted_types;
}
@@ -411,13 +410,11 @@
return sorted_entries;
}
- bool FlattenTypeSpec(ResourceTableType* type,
- std::vector<ResourceEntry*>* sorted_entries,
+ bool FlattenTypeSpec(ResourceTableType* type, std::vector<ResourceEntry*>* sorted_entries,
BigBuffer* buffer) {
ChunkWriter type_spec_writer(buffer);
ResTable_typeSpec* spec_header =
- type_spec_writer.StartChunk<ResTable_typeSpec>(
- RES_TABLE_TYPE_SPEC_TYPE);
+ type_spec_writer.StartChunk<ResTable_typeSpec>(RES_TABLE_TYPE_SPEC_TYPE);
spec_header->id = type->id.value();
if (sorted_entries->empty()) {
@@ -443,8 +440,7 @@
// Populate the config masks for this entry.
if (entry->symbol_status.state == SymbolState::kPublic) {
- config_masks[entry->id.value()] |=
- util::HostToDevice32(ResTable_typeSpec::SPEC_PUBLIC);
+ config_masks[entry->id.value()] |= util::HostToDevice32(ResTable_typeSpec::SPEC_PUBLIC);
}
const size_t config_count = entry->values.size();
diff --git a/tools/aapt2/flatten/TableFlattener.h b/tools/aapt2/format/binary/TableFlattener.h
similarity index 89%
rename from tools/aapt2/flatten/TableFlattener.h
rename to tools/aapt2/format/binary/TableFlattener.h
index 223aef8..88cbddf 100644
--- a/tools/aapt2/flatten/TableFlattener.h
+++ b/tools/aapt2/format/binary/TableFlattener.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef AAPT_FLATTEN_TABLEFLATTENER_H
-#define AAPT_FLATTEN_TABLEFLATTENER_H
+#ifndef AAPT_FORMAT_BINARY_TABLEFLATTENER_H
+#define AAPT_FORMAT_BINARY_TABLEFLATTENER_H
#include "android-base/macros.h"
@@ -40,7 +40,8 @@
class TableFlattener : public IResourceTableConsumer {
public:
explicit TableFlattener(const TableFlattenerOptions& options, BigBuffer* buffer)
- : options_(options), buffer_(buffer) {}
+ : options_(options), buffer_(buffer) {
+ }
bool Consume(IAaptContext* context, ResourceTable* table) override;
@@ -53,4 +54,4 @@
} // namespace aapt
-#endif /* AAPT_FLATTEN_TABLEFLATTENER_H */
+#endif /* AAPT_FORMAT_BINARY_TABLEFLATTENER_H */
diff --git a/tools/aapt2/flatten/TableFlattener_test.cpp b/tools/aapt2/format/binary/TableFlattener_test.cpp
similarity index 83%
rename from tools/aapt2/flatten/TableFlattener_test.cpp
rename to tools/aapt2/format/binary/TableFlattener_test.cpp
index 4fdb2ec..6d75973 100644
--- a/tools/aapt2/flatten/TableFlattener_test.cpp
+++ b/tools/aapt2/format/binary/TableFlattener_test.cpp
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-#include "flatten/TableFlattener.h"
+#include "format/binary/TableFlattener.h"
#include "android-base/stringprintf.h"
#include "ResourceUtils.h"
#include "SdkConstants.h"
+#include "format/binary/BinaryResourceParser.h"
#include "test/Test.h"
-#include "unflatten/BinaryResourceParser.h"
#include "util/Util.h"
using namespace android;
@@ -34,10 +34,8 @@
class TableFlattenerTest : public ::testing::Test {
public:
void SetUp() override {
- context_ = test::ContextBuilder()
- .SetCompilationPackage("com.app.test")
- .SetPackageId(0x7f)
- .Build();
+ context_ =
+ test::ContextBuilder().SetCompilationPackage("com.app.test").SetPackageId(0x7f).Build();
}
::testing::AssertionResult Flatten(IAaptContext* context, const TableFlattenerOptions& options,
@@ -80,12 +78,10 @@
return ::testing::AssertionSuccess();
}
- ::testing::AssertionResult Exists(ResTable* table,
- const StringPiece& expected_name,
+ ::testing::AssertionResult Exists(ResTable* table, const StringPiece& expected_name,
const ResourceId& expected_id,
const ConfigDescription& expected_config,
- const uint8_t expected_data_type,
- const uint32_t expected_data,
+ const uint8_t expected_data_type, const uint32_t expected_data,
const uint32_t expected_spec_flags) {
const ResourceName expected_res_name = test::ParseNameOrDie(expected_name);
@@ -94,28 +90,26 @@
ResTable_config config;
Res_value val;
uint32_t spec_flags;
- if (table->getResource(expected_id.id, &val, false, 0, &spec_flags,
- &config) < 0) {
+ if (table->getResource(expected_id.id, &val, false, 0, &spec_flags, &config) < 0) {
return ::testing::AssertionFailure() << "could not find resource with";
}
if (expected_data_type != val.dataType) {
return ::testing::AssertionFailure()
<< "expected data type " << std::hex << (int)expected_data_type
- << " but got data type " << (int)val.dataType << std::dec
- << " instead";
+ << " but got data type " << (int)val.dataType << std::dec << " instead";
}
if (expected_data != val.data) {
return ::testing::AssertionFailure()
- << "expected data " << std::hex << expected_data
- << " but got data " << val.data << std::dec << " instead";
+ << "expected data " << std::hex << expected_data << " but got data " << val.data
+ << std::dec << " instead";
}
if (expected_spec_flags != spec_flags) {
return ::testing::AssertionFailure()
- << "expected specFlags " << std::hex << expected_spec_flags
- << " but got specFlags " << spec_flags << std::dec << " instead";
+ << "expected specFlags " << std::hex << expected_spec_flags << " but got specFlags "
+ << spec_flags << std::dec << " instead";
}
ResTable::resource_name actual_name;
@@ -127,16 +121,14 @@
if (!resName) {
return ::testing::AssertionFailure()
<< "expected name '" << expected_res_name << "' but got '"
- << StringPiece16(actual_name.package, actual_name.packageLen)
- << ":" << StringPiece16(actual_name.type, actual_name.typeLen)
- << "/" << StringPiece16(actual_name.name, actual_name.nameLen)
- << "'";
+ << StringPiece16(actual_name.package, actual_name.packageLen) << ":"
+ << StringPiece16(actual_name.type, actual_name.typeLen) << "/"
+ << StringPiece16(actual_name.name, actual_name.nameLen) << "'";
}
if (expected_config != config) {
- return ::testing::AssertionFailure() << "expected config '"
- << expected_config << "' but got '"
- << ConfigDescription(config) << "'";
+ return ::testing::AssertionFailure() << "expected config '" << expected_config
+ << "' but got '" << ConfigDescription(config) << "'";
}
return ::testing::AssertionSuccess();
}
@@ -152,57 +144,46 @@
.AddSimple("com.app.test:id/one", ResourceId(0x7f020000))
.AddSimple("com.app.test:id/two", ResourceId(0x7f020001))
.AddValue("com.app.test:id/three", ResourceId(0x7f020002),
- test::BuildReference("com.app.test:id/one",
- ResourceId(0x7f020000)))
+ test::BuildReference("com.app.test:id/one", ResourceId(0x7f020000)))
.AddValue("com.app.test:integer/one", ResourceId(0x7f030000),
- util::make_unique<BinaryPrimitive>(
- uint8_t(Res_value::TYPE_INT_DEC), 1u))
+ util::make_unique<BinaryPrimitive>(uint8_t(Res_value::TYPE_INT_DEC), 1u))
.AddValue("com.app.test:integer/one", test::ParseConfigOrDie("v1"),
ResourceId(0x7f030000),
- util::make_unique<BinaryPrimitive>(
- uint8_t(Res_value::TYPE_INT_DEC), 2u))
+ util::make_unique<BinaryPrimitive>(uint8_t(Res_value::TYPE_INT_DEC), 2u))
.AddString("com.app.test:string/test", ResourceId(0x7f040000), "foo")
- .AddString("com.app.test:layout/bar", ResourceId(0x7f050000),
- "res/layout/bar.xml")
+ .AddString("com.app.test:layout/bar", ResourceId(0x7f050000), "res/layout/bar.xml")
.Build();
ResTable res_table;
ASSERT_TRUE(Flatten(context_.get(), {}, table.get(), &res_table));
- EXPECT_TRUE(Exists(&res_table, "com.app.test:id/one", ResourceId(0x7f020000),
- {}, Res_value::TYPE_INT_BOOLEAN, 0u, 0u));
+ EXPECT_TRUE(Exists(&res_table, "com.app.test:id/one", ResourceId(0x7f020000), {},
+ Res_value::TYPE_INT_BOOLEAN, 0u, 0u));
- EXPECT_TRUE(Exists(&res_table, "com.app.test:id/two", ResourceId(0x7f020001),
- {}, Res_value::TYPE_INT_BOOLEAN, 0u, 0u));
+ EXPECT_TRUE(Exists(&res_table, "com.app.test:id/two", ResourceId(0x7f020001), {},
+ Res_value::TYPE_INT_BOOLEAN, 0u, 0u));
- EXPECT_TRUE(Exists(&res_table, "com.app.test:id/three",
- ResourceId(0x7f020002), {}, Res_value::TYPE_REFERENCE,
- 0x7f020000u, 0u));
+ EXPECT_TRUE(Exists(&res_table, "com.app.test:id/three", ResourceId(0x7f020002), {},
+ Res_value::TYPE_REFERENCE, 0x7f020000u, 0u));
- EXPECT_TRUE(Exists(&res_table, "com.app.test:integer/one",
- ResourceId(0x7f030000), {}, Res_value::TYPE_INT_DEC, 1u,
- ResTable_config::CONFIG_VERSION));
+ EXPECT_TRUE(Exists(&res_table, "com.app.test:integer/one", ResourceId(0x7f030000), {},
+ Res_value::TYPE_INT_DEC, 1u, ResTable_config::CONFIG_VERSION));
- EXPECT_TRUE(Exists(&res_table, "com.app.test:integer/one",
- ResourceId(0x7f030000), test::ParseConfigOrDie("v1"),
- Res_value::TYPE_INT_DEC, 2u,
+ EXPECT_TRUE(Exists(&res_table, "com.app.test:integer/one", ResourceId(0x7f030000),
+ test::ParseConfigOrDie("v1"), Res_value::TYPE_INT_DEC, 2u,
ResTable_config::CONFIG_VERSION));
std::u16string foo_str = u"foo";
- ssize_t idx = res_table.getTableStringBlock(0)->indexOfString(foo_str.data(),
- foo_str.size());
+ ssize_t idx = res_table.getTableStringBlock(0)->indexOfString(foo_str.data(), foo_str.size());
ASSERT_GE(idx, 0);
- EXPECT_TRUE(Exists(&res_table, "com.app.test:string/test",
- ResourceId(0x7f040000), {}, Res_value::TYPE_STRING,
- (uint32_t)idx, 0u));
+ EXPECT_TRUE(Exists(&res_table, "com.app.test:string/test", ResourceId(0x7f040000), {},
+ Res_value::TYPE_STRING, (uint32_t)idx, 0u));
std::u16string bar_path = u"res/layout/bar.xml";
- idx = res_table.getTableStringBlock(0)->indexOfString(bar_path.data(),
- bar_path.size());
+ idx = res_table.getTableStringBlock(0)->indexOfString(bar_path.data(), bar_path.size());
ASSERT_GE(idx, 0);
- EXPECT_TRUE(Exists(&res_table, "com.app.test:layout/bar",
- ResourceId(0x7f050000), {}, Res_value::TYPE_STRING,
- (uint32_t)idx, 0u));
+ EXPECT_TRUE(Exists(&res_table, "com.app.test:layout/bar", ResourceId(0x7f050000), {},
+ Res_value::TYPE_STRING, (uint32_t)idx, 0u));
}
TEST_F(TableFlattenerTest, FlattenEntriesWithGapsInIds) {
@@ -216,11 +197,10 @@
ResTable res_table;
ASSERT_TRUE(Flatten(context_.get(), {}, table.get(), &res_table));
- EXPECT_TRUE(Exists(&res_table, "com.app.test:id/one", ResourceId(0x7f020001),
- {}, Res_value::TYPE_INT_BOOLEAN, 0u, 0u));
- EXPECT_TRUE(Exists(&res_table, "com.app.test:id/three",
- ResourceId(0x7f020003), {}, Res_value::TYPE_INT_BOOLEAN,
- 0u, 0u));
+ EXPECT_TRUE(Exists(&res_table, "com.app.test:id/one", ResourceId(0x7f020001), {},
+ Res_value::TYPE_INT_BOOLEAN, 0u, 0u));
+ EXPECT_TRUE(Exists(&res_table, "com.app.test:id/three", ResourceId(0x7f020003), {},
+ Res_value::TYPE_INT_BOOLEAN, 0u, 0u));
}
TEST_F(TableFlattenerTest, FlattenMinMaxAttributes) {
@@ -231,8 +211,7 @@
std::unique_ptr<ResourceTable> table =
test::ResourceTableBuilder()
.SetPackageId("android", 0x01)
- .AddValue("android:attr/foo", ResourceId(0x01010000),
- util::make_unique<Attribute>(attr))
+ .AddValue("android:attr/foo", ResourceId(0x01010000), util::make_unique<Attribute>(attr))
.Build();
ResourceTable result;
@@ -308,9 +287,12 @@
ASSERT_THAT(value, NotNull());
EXPECT_EQ(0u, value->value.data);
- ASSERT_THAT(test::GetValueForConfig<BinaryPrimitive>(&sparse_table, "android:string/foo_1", sparse_config), IsNull());
+ ASSERT_THAT(test::GetValueForConfig<BinaryPrimitive>(&sparse_table, "android:string/foo_1",
+ sparse_config),
+ IsNull());
- value = test::GetValueForConfig<BinaryPrimitive>(&sparse_table, "android:string/foo_4", sparse_config);
+ value = test::GetValueForConfig<BinaryPrimitive>(&sparse_table, "android:string/foo_4",
+ sparse_config);
ASSERT_THAT(value, NotNull());
EXPECT_EQ(4u, value->value.data);
}
diff --git a/tools/aapt2/flatten/XmlFlattener.cpp b/tools/aapt2/format/binary/XmlFlattener.cpp
similarity index 93%
rename from tools/aapt2/flatten/XmlFlattener.cpp
rename to tools/aapt2/format/binary/XmlFlattener.cpp
index b3b308a..f8f09ab 100644
--- a/tools/aapt2/flatten/XmlFlattener.cpp
+++ b/tools/aapt2/format/binary/XmlFlattener.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "flatten/XmlFlattener.h"
+#include "format/binary/XmlFlattener.h"
#include <algorithm>
#include <map>
@@ -26,8 +26,8 @@
#include "utils/misc.h"
#include "SdkConstants.h"
-#include "flatten/ChunkWriter.h"
-#include "flatten/ResourceTypeExtensions.h"
+#include "format/binary/ChunkWriter.h"
+#include "format/binary/ResourceTypeExtensions.h"
#include "xml/XmlDom.h"
using namespace android;
@@ -71,7 +71,8 @@
std::vector<StringFlattenDest> string_refs;
XmlFlattenerVisitor(BigBuffer* buffer, XmlFlattenerOptions options)
- : buffer_(buffer), options_(options) {}
+ : buffer_(buffer), options_(options) {
+ }
void Visit(xml::Text* node) override {
if (util::TrimWhitespace(node->text).empty()) {
@@ -152,15 +153,14 @@
private:
DISALLOW_COPY_AND_ASSIGN(XmlFlattenerVisitor);
- void AddString(const StringPiece& str, uint32_t priority,
- android::ResStringPool_ref* dest,
+ void AddString(const StringPiece& str, uint32_t priority, android::ResStringPool_ref* dest,
bool treat_empty_string_as_null = false) {
if (str.empty() && treat_empty_string_as_null) {
// Some parts of the runtime treat null differently than empty string.
dest->index = util::DeviceToHost32(-1);
} else {
- string_refs.push_back(StringFlattenDest{
- pool.MakeRef(str, StringPool::Context(priority)), dest});
+ string_refs.push_back(
+ StringFlattenDest{pool.MakeRef(str, StringPool::Context(priority)), dest});
}
}
@@ -208,8 +208,7 @@
uint16_t attribute_index = 1;
for (const xml::Attribute* xml_attr : filtered_attrs_) {
// Assign the indices for specific attributes.
- if (xml_attr->compiled_attribute &&
- xml_attr->compiled_attribute.value().id &&
+ if (xml_attr->compiled_attribute && xml_attr->compiled_attribute.value().id &&
xml_attr->compiled_attribute.value().id.value() == kIdAttr) {
flat_elem->idIndex = util::HostToDevice16(attribute_index);
} else if (xml_attr->namespace_uri.empty()) {
@@ -241,9 +240,8 @@
// Lookup the StringPool for this package and make the reference there.
const xml::AaptAttribute& aapt_attr = xml_attr->compiled_attribute.value();
- StringPool::Ref name_ref =
- package_pools[aapt_attr.id.value().package_id()].MakeRef(
- xml_attr->name, StringPool::Context(aapt_attr.id.value().id));
+ StringPool::Ref name_ref = package_pools[aapt_attr.id.value().package_id()].MakeRef(
+ xml_attr->name, StringPool::Context(aapt_attr.id.value().id));
// Add it to the list of strings to flatten.
AddString(name_ref, &flat_attr->name);
@@ -272,7 +270,7 @@
flat_attr->typedValue.dataType = android::Res_value::TYPE_STRING;
AddString(str_builder.ToString(), kLowPriority,
- (ResStringPool_ref*) &flat_attr->typedValue.data);
+ (ResStringPool_ref*)&flat_attr->typedValue.data);
}
flat_attr->typedValue.size = util::HostToDevice16(sizeof(flat_attr->typedValue));
diff --git a/tools/aapt2/flatten/XmlFlattener.h b/tools/aapt2/format/binary/XmlFlattener.h
similarity index 83%
rename from tools/aapt2/flatten/XmlFlattener.h
rename to tools/aapt2/format/binary/XmlFlattener.h
index 87557f2..6a48835 100644
--- a/tools/aapt2/flatten/XmlFlattener.h
+++ b/tools/aapt2/format/binary/XmlFlattener.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef AAPT_FLATTEN_XMLFLATTENER_H
-#define AAPT_FLATTEN_XMLFLATTENER_H
+#ifndef AAPT_FORMAT_BINARY_XMLFLATTENER_H
+#define AAPT_FORMAT_BINARY_XMLFLATTENER_H
#include "android-base/macros.h"
@@ -26,16 +26,15 @@
namespace aapt {
struct XmlFlattenerOptions {
- /**
- * Keep attribute raw string values along with typed values.
- */
+ // Keep attribute raw string values along with typed values.
bool keep_raw_values = false;
};
class XmlFlattener : public IXmlResourceConsumer {
public:
XmlFlattener(BigBuffer* buffer, XmlFlattenerOptions options)
- : buffer_(buffer), options_(options) {}
+ : buffer_(buffer), options_(options) {
+ }
bool Consume(IAaptContext* context, xml::XmlResource* resource) override;
@@ -50,4 +49,4 @@
} // namespace aapt
-#endif /* AAPT_FLATTEN_XMLFLATTENER_H */
+#endif /* AAPT_FORMAT_BINARY_XMLFLATTENER_H */
diff --git a/tools/aapt2/flatten/XmlFlattener_test.cpp b/tools/aapt2/format/binary/XmlFlattener_test.cpp
similarity index 98%
rename from tools/aapt2/flatten/XmlFlattener_test.cpp
rename to tools/aapt2/format/binary/XmlFlattener_test.cpp
index a57e317..0450f6c 100644
--- a/tools/aapt2/flatten/XmlFlattener_test.cpp
+++ b/tools/aapt2/format/binary/XmlFlattener_test.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "flatten/XmlFlattener.h"
+#include "format/binary/XmlFlattener.h"
#include "androidfw/ResourceTypes.h"
@@ -55,8 +55,7 @@
.Build();
}
- ::testing::AssertionResult Flatten(xml::XmlResource* doc,
- android::ResXMLTree* out_tree,
+ ::testing::AssertionResult Flatten(xml::XmlResource* doc, android::ResXMLTree* out_tree,
const XmlFlattenerOptions& options = {}) {
using namespace android; // For NO_ERROR on windows because it is a macro.
diff --git a/tools/aapt2/proto/ProtoDeserialize.cpp b/tools/aapt2/format/proto/ProtoDeserialize.cpp
similarity index 98%
rename from tools/aapt2/proto/ProtoDeserialize.cpp
rename to tools/aapt2/format/proto/ProtoDeserialize.cpp
index dc13881..c14f09a 100644
--- a/tools/aapt2/proto/ProtoDeserialize.cpp
+++ b/tools/aapt2/format/proto/ProtoDeserialize.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "proto/ProtoDeserialize.h"
+#include "format/proto/ProtoDeserialize.h"
#include "android-base/logging.h"
#include "android-base/macros.h"
@@ -699,11 +699,11 @@
} break;
default:
- LOG(FATAL) << "unknown compound value: " << (int) pb_compound_value.value_case();
+ LOG(FATAL) << "unknown compound value: " << (int)pb_compound_value.value_case();
break;
}
} else {
- LOG(FATAL) << "unknown value: " << (int) pb_value.value_case();
+ LOG(FATAL) << "unknown value: " << (int)pb_value.value_case();
return {};
}
@@ -764,7 +764,7 @@
} break;
default:
- LOG(FATAL) << "unknown item: " << (int) pb_item.value_case();
+ LOG(FATAL) << "unknown item: " << (int)pb_item.value_case();
break;
}
return {};
@@ -840,7 +840,7 @@
} break;
default:
- LOG(FATAL) << "unknown XmlNode " << (int) pb_child.node_case();
+ LOG(FATAL) << "unknown XmlNode " << (int)pb_child.node_case();
break;
}
}
diff --git a/tools/aapt2/proto/ProtoDeserialize.h b/tools/aapt2/format/proto/ProtoDeserialize.h
similarity index 95%
rename from tools/aapt2/proto/ProtoDeserialize.h
rename to tools/aapt2/format/proto/ProtoDeserialize.h
index 3d76ea4..c8a7199 100644
--- a/tools/aapt2/proto/ProtoDeserialize.h
+++ b/tools/aapt2/format/proto/ProtoDeserialize.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef AAPT_PROTO_PROTODESERIALIZE_H
-#define AAPT_PROTO_PROTODESERIALIZE_H
+#ifndef AAPT_FORMAT_PROTO_PROTODESERIALIZE_H
+#define AAPT_FORMAT_PROTO_PROTODESERIALIZE_H
#include "android-base/macros.h"
#include "androidfw/ResourceTypes.h"
@@ -75,4 +75,4 @@
} // namespace aapt
-#endif /* AAPT_PROTO_PROTODESERIALIZE_H */
+#endif /* AAPT_FORMAT_PROTO_PROTODESERIALIZE_H */
diff --git a/tools/aapt2/proto/ProtoSerialize.cpp b/tools/aapt2/format/proto/ProtoSerialize.cpp
similarity index 99%
rename from tools/aapt2/proto/ProtoSerialize.cpp
rename to tools/aapt2/format/proto/ProtoSerialize.cpp
index d36d668..c0d3614 100644
--- a/tools/aapt2/proto/ProtoSerialize.cpp
+++ b/tools/aapt2/format/proto/ProtoSerialize.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "proto/ProtoSerialize.h"
+#include "format/proto/ProtoSerialize.h"
#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
diff --git a/tools/aapt2/proto/ProtoSerialize.h b/tools/aapt2/format/proto/ProtoSerialize.h
similarity index 95%
rename from tools/aapt2/proto/ProtoSerialize.h
rename to tools/aapt2/format/proto/ProtoSerialize.h
index 4bf7e1c..1694b16 100644
--- a/tools/aapt2/proto/ProtoSerialize.h
+++ b/tools/aapt2/format/proto/ProtoSerialize.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef AAPT_FLATTEN_TABLEPROTOSERIALIZER_H
-#define AAPT_FLATTEN_TABLEPROTOSERIALIZER_H
+#ifndef AAPT_FORMAT_PROTO_PROTOSERIALIZE_H
+#define AAPT_FORMAT_PROTO_PROTOSERIALIZE_H
#include "android-base/macros.h"
#include "google/protobuf/io/coded_stream.h"
@@ -86,4 +86,4 @@
} // namespace aapt
-#endif /* AAPT_FLATTEN_TABLEPROTOSERIALIZER_H */
+#endif /* AAPT_FORMAT_PROTO_PROTOSERIALIZE_H */
diff --git a/tools/aapt2/proto/ProtoSerialize_test.cpp b/tools/aapt2/format/proto/ProtoSerialize_test.cpp
similarity index 99%
rename from tools/aapt2/proto/ProtoSerialize_test.cpp
rename to tools/aapt2/format/proto/ProtoSerialize_test.cpp
index b263aff..2154d5a 100644
--- a/tools/aapt2/proto/ProtoSerialize_test.cpp
+++ b/tools/aapt2/format/proto/ProtoSerialize_test.cpp
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-#include "proto/ProtoSerialize.h"
+#include "format/proto/ProtoSerialize.h"
#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
#include "ResourceUtils.h"
-#include "proto/ProtoDeserialize.h"
+#include "format/proto/ProtoDeserialize.h"
#include "test/Test.h"
using ::android::StringPiece;
diff --git a/tools/aapt2/io/Util.h b/tools/aapt2/io/Util.h
index ec1ddb8..02ee876 100644
--- a/tools/aapt2/io/Util.h
+++ b/tools/aapt2/io/Util.h
@@ -21,7 +21,7 @@
#include "google/protobuf/message_lite.h"
-#include "flatten/Archive.h"
+#include "format/Archive.h"
#include "io/File.h"
#include "io/Io.h"
#include "process/IResourceTableConsumer.h"
diff --git a/tools/aapt2/optimize/MultiApkGenerator.cpp b/tools/aapt2/optimize/MultiApkGenerator.cpp
index 8e4b82c..6803088 100644
--- a/tools/aapt2/optimize/MultiApkGenerator.cpp
+++ b/tools/aapt2/optimize/MultiApkGenerator.cpp
@@ -27,8 +27,8 @@
#include "configuration/ConfigurationParser.h"
#include "filter/AbiFilter.h"
#include "filter/Filter.h"
-#include "flatten/Archive.h"
-#include "flatten/XmlFlattener.h"
+#include "format/Archive.h"
+#include "format/binary/XmlFlattener.h"
#include "optimize/VersionCollapser.h"
#include "process/IResourceTableConsumer.h"
#include "split/TableSplitter.h"
diff --git a/tools/aapt2/optimize/MultiApkGenerator_test.cpp b/tools/aapt2/optimize/MultiApkGenerator_test.cpp
index e8e6adc..c8f3524 100644
--- a/tools/aapt2/optimize/MultiApkGenerator_test.cpp
+++ b/tools/aapt2/optimize/MultiApkGenerator_test.cpp
@@ -25,8 +25,8 @@
#include "ResourceTable.h"
#include "configuration/ConfigurationParser.h"
#include "filter/Filter.h"
-#include "flatten/Archive.h"
-#include "flatten/TableFlattener.h"
+#include "format/Archive.h"
+#include "format/binary/TableFlattener.h"
#include "process/IResourceTableConsumer.h"
#include "test/Context.h"
#include "test/Test.h"
diff --git a/tools/aapt2/xml/XmlDom_test.cpp b/tools/aapt2/xml/XmlDom_test.cpp
index 6b97ae6..4ba0443 100644
--- a/tools/aapt2/xml/XmlDom_test.cpp
+++ b/tools/aapt2/xml/XmlDom_test.cpp
@@ -18,7 +18,7 @@
#include <string>
-#include "flatten/XmlFlattener.h"
+#include "format/binary/XmlFlattener.h"
#include "io/StringInputStream.h"
#include "test/Test.h"