[HAM] check privilege and throw NotSupportedError from readRecorderData 22/89022/1
authorJakub Skowron <j.skowron@samsung.com>
Wed, 21 Sep 2016 12:41:45 +0000 (14:41 +0200)
committerJakub Skowron <j.skowron@samsung.com>
Wed, 21 Sep 2016 12:41:45 +0000 (14:41 +0200)
Added check if given HumanActivityRecorderType is supported.

[Verification]
  Code compiles without errors.
  100% TCT pass rate (humanactivitymonitor)

Change-Id: I8a7ee7ec24eb3b144f651cc244c307d128ad7ac0
Signed-off-by: Jakub Skowron <j.skowron@samsung.com>
src/humanactivitymonitor/humanactivitymonitor_instance.cc
src/humanactivitymonitor/humanactivitymonitor_manager.cc
src/humanactivitymonitor/humanactivitymonitor_manager.h

index 5000cb4..89eeb67 100755 (executable)
@@ -335,6 +335,7 @@ void HumanActivityMonitorInstance::HumanActivityMonitorManagerStopRecorder(
 void HumanActivityMonitorInstance::HumanActivityMonitorManagerReadRecorderData(
     const picojson::value& args, picojson::object& out) {
   LoggerD("Enter");
+  CHECK_PRIVILEGE_ACCESS(kPrivilegeHealthInfo, &out);
   CHECK_EXIST(args, "type", out)
   CHECK_EXIST(args, "query", out)
 
@@ -347,6 +348,12 @@ void HumanActivityMonitorInstance::HumanActivityMonitorManagerReadRecorderData(
     return;
   }
 
+  /* check if given human activity recorder type is supported */
+  if (!manager_->IsSupported(type)) {
+    LogAndReportError(PlatformResult(ErrorCode::NOT_SUPPORTED_ERR,"NOT_SUPPORTED_ERR"), &out);
+    return;
+  }
+
   const auto callback_id = args.get("callbackId").get<double>();
 
   auto get = [this, type, query, callback_id]() -> void {
index 387220f..c8e1ab9 100755 (executable)
@@ -398,7 +398,7 @@ class HumanActivityMonitorManager::Monitor {
     return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,"NOT_SUPPORTED_ERR");
   }
 
- private:
+ public:
   PlatformResult IsSupported() {
     ScopeLogger(type());
 
@@ -419,6 +419,7 @@ class HumanActivityMonitorManager::Monitor {
     }
   }
 
+ private:
   std::string type_;
   common::optional<bool> is_supported_;
   JsonCallback event_callback_;
@@ -1495,6 +1496,10 @@ PlatformResult HumanActivityMonitorManager::Init() {
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
+PlatformResult HumanActivityMonitorManager::IsSupported( const std::string& type ) {
+  return this->GetMonitor(type)->IsSupported();
+}
+
 PlatformResult HumanActivityMonitorManager::SetListener(
     const std::string& type, JsonCallback callback,
     const picojson::value& args) {
index caca7a3..8cd82be 100755 (executable)
@@ -38,6 +38,9 @@ class HumanActivityMonitorManager {
 
   common::PlatformResult Init();
 
+  /* checks if given HumanActivityRecorderType is supported */
+  common::PlatformResult IsSupported( const std::string& type );
+
   common::PlatformResult SetListener(const std::string& type,
                                      JsonCallback callback,
                                      const picojson::value& args);