Add StepParsePreload 65/57465/18
authorArkadiusz Szulakiewicz <a.szulakiewi@partner.samsung.com>
Wed, 20 Jan 2016 08:53:28 +0000 (09:53 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Tue, 26 Jan 2016 11:51:45 +0000 (03:51 -0800)
This change is dependant on the following patches:
https://review.tizen.org/gerrit/57463
https://review.tizen.org/gerrit/57647

Change-Id: I260435ac4dacad2f527dce1aac99afa5c6ed079e

src/tpk/CMakeLists.txt
src/tpk/step/step_parse_preload.cc [new file with mode: 0644]
src/tpk/step/step_parse_preload.h [new file with mode: 0644]
src/tpk/tpk_backend.cc
src/tpk/tpk_installer.cc

index ef7d03c422a1765c8d0da19b4a39dd5cf6a208ea..671f57acc6c99c7c342baa356016a4784d9d00ce 100644 (file)
@@ -1,6 +1,7 @@
 SET(SRCS
     step/step_check_tpk_background_category.cc
     step/step_create_symbolic_link.cc
+    step/step_parse_preload.cc
     step/step_convert_xml.cc
     step/step_tpk_patch_icons.cc
     tpk_app_query_interface.cc
diff --git a/src/tpk/step/step_parse_preload.cc b/src/tpk/step/step_parse_preload.cc
new file mode 100644 (file)
index 0000000..790e80d
--- /dev/null
@@ -0,0 +1,60 @@
+// 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 "tpk/step/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 {
+const char kPathManifestPrefix[] = "/usr/share/packages";
+}
+
+namespace common_installer {
+namespace tpk {
+
+namespace bf = boost::filesystem;
+
+Step::Status StepParsePreload::process() {
+  const char* preload_manifest_val = context_->manifest_data.get()->preload;
+
+  bool is_preload = false;
+
+  if (context_->installation_mode.get() == InstallationMode::OFFLINE) {
+    if (strcmp(preload_manifest_val, "false") != 0) {
+          is_preload = true;
+    }
+  } else {
+    if (context_->request_type.get() == RequestType::ManifestDirectInstall ||
+        context_->request_type.get() == RequestType::ManifestDirectUpdate) {
+      if (strcmp(preload_manifest_val, "true") == 0) {
+        is_preload = true;
+      }
+    }
+  }
+
+  if (is_preload) {
+    context_->manifest_data.get()->preload = strdup("true");
+
+    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 tpk
+}  // namespace common_installer
diff --git a/src/tpk/step/step_parse_preload.h b/src/tpk/step/step_parse_preload.h
new file mode 100644 (file)
index 0000000..8bbaebd
--- /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_STEP_PARSE_PRELOAD_H_
+#define COMMON_STEP_STEP_PARSE_PRELOAD_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include "common/installer_context.h"
+#include "common/step/step.h"
+
+namespace common_installer {
+namespace tpk {
+
+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; }
+
+  SCOPE_LOG_TAG(ParsePreload)
+};
+
+}  // namespace tpk
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_STEP_PARSE_PRELOAD_H_
index 657c89b3a03508856a19c49d524dfc83778afbf4..8e3479e27b712dab9ab978f0ad84a7689a38d058 100644 (file)
@@ -17,6 +17,7 @@ int main(const int argc, char* argv[]) {
     LOG(ERROR) << "Failed to create pkgmgr interface";
     return -1;
   }
+
   tpk::TpkInstaller t(pkgmgr);
   if (t.Run() != ci::AppInstaller::Result::OK) {
     LOG(ERROR) << "TpkInstaller run failure";
index b4a211136433e4945f4d7604722a14e309e0b677..feb67355003d6d476fe8ab34ada4b590f30f2cbb 100644 (file)
@@ -40,6 +40,7 @@
 #include <common/step/step_update_tep.h>
 #include "tpk/step/step_check_tpk_background_category.h"
 #include "tpk/step/step_create_symbolic_link.h"
+#include "tpk/step/step_parse_preload.h"
 #include "tpk/step/step_convert_xml.h"
 #include "tpk/step/step_tpk_patch_icons.h"
 
@@ -99,6 +100,7 @@ void TpkInstaller::InstallSteps() {
   AddStep<ci::parse::StepParseManifest>(
       ci::parse::StepParseManifest::ManifestLocation::PACKAGE,
       ci::parse::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::tpk::StepParsePreload>();
   AddStep<ci::security::StepCheckSignature>();
   AddStep<ci::security::StepPrivilegeCompatibility>();
   AddStep<tpk::security::StepCheckTpkBackgroundCategory>();
@@ -120,6 +122,7 @@ void TpkInstaller::UpdateSteps() {
   AddStep<ci::parse::StepParseManifest>(
       ci::parse::StepParseManifest::ManifestLocation::PACKAGE,
       ci::parse::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::tpk::StepParsePreload>();
   AddStep<ci::security::StepCheckSignature>();
   AddStep<ci::security::StepPrivilegeCompatibility>();
   AddStep<tpk::security::StepCheckTpkBackgroundCategory>();
@@ -209,6 +212,7 @@ void TpkInstaller::ManifestDirectInstallSteps() {
   AddStep<ci::parse::StepParseManifest>(
       ci::parse::StepParseManifest::ManifestLocation::INSTALLED,
       ci::parse::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::tpk::StepParsePreload>();
   AddStep<ci::security::StepPrivilegeCompatibility>();
   AddStep<tpk::security::StepCheckTpkBackgroundCategory>();
   AddStep<ci::security::StepRollbackInstallationSecurity>();
@@ -221,6 +225,7 @@ void TpkInstaller::ManifestDirectUpdateSteps() {
   AddStep<ci::parse::StepParseManifest>(
       ci::parse::StepParseManifest::ManifestLocation::INSTALLED,
       ci::parse::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::tpk::StepParsePreload>();
   AddStep<ci::security::StepPrivilegeCompatibility>();
   AddStep<tpk::security::StepCheckTpkBackgroundCategory>();
   AddStep<ci::pkgmgr::StepKillApps>();