Adapter interface for external PkgMgr module 98/138998/14
authorDamian Pietruchowski <d.pietruchow@samsung.com>
Fri, 14 Jul 2017 15:56:52 +0000 (17:56 +0200)
committerDamian Pietruchowski <d.pietruchow@samsung.com>
Thu, 24 Aug 2017 08:48:54 +0000 (10:48 +0200)
PkgQueryInterface class for pkginfo queries instead of functions.
Advantage of this solution is that pkgmgrinfo_pkginfo_get_usr_pkginfo()
is called only once in constructor and handle is freed in destructor.

Submit together:
- https://review.tizen.org/gerrit/#/c/139347/
- https://review.tizen.org/gerrit/#/c/139346/

Change-Id: I820a92eedcbe90d058c1d61f49a595e0444d1fea
Signed-off-by: Damian Pietruchowski <d.pietruchow@samsung.com>
20 files changed:
src/common/app_query_interface.cc
src/common/external_mount.cc
src/common/pkgmgr_interface.cc
src/common/pkgmgr_query.cc
src/common/pkgmgr_query.h
src/common/pkgmgr_signal.cc
src/common/security_registration.cc
src/common/shared_dirs.cc
src/common/step/configuration/step_check_install_location.cc
src/common/step/configuration/step_parse_manifest.cc
src/common/step/configuration/step_parse_preload.cc
src/common/step/filesystem/step_create_globalapp_symlinks.cc
src/common/step/filesystem/step_migrate_legacy_external_image.cc
src/common/step/filesystem/step_move_installed_storage.cc
src/common/step/filesystem/step_optional_acquire_external_storage.cc
src/common/step/filesystem/step_remove_files.cc
src/common/step/filesystem/step_remove_globalapp_symlinks.cc
src/common/step/pkgmgr/step_check_force_clean.cc
src/common/step/pkgmgr/step_check_installable.cc
src/common/utils/manifest_util.cc

