| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef AAPT_LOADEDAPK_H |
| 18 |
#define AAPT_LOADEDAPK_H |
| 19 |
|
| 20 |
#include "androidfw/StringPiece.h" |
| 21 |
|
| 22 |
#include "ResourceTable.h" |
| 23 |
#include "filter/Filter.h" |
| 24 |
#include "format/Archive.h" |
| 25 |
#include "format/binary/BinaryResourceParser.h" |
| 26 |
#include "format/binary/TableFlattener.h" |
| 27 |
#include "io/ZipArchive.h" |
| 28 |
#include "xml/XmlDom.h" |
| 29 |
|
| 30 |
namespace aapt { |
| 31 |
|
| 32 |
constexpr static const char kApkResourceTablePath[] = "resources.arsc"; |
| 33 |
constexpr static const char kProtoResourceTablePath[] = "resources.pb"; |
| 34 |
constexpr static const char kAndroidManifestPath[] = "AndroidManifest.xml"; |
| 35 |
|
| 36 |
enum ApkFormat { |
| 37 |
kUnknown, |
| 38 |
kBinary, |
| 39 |
kProto, |
| 40 |
}; |
| 41 |
|
| 42 |
|
| 43 |
class LoadedApk { |
| 44 |
public: |
| 45 |
virtual ~LoadedApk() = default; |
| 46 |
|
| 47 |
|
| 48 |
static std::unique_ptr<LoadedApk> LoadApkFromPath(const ::android::StringPiece& path, |
| 49 |
IDiagnostics* diag); |
| 50 |
|
| 51 |
|
| 52 |
static std::unique_ptr<LoadedApk> LoadProtoApkFromFileCollection( |
| 53 |
const Source& source, std::unique_ptr<io::IFileCollection> collection, IDiagnostics* diag); |
| 54 |
|
| 55 |
|
| 56 |
static std::unique_ptr<LoadedApk> LoadBinaryApkFromFileCollection( |
| 57 |
const Source& source, std::unique_ptr<io::IFileCollection> collection, IDiagnostics* diag); |
| 58 |
|
| 59 |
LoadedApk(const Source& source, std::unique_ptr<io::IFileCollection> apk, |
| 60 |
std::unique_ptr<ResourceTable> table, std::unique_ptr<xml::XmlResource> manifest, |
| 61 |
const ApkFormat& format) |
| 62 |
: source_(source), |
| 63 |
apk_(std::move(apk)), |
| 64 |
table_(std::move(table)), |
| 65 |
manifest_(std::move(manifest)), |
| 66 |
format_(format) { |
| 67 |
} |
| 68 |
|
| 69 |
io::IFileCollection* GetFileCollection() { |
| 70 |
return apk_.get(); |
| 71 |
} |
| 72 |
|
| 73 |
ApkFormat GetApkFormat() { |
| 74 |
return format_; |
| 75 |
} |
| 76 |
|
| 77 |
const ResourceTable* GetResourceTable() const { |
| 78 |
return table_.get(); |
| 79 |
} |
| 80 |
|
| 81 |
ResourceTable* GetResourceTable() { |
| 82 |
return table_.get(); |
| 83 |
} |
| 84 |
|
| 85 |
const Source& GetSource() { |
| 86 |
return source_; |
| 87 |
} |
| 88 |
|
| 89 |
const xml::XmlResource* GetManifest() const { |
| 90 |
return manifest_.get(); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
virtual bool WriteToArchive(IAaptContext* context, const TableFlattenerOptions& options, |
| 98 |
IArchiveWriter* writer); |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
virtual bool WriteToArchive(IAaptContext* context, ResourceTable* split_table, |
| 110 |
const TableFlattenerOptions& options, FilterChain* filters, |
| 111 |
IArchiveWriter* writer, xml::XmlResource* manifest = nullptr); |
| 112 |
|
| 113 |
|
| 114 |
std::unique_ptr<xml::XmlResource> LoadXml(const std::string& file_path, IDiagnostics* diag) const; |
| 115 |
|
| 116 |
private: |
| 117 |
DISALLOW_COPY_AND_ASSIGN(LoadedApk); |
| 118 |
|
| 119 |
Source source_; |
| 120 |
std::unique_ptr<io::IFileCollection> apk_; |
| 121 |
std::unique_ptr<ResourceTable> table_; |
| 122 |
std::unique_ptr<xml::XmlResource> manifest_; |
| 123 |
ApkFormat format_; |
| 124 |
}; |
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
#endif |