Fix compatibility between 'aapt2 dump' and 'aapt dump.'.
1. Report permissions declared only under <manifest>.
2. If the same feature reported multiple times: the last declaration
wins.
Bug: b/260704482
Test: manual runs
Change-Id: Ic9ff32573d2bf6550c3a01ed3019da83590eda2f
diff --git a/tools/aapt2/dump/DumpManifest.cpp b/tools/aapt2/dump/DumpManifest.cpp
index c4c002d..d60869a 100644
--- a/tools/aapt2/dump/DumpManifest.cpp
+++ b/tools/aapt2/dump/DumpManifest.cpp
@@ -1076,7 +1076,7 @@
/** Adds a feature to the feature group. */
void AddFeature(const std::string& name, bool required = true, int32_t version = -1) {
- features_.insert(std::make_pair(name, Feature{ required, version }));
+ features_.insert_or_assign(name, Feature{required, version});
if (required) {
if (name == "android.hardware.camera.autofocus" ||
name == "android.hardware.camera.flash") {
@@ -1348,6 +1348,11 @@
std::string impliedReason;
void Extract(xml::Element* element) override {
+ const auto parent_stack = extractor()->parent_stack();
+ if (!extractor()->options_.only_permissions &&
+ (parent_stack.size() != 1 || !ElementCast<Manifest>(parent_stack[0]))) {
+ return;
+ }
name = GetAttributeStringDefault(FindAttribute(element, NAME_ATTR), "");
std::string feature =
GetAttributeStringDefault(FindAttribute(element, REQUIRED_FEATURE_ATTR), "");
@@ -1472,6 +1477,11 @@
const int32_t* maxSdkVersion = nullptr;
void Extract(xml::Element* element) override {
+ const auto parent_stack = extractor()->parent_stack();
+ if (!extractor()->options_.only_permissions &&
+ (parent_stack.size() != 1 || !ElementCast<Manifest>(parent_stack[0]))) {
+ return;
+ }
name = GetAttributeString(FindAttribute(element, NAME_ATTR));
maxSdkVersion = GetAttributeInteger(FindAttribute(element, MAX_SDK_VERSION_ATTR));