Loading cmds/installd/commands.cpp +39 −39 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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: 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; break; case DEXOPT_SELF_PATCHOAT_NEEDED: } else { input_file = out_oat_path; } break; default: Loading Loading @@ -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()) { Loading @@ -1744,28 +1750,26 @@ 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 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 { // 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); 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", apk_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)); } 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", in_odex_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)); } } } // Infer the name of the output VDEX and create it. const std::string out_vdex_path_str = create_vdex_filename(out_oat_path_str); Loading Loading @@ -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; Loading Loading @@ -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(), Loading @@ -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(), Loading @@ -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 { Loading Loading
cmds/installd/commands.cpp +39 −39 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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: 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; break; case DEXOPT_SELF_PATCHOAT_NEEDED: } else { input_file = out_oat_path; } break; default: Loading Loading @@ -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()) { Loading @@ -1744,28 +1750,26 @@ 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 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 { // 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); 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", apk_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)); } 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", in_odex_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)); } } } // Infer the name of the output VDEX and create it. const std::string out_vdex_path_str = create_vdex_filename(out_oat_path_str); Loading Loading @@ -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; Loading Loading @@ -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(), Loading @@ -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(), Loading @@ -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 { Loading