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

Commit 94e7fa98 authored by Andreas Gampe's avatar Andreas Gampe Committed by android-build-merger
Browse files

Merge "Otapreopt: Fix after shared-library work" into nyc-mr1-dev am: 3dfafe38

am: d6b4cb24

* commit 'd6b4cb24':
  Otapreopt: Fix after shared-library work

Change-Id: I996b105c9aa1689ae059c6883e0ab7a309d3c50b
parents 75fbfb52 d6b4cb24
Loading
Loading
Loading
Loading
+22 −0
Original line number Original line Diff line number Diff line
@@ -1385,6 +1385,28 @@ bool merge_profiles(uid_t uid, const char *pkgname) {
    return analyse_profiles(uid, pkgname);
    return analyse_profiles(uid, pkgname);
}
}


static const char* parse_null(const char* arg) {
    if (strcmp(arg, "!") == 0) {
        return nullptr;
    } else {
        return arg;
    }
}

int dexopt(const char* params[DEXOPT_PARAM_COUNT]) {
    return dexopt(params[0],                    // apk_path
                  atoi(params[1]),              // uid
                  params[2],                    // pkgname
                  params[3],                    // instruction_set
                  atoi(params[4]),              // dexopt_needed
                  params[5],                    // oat_dir
                  atoi(params[6]),              // dexopt_flags
                  params[7],                    // compiler_filter
                  parse_null(params[8]),        // volume_uuid
                  parse_null(params[9]));       // shared_libraries
    static_assert(DEXOPT_PARAM_COUNT == 10U, "Unexpected dexopt param count");
}

int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* instruction_set,
int dexopt(const char* apk_path, uid_t uid, const char* pkgname, const char* instruction_set,
           int dexopt_needed, const char* oat_dir, int dexopt_flags, const char* compiler_filter,
           int dexopt_needed, const char* oat_dir, int dexopt_flags, const char* compiler_filter,
           const char* volume_uuid ATTRIBUTE_UNUSED, const char* shared_libraries)
           const char* volume_uuid ATTRIBUTE_UNUSED, const char* shared_libraries)
+15 −3
Original line number Original line Diff line number Diff line
@@ -56,9 +56,21 @@ bool merge_profiles(uid_t uid, const char *pkgname);


bool dump_profile(uid_t uid, const char *pkgname, const char *dex_files);
bool dump_profile(uid_t uid, const char *pkgname, const char *dex_files);


int dexopt(const char *apk_path, uid_t uid, const char *pkgName, const char *instruction_set,
int dexopt(const char *apk_path,
           int dexopt_needed, const char* oat_dir, int dexopt_flags, const char* compiler_filter,
           uid_t uid,
           const char* volume_uuid, const char* shared_libraries);
           const char *pkgName,
           const char *instruction_set,
           int dexopt_needed,
           const char* oat_dir,
           int dexopt_flags,
           const char* compiler_filter,
           const char* volume_uuid,
           const char* shared_libraries);
static_assert(DEXOPT_PARAM_COUNT == 10U, "Unexpected dexopt param size");

// Helper for the above, converting arguments.
int dexopt(const char* params[DEXOPT_PARAM_COUNT]);

