diff options
author | 2016-11-28 13:25:26 +0000 | |
---|---|---|
committer | 2016-11-28 13:25:26 +0000 | |
commit | f1188685490aae1a670fff038e0e613c861b6cf0 (patch) | |
tree | 8f4e8cf7d2015c8eb5f68dd3822e8003bd350500 | |
parent | 87b2535ff8f3ddc6589d699bbf375fd34b54de5c (diff) | |
parent | b29c82b67e05c9093d2accfa23e6007dc601f96b (diff) |
Merge "Adjust installd with new dexopt return values."
am: b29c82b67e
Change-Id: Ib0f3811c5891d6871d7b9d44c615954b06f261c6
-rw-r--r-- | cmds/installd/commands.cpp | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/cmds/installd/commands.cpp b/cmds/installd/commands.cpp index f21dfa1a39..d72ec365d4 100644 --- a/cmds/installd/commands.cpp +++ b/cmds/installd/commands.cpp @@ -76,9 +76,11 @@ static constexpr int FLAG_CLEAR_CACHE_ONLY = 1 << 8; static constexpr int FLAG_CLEAR_CODE_CACHE_ONLY = 1 << 9; /* dexopt needed flags matching those in dalvik.system.DexFile */ -static constexpr int DEXOPT_DEX2OAT_NEEDED = 1; -static constexpr int DEXOPT_PATCHOAT_NEEDED = 2; -static constexpr int DEXOPT_SELF_PATCHOAT_NEEDED = 3; +static constexpr int DEX2OAT_FROM_SCRATCH = 1; +static constexpr int DEX2OAT_FOR_BOOT_IMAGE = 2; +static constexpr int DEX2OAT_FOR_FILTER = 3; +static constexpr int DEX2OAT_FOR_RELOCATION = 4; +static constexpr int PATCHOAT_FOR_RELOCATION = 5; #define MIN_RESTRICTED_HOME_SDK_VERSION 24 // > M @@ -1680,20 +1682,25 @@ int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* ins const char *input_file; char in_odex_path[PKG_PATH_MAX]; - switch (dexopt_needed) { - case DEXOPT_DEX2OAT_NEEDED: + int dexopt_action = abs(dexopt_needed); + bool is_odex_location = dexopt_needed < 0; + switch (dexopt_action) { + case DEX2OAT_FROM_SCRATCH: + case DEX2OAT_FOR_BOOT_IMAGE: + case DEX2OAT_FOR_FILTER: + case DEX2OAT_FOR_RELOCATION: input_file = apk_path; break; - case DEXOPT_PATCHOAT_NEEDED: - if (!calculate_odex_file_path(in_odex_path, apk_path, instruction_set)) { - return -1; + case PATCHOAT_FOR_RELOCATION: + if (is_odex_location) { + if (!calculate_odex_file_path(in_odex_path, apk_path, instruction_set)) { + return -1; + } + input_file = in_odex_path; + } else { + input_file = out_oat_path; } - input_file = in_odex_path; - break; - - case DEXOPT_SELF_PATCHOAT_NEEDED: - input_file = out_oat_path; break; default: @@ -1730,8 +1737,7 @@ int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* ins // unlink the old one. base::unique_fd in_vdex_fd; std::string in_vdex_path_str; - if (dexopt_needed == DEXOPT_PATCHOAT_NEEDED - || dexopt_needed == DEXOPT_SELF_PATCHOAT_NEEDED) { + if (dexopt_action == PATCHOAT_FOR_RELOCATION) { // `input_file` is the OAT file to be relocated. The VDEX has to be there as well. in_vdex_path_str = create_vdex_filename(input_file); if (in_vdex_path_str.empty()) { @@ -1744,27 +1750,25 @@ int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* ins in_vdex_path_str.c_str(), strerror(errno)); return -1; } - } else { - // Open the possibly existing vdex in the `out_oat_path`. If none exist, we pass -1 - // to dex2oat for input-vdex-fd. - in_vdex_path_str = create_vdex_filename(out_oat_path); + } else if (dexopt_action != DEX2OAT_FROM_SCRATCH) { + // Open the possibly existing vdex. If none exist, we pass -1 to dex2oat for input-vdex-fd. + const char* path = nullptr; + if (is_odex_location) { + if (calculate_odex_file_path(in_odex_path, apk_path, instruction_set)) { + path = in_odex_path; + } else { + ALOGE("installd cannot compute input vdex location for '%s'\n", apk_path); + return -1; + } + } else { + path = out_oat_path; + } + in_vdex_path_str = create_vdex_filename(path); if (in_vdex_path_str.empty()) { - ALOGE("installd cannot compute input vdex location for '%s'\n", out_oat_path); + ALOGE("installd cannot compute input vdex location for '%s'\n", path); return -1; } in_vdex_fd.reset(open(in_vdex_path_str.c_str(), O_RDONLY, 0)); - // If there is no vdex file in out_oat_path, check if we have a vdex - // file next to the odex file. For other failures, we will just pass a -1 fd. - if (in_vdex_fd.get() < 0 && (errno == ENOENT) && IsOutputDalvikCache(oat_dir)) { - if (calculate_odex_file_path(in_odex_path, apk_path, instruction_set)) { - in_vdex_path_str = create_vdex_filename(std::string(in_odex_path)); - if (in_vdex_path_str.empty()) { - ALOGE("installd cannot compute input vdex location for '%s'\n", in_odex_path); - return -1; - } - in_vdex_fd.reset(open(in_vdex_path_str.c_str(), O_RDONLY, 0)); - } - } } // Infer the name of the output VDEX and create it. @@ -1808,7 +1812,7 @@ int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* ins // Avoid generating an app image for extract only since it will not contain any classes. Dex2oatFileWrapper<std::function<void ()>> image_fd; const std::string image_path = create_image_filename(out_oat_path); - if (dexopt_needed == DEXOPT_DEX2OAT_NEEDED && !image_path.empty()) { + if (dexopt_action != PATCHOAT_FOR_RELOCATION && !image_path.empty()) { char app_image_format[kPropertyValueMax]; bool have_app_image_format = get_property("dalvik.vm.appimageformat", app_image_format, NULL) > 0; @@ -1858,8 +1862,7 @@ int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* ins _exit(67); } - if (dexopt_needed == DEXOPT_PATCHOAT_NEEDED - || dexopt_needed == DEXOPT_SELF_PATCHOAT_NEEDED) { + if (dexopt_action == PATCHOAT_FOR_RELOCATION) { run_patchoat(input_fd.get(), in_vdex_fd.get(), out_oat_fd.get(), @@ -1870,7 +1873,7 @@ int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* ins out_vdex_path_str.c_str(), pkgname, instruction_set); - } else if (dexopt_needed == DEXOPT_DEX2OAT_NEEDED) { + } else { // Pass dex2oat the relative path to the input file. const char *input_file_name = get_location_from_path(input_file); run_dex2oat(input_fd.get(), @@ -1888,9 +1891,6 @@ int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* ins boot_complete, reference_profile_fd.get(), shared_libraries); - } else { - ALOGE("Invalid dexopt needed: %d\n", dexopt_needed); - _exit(73); } _exit(68); /* only get here on exec failure */ } else { |