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>
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 {
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;
} 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 {
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;
#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>
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 "";
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
#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
*
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
*
*/
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_
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(),
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(
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_);
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_);
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)) {
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;
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;
}
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;
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;
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;
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;
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;
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;
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) {
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();
// 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);
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());
}
}
}
+ 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)) {
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 {
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 ||
(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");
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())) {
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;
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") ||
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
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;
}
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();
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)));
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;
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());