Merge "AAPT2: Only print last uses-sdk tag" into sc-dev am: 556d84ca6c am: 4380a6a162

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14413055

Change-Id: I50965a316a4da384fbe098c5d665235a333a9b33
This commit is contained in:
Ryan Mitchell
2021-05-04 18:33:33 +00:00
committed by Automerger Merge Worker

View File

@@ -132,6 +132,12 @@ class ManifestExtractor {
/** Adds an element to the list of children of the element. */ /** Adds an element to the list of children of the element. */
void AddChild(std::unique_ptr<Element>& child) { children_.push_back(std::move(child)); } void AddChild(std::unique_ptr<Element>& child) { children_.push_back(std::move(child)); }
template <typename Predicate>
void Filter(Predicate&& func) {
children_.erase(std::remove_if(children_.begin(), children_.end(),
[&](const auto& e) { return func(e.get()); }));
}
/** Retrieves the list of children of the element. */ /** Retrieves the list of children of the element. */
const std::vector<std::unique_ptr<Element>>& children() const { const std::vector<std::unique_ptr<Element>>& children() const {
return children_; return children_;
@@ -1963,6 +1969,21 @@ bool ManifestExtractor::Dump(text::Printer* printer, IDiagnostics* diag) {
// Extract badging information // Extract badging information
auto root = Visit(element); auto root = Visit(element);
// Filter out all "uses-sdk" tags besides the very last tag. The android runtime only uses the
// attribute values from the last defined tag.
std::vector<UsesSdkBadging*> filtered_uses_sdk_tags;
for (const auto& child : root->children()) {
if (auto uses_sdk = ElementCast<UsesSdkBadging>(child.get())) {
filtered_uses_sdk_tags.emplace_back(uses_sdk);
}
}
filtered_uses_sdk_tags.pop_back();
root->Filter([&](const ManifestExtractor::Element* e) {
return std::find(filtered_uses_sdk_tags.begin(), filtered_uses_sdk_tags.end(), e) !=
filtered_uses_sdk_tags.end();
});
// Print the elements in order seen // Print the elements in order seen
Print(root.get(), printer); Print(root.get(), printer);