Implement StepCheckInstallable 76/98476/2 accepted/tizen/3.0/common/20161118.193007 accepted/tizen/3.0/ivi/20161118.004152 accepted/tizen/3.0/mobile/20161118.004022 accepted/tizen/3.0/tv/20161118.004108 accepted/tizen/3.0/wearable/20161118.004132 submit/tizen_3.0/20161117.054138
authorSangyoon Jang <s89.jang@samsung.com>
Thu, 17 Nov 2016 06:16:25 +0000 (15:16 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Thu, 17 Nov 2016 10:43:18 +0000 (19:43 +0900)
The platform does not allow package override.
If the package installed as global package, the user cannot install the
package as local package. Likewise, if the package is installed as local
package, the package cannot be installed as global package.

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

diff --git a/src/common/step/pkgmgr/step_check_installable.cc b/src/common/step/pkgmgr/step_check_installable.cc
new file mode 100644 (file)
index 0000000..64a4380
--- /dev/null
@@ -0,0 +1,53 @@
+// 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
diff --git a/src/common/step/pkgmgr/step_check_installable.h b/src/common/step/pkgmgr/step_check_installable.h
new file mode 100644 (file)
index 0000000..fa1453b
--- /dev/null
@@ -0,0 +1,30 @@
+// 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_