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

Commit 0f3bebad authored by Calin Juravle's avatar Calin Juravle
Browse files

Return the freed bytes from deleteOdex API

This will help quantify the number of bytes we free for
telemetry purposes.

Test: installd_tests
Bug: 187458876
Change-Id: I29f7974977a58decf784bda443715f8b11fdf7c1
parent e90de86f
Loading
Loading
Loading
Loading
+4 −3
Original line number Original line Diff line number Diff line
@@ -2654,7 +2654,8 @@ binder::Status InstalldNativeService::moveAb(const std::string& apkPath,
}
}


binder::Status InstalldNativeService::deleteOdex(const std::string& apkPath,
binder::Status InstalldNativeService::deleteOdex(const std::string& apkPath,
        const std::string& instructionSet, const std::optional<std::string>& outputPath) {
        const std::string& instructionSet, const std::optional<std::string>& outputPath,
        int64_t* _aidl_return) {
    ENFORCE_UID(AID_SYSTEM);
    ENFORCE_UID(AID_SYSTEM);
    CHECK_ARGUMENT_PATH(apkPath);
    CHECK_ARGUMENT_PATH(apkPath);
    CHECK_ARGUMENT_PATH(outputPath);
    CHECK_ARGUMENT_PATH(outputPath);
@@ -2664,8 +2665,8 @@ binder::Status InstalldNativeService::deleteOdex(const std::string& apkPath,
    const char* instruction_set = instructionSet.c_str();
    const char* instruction_set = instructionSet.c_str();
    const char* oat_dir = outputPath ? outputPath->c_str() : nullptr;
    const char* oat_dir = outputPath ? outputPath->c_str() : nullptr;


    bool res = delete_odex(apk_path, instruction_set, oat_dir);
    *_aidl_return = delete_odex(apk_path, instruction_set, oat_dir);
    return res ? ok() : error();
    return *_aidl_return == -1 ? error() : ok();
}
}


// This kernel feature is experimental.
// This kernel feature is experimental.
+1 −1
Original line number Original line Diff line number Diff line
@@ -147,7 +147,7 @@ public:
    binder::Status moveAb(const std::string& apkPath, const std::string& instructionSet,
    binder::Status moveAb(const std::string& apkPath, const std::string& instructionSet,
            const std::string& outputPath);
            const std::string& outputPath);
    binder::Status deleteOdex(const std::string& apkPath, const std::string& instructionSet,
    binder::Status deleteOdex(const std::string& apkPath, const std::string& instructionSet,
            const std::optional<std::string>& outputPath);
            const std::optional<std::string>& outputPath, int64_t* _aidl_return);
    binder::Status installApkVerity(const std::string& filePath,
    binder::Status installApkVerity(const std::string& filePath,
            android::base::unique_fd verityInput, int32_t contentSize);
            android::base::unique_fd verityInput, int32_t contentSize);
    binder::Status assertFsverityRootHashMatches(const std::string& filePath,
    binder::Status assertFsverityRootHashMatches(const std::string& filePath,
+1 −1
Original line number Original line Diff line number Diff line
@@ -93,7 +93,7 @@ interface IInstalld {
            @utf8InCpp String toBase);
            @utf8InCpp String toBase);
    void moveAb(@utf8InCpp String apkPath, @utf8InCpp String instructionSet,
    void moveAb(@utf8InCpp String apkPath, @utf8InCpp String instructionSet,
            @utf8InCpp String outputPath);
            @utf8InCpp String outputPath);
    void deleteOdex(@utf8InCpp String apkPath, @utf8InCpp String instructionSet,
    long deleteOdex(@utf8InCpp String apkPath, @utf8InCpp String instructionSet,
            @nullable @utf8InCpp String outputPath);
            @nullable @utf8InCpp String outputPath);
    void installApkVerity(@utf8InCpp String filePath, in FileDescriptor verityInput,
    void installApkVerity(@utf8InCpp String filePath, in FileDescriptor verityInput,
            int contentSize);
            int contentSize);
+28 −14
Original line number Original line Diff line number Diff line
@@ -2252,38 +2252,52 @@ bool move_ab(const char* apk_path, const char* instruction_set, const char* oat_
    return success;
    return success;
}
}


bool delete_odex(const char* apk_path, const char* instruction_set, const char* oat_dir) {
int64_t delete_odex(const char* apk_path, const char* instruction_set, const char* oat_dir) {
    // Delete the oat/odex file.
    // Delete the oat/odex file.
    char out_path[PKG_PATH_MAX];
    char out_path[PKG_PATH_MAX];
    if (!create_oat_out_path(apk_path, instruction_set, oat_dir,
    if (!create_oat_out_path(apk_path, instruction_set, oat_dir,
            /*is_secondary_dex*/false, out_path)) {
            /*is_secondary_dex*/false, out_path)) {
        return false;
        LOG(ERROR) << "Cannot create apk path for " << apk_path;
        return -1;
    }
    }


    // In case of a permission failure report the issue. Otherwise just print a warning.
    // In case of a permission failure report the issue. Otherwise just print a warning.
    auto unlink_and_check = [](const char* path) -> bool {
    auto unlink_and_check = [](const char* path) -> int64_t {
        int result = unlink(path);
        struct stat file_stat;
        if (result != 0) {
        if (stat(path, &file_stat) != 0) {
            if (errno == EACCES || errno == EPERM) {
            if (errno != ENOENT) {
                PLOG(ERROR) << "Could not stat " << path;
                return -1;
            }
            return 0;
        }

        if (unlink(path) != 0) {
            if (errno != ENOENT) {
                PLOG(ERROR) << "Could not unlink " << path;
                PLOG(ERROR) << "Could not unlink " << path;
                return false;
                return -1;
            }
            }
            PLOG(WARNING) << "Could not unlink " << path;
        }
        }
        return true;
        return static_cast<int64_t>(file_stat.st_size);
    };
    };


    // Delete the oat/odex file.
    // Delete the oat/odex file.
    bool return_value_oat = unlink_and_check(out_path);
    int64_t return_value_oat = unlink_and_check(out_path);


    // Derive and delete the app image.
    // Derive and delete the app image.
    bool return_value_art = unlink_and_check(create_image_filename(out_path).c_str());
    int64_t return_value_art = unlink_and_check(create_image_filename(out_path).c_str());


    // Derive and delete the vdex file.
    // Derive and delete the vdex file.
    bool return_value_vdex = unlink_and_check(create_vdex_filename(out_path).c_str());
    int64_t return_value_vdex = unlink_and_check(create_vdex_filename(out_path).c_str());

    // Report result
    if (return_value_oat == -1
            || return_value_art == -1
            || return_value_vdex == -1) {
        return -1;
    }


    // Report success.
    return return_value_oat + return_value_art + return_value_vdex;
    return return_value_oat && return_value_art && return_value_vdex;
}
}


static bool is_absolute_path(const std::string& path) {
static bool is_absolute_path(const std::string& path) {
+2 −1
Original line number Original line Diff line number Diff line
@@ -109,7 +109,8 @@ bool prepare_app_profile(const std::string& package_name,
                         const std::string& code_path,
                         const std::string& code_path,
                         const std::optional<std::string>& dex_metadata);
                         const std::optional<std::string>& dex_metadata);


bool delete_odex(const char* apk_path, const char* instruction_set, const char* output_path);
// Returns the total bytes that were freed, or -1 in case of errors.
int64_t delete_odex(const char* apk_path, const char* instruction_set, const char* output_path);


bool reconcile_secondary_dex_file(const std::string& dex_path,
bool reconcile_secondary_dex_file(const std::string& dex_path,
        const std::string& pkgname, int uid, const std::vector<std::string>& isas,
        const std::string& pkgname, int uid, const std::vector<std::string>& isas,
Loading