Implement pkg enable/disable 19/78919/5
authorJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 7 Jul 2016 10:19:57 +0000 (19:19 +0900)
committerjongmyeong ko <jongmyeong.ko@samsung.com>
Tue, 12 Jul 2016 06:25:50 +0000 (23:25 -0700)
Related changes
[pkgmgr-tool] https://review.tizen.org/gerrit/78916
[slp-pkgmgr] https://review.tizen.org/gerrit/78917
[pkgmgr-server] https://review.tizen.org/gerrit/78918
[tpk-backend] https://review.tizen.org/gerrit/#/c/79070/

Change-Id: Ie0467a66d133cec859108229a4a499ebcf4d6b21
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/CMakeLists.txt
src/common/pkgmgr_interface.cc
src/common/pkgmgr_registration.cc
src/common/pkgmgr_registration.h
src/common/pkgmgr_signal.cc
src/common/request.h
src/common/step/configuration/step_configure.cc
src/common/step/pkgmgr/step_update_pkg_disable_info.cc [new file with mode: 0644]
src/common/step/pkgmgr/step_update_pkg_disable_info.h [new file with mode: 0644]

index c64a9b0..d0cfdbb 100644 (file)
@@ -69,6 +69,7 @@ SET(SRCS
   step/pkgmgr/step_run_parser_plugins.cc
   step/pkgmgr/step_unregister_app.cc
   step/pkgmgr/step_update_app.cc
+  step/pkgmgr/step_update_pkg_disable_info.cc
   step/rds/step_rds_modify.cc
   step/rds/step_rds_parse.cc
   step/recovery/step_open_recovery_file.cc
index 8c2154f..879c959 100644 (file)
@@ -136,6 +136,10 @@ RequestType PkgMgrInterface::GetRequestType() const {
         return RequestType::MountInstall;
       else
         return RequestType::MountUpdate;
+    case PKGMGR_REQ_DISABLE_PKG:
+      return RequestType::DisablePkg;
+    case PKGMGR_REQ_ENABLE_PKG:
+      return RequestType::EnablePkg;
     default:
       return RequestType::Unknown;
   }
index 537a670..410fa6f 100644 (file)
@@ -253,4 +253,30 @@ bool UpdateTepInfoInPkgmgr(const bf::path& tep_path, const std::string& pkgid,
   return true;
 }
 
+bool DisablePkgInPkgmgr(const std::string& pkgid, uid_t uid,
+                        RequestMode request_mode) {
+  int ret = request_mode != RequestMode::GLOBAL ?
+        pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid.c_str(), uid, 1) :
+        pkgmgr_parser_update_pkg_disable_info_in_db(pkgid.c_str(), 1);
+  if (ret != 0) {
+    LOG(ERROR) << "Failed to disable pkg: " << pkgid;
+    return false;
+  }
+
+  return true;
+}
+
+bool EnablePkgInPkgmgr(const std::string& pkgid, uid_t uid,
+                        RequestMode request_mode) {
+  int ret = request_mode != RequestMode::GLOBAL ?
+        pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid.c_str(), uid, 0) :
+        pkgmgr_parser_update_pkg_disable_info_in_db(pkgid.c_str(), 0);
+  if (ret != 0) {
+    LOG(ERROR) << "Failed to enable pkg: " << pkgid;
+    return false;
+  }
+
+  return true;
+}
+
 }  // namespace common_installer
index 5eb3ba8..70d71b1 100644 (file)
@@ -87,6 +87,32 @@ bool UpdateTepInfoInPkgmgr(const boost::filesystem::path& tep_path,
                            uid_t uid,
                            RequestMode request_mode);
 
+/**
+ * \brief Adapter interface for external PkgMgr module used for updating
+ *        pkg disable info about package within pkgmgr
+ *
+ * \param pkgid package pkgid
+ * \param uid user id
+ * \param request_mode current request mode
+ *
+ * \return true if success
+ */
+bool DisablePkgInPkgmgr(const std::string& pkgid, uid_t uid,
+                        RequestMode request_mode);
+
+/**
+ * \brief Adapter interface for external PkgMgr module used for updating
+ *        pkg enable info about package within pkgmgr
+ *
+ * \param pkgid package pkgid
+ * \param uid user id
+ * \param request_mode current request mode
+ *
+ * \return true if success
+ */
+bool EnablePkgInPkgmgr(const std::string& pkgid, uid_t uid,
+                        RequestMode request_mode);
+
 }  // namespace common_installer
 
 #endif  // COMMON_PKGMGR_REGISTRATION_H_
index 96cb01a..9c38de2 100644 (file)
@@ -32,6 +32,8 @@ const std::map<ci::RequestType, const char*> kEventStr = {
   {ci::RequestType::MountUpdate, PKGMGR_INSTALLER_UPGRADE_EVENT_STR},
   {ci::RequestType::ManifestDirectInstall, PKGMGR_INSTALLER_INSTALL_EVENT_STR},
   {ci::RequestType::ManifestDirectUpdate, PKGMGR_INSTALLER_UPGRADE_EVENT_STR},
+  {ci::RequestType::DisablePkg, PKGMGR_INSTALLER_UNINSTALL_EVENT_STR},
+  {ci::RequestType::EnablePkg, PKGMGR_INSTALLER_INSTALL_EVENT_STR},
   {ci::RequestType::Unknown, PKGMGR_INSTALLER_UNKNOWN_EVENT_STR}
 };
 
