Add StepCheckTizenVersion 43/71143/10
authorSangyoon Jang <s89.jang@samsung.com>
Tue, 24 May 2016 08:35:29 +0000 (17:35 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Wed, 25 May 2016 05:21:00 +0000 (14:21 +0900)
Requires:
 - https://review.tizen.org/gerrit/71327

Change-Id: Id0d838a9244395f4b996f17391ee1dbdfed2c77a
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
packaging/app-installers.spec
src/common/CMakeLists.txt
src/common/step/configuration/step_check_tizen_version.cc [new file with mode: 0644]
src/common/step/configuration/step_check_tizen_version.h [new file with mode: 0644]

index a0419b3..9fdd323 100644 (file)
@@ -66,7 +66,8 @@ cp %{SOURCE1000} .
 cp %{SOURCE1001} .
 
 %build
-%cmake . -DCMAKE_BUILD_TYPE=%{?build_type:%build_type}
+%cmake . -DCMAKE_BUILD_TYPE=%{?build_type:%build_type} \
+         -DTIZEN_FULL_VERSION=%{tizen_full_version}
 make %{?_smp_mflags}
 
 %install
index 68e510a..5be7bdd 100644 (file)
@@ -25,6 +25,7 @@ SET(SRCS
   step/backup/step_backup_manifest.cc
   step/backup/step_copy_backup.cc
   step/configuration/step_block_cross_update.cc
+  step/configuration/step_check_tizen_version.cc
   step/configuration/step_configure.cc
   step/configuration/step_fail.cc
   step/configuration/step_parse_manifest.cc
@@ -120,6 +121,11 @@ SET(PLUGINS_LIST_INSTALL_PATH ${SHAREDIR}/app-installers/)
 SET(PLUGINS_LIST_INSTALL_FILE_PATH ${PLUGINS_LIST_INSTALL_PATH}/${PLUGINS_LIST_FILE_NAME})
 
 ADD_DEFINITIONS("-DPLUGINS_LIST_INSTALL_FILE_PATH=\"${PLUGINS_LIST_INSTALL_FILE_PATH}\"")
+IF(NOT DEFINED TIZEN_FULL_VERSION)
+  MESSAGE(FATAL_ERROR "TIZEN_FULL_VERSION MUST BE defined")
+ELSE(NOT DEFINED TIZEN_FULL_VERSION)
+  ADD_DEFINITIONS("-DTIZEN_FULL_VERSION=\"${TIZEN_FULL_VERSION}\"")
+ENDIF(NOT DEFINED TIZEN_FULL_VERSION)
 CONFIGURE_FILE(${PLUGINS_LIST_FILE_PATH}.in ${PLUGINS_LIST_FILE_PATH} @ONLY)
 INSTALL(FILES ${PLUGINS_LIST_FILE_PATH} DESTINATION ${PLUGINS_LIST_INSTALL_PATH}/)
 
diff --git a/src/common/step/configuration/step_check_tizen_version.cc b/src/common/step/configuration/step_check_tizen_version.cc
new file mode 100644 (file)
index 0000000..532dadb
--- /dev/null
@@ -0,0 +1,47 @@
+// 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_check_tizen_version.h"
+
+#include <manifest_parser/utils/version_number.h>
+
+#include "common/installer_context.h"
+
+namespace {
+
+const char kPlatformVersion[] = TIZEN_FULL_VERSION;
+
+int CompareVersion(const std::string& a, const std::string& b) {
+  utils::VersionNumber a_ver(a);
+  utils::VersionNumber b_ver(b);
+
+  return a_ver.Trim(3).Compare(b_ver.Trim(3));
+}
+
+}  // namespace
+
+namespace common_installer {
+namespace configuration {
+
+Step::Status StepCheckTizenVersion::process() {
+  const char* version = context_->manifest_data.get()->api_version;
+  if (CompareVersion(std::string(kPlatformVersion), std::string(version)) < 0) {
+    LOG(ERROR) << "Package's api version(" << version << ") is higher than "
+               << "platform version(" << kPlatformVersion << ")";
+    return Status::OPERATION_NOT_ALLOWED;
+  }
+  return Status::OK;
+}
+
+Step::Status StepCheckTizenVersion::precheck() {
+  const char* version = context_->manifest_data.get()->api_version;
+  if (version == nullptr) {
+    LOG(ERROR) << "Api version not found";
+    return Status::INVALID_VALUE;
+  }
+  return Status::OK;
+}
+
+}  // namespace configuration
+}  // namespace common_installer
diff --git a/src/common/step/configuration/step_check_tizen_version.h b/src/common/step/configuration/step_check_tizen_version.h
new file mode 100644 (file)
index 0000000..82cdb90
--- /dev/null
@@ -0,0 +1,30 @@
+// 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_CHECK_TIZEN_VERSION_H_
+#define COMMON_STEP_CONFIGURATION_STEP_CHECK_TIZEN_VERSION_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include "common/step/step.h"
+
+namespace common_installer {
+namespace configuration {
+
+class StepCheckTizenVersion : public Step {
+ public:
+  using Step::Step;
+
+  Status process() override;
+  Status clean() override { return Status::OK; }
+  Status undo() override { return Status::OK; }
+  Status precheck() override;
+
+  SCOPE_LOG_TAG(CheckTizenVersion)
+};
+
+}  // namespace configuration
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_CONFIGURATION_STEP_CHECK_TIZEN_VERSION_H_