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
*
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
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);
}
*/
#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) {
}
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
*/
#include "application_manager/commands/hmi/sdl_get_list_of_permissions_response.h"
+#include "application_manager/application_manager_impl.h"
namespace application_manager {
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
}
}
- 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);
}
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 =