summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Zhdanov (GitHub) <39907184+ZhdanovP@users.noreply.github.com>2021-05-07 19:15:57 +0300
committerGitHub <noreply@github.com>2021-05-07 12:15:57 -0400
commit0cb74bf5a867a71ac760a8bd5c9c2b2af7faccf2 (patch)
tree352be71e085b7bb3e37455f94aee68d83aa7fec8
parentd9fd9fb66ecd854207d8bbd5efb1728f1f6c1b5b (diff)
downloadsdl_core-0cb74bf5a867a71ac760a8bd5c9c2b2af7faccf2.tar.gz
Add mobile response with disallowed by user params (#2499)
* Add mobile responce with disallowed by user params * Answer PR comments * Answer PR comments * Update fix according to new hierarchy * fixup! Update fix according to new hierarchy * fixup! Update fix according to new hierarchy Co-authored-by: Andrii Kalinich <AKalinich@luxoft.com> Co-authored-by: Dmitriy Boltovskiy <dboltovskyi@luxoft.com>
-rw-r--r--src/components/application_manager/include/application_manager/commands/command_impl.h46
-rw-r--r--src/components/application_manager/include/application_manager/commands/command_request_impl.h23
-rw-r--r--src/components/application_manager/src/commands/command_impl.cc181
-rw-r--r--src/components/application_manager/src/commands/command_request_impl.cc91
-rw-r--r--src/components/application_manager/test/commands/command_request_impl_test.cc4
5 files changed, 231 insertions, 114 deletions
diff --git a/src/components/application_manager/include/application_manager/commands/command_impl.h b/src/components/application_manager/include/application_manager/commands/command_impl.h
index e3e30a9eff..1b4db7e888 100644
--- a/src/components/application_manager/include/application_manager/commands/command_impl.h
+++ b/src/components/application_manager/include/application_manager/commands/command_impl.h
@@ -40,6 +40,8 @@
#include "policy/policy_types.h"
#include "utils/logger.h"
+#include <algorithm>
+
namespace application_manager {
/**
@@ -50,6 +52,20 @@ struct CommandParametersPermissions {
RPCParams allowed_params;
RPCParams disallowed_params;
RPCParams undefined_params;
+
+ bool AreDisallowedParamsIncluded(const RPCParams& parameters) {
+ return std::includes(disallowed_params.begin(),
+ disallowed_params.end(),
+ parameters.begin(),
+ parameters.end());
+ }
+
+ bool AreUndefinedParamsIncluded(const RPCParams& parameters) {
+ return std::includes(undefined_params.begin(),
+ undefined_params.end(),
+ parameters.begin(),
+ parameters.end());
+ }
};
namespace commands {
@@ -183,6 +199,29 @@ class CommandImpl : public Command {
bool CheckAllowedParameters(const Command::CommandSource source);
/**
+ * @brief Adds disallowed parameters back to response with appropriate
+ * reasons
+ * @param response Response message, which should be extended with blocked
+ * parameters reasons
+ */
+ void AddDisallowedParameters(smart_objects::SmartObject& response);
+
+ /**
+ * @brief Adds disallowed parameters to response info
+ * @param response Response message, which info should be extended
+ */
+ void AddDisallowedParametersToInfo(
+ smart_objects::SmartObject& response) const;
+
+ /**
+ * @brief Adds param to disallowed parameters enumeration
+ * @param info string with disallowed params enumeration
+ * @param param disallowed param
+ */
+ void AddDisallowedParameterToInfoString(std::string& info,
+ const std::string& param) const;
+
+ /**
* @brief Remove from current message parameters disallowed by policy table
*/
void RemoveDisallowedParameters();
@@ -201,6 +240,13 @@ class CommandImpl : public Command {
*/
bool ReplaceHMIWithMobileAppId(smart_objects::SmartObject& message);
+ /**
+ * @brief Adds disallowed parameters to info string, sets result codes if
+ * necessary
+ * @param response Command smart object
+ */
+ void FormatResponse(smart_objects::SmartObject& response);
+
MessageSharedPtr message_;
uint32_t default_timeout_;
bool allowed_to_terminate_;
diff --git a/src/components/application_manager/include/application_manager/commands/command_request_impl.h b/src/components/application_manager/include/application_manager/commands/command_request_impl.h
index 87c19ca1d1..5723de3b08 100644
--- a/src/components/application_manager/include/application_manager/commands/command_request_impl.h
+++ b/src/components/application_manager/include/application_manager/commands/command_request_impl.h
@@ -243,14 +243,6 @@ class CommandRequestImpl : public CommandImpl,
bool CheckHMICapabilities(const mobile_apis::ButtonName::eType button) const;
/**
- * @brief Adds disallowed parameters back to response with appropriate
- * reasons
- * @param response Response message, which should be extended with blocked
- * parameters reasons
- */
- void AddDisallowedParameters(smart_objects::SmartObject& response);
-
- /**
* @brief Checks if any request param was marked as disallowed by policy
* @return true if any param was marked as disallowed
*/
@@ -375,21 +367,6 @@ class CommandRequestImpl : public CommandImpl,
private:
DISALLOW_COPY_AND_ASSIGN(CommandRequestImpl);
- /**
- * @brief Adds param to disallowed parameters enumeration
- * @param info string with disallowed params enumeration
- * @param param disallowed param
- */
- void AddDisallowedParameterToInfoString(std::string& info,
- const std::string& param) const;
-
- /**
- * @brief Adds disallowed parameters to response info
- * @param response Response message, which info should be extended
- */
- void AddDisallowedParametersToInfo(
- smart_objects::SmartObject& response) const;
-
bool ProcessHMIInterfacesAvailability(
const uint32_t hmi_correlation_id,
const hmi_apis::FunctionID::eType& function_id);
diff --git a/src/components/application_manager/src/commands/command_impl.cc b/src/components/application_manager/src/commands/command_impl.cc
index 47659e52ca..9efcaa451a 100644
--- a/src/components/application_manager/src/commands/command_impl.cc
+++ b/src/components/application_manager/src/commands/command_impl.cc
@@ -45,6 +45,26 @@ struct AppExtensionPredicate {
return app ? (app->QueryInterface(uid).use_count() != 0) : false;
}
};
+
+/**
+ * @brief Functor for build info string
+ */
+struct InfoAppender {
+ explicit InfoAppender(std::string& info) : info_(info) {}
+
+ void operator()(const RPCParams::value_type& parameter) {
+ if (info_.empty()) {
+ info_ = "\'" + parameter + "\'";
+ return;
+ }
+
+ info_ = info_ + ", \'" + parameter + "\'";
+ }
+
+ private:
+ std::string& info_;
+};
+
} // namespace
namespace commands {
@@ -179,6 +199,25 @@ bool CommandImpl::CheckAllowedParameters(const Command::CommandSource source) {
check_result,
correlation_id(),
app->app_id());
+
+ if (!params.empty()) {
+ if (parameters_permissions_.AreDisallowedParamsIncluded(params)) {
+ const std::string info = "RPC is disallowed by the user";
+ SDL_LOG_DEBUG(info);
+ (*response)[strings::msg_params][strings::info] = info;
+ AddDisallowedParameters(*response);
+ } else if (parameters_permissions_.AreUndefinedParamsIncluded(params)) {
+ const std::string info =
+ "Requested parameters are disallowed by Policies";
+
+ SDL_LOG_DEBUG(info);
+ (*response)[strings::msg_params][strings::info] = info;
+ AddDisallowedParameters(*response);
+ } else {
+ FormatResponse(*response);
+ }
+ }
+
rpc_service_.SendMessageToMobile(response);
}
@@ -198,6 +237,143 @@ bool CommandImpl::CheckAllowedParameters(const Command::CommandSource source) {
return true;
}
+struct DisallowedParamsInserter {
+ DisallowedParamsInserter(smart_objects::SmartObject& response,
+ mobile_apis::VehicleDataResultCode::eType code)
+ : response_(response), code_(code) {}
+
+ bool operator()(const std::string& param) {
+ smart_objects::SmartObjectSPtr disallowed_param =
+ std::make_shared<smart_objects::SmartObject>(
+ smart_objects::SmartType_Map);
+
+ auto rpc_spec_vehicle_data = MessageHelper::vehicle_data();
+ auto vehicle_data = rpc_spec_vehicle_data.find(param);
+ auto vehicle_data_type =
+ vehicle_data == rpc_spec_vehicle_data.end()
+ ? mobile_apis::VehicleDataType::VEHICLEDATA_OEM_CUSTOM_DATA
+ : vehicle_data->second;
+
+ (*disallowed_param)[strings::data_type] = vehicle_data_type;
+ (*disallowed_param)[strings::result_code] = code_;
+ response_[strings::msg_params][param.c_str()] = *disallowed_param;
+ return true;
+ }
+
+ private:
+ smart_objects::SmartObject& response_;
+ mobile_apis::VehicleDataResultCode::eType code_;
+};
+
+void CommandImpl::AddDisallowedParameters(
+ smart_objects::SmartObject& response) {
+ const mobile_apis::FunctionID::eType id =
+ static_cast<mobile_apis::FunctionID::eType>(function_id());
+
+ if (!helpers::
+ Compare<mobile_apis::FunctionID::eType, helpers::EQ, helpers::ONE>(
+ id,
+ mobile_apis::FunctionID::SubscribeVehicleDataID,
+ mobile_apis::FunctionID::UnsubscribeVehicleDataID)) {
+ SDL_LOG_INFO("The function id: " << id << " is not supported.");
+ return;
+ }
+
+ DisallowedParamsInserter disallowed_inserter(
+ response, mobile_apis::VehicleDataResultCode::VDRC_USER_DISALLOWED);
+ std::for_each(removed_parameters_permissions_.disallowed_params.begin(),
+ removed_parameters_permissions_.disallowed_params.end(),
+ disallowed_inserter);
+
+ DisallowedParamsInserter undefined_inserter(
+ response, mobile_apis::VehicleDataResultCode::VDRC_DISALLOWED);
+ std::for_each(removed_parameters_permissions_.undefined_params.begin(),
+ removed_parameters_permissions_.undefined_params.end(),
+ undefined_inserter);
+}
+
+void CommandImpl::AddDisallowedParameterToInfoString(
+ std::string& info, const std::string& param) const {
+ // prepare disallowed params enumeration for response info string
+ if (info.empty()) {
+ info = "\'" + param + "\'";
+ } else {
+ info = info + "," + " " + "\'" + param + "\'";
+ }
+}
+
+void CommandImpl::AddDisallowedParametersToInfo(
+ smart_objects::SmartObject& response) const {
+ SDL_LOG_AUTO_TRACE();
+ const mobile_apis::FunctionID::eType id =
+ static_cast<mobile_apis::FunctionID::eType>(function_id());
+
+ if (!helpers::
+ Compare<mobile_apis::FunctionID::eType, helpers::EQ, helpers::ONE>(
+ id,
+ mobile_apis::FunctionID::SubscribeVehicleDataID,
+ mobile_apis::FunctionID::UnsubscribeVehicleDataID,
+ mobile_apis::FunctionID::GetVehicleDataID,
+ mobile_apis::FunctionID::SendLocationID)) {
+ SDL_LOG_INFO("The function id: " << id << " is not supported.");
+ return;
+ }
+
+ std::string disallowed_by_user_info;
+ InfoAppender user_info_appender(disallowed_by_user_info);
+
+ std::for_each(removed_parameters_permissions_.disallowed_params.begin(),
+ removed_parameters_permissions_.disallowed_params.end(),
+ user_info_appender);
+
+ const size_t min_number_of_disallowed_params = 1;
+ if (!disallowed_by_user_info.empty()) {
+ disallowed_by_user_info +=
+ min_number_of_disallowed_params <
+ removed_parameters_permissions_.disallowed_params.size()
+ ? " are"
+ : " is";
+ disallowed_by_user_info += " disallowed by user";
+ }
+
+ std::string disallowed_by_policy_info;
+ InfoAppender policy_info_appender(disallowed_by_policy_info);
+
+ std::for_each(removed_parameters_permissions_.undefined_params.begin(),
+ removed_parameters_permissions_.undefined_params.end(),
+ policy_info_appender);
+
+ const size_t min_number_of_undefined_params = 1;
+ if (!disallowed_by_policy_info.empty()) {
+ disallowed_by_policy_info +=
+ min_number_of_undefined_params <
+ removed_parameters_permissions_.undefined_params.size()
+ ? " are"
+ : " is";
+ disallowed_by_policy_info += " disallowed by policies";
+ }
+
+ if (disallowed_by_user_info.empty() && disallowed_by_policy_info.empty()) {
+ SDL_LOG_INFO("There are not disallowed by user or by policy parameters.");
+ return;
+ }
+
+ smart_objects::SmartObject& info =
+ response[strings::msg_params][strings::info];
+
+ std::string summary;
+ if (!disallowed_by_policy_info.empty()) {
+ summary += disallowed_by_policy_info;
+ }
+
+ if (!disallowed_by_user_info.empty()) {
+ summary = summary.empty() ? disallowed_by_user_info
+ : summary + ", " + disallowed_by_user_info;
+ }
+
+ info = info.asString().empty() ? summary : info.asString() + " " + summary;
+}
+
void CommandImpl::RemoveDisallowedParameters() {
SDL_LOG_AUTO_TRACE();
@@ -275,6 +451,11 @@ bool CommandImpl::ReplaceMobileWithHMIAppId(
return true;
}
+void CommandImpl::FormatResponse(smart_objects::SmartObject& response) {
+ AddDisallowedParametersToInfo(response);
+ AddDisallowedParameters(response);
+}
+
bool CommandImpl::ReplaceHMIWithMobileAppId(
ns_smart_device_link::ns_smart_objects::SmartObject& message) {
if (message.keyExists(strings::app_id)) {
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 08bf25de54..bc4b514be4 100644
--- a/src/components/application_manager/src/commands/command_request_impl.cc
+++ b/src/components/application_manager/src/commands/command_request_impl.cc
@@ -138,34 +138,6 @@ bool IsResultCodeWarning(const ResponseInfo& first,
return first_is_ok_second_is_warn || both_warnings;
}
-struct DisallowedParamsInserter {
- DisallowedParamsInserter(smart_objects::SmartObject& response,
- mobile_apis::VehicleDataResultCode::eType code)
- : response_(response), code_(code) {}
-
- bool operator()(const std::string& param) {
- smart_objects::SmartObjectSPtr disallowed_param =
- std::make_shared<smart_objects::SmartObject>(
- smart_objects::SmartType_Map);
-
- auto rpc_spec_vehicle_data = MessageHelper::vehicle_data();
- auto vehicle_data = rpc_spec_vehicle_data.find(param);
- auto vehicle_data_type =
- vehicle_data == rpc_spec_vehicle_data.end()
- ? mobile_apis::VehicleDataType::VEHICLEDATA_OEM_CUSTOM_DATA
- : vehicle_data->second;
-
- (*disallowed_param)[strings::data_type] = vehicle_data_type;
- (*disallowed_param)[strings::result_code] = code_;
- response_[strings::msg_params][param.c_str()] = *disallowed_param;
- return true;
- }
-
- private:
- smart_objects::SmartObject& response_;
- mobile_apis::VehicleDataResultCode::eType code_;
-};
-
ResponseInfo::ResponseInfo()
: result_code(hmi_apis::Common_Result::INVALID_ENUM)
, interface(HmiInterfaces::HMI_INTERFACE_INVALID_ENUM)
@@ -305,15 +277,7 @@ void CommandRequestImpl::SendResponse(
// appropriate reasons (VehicleData result codes)
if (result_code != mobile_apis::Result::APPLICATION_NOT_REGISTERED &&
result_code != mobile_apis::Result::INVALID_DATA) {
- 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);
- }
+ FormatResponse(response);
}
response[strings::msg_params][strings::success] = success;
@@ -721,59 +685,6 @@ bool CommandRequestImpl::CheckHMICapabilities(
return false;
}
-void CommandRequestImpl::AddDisallowedParameterToInfoString(
- std::string& info, const std::string& param) const {
- // prepare disallowed params enumeration for response info string
- if (info.empty()) {
- info = "\'" + param + "\'";
- } else {
- info = info + "," + " " + "\'" + param + "\'";
- }
-}
-
-void CommandRequestImpl::AddDisallowedParametersToInfo(
- smart_objects::SmartObject& response) const {
- std::string info;
-
- RPCParams::const_iterator it =
- removed_parameters_permissions_.disallowed_params.begin();
- for (; it != removed_parameters_permissions_.disallowed_params.end(); ++it) {
- AddDisallowedParameterToInfoString(info, (*it));
- }
-
- it = removed_parameters_permissions_.undefined_params.begin();
- for (; it != removed_parameters_permissions_.undefined_params.end(); ++it) {
- AddDisallowedParameterToInfoString(info, (*it));
- }
-
- if (!info.empty()) {
- info += " disallowed by policies.";
-
- if (!response[strings::msg_params][strings::info].asString().empty()) {
- // If we already have info add info about disallowed params to it
- response[strings::msg_params][strings::info] =
- response[strings::msg_params][strings::info].asString() + " " + info;
- } else {
- response[strings::msg_params][strings::info] = info;
- }
- }
-}
-
-void CommandRequestImpl::AddDisallowedParameters(
- smart_objects::SmartObject& response) {
- DisallowedParamsInserter disallowed_inserter(
- response, mobile_apis::VehicleDataResultCode::VDRC_USER_DISALLOWED);
- std::for_each(removed_parameters_permissions_.disallowed_params.begin(),
- removed_parameters_permissions_.disallowed_params.end(),
- disallowed_inserter);
-
- DisallowedParamsInserter undefined_inserter(
- response, mobile_apis::VehicleDataResultCode::VDRC_DISALLOWED);
- std::for_each(removed_parameters_permissions_.undefined_params.begin(),
- removed_parameters_permissions_.undefined_params.end(),
- undefined_inserter);
-}
-
bool CommandRequestImpl::HasDisallowedParams() const {
return ((!removed_parameters_permissions_.disallowed_params.empty()) ||
(!removed_parameters_permissions_.undefined_params.empty()));
diff --git a/src/components/application_manager/test/commands/command_request_impl_test.cc b/src/components/application_manager/test/commands/command_request_impl_test.cc
index 9034bf442f..6470988680 100644
--- a/src/components/application_manager/test/commands/command_request_impl_test.cc
+++ b/src/components/application_manager/test/commands/command_request_impl_test.cc
@@ -454,7 +454,9 @@ TEST_F(CommandRequestImplTest, AddDisallowedParameters_SUCCESS) {
vehicle_data.insert(am::VehicleData::value_type(
kDisallowedParam1, mobile_apis::VehicleDataType::VEHICLEDATA_MYKEY));
- MessageSharedPtr msg;
+ MessageSharedPtr msg = CreateMessage();
+ (*msg)[strings::params][strings::function_id] =
+ mobile_apis::FunctionID::SubscribeVehicleDataID;
CommandPtr command = CreateCommand<UCommandRequestImpl>(msg);