am b8d1ee37: am 19db8c88: am ab91d03b: Merge "installd: Add support for SELF_PATCHOAT_NEEDED."

* commit 'b8d1ee37c4a6897442f5d381d5eb7162e04fcebd':
  installd: Add support for SELF_PATCHOAT_NEEDED.
This commit is contained in:
Richard Uhler 2015-04-09 14:51:00 +00:00 committed by Android Git Automerger
commit 9cebc2bc77
3 changed files with 40 additions and 26 deletions

View File

@ -988,8 +988,8 @@ static bool calculate_odex_file_path(char path[PKG_PATH_MAX],
} }
int dexopt(const char *apk_path, uid_t uid, bool is_public, int dexopt(const char *apk_path, uid_t uid, bool is_public,
const char *pkgname, const char *instruction_set, const char *pkgname, const char *instruction_set, int dexopt_needed,
bool vm_safe_mode, bool is_patchoat, bool debuggable, const char* oat_dir) bool vm_safe_mode, bool debuggable, const char* oat_dir)
{ {
struct utimbuf ut; struct utimbuf ut;
struct stat input_stat; struct stat input_stat;
@ -1021,13 +1021,25 @@ int dexopt(const char *apk_path, uid_t uid, bool is_public,
} }
} }
if (is_patchoat) { switch (dexopt_needed) {
if (!calculate_odex_file_path(in_odex_path, apk_path, instruction_set)) { case DEXOPT_DEX2OAT_NEEDED:
return -1; input_file = apk_path;
} break;
input_file = in_odex_path;
} else { case DEXOPT_PATCHOAT_NEEDED:
input_file = apk_path; if (!calculate_odex_file_path(in_odex_path, apk_path, instruction_set)) {
return -1;
}
input_file = in_odex_path;
break;
case DEXOPT_SELF_PATCHOAT_NEEDED:
input_file = out_path;
break;
default:
ALOGE("Invalid dexopt needed: %d\n", dexopt_needed);
exit(72);
} }
memset(&input_stat, 0, sizeof(input_stat)); memset(&input_stat, 0, sizeof(input_stat));
@ -1062,7 +1074,7 @@ int dexopt(const char *apk_path, uid_t uid, bool is_public,
} }
// Create a swap file if necessary. // Create a swap file if necessary.
if (!is_patchoat && ShouldUseSwapFileForDexopt()) { if (ShouldUseSwapFileForDexopt()) {
// Make sure there really is enough space. // Make sure there really is enough space.
size_t out_len = strlen(out_path); size_t out_len = strlen(out_path);
if (out_len + strlen(".swap") + 1 <= PKG_PATH_MAX) { if (out_len + strlen(".swap") + 1 <= PKG_PATH_MAX) {
@ -1121,9 +1133,10 @@ int dexopt(const char *apk_path, uid_t uid, bool is_public,
exit(67); exit(67);
} }
if (is_patchoat) { if (dexopt_needed == DEXOPT_PATCHOAT_NEEDED
|| dexopt_needed == DEXOPT_SELF_PATCHOAT_NEEDED) {
run_patchoat(input_fd, out_fd, input_file, out_path, pkgname, instruction_set); run_patchoat(input_fd, out_fd, input_file, out_path, pkgname, instruction_set);
} else { } else if (dexopt_needed == DEXOPT_DEX2OAT_NEEDED) {
const char *input_file_name = strrchr(input_file, '/'); const char *input_file_name = strrchr(input_file, '/');
if (input_file_name == NULL) { if (input_file_name == NULL) {
input_file_name = input_file; input_file_name = input_file;
@ -1132,6 +1145,9 @@ int dexopt(const char *apk_path, uid_t uid, bool is_public,
} }
run_dex2oat(input_fd, out_fd, input_file_name, out_path, swap_fd, pkgname, run_dex2oat(input_fd, out_fd, input_file_name, out_path, swap_fd, pkgname,
instruction_set, vm_safe_mode, debuggable); instruction_set, vm_safe_mode, debuggable);
} else {
ALOGE("Invalid dexopt needed: %d\n", dexopt_needed);
exit(73);
} }
exit(68); /* only get here on exec failure */ exit(68); /* only get here on exec failure */
} else { } else {

View File

@ -38,10 +38,10 @@ static int do_install(char **arg, char reply[REPLY_MAX] __unused)
static int do_dexopt(char **arg, char reply[REPLY_MAX] __unused) static int do_dexopt(char **arg, char reply[REPLY_MAX] __unused)
{ {
/* apk_path, uid, is_public, pkgname, instruction_set, vm_safe_mode, should_relocate /* apk_path, uid, is_public, pkgname, instruction_set,
debuggable, outputPath */ * dexopt_needed, vm_safe_mode, debuggable, oat_dir */
return dexopt(arg[0], atoi(arg[1]), atoi(arg[2]), arg[3], arg[4], atoi(arg[5]), 0, return dexopt(arg[0], atoi(arg[1]), atoi(arg[2]), arg[3], arg[4], atoi(arg[5]),
atoi(arg[6]), arg[7]); atoi(arg[6]), atoi(arg[7]), arg[8]);
} }
static int do_mark_boot_complete(char **arg, char reply[REPLY_MAX] __unused) static int do_mark_boot_complete(char **arg, char reply[REPLY_MAX] __unused)
@ -152,12 +152,6 @@ static int do_restorecon_data(char **arg, char reply[REPLY_MAX] __attribute__((u
/* pkgName, seinfo, uid*/ /* pkgName, seinfo, uid*/
} }
static int do_patchoat(char **arg, char reply[REPLY_MAX] __unused) {
/* apk_path, uid, is_public, pkgname, instruction_set, vm_safe_mode, should_relocate,
debuggable, outputPath */
return dexopt(arg[0], atoi(arg[1]), atoi(arg[2]), arg[3], arg[4], 0, 1, 0, "!");
}
static int do_create_oat_dir(char **arg, char reply[REPLY_MAX] __unused) static int do_create_oat_dir(char **arg, char reply[REPLY_MAX] __unused)
{ {
/* oat_dir, instruction_set */ /* oat_dir, instruction_set */
@ -179,7 +173,7 @@ struct cmdinfo {
struct cmdinfo cmds[] = { struct cmdinfo cmds[] = {
{ "ping", 0, do_ping }, { "ping", 0, do_ping },
{ "install", 4, do_install }, { "install", 4, do_install },
{ "dexopt", 8, do_dexopt }, { "dexopt", 9, do_dexopt },
{ "markbootcomplete", 1, do_mark_boot_complete }, { "markbootcomplete", 1, do_mark_boot_complete },
{ "movedex", 3, do_move_dex }, { "movedex", 3, do_move_dex },
{ "rmdex", 2, do_rm_dex }, { "rmdex", 2, do_rm_dex },
@ -198,7 +192,6 @@ struct cmdinfo cmds[] = {
{ "rmuser", 1, do_rm_user }, { "rmuser", 1, do_rm_user },
{ "idmap", 3, do_idmap }, { "idmap", 3, do_idmap },
{ "restorecondata", 3, do_restorecon_data }, { "restorecondata", 3, do_restorecon_data },
{ "patchoat", 5, do_patchoat },
{ "createoatdir", 2, do_create_oat_dir }, { "createoatdir", 2, do_create_oat_dir },
{ "rmpackagedir", 1, do_rm_package_dir}, { "rmpackagedir", 1, do_rm_package_dir},
}; };

View File

@ -83,6 +83,11 @@
#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 */
/* dexopt needed flags matching those in dalvik.system.DexFile */
#define DEXOPT_DEX2OAT_NEEDED 1
#define DEXOPT_PATCHOAT_NEEDED 2
#define DEXOPT_SELF_PATCHOAT_NEEDED 3
/* data structures */ /* data structures */
typedef struct { typedef struct {
@ -221,8 +226,8 @@ int get_size(const char *pkgname, userid_t userid, const char *apkpath, const ch
int64_t *codesize, int64_t *datasize, int64_t *cachesize, int64_t *asecsize); int64_t *codesize, int64_t *datasize, int64_t *cachesize, int64_t *asecsize);
int free_cache(int64_t free_size); int free_cache(int64_t free_size);
int dexopt(const char *apk_path, uid_t uid, bool is_public, const char *pkgName, int dexopt(const char *apk_path, uid_t uid, bool is_public, const char *pkgName,
const char *instruction_set, bool vm_safe_mode, bool should_relocate, bool debuggable, const char *instruction_set, int dexopt_needed, bool vm_safe_mode,
const char* outputPath); bool debuggable, const char* oat_dir);
int mark_boot_complete(const char *instruction_set); int mark_boot_complete(const char *instruction_set);
int movefiles(); int movefiles();
int linklib(const char* target, const char* source, int userId); int linklib(const char* target, const char* source, int userId);