AAPT2: Implement attribute compat versioning
This change defines some hardcoded rules to degrade
attributes in newer SDKs to specific older attributes.
An attribute with a degrade rule will generate a new XML for the API
in which the attribute resulting from the degradation was introduced.
Since API 22 (Lollipop MR1), attributes are correctly ignored and do
not need to be versioned. In XML files defined for APIs 22+, the
original and degraded attributes coexist in the same XML file.
One such example is paddingHorizontal, introduced in API 26.
paddingHorizontal degrades to paddingLeft and paddingRight, which
were both introduced in API 1.
Bug: 35763493
Test: make aapt2_tests
Change-Id: I4aa8755a9ee2c0cc5afdc55c3d30093fd3a47f3d
diff --git a/tools/aapt2/process/SymbolTable.cpp b/tools/aapt2/process/SymbolTable.cpp
index 1a648bf..882a85b 100644
--- a/tools/aapt2/process/SymbolTable.cpp
+++ b/tools/aapt2/process/SymbolTable.cpp
@@ -237,14 +237,12 @@
}
// We found a resource.
- std::unique_ptr<SymbolTable::Symbol> s = util::make_unique<SymbolTable::Symbol>();
- s->id = id;
+ std::unique_ptr<SymbolTable::Symbol> s = util::make_unique<SymbolTable::Symbol>(id);
// Check to see if it is an attribute.
for (size_t i = 0; i < (size_t)count; i++) {
if (entry[i].map.name.ident == android::ResTable_map::ATTR_TYPE) {
- s->attribute = std::make_shared<Attribute>(false);
- s->attribute->type_mask = entry[i].map.value.data;
+ s->attribute = std::make_shared<Attribute>(false, entry[i].map.value.data);
break;
}
}
diff --git a/tools/aapt2/process/SymbolTable.h b/tools/aapt2/process/SymbolTable.h
index bd252d2..4a2181e 100644
--- a/tools/aapt2/process/SymbolTable.h
+++ b/tools/aapt2/process/SymbolTable.h
@@ -53,16 +53,12 @@
class SymbolTable {
public:
struct Symbol {
- Symbol() : Symbol(Maybe<ResourceId>{}) {}
+ Symbol() = default;
- explicit Symbol(const Maybe<ResourceId>& i) : Symbol(i, nullptr) {}
-
- Symbol(const Maybe<ResourceId>& i, const std::shared_ptr<Attribute>& attr)
- : Symbol(i, attr, false) {}
-
- Symbol(const Maybe<ResourceId>& i, const std::shared_ptr<Attribute>& attr,
- bool pub)
- : id(i), attribute(attr), is_public(pub) {}
+ explicit Symbol(const Maybe<ResourceId>& i, const std::shared_ptr<Attribute>& attr = {},
+ bool pub = false)
+ : id(i), attribute(attr), is_public(pub) {
+ }
Symbol(const Symbol&) = default;
Symbol(Symbol&&) = default;