summaryrefslogtreecommitdiff
path: root/tools/aapt2/LoadedApk.cpp
diff options
context:
space:
mode:
authorRyan Mitchell <rtmitchell@google.com>2018-10-17 09:30:01 -0700
committerRyan Mitchell <rtmitchell@google.com>2018-10-17 09:30:01 -0700
commitec74f2fbd56a5021ab7c74bd7e65c165e287ad7f (patch)
tree02a209b2729d37ee6d2453f543b9d84ad80a7b11 /tools/aapt2/LoadedApk.cpp
parentbbcfda0d35e83b95b2acc742c36ced3f92700ce9 (diff)
Fix incorrect proto apk loading
If a proto apk is missing resources.pb, AAPT2 would fail to detrmine the apk format because of an incorrect check. This fixes that check and removes the checking fuction from the LoadedApk header. Bug: 117820549 Test: removed resources.pb from proto apks and confirmed that loading in apks still works Change-Id: If3628a821e7b59c7dfcbefb502b6080be083cec1
Diffstat (limited to 'tools/aapt2/LoadedApk.cpp')
-rw-r--r--tools/aapt2/LoadedApk.cpp74
1 files changed, 37 insertions, 37 deletions
diff --git a/tools/aapt2/LoadedApk.cpp b/tools/aapt2/LoadedApk.cpp
index a20b9b76a703..b353ff00a23f 100644
--- a/tools/aapt2/LoadedApk.cpp
+++ b/tools/aapt2/LoadedApk.cpp
@@ -35,6 +35,43 @@ using ::std::unique_ptr;
namespace aapt {
+static ApkFormat DetermineApkFormat(io::IFileCollection* apk) {
+ if (apk->FindFile(kApkResourceTablePath) != nullptr) {
+ return ApkFormat::kBinary;
+ } else if (apk->FindFile(kProtoResourceTablePath) != nullptr) {
+ return ApkFormat::kProto;
+ } else {
+ // If the resource table is not present, attempt to read the manifest.
+ io::IFile* manifest_file = apk->FindFile(kAndroidManifestPath);
+ if (manifest_file == nullptr) {
+ return ApkFormat::kUnknown;
+ }
+
+ // First try in proto format.
+ std::unique_ptr<io::InputStream> manifest_in = manifest_file->OpenInputStream();
+ if (manifest_in != nullptr) {
+ pb::XmlNode pb_node;
+ io::ProtoInputStreamReader proto_reader(manifest_in.get());
+ if (proto_reader.ReadMessage(&pb_node)) {
+ return ApkFormat::kProto;
+ }
+ }
+
+ // If it didn't work, try in binary format.
+ std::unique_ptr<io::IData> manifest_data = manifest_file->OpenAsData();
+ if (manifest_data != nullptr) {
+ std::string error;
+ std::unique_ptr<xml::XmlResource> manifest =
+ xml::Inflate(manifest_data->data(), manifest_data->size(), &error);
+ if (manifest != nullptr) {
+ return ApkFormat::kBinary;
+ }
+ }
+
+ return ApkFormat::kUnknown;
+ }
+}
+
std::unique_ptr<LoadedApk> LoadedApk::LoadApkFromPath(const StringPiece& path, IDiagnostics* diag) {
Source source(path);
std::string error;
@@ -301,41 +338,4 @@ std::unique_ptr<xml::XmlResource> LoadedApk::LoadXml(const std::string& file_pat
return doc;
}
-ApkFormat LoadedApk::DetermineApkFormat(io::IFileCollection* apk) {
- if (apk->FindFile(kApkResourceTablePath) != nullptr) {
- return ApkFormat::kBinary;
- } else if (apk->FindFile(kProtoResourceTablePath) != nullptr) {
- return ApkFormat::kProto;
- } else {
- // If the resource table is not present, attempt to read the manifest.
- io::IFile* manifest_file = apk->FindFile(kAndroidManifestPath);
- if (manifest_file == nullptr) {
- return ApkFormat::kUnknown;
- }
-
- // First try in proto format.
- std::unique_ptr<io::InputStream> manifest_in = manifest_file->OpenInputStream();
- if (manifest_in != nullptr) {
- pb::XmlNode pb_node;
- io::ProtoInputStreamReader proto_reader(manifest_in.get());
- if (!proto_reader.ReadMessage(&pb_node)) {
- return ApkFormat::kProto;
- }
- }
-
- // If it didn't work, try in binary format.
- std::unique_ptr<io::IData> manifest_data = manifest_file->OpenAsData();
- if (manifest_data != nullptr) {
- std::string error;
- std::unique_ptr<xml::XmlResource> manifest =
- xml::Inflate(manifest_data->data(), manifest_data->size(), &error);
- if (manifest != nullptr) {
- return ApkFormat::kBinary;
- }
- }
-
- return ApkFormat::kUnknown;
- }
-}
-
} // namespace aapt