summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceTable.h
diff options
context:
space:
mode:
Diffstat (limited to 'tools/aapt2/ResourceTable.h')
-rw-r--r--tools/aapt2/ResourceTable.h52
1 files changed, 42 insertions, 10 deletions
diff --git a/tools/aapt2/ResourceTable.h b/tools/aapt2/ResourceTable.h
index 7b19a3188a76..3dd0a769d944 100644
--- a/tools/aapt2/ResourceTable.h
+++ b/tools/aapt2/ResourceTable.h
@@ -57,8 +57,27 @@ struct AllowNew {
std::string comment;
};
-// The policy dictating whether an entry is overlayable at runtime by RROs.
+// Represents a declaration that a resource is overayable at runtime.
struct Overlayable {
+ // Represents the types overlays that are allowed to overlay the resource.
+ enum class Policy {
+ // The resource can be overlaid by any overlay.
+ kPublic,
+
+ // The resource can be overlaid by any overlay on the system partition.
+ kSystem,
+
+ // The resource can be overlaid by any overlay on the vendor partition.
+ kVendor,
+
+ // The resource can be overlaid by any overlay on the product partition.
+ kProduct,
+
+ // The resource can be overlaid by any overlay on the product services partition.
+ kProductServices,
+ };
+
+ Maybe<Policy> policy;
Source source;
std::string comment;
};
@@ -96,7 +115,8 @@ class ResourceEntry {
Maybe<AllowNew> allow_new;
- Maybe<Overlayable> overlayable;
+ // The declarations of this resource as overlayable for RROs
+ std::vector<Overlayable> overlayable_declarations;
// The resource's values for each configuration.
std::vector<std::unique_ptr<ResourceConfigValue>> values;
@@ -146,8 +166,10 @@ 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<uint16_t> id = Maybe<uint16_t>());
+ ResourceEntry* FindOrCreateEntry(const android::StringPiece& name,
+ Maybe<uint16_t> id = Maybe<uint16_t>());
private:
DISALLOW_COPY_AND_ASSIGN(ResourceTableType);
@@ -163,8 +185,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 +197,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 android::ConfigDescription& config,
const android::StringPiece& product, std::unique_ptr<Value> value,
IDiagnostics* diag);
@@ -209,6 +236,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);
@@ -217,9 +246,9 @@ class ResourceTable {
bool SetVisibilityWithIdMangled(const ResourceNameRef& name, const Visibility& visibility,
const ResourceId& res_id, IDiagnostics* diag);
- bool SetOverlayable(const ResourceNameRef& name, const Overlayable& overlayable,
+ bool AddOverlayable(const ResourceNameRef& name, const Overlayable& overlayable,
IDiagnostics* diag);
- bool SetOverlayableMangled(const ResourceNameRef& name, const Overlayable& overlayable,
+ bool AddOverlayableMangled(const ResourceNameRef& name, const Overlayable& overlayable,
IDiagnostics* diag);
bool SetAllowNew(const ResourceNameRef& name, const AllowNew& allow_new, IDiagnostics* diag);
@@ -294,13 +323,16 @@ class ResourceTable {
bool SetAllowNewImpl(const ResourceNameRef& name, const AllowNew& allow_new,
NameValidator name_validator, IDiagnostics* diag);
- bool SetOverlayableImpl(const ResourceNameRef& name, const Overlayable& overlayable,
+ bool AddOverlayableImpl(const ResourceNameRef& name, const Overlayable& overlayable,
NameValidator name_validator, IDiagnostics* diag);
bool SetSymbolStateImpl(const ResourceNameRef& name, const ResourceId& res_id,
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);
};