summaryrefslogtreecommitdiff
path: root/tools/aapt2/LoadedApk.cpp
diff options
context:
space:
mode:
authorTom Dobek <tdobek@google.com>2017-12-08 14:19:01 +0000
committerTom Dobek <tdobek@google.com>2017-12-11 10:30:12 +0000
commit725fb12c0d271c179c4f3689ee56296253f3cb62 (patch)
treea69b7e539b47cee4583e63cb970bd3e6c96d5915 /tools/aapt2/LoadedApk.cpp
parent3a1e51ab804d27ab8a486e17af7f3ea0e6d8fb43 (diff)
Aapt2 convert: skip processing resources when resource table is absent.
Test: manual Change-Id: Iafe20f98857a29d625e7a57a9201db6279d43e45
Diffstat (limited to 'tools/aapt2/LoadedApk.cpp')
-rw-r--r--tools/aapt2/LoadedApk.cpp75
1 files changed, 36 insertions, 39 deletions
diff --git a/tools/aapt2/LoadedApk.cpp b/tools/aapt2/LoadedApk.cpp
index 33b5a8b2686d..20a9f417228c 100644
--- a/tools/aapt2/LoadedApk.cpp
+++ b/tools/aapt2/LoadedApk.cpp
@@ -57,31 +57,30 @@ std::unique_ptr<LoadedApk> LoadedApk::LoadApkFromPath(const StringPiece& path, I
std::unique_ptr<LoadedApk> LoadedApk::LoadProtoApkFromFileCollection(
const Source& source, unique_ptr<io::IFileCollection> collection, IDiagnostics* diag) {
- io::IFile* table_file = collection->FindFile(kProtoResourceTablePath);
- if (table_file == nullptr) {
- diag->Error(DiagMessage(source) << "failed to find " << kProtoResourceTablePath);
- return {};
- }
+ std::unique_ptr<ResourceTable> table;
- std::unique_ptr<io::InputStream> in = table_file->OpenInputStream();
- if (in == nullptr) {
- diag->Error(DiagMessage(source) << "failed to open " << kProtoResourceTablePath);
- return {};
- }
+ io::IFile* table_file = collection->FindFile(kProtoResourceTablePath);
+ if (table_file != nullptr) {
+ pb::ResourceTable pb_table;
+ std::unique_ptr<io::InputStream> in = table_file->OpenInputStream();
+ if (in == nullptr) {
+ diag->Error(DiagMessage(source) << "failed to open " << kProtoResourceTablePath);
+ return {};
+ }
- pb::ResourceTable pb_table;
- io::ZeroCopyInputAdaptor adaptor(in.get());
- if (!pb_table.ParseFromZeroCopyStream(&adaptor)) {
- diag->Error(DiagMessage(source) << "failed to read " << kProtoResourceTablePath);
- return {};
- }
+ io::ZeroCopyInputAdaptor adaptor(in.get());
+ if (!pb_table.ParseFromZeroCopyStream(&adaptor)) {
+ diag->Error(DiagMessage(source) << "failed to read " << kProtoResourceTablePath);
+ return {};
+ }
- std::string error;
- std::unique_ptr<ResourceTable> table = util::make_unique<ResourceTable>();
- if (!DeserializeTableFromPb(pb_table, collection.get(), table.get(), &error)) {
- diag->Error(DiagMessage(source)
- << "failed to deserialize " << kProtoResourceTablePath << ": " << error);
- return {};
+ std::string error;
+ table = util::make_unique<ResourceTable>();
+ if (!DeserializeTableFromPb(pb_table, collection.get(), table.get(), &error)) {
+ diag->Error(DiagMessage(source)
+ << "failed to deserialize " << kProtoResourceTablePath << ": " << error);
+ return {};
+ }
}
io::IFile* manifest_file = collection->FindFile(kAndroidManifestPath);
@@ -103,6 +102,7 @@ std::unique_ptr<LoadedApk> LoadedApk::LoadProtoApkFromFileCollection(
return {};
}
+ std::string error;
std::unique_ptr<xml::XmlResource> manifest = DeserializeXmlResourceFromPb(pb_node, &error);
if (manifest == nullptr) {
diag->Error(DiagMessage(source)
@@ -115,24 +115,21 @@ std::unique_ptr<LoadedApk> LoadedApk::LoadProtoApkFromFileCollection(
std::unique_ptr<LoadedApk> LoadedApk::LoadBinaryApkFromFileCollection(
const Source& source, unique_ptr<io::IFileCollection> collection, IDiagnostics* diag) {
- io::IFile* table_file = collection->FindFile(kApkResourceTablePath);
- if (table_file == nullptr) {
- diag->Error(DiagMessage(source) << "failed to find " << kApkResourceTablePath);
-
- return {};
- }
+ std::unique_ptr<ResourceTable> table;
- std::unique_ptr<io::IData> data = table_file->OpenAsData();
- if (data == nullptr) {
- diag->Error(DiagMessage(source) << "failed to open " << kApkResourceTablePath);
- return {};
- }
-
- std::unique_ptr<ResourceTable> table = util::make_unique<ResourceTable>();
- BinaryResourceParser parser(diag, table.get(), source, data->data(), data->size(),
- collection.get());
- if (!parser.Parse()) {
- return {};
+ io::IFile* table_file = collection->FindFile(kApkResourceTablePath);
+ if (table_file != nullptr) {
+ table = util::make_unique<ResourceTable>();
+ std::unique_ptr<io::IData> data = table_file->OpenAsData();
+ if (data == nullptr) {
+ diag->Error(DiagMessage(source) << "failed to open " << kApkResourceTablePath);
+ return {};
+ }
+ BinaryResourceParser parser(diag, table.get(), source, data->data(), data->size(),
+ collection.get());
+ if (!parser.Parse()) {
+ return {};
+ }
}
io::IFile* manifest_file = collection->FindFile(kAndroidManifestPath);