int mark_boot_complete(const char *instruction_set);
int mark_boot_complete(const char *instruction_set);
int linklib(const char* uuid, const char* pkgname, const char* asecLibDir, int userId);
int linklib(const char* uuid, const char* pkgname, const char* asecLibDir, int userId);
int idmap(const char *target_path, const char *overlay_path, uid_t uid);
int idmap(const char *target_path, const char *overlay_path, uid_t uid);
+28 −17
Original line number Original line Diff line number Diff line
@@ -219,7 +219,8 @@ static int do_destroy_app_data(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSE
// We use otapreopt_chroot to get into the chroot.
// We use otapreopt_chroot to get into the chroot.
static constexpr const char* kOtaPreopt = "/system/bin/otapreopt_chroot";
static constexpr const char* kOtaPreopt = "/system/bin/otapreopt_chroot";


static int do_ota_dexopt(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED) {
static int do_ota_dexopt(const char* args[DEXOPT_PARAM_COUNT],
                         char reply[REPLY_MAX] ATTRIBUTE_UNUSED) {
    // Time to fork and run otapreopt.
    // Time to fork and run otapreopt.


    // Check that the tool exists.
    // Check that the tool exists.
@@ -231,12 +232,14 @@ static int do_ota_dexopt(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED) {


    pid_t pid = fork();
    pid_t pid = fork();
    if (pid == 0) {
    if (pid == 0) {
        const char* argv[1 + 9 + 1];
        const char* argv[1 + DEXOPT_PARAM_COUNT + 1];
        argv[0] = kOtaPreopt;
        argv[0] = kOtaPreopt;
        for (size_t i = 1; i <= 9; ++i) {

            argv[i] = arg[i - 1];
        for (size_t i = 0; i < DEXOPT_PARAM_COUNT; ++i) {
            argv[i + 1] = args[i];
        }
        }
        argv[10] = nullptr;

        argv[DEXOPT_PARAM_COUNT + 1] = nullptr;


        execv(argv[0], (char * const *)argv);
        execv(argv[0], (char * const *)argv);
        PLOG(ERROR) << "execv(OTAPREOPT_CHROOT) failed";
        PLOG(ERROR) << "execv(OTAPREOPT_CHROOT) failed";
@@ -252,22 +255,30 @@ static int do_ota_dexopt(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED) {
    }
    }
}
}


static int do_regular_dexopt(const char* args[DEXOPT_PARAM_COUNT],
                             char reply[REPLY_MAX] ATTRIBUTE_UNUSED) {
    return dexopt(args);
}

using DexoptFn = int (*)(const char* args[DEXOPT_PARAM_COUNT],
                         char reply[REPLY_MAX]);

static int do_dexopt(char **arg, char reply[REPLY_MAX])
static int do_dexopt(char **arg, char reply[REPLY_MAX])
{
{
    const char* args[DEXOPT_PARAM_COUNT];
    for (size_t i = 0; i < DEXOPT_PARAM_COUNT; ++i) {
        CHECK(arg[i] != nullptr);
        args[i] = arg[i];
    }

    int dexopt_flags = atoi(arg[6]);
    int dexopt_flags = atoi(arg[6]);
    DexoptFn dexopt_fn;
    if ((dexopt_flags & DEXOPT_OTA) != 0) {
    if ((dexopt_flags & DEXOPT_OTA) != 0) {
      return do_ota_dexopt(arg, reply);
        dexopt_fn = do_ota_dexopt;
    }
    } else {
    return dexopt(arg[0],                      // apk_path
        dexopt_fn = do_regular_dexopt;
                  atoi(arg[1]),                // uid
    }
                  arg[2],                      // pkgname
    return dexopt_fn(args, reply);
                  arg[3],                      // instruction_set
                  atoi(arg[4]),                // dexopt_needed
                  arg[5],                      // oat_dir
                  dexopt_flags,
                  arg[7],                      // compiler_filter
                  parse_null(arg[8]),          // volume_uuid
                  parse_null(arg[9]));         // shared_libraries
}
}


static int do_merge_profiles(char **arg, char reply[REPLY_MAX])
static int do_merge_profiles(char **arg, char reply[REPLY_MAX])
+2 −0
Original line number Original line Diff line number Diff line
@@ -21,6 +21,8 @@
namespace android {
namespace android {
namespace installd {
namespace installd {


constexpr size_t DEXOPT_PARAM_COUNT = 10U;

/* elements combined with a valid package name to form paths */
/* elements combined with a valid package name to form paths */


constexpr const char* PRIMARY_USER_PREFIX = "data/";
constexpr const char* PRIMARY_USER_PREFIX = "data/";
+6 −14
Original line number Original line Diff line number Diff line
@@ -188,12 +188,14 @@ private:


    bool ReadPackage(int argc ATTRIBUTE_UNUSED, char** argv) {
    bool ReadPackage(int argc ATTRIBUTE_UNUSED, char** argv) {
        size_t index = 0;
        size_t index = 0;
        while (index < ARRAY_SIZE(package_parameters_) &&
        static_assert(DEXOPT_PARAM_COUNT == ARRAY_SIZE(package_parameters_),
                      "Unexpected dexopt param count");
        while (index < DEXOPT_PARAM_COUNT &&
                argv[index + 1] != nullptr) {
                argv[index + 1] != nullptr) {
            package_parameters_[index] = argv[index + 1];
            package_parameters_[index] = argv[index + 1];
            index++;
            index++;
        }
        }
        if (index != ARRAY_SIZE(package_parameters_)) {
        if (index != ARRAY_SIZE(package_parameters_) || argv[index + 1] != nullptr) {
            LOG(ERROR) << "Wrong number of parameters";
            LOG(ERROR) << "Wrong number of parameters";
            return false;
            return false;
        }
        }
@@ -357,17 +359,7 @@ private:
    }
    }


    int RunPreopt() {
    int RunPreopt() {
        int ret = dexopt(package_parameters_[0],          // apk_path
        return dexopt(package_parameters_);
                atoi(package_parameters_[1]),             // uid
                package_parameters_[2],                   // pkgname
                package_parameters_[3],                   // instruction_set
                atoi(package_parameters_[4]),             // dexopt_needed
                package_parameters_[5],                   // oat_dir
                atoi(package_parameters_[6]),             // dexopt_flags
                package_parameters_[7],                   // compiler_filter
                ParseNull(package_parameters_[8]),        // volume_uuid
                ParseNull(package_parameters_[9]));       // shared_libraries
        return ret;
    }
    }


    ////////////////////////////////////
    ////////////////////////////////////
@@ -484,7 +476,7 @@ private:
    // to compile, instead of the A properties we could get from init/get_property.
    // to compile, instead of the A properties we could get from init/get_property.
    SystemProperties system_properties_;
    SystemProperties system_properties_;


    const char* package_parameters_[10];
    const char* package_parameters_[DEXOPT_PARAM_COUNT];


    // Store environment values we need to set.
    // Store environment values we need to set.
    std::vector<std::string> environ_;
    std::vector<std::string> environ_;
Loading