From 6e584aedbe55e7ccce0fac4c164f444c0596bb9c Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Wed, 16 Sep 2015 14:28:55 +0200 Subject: [PATCH] Workaround - sending appid during deinstallation Web application application plugin needs information about uninstalled application but it cannot get it from database during uninstallation. Therefore, this workaround is provided to send appids explicitly. Submit after: https://review.tizen.org/gerrit/48250 Change-Id: I8138c888c17a0421caf87c29f20599e7eed962ef --- src/common/pkgmgr_registration.cc | 25 +++++++++++++++++++++++++ src/common/pkgmgr_registration.h | 3 +++ src/common/pkgmgr_signal.cc | 32 +++++++++++++++++++++++++++++--- src/common/pkgmgr_signal.h | 1 + 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/common/pkgmgr_registration.cc b/src/common/pkgmgr_registration.cc index 69ff5fa..0a505a0 100644 --- a/src/common/pkgmgr_registration.cc +++ b/src/common/pkgmgr_registration.cc @@ -52,6 +52,16 @@ bool RegisterAuthorCertificate( return true; } +int PkgmgrForeachAppCallback(const pkgmgrinfo_appinfo_h handle, + void *user_data) { + auto* data = static_cast*>(user_data); + char* app_id = nullptr; + if (pkgmgrinfo_appinfo_get_appid(handle, &app_id) != PMINFO_R_OK) + return PMINFO_R_ERROR; + data->emplace_back(app_id); + return PMINFO_R_OK; +} + } // anonymous namespace namespace common_installer { @@ -160,6 +170,21 @@ std::string QueryCertificateAuthorCertificate(const std::string& pkgid, return old_author_certificate; } + +bool QueryAppidsForPkgId(const std::string& pkg_id, + std::vector* result, uid_t uid) { + pkgmgrinfo_pkginfo_h package_info; + if (pkgmgrinfo_pkginfo_get_usr_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 IsPackageInstalled(const std::string& pkg_id, RequestMode request_mode) { pkgmgrinfo_pkginfo_h handle; int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkg_id.c_str(), getuid(), diff --git a/src/common/pkgmgr_registration.h b/src/common/pkgmgr_registration.h index 43ef34b..dec8052 100644 --- a/src/common/pkgmgr_registration.h +++ b/src/common/pkgmgr_registration.h @@ -10,6 +10,7 @@ #include #include +#include #include "common/context_installer.h" @@ -31,6 +32,8 @@ bool UnregisterAppInPkgmgr(const boost::filesystem::path& xml_path, RequestMode request_mode); std::string QueryCertificateAuthorCertificate(const std::string& pkgid, uid_t uid); +bool QueryAppidsForPkgId(const std::string& pkg_id, + std::vector* result, uid_t uid); bool IsPackageInstalled(const std::string& pkg_id, RequestMode request_mode); } // namespace common_installer diff --git a/src/common/pkgmgr_signal.cc b/src/common/pkgmgr_signal.cc index 7970c45..ee3c17a 100644 --- a/src/common/pkgmgr_signal.cc +++ b/src/common/pkgmgr_signal.cc @@ -4,9 +4,14 @@ #include "common/pkgmgr_signal.h" +#include +#include + #include #include +#include +#include "common/pkgmgr_registration.h" #include "common/utils/logging.h" // Redefine this value as it is not exported by pkgmgr @@ -16,14 +21,14 @@ namespace { -namespace ci=common_installer; +namespace ci = common_installer; -const std::map kEventStr = { +const std::map kEventStr = { {ci::RequestType::Install, PKGMGR_INSTALLER_INSTALL_EVENT_STR}, {ci::RequestType::Recovery, PKGMGR_INSTALLER_INSTALL_EVENT_STR}, {ci::RequestType::Reinstall, PKGMGR_INSTALLER_INSTALL_EVENT_STR}, {ci::RequestType::Uninstall, PKGMGR_INSTALLER_UNINSTALL_EVENT_STR}, - {ci::RequestType::Unknown, PKGMGR_INSTALLER_INSTALL_EVENT_STR}, //not needed + {ci::RequestType::Unknown, PKGMGR_INSTALLER_INSTALL_EVENT_STR}, // not needed {ci::RequestType::Update, PKGMGR_INSTALLER_UPGRADE_EVENT_STR} }; @@ -47,7 +52,14 @@ bool PkgmgrSignal::SendStarted( if (!SendSignal(PKGMGR_INSTALLER_START_KEY_STR, key->second, type, pkgid)) { return false; } + state_ = State::STARTED; + + // workaround for pkgmgr client to know all appids which are uninstalled + if (request_type_ == ci::RequestType::Uninstall) + if (!SendAppids(type, pkgid)) + return false; + return true; } @@ -113,4 +125,18 @@ const char* PkgmgrSignal::GetResultKey(Step::Status result) const { } } +bool PkgmgrSignal::SendAppids(const std::string& type, + const std::string& pkgid) const { + std::vector appids; + if (!QueryAppidsForPkgId(pkgid, &appids, getuid())) + return true; + for (auto& appid : appids) { + if (!pkgmgr_installer_send_app_uninstall_signal(pi_, type.c_str(), + pkgid.c_str(), + appid.c_str())) + return false; + } + return true; +} + } // namespace common_installer diff --git a/src/common/pkgmgr_signal.h b/src/common/pkgmgr_signal.h index 87eb750..0744a47 100644 --- a/src/common/pkgmgr_signal.h +++ b/src/common/pkgmgr_signal.h @@ -49,6 +49,7 @@ class PkgmgrSignal { const std::string& type = std::string(), const std::string& pkgid = std::string()) const; const char* GetResultKey(Step::Status result) const; + bool SendAppids(const std::string& type, const std::string& pkgid) const; pkgmgr_installer* pi_; static State state_; -- 2.7.4