diff options
Diffstat (limited to 'cmds/idmap/scan.cpp')
-rw-r--r-- | cmds/idmap/scan.cpp | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/cmds/idmap/scan.cpp b/cmds/idmap/scan.cpp index 67874a8b9c02..d69dd79555a1 100644 --- a/cmds/idmap/scan.cpp +++ b/cmds/idmap/scan.cpp @@ -10,6 +10,7 @@ #include <androidfw/StreamingZipInflater.h> #include <androidfw/ZipFileRO.h> #include <cutils/jstring.h> +#include <cutils/properties.h> #include <private/android_filesystem_config.h> // for AID_SYSTEM #include <utils/SortedVector.h> #include <utils/String16.h> @@ -82,12 +83,26 @@ namespace { return String8(tmp); } + bool check_property(String16 property, String16 value) { + const char *prop; + const char *val; + + prop = strndup16to8(property.string(), property.size()); + char propBuf[PROPERTY_VALUE_MAX]; + property_get(prop, propBuf, NULL); + val = strndup16to8(value.string(), value.size()); + + return (strcmp(propBuf, val) == 0); + } + int parse_overlay_tag(const ResXMLTree& parser, const char *target_package_name, bool* is_static_overlay) { const size_t N = parser.getAttributeCount(); String16 target; int priority = -1; + String16 propName = String16(); + String16 propValue = String16(); for (size_t i = 0; i < N; ++i) { size_t len; String16 key(parser.getAttributeName(i, &len)); @@ -109,34 +124,32 @@ namespace { if (parser.getAttributeValue(i, &v) == sizeof(Res_value)) { *is_static_overlay = (v.data != 0); } - } - } - if (target == String16(target_package_name)) { - return priority; - } - return NO_OVERLAY_TAG; - } - - String16 parse_package_name(const ResXMLTree& parser) - { - const size_t N = parser.getAttributeCount(); - String16 package_name; - for (size_t i = 0; i < N; ++i) { - size_t len; - String16 key(parser.getAttributeName(i, &len)); - if (key == String16("package")) { + } else if (key == String16("requiredSystemPropertyName")) { const char16_t *p = parser.getAttributeStringValue(i, &len); if (p != NULL) { - package_name = String16(p, len); + propName = String16(p, len); + } + } else if (key == String16("requiredSystemPropertyValue")) { + const char16_t *p = parser.getAttributeStringValue(i, &len); + if (p != NULL) { + propValue = String16(p, len); } } } - return package_name; - } - bool isValidStaticOverlayPackage(const String16& package_name) { - // TODO(b/35742444): Need to support selection method based on a package name. - return package_name.size() > 0; + // Note that conditional property enablement/exclusion only applies if + // the attribute is present. In its absence, all overlays are presumed enabled. + if (propName.size() > 0 && propValue.size() > 0) { + // if property set & equal to value, then include overlay - otherwise skip + if (!check_property(propName, propValue)) { + return NO_OVERLAY_TAG; + } + } + + if (target == String16(target_package_name)) { + return priority; + } + return NO_OVERLAY_TAG; } int parse_manifest(const void *data, size_t size, const char *target_package_name) @@ -149,7 +162,6 @@ namespace { } ResXMLParser::event_code_t type; - String16 package_name; bool is_static_overlay = false; int priority = NO_OVERLAY_TAG; do { @@ -157,16 +169,14 @@ namespace { if (type == ResXMLParser::START_TAG) { size_t len; String16 tag(parser.getElementName(&len)); - if (tag == String16("manifest")) { - package_name = parse_package_name(parser); - } else if (tag == String16("overlay")) { + if (tag == String16("overlay")) { priority = parse_overlay_tag(parser, target_package_name, &is_static_overlay); break; } } } while (type != ResXMLParser::BAD_DOCUMENT && type != ResXMLParser::END_DOCUMENT); - if (is_static_overlay && isValidStaticOverlayPackage(package_name)) { + if (is_static_overlay) { return priority; } return NO_OVERLAY_TAG; |