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/link/XmlReferenceLinker.cpp b/tools/aapt2/link/XmlReferenceLinker.cpp
index 94bdccd..721fc26 100644
--- a/tools/aapt2/link/XmlReferenceLinker.cpp
+++ b/tools/aapt2/link/XmlReferenceLinker.cpp
@@ -72,13 +72,13 @@
   using xml::PackageAwareVisitor::Visit;
 
   XmlVisitor(const Source& source, const CallSite& callsite, IAaptContext* context,
-             SymbolTable* symbols, std::set<int>* sdk_levels_found)
+             SymbolTable* symbols)
       : source_(source),
         callsite_(callsite),
         context_(context),
         symbols_(symbols),
-        sdk_levels_found_(sdk_levels_found),
-        reference_visitor_(callsite, context, symbols, this) {}
+        reference_visitor_(callsite, context, symbols, this) {
+  }
 
   void Visit(xml::Element* el) override {
     // The default Attribute allows everything except enums or flags.
@@ -118,22 +118,12 @@
           continue;
         }
 
-        // Find this compiled attribute's SDK level.
-        const xml::AaptAttribute& aapt_attr = attr.compiled_attribute.value();
-        if (aapt_attr.id) {
-          // Record all SDK levels from which the attributes were defined.
-          const size_t sdk_level = FindAttributeSdkLevel(aapt_attr.id.value());
-          if (sdk_level > 1) {
-            sdk_levels_found_->insert(sdk_level);
-          }
-        }
-        attribute = &aapt_attr.attribute;
+        attribute = &attr.compiled_attribute.value().attribute;
       }
 
       attr.compiled_value = ResourceUtils::TryParseItemForAttribute(attr.value, attribute);
       if (attr.compiled_value) {
-        // With a compiledValue, we must resolve the reference and assign it an
-        // ID.
+        // With a compiledValue, we must resolve the reference and assign it an ID.
         attr.compiled_value->SetSource(source);
         attr.compiled_value->Accept(&reference_visitor_);
       } else if ((attribute->type_mask & android::ResTable_map::TYPE_STRING) == 0) {
@@ -164,7 +154,6 @@
   IAaptContext* context_;
   SymbolTable* symbols_;
 
-  std::set<int>* sdk_levels_found_;
   ReferenceVisitor reference_visitor_;
   bool error_ = false;
 };
@@ -172,10 +161,8 @@
 }  // namespace
 
 bool XmlReferenceLinker::Consume(IAaptContext* context, xml::XmlResource* resource) {
-  sdk_levels_found_.clear();
   const CallSite callsite = {resource->file.name};
-  XmlVisitor visitor(resource->file.source, callsite, context, context->GetExternalSymbols(),
-                     &sdk_levels_found_);
+  XmlVisitor visitor(resource->file.source, callsite, context, context->GetExternalSymbols());
   if (resource->root) {
     resource->root->Accept(&visitor);
     return !visitor.HasError();