From 598c25e23f7c97470e09a2316513ddf2efdfb670 Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Tue, 3 Mar 2015 09:15:06 -0800 Subject: [PATCH] Installd: Pass debuggable flag Pass the debuggable flag from the package manager to dex2oat. Change-Id: Id17ec72babe2ee88713a0d274eff86508de30666 --- cmds/installd/commands.c | 17 ++++++++++++++--- cmds/installd/installd.c | 13 ++++++++----- cmds/installd/installd.h | 2 +- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/cmds/installd/commands.c b/cmds/installd/commands.c index 386d2f33a..8a31ca50d 100644 --- a/cmds/installd/commands.c +++ b/cmds/installd/commands.c @@ -698,7 +698,7 @@ static void run_patchoat(int input_fd, int oat_fd, const char* input_file_name, static void run_dex2oat(int zip_fd, int oat_fd, const char* input_file_name, const char* output_file_name, int swap_fd, const char *pkgname, const char *instruction_set, - bool vm_safe_mode) + bool vm_safe_mode, bool debuggable) { static const unsigned int MAX_INSTRUCTION_SET_LEN = 7; @@ -816,6 +816,13 @@ static void run_dex2oat(int zip_fd, int oat_fd, const char* input_file_name, sprintf(dex2oat_compiler_filter_arg, "--compiler-filter=%s", dex2oat_compiler_filter_flag); } + // Check whether all apps should be compiled debuggable. + if (!debuggable) { + debuggable = + (property_get("dalvik.vm.always_debuggable", prop_buf, "0") > 0) && + (prop_buf[0] == '1'); + } + ALOGV("Running %s in=%s out=%s\n", DEX2OAT_BIN, input_file_name, output_file_name); const char* argv[7 // program name, mandatory arguments and the final NULL @@ -828,6 +835,7 @@ static void run_dex2oat(int zip_fd, int oat_fd, const char* input_file_name, + (have_dex2oat_compiler_filter_flag ? 1 : 0) + (have_dex2oat_swap_fd ? 1 : 0) + (have_dex2oat_relocation_skip_flag ? 2 : 0) + + (debuggable ? 1 : 0) + dex2oat_flags_count]; int i = 0; argv[i++] = DEX2OAT_BIN; @@ -862,6 +870,9 @@ static void run_dex2oat(int zip_fd, int oat_fd, const char* input_file_name, if (have_dex2oat_swap_fd) { argv[i++] = dex2oat_swap_fd; } + if (debuggable) { + argv[i++] = "--debuggable"; + } if (dex2oat_flags_count) { i += split(dex2oat_flags, argv + i); } @@ -921,7 +932,7 @@ static bool ShouldUseSwapFileForDexopt() { int dexopt(const char *apk_path, uid_t uid, bool is_public, const char *pkgname, const char *instruction_set, - bool vm_safe_mode, bool is_patchoat) + bool vm_safe_mode, bool is_patchoat, bool debuggable) { struct utimbuf ut; struct stat input_stat, dex_stat; @@ -1069,7 +1080,7 @@ int dexopt(const char *apk_path, uid_t uid, bool is_public, run_patchoat(input_fd, out_fd, input_file, out_path, pkgname, instruction_set); } else { run_dex2oat(input_fd, out_fd, input_file, out_path, swap_fd, pkgname, instruction_set, - vm_safe_mode); + vm_safe_mode, debuggable); } exit(68); /* only get here on exec failure */ } else { diff --git a/cmds/installd/installd.c b/cmds/installd/installd.c index 4dd83ae92..8f9417051 100644 --- a/cmds/installd/installd.c +++ b/cmds/installd/installd.c @@ -38,8 +38,10 @@ static int do_install(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 */ - return dexopt(arg[0], atoi(arg[1]), atoi(arg[2]), arg[3], arg[4], atoi(arg[5]), 0); + /* apk_path, uid, is_public, pkgname, instruction_set, vm_safe_mode, should_relocate, + debuggable */ + return dexopt(arg[0], atoi(arg[1]), atoi(arg[2]), arg[3], arg[4], atoi(arg[5]), 0, + atoi(arg[6])); } static int do_mark_boot_complete(char **arg, char reply[REPLY_MAX] __unused) @@ -151,8 +153,9 @@ static int do_restorecon_data(char **arg, char reply[REPLY_MAX] __attribute__((u } static int do_patchoat(char **arg, char reply[REPLY_MAX] __unused) { - /* apk_path, uid, is_public, pkgname, instruction_set, vm_safe_mode, should_relocate */ - return dexopt(arg[0], atoi(arg[1]), atoi(arg[2]), arg[3], arg[4], 0, 1); + /* apk_path, uid, is_public, pkgname, instruction_set, vm_safe_mode, should_relocate, + debuggable */ + return dexopt(arg[0], atoi(arg[1]), atoi(arg[2]), arg[3], arg[4], 0, 1, 0); } struct cmdinfo { @@ -164,7 +167,7 @@ struct cmdinfo { struct cmdinfo cmds[] = { { "ping", 0, do_ping }, { "install", 4, do_install }, - { "dexopt", 6, do_dexopt }, + { "dexopt", 7, do_dexopt }, { "markbootcomplete", 1, do_mark_boot_complete }, { "movedex", 3, do_move_dex }, { "rmdex", 2, do_rm_dex }, diff --git a/cmds/installd/installd.h b/cmds/installd/installd.h index a9a19995e..47577d60f 100644 --- a/cmds/installd/installd.h +++ b/cmds/installd/installd.h @@ -220,7 +220,7 @@ 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); int free_cache(int64_t free_size); 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); + const char *instruction_set, bool vm_safe_mode, bool should_relocate, bool debuggable); int mark_boot_complete(const char *instruction_set); int movefiles(); int linklib(const char* target, const char* source, int userId);