diff options
author | Ryan Mitchell <rtmitchell@google.com> | 2018-08-06 16:32:24 -0700 |
---|---|---|
committer | Ryan Mitchell <rtmitchell@google.com> | 2018-08-09 10:57:29 -0700 |
commit | 83a37adfbb3c9fc139cc7881995ddd63db4caff8 (patch) | |
tree | 706379b92d5d73409c3d2e158fc560f720d764a1 /tools/aapt2/ResourceTable.h | |
parent | deee39507f594db017f0e1beab5c973d178387a4 (diff) |
AAPT2: Loosen loading apk format requirements
The Android runtime and AAPT are more lenient of apk format, allowing
for duplicate enty, types, and configs. This change loosens the
ResourceTable's checks on resource uniqueness when apks are loaded; not
when ResourceTables are being created by aapt2.
Bug: 36051266
Test: Tested using apks in bug with allow_duplicates on and off
Change-Id: I9296417bf2dc53e1e891479a53679a0388210d50
Diffstat (limited to 'tools/aapt2/ResourceTable.h')
-rw-r--r-- | tools/aapt2/ResourceTable.h | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/tools/aapt2/ResourceTable.h b/tools/aapt2/ResourceTable.h index 8534eaaf0366..c40323c34f48 100644 --- a/tools/aapt2/ResourceTable.h +++ b/tools/aapt2/ResourceTable.h @@ -146,8 +146,9 @@ class ResourceTableType { explicit ResourceTableType(const ResourceType type) : type(type) {} - ResourceEntry* FindEntry(const android::StringPiece& name); - ResourceEntry* FindOrCreateEntry(const android::StringPiece& name); + ResourceEntry* FindEntry(const android::StringPiece& name, Maybe<uint8_t> id = Maybe<uint8_t>()); + ResourceEntry* FindOrCreateEntry(const android::StringPiece& name, + Maybe<uint8_t> id = Maybe<uint8_t>()); private: DISALLOW_COPY_AND_ASSIGN(ResourceTableType); @@ -163,8 +164,9 @@ class ResourceTablePackage { std::vector<std::unique_ptr<ResourceTableType>> types; ResourceTablePackage() = default; - ResourceTableType* FindType(ResourceType type); - ResourceTableType* FindOrCreateType(const ResourceType type); + ResourceTableType* FindType(ResourceType type, Maybe<uint8_t> id = Maybe<uint8_t>()); + ResourceTableType* FindOrCreateType(const ResourceType type, + Maybe<uint8_t> id = Maybe<uint8_t>()); private: DISALLOW_COPY_AND_ASSIGN(ResourceTablePackage); @@ -174,14 +176,18 @@ class ResourceTablePackage { class ResourceTable { public: ResourceTable() = default; + explicit ResourceTable(bool validate_resources) : validate_resources_(validate_resources) {} - enum class CollisionResult { kKeepOriginal, kConflict, kTakeNew }; + enum class CollisionResult { kKeepBoth, kKeepOriginal, kConflict, kTakeNew }; using CollisionResolverFunc = std::function<CollisionResult(Value*, Value*)>; // When a collision of resources occurs, this method decides which value to keep. static CollisionResult ResolveValueCollision(Value* existing, Value* incoming); + // When a collision of resources occurs, this method keeps both values + static CollisionResult IgnoreCollision(Value* existing, Value* incoming); + bool AddResource(const ResourceNameRef& name, const ConfigDescription& config, const android::StringPiece& product, std::unique_ptr<Value> value, IDiagnostics* diag); @@ -208,6 +214,8 @@ class ResourceTable { const android::StringPiece& product, std::unique_ptr<Value> value, IDiagnostics* diag); + bool GetValidateResources(); + bool SetVisibility(const ResourceNameRef& name, const Visibility& visibility, IDiagnostics* diag); bool SetVisibilityMangled(const ResourceNameRef& name, const Visibility& visibility, IDiagnostics* diag); @@ -299,6 +307,9 @@ class ResourceTable { const Visibility& symbol, NameValidator name_validator, IDiagnostics* diag); + // Controls whether the table validates resource names and prevents duplicate resource names + bool validate_resources_ = true; + DISALLOW_COPY_AND_ASSIGN(ResourceTable); }; |