diff options
Diffstat (limited to 'tools/aapt2/LoadedApk.h')
-rw-r--r-- | tools/aapt2/LoadedApk.h | 91 |
1 files changed, 69 insertions, 22 deletions
diff --git a/tools/aapt2/LoadedApk.h b/tools/aapt2/LoadedApk.h index 8aa9674aa2ed..81bcecc3ca5d 100644 --- a/tools/aapt2/LoadedApk.h +++ b/tools/aapt2/LoadedApk.h @@ -21,52 +21,99 @@ #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. */ +constexpr static const char kApkResourceTablePath[] = "resources.arsc"; +constexpr static const char kProtoResourceTablePath[] = "resources.pb"; +constexpr static const char kAndroidManifestPath[] = "AndroidManifest.xml"; + +enum ApkFormat { + kUnknown, + kBinary, + kProto, +}; + +// 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(); } + io::IFileCollection* GetFileCollection() { + return apk_.get(); + } - ResourceTable* GetResourceTable() { return table_.get(); } + const ResourceTable* GetResourceTable() const { + return table_.get(); + } - const Source& GetSource() { return source_; } + ResourceTable* GetResourceTable() { + return table_.get(); + } + + const Source& GetSource() { + 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. */ - bool WriteToArchive(IAaptContext* context, const TableFlattenerOptions& options, - IArchiveWriter* writer); + virtual bool WriteToArchive(IAaptContext* context, const TableFlattenerOptions& options, + IArchiveWriter* writer); /** - * Writes the APK on disk at the given path, while also removing the resource - * files that are not referenced in the resource table. The provided filter - * chain is applied to each entry in the APK file. + * Writes the APK on disk at the given path, while also removing the resource files that are not + * referenced in the resource table. The provided filter chain is applied to each entry in the APK + * file. + * + * If the manifest is also provided, it will be written to the new APK file, otherwise the + * original manifest will be written. The manifest is only required if the contents of the new APK + * have been modified in a way that require the AndroidManifest.xml to also be modified. */ - bool WriteToArchive(IAaptContext* context, const TableFlattenerOptions& options, - FilterChain* filters, IArchiveWriter* writer); + virtual bool WriteToArchive(IAaptContext* context, ResourceTable* split_table, + const TableFlattenerOptions& options, FilterChain* filters, + IArchiveWriter* writer, xml::XmlResource* manifest = nullptr); - static std::unique_ptr<LoadedApk> LoadApkFromPath(IAaptContext* context, - const android::StringPiece& path); private: + DISALLOW_COPY_AND_ASSIGN(LoadedApk); + Source source_; std::unique_ptr<io::IFileCollection> apk_; std::unique_ptr<ResourceTable> table_; + std::unique_ptr<xml::XmlResource> manifest_; - DISALLOW_COPY_AND_ASSIGN(LoadedApk); + static ApkFormat DetermineApkFormat(io::IFileCollection* apk); }; } // namespace aapt |