APPLINK-6566. Implementation of GetListOfPermissions request/response.
authorAndrey Oleynik <AOleynik@luxoft.com>
Fri, 4 Apr 2014 11:15:18 +0000 (14:15 +0300)
committerJustin Dickow <jjdickow@gmail.com>
Tue, 8 Jul 2014 22:48:33 +0000 (18:48 -0400)
Signed-off-by: Justin Dickow <jjdickow@gmail.com>
Conflicts:
src/components/policy

src/components/application_manager/include/application_manager/message_helper.h
src/components/application_manager/include/application_manager/policies/policy_handler.h
src/components/application_manager/src/commands/hmi/on_app_permission_consent_notification.cc
src/components/application_manager/src/commands/hmi/sdl_get_list_of_permissions_request.cc
src/components/application_manager/src/commands/hmi/sdl_get_list_of_permissions_response.cc
src/components/application_manager/src/message_helper.cc
src/components/application_manager/src/policies/policy_handler.cc

index ee01287..f87414e 100644 (file)
@@ -254,6 +254,15 @@ class MessageHelper {
         const std::vector<policy::UserFriendlyMessage>& msg,
         uint32_t correlation_id);
 
+    /**
+     * @brief Send GetListOfPermissions response to HMI
+     * @param permissions Array of groups permissions
+     * @param correlation_id Correlation id of request
+     */
+    static void SendGetListOfPermissionsResponse(
+        std::vector<policy::FunctionalGroupPermission>& permissions,
+        uint32_t correlation_id);
+
     /*
      * @brief Sends notification to HMI to start video streaming
      *
index eb9d866..d87a4b5 100644 (file)
@@ -150,6 +150,15 @@ class PolicyHandler : public utils::Singleton<PolicyHandler>,
                                 const std::string& language,
                                 uint32_t correlation_id);
 
+  /**
+   * @brief Get list of permissions for application/device binded to
+   * connection key from request and send response
+   * @param connection_key Connection key
+   * @param correlation_id Correlation id from request
+   */
+  void OnGetListOfPermissions(const uint32_t connection_key,
+                              const uint32_t correlation_id);
+
  protected:
   /**
    * Starts next retry exchange policy table
index 9782e3a..eb50106 100644 (file)
@@ -84,7 +84,13 @@ void OnAppPermissionConsent::Run() {
     policy::FunctionalGroupPermission permissions;
     permissions.group_id = (*it)["id"].asInt();
     permissions.group_name = (*it)["name"].asString();
-    permissions.is_allowed = (*it)["allowed"].asBool();
+    if ((*it).keyExists("allowed")) {
+      permissions.state = (*it)["allowed"].asBool() ? policy::kAllowed :
+                                                      policy::kDisallowed;
+    } else {
+      permissions.state = policy::kUndefined;
+    }
+
     permission_consent.group_permissions.push_back(permissions);
   }
 
index c4bd099..911fcbb 100644 (file)
  */
 
 #include "application_manager/commands/hmi/sdl_get_list_of_permissions_request.h"
