summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/application_manager/include/application_manager/app_service_manager.h15
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_publish_app_service_request.cc12
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_request.cc10
-rw-r--r--src/components/application_manager/src/app_service_manager.cc44
-rw-r--r--src/components/application_manager/test/app_service_manager_test.cc9
5 files changed, 79 insertions, 11 deletions
diff --git a/src/components/application_manager/include/application_manager/app_service_manager.h b/src/components/application_manager/include/application_manager/app_service_manager.h
index 9690d7cd46..5080748f17 100644
--- a/src/components/application_manager/include/application_manager/app_service_manager.h
+++ b/src/components/application_manager/include/application_manager/app_service_manager.h
@@ -81,7 +81,8 @@ class AppServiceManager {
* app. False, if published by the embedded system.
* @param connection_key - If mobile_service is true, the connection key of
* the app publishing this service.
- * @return The app service record of the published app service
+ * @return The app service record of the published app service on success, a
+ * Null SmartObject value on failure
*/
virtual smart_objects::SmartObject PublishAppService(
const smart_objects::SmartObject& manifest,
@@ -197,7 +198,7 @@ class AppServiceManager {
/**
* @brief Get the service with a given service ID.
- * @param service_type - The service ID
+ * @param service_id - The service ID
* @return A pointer to requested service on success, NULL on failure
*/
virtual AppService* FindServiceByID(const std::string service_id);
@@ -247,6 +248,16 @@ class AppServiceManager {
std::string DefaultServiceByType(const std::string service_type);
AppService* FindServiceByPolicyAppID(const std::string policy_app_id,
const std::string type);
+
+ /**
+ * @brief Get the service of a given type published by a given provider.
+ * @param connection_key - The connection key of the service provider
+ * @param service_type - The service type
+ * @return A pointer to requested service on success, NULL on failure
+ */
+ AppService* FindServiceByProvider(const uint32_t connection_key,
+ const std::string service_type);
+ AppService* FindServiceByName(std::string name);
std::string GetPolicyAppID(AppService service);
};
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_publish_app_service_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_publish_app_service_request.cc
index 637240666d..35a3e8a6b3 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_publish_app_service_request.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_publish_app_service_request.cc
@@ -63,13 +63,23 @@ void ASPublishAppServiceRequest::Run() {
smart_objects::SmartObject service_record =
application_manager_.GetAppServiceManager().PublishAppService(manifest,
false);
+ if (service_record.empty()) {
+ SendErrorResponse(
+ (*message_)[strings::params][strings::correlation_id].asUInt(),
+ hmi_apis::FunctionID::AppService_PublishAppService,
+ hmi_apis::Common_Result::REJECTED,
+ "Failed to publish service",
+ application_manager::commands::Command::SOURCE_SDL_TO_HMI);
+ return;
+ }
response_params[strings::app_service_record] = service_record;
SendResponse(true,
(*message_)[strings::params][strings::correlation_id].asUInt(),
hmi_apis::FunctionID::AppService_PublishAppService,
hmi_apis::Common_Result::SUCCESS,
- &response_params);
+ &response_params,
+ application_manager::commands::Command::SOURCE_SDL_TO_HMI);
}
} // namespace commands
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_request.cc
index bb0855d42f..86819b44ad 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_request.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_request.cc
@@ -99,8 +99,7 @@ void PublishAppServiceRequest::Run() {
if (!result) {
SendResponse(false,
mobile_apis::Result::DISALLOWED,
- "Service disallowed by policies",
- NULL);
+ "Service disallowed by policies");
return;
}
@@ -111,6 +110,13 @@ void PublishAppServiceRequest::Run() {
smart_objects::SmartObject service_record =
application_manager_.GetAppServiceManager().PublishAppService(
manifest, true, connection_key());
+
+ if (service_record.empty()) {
+ SendResponse(
+ false, mobile_apis::Result::REJECTED, "Failed to publish service");
+ return;
+ }
+
if (app->IsFullscreen()) {
// Service should be activated if app is in the foreground
application_manager_.GetAppServiceManager().ActivateAppService(
diff --git a/src/components/application_manager/src/app_service_manager.cc b/src/components/application_manager/src/app_service_manager.cc
index 1711180980..bab8147d9f 100644
--- a/src/components/application_manager/src/app_service_manager.cc
+++ b/src/components/application_manager/src/app_service_manager.cc
@@ -70,6 +70,20 @@ smart_objects::SmartObject AppServiceManager::PublishAppService(
std::string str_to_hash = "";
std::string service_id = "";
+ std::string service_type = manifest[strings::service_type].asString();
+
+ if (FindServiceByProvider(connection_key, service_type)) {
+ LOG4CXX_WARN(logger_,
+ "Service already exists for this provider, rejecting");
+ return smart_objects::SmartObject();
+ }
+
+ if (manifest.keyExists(strings::service_name) &&
+ FindServiceByName(manifest[strings::service_name].asString())) {
+ LOG4CXX_WARN(logger_, "A service already exists with this name, rejecting");
+ return smart_objects::SmartObject();
+ }
+
published_services_lock_.Acquire();
do {
str_to_hash = manifest[strings::service_type].asString() +
@@ -88,8 +102,6 @@ smart_objects::SmartObject AppServiceManager::PublishAppService(
service_record[strings::service_active] = false;
app_service.record = service_record;
- std::string service_type = manifest[strings::service_type].asString();
-
std::string default_app_id = DefaultServiceByType(service_type);
if (default_app_id.empty() && !mobile_service) {
auto embedded_services = app_manager_.get_settings().embedded_services();
@@ -378,7 +390,7 @@ bool AppServiceManager::DeactivateAppService(const std::string service_id) {
auto embedded_service = EmbeddedServiceForType(service_type);
if (embedded_service &&
embedded_service->record[strings::service_id].asString() !=
- service[strings::service_id].asString()) {
+ service_id) {
embedded_service->record[strings::service_active] = true;
AppServiceUpdated(embedded_service->record,
mobile_apis::ServiceUpdateReason::ACTIVATED,
@@ -456,6 +468,32 @@ AppService* AppServiceManager::FindServiceByID(const std::string service_id) {
return &(it->second);
}
+AppService* AppServiceManager::FindServiceByProvider(
+ const uint32_t connection_key, const std::string service_type) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock lock(published_services_lock_);
+ for (auto& service : published_services_) {
+ if (service.second.connection_key == connection_key &&
+ service.second.record[strings::service_manifest][strings::service_type]
+ .asString() == service_type) {
+ return &(service.second);
+ }
+ }
+ return NULL;
+}
+
+AppService* AppServiceManager::FindServiceByName(std::string name) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock lock(published_services_lock_);
+ for (auto& service : published_services_) {
+ if (service.second.record[strings::service_manifest][strings::service_name]
+ .asString() == name) {
+ return &(service.second);
+ }
+ }
+ return NULL;
+}
+
std::string AppServiceManager::DefaultServiceByType(
const std::string service_type) {
LOG4CXX_AUTO_TRACE(logger_);
diff --git a/src/components/application_manager/test/app_service_manager_test.cc b/src/components/application_manager/test/app_service_manager_test.cc
index 960e8e31f6..526bbbdb7d 100644
--- a/src/components/application_manager/test/app_service_manager_test.cc
+++ b/src/components/application_manager/test/app_service_manager_test.cc
@@ -120,8 +120,11 @@ class AppServiceManagerTest : public testing::Test {
}
smart_objects::SmartObject PublishService(
- uint32_t connection_key = kConnectionKey, bool first_run = true) {
- smart_objects::SmartObject manifest = GenerateMediaManifest(true);
+ uint32_t connection_key = kConnectionKey,
+ std::string service_name = kServiceName,
+ bool first_run = true) {
+ smart_objects::SmartObject manifest =
+ GenerateMediaManifest(true, service_name);
Json::Value empty_json;
EXPECT_CALL(mock_last_state_, get_dictionary())
@@ -326,7 +329,7 @@ TEST_F(AppServiceManagerTest, ActivateAppService_TwoApps_SUCCESS) {
// Register two services with the same service type, the first is activated
// automatically
auto record = PublishService();
- auto record2 = PublishService(kConnectionKey + 1, false);
+ auto record2 = PublishService(kConnectionKey + 1, kServiceName + "2", false);
// No capability update
smart_objects::SmartObject syscap_update_activated;