Workaround - sending appid during deinstallation 51/48251/3 accepted/tizen/mobile/20150918.024754 accepted/tizen/mobile/20150918.040323 accepted/tizen/tv/20150918.024810 accepted/tizen/tv/20150918.040335 accepted/tizen/wearable/20150918.024827 accepted/tizen/wearable/20150918.040348 submit/tizen/20150917.081152 submit/tizen/20150918.000000
authorTomasz Iwanek <t.iwanek@samsung.com>
Wed, 16 Sep 2015 12:28:55 +0000 (14:28 +0200)
committerPawel Sikorski <p.sikorski@samsung.com>
Thu, 17 Sep 2015 08:04:23 +0000 (01:04 -0700)
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
src/common/pkgmgr_registration.h
src/common/pkgmgr_signal.cc
src/common/pkgmgr_signal.h

index 69ff5fa..0a505a0 100644 (file)
@@ -52,6 +52,16 @@ bool RegisterAuthorCertificate(
   return true;
 }
 
+int PkgmgrForeachAppCallback(const pkgmgrinfo_appinfo_h handle,
+                              void *user_data) {
+  auto* data = static_cast<std::vector<std::string>*>(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<std::string>* 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(),
index 43ef34b..dec8052 100644 (file)
@@ -10,6 +10,7 @@
 #include <unistd.h>
 
 #include <string>
+#include <vector>
 
 #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<std::string>* result, uid_t uid);
 bool IsPackageInstalled(const std::string& pkg_id, RequestMode request_mode);
 
 }  // namespace common_installer
index 7970c45..ee3c17a 100644 (file)
@@ -4,9 +4,14 @@
 
 #include "common/pkgmgr_signal.h"
 
+#include <unistd.h>
+#include <sys/types.h>
+
 #include <cassert>
 #include <map>
+#include <vector>
 
+#include "common/pkgmgr_registration.h"
 #include "common/utils/logging.h"
 
 // Redefine this value as it is not exported by pkgmgr
 
 namespace {
 
-namespace ci=common_installer;
+namespace ci = common_installer;
 
-const std::map<ci::RequestType,const char *> kEventStr = {
+const std::map<ci::RequestType, const char*> 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<std::string> 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
index 87eb750..0744a47 100644 (file)
@@ -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_;