diff options
| author | 2017-03-11 01:00:07 +0000 | |
|---|---|---|
| committer | 2017-03-11 01:00:07 +0000 | |
| commit | 0045d606d1595aa5665e92060ce508ed0f54d12c (patch) | |
| tree | 05fcbffc58f28229092b6adea9285fa67257d6b6 | |
| parent | 0c90e1c416ca5e6b24e00955ccde23705790e226 (diff) | |
| parent | ccaa1f3f78e7f0891877153f3d5c07bfd596b084 (diff) | |
Merge "Use std::string for profile operations instead of const char" am: 7c7d888d94
am: ccaa1f3f78
Change-Id: If09e67000ca5818c27bbfe521554c22209c0d04f
| -rw-r--r-- | cmds/installd/InstalldNativeService.cpp | 20 | ||||
| -rw-r--r-- | cmds/installd/dexopt.cpp | 24 | ||||
| -rw-r--r-- | cmds/installd/dexopt.h | 10 | ||||
| -rw-r--r-- | cmds/installd/tests/installd_utils_test.cpp | 31 | ||||
| -rw-r--r-- | cmds/installd/utils.cpp | 12 | ||||
| -rw-r--r-- | cmds/installd/utils.h | 4 | 
6 files changed, 63 insertions, 38 deletions
| diff --git a/cmds/installd/InstalldNativeService.cpp b/cmds/installd/InstalldNativeService.cpp index 29eb6e5c5b..f9235e5d54 100644 --- a/cmds/installd/InstalldNativeService.cpp +++ b/cmds/installd/InstalldNativeService.cpp @@ -424,12 +424,11 @@ binder::Status InstalldNativeService::clearAppProfiles(const std::string& packag      CHECK_ARGUMENT_PACKAGE_NAME(packageName);      std::lock_guard<std::recursive_mutex> lock(mLock); -    const char* pkgname = packageName.c_str();      binder::Status res = ok(); -    if (!clear_reference_profile(pkgname)) { +    if (!clear_reference_profile(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);      }      return res; @@ -477,7 +476,7 @@ binder::Status InstalldNativeService::clearAppData(const std::unique_ptr<std::st              }          }          if (!only_cache) { -            if (!clear_current_profile(pkgname, userId)) { +            if (!clear_current_profile(packageName, userId)) {                  res = error("Failed to clear current profile for " + packageName);              }          } @@ -485,13 +484,13 @@ binder::Status InstalldNativeService::clearAppData(const std::unique_ptr<std::st      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(          create_data_ref_profile_package_path(pkgname),          /*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(          create_data_user_profile_package_path(userid, pkgname),          /*ignore_if_missing*/ true); @@ -502,15 +501,14 @@ binder::Status InstalldNativeService::destroyAppProfiles(const std::string& pack      CHECK_ARGUMENT_PACKAGE_NAME(packageName);      std::lock_guard<std::recursive_mutex> lock(mLock); -    const char* pkgname = packageName.c_str();      binder::Status res = ok();      std::vector<userid_t> users = get_known_users(/*volume_uuid*/ nullptr);      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);          }      } -    if (destroy_app_reference_profile(pkgname) != 0) { +    if (destroy_app_reference_profile(packageName) != 0) {          res = error("Failed to destroy reference profile for " + packageName);      }      return res; @@ -538,11 +536,11 @@ binder::Status InstalldNativeService::destroyAppData(const std::unique_ptr<std::          if (delete_dir_contents_and_dir(path) != 0) {              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          // beneficial to keep the reference profile around.          // Verify if it's ok to do that. -        destroy_app_reference_profile(pkgname); +        destroy_app_reference_profile(packageName);      }      return res;  } diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp index 215600bd52..58b9d2cff0 100644 --- a/cmds/installd/dexopt.cpp +++ b/cmds/installd/dexopt.cpp @@ -101,19 +101,19 @@ static bool clear_profile(const std::string& profile) {      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 = create_primary_profile(reference_profile_dir);      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 = create_primary_profile(profile_dir);      return clear_profile(profile);  } -bool clear_current_profiles(const char* pkgname) { +bool clear_current_profiles(const std::string& pkgname) {      bool success = true;      std::vector<userid_t> users = get_known_users(/*volume_uuid*/ nullptr);      for (auto user : users) { @@ -512,12 +512,12 @@ static fd_t open_primary_profile_file_from_dir(const std::string& profile_dir, m      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);      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);      int flags = read_write ? O_RDWR | O_CREAT : O_RDONLY;      fd_t fd = open_primary_profile_file_from_dir(reference_profile_dir, flags); @@ -534,7 +534,7 @@ static fd_t open_reference_profile(uid_t uid, const char* pkgname, bool read_wri      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) {      // 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); @@ -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.  // If the return value is true all the current profiles would have been merged into  // 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;      fd_t reference_profile_fd = -1;      open_profile_files(uid, pkgname, &profiles_fd, &reference_profile_fd); @@ -628,8 +628,6 @@ bool analyse_profiles(uid_t uid, const char* pkgname) {          return false;      } -    ALOGV("PROFMAN (MERGE): --- BEGIN '%s' ---\n", pkgname); -      pid_t pid = fork();      if (pid == 0) {          /* child -- drop privileges before continuing */ @@ -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;      fd_t reference_profile_fd = -1; -    std::string out_file_name = StringPrintf("/data/misc/profman/%s.txt", pkgname); - -    ALOGV("PROFMAN (DUMP): --- BEGIN '%s' ---\n", pkgname); +    std::string out_file_name = StringPrintf("/data/misc/profman/%s.txt", pkgname.c_str());      open_profile_files(uid, pkgname, &profile_fds, &reference_profile_fd); @@ -753,7 +749,7 @@ bool dump_profiles(int32_t uid, const char* pkgname, const char* code_paths) {      const bool has_profiles = !profile_fds.empty();      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;      } diff --git a/cmds/installd/dexopt.h b/cmds/installd/dexopt.h index 7bb6eeef73..fab4d9416c 100644 --- a/cmds/installd/dexopt.h +++ b/cmds/installd/dexopt.h @@ -34,14 +34,14 @@ static constexpr int PATCHOAT_FOR_RELOCATION     = 5;  typedef int fd_t; -bool clear_reference_profile(const char* pkgname); -bool clear_current_profile(const char* pkgname, userid_t user); -bool clear_current_profiles(const char* pkgname); +bool clear_reference_profile(const std::string& pkgname); +bool clear_current_profile(const std::string& pkgname, userid_t user); +bool clear_current_profiles(const std::string& pkgname);  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 dump_profiles(int32_t uid, const char* pkgname, const char* code_paths); +bool analyse_profiles(uid_t uid, const std::string& pkgname); +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); diff --git a/cmds/installd/tests/installd_utils_test.cpp b/cmds/installd/tests/installd_utils_test.cpp index 8b23b3e55f..940046fb75 100644 --- a/cmds/installd/tests/installd_utils_test.cpp +++ b/cmds/installd/tests/installd_utils_test.cpp @@ -35,6 +35,8 @@  #define TEST_SYSTEM_DIR1 "/system/app/"  #define TEST_SYSTEM_DIR2 "/vendor/app/" +#define TEST_PROFILE_DIR "/data/misc/profiles" +  #define REALLY_LONG_APP_NAME "com.example." \          "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa." \          "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa." \ @@ -74,6 +76,9 @@ protected:          android_system_dirs.dirs[1].path = (char*) 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() { @@ -515,5 +520,31 @@ TEST_F(UtilsTest, IsValidPackageName) {      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 android diff --git a/cmds/installd/utils.cpp b/cmds/installd/utils.cpp index c59f4816e7..a6fa6561c9 100644 --- a/cmds/installd/utils.cpp +++ b/cmds/installd/utils.cpp @@ -217,18 +217,18 @@ std::string create_data_user_profile_path(userid_t 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) { -    check_package_name(package_name); -    return StringPrintf("%s/%s",create_data_user_profile_path(user).c_str(), package_name); +std::string create_data_user_profile_package_path(userid_t user, const std::string& package_name) { +    check_package_name(package_name.c_str()); +    return StringPrintf("%s/%s",create_data_user_profile_path(user).c_str(), package_name.c_str());  }  std::string create_data_ref_profile_path() {      return StringPrintf("%s/ref", android_profiles_dir.path);  } -std::string create_data_ref_profile_package_path(const char* package_name) { -    check_package_name(package_name); -    return StringPrintf("%s/ref/%s", android_profiles_dir.path, package_name); +std::string create_data_ref_profile_package_path(const std::string& package_name) { +    check_package_name(package_name.c_str()); +    return StringPrintf("%s/ref/%s", android_profiles_dir.path, package_name.c_str());  }  std::string create_data_dalvik_cache_path() { diff --git a/cmds/installd/utils.h b/cmds/installd/utils.h index 425b675b5e..8090b18993 100644 --- a/cmds/installd/utils.h +++ b/cmds/installd/utils.h @@ -95,10 +95,10 @@ std::string create_data_media_package_path(const char* volume_uuid, userid_t use  std::string create_data_misc_legacy_path(userid_t userid);  std::string create_data_user_profile_path(userid_t 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);  std::string create_data_ref_profile_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);  std::string create_data_dalvik_cache_path(); |