diff options
author | Jacob Keeler <jacob.keeler@livioradio.com> | 2019-04-29 15:07:33 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-29 15:07:33 -0400 |
commit | 9165e83afbb7c852d90108dbff2e458ca10f1fae (patch) | |
tree | e4b64eac27a54d9c25a4212afb08c1f7182577fd /src/components | |
parent | 366111c16bb014c0ab13bca9e2265ea6b5a1f0fe (diff) | |
parent | 6706ce1dee84d8cb7d48bbbee685f9feb35955cd (diff) | |
download | sdl_core-9165e83afbb7c852d90108dbff2e458ca10f1fae.tar.gz |
Merge pull request #2894 from smartdevicelink/hotfix/on_app_service_data_error_cases
Add checks for error cases in OnAppServiceData
Diffstat (limited to 'src/components')
2 files changed, 69 insertions, 1 deletions
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/on_as_app_service_data_notification_from_hmi.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/on_as_app_service_data_notification_from_hmi.cc index 05266f834b..575aa5ca28 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/on_as_app_service_data_notification_from_hmi.cc +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/on_as_app_service_data_notification_from_hmi.cc @@ -32,6 +32,8 @@ #include "app_service_rpc_plugin/commands/hmi/on_as_app_service_data_notification_from_hmi.h" +#include "application_manager/app_service_manager.h" + namespace app_service_rpc_plugin { using namespace application_manager; namespace commands { @@ -54,6 +56,39 @@ OnASAppServiceDataNotificationFromHMI:: void OnASAppServiceDataNotificationFromHMI::Run() { LOG4CXX_AUTO_TRACE(logger_); LOG4CXX_DEBUG(logger_, "Received an OnAppServiceData from HMI"); + + std::string service_id = + (*message_)[strings::msg_params][strings::service_data] + [strings::service_id].asString(); + AppService* service = + application_manager_.GetAppServiceManager().FindServiceByID(service_id); + if (!service) { + LOG4CXX_ERROR( + logger_, "No published services exist with service ID: " << service_id); + return; + } else if (service->mobile_service) { + LOG4CXX_ERROR(logger_, "Service was not published by the HMI"); + return; + } else if (!service->record[strings::service_active].asBool()) { + LOG4CXX_ERROR(logger_, "Service is not active"); + return; + } + + std::string service_type = + (*message_)[strings::msg_params][strings::service_data] + [strings::service_type].asString(); + std::string published_service_type = + service->record[strings::service_manifest][strings::service_type] + .asString(); + if (published_service_type != service_type) { + LOG4CXX_ERROR(logger_, + "Service type mismatch, expected " + << service_type + << ", but service was published with type " + << published_service_type); + return; + } + SendNotificationToConsumers( mobile_apis::FunctionID::eType::OnAppServiceDataID); } diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/on_app_service_data_notification_from_mobile.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/on_app_service_data_notification_from_mobile.cc index 7bb62d298d..2e92bd19bb 100644 --- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/on_app_service_data_notification_from_mobile.cc +++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/on_app_service_data_notification_from_mobile.cc @@ -31,6 +31,7 @@ */ #include "app_service_rpc_plugin/commands/mobile/on_app_service_data_notification_from_mobile.h" +#include "application_manager/app_service_manager.h" #include "application_manager/application_impl.h" #include "application_manager/message_helper.h" #include "application_manager/rpc_service.h" @@ -60,11 +61,13 @@ void OnAppServiceDataNotificationFromMobile::Run() { LOG4CXX_DEBUG(logger_, "Received an OnAppServiceData"); MessageHelper::PrintSmartObject(*message_); + uint32_t app_connection_key = connection_key(); std::string service_type = (*message_)[strings::msg_params][strings::service_data] [strings::service_type].asString(); - ApplicationSharedPtr app = application_manager_.application(connection_key()); + ApplicationSharedPtr app = + application_manager_.application(app_connection_key); bool result = policy_handler_.CheckAppServiceParameters( app->policy_app_id(), std::string(), service_type, NULL); @@ -76,6 +79,36 @@ void OnAppServiceDataNotificationFromMobile::Run() { return; } + std::string service_id = + (*message_)[strings::msg_params][strings::service_data] + [strings::service_id].asString(); + AppService* service = + application_manager_.GetAppServiceManager().FindServiceByID(service_id); + if (!service) { + LOG4CXX_ERROR( + logger_, "No published services exist with service ID: " << service_id); + return; + } else if (!service->mobile_service || + service->connection_key != app_connection_key) { + LOG4CXX_ERROR(logger_, "Service was not published by this application"); + return; + } else if (!service->record[strings::service_active].asBool()) { + LOG4CXX_ERROR(logger_, "Service is not active"); + return; + } + + std::string published_service_type = + service->record[strings::service_manifest][strings::service_type] + .asString(); + if (published_service_type != service_type) { + LOG4CXX_ERROR(logger_, + "Service type mismatch, expected " + << service_type + << ", but service was published with type " + << published_service_type); + return; + } + SendNotificationToConsumers( hmi_apis::FunctionID::eType::AppService_OnAppServiceData); } |