summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjacobkeeler <jacob.keeler@livioradio.com>2019-04-23 16:47:04 -0400
committerjacobkeeler <jacob.keeler@livioradio.com>2019-04-23 16:47:04 -0400
commitcedac89de0756fdab6f9cbe2c4a202e9370ca2be (patch)
tree09ebd170c22784a4e1c84c42fc7d767f2a2f476f
parent4e09fc9eabcfccb1a7cc6f13c34a1028d4abc75f (diff)
downloadsdl_core-cedac89de0756fdab6f9cbe2c4a202e9370ca2be.tar.gz
Add checks for error cases in OnAppServiceData
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/on_as_app_service_data_notification_from_hmi.cc35
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/on_app_service_data_notification_from_mobile.cc35
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..1da213e93d 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_DEBUG(
+ logger_, "No published services exist with service ID: " << service_id);
+ return;
+ } else if (service->mobile_service) {
+ LOG4CXX_DEBUG(logger_, "Service was not published by the HMI");
+ return;
+ } else if (!service->record[strings::service_active].asBool()) {
+ LOG4CXX_DEBUG(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_DEBUG(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..bfd9921e67 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_DEBUG(
+ logger_, "No published services exist with service ID: " << service_id);
+ return;
+ } else if (!service->mobile_service ||
+ service->connection_key != app_connection_key) {
+ LOG4CXX_DEBUG(logger_, "Service was not published by this application");
+ return;
+ } else if (!service->record[strings::service_active].asBool()) {
+ LOG4CXX_DEBUG(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_DEBUG(logger_,
+ "Service type mismatch, expected "
+ << service_type
+ << ", but service was published with type "
+ << published_service_type);
+ return;
+ }
+
SendNotificationToConsumers(
hmi_apis::FunctionID::eType::AppService_OnAppServiceData);
}