Themes: Restructure resource cache [2/2]

Change-Id: Ib62081e0551e572680b92c0a587bdc7bbee9b62b
This commit is contained in:
d34d 2015-01-19 08:19:29 -08:00
parent ea0c03875f
commit 2a7b426c03
3 changed files with 16 additions and 48 deletions

View File

@ -1601,8 +1601,8 @@ out:
return rc; return rc;
} }
static void run_idmap(const char *target_apk, const char *overlay_apk, int idmap_fd, static void run_idmap(const char *target_apk, const char *overlay_apk, const char *cache_path,
uint32_t target_hash, uint32_t overlay_hash) int idmap_fd, uint32_t target_hash, uint32_t overlay_hash)
{ {
static const char *IDMAP_BIN = "/system/bin/idmap"; static const char *IDMAP_BIN = "/system/bin/idmap";
static const size_t MAX_INT_LEN = 32; static const size_t MAX_INT_LEN = 32;
@ -1614,65 +1614,33 @@ static void run_idmap(const char *target_apk, const char *overlay_apk, int idmap
snprintf(target_hash_str, sizeof(target_hash_str), "%d", target_hash); snprintf(target_hash_str, sizeof(target_hash_str), "%d", target_hash);
snprintf(overlay_hash_str, sizeof(overlay_hash_str), "%d", overlay_hash); snprintf(overlay_hash_str, sizeof(overlay_hash_str), "%d", overlay_hash);
execl(IDMAP_BIN, IDMAP_BIN, "--fd", target_apk, overlay_apk, idmap_str, execl(IDMAP_BIN, IDMAP_BIN, "--fd", target_apk, overlay_apk, cache_path, idmap_str,
target_hash_str, overlay_hash_str, (char*)NULL); target_hash_str, overlay_hash_str, (char*)NULL);
ALOGE("execl(%s) failed: %s\n", IDMAP_BIN, strerror(errno)); ALOGE("execl(%s) failed: %s\n", IDMAP_BIN, strerror(errno));
} }
/* Prints to idmap_path (prefix)/(flat_target)@(flat_overerlay)@(suffix) static int get_idmap_path(const char *prefix, const char *suffix, char *idmap_path, size_t N)
* Note: "Flat" is a string with '/' changed to @
* Example input:
* prefix: /data/resource-cache/
* suffix: idmap
* overlay_path: /data/app/com.theme.apk
* target_path: /data/app/com.target.apk
* Example output:
* idmap_path: /data/resource-cache/data@app@com.target.apk@data@app@theme.apk@idmap
*/
static int flatten_path(const char *prefix, const char *suffix,
const char *overlay_path, const char *target_path, char *idmap_path, size_t N)
{ {
if (overlay_path == NULL || idmap_path == NULL || target_path == NULL) { if (idmap_path == NULL) return -1;
return -1;
}
const size_t len_target_path = strlen(target_path);
if (len_target_path < 2 || *target_path != '/') {
return -1;
}
const size_t len_overlay_path = strlen(overlay_path);
// will access overlay_path + 1 further below; requires absolute path
if (len_overlay_path < 2 || *overlay_path != '/') {
return -1;
}
const size_t len_idmap_root = strlen(prefix);
memset(idmap_path, 0, N); memset(idmap_path, 0, N);
int len = snprintf(idmap_path, N, "%s%s%s%s", prefix, target_path + 1, overlay_path, suffix); int len = snprintf(idmap_path, N, "%s/%s", prefix, suffix);
if (len < 0 || (size_t)len >= N) { if (len < 0 || (size_t)len >= N) {
return -1; // error or truncated return -1; // error or truncated
} }
char *ch = idmap_path + len_idmap_root;
while (*ch != '\0') {
if (*ch == '/') {
*ch = '@';
}
++ch;
}
return 0; return 0;
} }
int idmap(const char *target_apk, const char *overlay_apk, uid_t uid, int idmap(const char *target_apk, const char *overlay_apk, const char *cache_path,
uint32_t target_hash, uint32_t overlay_hash) uid_t uid, uint32_t target_hash, uint32_t overlay_hash)
{ {
ALOGV("idmap target_apk=%s overlay_apk=%s uid=%d\n", target_apk, overlay_apk, uid); ALOGD("idmap target_apk=%s overlay_apk=%s cache_path=%s uid=%d\n", target_apk, overlay_apk,
cache_path, uid);
int idmap_fd = -1; int idmap_fd = -1;
char idmap_path[PATH_MAX]; char idmap_path[PATH_MAX];
if (flatten_path(IDMAP_PREFIX, IDMAP_SUFFIX, overlay_apk, target_apk, if (get_idmap_path(cache_path, IDMAP_SUFFIX, idmap_path, sizeof(idmap_path)) == -1) {
idmap_path, sizeof(idmap_path)) == -1) {
ALOGE("idmap cannot generate idmap path for overlay %s\n", overlay_apk); ALOGE("idmap cannot generate idmap path for overlay %s\n", overlay_apk);
goto fail; goto fail;
} }
@ -1709,7 +1677,7 @@ int idmap(const char *target_apk, const char *overlay_apk, uid_t uid,
exit(1); exit(1);
} }
run_idmap(target_apk, overlay_apk, idmap_fd, target_hash, overlay_hash); run_idmap(target_apk, overlay_apk, cache_path, idmap_fd, target_hash, overlay_hash);
exit(1); /* only if exec call to idmap failed */ exit(1); /* only if exec call to idmap failed */
} else { } else {
int status = wait_child(pid); int status = wait_child(pid);

View File

@ -158,7 +158,7 @@ static int do_linklib(char **arg, char reply[REPLY_MAX] __unused)
static int do_idmap(char **arg, char reply[REPLY_MAX] __unused) static int do_idmap(char **arg, char reply[REPLY_MAX] __unused)
{ {
return idmap(arg[0], arg[1], atoi(arg[2]), atoi(arg[3]), atoi(arg[4])); return idmap(arg[0], arg[1], arg[2], atoi(arg[3]), atoi(arg[4]), atoi(arg[5]));
} }
static int do_aapt(char **arg, char reply[REPLY_MAX] __unused) static int do_aapt(char **arg, char reply[REPLY_MAX] __unused)
@ -222,7 +222,7 @@ struct cmdinfo cmds[] = {
{ "mkuserdata", 5, do_mk_user_data }, { "mkuserdata", 5, do_mk_user_data },
{ "mkuserconfig", 1, do_mk_user_config }, { "mkuserconfig", 1, do_mk_user_config },
{ "rmuser", 2, do_rm_user }, { "rmuser", 2, do_rm_user },
{ "idmap", 5, do_idmap }, { "idmap", 6, do_idmap },
{ "aapt", 6, do_aapt }, { "aapt", 6, do_aapt },
{ "aapt_with_common", 7, do_aapt_with_common }, { "aapt_with_common", 7, do_aapt_with_common },
{ "restorecondata", 4, do_restorecon_data }, { "restorecondata", 4, do_restorecon_data },

View File

@ -80,7 +80,7 @@
#define UPDATE_COMMANDS_DIR_PREFIX "/system/etc/updatecmds/" #define UPDATE_COMMANDS_DIR_PREFIX "/system/etc/updatecmds/"
#define IDMAP_PREFIX "/data/resource-cache/" #define IDMAP_PREFIX "/data/resource-cache/"
#define IDMAP_SUFFIX "@idmap" #define IDMAP_SUFFIX "idmap"
#define PKG_NAME_MAX 128 /* largest allowed package name */ #define PKG_NAME_MAX 128 /* largest allowed package name */
#define PKG_PATH_MAX 256 /* max size of any path we use */ #define PKG_PATH_MAX 256 /* max size of any path we use */
@ -247,7 +247,7 @@ int dexopt(const char *apk_path, uid_t uid, bool is_public, const char *pkgName,
int mark_boot_complete(const char *instruction_set); int mark_boot_complete(const char *instruction_set);
int movefiles(); int movefiles();
int linklib(const char* uuid, const char* pkgname, const char* asecLibDir, int userId); int linklib(const char* uuid, const char* pkgname, const char* asecLibDir, int userId);
int idmap(const char *target_path, const char *overlay_path, uid_t uid, int idmap(const char *target_path, const char *overlay_path, const char *cache_path, uid_t uid,
uint32_t target_hash, uint32_t overlay_hash); uint32_t target_hash, uint32_t overlay_hash);
int aapt(const char *source_apk, const char *internal_path, const char *out_restable, uid_t uid, int aapt(const char *source_apk, const char *internal_path, const char *out_restable, uid_t uid,
int pkgId, int min_sdk_version, const char *common_res_path); int pkgId, int min_sdk_version, const char *common_res_path);