Add requiredSystemPropertyValue support in idmap2

Up to Android P, there was this feature were we are able to
define "requiredSystemPropertyValue" in the AndroidManifest.xml
of the RRO apk, so that it will only be loaded if
requiredSystemPropertyValue/requiredSystemPropertyName are matched.

Porting support from idmap
https://android.googlesource.com/platform/frameworks/base/+/master/cmds/idmap/scan.cpp#135

To idmap2
https://android.googlesource.com/platform/frameworks/base/+/master/cmds/idmap2/idmap2/Scan.cpp#175

Bug: 140891738
Change-Id: I47752af93efa4563a60e336c1e1b1ffc081b51ec
This commit is contained in:
Gabriel Siqueira
2019-09-17 18:42:07 -03:00
parent 52efd46075
commit d7fc4f774a
3 changed files with 23 additions and 0 deletions

View File

@@ -175,6 +175,17 @@ Result<Unit> Scan(const std::vector<std::string>& args) {
continue;
}
// Note that conditional property enablement/exclusion only applies if
// the attribute is present. In its absence, all overlays are presumed enabled.
if (!overlay_info->requiredSystemPropertyName.empty()
&& !overlay_info->requiredSystemPropertyValue.empty()) {
// if property set & equal to value, then include overlay - otherwise skip
if (android::base::GetProperty(overlay_info->requiredSystemPropertyName, "")
!= overlay_info->requiredSystemPropertyValue) {
continue;
}
}
std::vector<std::string> fulfilled_policies;
if (!override_policies.empty()) {
fulfilled_policies = override_policies;

View File

@@ -30,6 +30,8 @@ namespace android::idmap2::utils {
struct OverlayManifestInfo {
std::string target_package; // NOLINT(misc-non-private-member-variables-in-classes)
std::string target_name; // NOLINT(misc-non-private-member-variables-in-classes)
std::string requiredSystemPropertyName; // NOLINT(misc-non-private-member-variables-in-classes)
std::string requiredSystemPropertyValue; // NOLINT(misc-non-private-member-variables-in-classes)
bool is_static; // NOLINT(misc-non-private-member-variables-in-classes)
int priority = -1; // NOLINT(misc-non-private-member-variables-in-classes)
};

View File

@@ -103,6 +103,16 @@ Result<OverlayManifestInfo> ExtractOverlayManifestInfo(const std::string& path,
info.priority = std::stoi(iter->second);
}
iter = tag->find("requiredSystemPropertyName");
if (iter != tag->end()) {
info.requiredSystemPropertyName = iter->second;
}
iter = tag->find("requiredSystemPropertyValue");
if (iter != tag->end()) {
info.requiredSystemPropertyValue = iter->second;
}
return info;
}