diff options
author | AKalinich-Luxoft <AKalinich@luxoft.com> | 2017-11-03 13:25:04 +0200 |
---|---|---|
committer | BSolonenko <BSolonenko@luxoft.com> | 2018-01-26 12:36:17 +0200 |
commit | 533b2e3af6dbf967f864470299b4ade6ba32cd97 (patch) | |
tree | 2e6a829d6bd30acac033ee7fbe9c7e046c3d842d /src/components/application_manager/src | |
parent | 003b05cdd8cbfbbea04291031bb700396d6f87ff (diff) | |
download | sdl_core-533b2e3af6dbf967f864470299b4ade6ba32cd97.tar.gz |
Fix disallowed info message generating for specific RPCs
There was found a problem that general info message in case of disallowed
by policies params is not applicable for all RPCs. For example
SubscribeVehicleData/UnsubscribeVehicleData has own specific format of
info message in this case.
To fix that following changes were done:
- Added virtual function AddSpecificInfoToResponse() which could be overriden
in child RPCs in case custom info message required
- Removed hardcoded checks of function_id from command_request_impl - all this
checks will be done using polymorphism inside aproriate RPCs
- Fixed affected UT expectation. Invalid unit test was replaced with actual one.
Diffstat (limited to 'src/components/application_manager/src')
4 files changed, 44 insertions, 20 deletions
diff --git a/src/components/application_manager/src/commands/command_request_impl.cc b/src/components/application_manager/src/commands/command_request_impl.cc index c72dd0d435..b5fb062241 100644 --- a/src/components/application_manager/src/commands/command_request_impl.cc +++ b/src/components/application_manager/src/commands/command_request_impl.cc @@ -298,30 +298,16 @@ void CommandRequestImpl::SendResponse( response[strings::msg_params] = *response_params; } + response[strings::msg_params][strings::success] = success; + response[strings::msg_params][strings::result_code] = result_code; + if (info) { response[strings::msg_params][strings::info] = std::string(info); } - // Add disallowed parameters and info from request back to response with - // appropriate - // reasons (VehicleData result codes) - if (result_code != mobile_apis::Result::APPLICATION_NOT_REGISTERED) { - const mobile_apis::FunctionID::eType& id = - static_cast<mobile_apis::FunctionID::eType>(function_id()); - if ((id == mobile_apis::FunctionID::SubscribeVehicleDataID) || - (id == mobile_apis::FunctionID::UnsubscribeVehicleDataID)) { - AddDisallowedParameters(response); - AddDisallowedParametersToInfo(response); - } else if (id == mobile_apis::FunctionID::GetVehicleDataID) { - AddDisallowedParametersToInfo(response); - } - } - - response[strings::msg_params][strings::success] = success; - response[strings::msg_params][strings::result_code] = result_code; + AddSpecificInfoToResponse(response); is_success_result_ = success; - application_manager_.ManageMobileCommand(result, ORIGIN_SDL); } @@ -640,6 +626,8 @@ bool CommandRequestImpl::CheckAllowedParameters() { params, ¶meters_permissions_); + RemoveDisallowedParameters(); + // Check, if RPC is allowed by policy if (mobile_apis::Result::SUCCESS != check_result) { smart_objects::SmartObjectSPtr response = @@ -653,6 +641,8 @@ bool CommandRequestImpl::CheckAllowedParameters() { if (!info.empty()) { (*response)[strings::msg_params][strings::info] = info; } + AddSpecificInfoToResponse(*response); + application_manager_.SendMessageToMobile(response); return false; } @@ -665,8 +655,6 @@ bool CommandRequestImpl::CheckAllowedParameters() { return true; } - RemoveDisallowedParameters(); - return true; } @@ -765,6 +753,9 @@ void CommandRequestImpl::RemoveDisallowedParameters() { } } +void CommandRequestImpl::AddSpecificInfoToResponse( + smart_objects::SmartObject& response) {} + void CommandRequestImpl::AddDissalowedParameterToInfoString( std::string& info, const std::string& param) const { // prepare disallowed params enumeration for response info string diff --git a/src/components/application_manager/src/commands/mobile/get_vehicle_data_request.cc b/src/components/application_manager/src/commands/mobile/get_vehicle_data_request.cc index 84c6e0ba7c..85b21812fa 100644 --- a/src/components/application_manager/src/commands/mobile/get_vehicle_data_request.cc +++ b/src/components/application_manager/src/commands/mobile/get_vehicle_data_request.cc @@ -217,6 +217,11 @@ GetVehicleDataRequest::GetVehicleDataRequest( GetVehicleDataRequest::~GetVehicleDataRequest() {} +void GetVehicleDataRequest::AddSpecificInfoToResponse( + smart_objects::SmartObject& response) { + AddDisallowedParametersToInfo(response); +} + void GetVehicleDataRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); diff --git a/src/components/application_manager/src/commands/mobile/subscribe_vehicle_data_request.cc b/src/components/application_manager/src/commands/mobile/subscribe_vehicle_data_request.cc index 4e31a2abe2..6bf3da2db5 100644 --- a/src/components/application_manager/src/commands/mobile/subscribe_vehicle_data_request.cc +++ b/src/components/application_manager/src/commands/mobile/subscribe_vehicle_data_request.cc @@ -316,6 +316,20 @@ void SubscribeVehicleDataRequest::AddAlreadySubscribedVI( } } +void SubscribeVehicleDataRequest::AddSpecificInfoToResponse( + smart_objects::SmartObject& response) { + LOG4CXX_AUTO_TRACE(logger_); + AddDisallowedParameters(response); + if (helpers::Compare<mobile_apis::Result::eType, helpers::EQ, helpers::ONE>( + static_cast<mobile_apis::Result::eType>( + response[strings::msg_params][strings::result_code].asInt()), + mobile_apis::Result::DISALLOWED, + mobile_apis::Result::USER_DISALLOWED)) { + response[strings::msg_params][strings::info] = std::string(); + AddDisallowedParametersToInfo(response); + } +} + void SubscribeVehicleDataRequest::UnsubscribeFailedSubscriptions( ApplicationSharedPtr app, const smart_objects::SmartObject& msg_params) const { diff --git a/src/components/application_manager/src/commands/mobile/unsubscribe_vehicle_data_request.cc b/src/components/application_manager/src/commands/mobile/unsubscribe_vehicle_data_request.cc index f7317d72f9..2ff2b64405 100644 --- a/src/components/application_manager/src/commands/mobile/unsubscribe_vehicle_data_request.cc +++ b/src/components/application_manager/src/commands/mobile/unsubscribe_vehicle_data_request.cc @@ -395,5 +395,19 @@ void UnsubscribeVehicleDataRequest::AddAlreadyUnsubscribedVI( } } +void UnsubscribeVehicleDataRequest::AddSpecificInfoToResponse( + smart_objects::SmartObject& response) { + LOG4CXX_AUTO_TRACE(logger_); + AddDisallowedParameters(response); + if (helpers::Compare<mobile_apis::Result::eType, helpers::EQ, helpers::ONE>( + static_cast<mobile_apis::Result::eType>( + response[strings::msg_params][strings::result_code].asInt()), + mobile_apis::Result::DISALLOWED, + mobile_apis::Result::USER_DISALLOWED)) { + response[strings::msg_params][strings::info] = std::string(); + AddDisallowedParametersToInfo(response); + } +} + } // namespace commands } // namespace application_manager |