Check widget settings according to privilege level 48/41948/2
authorTomasz Iwanek <t.iwanek@samsung.com>
Thu, 11 Jun 2015 08:11:12 +0000 (10:11 +0200)
committerPawel Sikorski <p.sikorski@samsung.com>
Thu, 25 Jun 2015 10:12:59 +0000 (03:12 -0700)
Some of widget settings requires certain privilege level
to be accepted by installation process.

In current shape of wrt spec, only one setting is forcing
privilege level: background-vibration

Change-Id: Ie88f415d84421859c250a8c7a55c9102ceed6c4e

src/common/context_installer.cc
src/common/context_installer.h
src/common/step/step_check_signature.cc
src/wgt/CMakeLists.txt
src/wgt/step/step_check_settings_level.cc [new file with mode: 0644]
src/wgt/step/step_check_settings_level.h [new file with mode: 0644]
src/wgt/wgt_backend.cc

index 8583767..e5e1bb9 100644 (file)
@@ -11,6 +11,11 @@ namespace common_installer {
 
 namespace fs = boost::filesystem;
 
+bool SatifiesPrivilegeLevel(PrivilegeLevel required_level,
+                   PrivilegeLevel allowed_level) {
+  return static_cast<int>(required_level) <= static_cast<int>(allowed_level);
+}
+
 const char* PrivilegeLevelToString(PrivilegeLevel level) {
   switch (level) {
     case PrivilegeLevel::UNTRUSTED:
index 30e8489..55e597a 100644 (file)
@@ -39,6 +39,8 @@ enum class PrivilegeLevel : int {
   PLATFORM   = 3
 };
 
+bool SatifiesPrivilegeLevel(PrivilegeLevel required_level,
+                   PrivilegeLevel allowed_level);
 const char* PrivilegeLevelToString(PrivilegeLevel level);
 
 // TODO(p.sikorski@samsung.com) this class should be divided into:
index a046728..503bcb2 100644 (file)
@@ -213,8 +213,6 @@ Step::Status StepCheckSignature::process() {
   LOG(INFO) << "Privilege level: " << PrivilegeLevelToString(level);
   context_->privilege_level.set(level);
 
-  // TODO(t.iwanek): check settings for privilege level...
-
   // TODO(t.iwanek): refactoring, move to wgt backend
   bool is_webapp = context_->pkg_type.get() == "wgt";
   if (!ValidatePrivilegeLevel(level, is_webapp,
index e28de86..2d721fd 100644 (file)
@@ -1,5 +1,6 @@
 # Target - sources
 SET(SRCS
+  step/step_check_settings_level.cc
   step/step_create_symbolic_link.cc
   step/step_parse.cc
   wgt_app_query_interface.cc
diff --git a/src/wgt/step/step_check_settings_level.cc b/src/wgt/step/step_check_settings_level.cc
new file mode 100644 (file)
index 0000000..0a0d86a
--- /dev/null
@@ -0,0 +1,48 @@
+// Copyright (c) 2015 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 "wgt/step/step_check_settings_level.h"
+
+#include <manifest_handlers/setting_handler.h>
+
+#include <map>
+
+#include "common/utils/logging.h"
+
+#include "wgt/wgt_backend_data.h"
+
+namespace {
+
+bool ValidateSettingsForLevel(common_installer::PrivilegeLevel level,
+                              const wgt::parse::SettingInfo& settings) {
+  if (settings.background_vibration()) {
+    common_installer::PrivilegeLevel required_level =
+        common_installer::PrivilegeLevel::PARTNER;
+    if (!common_installer::SatifiesPrivilegeLevel(required_level, level)) {
+      LOG(ERROR) << "background_vibration requires visibility level: "
+                 << common_installer::PrivilegeLevelToString(required_level);
+      return false;
+    }
+    LOG(INFO) << "Setting: 'background-vibration' allowed";
+  }
+  return true;
+}
+
+}  // namespace
+
+namespace wgt {
+namespace check_settings {
+
+common_installer::Step::Status StepCheckSettingsLevel::process() {
+  if (!ValidateSettingsForLevel(context_->privilege_level.get(),
+      static_cast<WgtBackendData*>(
+          context_->backend_data.get())->settings.get())) {
+    return Status::ERROR;
+  }
+  LOG(INFO) << "Settings privilege level checked";
+  return Status::OK;
+}
+
+}  // namespace check_settings
+}  // namespace wgt
diff --git a/src/wgt/step/step_check_settings_level.h b/src/wgt/step/step_check_settings_level.h
new file mode 100644 (file)
index 0000000..f7b72a6
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright (c) 2015 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 WGT_STEP_STEP_CHECK_SETTINGS_LEVEL_H_
+#define WGT_STEP_STEP_CHECK_SETTINGS_LEVEL_H_
+
+#include "common/app_installer.h"
+#include "common/context_installer.h"
+#include "common/step/step.h"
+#include "common/utils/logging.h"
+
+namespace wgt {
+namespace check_settings {
+
+class StepCheckSettingsLevel : 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(CheckSettingsLevel)
+};
+
+}  // namespace check_settings
+}  // namespace wgt
+
+#endif  // WGT_STEP_STEP_CHECK_SETTINGS_LEVEL_H_
index 031960f..7d302fa 100644 (file)
@@ -28,6 +28,7 @@
 #include "common/step/step_update_security.h"
 
 #include "wgt/step/step_create_symbolic_link.h"
+#include "wgt/step/step_check_settings_level.h"
 #include "wgt/step/step_parse.h"
 #include "wgt/wgt_app_query_interface.h"
 
@@ -50,6 +51,7 @@ int main(int argc, char** argv) {
       installer.AddStep<ci::unzip::StepUnzip>();
       installer.AddStep<wgt::parse::StepParse>();
       installer.AddStep<ci::signature::StepCheckSignature>();
+      installer.AddStep<wgt::check_settings::StepCheckSettingsLevel>();
       installer.AddStep<ci::copy::StepCopy>();
       installer.AddStep<ci::create_storage::StepCreateStorageDirectories>();
       installer.AddStep<wgt::symbolic_link::StepCreateSymbolicLink>();
@@ -63,6 +65,7 @@ int main(int argc, char** argv) {
       installer.AddStep<ci::unzip::StepUnzip>();
       installer.AddStep<wgt::parse::StepParse>();
       installer.AddStep<ci::signature::StepCheckSignature>();
+      installer.AddStep<wgt::check_settings::StepCheckSettingsLevel>();
       installer.AddStep<ci::old_manifest::StepOldManifest>();
       installer.AddStep<ci::backup_manifest::StepBackupManifest>();
       installer.AddStep<ci::backup_icons::StepBackupIcons>();