Modify sending AUL signal
[platform/core/appfw/app-installers.git] / src / common / pkgmgr_signal.cc
index 2c90ecc..1f5ba98 100644 (file)
@@ -6,6 +6,8 @@
 
 #include <manifest_parser/utils/logging.h>
 
+#include <aul.h>
+#include <bundle_cpp.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <systemd/sd-login.h>
@@ -54,7 +56,7 @@ namespace common_installer {
 
 PkgmgrSignal::PkgmgrSignal(pkgmgr_installer* pi)
     : pi_(pi), state_(State::NOT_SENT), request_type_(RequestType::Unknown),
-      error_message_sent_(false) {
+      error_message_sent_(false), is_upgrade_(false) {
   uid_ = pkgmgr_installer_get_uid(pi_);
   request_mode_ = GetRequestMode(uid_);
 }
@@ -71,6 +73,11 @@ bool PkgmgrSignal::SendStarted(
   if (key == kEventStr.end())
     return false;
 
+  if (strcmp(key->second, PKGMGR_INSTALLER_UPGRADE_EVENT_STR) == 0)
+    is_upgrade_ = true;
+
+  pkgmgr_installer_set_is_upgrade(pi_, is_upgrade_ ? 1 : 0);
+
   if (!SendSignal(PKGMGR_INSTALLER_START_KEY_STR, key->second, type, pkgid))
     return false;
 
@@ -117,6 +124,8 @@ bool PkgmgrSignal::SendFinished(
   if (state_ != State::STARTED)
     return false;
 
+  pkgmgr_installer_set_is_upgrade(pi_, is_upgrade_ ? 1 : 0);
+
   if (result != Step::Status::OK && !error_message_sent_) {
     if (!SendSignal(
         PKGMGR_INSTALLER_ERROR_KEY_STR,
@@ -128,6 +137,7 @@ bool PkgmgrSignal::SendFinished(
           PKGMGR_INSTALLER_ERROR_KEY_STR,
           std::to_string(static_cast<int>(result)).c_str(), type, pkgid);
   }
+
   if (!SendSignal(
       PKGMGR_INSTALLER_END_KEY_STR, GetResultKey(result), type, pkgid))
     return false;
@@ -135,6 +145,7 @@ bool PkgmgrSignal::SendFinished(
   for (auto l : user_list_)
     SendSignal(l.first,
         PKGMGR_INSTALLER_END_KEY_STR, GetResultKey(result), type, pkgid);
+
   state_ = State::FINISHED;
   return true;
 }
@@ -147,6 +158,8 @@ bool PkgmgrSignal::SendError(
   if (state_ != State::STARTED)
     return false;
 
+  pkgmgr_installer_set_is_upgrade(pi_, is_upgrade_ ? 1 : 0);
+
   std::string error_value = std::to_string(static_cast<int>(result));
   if (!error_message.empty())
     error_value = error_value + ":" + error_message;
@@ -177,6 +190,19 @@ bool PkgmgrSignal::SendSignal(
     const char* value,
     const std::string& type,
     const std::string& pkgid) const {
+  if (!strcmp(key, "start") || !strcmp(key, "error") || !strcmp(key, "end")) {
+    uid_t uid = pkgmgr_installer_get_uid(pi_);
+    tizen_base::Bundle b({
+        { AUL_K_PKGID, pkgid },
+        { AUL_K_PACKAGETYPE, type },
+        { AUL_K_PKG_EVENT_NAME, key },
+        { AUL_K_PKG_EVENT_RESULT, value }
+        });
+
+    if (aul_package_pre_event_send(uid, b.GetHandle()) != AUL_R_OK)
+      LOG(ERROR) << "aul_package_pre_event_send() is failed";
+  }
+
   // send pkgmgr signal
   if (pkgmgr_installer_send_signal(
         pi_,
@@ -280,12 +306,7 @@ bool PkgmgrSignal::SetupUserList(const std::string& pkgid) {
       case RequestMode::USER:
         if (uid_ != uids[i])
           continue;
-        // if global pkg is installed,
-        // user pkg operation will be handled as update.
-        if (pkg_query_for_global.IsPackageInstalled(ci::RequestMode::GLOBAL))
-          user_list_.emplace_back(uids[i], RequestType::Update);
-        else
-          user_list_.emplace_back(uids[i], request_type_);
+        user_list_.emplace_back(uids[i], request_type_);
         break;
       default:
         user_list_.emplace_back(uids[i], request_type_);