From d7fc4f774a9a2ca5e9032daaecaa1e32e3d367d3 Mon Sep 17 00:00:00 2001 From: Gabriel Siqueira Date: Tue, 17 Sep 2019 18:42:07 -0300 Subject: 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 --- cmds/idmap2/idmap2/Scan.cpp | 11 +++++++++++ cmds/idmap2/include/idmap2/ResourceUtils.h | 2 ++ cmds/idmap2/libidmap2/ResourceUtils.cpp | 10 ++++++++++ 3 files changed, 23 insertions(+) (limited to 'cmds/idmap2') diff --git a/cmds/idmap2/idmap2/Scan.cpp b/cmds/idmap2/idmap2/Scan.cpp index cfac5f31e2e6..316e4d3a44a8 100644 --- a/cmds/idmap2/idmap2/Scan.cpp +++ b/cmds/idmap2/idmap2/Scan.cpp @@ -175,6 +175,17 @@ Result Scan(const std::vector& 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 fulfilled_policies; if (!override_policies.empty()) { fulfilled_policies = override_policies; diff --git a/cmds/idmap2/include/idmap2/ResourceUtils.h b/cmds/idmap2/include/idmap2/ResourceUtils.h index 8797a788dd1d..9a0c2abced5a 100644 --- a/cmds/idmap2/include/idmap2/ResourceUtils.h +++ b/cmds/idmap2/include/idmap2/ResourceUtils.h @@ -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) }; diff --git a/cmds/idmap2/libidmap2/ResourceUtils.cpp b/cmds/idmap2/libidmap2/ResourceUtils.cpp index 71ba3f0f1ac2..dce83e35978d 100644 --- a/cmds/idmap2/libidmap2/ResourceUtils.cpp +++ b/cmds/idmap2/libidmap2/ResourceUtils.cpp @@ -103,6 +103,16 @@ Result 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; } -- cgit v1.2.3-59-g8ed1b