From 69a559dae8c9e16b9b998e516b8ff39cf5a376c9 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Fri, 11 Mar 2016 14:47:05 +0900 Subject: [PATCH] Add StepCheckRemovable This step checks the given package is removable or not. Change-Id: I63ddfcfd8dbd2f100e413c2c5c6b1290842ac590 Signed-off-by: Sangyoon Jang --- src/common/CMakeLists.txt | 1 + src/common/step/step_check_removable.cc | 50 +++++++++++++++++++++++++++++++++ src/common/step/step_check_removable.h | 28 ++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 src/common/step/step_check_removable.cc create mode 100644 src/common/step/step_check_removable.h diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index b5c5efc..7edd833 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -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 index 0000000..f5e7b1a --- /dev/null +++ b/src/common/step/step_check_removable.cc @@ -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 + +#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 index 0000000..adefa7c --- /dev/null +++ b/src/common/step/step_check_removable.h @@ -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_ -- 2.7.4