summaryrefslogtreecommitdiff
path: root/cmds/idmap2
diff options
context:
space:
mode:
author Ryan Mitchell <rtmitchell@google.com> 2019-10-16 08:32:55 -0700
committer Ryan Mitchell <rtmitchell@google.com> 2020-01-10 23:20:19 +0000
commitee4a564d4ff2d16b6cdb6972e3aa92cd72668229 (patch)
tree7b5fa4c8bbb6df56b4445056236decafc1d9e9db /cmds/idmap2
parentfe50d739f75e13ebf64c010bf6ef504bcc81d860 (diff)
Allow for overlaying dynamic shared libraries
Overlays targeting shared libraries should be loaded into the resources of every target that depends on the shared library. Static shared libraries are currently not supported because overlays should override all versions of static shared libraries and there is not currently support for an overlay targeting multiple APKs. Also created a test instrumentation and host test suite for testing overlays and packages on the system image. Bug: 140790224 Test: atest OverlayRemountedTest Change-Id: I20a217b6368d6cf92b2b9f46908fd58012933f72
Diffstat (limited to 'cmds/idmap2')
-rw-r--r--cmds/idmap2/libidmap2/ResourceMapping.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/cmds/idmap2/libidmap2/ResourceMapping.cpp b/cmds/idmap2/libidmap2/ResourceMapping.cpp
index 229628c7dd8b..407478945151 100644
--- a/cmds/idmap2/libidmap2/ResourceMapping.cpp
+++ b/cmds/idmap2/libidmap2/ResourceMapping.cpp
@@ -33,6 +33,8 @@ namespace android::idmap2 {
namespace {
+#define REWRITE_PACKAGE(resid, package_id) \
+ (((resid)&0x00ffffffU) | (((uint32_t)(package_id)) << 24U))
#define EXTRACT_PACKAGE(resid) ((0xff000000 & (resid)) >> 24)
std::string ConcatPolicies(const std::vector<std::string>& policies) {
@@ -154,6 +156,7 @@ Result<ResourceMapping> ResourceMapping::CreateResourceMapping(const AssetManage
return Error("root element is not <overlay> tag");
}
+ const uint8_t target_package_id = target_package->GetPackageId();
const uint8_t overlay_package_id = overlay_package->GetPackageId();
auto overlay_it_end = root_it.end();
for (auto overlay_it = root_it.begin(); overlay_it != overlay_it_end; ++overlay_it) {
@@ -187,6 +190,9 @@ Result<ResourceMapping> ResourceMapping::CreateResourceMapping(const AssetManage
continue;
}
+ // Retrieve the compile-time resource id of the target resource.
+ target_id = REWRITE_PACKAGE(target_id, target_package_id);
+
if (overlay_resource->dataType == Res_value::TYPE_STRING) {
overlay_resource->data += string_pool_offset;
}
@@ -214,6 +220,7 @@ Result<ResourceMapping> ResourceMapping::CreateResourceMappingLegacy(
const AssetManager2* target_am, const AssetManager2* overlay_am,
const LoadedPackage* target_package, const LoadedPackage* overlay_package) {
ResourceMapping resource_mapping;
+ const uint8_t target_package_id = target_package->GetPackageId();
const auto end = overlay_package->end();
for (auto iter = overlay_package->begin(); iter != end; ++iter) {
const ResourceId overlay_resid = *iter;
@@ -225,11 +232,14 @@ Result<ResourceMapping> ResourceMapping::CreateResourceMappingLegacy(
// Find the resource with the same type and entry name within the target package.
const std::string full_name =
base::StringPrintf("%s:%s", target_package->GetPackageName().c_str(), name->c_str());
- const ResourceId target_resource = target_am->GetResourceId(full_name);
+ ResourceId target_resource = target_am->GetResourceId(full_name);
if (target_resource == 0U) {
continue;
}
+ // Retrieve the compile-time resource id of the target resource.
+ target_resource = REWRITE_PACKAGE(target_resource, target_package_id);
+
resource_mapping.AddMapping(target_resource, Res_value::TYPE_REFERENCE, overlay_resid,
/* rewrite_overlay_reference */ false);
}