Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c744ae8a authored by Adam Lesinski's avatar Adam Lesinski
Browse files

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
parent 0418b72f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ cc_library_host_static {
        "link/PrivateAttributeMover.cpp",
        "link/ReferenceLinker.cpp",
        "link/TableMerger.cpp",
        "link/XmlCompatVersioner.cpp",
        "link/XmlNamespaceRemover.cpp",
        "link/XmlReferenceLinker.cpp",
        "optimize/ResourceDeduper.cpp",
+1 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ struct Debug {
                              const ResourceName& target_style);
  static void DumpHex(const void* data, size_t len);
  static void DumpXml(xml::XmlResource* doc);
  static std::string ToString(xml::XmlResource* doc);
};

}  // namespace aapt
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ namespace aapt {
static const char* sMajorVersion = "2";

// Update minor version whenever a feature or flag is added.
static const char* sMinorVersion = "15";
static const char* sMinorVersion = "16";

int PrintVersion() {
  std::cerr << "Android Asset Packaging Tool (aapt) " << sMajorVersion << "."
+9 −2
Original line number Diff line number Diff line
@@ -388,13 +388,20 @@ template <>
struct hash<aapt::ResourceName> {
  size_t operator()(const aapt::ResourceName& name) const {
    android::hash_t h = 0;
    h = android::JenkinsHashMix(h, hash<string>()(name.package));
    h = android::JenkinsHashMix(h, static_cast<uint32_t>(hash<string>()(name.package)));
    h = android::JenkinsHashMix(h, static_cast<uint32_t>(name.type));
    h = android::JenkinsHashMix(h, hash<string>()(name.entry));
    h = android::JenkinsHashMix(h, static_cast<uint32_t>(hash<string>()(name.entry)));
    return static_cast<size_t>(h);
  }
};

template <>
struct hash<aapt::ResourceId> {
  size_t operator()(const aapt::ResourceId& id) const {
    return id.id;
  }
};

}  // namespace std

#endif  // AAPT_RESOURCE_H
+6 −0
Original line number Diff line number Diff line
@@ -333,6 +333,12 @@ void BinaryPrimitive::Print(std::ostream* out) const {
  }
}

Attribute::Attribute()
    : type_mask(0u),
      min_int(std::numeric_limits<int32_t>::min()),
      max_int(std::numeric_limits<int32_t>::max()) {
}

Attribute::Attribute(bool w, uint32_t t)
    : type_mask(t),
      min_int(std::numeric_limits<int32_t>::min()),
Loading