+#include "application_manager/policies/policy_handler.h"
 
 namespace application_manager {
 
 namespace commands {
 
-SDLGetListOfPermissionsRequest::SDLGetListOfPermissionsRequest(const MessageSharedPtr& message)
+SDLGetListOfPermissionsRequest::SDLGetListOfPermissionsRequest(
+    const MessageSharedPtr& message)
     : RequestFromHMI(message) {
 }
 
@@ -45,6 +47,9 @@ SDLGetListOfPermissionsRequest::~SDLGetListOfPermissionsRequest() {
 
 void SDLGetListOfPermissionsRequest::Run() {
   LOG4CXX_INFO(logger_, "SDLGetListOfPermissionsRequest::Run");
+  policy::PolicyHandler::instance()->OnGetListOfPermissions(
+      (*message_)[strings::msg_params][strings::app_id].asUInt(),
+      (*message_)[strings::params][strings::correlation_id].asUInt());
 }
 
 }  // namespace commands
index 1c1c43c..da474cb 100644 (file)
@@ -31,6 +31,7 @@
  */
 
 #include "application_manager/commands/hmi/sdl_get_list_of_permissions_response.h"
+#include "application_manager/application_manager_impl.h"
 
 namespace application_manager {
 
@@ -45,6 +46,10 @@ SDLGetListOfPermissionsResponse::~SDLGetListOfPermissionsResponse() {
 
 void SDLGetListOfPermissionsResponse::Run() {
   LOG4CXX_INFO(logger_, "SDLGetListOfPermissionsResponse::Run");
+  (*message_)[strings::params][strings::protocol_type] = hmi_protocol_type_;
+  (*message_)[strings::params][strings::protocol_version] = protocol_version_;
+
+  ApplicationManagerImpl::instance()->SendMessageToHMI(message_);
 }
 
 }  // namespace commands
index b9f063d..629b829 100644 (file)
@@ -1389,7 +1389,49 @@ void MessageHelper::SendGetUserFriendlyMessageResponse(
     }
   }
 
-  PrintSmartObject(*message);
+  ApplicationManagerImpl::instance()->ManageHMICommand(message);
+}
+
+void MessageHelper::SendGetListOfPermissionsResponse(
+    std::vector<policy::FunctionalGroupPermission>& permissions,
+    uint32_t correlation_id) {
+  smart_objects::SmartObject* message = new smart_objects::SmartObject(
+    smart_objects::SmartType_Map);
+  if (!message) {
+    return;
+  }
+
+  (*message)[strings::params][strings::function_id] =
+    hmi_apis::FunctionID::SDL_GetListOfPermissions;
+  (*message)[strings::params][strings::message_type] =
+    MessageType::kResponse;
+  (*message)[strings::params][strings::correlation_id] = correlation_id;
+  (*message)[strings::params]["code"] = 0;
+
+  const std::string allowed_functions = "allowedFunctions";
+  (*message)[strings::msg_params][allowed_functions] =
+      smart_objects::SmartObject(smart_objects::SmartType_Array);
+
+  smart_objects::SmartObject& allowed_functions_array =
+      (*message)[strings::msg_params][allowed_functions];
+
+  std::vector<policy::FunctionalGroupPermission>::const_iterator it =
+      permissions.begin();
+  std::vector<policy::FunctionalGroupPermission>::const_iterator it_end =
+      permissions.end();
+  for (uint32_t index = 0; it != it_end; ++it, ++index) {
+    allowed_functions_array[index] = smart_objects::SmartObject(
+                                       smart_objects::SmartType_Map);
+
+    smart_objects::SmartObject& item = allowed_functions_array[index];
+    item[strings::name] = (*it).group_name;
+    item[strings::id] = (*it).group_id;
+    policy::PermissionState permission_state = (*it).state;
+    // If state undefined, 'allowed' parameter should be absent
+    if (policy::kUndefined != permission_state) {
+      item["allowed"] = policy::kAllowed == permission_state;
+    }
+  }
 
   ApplicationManagerImpl::instance()->ManageHMICommand(message);
 }
index 0a77d41..7aae9c5 100644 (file)
@@ -252,6 +252,41 @@ void PolicyHandler::OnGetUserFriendlyMessage(
         result, correlation_id);
 }
 
+void PolicyHandler::OnGetListOfPermissions(const uint32_t connection_key,
+                                           const uint32_t correlation_id) {
+  LOG4CXX_INFO(logger_, "OnGetListOfPermissions");
+  // Get policy_app_id
+  std::string policy_app_id;
+  const ApplicationList app_list =
+    application_manager::ApplicationManagerImpl::instance()->applications();
+  ApplicationList::const_iterator it = app_list.begin();
+  ApplicationList::const_iterator it_end = app_list.end();
+  for (; it != it_end; ++it) {
+    if ((*(*it)).app_id() == connection_key) {
+      policy_app_id = (*(*it)).mobile_app_id()->asString();
+      break;
+    }
+  }
+
+  DeviceParams device_params;
+  char buffer[16];
+  snprintf(buffer, 16, "%d", connection_key);
+  application_manager::MessageHelper::GetDeviceInfoForApp(std::string(buffer),
+                                                          &device_params);
+  std::vector<FunctionalGroupPermission> group_permissions;
+  if (device_params.device_mac_address.empty()) {
+    LOG4CXX_WARN(logger_, "Couldn't find device, which hosts application.");
+  } else if (policy_app_id.empty()) {
+    LOG4CXX_WARN(logger_, "Couldn't find application to get permissions.");
+  } else {
+   policy_manager_->GetUserPermissionsForApp(device_params.device_mac_address,
+                                             policy_app_id, group_permissions);
+  }
+
+  application_manager::MessageHelper::SendGetListOfPermissionsResponse(
+        group_permissions, correlation_id);
+}
+
 void PolicyHandler::OnAppRevoked(const std::string& policy_app_id) {
   LOG4CXX_INFO(logger_, "OnAppRevoked");
   const ApplicationList app_list =