--- /dev/null
+// 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_check_installable.h"
+
+#include <pkgmgr-info.h>
+#include <sys/types.h>
+#include <tzplatform_config.h>
+
+#include "common/pkgmgr_query.h"
+#include "common/utils/user_util.h"
+
+namespace {
+
+const uid_t kGlobalUserUid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+
+} // namespace
+
+namespace common_installer {
+namespace pkgmgr {
+
+Step::Status StepCheckInstallable::process() {
+ switch (context_->request_mode.get()) {
+ case RequestMode::USER:
+ if (QueryIsPackageInstalled(context_->pkgid.get(), kGlobalUserUid)) {
+ LOG(ERROR) << "This package is already installed as global package";
+ return Status::OPERATION_NOT_ALLOWED;
+ }
+ break;
+ case RequestMode::GLOBAL:
+ UserList list = GetUserList();
+ for (auto l : list) {
+ uid_t uid = std::get<0>(l);
+ if (QueryIsPackageInstalled(context_->pkgid.get(), uid)) {
+ LOG(ERROR) << "This package is already installed by user("
+ << uid << ")";
+ return Status::OPERATION_NOT_ALLOWED;
+ }
+ }
+ break;
+ }
+ return Status::OK;
+}
+
+Step::Status StepCheckInstallable::precheck() {
+ if (context_->pkgid.get().empty())
+ return Status::INVALID_VALUE;
+ return Status::OK;
+}
+
+} // namespace pkgmgr
+} // namespace common_installer
--- /dev/null
+// 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_CHECK_INSTALLABLE_H_
+#define COMMON_STEP_PKGMGR_STEP_CHECK_INSTALLABLE_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include "common/installer_context.h"
+#include "common/step/step.h"
+
+namespace common_installer {
+namespace pkgmgr {
+
+class StepCheckInstallable : public Step {
+ public:
+ using Step::Step;
+ Status process() override;
+ Status clean() override { return Status::OK; }
+ Status undo() override { return Status::OK; }
+ Status precheck() override;
+
+ STEP_NAME(StepCheckInstallable)
+};
+
+} // namespace pkgmgr
+} // namespace common_installer
+
+#endif // COMMON_STEP_PKGMGR_STEP_CHECK_INSTALLABLE_H_