Loading cmds/installd/InstalldNativeService.cpp +9 −11 Original line number Original line Diff line number Diff line Loading @@ -424,12 +424,11 @@ binder::Status InstalldNativeService::clearAppProfiles(const std::string& packag CHECK_ARGUMENT_PACKAGE_NAME(packageName); CHECK_ARGUMENT_PACKAGE_NAME(packageName); std::lock_guard<std::recursive_mutex> lock(mLock); std::lock_guard<std::recursive_mutex> lock(mLock); const char* pkgname = packageName.c_str(); binder::Status res = ok(); binder::Status res = ok(); if (!clear_reference_profile(pkgname)) { if (!clear_reference_profile(packageName)) { res = error("Failed to clear reference profile for " + packageName); res = error("Failed to clear reference profile for " + packageName); } } if (!clear_current_profiles(pkgname)) { if (!clear_current_profiles(packageName)) { res = error("Failed to clear current profiles for " + packageName); res = error("Failed to clear current profiles for " + packageName); } } return res; return res; Loading Loading @@ -477,7 +476,7 @@ binder::Status InstalldNativeService::clearAppData(const std::unique_ptr<std::st } } } } if (!only_cache) { if (!only_cache) { if (!clear_current_profile(pkgname, userId)) { if (!clear_current_profile(packageName, userId)) { res = error("Failed to clear current profile for " + packageName); res = error("Failed to clear current profile for " + packageName); } } } } Loading @@ -485,13 +484,13 @@ binder::Status InstalldNativeService::clearAppData(const std::unique_ptr<std::st return res; return res; } } static int destroy_app_reference_profile(const char *pkgname) { static int destroy_app_reference_profile(const std::string& pkgname) { return delete_dir_contents_and_dir( return delete_dir_contents_and_dir( create_data_ref_profile_package_path(pkgname), create_data_ref_profile_package_path(pkgname), /*ignore_if_missing*/ true); /*ignore_if_missing*/ true); } } static int destroy_app_current_profiles(const char *pkgname, userid_t userid) { static int destroy_app_current_profiles(const std::string& pkgname, userid_t userid) { return delete_dir_contents_and_dir( return delete_dir_contents_and_dir( create_data_user_profile_package_path(userid, pkgname), create_data_user_profile_package_path(userid, pkgname), /*ignore_if_missing*/ true); /*ignore_if_missing*/ true); Loading @@ -502,15 +501,14 @@ binder::Status InstalldNativeService::destroyAppProfiles(const std::string& pack CHECK_ARGUMENT_PACKAGE_NAME(packageName); CHECK_ARGUMENT_PACKAGE_NAME(packageName); std::lock_guard<std::recursive_mutex> lock(mLock); std::lock_guard<std::recursive_mutex> lock(mLock); const char* pkgname = packageName.c_str(); binder::Status res = ok(); binder::Status res = ok(); std::vector<userid_t> users = get_known_users(/*volume_uuid*/ nullptr); std::vector<userid_t> users = get_known_users(/*volume_uuid*/ nullptr); for (auto user : users) { for (auto user : users) { if (destroy_app_current_profiles(pkgname, user) != 0) { if (destroy_app_current_profiles(packageName, user) != 0) { res = error("Failed to destroy current profiles for " + packageName); res = error("Failed to destroy current profiles for " + packageName); } } } } if (destroy_app_reference_profile(pkgname) != 0) { if (destroy_app_reference_profile(packageName) != 0) { res = error("Failed to destroy reference profile for " + packageName); res = error("Failed to destroy reference profile for " + packageName); } } return res; return res; Loading Loading @@ -538,11 +536,11 @@ binder::Status InstalldNativeService::destroyAppData(const std::unique_ptr<std:: if (delete_dir_contents_and_dir(path) != 0) { if (delete_dir_contents_and_dir(path) != 0) { res = error("Failed to delete " + path); res = error("Failed to delete " + path); } } destroy_app_current_profiles(pkgname, userId); destroy_app_current_profiles(packageName, userId); // TODO(calin): If the package is still installed by other users it's probably // TODO(calin): If the package is still installed by other users it's probably // beneficial to keep the reference profile around. // beneficial to keep the reference profile around. // Verify if it's ok to do that. // Verify if it's ok to do that. destroy_app_reference_profile(pkgname); destroy_app_reference_profile(packageName); } } return res; return res; } } Loading cmds/installd/dexopt.cpp +10 −14 Original line number Original line Diff line number Diff line Loading @@ -101,19 +101,19 @@ static bool clear_profile(const std::string& profile) { return truncated; return truncated; } } bool clear_reference_profile(const char* pkgname) { bool clear_reference_profile(const std::string& pkgname) { std::string reference_profile_dir = create_data_ref_profile_package_path(pkgname); std::string reference_profile_dir = create_data_ref_profile_package_path(pkgname); std::string reference_profile = create_primary_profile(reference_profile_dir); std::string reference_profile = create_primary_profile(reference_profile_dir); return clear_profile(reference_profile); return clear_profile(reference_profile); } } bool clear_current_profile(const char* pkgname, userid_t user) { bool clear_current_profile(const std::string& pkgname, userid_t user) { std::string profile_dir = create_data_user_profile_package_path(user, pkgname); std::string profile_dir = create_data_user_profile_package_path(user, pkgname); std::string profile = create_primary_profile(profile_dir); std::string profile = create_primary_profile(profile_dir); return clear_profile(profile); return clear_profile(profile); } } bool clear_current_profiles(const char* pkgname) { bool clear_current_profiles(const std::string& pkgname) { bool success = true; bool success = true; std::vector<userid_t> users = get_known_users(/*volume_uuid*/ nullptr); std::vector<userid_t> users = get_known_users(/*volume_uuid*/ nullptr); for (auto user : users) { for (auto user : users) { Loading Loading @@ -512,12 +512,12 @@ static fd_t open_primary_profile_file_from_dir(const std::string& profile_dir, m return profile_fd; return profile_fd; } } static fd_t open_primary_profile_file(userid_t user, const char* pkgname) { static fd_t open_primary_profile_file(userid_t user, const std::string& pkgname) { std::string profile_dir = create_data_user_profile_package_path(user, pkgname); std::string profile_dir = create_data_user_profile_package_path(user, pkgname); return open_primary_profile_file_from_dir(profile_dir, O_RDONLY); return open_primary_profile_file_from_dir(profile_dir, O_RDONLY); } } static fd_t open_reference_profile(uid_t uid, const char* pkgname, bool read_write) { static fd_t open_reference_profile(uid_t uid, const std::string& pkgname, bool read_write) { std::string reference_profile_dir = create_data_ref_profile_package_path(pkgname); std::string reference_profile_dir = create_data_ref_profile_package_path(pkgname); int flags = read_write ? O_RDWR | O_CREAT : O_RDONLY; int flags = read_write ? O_RDWR | O_CREAT : O_RDONLY; fd_t fd = open_primary_profile_file_from_dir(reference_profile_dir, flags); fd_t fd = open_primary_profile_file_from_dir(reference_profile_dir, flags); Loading @@ -534,7 +534,7 @@ static fd_t open_reference_profile(uid_t uid, const char* pkgname, bool read_wri return fd; return fd; } } static void open_profile_files(uid_t uid, const char* pkgname, static void open_profile_files(uid_t uid, const std::string& pkgname, /*out*/ std::vector<fd_t>* profiles_fd, /*out*/ fd_t* reference_profile_fd) { /*out*/ std::vector<fd_t>* profiles_fd, /*out*/ fd_t* reference_profile_fd) { // Open the reference profile in read-write mode as profman might need to save the merge. // Open the reference profile in read-write mode as profman might need to save the merge. *reference_profile_fd = open_reference_profile(uid, pkgname, /*read_write*/ true); *reference_profile_fd = open_reference_profile(uid, pkgname, /*read_write*/ true); Loading Loading @@ -614,7 +614,7 @@ static void run_profman_merge(const std::vector<fd_t>& profiles_fd, fd_t referen // a re-compilation of the package. // a re-compilation of the package. // If the return value is true all the current profiles would have been merged into // If the return value is true all the current profiles would have been merged into // the reference profiles accessible with open_reference_profile(). // the reference profiles accessible with open_reference_profile(). bool analyse_profiles(uid_t uid, const char* pkgname) { bool analyse_profiles(uid_t uid, const std::string& pkgname) { std::vector<fd_t> profiles_fd; std::vector<fd_t> profiles_fd; fd_t reference_profile_fd = -1; fd_t reference_profile_fd = -1; open_profile_files(uid, pkgname, &profiles_fd, &reference_profile_fd); open_profile_files(uid, pkgname, &profiles_fd, &reference_profile_fd); Loading @@ -628,8 +628,6 @@ bool analyse_profiles(uid_t uid, const char* pkgname) { return false; return false; } } ALOGV("PROFMAN (MERGE): --- BEGIN '%s' ---\n", pkgname); pid_t pid = fork(); pid_t pid = fork(); if (pid == 0) { if (pid == 0) { /* child -- drop privileges before continuing */ /* child -- drop privileges before continuing */ Loading Loading @@ -740,12 +738,10 @@ static const char* get_location_from_path(const char* path) { } } } } bool dump_profiles(int32_t uid, const char* pkgname, const char* code_paths) { bool dump_profiles(int32_t uid, const std::string& pkgname, const char* code_paths) { std::vector<fd_t> profile_fds; std::vector<fd_t> profile_fds; fd_t reference_profile_fd = -1; fd_t reference_profile_fd = -1; std::string out_file_name = StringPrintf("/data/misc/profman/%s.txt", pkgname); std::string out_file_name = StringPrintf("/data/misc/profman/%s.txt", pkgname.c_str()); ALOGV("PROFMAN (DUMP): --- BEGIN '%s' ---\n", pkgname); open_profile_files(uid, pkgname, &profile_fds, &reference_profile_fd); open_profile_files(uid, pkgname, &profile_fds, &reference_profile_fd); Loading @@ -753,7 +749,7 @@ bool dump_profiles(int32_t uid, const char* pkgname, const char* code_paths) { const bool has_profiles = !profile_fds.empty(); const bool has_profiles = !profile_fds.empty(); if (!has_reference_profile && !has_profiles) { if (!has_reference_profile && !has_profiles) { ALOGE("profman dump: no profiles to dump for '%s'", pkgname); LOG(ERROR) << "profman dump: no profiles to dump for " << pkgname; return false; return false; } } Loading cmds/installd/dexopt.h +5 −5 Original line number Original line Diff line number Diff line Loading @@ -34,14 +34,14 @@ static constexpr int PATCHOAT_FOR_RELOCATION = 5; typedef int fd_t; typedef int fd_t; bool clear_reference_profile(const char* pkgname); bool clear_reference_profile(const std::string& pkgname); bool clear_current_profile(const char* pkgname, userid_t user); bool clear_current_profile(const std::string& pkgname, userid_t user); bool clear_current_profiles(const char* pkgname); bool clear_current_profiles(const std::string& pkgname); bool move_ab(const char* apk_path, const char* instruction_set, const char* output_path); bool move_ab(const char* apk_path, const char* instruction_set, const char* output_path); bool analyse_profiles(uid_t uid, const char* pkgname); bool analyse_profiles(uid_t uid, const std::string& pkgname); bool dump_profiles(int32_t uid, const char* pkgname, const char* code_paths); bool dump_profiles(int32_t uid, const std::string& pkgname, const char* code_paths); bool delete_odex(const char* apk_path, const char* instruction_set, const char* output_path); bool delete_odex(const char* apk_path, const char* instruction_set, const char* output_path); Loading cmds/installd/tests/installd_utils_test.cpp +31 −0 Original line number Original line Diff line number Diff line Loading @@ -35,6 +35,8 @@ #define TEST_SYSTEM_DIR1 "/system/app/" #define TEST_SYSTEM_DIR1 "/system/app/" #define TEST_SYSTEM_DIR2 "/vendor/app/" #define TEST_SYSTEM_DIR2 "/vendor/app/" #define TEST_PROFILE_DIR "/data/misc/profiles" #define REALLY_LONG_APP_NAME "com.example." \ #define REALLY_LONG_APP_NAME "com.example." \ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa." \ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa." \ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa." \ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa." \ Loading Loading @@ -74,6 +76,9 @@ protected: android_system_dirs.dirs[1].path = (char*) TEST_SYSTEM_DIR2; android_system_dirs.dirs[1].path = (char*) TEST_SYSTEM_DIR2; android_system_dirs.dirs[1].len = strlen(TEST_SYSTEM_DIR2); android_system_dirs.dirs[1].len = strlen(TEST_SYSTEM_DIR2); android_profiles_dir.path = (char*) TEST_PROFILE_DIR; android_profiles_dir.len = strlen(TEST_PROFILE_DIR); } } virtual void TearDown() { virtual void TearDown() { Loading Loading @@ -515,5 +520,31 @@ TEST_F(UtilsTest, IsValidPackageName) { EXPECT_EQ(false, is_valid_package_name("/com.evil")); EXPECT_EQ(false, is_valid_package_name("/com.evil")); } } TEST_F(UtilsTest, CreateDataUserProfilePath) { EXPECT_EQ("/data/misc/profiles/cur/0", create_data_user_profile_path(0)); EXPECT_EQ("/data/misc/profiles/cur/1", create_data_user_profile_path(1)); } TEST_F(UtilsTest, CreateDataUserProfilePackagePath) { EXPECT_EQ("/data/misc/profiles/cur/0/com.example", create_data_user_profile_package_path(0, "com.example")); EXPECT_EQ("/data/misc/profiles/cur/1/com.example", create_data_user_profile_package_path(1, "com.example")); } TEST_F(UtilsTest, CreateDataRefProfilePath) { EXPECT_EQ("/data/misc/profiles/ref", create_data_ref_profile_path()); } TEST_F(UtilsTest, CreateDataRefProfilePackagePath) { EXPECT_EQ("/data/misc/profiles/ref/com.example", create_data_ref_profile_package_path("com.example")); } TEST_F(UtilsTest, CreatePrimaryProfile) { EXPECT_EQ("/data/misc/profiles/ref/com.example/primary.prof", create_primary_profile("/data/misc/profiles/ref/com.example")); } } // namespace installd } // namespace installd } // namespace android } // namespace android cmds/installd/utils.cpp +6 −6 Original line number Original line Diff line number Diff line Loading @@ -217,18 +217,18 @@ std::string create_data_user_profile_path(userid_t userid) { return StringPrintf("%s/cur/%u", android_profiles_dir.path, userid); return StringPrintf("%s/cur/%u", android_profiles_dir.path, userid); } } std::string create_data_user_profile_package_path(userid_t user, const char* package_name) { std::string create_data_user_profile_package_path(userid_t user, const std::string& package_name) { check_package_name(package_name); check_package_name(package_name.c_str()); return StringPrintf("%s/%s",create_data_user_profile_path(user).c_str(), package_name); return StringPrintf("%s/%s",create_data_user_profile_path(user).c_str(), package_name.c_str()); } } std::string create_data_ref_profile_path() { std::string create_data_ref_profile_path() { return StringPrintf("%s/ref", android_profiles_dir.path); return StringPrintf("%s/ref", android_profiles_dir.path); } } std::string create_data_ref_profile_package_path(const char* package_name) { std::string create_data_ref_profile_package_path(const std::string& package_name) { check_package_name(package_name); check_package_name(package_name.c_str()); return StringPrintf("%s/ref/%s", android_profiles_dir.path, package_name); return StringPrintf("%s/ref/%s", android_profiles_dir.path, package_name.c_str()); } } std::string create_data_dalvik_cache_path() { std::string create_data_dalvik_cache_path() { Loading Loading
cmds/installd/InstalldNativeService.cpp +9 −11 Original line number Original line Diff line number Diff line Loading @@ -424,12 +424,11 @@ binder::Status InstalldNativeService::clearAppProfiles(const std::string& packag CHECK_ARGUMENT_PACKAGE_NAME(packageName); CHECK_ARGUMENT_PACKAGE_NAME(packageName); std::lock_guard<std::recursive_mutex> lock(mLock); std::lock_guard<std::recursive_mutex> lock(mLock); const char* pkgname = packageName.c_str(); binder::Status res = ok(); binder::Status res = ok(); if (!clear_reference_profile(pkgname)) { if (!clear_reference_profile(packageName)) { res = error("Failed to clear reference profile for " + packageName); res = error("Failed to clear reference profile for " + packageName); } } if (!clear_current_profiles(pkgname)) { if (!clear_current_profiles(packageName)) { res = error("Failed to clear current profiles for " + packageName); res = error("Failed to clear current profiles for " + packageName); } } return res; return res; Loading Loading @@ -477,7 +476,7 @@ binder::Status InstalldNativeService::clearAppData(const std::unique_ptr<std::st } } } } if (!only_cache) { if (!only_cache) { if (!clear_current_profile(pkgname, userId)) { if (!clear_current_profile(packageName, userId)) { res = error("Failed to clear current profile for " + packageName); res = error("Failed to clear current profile for " + packageName); } } } } Loading @@ -485,13 +484,13 @@ binder::Status InstalldNativeService::clearAppData(const std::unique_ptr<std::st return res; return res; } } static int destroy_app_reference_profile(const char *pkgname) { static int destroy_app_reference_profile(const std::string& pkgname) { return delete_dir_contents_and_dir( return delete_dir_contents_and_dir( create_data_ref_profile_package_path(pkgname), create_data_ref_profile_package_path(pkgname), /*ignore_if_missing*/ true); /*ignore_if_missing*/ true); } } static int destroy_app_current_profiles(const char *pkgname, userid_t userid) { static int destroy_app_current_profiles(const std::string& pkgname, userid_t userid) { return delete_dir_contents_and_dir( return delete_dir_contents_and_dir( create_data_user_profile_package_path(userid, pkgname), create_data_user_profile_package_path(userid, pkgname), /*ignore_if_missing*/ true); /*ignore_if_missing*/ true); Loading @@ -502,15 +501,14 @@ binder::Status InstalldNativeService::destroyAppProfiles(const std::string& pack CHECK_ARGUMENT_PACKAGE_NAME(packageName); CHECK_ARGUMENT_PACKAGE_NAME(packageName); std::lock_guard<std::recursive_mutex> lock(mLock); std::lock_guard<std::recursive_mutex> lock(mLock); const char* pkgname = packageName.c_str(); binder::Status res = ok(); binder::Status res = ok(); std::vector<userid_t> users = get_known_users(/*volume_uuid*/ nullptr); std::vector<userid_t> users = get_known_users(/*volume_uuid*/ nullptr); for (auto user : users) { for (auto user : users) { if (destroy_app_current_profiles(pkgname, user) != 0) { if (destroy_app_current_profiles(packageName, user) != 0) { res = error("Failed to destroy current profiles for " + packageName); res = error("Failed to destroy current profiles for " + packageName); } } } } if (destroy_app_reference_profile(pkgname) != 0) { if (destroy_app_reference_profile(packageName) != 0) { res = error("Failed to destroy reference profile for " + packageName); res = error("Failed to destroy reference profile for " + packageName); } } return res; return res; Loading Loading @@ -538,11 +536,11 @@ binder::Status InstalldNativeService::destroyAppData(const std::unique_ptr<std:: if (delete_dir_contents_and_dir(path) != 0) { if (delete_dir_contents_and_dir(path) != 0) { res = error("Failed to delete " + path); res = error("Failed to delete " + path); } } destroy_app_current_profiles(pkgname, userId); destroy_app_current_profiles(packageName, userId); // TODO(calin): If the package is still installed by other users it's probably // TODO(calin): If the package is still installed by other users it's probably // beneficial to keep the reference profile around. // beneficial to keep the reference profile around. // Verify if it's ok to do that. // Verify if it's ok to do that. destroy_app_reference_profile(pkgname); destroy_app_reference_profile(packageName); } } return res; return res; } } Loading
cmds/installd/dexopt.cpp +10 −14 Original line number Original line Diff line number Diff line Loading @@ -101,19 +101,19 @@ static bool clear_profile(const std::string& profile) { return truncated; return truncated; } } bool clear_reference_profile(const char* pkgname) { bool clear_reference_profile(const std::string& pkgname) { std::string reference_profile_dir = create_data_ref_profile_package_path(pkgname); std::string reference_profile_dir = create_data_ref_profile_package_path(pkgname); std::string reference_profile = create_primary_profile(reference_profile_dir); std::string reference_profile = create_primary_profile(reference_profile_dir); return clear_profile(reference_profile); return clear_profile(reference_profile); } } bool clear_current_profile(const char* pkgname, userid_t user) { bool clear_current_profile(const std::string& pkgname, userid_t user) { std::string profile_dir = create_data_user_profile_package_path(user, pkgname); std::string profile_dir = create_data_user_profile_package_path(user, pkgname); std::string profile = create_primary_profile(profile_dir); std::string profile = create_primary_profile(profile_dir); return clear_profile(profile); return clear_profile(profile); } } bool clear_current_profiles(const char* pkgname) { bool clear_current_profiles(const std::string& pkgname) { bool success = true; bool success = true; std::vector<userid_t> users = get_known_users(/*volume_uuid*/ nullptr); std::vector<userid_t> users = get_known_users(/*volume_uuid*/ nullptr); for (auto user : users) { for (auto user : users) { Loading Loading @@ -512,12 +512,12 @@ static fd_t open_primary_profile_file_from_dir(const std::string& profile_dir, m return profile_fd; return profile_fd; } } static fd_t open_primary_profile_file(userid_t user, const char* pkgname) { static fd_t open_primary_profile_file(userid_t user, const std::string& pkgname) { std::string profile_dir = create_data_user_profile_package_path(user, pkgname); std::string profile_dir = create_data_user_profile_package_path(user, pkgname); return open_primary_profile_file_from_dir(profile_dir, O_RDONLY); return open_primary_profile_file_from_dir(profile_dir, O_RDONLY); } } static fd_t open_reference_profile(uid_t uid, const char* pkgname, bool read_write) { static fd_t open_reference_profile(uid_t uid, const std::string& pkgname, bool read_write) { std::string reference_profile_dir = create_data_ref_profile_package_path(pkgname); std::string reference_profile_dir = create_data_ref_profile_package_path(pkgname); int flags = read_write ? O_RDWR | O_CREAT : O_RDONLY; int flags = read_write ? O_RDWR | O_CREAT : O_RDONLY; fd_t fd = open_primary_profile_file_from_dir(reference_profile_dir, flags); fd_t fd = open_primary_profile_file_from_dir(reference_profile_dir, flags); Loading @@ -534,7 +534,7 @@ static fd_t open_reference_profile(uid_t uid, const char* pkgname, bool read_wri return fd; return fd; } } static void open_profile_files(uid_t uid, const char* pkgname, static void open_profile_files(uid_t uid, const std::string& pkgname, /*out*/ std::vector<fd_t>* profiles_fd, /*out*/ fd_t* reference_profile_fd) { /*out*/ std::vector<fd_t>* profiles_fd, /*out*/ fd_t* reference_profile_fd) { // Open the reference profile in read-write mode as profman might need to save the merge. // Open the reference profile in read-write mode as profman might need to save the merge. *reference_profile_fd = open_reference_profile(uid, pkgname, /*read_write*/ true); *reference_profile_fd = open_reference_profile(uid, pkgname, /*read_write*/ true); Loading Loading @@ -614,7 +614,7 @@ static void run_profman_merge(const std::vector<fd_t>& profiles_fd, fd_t referen // a re-compilation of the package. // a re-compilation of the package. // If the return value is true all the current profiles would have been merged into // If the return value is true all the current profiles would have been merged into // the reference profiles accessible with open_reference_profile(). // the reference profiles accessible with open_reference_profile(). bool analyse_profiles(uid_t uid, const char* pkgname) { bool analyse_profiles(uid_t uid, const std::string& pkgname) { std::vector<fd_t> profiles_fd; std::vector<fd_t> profiles_fd; fd_t reference_profile_fd = -1; fd_t reference_profile_fd = -1; open_profile_files(uid, pkgname, &profiles_fd, &reference_profile_fd); open_profile_files(uid, pkgname, &profiles_fd, &reference_profile_fd); Loading @@ -628,8 +628,6 @@ bool analyse_profiles(uid_t uid, const char* pkgname) { return false; return false; } } ALOGV("PROFMAN (MERGE): --- BEGIN '%s' ---\n", pkgname); pid_t pid = fork(); pid_t pid = fork(); if (pid == 0) { if (pid == 0) { /* child -- drop privileges before continuing */ /* child -- drop privileges before continuing */ Loading Loading @@ -740,12 +738,10 @@ static const char* get_location_from_path(const char* path) { } } } } bool dump_profiles(int32_t uid, const char* pkgname, const char* code_paths) { bool dump_profiles(int32_t uid, const std::string& pkgname, const char* code_paths) { std::vector<fd_t> profile_fds; std::vector<fd_t> profile_fds; fd_t reference_profile_fd = -1; fd_t reference_profile_fd = -1; std::string out_file_name = StringPrintf("/data/misc/profman/%s.txt", pkgname); std::string out_file_name = StringPrintf("/data/misc/profman/%s.txt", pkgname.c_str()); ALOGV("PROFMAN (DUMP): --- BEGIN '%s' ---\n", pkgname); open_profile_files(uid, pkgname, &profile_fds, &reference_profile_fd); open_profile_files(uid, pkgname, &profile_fds, &reference_profile_fd); Loading @@ -753,7 +749,7 @@ bool dump_profiles(int32_t uid, const char* pkgname, const char* code_paths) { const bool has_profiles = !profile_fds.empty(); const bool has_profiles = !profile_fds.empty(); if (!has_reference_profile && !has_profiles) { if (!has_reference_profile && !has_profiles) { ALOGE("profman dump: no profiles to dump for '%s'", pkgname); LOG(ERROR) << "profman dump: no profiles to dump for " << pkgname; return false; return false; } } Loading
cmds/installd/dexopt.h +5 −5 Original line number Original line Diff line number Diff line Loading @@ -34,14 +34,14 @@ static constexpr int PATCHOAT_FOR_RELOCATION = 5; typedef int fd_t; typedef int fd_t; bool clear_reference_profile(const char* pkgname); bool clear_reference_profile(const std::string& pkgname); bool clear_current_profile(const char* pkgname, userid_t user); bool clear_current_profile(const std::string& pkgname, userid_t user); bool clear_current_profiles(const char* pkgname); bool clear_current_profiles(const std::string& pkgname); bool move_ab(const char* apk_path, const char* instruction_set, const char* output_path); bool move_ab(const char* apk_path, const char* instruction_set, const char* output_path); bool analyse_profiles(uid_t uid, const char* pkgname); bool analyse_profiles(uid_t uid, const std::string& pkgname); bool dump_profiles(int32_t uid, const char* pkgname, const char* code_paths); bool dump_profiles(int32_t uid, const std::string& pkgname, const char* code_paths); bool delete_odex(const char* apk_path, const char* instruction_set, const char* output_path); bool delete_odex(const char* apk_path, const char* instruction_set, const char* output_path); Loading
cmds/installd/tests/installd_utils_test.cpp +31 −0 Original line number Original line Diff line number Diff line Loading @@ -35,6 +35,8 @@ #define TEST_SYSTEM_DIR1 "/system/app/" #define TEST_SYSTEM_DIR1 "/system/app/" #define TEST_SYSTEM_DIR2 "/vendor/app/" #define TEST_SYSTEM_DIR2 "/vendor/app/" #define TEST_PROFILE_DIR "/data/misc/profiles" #define REALLY_LONG_APP_NAME "com.example." \ #define REALLY_LONG_APP_NAME "com.example." \ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa." \ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa." \ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa." \ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa." \ Loading Loading @@ -74,6 +76,9 @@ protected: android_system_dirs.dirs[1].path = (char*) TEST_SYSTEM_DIR2; android_system_dirs.dirs[1].path = (char*) TEST_SYSTEM_DIR2; android_system_dirs.dirs[1].len = strlen(TEST_SYSTEM_DIR2); android_system_dirs.dirs[1].len = strlen(TEST_SYSTEM_DIR2); android_profiles_dir.path = (char*) TEST_PROFILE_DIR; android_profiles_dir.len = strlen(TEST_PROFILE_DIR); } } virtual void TearDown() { virtual void TearDown() { Loading Loading @@ -515,5 +520,31 @@ TEST_F(UtilsTest, IsValidPackageName) { EXPECT_EQ(false, is_valid_package_name("/com.evil")); EXPECT_EQ(false, is_valid_package_name("/com.evil")); } } TEST_F(UtilsTest, CreateDataUserProfilePath) { EXPECT_EQ("/data/misc/profiles/cur/0", create_data_user_profile_path(0)); EXPECT_EQ("/data/misc/profiles/cur/1", create_data_user_profile_path(1)); } TEST_F(UtilsTest, CreateDataUserProfilePackagePath) { EXPECT_EQ("/data/misc/profiles/cur/0/com.example", create_data_user_profile_package_path(0, "com.example")); EXPECT_EQ("/data/misc/profiles/cur/1/com.example", create_data_user_profile_package_path(1, "com.example")); } TEST_F(UtilsTest, CreateDataRefProfilePath) { EXPECT_EQ("/data/misc/profiles/ref", create_data_ref_profile_path()); } TEST_F(UtilsTest, CreateDataRefProfilePackagePath) { EXPECT_EQ("/data/misc/profiles/ref/com.example", create_data_ref_profile_package_path("com.example")); } TEST_F(UtilsTest, CreatePrimaryProfile) { EXPECT_EQ("/data/misc/profiles/ref/com.example/primary.prof", create_primary_profile("/data/misc/profiles/ref/com.example")); } } // namespace installd } // namespace installd } // namespace android } // namespace android
cmds/installd/utils.cpp +6 −6 Original line number Original line Diff line number Diff line Loading @@ -217,18 +217,18 @@ std::string create_data_user_profile_path(userid_t userid) { return StringPrintf("%s/cur/%u", android_profiles_dir.path, userid); return StringPrintf("%s/cur/%u", android_profiles_dir.path, userid); } } std::string create_data_user_profile_package_path(userid_t user, const char* package_name) { std::string create_data_user_profile_package_path(userid_t user, const std::string& package_name) { check_package_name(package_name); check_package_name(package_name.c_str()); return StringPrintf("%s/%s",create_data_user_profile_path(user).c_str(), package_name); return StringPrintf("%s/%s",create_data_user_profile_path(user).c_str(), package_name.c_str()); } } std::string create_data_ref_profile_path() { std::string create_data_ref_profile_path() { return StringPrintf("%s/ref", android_profiles_dir.path); return StringPrintf("%s/ref", android_profiles_dir.path); } } std::string create_data_ref_profile_package_path(const char* package_name) { std::string create_data_ref_profile_package_path(const std::string& package_name) { check_package_name(package_name); check_package_name(package_name.c_str()); return StringPrintf("%s/ref/%s", android_profiles_dir.path, package_name); return StringPrintf("%s/ref/%s", android_profiles_dir.path, package_name.c_str()); } } std::string create_data_dalvik_cache_path() { std::string create_data_dalvik_cache_path() { Loading