Make 'idmap --scan' accept more than one input directory
The 'idmap --scan' command was limited to only scan a single directory
for overlay packages. Update idmap to support any number of directories.
Change-Id: I851f5720a3c1d844235911a0833670652a20a3c8
diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp
index 0ff2524..8385f75 100644
--- a/core/jni/android_util_AssetManager.cpp
+++ b/core/jni/android_util_AssetManager.cpp
@@ -24,6 +24,7 @@
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <sys/stat.h>
#include <private/android_filesystem_config.h> // for AID_SYSTEM
@@ -162,11 +163,32 @@
exit(1);
}
- execl(AssetManager::IDMAP_BIN, AssetManager::IDMAP_BIN, "--scan",
- AssetManager::OVERLAY_DIR, AssetManager::TARGET_PACKAGE_NAME,
- AssetManager::TARGET_APK_PATH, AssetManager::IDMAP_DIR, (char*)NULL);
- ALOGE("failed to execl for idmap: %s", strerror(errno));
- exit(1); // should never get here
+ // Generic idmap parameters
+ const char* argv[7];
+ int argc = 0;
+ struct stat st;
+
+ memset(argv, NULL, sizeof(argv));
+ argv[argc++] = AssetManager::IDMAP_BIN;
+ argv[argc++] = "--scan";
+ argv[argc++] = AssetManager::TARGET_PACKAGE_NAME;
+ argv[argc++] = AssetManager::TARGET_APK_PATH;
+ argv[argc++] = AssetManager::IDMAP_DIR;
+
+ // Directories to scan for overlays
+ // /vendor/overlay
+ if (stat(AssetManager::OVERLAY_DIR, &st) == 0) {
+ argv[argc++] = AssetManager::OVERLAY_DIR;
+ }
+
+ // Finally, invoke idmap (if any overlay directory exists)
+ if (argc > 5) {
+ execv(AssetManager::IDMAP_BIN, (char* const*)argv);
+ ALOGE("failed to execl for idmap: %s", strerror(errno));
+ exit(1); // should never get here
+ } else {
+ exit(0);
+ }
}
break;
default: // parent