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

Commit d1a6a249 authored by Calin Juravle's avatar Calin Juravle Committed by Android (Google) Code Review
Browse files

Merge "Do not clean profiles unconditonally during app data clean up" into nyc-dev

parents 830f5004 edae669f
Loading
Loading
Loading
Loading
+36 −23
Original line number Diff line number Diff line
@@ -173,35 +173,43 @@ static bool unlink_reference_profile(const char* pkgname) {
    return true;
}

static bool unlink_current_profiles(const char* pkgname) {
    bool success = true;
    std::vector<userid_t> users = get_known_users(/*volume_uuid*/ nullptr);
    for (auto user : users) {
static bool unlink_current_profile(const char* pkgname, userid_t user) {
    std::string profile_dir = create_data_user_profile_package_path(user, pkgname);
    std::string profile = create_primary_profile(profile_dir);
    if (unlink(profile.c_str()) != 0) {
        if (errno != ENOENT) {
            PLOG(WARNING) << "Could not unlink " << profile;
                success = false;
            return false;
        }
    }
    return true;
}

static bool unlink_current_profiles(const char* pkgname) {
    bool success = true;
    std::vector<userid_t> users = get_known_users(/*volume_uuid*/ nullptr);
    for (auto user : users) {
        success &= unlink_current_profile(pkgname, user);
    }
    return success;
}

static bool unlink_all_profiles(const char* pkgname) {
int clear_app_profiles(const char* pkgname) {
    bool success = true;
    success &= unlink_reference_profile(pkgname);
    success &= unlink_current_profiles(pkgname);
    return success;
    return success ? 0 : -1;
}

int clear_app_data(const char *uuid, const char *pkgname, userid_t userid, int flags) {
    std::string suffix = "";
    bool only_cache = false;
    if (flags & FLAG_CLEAR_CACHE_ONLY) {
        suffix = CACHE_DIR_POSTFIX;
        only_cache = true;
    } else if (flags & FLAG_CLEAR_CODE_CACHE_ONLY) {
        suffix = CODE_CACHE_DIR_POSTFIX;
        only_cache = true;
    }

    int res = 0;
@@ -217,17 +225,27 @@ int clear_app_data(const char *uuid, const char *pkgname, userid_t userid, int f
            // TODO: include result once 25796509 is fixed
            delete_dir_contents(path);
        }
        unlink_all_profiles(pkgname);
        if (!only_cache) {
            if (!unlink_current_profile(pkgname, userid)) {
                res |= -1;
            }
        }
    }
    return res;
}

static int destroy_app_profiles(const char *pkgname, userid_t userid) {
    // TODO: this doesn't destroy the marks for foreign dex use yet.
    int res = 0;
    res |= delete_dir_contents_and_dir(create_data_user_profile_package_path( userid, pkgname));
    res |= delete_dir_contents_and_dir(create_data_ref_profile_package_path(pkgname));
    return res;
static int destroy_app_current_profiles(const char *pkgname, userid_t userid) {
    return delete_dir_contents_and_dir(create_data_user_profile_package_path(userid, pkgname));
}

int destroy_app_profiles(const char *pkgname) {
    int result = 0;
    std::vector<userid_t> users = get_known_users(/*volume_uuid*/ nullptr);
    for (auto user : users) {
        result |= destroy_app_current_profiles(pkgname, user);
    }
    result |= delete_dir_contents_and_dir(create_data_ref_profile_package_path(pkgname));
    return result;
}

int destroy_app_data(const char *uuid, const char *pkgname, userid_t userid, int flags) {
@@ -239,8 +257,8 @@ int destroy_app_data(const char *uuid, const char *pkgname, userid_t userid, int
    if (flags & FLAG_STORAGE_DE) {
        res |= delete_dir_contents_and_dir(
                create_data_user_de_package_path(uuid, userid, pkgname));
        res |= destroy_app_profiles(pkgname, userid);
    }
    destroy_app_current_profiles(pkgname, userid);
    return res;
}

@@ -1780,11 +1798,6 @@ int rm_package_dir(const char* apk_path)
    return delete_dir_contents(apk_path, 1 /* also_delete_dir */ , NULL /* exclusion_predicate */);
}

int rm_profiles(const char* pkgname)
{
    return unlink_all_profiles(pkgname) ? 0 : -1;
}

int link_file(const char* relative_path, const char* from_base, const char* to_base) {
    char from_path[PKG_PATH_MAX];
    char to_path[PKG_PATH_MAX];
+2 −1
Original line number Diff line number Diff line
@@ -59,7 +59,8 @@ int linklib(const char* uuid, const char* pkgname, const char* asecLibDir, int u
int idmap(const char *target_path, const char *overlay_path, uid_t uid);
int create_oat_dir(const char* oat_dir, const char *instruction_set);
int rm_package_dir(const char* apk_path);
int rm_profiles(const char* pkgname);
int clear_app_profiles(const char* pkgname);
int destroy_app_profiles(const char* pkgname);
int link_file(const char *relative_path, const char *from_base, const char *to_base);

// Move a B version over to the A location. Only works for oat_dir != nullptr.
+10 −3
Original line number Diff line number Diff line
@@ -358,10 +358,16 @@ static int do_rm_package_dir(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED)
    return rm_package_dir(arg[0]);
}

static int do_rm_profiles(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED)
static int do_clear_app_profiles(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED)
{
    /* package_name */
    return rm_profiles(arg[0]);
    return clear_app_profiles(arg[0]);
}

static int do_destroy_app_profiles(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED)
{
    /* package_name */
    return destroy_app_profiles(arg[0]);
}

static int do_link_file(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED)
@@ -402,7 +408,8 @@ struct cmdinfo cmds[] = {
    { "idmap",                3, do_idmap },
    { "createoatdir",         2, do_create_oat_dir },
    { "rmpackagedir",         1, do_rm_package_dir },
    { "rmprofiles",           1, do_rm_profiles },
    { "clear_app_profiles",   1, do_clear_app_profiles },
    { "destroy_app_profiles", 1, do_destroy_app_profiles },
    { "linkfile",             3, do_link_file },
    { "move_ab",              3, do_move_ab },
    { "merge_profiles",       2, do_merge_profiles },