index 7b30ec3..f3e6602 100644 (file)
@@ -14,14 +14,16 @@ namespace common_installer {
 bool AppQueryInterface::IsPkgInstalled(const std::string& arg,
                                        uid_t uid) const {
   // argument from commandline is package id
-  if (QueryIsPackageInstalled(arg, GetRequestMode(uid), uid))
+  PkgQueryInterface pkg_query(arg, uid);
+  if (pkg_query.IsPackageInstalled(GetRequestMode(uid)))
     return true;
 
   // argument from commandline is path to file
   std::string pkg_id = GetPkgIdFromPath(arg);
   if (pkg_id.empty())
     return false;
-  return QueryIsPackageInstalled(pkg_id, GetRequestMode(uid), uid);
+  PkgQueryInterface pkg_query2(pkg_id, uid);
+  return pkg_query2.IsPackageInstalled(GetRequestMode(uid));
 }
 
 std::string AppQueryInterface::GetPkgId(const std::string& arg) const {
index a828d5d..b607c36 100644 (file)
@@ -39,7 +39,8 @@ bool ExternalMount::IsAvailable() const {
     LOG(WARNING) << "External storage (SD Card) is not mounted.";
     return false;
   }
-  std::string storage = QueryStorageForPkgId(pkgid_, uid_);
+  PkgQueryInterface pkg_query(pkgid_, uid_);
+  std::string storage = pkg_query.StorageForPkgId();
   if (storage != kInstalledExternally)
     return false;
 
index a62ae64..82fd336 100644 (file)
@@ -149,12 +149,13 @@ RequestType PkgMgrInterface::GetRequestType() const {
         } else {
           std::string pkgid = query_interface_->GetPkgId(GetRequestInfo());
           uid_t uid = GetUid();
+          ci::PkgQueryInterface pkg_query(pkgid, uid);
           if (!GetIsPreloadRequest() &&
-              QueryIsReadonlyPackage(pkgid, uid) &&
-              !QueryIsUpdatedPackage(pkgid, uid)) {
+              pkg_query.IsReadonlyPackage() &&
+              !pkg_query.IsUpdatedPackage()) {
             return RequestType::ReadonlyUpdateInstall;
           } else if (CheckIfAppFilesExists(pkgid, uid,
-              QueryIsReadonlyPackage(pkgid, uid))
+              pkg_query.IsReadonlyPackage())
                   ) {
             return RequestType::Update;
           } else {
@@ -168,9 +169,10 @@ RequestType PkgMgrInterface::GetRequestType() const {
     case PKGMGR_REQ_UNINSTALL: {
       std::string pkgid = GetRequestInfo();
       uid_t uid = GetUid();
-      if (QueryIsSystemPackage(pkgid, uid) &&
-          QueryIsUpdatedPackage(pkgid, uid) &&
-          QueryIsRemovablePackage(pkgid, uid))
+      ci::PkgQueryInterface pkg_query(pkgid, uid);
+      if (pkg_query.IsSystemPackage() &&
+          pkg_query.IsUpdatedPackage() &&
+          pkg_query.IsRemovablePackage())
         return RequestType::ReadonlyUpdateUninstall;
       else if (GetIsPreloadRequest() && GetIsPartialRW())
         return RequestType::PartialUninstall;
index 75c66a8..043a8e4 100644 (file)
@@ -7,7 +7,6 @@
 #include <sys/types.h>
 #include <manifest_parser/utils/logging.h>
 #include <pkgmgr_installer.h>
-#include <pkgmgr-info.h>
 #include <pkgmgr_parser.h>
 #include <tzplatform_config.h>
 
@@ -36,122 +35,72 @@ int PkgmgrForeachPrivilegeCallback(const char* privilege_name,
 
 namespace common_installer {
 
-
-std::string QueryCertificateAuthorCertificate(const std::string& pkgid,
-                                              uid_t uid) {
-  pkgmgrinfo_certinfo_h handle;
-  int ret = pkgmgrinfo_pkginfo_create_certinfo(&handle);
-  if (ret != PMINFO_R_OK) {
-    LOG(DEBUG) << "pkgmgrinfo_pkginfo_create_certinfo failed with error: "
-               << ret;
-    return {};
-  }
-  ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid.c_str(), handle, uid);
+PkgQueryInterface::PkgQueryInterface(const std::string& pkgid, uid_t uid)
+    : pkgid_(pkgid), uid_(uid), handle_(nullptr) {
+  int ret = pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid_.c_str(), uid_,
+      &handle_);
   if (ret != PMINFO_R_OK) {
-    if (ret != PMINFO_R_ENOENT)
-      LOG(DEBUG) << "pkgmgrinfo_pkginfo_load_certinfo failed with error: "
-                 << ret;
-    pkgmgrinfo_pkginfo_destroy_certinfo(handle);
-    return {};
+    if (ret != PMINFO_R_ENOENT) {
+      LOG(ERROR) << "Failed to call pkgmgrinfo_pkginfo_get_usr_pkginfo";
+      handle_ = nullptr;
+    }
   }
-  const char* author_cert = nullptr;
-  ret = pkgmgrinfo_pkginfo_get_cert_value(handle, PMINFO_AUTHOR_SIGNER_CERT,
-                                          &author_cert);
-  if (ret != PMINFO_R_OK) {
-    LOG(DEBUG) << "pkgmgrinfo_pkginfo_get_cert_value failed with error: "
-               << ret;
-    pkgmgrinfo_pkginfo_destroy_certinfo(handle);
-    return {};
+}
+
+PkgQueryInterface::~PkgQueryInterface() {
+  if (handle_ != nullptr) {
+    int ret = pkgmgrinfo_pkginfo_destroy_pkginfo(handle_);
+    if (ret != PMINFO_R_OK)
+      LOG(ERROR) << "Failed to call pkgmgrinfo_pkginfo_destroy_pkginfo";
   }
-  std::string old_author_certificate;
-  if (author_cert)
-    old_author_certificate = author_cert;
-  pkgmgrinfo_pkginfo_destroy_certinfo(handle);
-  return old_author_certificate;
 }
 
-std::string QueryTepPath(const std::string& pkgid, uid_t uid) {
-  pkgmgrinfo_pkginfo_h package_info;
-  if (pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid.c_str(), uid, &package_info)
-      != PMINFO_R_OK)
+bool PkgQueryInterface::IsValid() {
+  return handle_ != nullptr;
+}
+
+std::string PkgQueryInterface::TepPath() {
+  if(!IsValid())
     return {};
   char* tep_name = nullptr;
-  int ret = pkgmgrinfo_pkginfo_get_tep_name(package_info, &tep_name);
+  int ret = pkgmgrinfo_pkginfo_get_tep_name(handle_, &tep_name);
   if (ret != PMINFO_R_OK) {
     LOG(DEBUG) << "pkgmgrinfo_pkginfo_get_tep_name failed with error: "
                << ret;
-    pkgmgrinfo_pkginfo_destroy_pkginfo(package_info);
     return {};
   }
   std::string tep_name_value;
   if (tep_name)
     tep_name_value = tep_name;
-  pkgmgrinfo_pkginfo_destroy_pkginfo(package_info);
   return tep_name_value;
 }
 
-std::string QueryZipMountFile(const std::string& pkgid, uid_t uid) {
-  pkgmgrinfo_pkginfo_h package_info;
-  if (pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid.c_str(), uid, &package_info)
-      != PMINFO_R_OK)
+std::string PkgQueryInterface::ZipMountFile() {
+  if(!IsValid())
     return {};
   char* zip_mount_file = nullptr;
-  int ret = pkgmgrinfo_pkginfo_get_zip_mount_file(package_info,
+  int ret = pkgmgrinfo_pkginfo_get_zip_mount_file(handle_,
           &zip_mount_file);
   if (ret != PMINFO_R_OK) {
     LOG(DEBUG) << "pkgmgrinfo_pkginfo_get_zip_mount_file failed with error: "
                << ret;
-    pkgmgrinfo_pkginfo_destroy_pkginfo(package_info);
     return {};
   }
   std::string zip_mount_file_value;
   if (zip_mount_file)
     zip_mount_file_value = zip_mount_file;
-  pkgmgrinfo_pkginfo_destroy_pkginfo(package_info);
   return zip_mount_file_value;
 }
 
-bool QueryAppidsForPkgId(const std::string& pkg_id,
-                         std::vector<std::string>* result, uid_t uid) {
-  pkgmgrinfo_pkginfo_h package_info;
-  if (pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkg_id.c_str(), uid, &package_info)
-      != PMINFO_R_OK) {
-    return false;
-  }
-
-  bool ret = pkgmgrinfo_appinfo_get_usr_list(package_info, PMINFO_ALL_APP,
-      &PkgmgrForeachAppCallback, result, uid) == PMINFO_R_OK;
-  pkgmgrinfo_pkginfo_destroy_pkginfo(package_info);
-  return ret;
-}
-
-bool QueryPrivilegesForPkgId(const std::string& pkg_id, uid_t uid,
-                             std::vector<std::string>* result) {
-  pkgmgrinfo_pkginfo_h package_info;
-  if (pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkg_id.c_str(), uid, &package_info)
-      != PMINFO_R_OK) {
-    return false;
-  }
-
-  bool ret = pkgmgrinfo_pkginfo_foreach_privilege(package_info,
-      &PkgmgrForeachPrivilegeCallback, result) == PMINFO_R_OK;
-  pkgmgrinfo_pkginfo_destroy_pkginfo(package_info);
-  return ret;
-}
-
-std::string QueryStorageForPkgId(const std::string& pkg_id, uid_t uid) {
+std::string PkgQueryInterface::StorageForPkgId() {
+  if(!IsValid())
+    return {};
   // initial & default : internal
   std::string installed_location = "installed_internal";
-  pkgmgrinfo_pkginfo_h package_info;
-  if (pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkg_id.c_str(), uid, &package_info)
-      != PMINFO_R_OK) {
-    return "";
-  }
 
   pkgmgrinfo_installed_storage storage;
-  bool ok = pkgmgrinfo_pkginfo_get_installed_storage(package_info,
+  bool ok = pkgmgrinfo_pkginfo_get_installed_storage(handle_,
       &storage) == PMINFO_R_OK;
-  pkgmgrinfo_pkginfo_destroy_pkginfo(package_info);
 
   if (!ok)
     return "";
@@ -164,197 +113,152 @@ std::string QueryStorageForPkgId(const std::string& pkg_id, uid_t uid) {
   return installed_location;
 }
 
-bool QueryIsPackageInstalled(const std::string& pkg_id,
-                             RequestMode request_mode, uid_t uid) {
-  pkgmgrinfo_pkginfo_h handle;
-  int ret = pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkg_id.c_str(), uid,
-                                               &handle);
-  if (ret != PMINFO_R_OK) {
-    if (ret != PMINFO_R_ENOENT)
-      LOG(ERROR) << "Failed to call pkgmgrinfo_pkginfo_get_usr_all_pkginfo";
+bool PkgQueryInterface::IsPackageInstalled(RequestMode request_mode
+                                      /* = RequestMode::USER */) {
+  if(!IsValid())
     return false;
-  }
   bool is_global = false;
-  if (pkgmgrinfo_pkginfo_is_for_all_users(handle, &is_global) != PMINFO_R_OK) {
+  if (pkgmgrinfo_pkginfo_is_for_all_users(handle_, &is_global) != PMINFO_R_OK) {
     LOG(ERROR) << "pkgmgrinfo_pkginfo_is_for_all_users failed";
-    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
     return false;
   }
-  if (request_mode != RequestMode::GLOBAL && is_global) {
-    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-    return false;
-  }
-
-  pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-  return true;
-}
-
-bool QueryIsPackageInstalled(const std::string& pkg_id, uid_t uid) {
-  pkgmgrinfo_pkginfo_h handle;
-  int ret = pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkg_id.c_str(),
-              uid, &handle);
-  if (ret != PMINFO_R_OK) {
-    if (ret != PMINFO_R_ENOENT)
-      LOG(ERROR) << "Failed to call pkgmgrinfo_pkginfo_get_usr_all_pkginfo";
+  if ((request_mode != RequestMode::GLOBAL) && is_global)
     return false;
-  }
 
-  bool is_global = false;
-  if (pkgmgrinfo_pkginfo_is_for_all_users(handle, &is_global) != PMINFO_R_OK) {
-    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_for_all_users failed";
-    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+  if ((uid_ != kGlobalUserUid) && is_global)
     return false;
-  }
 
-  if (uid == kGlobalUserUid && is_global) {
-    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-    return true;
-  }
-
-  if (uid != kGlobalUserUid && is_global) {
-    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-    return false;
-  }
-
-  pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
   return true;
 }
 
-bool QueryIsGlobalPackage(const std::string& pkg_id, uid_t uid) {
-  pkgmgrinfo_pkginfo_h handle;
-  int ret = pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkg_id.c_str(),
-              uid, &handle);
-  if (ret != PMINFO_R_OK) {
-    if (ret != PMINFO_R_ENOENT)
-      LOG(ERROR) << "Failed to call pkgmgrinfo_pkginfo_get_usr_all_pkginfo";
+bool PkgQueryInterface::IsGlobalPackage() {
+  if(!IsValid())
     return false;
-  }
-
   bool is_global = false;
-  if (pkgmgrinfo_pkginfo_is_for_all_users(handle, &is_global) != PMINFO_R_OK) {
+  if (pkgmgrinfo_pkginfo_is_for_all_users(handle_, &is_global) != PMINFO_R_OK) {
     LOG(ERROR) << "pkgmgrinfo_pkginfo_is_for_all_users failed";
-    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
     return false;
   }
-
-  pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
   return is_global;
 }
 
-bool QueryIsReadonlyPackage(const std::string& pkg_id, uid_t uid) {
-  pkgmgrinfo_pkginfo_h handle;
-  int ret = pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkg_id.c_str(),
-              uid, &handle);
-  if (ret != PMINFO_R_OK) {
-    if (ret != PMINFO_R_ENOENT)
-      LOG(ERROR) << "Failed to call pkgmgrinfo_pkginfo_get_usr_all_pkginfo";
+bool PkgQueryInterface::IsReadonlyPackage() {
+  if(!IsValid())
     return false;
-  }
-
   bool is_readonly = false;
-  if (pkgmgrinfo_pkginfo_is_readonly(handle, &is_readonly) != PMINFO_R_OK) {
+  if (pkgmgrinfo_pkginfo_is_readonly(handle_, &is_readonly) != PMINFO_R_OK) {
     LOG(ERROR) << "pkgmgrinfo_pkginfo_is_readonly failed";
-    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
     return false;
   }
-
-  pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
   return is_readonly;
 }
 
-bool QueryIsDisabledPackage(const std::string& pkg_id, uid_t uid) {
-  pkgmgrinfo_pkginfo_h handle;
-  int ret = pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkg_id.c_str(),
-              uid, &handle);
-  if (ret != PMINFO_R_OK) {
-    if (ret != PMINFO_R_ENOENT)
-      LOG(ERROR) <<
-          "Failed to call pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo";
-    return false;
-  }
-
-  pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-  return true;
-}
-
-bool QueryIsUpdatedPackage(const std::string& pkg_id, uid_t uid) {
-  pkgmgrinfo_pkginfo_h handle;
-  int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkg_id.c_str(), uid, &handle);
-  if (ret != PMINFO_R_OK) {
-    if (ret != PMINFO_R_ENOENT)
-      LOG(ERROR) << "Failed to call pkgmgrinfo_pkginfo_get_usr_pkginfo";
+bool PkgQueryInterface::IsUpdatedPackage() {
+  if(!IsValid())
     return false;
-  }
-
   bool is_update = false;
-  if (pkgmgrinfo_pkginfo_is_update(handle, &is_update) != PMINFO_R_OK) {
+  if (pkgmgrinfo_pkginfo_is_update(handle_, &is_update) != PMINFO_R_OK) {
     LOG(ERROR) << "pkgmgrinfo_pkginfo_is_update failed";
-    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
     return false;
   }
-
-  pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
   return is_update;
 }
 
-bool QueryIsPreloadPackage(const std::string& pkg_id, uid_t uid) {
-  pkgmgrinfo_pkginfo_h handle;
-  int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkg_id.c_str(), uid, &handle);
-  if (ret != PMINFO_R_OK) {
-    if (ret != PMINFO_R_ENOENT)
-      LOG(ERROR) << "Failed to call pkgmgrinfo_pkginfo_get_usr_pkginfo";
+bool PkgQueryInterface::IsPreloadPackage() {
+  if(!IsValid())
     return false;
-  }
-
   bool is_preload = false;
-  if (pkgmgrinfo_pkginfo_is_preload(handle, &is_preload) != PMINFO_R_OK) {
+  if (pkgmgrinfo_pkginfo_is_preload(handle_, &is_preload) != PMINFO_R_OK) {
     LOG(ERROR) << "pkgmgrinfo_pkginfo_is_preload failed";
-    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
     return false;
   }
-
-  pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
   return is_preload;
 }
 
-bool QueryIsSystemPackage(const std::string& pkg_id, uid_t uid) {
-  pkgmgrinfo_pkginfo_h handle;
-  int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkg_id.c_str(), uid, &handle);
-  if (ret != PMINFO_R_OK) {
-    if (ret != PMINFO_R_ENOENT)
-      LOG(ERROR) << "Failed to call pkgmgrinfo_pkginfo_get_usr_pkginfo";
+bool PkgQueryInterface::IsSystemPackage() {
+  if(!IsValid())
+    return false;
+  bool is_system = false;
+  if (pkgmgrinfo_pkginfo_is_system(handle_, &is_system) != PMINFO_R_OK) {
+    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_preload failed";
     return false;
   }
+  return is_system;
+}
 
-  bool is_system = false;
-  if (pkgmgrinfo_pkginfo_is_system(handle, &is_system) != PMINFO_R_OK) {
-    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_system failed";
-    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+bool PkgQueryInterface::IsRemovablePackage() {
+  if(!IsValid())
+    return false;
+  bool is_removable = false;
+  if (pkgmgrinfo_pkginfo_is_removable(handle_, &is_removable) != PMINFO_R_OK) {
+    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_preload failed";
     return false;
   }
+  return is_removable;
+}
 
-  pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-  return is_system;
+bool PkgQueryInterface::AppidsForPkgId(std::vector<std::string>* result) {
+  if(!IsValid())
+    return false;
+  bool ret = pkgmgrinfo_appinfo_get_usr_list(handle_, PMINFO_ALL_APP,
+      &PkgmgrForeachAppCallback, result, uid_) == PMINFO_R_OK;
+  return ret;
 }
 
-bool QueryIsRemovablePackage(const std::string& pkg_id, uid_t uid) {
-  pkgmgrinfo_pkginfo_h handle;
-  int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkg_id.c_str(), uid, &handle);
+bool PkgQueryInterface::PrivilegesForPkgId(std::vector<std::string>* result) {
+  if(!IsValid())
+    return false;
+  bool ret = pkgmgrinfo_pkginfo_foreach_privilege(handle_,
+      &PkgmgrForeachPrivilegeCallback, result) == PMINFO_R_OK;
+  return ret;
+}
+
+std::string QueryCertificateAuthorCertificate(const std::string& pkgid,
+                                              uid_t uid) {
+  pkgmgrinfo_certinfo_h handle;
+  int ret = pkgmgrinfo_pkginfo_create_certinfo(&handle);
+  if (ret != PMINFO_R_OK) {
+    LOG(DEBUG) << "pkgmgrinfo_pkginfo_create_certinfo failed with error: "
+               << ret;
+    return {};
+  }
+  ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid.c_str(), handle, uid);
   if (ret != PMINFO_R_OK) {
     if (ret != PMINFO_R_ENOENT)
-      LOG(ERROR) << "Failed to call pkgmgrinfo_pkginfo_get_usr_pkginfo";
-    return false;
+      LOG(DEBUG) << "pkgmgrinfo_pkginfo_load_certinfo failed with error: "
+                 << ret;
+    pkgmgrinfo_pkginfo_destroy_certinfo(handle);
+    return {};
   }
+  const char* author_cert = nullptr;
+  ret = pkgmgrinfo_pkginfo_get_cert_value(handle, PMINFO_AUTHOR_SIGNER_CERT,
+                                          &author_cert);
+  if (ret != PMINFO_R_OK) {
+    LOG(DEBUG) << "pkgmgrinfo_pkginfo_get_cert_value failed with error: "
+               << ret;
+    pkgmgrinfo_pkginfo_destroy_certinfo(handle);
+    return {};
+  }
+  std::string old_author_certificate;
+  if (author_cert)
+    old_author_certificate = author_cert;
+  pkgmgrinfo_pkginfo_destroy_certinfo(handle);
+  return old_author_certificate;
+}
 
-  bool is_removable = false;
-  if (pkgmgrinfo_pkginfo_is_removable(handle, &is_removable) != PMINFO_R_OK) {
-    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_removable failed";
-    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+bool QueryIsDisabledPackage(const std::string& pkg_id, uid_t uid) {
+  pkgmgrinfo_pkginfo_h handle;
+  int ret = pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkg_id.c_str(),
+              uid, &handle);
+  if (ret != PMINFO_R_OK) {
+    if (ret != PMINFO_R_ENOENT)
+      LOG(ERROR) <<
+          "Failed to call pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo";
     return false;
   }
 
   pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-  return is_removable;
+  return true;
 }
 
 }  // namespace common_installer
index c3d8ccc..f815414 100644 (file)
@@ -6,6 +6,7 @@
 #define COMMON_PKGMGR_QUERY_H_
 
 #include <unistd.h>
+#include <pkgmgr-info.h>
 
 #include <string>
 #include <vector>
 namespace common_installer {
 
 /**
+ * \brief Adapter interface for external PkgMgr module.
+ */
+class PkgQueryInterface {
+ public:
+  PkgQueryInterface() = delete;
+  PkgQueryInterface(const std::string& pkgid, uid_t uid);
+  ~PkgQueryInterface();
+
+  bool IsValid();
+
+  /**
+   * \brief Returns tizen extension package path for given package.
+   *
+   * @return path or empty
+   */
+  std::string TepPath();
+
+  /**
+   * \brief Returns zip mount path for given package.
+   *
+   * @return path or empty
+   */
+  std::string ZipMountFile();
+
+  /**
+   * \brief Returns storage for given package.
+   *
+   * @return path or empty
+   */
+  std::string StorageForPkgId();
+
+  /**
+   * \brief Checks if given package is installed/registered.
+   *
+   * \param request_mode request mode
+   *
+   * \return true if package is installed
+   */
+  bool IsPackageInstalled(RequestMode request_mode = RequestMode::USER);
+
+  /**
+   * \brief Checks if given package is global package.
+   *
+   * \param request_mode request mode
+   *
+   * \return t true if package is global package
+   */
+  bool IsGlobalPackage();
+
+  /**
+   * \brief Checks if given package is readonly package.
+   *
+   * \param request_mode request mode
+   *
+   * \return true if package is readonly
+   */
+  bool IsReadonlyPackage();
+
+  /**
+   * \brief Checks if given package is updated package.
+   *
+   * \param request_mode request mode
+   *
+   * \return true if package is updated
+   */
+  bool IsUpdatedPackage();
+
+  /**
+   * \brief Checks if given package is preloaded package.
+   *
+   * \param request_mode request mode
+   *
+   * \return true if package is preloaded
+   */
+  bool IsPreloadPackage();
+
+  /**
+   * \brief Checks if given package is system package.
+   *
+   * \return true if package is system package
+   */
+  bool IsSystemPackage();
+
+  /**
+   * \brief Checks if given package is removable package.
+   *
+   * \return true if package is removable package
+   */
+  bool IsRemovablePackage();
+
+  /**
+   * \brief Returns list of appids for given package.
+   *
+   * \param result[out] Output
+   *
+   * \return true if success
+   */
+  bool AppidsForPkgId(std::vector<std::string>* result);
+  /**
+   * \brief Returns list of privileges for given package
+   *
+   * \param result result - privileges
+   *
+   * \return true if success
+   */
+  bool PrivilegesForPkgId(std::vector<std::string>* result);
+
+ private:
+  std::string pkgid_;
+  uid_t uid_;
+  pkgmgrinfo_pkginfo_h handle_;
+};
+
+/**
  * \brief Adapter interface for external PkgMgr module used for getting
  *        certificate information for given package
  *
@@ -27,109 +142,6 @@ std::string QueryCertificateAuthorCertificate(const std::string& pkgid,
                                               uid_t uid);
 
 /**
- * \brief Adapter interface for external PkgMgr module used for getting
- *        tizen extension package path for given package
- *
- * @param pkgid package id
- * @param uid user id
- * @return path or empty
- */
-std::string QueryTepPath(const std::string& pkgid, uid_t uid);
-
-/**
- * \brief Adapter interface for external PkgMgr module used for getting
- *        zip mount path for given package
- *
- * @param pkgid package id
- * @param uid user id
- * @return path or empty
- */
-std::string QueryZipMountFile(const std::string& pkgid, uid_t uid);
-
-/**
- * \brief Adapter interface for external PkgMgr module used for getting
- *        list of appids for given package
- *
- * \param pkg_id[in] package pkgid
- * \param result[out] Output
- * \param uid user id
- *
- * \return true if success
- */
-bool QueryAppidsForPkgId(const std::string& pkg_id,
-                         std::vector<std::string>* result, uid_t uid);
-
-/**
- * \brief Adapter interface for external PkgMgr module used for getting
- *        list of privileges for given package
- *
- * \param pkg_id id of package
- * \param uid user id
- * \param result result - privileges
- *
- * \return true if success
- */
-bool QueryPrivilegesForPkgId(const std::string& pkg_id, uid_t uid,
-                             std::vector<std::string>* result);
-
-/**
- * \brief Adapter interface for external PkgMgr module used for getting
- *        storage for given package
- *
- * \param pkg_id id of package
- * \param uid user id
- *
- * \return storage name of empty if not installed
- */
-std::string QueryStorageForPkgId(const std::string& pkg_id, uid_t uid);
-
-/**
- * \brief Adapter interface for external PkgMgr module used for checking
- *        if given package is installed/registered
- *
- * \param pkg_id package id
- * \param request_mode request mode
- * \param uid user id
- *
- * \return true if package is installed
- */
-bool QueryIsPackageInstalled(const std::string& pkg_id,
-                             RequestMode request_mode, uid_t uid);
-
-/**
- * \brief Adapter interface for external PkgMgr module used for checking
- *        if given package is installed/registered per given uid only
- *
- * \param pkg_id package id
- * \param uid user id
- *
- * \return true if package is installed
- */
-bool QueryIsPackageInstalled(const std::string& pkg_id, uid_t uid);
-
-/**
- * \brief Adapter interface for external PkgMgr module used for checking
- *        if given package is global package
- *
- * \param pkg_id package id
- * \param uid user id
- *
- * \return true if package is global package
- */
-bool QueryIsGlobalPackage(const std::string& pkg_id, uid_t uid);
-
-/**
- * \brief Adapter interface for external PkgMgr module used for checking
- *        if given package is readonly package
- *
- * \param pkg_id package id
- * \param uid user id
- *
- * \return true if package is readonly
- */
-bool QueryIsReadonlyPackage(const std::string& pkg_id, uid_t uid);
-
-/**
  * \brief Adapter interface for external PkgMgr module used for checking
  *        if given package is disabled package
  *
@@ -140,50 +152,6 @@ bool QueryIsReadonlyPackage(const std::string& pkg_id, uid_t uid);
  */
 bool QueryIsDisabledPackage(const std::string& pkg_id, uid_t uid);
 
-/**
- * \brief Adapter interface for external PkgMgr module used for checking
- *        if given package is updated package
- *
- * \param pkg_id package id
- * \param uid user id
- *
- * \return true if package is updated
- */
-bool QueryIsUpdatedPackage(const std::string& pkg_id, uid_t uid);
-
-/**
- * \brief Adapter interface for external PkgMgr module used for checking
- *        if given package is preloaded package
- *
- * \param pkg_id package id
- * \param uid user id
- *
- * \return true if package is preloaded
- */
-bool QueryIsPreloadPackage(const std::string& pkg_id, uid_t uid);
-
-/**
- * \brief Adapter interface for external PkgMgr module used for checking
- *        if given package is system package
- *
- * \param pkg_id package id
- * \param uid user id
- *
- * \return true if package is system package
- */
-bool QueryIsSystemPackage(const std::string& pkg_id, uid_t uid);
-
-/**
- * \brief Adapter interface for external PkgMgr module used for checking
- *        if given package is removable package
- *
- * \param pkg_id package id
- * \param uid user id
- *
- * \return true if package is removable package
- */
-bool QueryIsRemovablePackage(const std::string& pkg_id, uid_t uid);
-
 }  // namespace common_installer
 
 #endif  // COMMON_PKGMGR_QUERY_H_
index 3a93205..c74eb6e 100644 (file)
@@ -229,7 +229,8 @@ const char* PkgmgrSignal::GetResultKey(Step::Status result) const {
 bool PkgmgrSignal::SendAppids(const std::string& type,
                               const std::string& pkgid) const {
   std::vector<std::string> appids;
-  if (!QueryAppidsForPkgId(pkgid, &appids, pkgmgr_installer_get_uid(pi_)))
+  ci::PkgQueryInterface pkg_query(pkgid, pkgmgr_installer_get_uid(pi_));
+  if (!pkg_query.AppidsForPkgId(&appids))
     return true;
   for (auto& appid : appids) {
     if (pkgmgr_installer_send_app_uninstall_signal(pi_, type.c_str(),
@@ -244,7 +245,8 @@ bool PkgmgrSignal::SendAppids(uid_t uid,
                               const std::string& type,
                               const std::string& pkgid) const {
   std::vector<std::string> appids;
-  if (!QueryAppidsForPkgId(pkgid, &appids, pkgmgr_installer_get_uid(pi_)))
+  ci::PkgQueryInterface pkg_query(pkgid, pkgmgr_installer_get_uid(pi_));
+  if (!pkg_query.AppidsForPkgId(&appids))
     return true;
   for (auto& appid : appids) {
     if (pkgmgr_installer_send_app_uninstall_signal_for_uid(
@@ -261,12 +263,13 @@ bool PkgmgrSignal::SetupUserList(const std::string& pkgid) {
 
   if (n < 0)
     return false;
-
+  ci::PkgQueryInterface pkg_query_for_global(pkgid, kGlobalUserUid);
   for (i = 0; i < n; i++) {
+    ci::PkgQueryInterface pkg_query(pkgid, uids[i]);
     switch (request_mode_) {
       case RequestMode::GLOBAL:
         // if user pkg is installed, installer will not send signal to user.
-        if (QueryIsPackageInstalled(pkgid, RequestMode::USER, uids[i]))
+        if (pkg_query.IsPackageInstalled(RequestMode::USER))
           continue;
         else
           user_list_.emplace_back(uids[i], request_type_);
@@ -276,7 +279,7 @@ bool PkgmgrSignal::SetupUserList(const std::string& pkgid) {
           continue;
         // if global pkg is installed,
         // user pkg operation will be handled as update.
-        if (QueryIsPackageInstalled(pkgid, kGlobalUserUid))
+        if (pkg_query_for_global.IsPackageInstalled())
           user_list_.emplace_back(uids[i], RequestType::Update);
         else
           user_list_.emplace_back(uids[i], request_type_);
index c936096..2950398 100644 (file)
@@ -431,7 +431,8 @@ bool UnregisterSecurityContextForManifest(const std::string& pkg_id,
 bool UnregisterSecurityContextForPkgId(const std::string &pkg_id,
     uid_t uid, std::string* error_message, bool ignore_data_absence) {
   std::vector<std::string> appids;
-  if (!QueryAppidsForPkgId(pkg_id, &appids, uid))
+  ci::PkgQueryInterface pkg_query(pkg_id, uid);
+  if (!pkg_query.AppidsForPkgId(&appids))
     return ignore_data_absence;
   for (auto& appid : appids) {
     if (!UnregisterSecurityContext(appid, pkg_id, uid, error_message)) {
index 32fea9d..f8d6343 100644 (file)
@@ -463,8 +463,9 @@ bool PerformExternalDirectoryDeletionForAllUsers(const std::string& pkgid) {
   UserList list = ci::GetUserList();
   for (auto l : list) {
     uid_t uid = std::get<0>(l);
+    ci::PkgQueryInterface pkg_query(pkgid, uid);
     LOG(DEBUG) << "Deleting directories for user: " << uid;
-    if (QueryIsPackageInstalled(pkgid, uid)) {
+    if (pkg_query.IsPackageInstalled()) {
       LOG(DEBUG) << "Package: " << pkgid << " for uid: " << uid
                  << " still exists. Skipping";
       continue;
@@ -564,7 +565,9 @@ bool DeleteSkelDirectories(const std::string& pkgid) {
 bool DeleteUserDirectories(const std::string& pkgid) {
   UserList list = ci::GetUserList();
   for (auto l : list) {
-    if (ci::QueryIsPackageInstalled(pkgid, std::get<0>(l))) {
+    uid_t uid = std::get<0>(l);
+    ci::PkgQueryInterface pkg_query(pkgid, uid);
+    if (pkg_query.IsPackageInstalled()) {
       LOG(INFO) << pkgid << " is installed for user " << std::get<0>(l);
       continue;
     }
@@ -582,13 +585,15 @@ bool DeleteUserDirectories(const std::string& pkgid) {
 bool DeleteUserExternalDirectories(const std::string& pkgid) {
   UserList list = ci::GetUserList();
   for (auto l : list) {
-    if (ci::QueryIsPackageInstalled(pkgid, std::get<0>(l))) {
-      LOG(INFO) << pkgid << " is installed for user " << std::get<0>(l);
+    uid_t uid = std::get<0>(l);
+    ci::PkgQueryInterface pkg_query(pkgid, uid);
+    if (pkg_query.IsPackageInstalled()) {
+      LOG(INFO) << pkgid << " is installed for user " << uid;
       continue;
     }
 
     LOG(DEBUG) << "Deleting external directories of " << pkgid
-               << ", for uid: " << std::get<0>(l);
+               << ", for uid: " << uid;
     bf::path apps_rw(std::get<2>(l) / "apps_rw");
     if (!DeleteDirectories(apps_rw, pkgid)) {
       return false;
@@ -619,7 +624,7 @@ bool CopyUserDirectories(const std::string& pkgid) {
         return false;
     }
     std::string error_message;
-    if (!RegisterSecurityContextForPath(pkgid, dst, std::get<0>(l),
+    if (!RegisterSecurityContextForPath(pkgid, dst, uid,
         false, &error_message)) {
       LOG(ERROR) << "Failed to register security context for path: " << dst
                  << ", error_message: " << error_message;
@@ -652,7 +657,7 @@ bool UpdateUserDirectory(const std::string& pkgid, bool is_remove_shareddata) {
         return false;
 
       std::string error_message;
-      if (!RegisterSecurityContextForPath(pkgid, root_dst, std::get<0>(l),
+      if (!RegisterSecurityContextForPath(pkgid, root_dst, uid,
           false, &error_message)) {
         LOG(ERROR) << "Failed to register security context for path: "
                    << root_dst << ", error_message: " << error_message;
@@ -678,7 +683,8 @@ bool CreateGlobalAppSymlinksForAllUsers(const std::string& pkgid) {
     uid_t uid = std::get<0>(l);
     LOG(DEBUG) << "Creating symlinks for uid: " << uid;
     // check installed user private app.
-    if (QueryIsPackageInstalled(pkgid, uid))
+    ci::PkgQueryInterface pkg_query(pkgid, uid);
+    if (pkg_query.IsPackageInstalled())
       continue;
     bf::path apps_rw(std::get<2>(l) / "apps_rw");
     bf::path dst_dir = apps_rw / pkgid;
@@ -723,7 +729,8 @@ bool DeleteGlobalAppSymlinksForAllUsers(const std::string& pkgid) {
     uid_t uid = std::get<0>(l);
     LOG(DEBUG) << "Deleting symlinks for uid: " << uid;
     // check installed user private app.
-    if (QueryIsPackageInstalled(pkgid, uid))
+    ci::PkgQueryInterface pkg_query(pkgid, uid);
+    if (pkg_query.IsPackageInstalled())
       continue;
     bf::path apps_rw(std::get<2>(l) / "apps_rw");
     bf::path dst_dir = apps_rw / pkgid;
index bbbe55e..f368501 100644 (file)
@@ -29,8 +29,8 @@ namespace configuration {
 
 Step::Status StepCheckInstallLocation::process() {
   manifest_x* manifest = context_->manifest_data.get();
-  if (!QueryIsPackageInstalled(context_->pkgid.get(),
-      context_->request_mode.get(), context_->uid.get())) {
+  PkgQueryInterface pkg_query(context_->pkgid.get(), context_->uid.get());
+  if (!pkg_query.IsPackageInstalled(context_->request_mode.get())) {
     // int type vconf value:
     // 0 means internal storage, 1 means external storage
     int default_storage = 0;
@@ -44,8 +44,7 @@ Step::Status StepCheckInstallLocation::process() {
     else
       context_->storage.set(Storage::EXTENDED);
   } else {
-    std::string storage = QueryStorageForPkgId(context_->pkgid.get(),
-        context_->uid.get());
+    std::string storage = pkg_query.StorageForPkgId();
     if (storage == kInstalledInternally) {
       context_->storage.set(Storage::INTERNAL);
     } else if (storage == kInstalledExternally) {
index a445b39..3089f64 100644 (file)
@@ -124,7 +124,8 @@ bool StepParseManifest::LocateConfigFile() {
     case ManifestLocation::INSTALLED: {
       uid_t uid;
       bool is_readonly = context_->is_readonly_package.get();
-      if (QueryIsGlobalPackage(context_->pkgid.get(), context_->uid.get()))
+      PkgQueryInterface pkg_query(context_->pkgid.get(), context_->uid.get());
+      if (pkg_query.IsGlobalPackage())
         uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
       else
         uid = context_->uid.get();
@@ -275,8 +276,8 @@ bool StepParseManifest::FillPackageInfo(manifest_x* manifest) {
   // we must know it
   if (manifest_location_ == ManifestLocation::INSTALLED ||
       manifest_location_ == ManifestLocation::RECOVERY) {
-    std::string storage = QueryStorageForPkgId(manifest->package,
-                                              context_->uid.get());
+    PkgQueryInterface pkg_query(manifest->package, context_->uid.get());
+    std::string storage = pkg_query.StorageForPkgId();
     if (storage.empty()) {
         // Failed to query installation storage, assign internal
         manifest->installed_storage = strdup(kInstalledInternally);
@@ -1051,14 +1052,13 @@ bool StepParseManifest::FillBackgroundCategoryInfo(application_x* app,
 bool StepParseManifest::FillExtraInfo(manifest_x* manifest) {
   if (manifest_location_ == ManifestLocation::INSTALLED) {
     // recovery of tep value for installed package
-    std::string old_tep =
-        QueryTepPath(context_->pkgid.get(), context_->uid.get());
+    PkgQueryInterface pkg_query(context_->pkgid.get(), context_->uid.get());
+    std::string old_tep = pkg_query.TepPath();
     if (!old_tep.empty())
       manifest->tep_name = strdup(old_tep.c_str());
 
     // recovery of zip mount file for installed package
-    std::string zip_mount_file =
-        QueryZipMountFile(context_->pkgid.get(), context_->uid.get());
+    std::string zip_mount_file = pkg_query.ZipMountFile();
     if (!zip_mount_file.empty())
       manifest->zip_mount_file = strdup(zip_mount_file.c_str());
   }
index c81ba20..9f333c2 100644 (file)
@@ -41,6 +41,7 @@ ci::Step::Status StepParsePreload::process() {
     }
   }
 
+  PkgQueryInterface pkg_query(context_->pkgid.get(), context_->uid.get());
   RequestType req_type = context_->request_type.get();
   const char* preload_val = context_->manifest_data.get()->preload;
   if (!preload_val || (preload_val && strlen(preload_val) == 0)) {
@@ -51,8 +52,7 @@ ci::Step::Status StepParsePreload::process() {
         req_type == RequestType::MountUpdate ||
         req_type == RequestType::ReadonlyUpdateInstall) {
       // In case of update, keep preload value
-      bool is_preload = QueryIsPreloadPackage(context_->pkgid.get(),
-          context_->uid.get());
+      bool is_preload = pkg_query.IsPreloadPackage();
       context_->manifest_data.get()->preload =
           strdup(is_preload ? "true" : "false");
     } else {
@@ -102,10 +102,10 @@ ci::Step::Status StepParsePreload::process() {
   if (req_type == RequestType::ReadonlyUpdateUninstall)
     manifest->update = strdup("false");
   // set update true if package is updated preload package
-  else if (QueryIsUpdatedPackage(context_->pkgid.get(), context_->uid.get()))
+  else if (pkg_query.IsUpdatedPackage())
     manifest->update = strdup("true");
   // set update true when update non-removable preload package
-  else if (QueryIsPreloadPackage(context_->pkgid.get(), context_->uid.get()) &&
+  else if (pkg_query.IsPreloadPackage() &&
       (req_type == RequestType::Update ||
        req_type == RequestType::Delta ||
        req_type == RequestType::MountUpdate ||
@@ -126,14 +126,14 @@ ci::Step::Status StepParsePreload::process() {
           (manifest->removable && !strcmp(manifest->removable, "false"))))
     manifest->system = strdup("true");
   // set system false when update non-removable RW preload package
-  else if (QueryIsSystemPackage(context_->pkgid.get(), context_->uid.get()) &&
-      !QueryIsReadonlyPackage(context_->pkgid.get(), context_->uid.get()) &&
-      !QueryIsUpdatedPackage(context_->pkgid.get(), context_->uid.get()))
+  else if (pkg_query.IsSystemPackage() &&
+      !pkg_query.IsReadonlyPackage() &&
+      !pkg_query.IsUpdatedPackage())
     manifest->system = strdup("false");
   // set system true when update RO preload package
   else if (req_type == RequestType::ReadonlyUpdateInstall ||
       req_type == RequestType::ReadonlyUpdateUninstall ||
-      QueryIsSystemPackage(context_->pkgid.get(), context_->uid.get()))
+      pkg_query.IsSystemPackage())
     manifest->system = strdup("true");
   else
     manifest->system = strdup("false");
index 4ca7d4c..046e877 100644 (file)
@@ -27,8 +27,9 @@ common_installer::Step::Status StepCreateGlobalAppSymlinks::process() {
   std::string package_id = context_->pkgid.get();
 
   if (context_->request_type.get() == RequestType::Uninstall) {
+    PkgQueryInterface pkg_query(context_->pkgid.get(), kGlobalUserUid);
     if ((context_->request_mode.get() == RequestMode::USER) &&
-        QueryIsPackageInstalled(context_->pkgid.get(), kGlobalUserUid)) {
+        pkg_query.IsPackageInstalled()) {
       LOG(INFO) << "Creating globalapp symlinks for current user, package: "
               << package_id;
       if (!CreateGlobalAppSymlinksForUser(package_id, context_->uid.get())) {
index 9066ff7..6caa6d1 100644 (file)
@@ -56,11 +56,11 @@ Step::Status StepMigrateLegacyExtImage::precheck() {
 Step::Status StepMigrateLegacyExtImage::process() {
   std::string pkgid = context_->pkgid.get();
   uid_t uid = context_->uid.get();
-  if (QueryIsGlobalPackage(pkgid, uid))
+  PkgQueryInterface pkg_query(pkgid, uid);
+  if (pkg_query.IsGlobalPackage())
     context_->uid.set(kGlobalUserUid);
 
-  std::string storage_str = QueryStorageForPkgId(context_->pkgid.get(),
-      context_->uid.get());
+  std::string storage_str = pkg_query.StorageForPkgId();
   if (strcmp(storage_str.c_str(), kInstalledExternally)) {
     LOG(ERROR) << "Pkg not installed at external storage";
     return Step::Status::ERROR;
index 6499275..cd566c9 100644 (file)
@@ -31,8 +31,9 @@ namespace common_installer {
 namespace filesystem {
 
 Step::Status StepMoveInstalledStorage::process() {
-  std::string installed_storage = QueryStorageForPkgId(context_->pkgid.get(),
+  PkgQueryInterface pkg_query(context_->pkgid.get(),
       context_->uid.get());
+  std::string installed_storage = pkg_query.StorageForPkgId();
 
   if ((move_type_ == MoveType::TO_INTERNAL &&
           installed_storage == "installed_external") ||
index dbeb326..9bc4356 100644 (file)
@@ -30,8 +30,8 @@ StepOptionalAcquireExternalStorage::StepOptionalAcquireExternalStorage(
 Step::Status StepOptionalAcquireExternalStorage::process() {
   Storage storage = Storage::INTERNAL;
 
-  std::string storage_str = QueryStorageForPkgId(context_->pkgid.get(),
-      context_->uid.get());
+  PkgQueryInterface pkg_query(context_->pkgid.get(), context_->uid.get());
+  std::string storage_str = pkg_query.StorageForPkgId();
   if (!strcmp(storage_str.c_str(), kInstalledExternally))
     storage = Storage::EXTERNAL;
   else
index 817f330..a49e6ad 100644 (file)
@@ -72,7 +72,8 @@ Step::Status StepRemoveFiles::process() {
 
   bool is_keep_rwdata = false;
   if (context_->request_mode.get() != RequestMode::GLOBAL) {
-    if (QueryIsPackageInstalled(context_->pkgid.get(), kGlobalUserUid) ||
+    PkgQueryInterface pkg_query(context_->pkgid.get(), kGlobalUserUid);
+    if (pkg_query.IsPackageInstalled() ||
         context_->keep_rwdata.get())
       is_keep_rwdata = true;
   }
index dae5712..80c6fce 100644 (file)
@@ -29,7 +29,8 @@ Step::Status StepRemoveGlobalAppSymlinks::process() {
   if (context_->request_mode.get() != RequestMode::GLOBAL)
     return Step::Status::OK;
 
-  if (!QueryIsPackageInstalled(context_->pkgid.get(), kGlobalUserUid))
+  PkgQueryInterface pkg_query(context_->pkgid.get(), kGlobalUserUid);
+  if (!pkg_query.IsPackageInstalled())
     return Step::Status::OK;
 
   std::string package_id = context_->pkgid.get();
index 42ab4ad..90be356 100644 (file)
@@ -31,8 +31,9 @@ Step::Status StepCheckForceClean::process() {
                                           context_->is_readonly_package.get());
 
   // if manifeset not found but pkg exist in db for target uid, do clean
+  PkgQueryInterface pkg_query(context_->pkgid.get(), context_->uid.get());
   if (!bf::exists(xml_path) &&
-      QueryIsPackageInstalled(context_->pkgid.get(), context_->uid.get())) {
+      pkg_query.IsPackageInstalled()) {
     context_->force_clean_from_db.set(true);
     manifest_x* manifest =
         static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)));
index 64a4380..863071c 100644 (file)
@@ -22,22 +22,26 @@ namespace pkgmgr {
 
 Step::Status StepCheckInstallable::process() {
   switch (context_->request_mode.get()) {
-    case RequestMode::USER:
-      if (QueryIsPackageInstalled(context_->pkgid.get(), kGlobalUserUid)) {
+    case RequestMode::USER: {
+      PkgQueryInterface pkg_query(context_->pkgid.get(), kGlobalUserUid);
+      if (pkg_query.IsPackageInstalled()) {
         LOG(ERROR) << "This package is already installed as global package";
         return Status::OPERATION_NOT_ALLOWED;
       }
+    }
       break;
-    case RequestMode::GLOBAL:
+    case RequestMode::GLOBAL: {
       UserList list = GetUserList();
       for (auto l : list) {
         uid_t uid = std::get<0>(l);
-        if (QueryIsPackageInstalled(context_->pkgid.get(), uid)) {
+        PkgQueryInterface pkg_query(context_->pkgid.get(), uid);
+        if (pkg_query.IsPackageInstalled()) {
           LOG(ERROR) << "This package is already installed by user("
                      << uid << ")";
           return Status::OPERATION_NOT_ALLOWED;
         }
       }
+    }
       break;
   }
   return Status::OK;
index e1a06ab..5d22d53 100644 (file)
@@ -64,9 +64,10 @@ namespace common_installer {
 bf::path GetManifestLocation(const std::string& pkgid,
                              uid_t uid,
                              bool is_readonly) {
-  if (QueryIsGlobalPackage(pkgid.c_str(), uid)) {
+  PkgQueryInterface pkg_query(pkgid, uid);
+  if (pkg_query.IsGlobalPackage()) {
     uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
-    is_readonly = QueryIsReadonlyPackage(pkgid.c_str(), uid);
+    is_readonly = pkg_query.IsReadonlyPackage();
   }
   bf::path xml_path = bf::path(getUserManifestPath(uid, is_readonly))
                       / bf::path(pkgid.c_str());