index fc67605..9b29019 100644 (file)
@@ -25,7 +25,9 @@ enum class RequestType : int {
   MountInstall,
   MountUpdate,
   ManifestDirectInstall,
-  ManifestDirectUpdate
+  ManifestDirectUpdate,
+  DisablePkg,
+  EnablePkg
 };
 
 /** Request mode (USER vs GLOBAL) */
index 39fdf0a..25694cc 100644 (file)
@@ -104,6 +104,10 @@ Step::Status StepConfigure::process() {
       context_->xml_path.set(xml_path);
       break;
     }
+    case RequestType::DisablePkg:
+    case RequestType::EnablePkg:
+      context_->pkgid.set(pkgmgr_->GetRequestInfo());
+      break;
     default:
       LOG(ERROR) <<
           "Only installation, update and uninstallation is now supported";
diff --git a/src/common/step/pkgmgr/step_update_pkg_disable_info.cc b/src/common/step/pkgmgr/step_update_pkg_disable_info.cc
new file mode 100644 (file)
index 0000000..521ae5c
--- /dev/null
@@ -0,0 +1,57 @@
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/step/pkgmgr/step_update_pkg_disable_info.h"
+#include "common/pkgmgr_registration.h"
+
+namespace common_installer {
+namespace pkgmgr {
+
+StepUpdatePkgDisableInfo::StepUpdatePkgDisableInfo(
+    common_installer::InstallerContext* context, ActionType action_type)
+    : Step(context), action_type_(action_type) {}
+
+Step::Status StepUpdatePkgDisableInfo::precheck() {
+  if (context_->pkgid.get().empty()) {
+    LOG(ERROR) << "pkgid attribute is empty";
+    return Status::PACKAGE_NOT_FOUND;
+  }
+
+  return Step::Status::OK;
+}
+
+Step::Status StepUpdatePkgDisableInfo::process() {
+  if (action_type_ ==  ActionType::Disable) {
+    if (!DisablePkgInPkgmgr(context_->pkgid.get(), context_->uid.get(), context_->request_mode.get())) {
+      LOG(ERROR) << "Failed to update pkg info to disable :" << context_->pkgid.get();
+      return Status::REGISTER_ERROR;
+    }
+  } else {
+    if (!EnablePkgInPkgmgr(context_->pkgid.get(), context_->uid.get(), context_->request_mode.get())) {
+      LOG(ERROR) << "Failed to update pkg info to enable :" << context_->pkgid.get();
+      return Status::REGISTER_ERROR;
+    }
+  }
+  LOG(DEBUG) << "Successfully set pkg enable/disable info";
+  return Status::OK;
+}
+
+Step::Status StepUpdatePkgDisableInfo::undo() {
+  if (action_type_ ==  ActionType::Disable) {
+    if (!EnablePkgInPkgmgr(context_->pkgid.get(), context_->uid.get(), context_->request_mode.get())) {
+      LOG(ERROR) << "Failed to update pkg info to enable : " << context_->pkgid.get();
+      return Status::REGISTER_ERROR;
+    }
+  } else {
+    if (!DisablePkgInPkgmgr(context_->pkgid.get(), context_->uid.get(), context_->request_mode.get())) {
+      LOG(ERROR) << "Failed to update pkg info to disable : " << context_->pkgid.get();
+      return Status::REGISTER_ERROR;
+    }
+  }
+  LOG(DEBUG) << "Successfully undo pkg enable/disable info";
+  return Status::OK;
+}
+
+}  // namespace pkgmgr
+}  // namespace common_installer
diff --git a/src/common/step/pkgmgr/step_update_pkg_disable_info.h b/src/common/step/pkgmgr/step_update_pkg_disable_info.h
new file mode 100644 (file)
index 0000000..5e95adc
--- /dev/null
@@ -0,0 +1,36 @@
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_STEP_PKGMGR_STEP_UPDATE_PKG_DISABLE_INFO_H_
+#define COMMON_STEP_PKGMGR_STEP_UPDATE_PKG_DISABLE_INFO_H_
+
+#include <common/app_installer.h>
+#include <common/installer_context.h>
+#include <common/step/step.h>
+
+namespace common_installer {
+namespace pkgmgr {
+
+class StepUpdatePkgDisableInfo : public common_installer::Step {
+ public:
+  using Step::Step;
+  enum class ActionType { Disable, Enable };
+
+  explicit StepUpdatePkgDisableInfo(common_installer::InstallerContext* context,
+                               ActionType action_type);
+
+  Step::Status process() override;
+  Step::Status clean() override { return Status::OK; }
+  Step::Status undo() override;
+  Status precheck() override;
+
+ private:
+  ActionType action_type_;
+  STEP_NAME(UpdatePkgDisableInfo)
+};
+
+}  // namespace pkgmgr
+}  // namespace common_installer
+
+#endif  //COMMON_STEP_PKGMGR_STEP_UPDATE_PKG_DISABLE_INFO_H_