Add support for adding fingerprint prefix install constraints
Since more install constraints could be added in the future, add a new
option for inserting just fingerprint prefixes.
Bug: 270562509
Test: atest aapt2_tests
Change-Id: If357c6df09491fa1bec5fe1a00a682d634af69b7
diff --git a/tools/aapt2/dump/DumpManifest.cpp b/tools/aapt2/dump/DumpManifest.cpp
index c66f4e5..a43bf1b 100644
--- a/tools/aapt2/dump/DumpManifest.cpp
+++ b/tools/aapt2/dump/DumpManifest.cpp
@@ -2120,6 +2120,33 @@
}
};
+/** Represents <install-constraints> elements. **/
+class InstallConstraints : public ManifestExtractor::Element {
+ public:
+ InstallConstraints() = default;
+ std::vector<std::string> fingerprint_prefixes;
+
+ void Extract(xml::Element* element) override {
+ for (xml::Element* child : element->GetChildElements()) {
+ if (child->name == "fingerprint-prefix") {
+ xml::Attribute* attr = child->FindAttribute(kAndroidNamespace, "value");
+ if (attr) {
+ fingerprint_prefixes.push_back(attr->value);
+ }
+ }
+ }
+ }
+
+ void Print(text::Printer* printer) override {
+ if (!fingerprint_prefixes.empty()) {
+ printer->Print(StringPrintf("install-constraints:\n"));
+ for (const auto& prefix : fingerprint_prefixes) {
+ printer->Print(StringPrintf(" fingerprint-prefix='%s'\n", prefix.c_str()));
+ }
+ }
+ }
+};
+
/** Represents <original-package> elements. **/
class OriginalPackage : public ManifestExtractor::Element {
public:
@@ -2869,7 +2896,7 @@
constexpr const char* GetExpectedTagForType() {
// This array does not appear at runtime, as GetExpectedTagForType function is used by compiler
// to inject proper 'expected_tag' into ElementCast.
- std::array<std::pair<const char*, bool>, 37> tags = {
+ std::array<std::pair<const char*, bool>, 38> tags = {
std::make_pair("action", std::is_same<Action, T>::value),
std::make_pair("activity", std::is_same<Activity, T>::value),
std::make_pair("additional-certificate", std::is_same<AdditionalCertificate, T>::value),
@@ -2878,6 +2905,7 @@
std::make_pair("compatible-screens", std::is_same<CompatibleScreens, T>::value),
std::make_pair("feature-group", std::is_same<FeatureGroup, T>::value),
std::make_pair("input-type", std::is_same<InputType, T>::value),
+ std::make_pair("install-constraints", std::is_same<InstallConstraints, T>::value),
std::make_pair("intent-filter", std::is_same<IntentFilter, T>::value),
std::make_pair("meta-data", std::is_same<MetaData, T>::value),
std::make_pair("manifest", std::is_same<Manifest, T>::value),
@@ -2948,6 +2976,7 @@
{"compatible-screens", &CreateType<CompatibleScreens>},
{"feature-group", &CreateType<FeatureGroup>},
{"input-type", &CreateType<InputType>},
+ {"install-constraints", &CreateType<InstallConstraints>},
{"intent-filter", &CreateType<IntentFilter>},
{"manifest", &CreateType<Manifest>},
{"meta-data", &CreateType<MetaData>},