Fix preload request for wgt 24/82424/3
authorTomasz Iwanek <t.iwanek@samsung.com>
Wed, 3 Aug 2016 08:35:49 +0000 (10:35 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Wed, 3 Aug 2016 12:29:52 +0000 (14:29 +0200)
This commit should allow to install preload wgt package with command:
 - wgt-backend --preload -i $package

Submit together:
 - https://review.tizen.org/gerrit/82424
 - https://review.tizen.org/gerrit/82496
 - https://review.tizen.org/gerrit/82497

Change-Id: I483f819444773f164fc63401efda93b6b828b10d

src/common/CMakeLists.txt
src/common/step/configuration/step_parse_preload.cc [new file with mode: 0644]
src/common/step/configuration/step_parse_preload.h [new file with mode: 0644]

index dac9a07..92506d9 100644 (file)
@@ -35,6 +35,7 @@ SET(SRCS
   step/configuration/step_configure.cc
   step/configuration/step_fail.cc
   step/configuration/step_parse_manifest.cc
+  step/configuration/step_parse_preload.cc
   step/filesystem/step_acquire_external_storage.cc
   step/filesystem/step_clear_data.cc
   step/filesystem/step_copy.cc
diff --git a/src/common/step/configuration/step_parse_preload.cc b/src/common/step/configuration/step_parse_preload.cc
new file mode 100644 (file)
index 0000000..dbf4c41
--- /dev/null
@@ -0,0 +1,49 @@
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/step/configuration/step_parse_preload.h"
+
+#include <pkgmgr-info.h>
+#include <unistd.h>
+
+#include <boost/filesystem.hpp>
+
+#include <cstring>
+#include <cstdio>
+#include <string>
+
+#include "common/pkgmgr_interface.h"
+#include "common/utils/file_util.h"
+
+namespace bf = boost::filesystem;
+namespace ci = common_installer;
+
+namespace common_installer {
+namespace configuration {
+
+ci::Step::Status StepParsePreload::process() {
+  const char* preload_manifest_val = context_->manifest_data.get()->preload;
+
+  if (strcmp(preload_manifest_val, "true") != 0) {
+    bool is_preload = context_->is_preload_request.get();
+
+    LOG(INFO) << "is_preload : (" << is_preload << ")";
+    if (is_preload) {
+      context_->manifest_data.get()->preload = strdup("true");
+
+      if (getuid() != 0) {
+        LOG(ERROR) << "You're not authorized to install preload app: "
+            << context_->pkgid.get().c_str();
+        return Status::OPERATION_NOT_ALLOWED;
+      }
+    } else {
+      context_->manifest_data.get()->preload = strdup("false");
+    }
+  }
+
+  return Status::OK;
+}
+
+}  // namespace configuration
+}  // namespace common_installer
diff --git a/src/common/step/configuration/step_parse_preload.h b/src/common/step/configuration/step_parse_preload.h
new file mode 100644 (file)
index 0000000..36b6ad9
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_STEP_CONFIGURATION_STEP_PARSE_PRELOAD_H_
+#define COMMON_STEP_CONFIGURATION_STEP_PARSE_PRELOAD_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include "common/installer_context.h"
+#include "common/step/step.h"
+
+namespace common_installer {
+namespace configuration {
+
+class StepParsePreload : public common_installer::Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+  Status clean() override { return Status::OK; }
+  Status undo() override { return Status::OK; }
+  Status precheck() override { return Status::OK; }
+
+  STEP_NAME(ParsePreload)
+};
+
+}  // namespace configuration
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_CONFIGURATION_STEP_PARSE_PRELOAD_H_