Fix to send different signal based on recovery info 53/167653/1
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 19 Jan 2018 04:48:00 +0000 (13:48 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 19 Jan 2018 04:48:00 +0000 (13:48 +0900)
- Previous implementation send only "install" signal as value
  when Recovery being performed.
- Installer will send proper signal based on recovery information
  with this changes.

Change-Id: Ia88d72a96af00e562384c38b177ac92b073ac842
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/app_installer.cc
src/common/pkgmgr_signal.cc
src/common/pkgmgr_signal.h

index ef2cf99..0655dda 100644 (file)
@@ -80,7 +80,8 @@ AppInstaller::Result AppInstaller::Run() {
       // send START signal as soon as possible if not sent
       if (pi_->state() == PkgmgrSignal::State::NOT_SENT) {
         if (!context_->pkgid.get().empty()) {
-          pi_->SendStarted(context_->pkg_type.get(), context_->pkgid.get());
+          pi_->SendStarted(context_->pkg_type.get(), context_->pkgid.get(),
+              context_->recovery_info.get());
         }
       }
 
@@ -131,7 +132,8 @@ AppInstaller::Result AppInstaller::Run() {
   if (pi_) {
     // send START if pkgid was not parsed
     if (pi_->state() == PkgmgrSignal::State::NOT_SENT) {
-      pi_->SendStarted(context_->pkg_type.get(), context_->pkgid.get());
+      pi_->SendStarted(context_->pkg_type.get(), context_->pkgid.get(),
+          context_->recovery_info.get());
     }
     pi_->SendFinished(process_status,
                       context_->pkg_type.get(),
index d544423..da070a2 100644 (file)
@@ -59,7 +59,8 @@ PkgmgrSignal::PkgmgrSignal(pkgmgr_installer* pi, RequestType req_type)
 }
 
 bool PkgmgrSignal::SendStarted(
-    const std::string& type, const std::string& pkgid) {
+    const std::string& type, const std::string& pkgid,
+    const RecoveryInfo& recovery_info) {
   if (state_ != State::NOT_SENT) {
     return false;
   }
@@ -71,14 +72,23 @@ bool PkgmgrSignal::SendStarted(
   if (key == kEventStr.end()) {
     return false;
   }
-  if (!SendSignal(PKGMGR_INSTALLER_START_KEY_STR, key->second, type, pkgid)) {
+  const char* value;
+  if (request_type_ == ci::RequestType::Recovery) {
+    value = GetRecoverySignalValue(recovery_info.recovery_file->type());
+    if (!value)
+      return false;
+  }
+  else {
+    value = key->second;
+  }
+  if (!SendSignal(PKGMGR_INSTALLER_START_KEY_STR, value, type, pkgid)) {
     return false;
   }
   for (auto l : user_list_) {
     key = kEventStr.find(l.second);
     if (key == kEventStr.end())
       continue;
-    SendSignal(l.first, PKGMGR_INSTALLER_START_KEY_STR, key->second, type,
+    SendSignal(l.first, PKGMGR_INSTALLER_START_KEY_STR, value, type,
         pkgid);
   }
 
@@ -95,6 +105,24 @@ bool PkgmgrSignal::SendStarted(
   return true;
 }
 
+const char* PkgmgrSignal::GetRecoverySignalValue(RequestType recovery_type) {
+  switch (recovery_type) {
+  case RequestType::Install:
+  case RequestType::Uninstall:
+  case RequestType::MountInstall:
+    return PKGMGR_INSTALLER_UNINSTALL_EVENT_STR;
+  case RequestType::Update:
+  case RequestType::Reinstall:
+  case RequestType::Delta:
+  case RequestType::MountUpdate:
+  case RequestType::ReadonlyUpdateInstall:
+    return PKGMGR_INSTALLER_UPGRADE_EVENT_STR;
+  default:
+    LOG(ERROR) << "Unsupported request type for recovery";
+    return nullptr;
+  }
+}
+
 bool PkgmgrSignal::SendProgress(int progress,
     const std::string& type, const std::string& pkgid) {
   if (state_ != State::STARTED) {
index b5bbd84..899dc20 100644 (file)
@@ -50,12 +50,14 @@ class PkgmgrSignal {
    *
    * \param type package type
    * \param pkgid package pkgid
+   * \param recovery_info recovery information
    *
    * \return true if success
    */
   bool SendStarted(
       const std::string& type = std::string(),
-      const std::string& pkgid = std::string());
+      const std::string& pkgid = std::string(),
+      const RecoveryInfo& recovery_info = RecoveryInfo());
 
   /**
    * "progress" Signal sending
@@ -120,6 +122,7 @@ class PkgmgrSignal {
   bool SendAppids(uid_t uid, const std::string& type,
       const std::string& pkgid) const;
   bool SetupUserList(const std::string& pkgid);
+  const char* GetRecoverySignalValue(RequestType recovery_type);
 
   pkgmgr_installer* pi_;
   static State state_;