diff options
author | Adam Lesinski <adamlesinski@google.com> | 2017-10-31 17:44:39 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2017-11-01 10:58:28 -0700 |
commit | 8780eb6e4918ae24fb1ae74d631042c32e41dc3d (patch) | |
tree | 938e18951a562fcd043ac779c7e758444b4bf0a8 /tools/aapt2/LoadedApk.h | |
parent | 4f340a4f8b50b29b562407e39563ee78a90bea3f (diff) |
AAPT2: Add convert command
This command allows a developer to convert their proto APK
(generated from the link phase using --proto-format) into
a binary APK suitable for use on device.
aapt2 convert -o output.apk input.apk
Test: manual + make aapt2_tests
Change-Id: I10a7c33bb4b57006d01fe00a8bf92f78e04e7e50
Diffstat (limited to 'tools/aapt2/LoadedApk.h')
-rw-r--r-- | tools/aapt2/LoadedApk.h | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/tools/aapt2/LoadedApk.h b/tools/aapt2/LoadedApk.h index d2dd5cf2bc67..ef97de301ad5 100644 --- a/tools/aapt2/LoadedApk.h +++ b/tools/aapt2/LoadedApk.h @@ -29,20 +29,41 @@ namespace aapt { +constexpr static const char kApkResourceTablePath[] = "resources.arsc"; +constexpr static const char kProtoResourceTablePath[] = "resources.pb"; +constexpr static const char kAndroidManifestPath[] = "AndroidManifest.xml"; + // 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)) {} - virtual ~LoadedApk() = default; + // Loads both binary and proto APKs from disk. + static std::unique_ptr<LoadedApk> LoadApkFromPath(const ::android::StringPiece& path, + IDiagnostics* diag); + + // Loads a proto APK from the given file collection. + static std::unique_ptr<LoadedApk> LoadProtoApkFromFileCollection( + const Source& source, std::unique_ptr<io::IFileCollection> collection, IDiagnostics* diag); + + // Loads a binary APK from the given file collection. + static std::unique_ptr<LoadedApk> LoadBinaryApkFromFileCollection( + const Source& source, std::unique_ptr<io::IFileCollection> collection, IDiagnostics* diag); + + LoadedApk(const Source& source, std::unique_ptr<io::IFileCollection> apk, + std::unique_ptr<ResourceTable> table, std::unique_ptr<xml::XmlResource> manifest) + : source_(source), + apk_(std::move(apk)), + table_(std::move(table)), + manifest_(std::move(manifest)) { + } io::IFileCollection* GetFileCollection() { return apk_.get(); } + const ResourceTable* GetResourceTable() const { + return table_.get(); + } + ResourceTable* GetResourceTable() { return table_.get(); } @@ -51,6 +72,10 @@ class LoadedApk { return source_; } + const xml::XmlResource* GetManifest() const { + return manifest_.get(); + } + /** * Writes the APK on disk at the given path, while also removing the resource * files that are not referenced in the resource table. @@ -71,11 +96,6 @@ class LoadedApk { const TableFlattenerOptions& options, FilterChain* filters, IArchiveWriter* writer, xml::XmlResource* manifest = nullptr); - /** Inflates the AndroidManifest.xml file from the APK. */ - std::unique_ptr<xml::XmlResource> InflateManifest(IAaptContext* context); - - static std::unique_ptr<LoadedApk> LoadApkFromPath(IAaptContext* context, - const android::StringPiece& path); private: DISALLOW_COPY_AND_ASSIGN(LoadedApk); @@ -83,6 +103,7 @@ class LoadedApk { Source source_; std::unique_ptr<io::IFileCollection> apk_; std::unique_ptr<ResourceTable> table_; + std::unique_ptr<xml::XmlResource> manifest_; }; } // namespace aapt |