diff options
Diffstat (limited to 'src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc')
-rw-r--r-- | src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc | 109 |
1 files changed, 90 insertions, 19 deletions
diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc index 065425dd02..885c5ac0dd 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc @@ -31,9 +31,13 @@ */ #include "rc_rpc_plugin/commands/rc_command_request.h" +#include <sstream> #include "application_manager/hmi_interfaces.h" #include "application_manager/message_helper.h" +#include "application_manager/policies/policy_handler_interface.h" +#include "rc_rpc_plugin/commands/rc_command_request.h" #include "rc_rpc_plugin/interior_data_cache.h" +#include "rc_rpc_plugin/rc_helpers.h" #include "rc_rpc_plugin/rc_module_constants.h" #include "smart_objects/enum_schema_item.h" @@ -55,7 +59,9 @@ RCCommandRequest::RCCommandRequest( , auto_allowed_(false) , resource_allocation_manager_(params.resource_allocation_manager_) , interior_data_cache_(params.interior_data_cache_) - , interior_data_manager_(params.interior_data_manager_) {} + , interior_data_manager_(params.interior_data_manager_) + , rc_capabilities_manager_(params.rc_capabilities_manager_) + , rc_consent_manager_(params.rc_consent_manager_) {} RCCommandRequest::~RCCommandRequest() {} @@ -100,6 +106,14 @@ rc_rpc_plugin::TypeAccess RCCommandRequest::CheckModule( : rc_rpc_plugin::TypeAccess::kDisallowed; } +bool RCCommandRequest::IsModuleIdProvided( + const smart_objects::SmartObject& hmi_response) const { + LOG4CXX_AUTO_TRACE(logger_); + return hmi_response[app_mngr::strings::msg_params] + [message_params::kModuleData] + .keyExists(message_params::kModuleId); +} + void RCCommandRequest::SendDisallowed(rc_rpc_plugin::TypeAccess access) { LOG4CXX_AUTO_TRACE(logger_); std::string info; @@ -143,6 +157,15 @@ void RCCommandRequest::Run() { "Remote control is disabled by user"); return; } + auto rc_capabilities = hmi_capabilities_.rc_capability(); + if (!rc_capabilities || rc_capabilities->empty()) { + LOG4CXX_WARN(logger_, "Accessing not supported module: " << ModuleType()); + SetResourceState(ModuleType(), ResourceState::FREE); + SendResponse(false, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + "Accessing not supported module"); + return; + } if (CheckDriverConsent()) { if (AcquireResources()) { @@ -157,8 +180,9 @@ void RCCommandRequest::Run() { bool RCCommandRequest::AcquireResources() { LOG4CXX_AUTO_TRACE(logger_); const std::string module_type = ModuleType(); + const std::string module_id = ModuleId(); - if (!IsResourceFree(module_type)) { + if (!IsResourceFree(module_type, module_id)) { LOG4CXX_WARN(logger_, "Resource is busy."); SendResponse(false, mobile_apis::Result::IN_USE, ""); return false; @@ -175,7 +199,7 @@ bool RCCommandRequest::AcquireResources() { return false; } case AcquireResult::ASK_DRIVER: { - SendGetUserConsent(module_type); + ProcessAskDriverMode(module_type, module_id); return false; } case AcquireResult::REJECTED: { @@ -203,6 +227,7 @@ void RCCommandRequest::ProcessAccessResponse( app_mngr::ApplicationSharedPtr app = application_manager_.application(CommandRequestImpl::connection_key()); const std::string module_type = ModuleType(); + const std::string module_id = ModuleId(); if (!app) { LOG4CXX_ERROR(logger_, "NULL pointer."); SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED, ""); @@ -227,23 +252,18 @@ void RCCommandRequest::ProcessAccessResponse( if (message[app_mngr::strings::msg_params].keyExists( message_params::kAllowed)) { is_allowed = - message[app_mngr::strings::msg_params][message_params::kAllowed] + message[app_mngr::strings::msg_params][message_params::kAllowed][0] .asBool(); } - if (is_allowed) { - resource_allocation_manager_.ForceAcquireResource(module_type, - app->app_id()); - SetResourceState(module_type, ResourceState::BUSY); - Execute(); // run child's logic - } else { - resource_allocation_manager_.OnDriverDisallowed(module_type, - app->app_id()); - SendResponse( - false, - mobile_apis::Result::REJECTED, - "The resource is in use and the driver disallows this remote " - "control RPC"); - } + std::string policy_app_id = app->policy_app_id(); + const auto mac_address = app->mac_address(); + std::vector<std::string> module_ids{module_id}; + std::vector<bool> module_allowed{is_allowed}; + auto module_consents = + RCHelpers::FillModuleConsents(module_type, module_ids, module_allowed); + rc_consent_manager_.SaveModuleConsents( + policy_app_id, mac_address, module_consents); + ProcessConsentResult(is_allowed, module_type, module_id, app->app_id()); } else { std::string response_info; GetInfo(message, response_info); @@ -251,7 +271,56 @@ void RCCommandRequest::ProcessAccessResponse( } } -void RCCommandRequest::SendGetUserConsent(const std::string& module_type) { +void RCCommandRequest::ProcessConsentResult(const bool is_allowed, + const std::string& module_type, + const std::string& module_id, + const uint32_t app_id) { + LOG4CXX_AUTO_TRACE(logger_); + if (is_allowed) { + SetResourceState(module_type, ResourceState::BUSY); + Execute(); // run child's logic + } else { + resource_allocation_manager_.OnDriverDisallowed( + module_type, module_id, app_id); + + std::stringstream ss; + ss << "The resource [" << module_type << ":" << module_id + << "] is in use and the driver disallows this remote " + "control RPC"; + SendResponse(false, mobile_apis::Result::REJECTED, ss.str().c_str()); + } +} + +void RCCommandRequest::ProcessAskDriverMode(const std::string& module_type, + const std::string& module_id) { + LOG4CXX_AUTO_TRACE(logger_); + auto app = + application_manager_.application(CommandRequestImpl::connection_key()); + const std::string policy_app_id = app->policy_app_id(); + const std::string mac_address = app->mac_address(); + + auto consent = rc_consent_manager_.GetModuleConsent( + policy_app_id, mac_address, {module_type, module_id}); + switch (consent) { + case rc_rpc_types::ModuleConsent::NOT_EXISTS: { + smart_objects::SmartObject module_ids( + smart_objects::SmartType::SmartType_Array); + module_ids[0] = module_id; + SendGetUserConsent(module_type, module_ids); + break; + } + case rc_rpc_types::ModuleConsent::NOT_CONSENTED: + case rc_rpc_types::ModuleConsent::CONSENTED: { + const bool is_allowed = rc_rpc_types::ModuleConsent::CONSENTED == consent; + ProcessConsentResult(is_allowed, module_type, module_id, app->app_id()); + break; + } + }; +} + +void RCCommandRequest::SendGetUserConsent( + const std::string& module_type, + const smart_objects::SmartObject& module_ids) { LOG4CXX_AUTO_TRACE(logger_); app_mngr::ApplicationSharedPtr app = application_manager_.application(CommandRequestImpl::connection_key()); @@ -260,6 +329,8 @@ void RCCommandRequest::SendGetUserConsent(const std::string& module_type) { smart_objects::SmartObject(smart_objects::SmartType_Map); msg_params[app_mngr::strings::app_id] = app->app_id(); msg_params[message_params::kModuleType] = module_type; + msg_params[message_params::kModuleIds] = module_ids; + SendHMIRequest(hmi_apis::FunctionID::RC_GetInteriorVehicleDataConsent, &msg_params, true); |