--- /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/feature_validator.h"
+
+#include <boost/scope_exit.hpp>
+
+#include <system_info.h>
+
+namespace {
+
+const char kTrueFeature[] = "true";
+
+} // namespace
+
+namespace common_installer {
+
+FeatureValidator::FeatureValidator(
+ const std::map<std::string, std::string>& features)
+ : features_(features) {
+}
+
+bool FeatureValidator::Validate(std::string* error) {
+ for (auto& pair : features_) {
+ const auto& feature = pair.first;
+ const auto& value = pair.second;
+
+ system_info_type_e type;
+ int ret = system_info_get_platform_type(feature.c_str(), &type);
+ if (ret != SYSTEM_INFO_ERROR_NONE) {
+ *error = std::string("Unknown feature: ") + feature;
+ return false;
+ }
+ bool ok = false;
+ switch (type) {
+ case SYSTEM_INFO_BOOL:
+ ok = ValidateBoolean(feature, value, error);
+ break;
+ case SYSTEM_INFO_INT:
+ ok = ValidateInteger(feature, value, error);
+ break;
+ case SYSTEM_INFO_STRING:
+ ok = ValidateString(feature, value, error);
+ break;
+ case SYSTEM_INFO_DOUBLE:
+ // There is no double typed feature on platform, no way to interpret it
+ ok = true;
+ break;
+ default:
+ ok = false;
+ *error = "Unknown type of feature";
+ }
+ if (!ok)
+ return false;
+ }
+ return true;
+}
+
+bool FeatureValidator::ValidateBoolean(
+ const std::string& feature, const std::string& value, std::string* error) {
+ bool supported = false;
+ int ret = system_info_get_platform_bool(feature.c_str(), &supported);
+ if (ret != SYSTEM_INFO_ERROR_NONE) {
+ *error = std::string("Failed to call system_info_get_platform_bool()") +
+ " for " + feature + ", error code: " + std::to_string(ret);
+ return false;
+ }
+ return true;
+}
+
+bool FeatureValidator::ValidateInteger(
+ const std::string& feature, const std::string& value, std::string* error) {
+ int platform_value = 0;
+ int ret = system_info_get_platform_int(feature.c_str(), &platform_value);
+ if (ret != SYSTEM_INFO_ERROR_NONE) {
+ *error = std::string("Failed to call system_info_get_platform_int()") +
+ " for " + feature + ", error code: " + std::to_string(ret);
+ return false;
+ }
+ return true;
+}
+
+bool FeatureValidator::ValidateString(
+ const std::string& feature, const std::string& value, std::string* error) {
+ char* text = nullptr;
+ BOOST_SCOPE_EXIT_ALL(text) {
+ free(text);
+ };
+ int ret = system_info_get_platform_string(feature.c_str(), &text);
+ if (ret != SYSTEM_INFO_ERROR_NONE) {
+ *error = std::string("Failed to call system_info_get_platform_string()") +
+ " for " + feature + ", error code: " + std::to_string(ret);
+ return false;
+ }
+ return true;
+}
+
+} // 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_FEATURE_VALIDATOR_H_
+#define COMMON_FEATURE_VALIDATOR_H_
+
+#include <map>
+#include <string>
+
+namespace common_installer {
+
+class FeatureValidator {
+ public:
+ explicit FeatureValidator(const std::map<std::string, std::string>& features);
+ bool Validate(std::string* error);
+
+ private:
+ bool ValidateBoolean(
+ const std::string& feature, const std::string& value, std::string* error);
+ bool ValidateInteger(
+ const std::string& feature, const std::string& value, std::string* error);
+ bool ValidateString(
+ const std::string& feature, const std::string& value, std::string* error);
+
+ const std::map<std::string, std::string>& features_;
+};
+
+} // namespace common_installer
+
+#endif // COMMON_FEATURE_VALIDATOR_H_
#include <tpk_manifest_handlers/application_manifest_constants.h>
#include <tpk_manifest_handlers/author_handler.h>
#include <tpk_manifest_handlers/description_handler.h>
+#include <tpk_manifest_handlers/feature_handler.h>
#include <tpk_manifest_handlers/package_handler.h>
#include <tpk_manifest_handlers/privileges_handler.h>
#include <tpk_manifest_handlers/profile_handler.h>
#include "common/app_installer.h"
#include "common/backup_paths.h"
+#include "common/feature_validator.h"
#include "common/installer_context.h"
#include "common/pkgmgr_registration.h"
#include "common/step/step.h"
return true;
}
+bool StepParseManifest::CheckFeatures() {
+ auto feature_info =
+ std::static_pointer_cast<const tpk::parse::FeatureInfo>(
+ parser_->GetManifestData(tpk::parse::FeatureInfo::Key()));
+ if (!feature_info)
+ return true;
+
+ std::string error;
+ FeatureValidator validator(feature_info->features());
+ if (!validator.Validate(&error)) {
+ LOG(ERROR) << "Feature validation error. " << error;
+ return false;
+ }
+
+ return true;
+}
+
template <typename T>
bool StepParseManifest::FillAppControl(application_x* app,
const T& app_control_list) {
return Step::Status::PARSE_ERROR;
}
+ if (!CheckFeatures())
+ return Status::PARSE_ERROR;
+
if (manifest_location_ == ManifestLocation::INSTALLED) {
// recovery of tep value for installed package
std::string old_tep =