Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 58cab077 authored by Calin Juravle's avatar Calin Juravle Committed by Andreas Gampe
Browse files

[installd] Add check that classpath is up to date to getDexOptNeeded

Pass the class loader context argument to dexoptanalyzer when analyzing
secondary dex files.

(cherry picked from commit ef81ec21)

Bug: 62269291
Test: manual, compile secondary dex files
      adb shell cmd package compile -m speed --secondary-dex
com.google.android.googlequicksearchbox

Merged-In: I25ae93cadd12441a13ff54bb3da5a198085c6f3d
Change-Id: I25ae93cadd12441a13ff54bb3da5a198085c6f3d
parent 6147c1f6
Loading
Loading
Loading
Loading
+15 −6
Original line number Original line Diff line number Diff line
@@ -1365,7 +1365,8 @@ void update_out_oat_access_times(const char* apk_path, const char* out_oat_path)
// If this is for a profile guided compilation, profile_was_updated will tell whether or not
// If this is for a profile guided compilation, profile_was_updated will tell whether or not
// the profile has changed.
// the profile has changed.
static void exec_dexoptanalyzer(const std::string& dex_file, const std::string& instruction_set,
static void exec_dexoptanalyzer(const std::string& dex_file, const std::string& instruction_set,
        const std::string& compiler_filter, bool profile_was_updated, bool downgrade) {
        const std::string& compiler_filter, bool profile_was_updated, bool downgrade,
        const char* class_loader_context) {
    const char* dexoptanalyzer_bin =
    const char* dexoptanalyzer_bin =
            is_debug_runtime()
            is_debug_runtime()
                    ? "/system/bin/dexoptanalyzerd"
                    ? "/system/bin/dexoptanalyzerd"
@@ -1383,11 +1384,16 @@ static void exec_dexoptanalyzer(const std::string& dex_file, const std::string&
    std::string compiler_filter_arg = "--compiler-filter=" + compiler_filter;
    std::string compiler_filter_arg = "--compiler-filter=" + compiler_filter;
    const char* assume_profile_changed = "--assume-profile-changed";
    const char* assume_profile_changed = "--assume-profile-changed";
    const char* downgrade_flag = "--downgrade";
    const char* downgrade_flag = "--downgrade";
    std::string class_loader_context_arg = "--class-loader-context=";
    if (class_loader_context != nullptr) {
        class_loader_context_arg += class_loader_context;
    }


    // program name, dex file, isa, filter, the final NULL
    // program name, dex file, isa, filter, the final NULL
    const int argc = 5 +
    const int argc = 5 +
        (profile_was_updated ? 1 : 0) +
        (profile_was_updated ? 1 : 0) +
        (downgrade ? 1 : 0);
        (downgrade ? 1 : 0) +
        (class_loader_context != nullptr ? 1 : 0);
    const char* argv[argc];
    const char* argv[argc];
    int i = 0;
    int i = 0;
    argv[i++] = dexoptanalyzer_bin;
    argv[i++] = dexoptanalyzer_bin;
@@ -1400,6 +1406,9 @@ static void exec_dexoptanalyzer(const std::string& dex_file, const std::string&
    if (downgrade) {
    if (downgrade) {
        argv[i++] = downgrade_flag;
        argv[i++] = downgrade_flag;
    }
    }
    if (class_loader_context != nullptr) {
        argv[i++] = class_loader_context;
    }
    argv[i] = NULL;
    argv[i] = NULL;


    execv(dexoptanalyzer_bin, (char * const *)argv);
    execv(dexoptanalyzer_bin, (char * const *)argv);
@@ -1480,7 +1489,8 @@ static bool process_dexoptanalyzer_result(const std::string& dex_path, int resul
static bool process_secondary_dex_dexopt(const char* original_dex_path, const char* pkgname,
static bool process_secondary_dex_dexopt(const char* original_dex_path, const char* pkgname,
        int dexopt_flags, const char* volume_uuid, int uid, const char* instruction_set,
        int dexopt_flags, const char* volume_uuid, int uid, const char* instruction_set,
        const char* compiler_filter, bool* is_public_out, int* dexopt_needed_out,
        const char* compiler_filter, bool* is_public_out, int* dexopt_needed_out,
        std::string* oat_dir_out, std::string* dex_path_out, bool downgrade) {
        std::string* oat_dir_out, std::string* dex_path_out, bool downgrade,
        const char* class_loader_context) {
    int storage_flag;
    int storage_flag;


    if ((dexopt_flags & DEXOPT_STORAGE_CE) != 0) {
    if ((dexopt_flags & DEXOPT_STORAGE_CE) != 0) {
@@ -1550,7 +1560,7 @@ static bool process_secondary_dex_dexopt(const char* original_dex_path, const ch
        drop_capabilities(uid);
        drop_capabilities(uid);
        // Run dexoptanalyzer to get dexopt_needed code.
        // Run dexoptanalyzer to get dexopt_needed code.
        exec_dexoptanalyzer(dex_path, instruction_set, compiler_filter, profile_was_updated,
        exec_dexoptanalyzer(dex_path, instruction_set, compiler_filter, profile_was_updated,
                            downgrade);
                            downgrade, class_loader_context);
        exit(DEXOPTANALYZER_BIN_EXEC_ERROR);
        exit(DEXOPTANALYZER_BIN_EXEC_ERROR);
    }
    }


@@ -1606,8 +1616,7 @@ int dexopt(const char* dex_path, uid_t uid, const char* pkgname, const char* ins
    if (is_secondary_dex) {
    if (is_secondary_dex) {
        if (process_secondary_dex_dexopt(dex_path, pkgname, dexopt_flags, volume_uuid, uid,
        if (process_secondary_dex_dexopt(dex_path, pkgname, dexopt_flags, volume_uuid, uid,
                instruction_set, compiler_filter, &is_public, &dexopt_needed, &oat_dir_str,
                instruction_set, compiler_filter, &is_public, &dexopt_needed, &oat_dir_str,
                &dex_real_path,
                &dex_real_path, downgrade, class_loader_context)) {
                downgrade)) {
            oat_dir = oat_dir_str.c_str();
            oat_dir = oat_dir_str.c_str();
            dex_path = dex_real_path.c_str();
            dex_path = dex_real_path.c_str();
            if (dexopt_needed == NO_DEXOPT_NEEDED) {
            if (dexopt_needed == NO_DEXOPT_NEEDED) {