Add StepCheckRemovable 99/61899/2
authorSangyoon Jang <s89.jang@samsung.com>
Fri, 11 Mar 2016 05:47:05 +0000 (14:47 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Mon, 14 Mar 2016 03:16:10 +0000 (20:16 -0700)
This step checks the given package is removable or not.

Change-Id: I63ddfcfd8dbd2f100e413c2c5c6b1290842ac590
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
src/common/CMakeLists.txt
src/common/step/step_check_removable.cc [new file with mode: 0644]
src/common/step/step_check_removable.h [new file with mode: 0644]

index b5c5efc..7edd833 100644 (file)
@@ -24,6 +24,7 @@ SET(SRCS
   step/step_create_icons.cc
   step/step_check_background_category.cc
   step/step_check_blacklist.cc
+  step/step_check_removable.cc
   step/step_check_old_certificate.cc
   step/step_check_signature.cc
   step/step_clear_data.cc
diff --git a/src/common/step/step_check_removable.cc b/src/common/step/step_check_removable.cc
new file mode 100644 (file)
index 0000000..f5e7b1a
--- /dev/null
@@ -0,0 +1,50 @@
+// 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/step_check_removable.h"
+
+#include <pkgmgr-info.h>
+
+#include "common/app_installer.h"
+#include "common/step/step.h"
+
+namespace common_installer {
+namespace pkgmgr {
+
+Step::Status StepCheckRemovable::process() {
+  pkgmgrinfo_pkginfo_h handle;
+
+  int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(context_->pkgid.get().c_str(),
+      context_->uid.get(), &handle);
+  if (ret != PMINFO_R_OK) {
+    LOG(ERROR) << "This package is not installed";
+    return Status::INVALID_VALUE;
+  }
+
+  bool removable;
+  ret = pkgmgrinfo_pkginfo_is_removable(handle, &removable);
+  if (ret != PMINFO_R_OK) {
+    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+    return Status::INVALID_VALUE;
+  }
+
+  if (!removable) {
+    LOG(ERROR) << "This package is not removable";
+    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+    return Status::OPERATION_NOT_ALLOWED;
+  }
+
+  pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+  return Status::OK;
+}
+
+Step::Status StepCheckRemovable::precheck() {
+  if (context_->pkgid.get().empty())
+    return Status::INVALID_VALUE;
+  return Status::OK;
+}
+
+}  // namespace pkgmgr
+}  // namespace common_installer
diff --git a/src/common/step/step_check_removable.h b/src/common/step/step_check_removable.h
new file mode 100644 (file)
index 0000000..adefa7c
--- /dev/null
@@ -0,0 +1,28 @@
+// 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_STEP_CHECK_REMOVABLE_H_
+#define COMMON_STEP_STEP_CHECK_REMOVABLE_H_
+
+#include "common/step/step.h"
+
+namespace common_installer {
+namespace pkgmgr {
+
+class StepCheckRemovable : public Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+  Status undo() override { return Status::OK; }
+  Status clean() override { return Status::OK; }
+  Status precheck() override;
+
+  SCOPE_LOG_TAG(CheckRemovable)
+};
+
+}  // namespace pkgmgr
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_STEP_CHECK_REMOVABLE_H_