diff options
author | Winson Chiu <chiuwinson@google.com> | 2019-10-11 18:05:00 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-10-11 18:05:00 +0000 |
commit | 8e4f087cc11f72424c304192291ef35c6f24c179 (patch) | |
tree | 12e3973812a95a93a5b2b517e986705b8014af48 /libs/androidfw/include | |
parent | 535bd634c8b6b93413048f7f0ea435f6fe3cfa60 (diff) | |
parent | 9947f1e4fa6b1e58ca38bfe0ed440a8ab4f66465 (diff) |
Merge "Add ResourceLoader API with .apk and .arsc support"
Diffstat (limited to 'libs/androidfw/include')
-rw-r--r-- | libs/androidfw/include/androidfw/ApkAssets.h | 38 | ||||
-rw-r--r-- | libs/androidfw/include/androidfw/Asset.h | 5 | ||||
-rw-r--r-- | libs/androidfw/include/androidfw/AssetManager2.h | 8 | ||||
-rw-r--r-- | libs/androidfw/include/androidfw/LoadedArsc.h | 26 |
4 files changed, 66 insertions, 11 deletions
diff --git a/libs/androidfw/include/androidfw/ApkAssets.h b/libs/androidfw/include/androidfw/ApkAssets.h index 49fc82bff11e..625b68207d83 100644 --- a/libs/androidfw/include/androidfw/ApkAssets.h +++ b/libs/androidfw/include/androidfw/ApkAssets.h @@ -40,7 +40,8 @@ class ApkAssets { // Creates an ApkAssets. // If `system` is true, the package is marked as a system package, and allows some functions to // filter out this package when computing what configurations/resources are available. - static std::unique_ptr<const ApkAssets> Load(const std::string& path, bool system = false); + static std::unique_ptr<const ApkAssets> Load(const std::string& path, bool system = false, + bool for_loader = false); // Creates an ApkAssets, but forces any package with ID 0x7f to be loaded as a shared library. // If `system` is true, the package is marked as a system package, and allows some functions to @@ -63,7 +64,21 @@ class ApkAssets { // If `force_shared_lib` is true, any package with ID 0x7f is loaded as a shared library. static std::unique_ptr<const ApkAssets> LoadFromFd(base::unique_fd fd, const std::string& friendly_name, bool system, - bool force_shared_lib); + bool force_shared_lib, + bool for_loader = false); + + // Creates an empty wrapper ApkAssets from the given path which points to an .arsc. + static std::unique_ptr<const ApkAssets> LoadArsc(const std::string& path, + bool for_loader = false); + + // Creates an empty wrapper ApkAssets from the given file descriptor which points to an .arsc, + // Takes ownership of the file descriptor. + static std::unique_ptr<const ApkAssets> LoadArsc(base::unique_fd fd, + const std::string& friendly_name, + bool resource_loader = false); + + // Creates a totally empty ApkAssets with no resources table and no file entries. + static std::unique_ptr<const ApkAssets> LoadEmpty(bool resource_loader = false); std::unique_ptr<Asset> Open(const std::string& path, Asset::AccessMode mode = Asset::AccessMode::ACCESS_RANDOM) const; @@ -86,24 +101,33 @@ class ApkAssets { bool IsUpToDate() const; + // Creates an Asset from any file on the file system. + static std::unique_ptr<Asset> CreateAssetFromFile(const std::string& path); + private: DISALLOW_COPY_AND_ASSIGN(ApkAssets); static std::unique_ptr<const ApkAssets> LoadImpl(base::unique_fd fd, const std::string& path, std::unique_ptr<Asset> idmap_asset, std::unique_ptr<const LoadedIdmap> loaded_idmap, - bool system, bool load_as_shared_library); + bool system, bool load_as_shared_library, + bool resource_loader = false); - // Creates an Asset from any file on the file system. - static std::unique_ptr<Asset> CreateAssetFromFile(const std::string& path); + static std::unique_ptr<const ApkAssets> LoadArscImpl(base::unique_fd fd, + const std::string& path, + bool resource_loader = false); - ApkAssets(ZipArchiveHandle unmanaged_handle, const std::string& path, time_t last_mod_time); + ApkAssets(ZipArchiveHandle unmanaged_handle, + const std::string& path, + time_t last_mod_time, + bool for_loader = false); - using ZipArchivePtr = std::unique_ptr<ZipArchive, void(*)(ZipArchiveHandle)>; + using ZipArchivePtr = std::unique_ptr<ZipArchive, void (*)(ZipArchiveHandle)>; ZipArchivePtr zip_handle_; const std::string path_; time_t last_mod_time_; + bool for_loader; std::unique_ptr<Asset> resources_asset_; std::unique_ptr<Asset> idmap_asset_; std::unique_ptr<const LoadedArsc> loaded_arsc_; diff --git a/libs/androidfw/include/androidfw/Asset.h b/libs/androidfw/include/androidfw/Asset.h index 9d12a35395c9..053dbb7864c6 100644 --- a/libs/androidfw/include/androidfw/Asset.h +++ b/libs/androidfw/include/androidfw/Asset.h @@ -121,6 +121,11 @@ public: */ const char* getAssetSource(void) const { return mAssetSource.string(); } + /* + * Create the asset from a file descriptor. + */ + static Asset* createFromFd(const int fd, const char* fileName, AccessMode mode); + protected: /* * Adds this Asset to the global Asset list for debugging and diff --git a/libs/androidfw/include/androidfw/AssetManager2.h b/libs/androidfw/include/androidfw/AssetManager2.h index de46081a6aa3..c7348b180648 100644 --- a/libs/androidfw/include/androidfw/AssetManager2.h +++ b/libs/androidfw/include/androidfw/AssetManager2.h @@ -382,7 +382,13 @@ class AssetManager2 { enum class Type { INITIAL, BETTER_MATCH, - OVERLAID + BETTER_MATCH_LOADER, + OVERLAID, + OVERLAID_LOADER, + SKIPPED, + SKIPPED_LOADER, + NO_ENTRY, + NO_ENTRY_LOADER, }; // Marks what kind of override this step was. diff --git a/libs/androidfw/include/androidfw/LoadedArsc.h b/libs/androidfw/include/androidfw/LoadedArsc.h index 950f5413f550..1a56876b9686 100644 --- a/libs/androidfw/include/androidfw/LoadedArsc.h +++ b/libs/androidfw/include/androidfw/LoadedArsc.h @@ -137,7 +137,8 @@ class LoadedPackage { static std::unique_ptr<const LoadedPackage> Load(const Chunk& chunk, const LoadedIdmap* loaded_idmap, bool system, - bool load_as_shared_library); + bool load_as_shared_library, + bool load_as_custom_loader); ~LoadedPackage(); @@ -187,6 +188,11 @@ class LoadedPackage { return overlay_; } + // Returns true if this package is a custom loader and should behave like an overlay + inline bool IsCustomLoader() const { + return custom_loader_; + } + // Returns the map of package name to package ID used in this LoadedPackage. At runtime, a // package could have been assigned a different package ID than what this LoadedPackage was // compiled with. AssetManager rewrites the package IDs so that they are compatible at runtime. @@ -260,6 +266,7 @@ class LoadedPackage { bool dynamic_ = false; bool system_ = false; bool overlay_ = false; + bool custom_loader_ = false; bool defines_overlayable_ = false; ByteBucketArray<TypeSpecPtr> type_specs_; @@ -282,7 +289,8 @@ class LoadedArsc { static std::unique_ptr<const LoadedArsc> Load(const StringPiece& data, const LoadedIdmap* loaded_idmap = nullptr, bool system = false, - bool load_as_shared_library = false); + bool load_as_shared_library = false, + bool for_loader = false); // Create an empty LoadedArsc. This is used when an APK has no resources.arsc. static std::unique_ptr<const LoadedArsc> CreateEmpty(); @@ -311,7 +319,19 @@ class LoadedArsc { DISALLOW_COPY_AND_ASSIGN(LoadedArsc); LoadedArsc() = default; - bool LoadTable(const Chunk& chunk, const LoadedIdmap* loaded_idmap, bool load_as_shared_library); + bool LoadTable( + const Chunk& chunk, + const LoadedIdmap* loaded_idmap, + bool load_as_shared_library, + bool for_loader + ); + + static std::unique_ptr<const LoadedArsc> LoadData(std::unique_ptr<LoadedArsc>& loaded_arsc, + const char* data, + size_t length, + const LoadedIdmap* loaded_idmap = nullptr, + bool load_as_shared_library = false, + bool for_loader = false); ResStringPool global_string_pool_; std::vector<std::unique_ptr<const LoadedPackage>> packages_; |