diff options
Diffstat (limited to 'libs/androidfw/include/androidfw/LoadedArsc.h')
-rw-r--r-- | libs/androidfw/include/androidfw/LoadedArsc.h | 89 |
1 files changed, 62 insertions, 27 deletions
diff --git a/libs/androidfw/include/androidfw/LoadedArsc.h b/libs/androidfw/include/androidfw/LoadedArsc.h index f30b158084eb..965e2dbd2fb2 100644 --- a/libs/androidfw/include/androidfw/LoadedArsc.h +++ b/libs/androidfw/include/androidfw/LoadedArsc.h @@ -25,6 +25,7 @@ #include "androidfw/ByteBucketArray.h" #include "androidfw/Chunk.h" +#include "androidfw/Idmap.h" #include "androidfw/ResourceTypes.h" #include "androidfw/Util.h" @@ -40,12 +41,18 @@ class DynamicPackageEntry { int package_id = 0; }; -struct LoadedArscEntry { +struct FindEntryResult { // A pointer to the resource table entry for this resource. // If the size of the entry is > sizeof(ResTable_entry), it can be cast to // a ResTable_map_entry and processed as a bag/map. const ResTable_entry* entry = nullptr; + // The configuration for which the resulting entry was defined. + const ResTable_config* config = nullptr; + + // Stores the resulting bitmask of configuration axis with which the resource value varies. + uint32_t type_flags = 0u; + // The dynamic package ID map for the package from which this resource came from. const DynamicRefTable* dynamic_ref_table = nullptr; @@ -62,28 +69,55 @@ struct TypeSpec; class LoadedArsc; class LoadedPackage { - friend class LoadedArsc; - public: + static std::unique_ptr<const LoadedPackage> Load(const Chunk& chunk, + const LoadedIdmap* loaded_idmap, bool system, + bool load_as_shared_library); + + ~LoadedPackage(); + bool FindEntry(uint8_t type_idx, uint16_t entry_idx, const ResTable_config& config, - LoadedArscEntry* out_entry, ResTable_config* out_selected_config, - uint32_t* out_flags) const; + FindEntryResult* out_entry) const; + + // Finds the entry with the specified type name and entry name. The names are in UTF-16 because + // the underlying ResStringPool API expects this. For now this is acceptable, but since + // the default policy in AAPT2 is to build UTF-8 string pools, this needs to change. + // Returns a partial resource ID, with the package ID left as 0x00. The caller is responsible + // for patching the correct package ID to the resource ID. + uint32_t FindEntryByName(const std::u16string& type_name, const std::u16string& entry_name) const; // Returns the string pool where type names are stored. - inline const ResStringPool* GetTypeStringPool() const { return &type_string_pool_; } + inline const ResStringPool* GetTypeStringPool() const { + return &type_string_pool_; + } // Returns the string pool where the names of resource entries are stored. - inline const ResStringPool* GetKeyStringPool() const { return &key_string_pool_; } + inline const ResStringPool* GetKeyStringPool() const { + return &key_string_pool_; + } - inline const std::string& GetPackageName() const { return package_name_; } + inline const std::string& GetPackageName() const { + return package_name_; + } - inline int GetPackageId() const { return package_id_; } + inline int GetPackageId() const { + return package_id_; + } // Returns true if this package is dynamic (shared library) and needs to have an ID assigned. - inline bool IsDynamic() const { return dynamic_; } + inline bool IsDynamic() const { + return dynamic_; + } // Returns true if this package originates from a system provided resource. - inline bool IsSystem() const { return system_; } + inline bool IsSystem() const { + return system_; + } + + // Returns true if this package is from an overlay ApkAssets. + inline bool IsOverlay() const { + return overlay_; + } // 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 @@ -101,19 +135,13 @@ class LoadedPackage { // before being inserted into the set. This may cause some equivalent locales to de-dupe. void CollectLocales(bool canonicalize, std::set<std::string>* out_locales) const; - // Finds the entry with the specified type name and entry name. The names are in UTF-16 because - // the underlying ResStringPool API expects this. For now this is acceptable, but since - // the default policy in AAPT2 is to build UTF-8 string pools, this needs to change. - // Returns a partial resource ID, with the package ID left as 0x00. The caller is responsible - // for patching the correct package ID to the resource ID. - uint32_t FindEntryByName(const std::u16string& type_name, const std::u16string& entry_name) const; - private: DISALLOW_COPY_AND_ASSIGN(LoadedPackage); - static std::unique_ptr<LoadedPackage> Load(const Chunk& chunk); + LoadedPackage(); - LoadedPackage() = default; + bool FindEntry(const util::unique_cptr<TypeSpec>& type_spec_ptr, uint16_t entry_idx, + const ResTable_config& config, FindEntryResult* out_entry) const; ResStringPool type_string_pool_; ResStringPool key_string_pool_; @@ -122,6 +150,7 @@ class LoadedPackage { int type_id_offset_ = 0; bool dynamic_ = false; bool system_ = false; + bool overlay_ = false; ByteBucketArray<util::unique_cptr<TypeSpec>> type_specs_; std::vector<DynamicPackageEntry> dynamic_package_map_; @@ -137,27 +166,33 @@ class LoadedArsc { // If `load_as_shared_library` is set to true, the application package (0x7f) is treated // as a shared library (0x00). When loaded into an AssetManager, the package will be assigned an // ID. - static std::unique_ptr<const LoadedArsc> Load(const void* data, size_t len, bool system = false, + static std::unique_ptr<const LoadedArsc> Load(const StringPiece& data, + const LoadedIdmap* loaded_idmap = nullptr, + bool system = false, bool load_as_shared_library = false); - ~LoadedArsc(); + // Create an empty LoadedArsc. This is used when an APK has no resources.arsc. + static std::unique_ptr<const LoadedArsc> CreateEmpty(); // Returns the string pool where all string resource values // (Res_value::dataType == Res_value::TYPE_STRING) are indexed. - inline const ResStringPool* GetStringPool() const { return &global_string_pool_; } + inline const ResStringPool* GetStringPool() const { + return &global_string_pool_; + } // Finds the resource with ID `resid` with the best value for configuration `config`. // The parameter `out_entry` will be filled with the resulting resource entry. // The resource entry can be a simple entry (ResTable_entry) or a complex bag // (ResTable_entry_map). - bool FindEntry(uint32_t resid, const ResTable_config& config, LoadedArscEntry* out_entry, - ResTable_config* selected_config, uint32_t* out_flags) const; + bool FindEntry(uint32_t resid, const ResTable_config& config, FindEntryResult* out_entry) const; // Gets a pointer to the name of the package in `resid`, or nullptr if the package doesn't exist. const LoadedPackage* GetPackageForId(uint32_t resid) const; // Returns true if this is a system provided resource. - inline bool IsSystem() const { return system_; } + inline bool IsSystem() const { + return system_; + } // Returns a vector of LoadedPackage pointers, representing the packages in this LoadedArsc. inline const std::vector<std::unique_ptr<const LoadedPackage>>& GetPackages() const { @@ -168,7 +203,7 @@ class LoadedArsc { DISALLOW_COPY_AND_ASSIGN(LoadedArsc); LoadedArsc() = default; - bool LoadTable(const Chunk& chunk, bool load_as_shared_library); + bool LoadTable(const Chunk& chunk, const LoadedIdmap* loaded_idmap, bool load_as_shared_library); ResStringPool global_string_pool_; std::vector<std::unique_ptr<const LoadedPackage>> packages_; |