summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIra Lytvynenko <ILytvynenko@luxoft.com>2017-09-06 18:24:11 +0300
committerAndriy Byzhynar <AByzhynar@luxoft.com>2018-01-26 11:38:08 +0200
commit84c66872ec88086332c96f3d7afef5d4d6445978 (patch)
treefe0a153d9e0cdab2311348fad6b282bf3649fd07
parentb973e81afb1d38a27a478ce706e16b5352fb026b (diff)
downloadsdl_core-84c66872ec88086332c96f3d7afef5d4d6445978.tar.gz
Fix SendLocation implementation according to proposal
Fixed processing of disallowed mandatory parameters. Removed logic no valid after setting longitude and latitude as mandatory.
-rw-r--r--src/components/application_manager/include/application_manager/commands/mobile/send_location_request.h16
-rw-r--r--src/components/application_manager/src/commands/command_request_impl.cc3
-rw-r--r--src/components/application_manager/src/commands/mobile/send_location_request.cc132
-rw-r--r--src/components/interfaces/HMI_API.xml8
-rw-r--r--src/components/interfaces/MOBILE_API.xml19
-rw-r--r--src/components/policy/policy_regular/include/policy/policy_table/enums.h11
-rw-r--r--src/components/policy/policy_regular/src/policy_table/enums.cc77
7 files changed, 211 insertions, 55 deletions
diff --git a/src/components/application_manager/include/application_manager/commands/mobile/send_location_request.h b/src/components/application_manager/include/application_manager/commands/mobile/send_location_request.h
index 570e70d007..063c8064ea 100644
--- a/src/components/application_manager/include/application_manager/commands/mobile/send_location_request.h
+++ b/src/components/application_manager/include/application_manager/commands/mobile/send_location_request.h
@@ -1,6 +1,6 @@
/*
- Copyright (c) 2013, Ford Motor Company
+ Copyright (c) 2017, Ford Motor Company
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -84,6 +84,20 @@ class SendLocationRequest : public CommandRequestImpl {
*/
bool IsWhiteSpaceExist();
+ /**
+ * @brief Check policy permissions of mandatory parameters
+ * @return false in case when one of mandatory params disallowed by policy
+ * otherwise return true
+ */
+ bool AreMandatoryParamsAllowedByPolicy() const;
+
+ /**
+ * @brief Check policy permissions of mandatory parameters
+ * @return false in case when one of mandatory params disallowed by user
+ * otherwise return true
+ */
+ bool AreMandatoryParamsAllowedByUser() const;
+
bool CheckHMICapabilities(
std::vector<hmi_apis::Common_TextFieldName::eType>& fields_names);
DISALLOW_COPY_AND_ASSIGN(SendLocationRequest);
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 09aa4169e5..eca05da1ad 100644
--- a/src/components/application_manager/src/commands/command_request_impl.cc
+++ b/src/components/application_manager/src/commands/command_request_impl.cc
@@ -290,7 +290,8 @@ void CommandRequestImpl::SendResponse(
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)) {
+ (id == mobile_apis::FunctionID::UnsubscribeVehicleDataID) ||
+ (id == mobile_apis::FunctionID::SendLocationID)) {
AddDisallowedParameters(response);
AddDisallowedParametersToInfo(response);
} else if (id == mobile_apis::FunctionID::GetVehicleDataID) {
diff --git a/src/components/application_manager/src/commands/mobile/send_location_request.cc b/src/components/application_manager/src/commands/mobile/send_location_request.cc
index 54664a8771..2dac94bbd2 100644
--- a/src/components/application_manager/src/commands/mobile/send_location_request.cc
+++ b/src/components/application_manager/src/commands/mobile/send_location_request.cc
@@ -1,6 +1,6 @@
/*
- Copyright (c) 2013, Ford Motor Company
+ Copyright (c) 2017, Ford Motor Company
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -62,13 +62,26 @@ void SendLocationRequest::Run() {
smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params];
if (msg_params.keyExists(strings::delivery_mode)) {
- const RPCParams& allowed_params = parameters_permissions().allowed_params;
+ const policy::RPCParams& allowed_params =
+ parameters_permissions().allowed_params;
if (helpers::in_range(allowed_params, strings::delivery_mode)) {
msg_params.erase(strings::delivery_mode);
}
}
+ if (!AreMandatoryParamsAllowedByUser()) {
+ LOG4CXX_ERROR(logger_, "All parameters are disallowed by user.");
+ SendResponse(false, mobile_api::Result::USER_DISALLOWED);
+ return;
+ }
+
+ if (!AreMandatoryParamsAllowedByPolicy()) {
+ LOG4CXX_ERROR(logger_, "Mandatory parameters are disallowed by policy.");
+ SendResponse(false, mobile_api::Result::DISALLOWED);
+ return;
+ }
+
std::vector<Common_TextFieldName::eType> fields_to_check;
if (msg_params.keyExists(strings::location_name)) {
fields_to_check.push_back(Common_TextFieldName::locationName);
@@ -94,14 +107,11 @@ void SendLocationRequest::Run() {
return;
}
- if (msg_params.keyExists(strings::address)) {
- const utils::custom_string::CustomString& address =
- msg_params[strings::address].asCustomString();
- if (address.empty()) {
- msg_params.erase(strings::address);
- }
+ if (msg_params.keyExists(strings::address) &&
+ msg_params[strings::address].empty()) {
+ msg_params.erase(strings::address);
}
-
+
if (!CheckFieldsCompatibility()) {
LOG4CXX_ERROR(logger_, "CheckFieldsCompatibility failed");
SendResponse(false, mobile_apis::Result::INVALID_DATA);
@@ -122,12 +132,11 @@ void SendLocationRequest::Run() {
}
}
- SmartObject request_msg_params = SmartObject(smart_objects::SmartType_Map);
- request_msg_params = msg_params;
- request_msg_params[strings::app_id] = app->hmi_app_id();
- StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Navigation);
- SendHMIRequest(
- hmi_apis::FunctionID::Navigation_SendLocation, &request_msg_params, true);
+ SmartObject hmi_request_msg_params = msg_params;
+ hmi_request_msg_params[strings::app_id] = app->hmi_app_id();
+ SendHMIRequest(hmi_apis::FunctionID::Navigation_SendLocation,
+ &hmi_request_msg_params,
+ true);
}
void SendLocationRequest::on_event(const event_engine::Event& event) {
@@ -207,15 +216,25 @@ bool SendLocationRequest::IsWhiteSpaceExist() {
if (msg_params.keyExists(strings::address)) {
const smart_objects::SmartObject& address_so = msg_params[strings::address];
- insert_if_contains(address_so, strings::country_name, fields_to_check);
- insert_if_contains(address_so, strings::country_code, fields_to_check);
- insert_if_contains(address_so, strings::postal_code, fields_to_check);
- insert_if_contains(
- address_so, strings::administrative_area, fields_to_check);
- insert_if_contains(address_so, strings::locality, fields_to_check);
- insert_if_contains(address_so, strings::sub_locality, fields_to_check);
- insert_if_contains(address_so, strings::thoroughfare, fields_to_check);
- insert_if_contains(address_so, strings::sub_thoroughfare, fields_to_check);
+ const std::set<std::string> keys = msg_params[strings::address].enumerate();
+
+ std::set<std::string>::const_iterator keys_it = keys.begin();
+
+ while (keys.end() != keys_it) {
+ const utils::custom_string::CustomString& field_value =
+ address_so[*keys_it].asCustomString();
+ if (!field_value.empty()) {
+ fields_to_check.push_back(field_value);
+ }
+ ++keys_it;
+ }
+ }
+
+ if (msg_params.keyExists(strings::location_image)) {
+ if (msg_params[strings::location_image].keyExists(strings::value)) {
+ fields_to_check.push_back(
+ msg_params[strings::location_image][strings::value].asCustomString());
+ }
}
std::vector<utils::custom_string::CustomString>::iterator it =
@@ -245,32 +264,59 @@ bool SendLocationRequest::CheckHMICapabilities(
LOG4CXX_ERROR(logger_, "UI is not supported.");
return false;
}
-
- if (hmi_capabilities.display_capabilities()) {
- const SmartObject disp_cap = (*hmi_capabilities.display_capabilities());
- const SmartObject& text_fields =
- disp_cap.getElement(hmi_response::text_fields);
- const size_t len = text_fields.length();
- for (size_t i = 0; i < len; ++i) {
- const SmartObject& text_field = text_fields[i];
- const Common_TextFieldName::eType filed_name =
- static_cast<Common_TextFieldName::eType>(
- text_field.getElement(strings::name).asInt());
- const std::vector<Common_TextFieldName::eType>::iterator it =
- std::find(fields_names.begin(), fields_names.end(), filed_name);
- if (it != fields_names.end()) {
- fields_names.erase(it);
+ if (!hmi_capabilities.is_navi_cooperating()) {
+ LOG4CXX_ERROR(logger_, "NAVI is not supported.");
+ return false;
+ }
+ if (!fields_names.empty()) {
+ if (hmi_capabilities.display_capabilities()) {
+ const SmartObject& disp_cap = (*hmi_capabilities.display_capabilities());
+ const SmartObject& text_fields =
+ disp_cap.getElement(hmi_response::text_fields);
+ const size_t len = text_fields.length();
+ for (size_t i = 0; i < len; ++i) {
+ const SmartObject& text_field = text_fields[i];
+ const Common_TextFieldName::eType field_name =
+ static_cast<Common_TextFieldName::eType>(
+ text_field.getElement(strings::name).asInt());
+ const std::vector<Common_TextFieldName::eType>::iterator it =
+ std::find(fields_names.begin(), fields_names.end(), field_name);
+ if (it != fields_names.end()) {
+ fields_names.erase(it);
+ }
}
}
- }
- if (!fields_names.empty()) {
- LOG4CXX_ERROR(logger_, "Some fields are not supported by capabilities");
- return false;
+ if (!fields_names.empty()) {
+ LOG4CXX_ERROR(logger_, "Some fields are not supported by capabilities");
+ return false;
+ }
}
return true;
}
+bool SendLocationRequest::AreMandatoryParamsAllowedByUser() const {
+ const policy::RPCParams& disallowed_params =
+ parameters_permissions().disallowed_params;
+ const bool latitude_degrees_disallowed =
+ helpers::in_range(disallowed_params, strings::latitude_degrees);
+ const bool longitude_degrees_disallowed =
+ helpers::in_range(disallowed_params, strings::longitude_degrees);
+
+ return !latitude_degrees_disallowed && !longitude_degrees_disallowed;
+}
+
+bool SendLocationRequest::AreMandatoryParamsAllowedByPolicy() const {
+ const policy::RPCParams& allowed_params =
+ parameters_permissions().allowed_params;
+ const bool latitude_degrees_allowed =
+ helpers::in_range(allowed_params, strings::latitude_degrees);
+ const bool longitude_degrees_allowed =
+ helpers::in_range(allowed_params, strings::longitude_degrees);
+
+ return latitude_degrees_allowed && longitude_degrees_allowed;
+}
+
} // namespace commands
} // namespace application_manager
diff --git a/src/components/interfaces/HMI_API.xml b/src/components/interfaces/HMI_API.xml
index ab3933fc0f..5d7f52cb92 100644
--- a/src/components/interfaces/HMI_API.xml
+++ b/src/components/interfaces/HMI_API.xml
@@ -2527,10 +2527,10 @@
<param name="countryName" minlength="0" maxlength="200" type="String" mandatory="false">
<description>Name of the country (localized)</description>
</param>
- <param name="countryCode" minlength="0" maxlength="50" type="String" mandatory="false">
+ <param name="countryCode" minlength="0" maxlength="200" type="String" mandatory="false">
<description>Name of country (ISO 3166-2)</description>
</param>
- <param name="postalCode" minlength="0" maxlength="16" type="String" mandatory="false">
+ <param name="postalCode" minlength="0" maxlength="200" type="String" mandatory="false">
<description>(PLZ, ZIP, PIN, CAP etc.)</description>
</param>
<param name="administrativeArea" minlength="0" maxlength="200" type="String" mandatory="false">
@@ -3879,9 +3879,9 @@
<param name="appID" type="Integer" mandatory="true">
<description>ID of application related to this RPC.</description>
</param>
- <param name="longitudeDegrees" type="Float" minvalue="-180" maxvalue="180" mandatory="false">
+ <param name="longitudeDegrees" type="Double" minvalue="-180" maxvalue="180" mandatory="true">
</param>
- <param name="latitudeDegrees" type="Float" minvalue="-90" maxvalue="90" mandatory="false">
+ <param name="latitudeDegrees" type="Double" minvalue="-90" maxvalue="90" mandatory="true">
</param>
<param name="locationName" type="String" maxlength="500" mandatory="false">
<description> Name / title of intended location </description>
diff --git a/src/components/interfaces/MOBILE_API.xml b/src/components/interfaces/MOBILE_API.xml
index a1c64aecda..9bf06049a8 100644
--- a/src/components/interfaces/MOBILE_API.xml
+++ b/src/components/interfaces/MOBILE_API.xml
@@ -2438,10 +2438,10 @@
<param name="countryName" minlength="0" maxlength="200" type="String" mandatory="false">
<description>Name of the country (localized)</description>
</param>
- <param name="countryCode" minlength="0" maxlength="50" type="String" mandatory="false">
+ <param name="countryCode" minlength="0" maxlength="200" type="String" mandatory="false">
<description>Name of country (ISO 3166-2)</description>
</param>
- <param name="postalCode" minlength="0" maxlength="16" type="String" mandatory="false">
+ <param name="postalCode" minlength="0" maxlength="200" type="String" mandatory="false">
<description>(PLZ, ZIP, PIN, CAP etc.)</description>
</param>
<param name="administrativeArea" minlength="0" maxlength="200" type="String" mandatory="false">
@@ -5331,9 +5331,9 @@
</function>
<function name="SendLocation" functionID="SendLocationID" messagetype="request">
- <param name="longitudeDegrees" type="Float" minvalue="-180" maxvalue="180" mandatory="false">
+ <param name="longitudeDegrees" type="Double" minvalue="-180" maxvalue="180" mandatory="true">
</param>
- <param name="latitudeDegrees" type="Float" minvalue="-90" maxvalue="90" mandatory="false">
+ <param name="latitudeDegrees" type="Double" minvalue="-90" maxvalue="90" mandatory="true">
</param>
<param name="locationName" type="String" maxlength="500" mandatory="false">
<description>
@@ -5370,8 +5370,12 @@
<param name="address" type="OASISAddress" mandatory="false">
<description>Address to be used for setting destination</description>
</param>
- <param name="deliveryMode" type="DeliveryMode" mandatory="false">
- <description>Defines the mode of prompt for user</description>
+ <param name="deliveryMode" type="DeliveryMode" defvalue="PROMPT" mandatory="false">
+ <description>
+ Prompt =>User should be prompted on HMI.
+ Destination => Set the location as destination.
+ Queue =>Add the current location to navigation queue.
+ </description>
</param>
</function>
@@ -5390,7 +5394,10 @@
<element name="GENERIC_ERROR"/>
<element name="REJECTED"/>
<element name="UNSUPPORTED_RESOURCE"/>
+ <element name="USER_DISALLOWED"/>
<element name="DISALLOWED"/>
+ <element name="ABORTED"/>
+ <element name="SAVED"/>
</param>
<param name="info" type="String" maxlength="1000" mandatory="false" platform="documentation">
diff --git a/src/components/policy/policy_regular/include/policy/policy_table/enums.h b/src/components/policy/policy_regular/include/policy/policy_table/enums.h
index 66ab9a1b60..8d9f0452ec 100644
--- a/src/components/policy/policy_regular/include/policy/policy_table/enums.h
+++ b/src/components/policy/policy_regular/include/policy/policy_table/enums.h
@@ -87,6 +87,17 @@ enum Parameter {
P_DEVICESTATUS,
P_EMERGENCYEVENT,
P_ECALLINFO,
+ P_LONGTITUDE_DEGREES,
+ P_LATITUDE_DEGREES,
+ P_LOCATION_NAME,
+ P_LOCATION_DESCRIPTION,
+ P_ADDRESS_LINES,
+ P_PHONE_NUMBER,
+ P_LOCATION_IMAGE,
+ P_DELIVERY_MODE,
+ P_TIMESTAMP,
+ P_ADDRESS,
+ P_EMPTY // Added to allow empty parameters handling
};
bool IsValidEnum(Parameter val);
diff --git a/src/components/policy/policy_regular/src/policy_table/enums.cc b/src/components/policy/policy_regular/src/policy_table/enums.cc
index e0f77be989..e47eacc6dd 100644
--- a/src/components/policy/policy_regular/src/policy_table/enums.cc
+++ b/src/components/policy/policy_regular/src/policy_table/enums.cc
@@ -161,6 +161,28 @@ bool IsValidEnum(Parameter val) {
return true;
case P_ECALLINFO:
return true;
+ case P_LONGTITUDE_DEGREES:
+ return true;
+ case P_LATITUDE_DEGREES:
+ return true;
+ case P_LOCATION_NAME:
+ return true;
+ case P_LOCATION_DESCRIPTION:
+ return true;
+ case P_ADDRESS_LINES:
+ return true;
+ case P_PHONE_NUMBER:
+ return true;
+ case P_LOCATION_IMAGE:
+ return true;
+ case P_DELIVERY_MODE:
+ return true;
+ case P_TIMESTAMP:
+ return true;
+ case P_ADDRESS:
+ return true;
+ case P_EMPTY:
+ return true;
default:
return false;
}
@@ -217,6 +239,28 @@ const char* EnumToJsonString(Parameter val) {
return "emergencyEvent";
case P_ECALLINFO:
return "eCallInfo";
+ case P_LONGTITUDE_DEGREES:
+ return "longitudeDegrees";
+ case P_LATITUDE_DEGREES:
+ return "latitudeDegrees";
+ case P_LOCATION_NAME:
+ return "locationName";
+ case P_LOCATION_DESCRIPTION:
+ return "locationDescription";
+ case P_ADDRESS_LINES:
+ return "addressLines";
+ case P_PHONE_NUMBER:
+ return "phoneNumber";
+ case P_LOCATION_IMAGE:
+ return "locationImage";
+ case P_DELIVERY_MODE:
+ return "deliveryMode";
+ case P_TIMESTAMP:
+ return "timeStamp";
+ case P_ADDRESS:
+ return "address";
+ case P_EMPTY:
+ return "EMPTY";
default:
return "";
}
@@ -297,6 +341,39 @@ bool EnumFromJsonString(const std::string& literal, Parameter* result) {
} else if ("eCallInfo" == literal) {
*result = P_ECALLINFO;
return true;
+ } else if ("longitudeDegrees" == literal) {
+ *result = P_LONGTITUDE_DEGREES;
+ return true;
+ } else if ("latitudeDegrees" == literal) {
+ *result = P_LATITUDE_DEGREES;
+ return true;
+ } else if ("locationName" == literal) {
+ *result = P_LOCATION_NAME;
+ return true;
+ } else if ("locationDescription" == literal) {
+ *result = P_LOCATION_DESCRIPTION;
+ return true;
+ } else if ("addressLines" == literal) {
+ *result = P_ADDRESS_LINES;
+ return true;
+ } else if ("phoneNumber" == literal) {
+ *result = P_PHONE_NUMBER;
+ return true;
+ } else if ("locationImage" == literal) {
+ *result = P_LOCATION_IMAGE;
+ return true;
+ } else if ("deliveryMode" == literal) {
+ *result = P_DELIVERY_MODE;
+ return true;
+ } else if ("timeStamp" == literal) {
+ *result = P_TIMESTAMP;
+ return true;
+ } else if ("address" == literal) {
+ *result = P_ADDRESS;
+ return true;
+ } else if ("EMPTY" == literal) {
+ *result = P_EMPTY;
+ return true;
} else {
return false;
}