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

Commit 45c87434 authored by Shubham Ajmera's avatar Shubham Ajmera
Browse files

Check dexopt needed for secondary dex while downgrading

Test: make otapreopt
Test: manual
* Remove the check in the code that allows downgrade only when
  the space is low on the device.
* adb root
* Set pm.dexopt_unopt_after_inactive_days to 600
* Make sure the current time of the device is correctly set
* Install 2 non system apps - B, C
* Downgrade B to extract
* Upgrade a system apps to speed-profile - E
* Downgrade a system app to quicken - G
* adb shell cmd package bg-dexopt-job

Expected Results:
* Extract - B
* Verify - C
* There should not be any entries for apps E an G
  in dalvik_cache

For secondary dex:
* compile googlequicksearchbox to everything.
* run background dexopt service for secondary dex.
* verify the compiler filter for the corresponding odex files.

Bug: 36598475
Change-Id: I6ad40e2c53433326f83c2589646d94ba555400b2
parent 385c590f
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -1826,7 +1826,7 @@ binder::Status InstalldNativeService::dexopt(const std::string& apkPath, int32_t
        int32_t dexoptNeeded, const std::unique_ptr<std::string>& outputPath, int32_t dexFlags,
        const std::string& compilerFilter, const std::unique_ptr<std::string>& uuid,
        const std::unique_ptr<std::string>& sharedLibraries,
        const std::unique_ptr<std::string>& seInfo) {
        const std::unique_ptr<std::string>& seInfo, bool downgrade) {
    ENFORCE_UID(AID_SYSTEM);
    CHECK_ARGUMENT_UUID(uuid);
    if (packageName && *packageName != "*") {
@@ -1843,7 +1843,8 @@ binder::Status InstalldNativeService::dexopt(const std::string& apkPath, int32_t
    const char* shared_libraries = sharedLibraries ? sharedLibraries->c_str() : nullptr;
    const char* se_info = seInfo ? seInfo->c_str() : nullptr;
    int res = android::installd::dexopt(apk_path, uid, pkgname, instruction_set, dexoptNeeded,
            oat_dir, dexFlags, compiler_filter, volume_uuid, shared_libraries, se_info);
            oat_dir, dexFlags, compiler_filter, volume_uuid, shared_libraries, se_info,
            downgrade);
    return res ? error(res, "Failed to dexopt") : ok();
}

+1 −1
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ public:
            int32_t dexoptNeeded, const std::unique_ptr<std::string>& outputPath, int32_t dexFlags,
            const std::string& compilerFilter, const std::unique_ptr<std::string>& uuid,
            const std::unique_ptr<std::string>& sharedLibraries,
            const std::unique_ptr<std::string>& seInfo);
            const std::unique_ptr<std::string>& seInfo, bool downgrade);

    binder::Status rmdex(const std::string& codePath, const std::string& instructionSet);

+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ interface IInstalld {
            @nullable @utf8InCpp String outputPath, int dexFlags,
            @utf8InCpp String compilerFilter, @nullable @utf8InCpp String uuid,
            @nullable @utf8InCpp String sharedLibraries,
            @nullable @utf8InCpp String seInfo);
            @nullable @utf8InCpp String seInfo, boolean downgrade);

    void rmdex(@utf8InCpp String codePath, @utf8InCpp String instructionSet);

+16 −6
Original line number Diff line number Diff line
@@ -1359,7 +1359,7 @@ 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
// the profile has changed.
static void exec_dexoptanalyzer(const std::string& dex_file, const std::string& instruction_set,
        const std::string& compiler_filter, bool profile_was_updated) {
        const std::string& compiler_filter, bool profile_was_updated, bool downgrade) {
    static const char* DEXOPTANALYZER_BIN = "/system/bin/dexoptanalyzer";
    static const unsigned int MAX_INSTRUCTION_SET_LEN = 7;

@@ -1373,9 +1373,13 @@ static void exec_dexoptanalyzer(const std::string& dex_file, const std::string&
    std::string isa_arg = "--isa=" + instruction_set;
    std::string compiler_filter_arg = "--compiler-filter=" + compiler_filter;
    const char* assume_profile_changed = "--assume-profile-changed";
    const char* downgrade_flag = "--downgrade";

    // program name, dex file, isa, filter, the final NULL
    const char* argv[5 + (profile_was_updated ? 1 : 0)];
    const int argc = 5 +
        (profile_was_updated ? 1 : 0) +
        (downgrade ? 1 : 0);
    const char* argv[argc];
    int i = 0;
    argv[i++] = DEXOPTANALYZER_BIN;
    argv[i++] = dex_file_arg.c_str();
@@ -1384,6 +1388,9 @@ static void exec_dexoptanalyzer(const std::string& dex_file, const std::string&
    if (profile_was_updated) {
        argv[i++] = assume_profile_changed;
    }
    if (downgrade) {
        argv[i++] = downgrade_flag;
    }
    argv[i] = NULL;

    execv(DEXOPTANALYZER_BIN, (char * const *)argv);
@@ -1464,7 +1471,7 @@ 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,
        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,
        std::string* oat_dir_out, std::string* dex_path_out) {
        std::string* oat_dir_out, std::string* dex_path_out, bool downgrade) {
    int storage_flag;

    if ((dexopt_flags & DEXOPT_STORAGE_CE) != 0) {
@@ -1533,7 +1540,8 @@ static bool process_secondary_dex_dexopt(const char* original_dex_path, const ch
        // child -- drop privileges before continuing.
        drop_capabilities(uid);
        // 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);
        exit(DEXOPTANALYZER_BIN_EXEC_ERROR);
    }

@@ -1560,7 +1568,8 @@ static bool process_secondary_dex_dexopt(const char* original_dex_path, const ch

int dexopt(const char* dex_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,
        const char* volume_uuid, const char* shared_libraries, const char* se_info) {
        const char* volume_uuid, const char* shared_libraries, const char* se_info,
        bool downgrade) {
    CHECK(pkgname != nullptr);
    CHECK(pkgname[0] != 0);
    if ((dexopt_flags & ~DEXOPT_MASK) != 0) {
@@ -1583,7 +1592,8 @@ int dexopt(const char* dex_path, uid_t uid, const char* pkgname, const char* ins
    if (is_secondary_dex) {
        if (process_secondary_dex_dexopt(dex_path, pkgname, dexopt_flags, volume_uuid, uid,
                instruction_set, compiler_filter, &is_public, &dexopt_needed, &oat_dir_str,
                &dex_real_path)) {
                &dex_real_path,
                downgrade)) {
            oat_dir = oat_dir_str.c_str();
            dex_path = dex_real_path.c_str();
            if (dexopt_needed == NO_DEXOPT_NEEDED) {
+2 −1
Original line number Diff line number Diff line
@@ -63,7 +63,8 @@ bool reconcile_secondary_dex_file(const std::string& dex_path,

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,
        const char* volume_uuid, const char* shared_libraries, const char* se_info);
        const char* volume_uuid, const char* shared_libraries, const char* se_info,
        bool downgrade);

}  // namespace installd
}  // namespace android
Loading