summaryrefslogtreecommitdiff
path: root/src/components/application_manager
diff options
context:
space:
mode:
authorJackLivio <jack@livio.io>2019-03-16 18:01:56 -0400
committerJackLivio <jack@livio.io>2019-03-16 18:01:56 -0400
commit1a0e1fd9daa392a2b68bf71e43ba89563c2f225b (patch)
tree67cb47d010c65429ba72c155ebb188a06b8d4f1e /src/components/application_manager
parentcf1fec553fdf9f86ad553e9d61e84d9b8dec6bbc (diff)
parente169090156eb89a060088df093b254599d4b4c68 (diff)
downloadsdl_core-1a0e1fd9daa392a2b68bf71e43ba89563c2f225b.tar.gz
Merge remote-tracking branch 'origin/feature/app_service_manager_tests' into tests/app_service_command_tests
Diffstat (limited to 'src/components/application_manager')
-rw-r--r--src/components/application_manager/include/application_manager/app_service_manager.h128
-rw-r--r--src/components/application_manager/include/application_manager/system_time/system_time_handler_impl.h2
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/commands/mobile/get_app_service_data_request.h3
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/commands/mobile/get_app_service_data_response_from_mobile.h1
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_to_hmi.cc1
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_response_from_hmi.cc2
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_response_to_hmi.cc1
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_publish_app_service_request.cc4
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request.cc32
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request_to_mobile.cc1
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_response.cc1
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_response_from_mobile.cc10
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request.cc9
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request_to_mobile.cc1
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_response.cc1
-rw-r--r--src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_response.cc1
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/basic_communication_get_system_time_response.h2
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_system_time_ready_notification.h2
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_file_request.cc1
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc2
-rw-r--r--src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_request_test.cc4
-rw-r--r--src/components/application_manager/src/app_launch/app_launch_data_db.cc2
-rw-r--r--src/components/application_manager/src/app_service_manager.cc28
-rw-r--r--src/components/application_manager/src/hmi_capabilities_impl.cc4
-rw-r--r--src/components/application_manager/src/resumption/resumption_data_json.cc2
-rw-r--r--src/components/application_manager/src/rpc_passing_handler.cc10
-rw-r--r--src/components/application_manager/src/system_time/system_time_handler_impl.cc2
-rwxr-xr-xsrc/components/application_manager/test/CMakeLists.txt1
-rw-r--r--src/components/application_manager/test/app_service_manager_test.cc440
-rw-r--r--src/components/application_manager/test/commands/command_impl_test.cc11
-rw-r--r--src/components/application_manager/test/include/application_manager/mock_app_service_manager.h7
-rw-r--r--src/components/application_manager/test/message_helper/message_helper_test.cc2
-rw-r--r--src/components/application_manager/test/policy_handler_test.cc104
33 files changed, 707 insertions, 115 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 47a60780bc..9690d7cd46 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
@@ -73,94 +73,149 @@ class AppServiceManager {
virtual ~AppServiceManager();
/**
- * @brief TODO
- * @param manifest
+ * @brief Publish an app service. This service will be activated if it is the
+ * default service for its type, or if it is the first service to register of
+ * its type.
+ * @param manifest - The app service manifest of the service to be published
+ * @param mobile_service - True, if the service is being published by a mobile
+ * 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
*/
virtual smart_objects::SmartObject PublishAppService(
const smart_objects::SmartObject& manifest,
const bool mobile_service,
- const uint32_t connection_key);
+ const uint32_t connection_key = 0u);
/**
- * @brief TODO
- * @param service_id
+ * @brief Unpublish an existing app service
+ * @param service_id - The ID of the app service to be deleted.
+ * @return True on success, false otherwise
*/
virtual bool UnpublishAppService(const std::string service_id);
+ /**
+ * @brief Callback for when an application is activated. Will activate all
+ * services which were published by this app.
+ * @param app - The application that was activated.
+ */
virtual void OnAppActivated(ApplicationConstSharedPtr app);
/**
- * @brief TODO
- * @param connection_key
+ * @brief Unpublish any published services for a given mobile application
+ * @param connection_key - The connection key of the application from which
+ * all published services should be deleted.
*/
virtual void UnpublishServices(const uint32_t connection_key);
/**
- * @brief TODO
- * @param service_id
+ * @brief Sets a service to the default service for its type
+ * @param service_id - The ID of the service to become the default
+ * @return True on success, false otherwise
*/
virtual bool SetDefaultService(const std::string service_id);
/**
- * @brief TODO
- * @param service_id
+ * @brief Removes a service from the list of default services.
+ * @param service_id - The ID of the existing default service.
+ * @return True on success, false otherwise
*/
virtual bool RemoveDefaultService(const std::string service_id);
/**
- * @brief TODO
- * @param service_id
+ * @brief Activate an existing service
+ * @param service_id - The ID of the service to be activated.
+ * @return True if the service is active, false otherwise
*/
virtual bool ActivateAppService(const std::string service_id);
/**
- * @brief TODO
- * @param service_id
+ * @brief Deactivate an existing active service
+ * @param service_id - The ID of the service to be deactivated.
+ * @return True if the service was deactivated, false otherwise
*/
virtual bool DeactivateAppService(const std::string service_id);
/**
- * @brief TODO
- * @param manifest
+ * @brief Get a list of all published service records.
+ * @return A list of all all published service records.
*/
virtual std::vector<smart_objects::SmartObject> GetAllServiceRecords();
- virtual std::vector<std::pair<std::string, AppService> > GetActiveServices();
+ /**
+ * @brief Get a list of all active app services.
+ * @return A list of all all active app services.
+ */
+ virtual std::vector<AppService> GetActiveServices();
+
+ /**
+ * @brief Retrieve the active service provider for a given service type
+ * @param service_type - The service type of the provider to be retrieved
+ * @param mobile_consumer - True, if the consumer trying to communicate with
+ * the provider is a mobile application
+ * @param app - Output parameter that will be filled with the application
+ * providing the requested service on success, unchanged on failure
+ * @param hmi_service - Output parameter set to true if the service
+ * provider is the HMI, unchanged on failure
+ */
virtual void GetProviderByType(const std::string& service_type,
const bool mobile_consumer,
ApplicationSharedPtr& app,
bool& hmi_service);
+ /**
+ * @brief Retrieve the service provider with a given service ID
+ * @param service_type - The service type of the provider to be retrieved
+ * @param mobile_consumer - True, if the consumer trying to communicate with
+ * the provider is a mobile application
+ * @param app - Output parameter that will be filled with the application
+ * providing the requested service on success, unchanged on failure
+ * @param hmi_service - Output parameter set to true if the service
+ * provider is the HMI, unchanged on failure
+ */
virtual void GetProviderByID(const std::string& service_id,
const bool mobile_consumer,
ApplicationSharedPtr& app,
bool& hmi_service);
+ /**
+ * @brief Get the active service for a given service type.
+ * @param service_type - The service type
+ * @return A pointer to the active service for the given service type on
+ * success, NULL on failure
+ */
virtual AppService* ActiveServiceForType(const std::string service_type);
+ /**
+ * @brief Get the embedded service for a given service type.
+ * @param service_type - The service type
+ * @return A pointer to the embedded service for the given service type on
+ * success, NULL on failure
+ */
virtual AppService* EmbeddedServiceForType(const std::string service_type);
- AppService* FindServiceByName(const std::string name);
-
- virtual AppService* FindServiceByID(const std::string service_id);
-
- virtual std::string DefaultServiceByType(const std::string service_type);
-
/**
- * @brief TODO
- * @param service_id
- * @param service_published
+ * @brief Get the service with a given service ID.
+ * @param service_type - The service ID
+ * @return A pointer to requested service on success, NULL on failure
*/
- virtual void SetServicePublished(const std::string service_id,
- bool service_published);
+ virtual AppService* FindServiceByID(const std::string service_id);
/**
- * @brief TODO
- * @param out_params
+ * @brief Update a navigation system capability struct with the capabilities
+ * of the active navigation service.
+ * @param out_params - The struct to be modified
+ * @return True on success, false otherwise (if there was no active NAVIGATION
+ * service)
*/
virtual bool UpdateNavigationCapabilities(
smart_objects::SmartObject& out_params);
+ /**
+ * @brief Get the RPCPassingHandler tied to this object
+ * @return The RPCPassingHandler tied to this object
+ */
virtual RPCPassingHandler& GetRPCPassingHandler();
private:
@@ -171,6 +226,8 @@ class AppServiceManager {
std::map<std::string, AppService> published_services_;
RPCPassingHandler rpc_passing_handler_;
+ void SetServicePublished(const std::string service_id,
+ bool service_published);
void AppServiceUpdated(
const smart_objects::SmartObject& service_record,
const mobile_apis::ServiceUpdateReason::eType update_reason,
@@ -179,6 +236,15 @@ class AppServiceManager {
const bool mobile_consumer,
ApplicationSharedPtr& app,
bool& hmi_service);
+
+ /**
+ * @brief Get the policy app ID of the default service provider for a given
+ * service type.
+ * @param service_type - The service type
+ * @return The policy app ID of the default service provider for the given
+ * service type on success, "" on failure
+ */
+ std::string DefaultServiceByType(const std::string service_type);
AppService* FindServiceByPolicyAppID(const std::string policy_app_id,
const std::string type);
std::string GetPolicyAppID(AppService service);
diff --git a/src/components/application_manager/include/application_manager/system_time/system_time_handler_impl.h b/src/components/application_manager/include/application_manager/system_time/system_time_handler_impl.h
index add440ad80..05565861f6 100644
--- a/src/components/application_manager/include/application_manager/system_time/system_time_handler_impl.h
+++ b/src/components/application_manager/include/application_manager/system_time/system_time_handler_impl.h
@@ -39,7 +39,7 @@
#include "utils/lock.h"
#include "utils/macro.h"
#include "utils/system_time_handler.h"
-#include "application_manager/application_manager_impl.h"
+#include "application_manager/application_manager.h"
#include "application_manager/event_engine/event_observer.h"
namespace application_manager {
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/commands/mobile/get_app_service_data_request.h b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/commands/mobile/get_app_service_data_request.h
index 8295e855fa..7c80ec5e03 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/commands/mobile/get_app_service_data_request.h
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/commands/mobile/get_app_service_data_request.h
@@ -77,7 +77,8 @@ class GetAppServiceDataRequest : public app_mngr::commands::CommandRequestImpl {
virtual void on_event(const app_mngr::event_engine::MobileEvent& event);
private:
- AppServiceRpcPlugin* plugin_;
+ void HandleSubscribe();
+
DISALLOW_COPY_AND_ASSIGN(GetAppServiceDataRequest);
};
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/commands/mobile/get_app_service_data_response_from_mobile.h b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/commands/mobile/get_app_service_data_response_from_mobile.h
index 1411b23e5a..7e2b26d8fb 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/commands/mobile/get_app_service_data_response_from_mobile.h
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/include/app_service_rpc_plugin/commands/mobile/get_app_service_data_response_from_mobile.h
@@ -70,7 +70,6 @@ class GetAppServiceDataResponseFromMobile
virtual void Run();
private:
- AppServiceRpcPlugin* plugin_;
DISALLOW_COPY_AND_ASSIGN(GetAppServiceDataResponseFromMobile);
};
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_to_hmi.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_to_hmi.cc
index 822cd0a29b..635cd7319a 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_to_hmi.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_request_to_hmi.cc
@@ -33,7 +33,6 @@
#include "app_service_rpc_plugin/commands/hmi/as_get_app_service_data_request_to_hmi.h"
#include "application_manager/application_impl.h"
#include "application_manager/rpc_service.h"
-#include "interfaces/MOBILE_API.h"
namespace app_service_rpc_plugin {
using namespace application_manager;
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_response_from_hmi.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_response_from_hmi.cc
index 9ce6ffdb50..c0b1b274fb 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_response_from_hmi.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_response_from_hmi.cc
@@ -33,7 +33,7 @@
#include "app_service_rpc_plugin/commands/hmi/as_get_app_service_data_response_from_hmi.h"
#include "application_manager/application_impl.h"
#include "application_manager/rpc_service.h"
-#include "interfaces/MOBILE_API.h"
+#include "interfaces/HMI_API.h"
#include "application_manager/message_helper.h"
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_response_to_hmi.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_response_to_hmi.cc
index 9e2289d39e..b489ec4765 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_response_to_hmi.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/hmi/as_get_app_service_data_response_to_hmi.cc
@@ -33,7 +33,6 @@
#include "app_service_rpc_plugin/commands/hmi/as_get_app_service_data_response_to_hmi.h"
#include "application_manager/application_impl.h"
#include "application_manager/rpc_service.h"
-#include "interfaces/MOBILE_API.h"
namespace app_service_rpc_plugin {
using namespace application_manager;
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 c9466ff52d..637240666d 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
@@ -61,8 +61,8 @@ void ASPublishAppServiceRequest::Run() {
smart_objects::SmartObject manifest =
(*message_)[strings::msg_params][strings::app_service_manifest];
smart_objects::SmartObject service_record =
- application_manager_.GetAppServiceManager().PublishAppService(
- manifest, false, UINT32_MAX);
+ application_manager_.GetAppServiceManager().PublishAppService(manifest,
+ false);
response_params[strings::app_service_record] = service_record;
SendResponse(true,
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request.cc
index 0d387785ee..7b29160692 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request.cc
@@ -52,28 +52,27 @@ GetAppServiceDataRequest::GetAppServiceDataRequest(
application_manager,
rpc_service,
hmi_capabilities,
- policy_handler)
- , plugin_(NULL) {
- auto plugin = (application_manager.GetPluginManager().FindPluginToProcess(
- mobile_apis::FunctionID::GetAppServiceDataID,
- app_mngr::commands::Command::CommandSource::SOURCE_MOBILE));
- if (plugin) {
- plugin_ = dynamic_cast<AppServiceRpcPlugin*>(&(*plugin));
- }
-}
+ policy_handler) {}
GetAppServiceDataRequest::~GetAppServiceDataRequest() {}
void GetAppServiceDataRequest::Run() {
LOG4CXX_AUTO_TRACE(logger_);
+ SendProviderRequest(mobile_apis::FunctionID::GetAppServiceDataID,
+ hmi_apis::FunctionID::AppService_GetAppServiceData,
+ &(*message_),
+ true);
+}
+
+void GetAppServiceDataRequest::HandleSubscribe() {
std::string service_type =
(*message_)[strings::msg_params][strings::service_type].asString();
-
- ApplicationSharedPtr app = application_manager_.application(connection_key());
if ((*message_)[strings::msg_params].keyExists(strings::subscribe)) {
bool subscribe =
(*message_)[strings::msg_params][strings::subscribe].asBool();
+ ApplicationSharedPtr app =
+ application_manager_.application(connection_key());
auto& ext = AppServiceAppExtension::ExtractASExtension(*app);
if (subscribe) {
ext.SubscribeToAppService(service_type);
@@ -81,11 +80,6 @@ void GetAppServiceDataRequest::Run() {
ext.UnsubscribeFromAppService(service_type);
}
}
-
- SendProviderRequest(mobile_apis::FunctionID::GetAppServiceDataID,
- hmi_apis::FunctionID::AppService_GetAppServiceData,
- &(*message_),
- true);
}
void GetAppServiceDataRequest::on_event(
@@ -97,6 +91,9 @@ void GetAppServiceDataRequest::on_event(
mobile_apis::Result::eType result = static_cast<mobile_apis::Result::eType>(
msg_params[strings::result_code].asInt());
bool success = IsMobileResultSuccess(result);
+ if (success) {
+ HandleSubscribe();
+ }
const char* info = msg_params.keyExists(strings::info)
? msg_params[strings::info].asCharArray()
@@ -118,6 +115,9 @@ void GetAppServiceDataRequest::on_event(const event_engine::Event& event) {
MessageHelper::HMIToMobileResult(hmi_result);
bool success = PrepareResultForMobileResponse(
hmi_result, HmiInterfaces::HMI_INTERFACE_AppService);
+ if (success) {
+ HandleSubscribe();
+ }
const char* info = msg_params.keyExists(strings::info)
? msg_params[strings::info].asCharArray()
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request_to_mobile.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request_to_mobile.cc
index 2bf81b3a2d..0af1a5436b 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request_to_mobile.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_request_to_mobile.cc
@@ -33,7 +33,6 @@
#include "app_service_rpc_plugin/commands/mobile/get_app_service_data_request_to_mobile.h"
#include "application_manager/application_impl.h"
#include "application_manager/rpc_service.h"
-#include "interfaces/MOBILE_API.h"
namespace app_service_rpc_plugin {
using namespace application_manager;
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_response.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_response.cc
index df7bbba2f7..32ad8e014d 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_response.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_response.cc
@@ -33,7 +33,6 @@
#include "app_service_rpc_plugin/commands/mobile/get_app_service_data_response.h"
#include "application_manager/application_impl.h"
#include "application_manager/rpc_service.h"
-#include "interfaces/MOBILE_API.h"
namespace app_service_rpc_plugin {
using namespace application_manager;
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_response_from_mobile.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_response_from_mobile.cc
index f8c1f3892d..90fca04eb2 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_response_from_mobile.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/get_app_service_data_response_from_mobile.cc
@@ -50,15 +50,7 @@ GetAppServiceDataResponseFromMobile::GetAppServiceDataResponseFromMobile(
application_manager,
rpc_service,
hmi_capabilities,
- policy_handler)
- , plugin_(NULL) {
- auto plugin = (application_manager.GetPluginManager().FindPluginToProcess(
- mobile_apis::FunctionID::PublishAppServiceID,
- app_mngr::commands::Command::CommandSource::SOURCE_MOBILE));
- if (plugin) {
- plugin_ = dynamic_cast<AppServiceRpcPlugin*>(&(*plugin));
- }
-}
+ policy_handler) {}
GetAppServiceDataResponseFromMobile::~GetAppServiceDataResponseFromMobile() {}
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request.cc
index 989b57ca12..4046ac7379 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request.cc
@@ -75,6 +75,15 @@ void PerformAppServiceInteractionRequest::Run() {
return;
}
+ if (!service->record[strings::service_manifest][strings::allow_app_consumers]
+ .asBool()) {
+ SendResponse(
+ false,
+ mobile_apis::Result::REJECTED,
+ "The requested service ID does not allow mobile app consumers");
+ return;
+ }
+
bool request_service_active = false;
if (msg_params.keyExists(strings::request_service_active)) {
request_service_active =
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request_to_mobile.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request_to_mobile.cc
index 8d71174c8d..2a7b644cb3 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request_to_mobile.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_request_to_mobile.cc
@@ -32,7 +32,6 @@
#include "app_service_rpc_plugin/commands/mobile/perform_app_service_interaction_request_to_mobile.h"
#include "application_manager/application_impl.h"
-#include "interfaces/MOBILE_API.h"
namespace app_service_rpc_plugin {
using namespace application_manager;
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_response.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_response.cc
index 774ec93720..5e84f42c34 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_response.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/perform_app_service_interaction_response.cc
@@ -32,7 +32,6 @@
#include "app_service_rpc_plugin/commands/mobile/perform_app_service_interaction_response.h"
#include "application_manager/application_impl.h"
-#include "interfaces/MOBILE_API.h"
namespace app_service_rpc_plugin {
using namespace application_manager;
diff --git a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_response.cc b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_response.cc
index b1136c79d0..d1bfc6e154 100644
--- a/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_response.cc
+++ b/src/components/application_manager/rpc_plugins/app_service_rpc_plugin/src/commands/mobile/publish_app_service_response.cc
@@ -34,7 +34,6 @@
#include "application_manager/application_impl.h"
#include "application_manager/message_helper.h"
#include "application_manager/rpc_service.h"
-#include "interfaces/MOBILE_API.h"
namespace app_service_rpc_plugin {
using namespace application_manager;
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/basic_communication_get_system_time_response.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/basic_communication_get_system_time_response.h
index 90160d9953..3a97ebdfb5 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/basic_communication_get_system_time_response.h
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/basic_communication_get_system_time_response.h
@@ -36,7 +36,7 @@
#include "application_manager/commands/response_from_hmi.h"
#include "utils/macro.h"
-#include "application_manager/application_manager_impl.h"
+#include "application_manager/application_manager.h"
namespace sdl_rpc_plugin {
namespace app_mngr = application_manager;
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_system_time_ready_notification.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_system_time_ready_notification.h
index 0beba8dc6b..7cd8410d8e 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_system_time_ready_notification.h
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_system_time_ready_notification.h
@@ -34,7 +34,7 @@
#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_SYSTEM_TIME_READY_NOTIFICATION_H_
#include "application_manager/commands/notification_from_hmi.h"
-#include "application_manager/application_manager_impl.h"
+#include "application_manager/application_manager.h"
namespace sdl_rpc_plugin {
namespace app_mngr = application_manager;
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_file_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_file_request.cc
index 2c92d74b47..a582670426 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_file_request.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_file_request.cc
@@ -37,7 +37,6 @@
#include "application_manager/rpc_service.h"
#include "interfaces/MOBILE_API.h"
#include "application_manager/message_helper.h"
-#include "application_manager/app_service_manager.h"
#include "utils/file_system.h"
#include <boost/crc.hpp>
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc
index 3cfe4d7118..fb809e8834 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/hmi_command_factory.cc
@@ -248,6 +248,8 @@
namespace sdl_rpc_plugin {
using namespace application_manager;
+CREATE_LOGGERPTR_GLOBAL(logger_, "HMICommandFactory")
+
HMICommandFactory::HMICommandFactory(
ApplicationManager& application_manager,
rpc_service::RPCService& rpc_service,
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_request_test.cc
index a90c0c70fc..917de81fb3 100644
--- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_request_test.cc
+++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_request_test.cc
@@ -140,6 +140,8 @@ TEST_F(SDLActivateAppRequestTest, Run_ActivateApp_SUCCESS) {
std::shared_ptr<SDLActivateAppRequest> command(
CreateCommand<SDLActivateAppRequest>(msg));
+ EXPECT_CALL(app_mngr_, WaitingApplicationByID(kAppID))
+ .WillOnce(Return(ApplicationSharedPtr()));
EXPECT_CALL(app_mngr_, state_controller())
.WillOnce(ReturnRef(mock_state_controller_));
EXPECT_CALL(mock_state_controller_,
@@ -446,8 +448,10 @@ TEST_F(SDLActivateAppRequestTest, WaitingCloudApplication_ConnectDevice) {
EXPECT_CALL(*mock_app, IsRegistered()).WillOnce(Return(false));
EXPECT_CALL(*mock_app, is_cloud_app()).WillOnce(Return(true));
+#ifndef EXTERNAL_PROPRIETARY_MODE
EXPECT_CALL(app_mngr_, application(kAppID))
.WillOnce(Return(ApplicationSharedPtr()));
+#endif
EXPECT_CALL(app_mngr_, WaitingApplicationByID(kAppID))
.WillOnce(Return(mock_app));
diff --git a/src/components/application_manager/src/app_launch/app_launch_data_db.cc b/src/components/application_manager/src/app_launch/app_launch_data_db.cc
index 393b01c952..22d2790183 100644
--- a/src/components/application_manager/src/app_launch/app_launch_data_db.cc
+++ b/src/components/application_manager/src/app_launch/app_launch_data_db.cc
@@ -33,7 +33,7 @@
#include <unistd.h>
#include "application_manager/app_launch/app_launch_data_db.h"
-#include "application_manager/application_manager_impl.h"
+#include "application_manager/application_manager.h"
#include "application_manager/app_launch/app_launch_sql_queries.h"
#include "application_manager/smart_object_keys.h"
#include "application_manager/message_helper.h"
diff --git a/src/components/application_manager/src/app_service_manager.cc b/src/components/application_manager/src/app_service_manager.cc
index c16311a087..1711180980 100644
--- a/src/components/application_manager/src/app_service_manager.cc
+++ b/src/components/application_manager/src/app_service_manager.cc
@@ -39,7 +39,6 @@
#include "application_manager/application_manager.h"
#include "application_manager/commands/command_impl.h"
#include "application_manager/message_helper.h"
-#include "application_manager/rpc_passing_handler.h"
#include "application_manager/smart_object_keys.h"
#include "encryption/hashing.h"
#include "resumption/last_state.h"
@@ -104,7 +103,8 @@ smart_objects::SmartObject AppServiceManager::PublishAppService(
}
}
}
- app_service.default_service = GetPolicyAppID(app_service) == default_app_id;
+ app_service.default_service =
+ !default_app_id.empty() && GetPolicyAppID(app_service) == default_app_id;
auto ret = published_services_.insert(
std::pair<std::string, AppService>(service_id, app_service));
@@ -376,7 +376,9 @@ bool AppServiceManager::DeactivateAppService(const std::string service_id) {
const std::string service_type =
service[strings::service_manifest][strings::service_type].asString();
auto embedded_service = EmbeddedServiceForType(service_type);
- if (embedded_service) {
+ if (embedded_service &&
+ embedded_service->record[strings::service_id].asString() !=
+ service[strings::service_id].asString()) {
embedded_service->record[strings::service_active] = true;
AppServiceUpdated(embedded_service->record,
mobile_apis::ServiceUpdateReason::ACTIVATED,
@@ -424,19 +426,6 @@ AppService* AppServiceManager::EmbeddedServiceForType(
return NULL;
}
-AppService* AppServiceManager::FindServiceByName(const std::string name) {
- LOG4CXX_AUTO_TRACE(logger_);
- sync_primitives::AutoLock lock(published_services_lock_);
- for (auto it = published_services_.begin(); it != published_services_.end();
- ++it) {
- if (it->second.record[strings::service_manifest][strings::service_name]
- .asString() == name) {
- return &(it->second);
- }
- }
- return NULL;
-}
-
AppService* AppServiceManager::FindServiceByPolicyAppID(
const std::string policy_app_id, const std::string type) {
LOG4CXX_AUTO_TRACE(logger_);
@@ -548,13 +537,12 @@ void AppServiceManager::AppServiceUpdated(
services[-1] = service;
}
-std::vector<std::pair<std::string, AppService> >
-AppServiceManager::GetActiveServices() {
- std::vector<std::pair<std::string, AppService> > active_services;
+std::vector<AppService> AppServiceManager::GetActiveServices() {
+ std::vector<AppService> active_services;
for (auto it = published_services_.begin(); it != published_services_.end();
++it) {
if (it->second.record[strings::service_active].asBool()) {
- active_services.push_back(*it);
+ active_services.push_back(it->second);
}
}
return active_services;
diff --git a/src/components/application_manager/src/hmi_capabilities_impl.cc b/src/components/application_manager/src/hmi_capabilities_impl.cc
index 6cd6747e99..060eaf011c 100644
--- a/src/components/application_manager/src/hmi_capabilities_impl.cc
+++ b/src/components/application_manager/src/hmi_capabilities_impl.cc
@@ -34,7 +34,7 @@
#include "utils/logger.h"
#include "application_manager/hmi_capabilities_impl.h"
-#include "application_manager/application_manager_impl.h"
+#include "application_manager/application_manager.h"
#include "smart_objects/smart_object.h"
#include "application_manager/message_helper.h"
#include "application_manager/smart_object_keys.h"
@@ -46,6 +46,8 @@
namespace application_manager {
namespace formatters = ns_smart_device_link::ns_json_handler::formatters;
+CREATE_LOGGERPTR_GLOBAL(logger_, "HMICapabilities")
+
namespace {
std::map<std::string, hmi_apis::Common_VrCapabilities::eType>
vr_enum_capabilities;
diff --git a/src/components/application_manager/src/resumption/resumption_data_json.cc b/src/components/application_manager/src/resumption/resumption_data_json.cc
index c8e9032dfa..584fb4e697 100644
--- a/src/components/application_manager/src/resumption/resumption_data_json.cc
+++ b/src/components/application_manager/src/resumption/resumption_data_json.cc
@@ -30,7 +30,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include "application_manager/application_manager_impl.h"
+#include "application_manager/application_manager.h"
#include "application_manager/resumption/resumption_data_json.h"
#include "smart_objects/smart_object.h"
#include "json/json.h"
diff --git a/src/components/application_manager/src/rpc_passing_handler.cc b/src/components/application_manager/src/rpc_passing_handler.cc
index 7ff01756f7..37b01a92f6 100644
--- a/src/components/application_manager/src/rpc_passing_handler.cc
+++ b/src/components/application_manager/src/rpc_passing_handler.cc
@@ -83,7 +83,7 @@ bool RPCPassingHandler::CanHandleFunctionID(int32_t function_id) {
auto services = app_service_manager_.GetActiveServices();
for (auto it = services.begin(); it != services.end(); ++it) {
auto handled_rpcs =
- it->second.record[strings::service_manifest][strings::handled_rpcs];
+ it->record[strings::service_manifest][strings::handled_rpcs];
for (size_t i = 0; i < handled_rpcs.length(); i++) {
if (handled_rpcs[i].asInt() == function_id) {
return true;
@@ -187,13 +187,13 @@ void RPCPassingHandler::PopulateRPCRequestQueue(
for (auto services_it = services.begin(); services_it != services.end();
++services_it) {
auto handled_rpcs =
- services_it->second
- .record[strings::service_manifest][strings::handled_rpcs];
+ services_it->record[strings::service_manifest][strings::handled_rpcs];
for (size_t i = 0; i < handled_rpcs.length(); i++) {
if (handled_rpcs[i].asInt() == function_id) {
// Add requests to queue
- ServiceInfo service_info{services_it->first,
- services_it->second.connection_key};
+ ServiceInfo service_info{
+ services_it->record[strings::service_id].asString(),
+ services_it->connection_key};
entry.second.push_back(service_info);
app_manager_.IncreaseForwardedRequestTimeout(origin_connection_key,
correlation_id);
diff --git a/src/components/application_manager/src/system_time/system_time_handler_impl.cc b/src/components/application_manager/src/system_time/system_time_handler_impl.cc
index 06343af5a3..f5d08a8ebf 100644
--- a/src/components/application_manager/src/system_time/system_time_handler_impl.cc
+++ b/src/components/application_manager/src/system_time/system_time_handler_impl.cc
@@ -41,6 +41,8 @@
namespace application_manager {
+CREATE_LOGGERPTR_GLOBAL(logger_, "SystemTimeHandler")
+
SystemTimeHandlerImpl::SystemTimeHandlerImpl(
ApplicationManager& application_manager)
: event_engine::EventObserver(application_manager.event_dispatcher())
diff --git a/src/components/application_manager/test/CMakeLists.txt b/src/components/application_manager/test/CMakeLists.txt
index 02cf58485a..4851a6b37e 100755
--- a/src/components/application_manager/test/CMakeLists.txt
+++ b/src/components/application_manager/test/CMakeLists.txt
@@ -63,6 +63,7 @@ set(testSources
${AM_TEST_DIR}/application_state_test.cc
${AM_TEST_DIR}/usage_statistics_test.cc
${AM_TEST_DIR}/policy_handler_test.cc
+ ${AM_TEST_DIR}/app_service_manager_test.cc
${AM_TEST_DIR}/application_manager_impl_test.cc
${AM_TEST_DIR}/application_helper_test.cc
${AM_TEST_DIR}/command_holder_test.cc
diff --git a/src/components/application_manager/test/app_service_manager_test.cc b/src/components/application_manager/test/app_service_manager_test.cc
new file mode 100644
index 0000000000..406f6fe0ce
--- /dev/null
+++ b/src/components/application_manager/test/app_service_manager_test.cc
@@ -0,0 +1,440 @@
+/*
+ * Copyright (c) 2017, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <gmock/gmock.h>
+
+#include "application_manager/commands/command.h"
+#include "application_manager/mock_application.h"
+#include "application_manager/mock_application_manager.h"
+#include "application_manager/mock_application_manager_settings.h"
+#include "application_manager/mock_message_helper.h"
+#include "application_manager/smart_object_keys.h"
+#include "resumption/mock_last_state.h"
+#include "smart_objects/smart_object.h"
+
+namespace test {
+namespace components {
+namespace application_manager_test {
+
+using testing::_;
+using ::testing::DoAll;
+using ::testing::Mock;
+using ::testing::Return;
+using ::testing::ReturnRef;
+using ::testing::SaveArg;
+
+namespace am = application_manager;
+
+const char* kAppServiceSection = "AppServices";
+const char* kDefaults = "defaults";
+const std::string kServiceType = "MEDIA";
+const std::string kServiceName = "service_name";
+const std::string kServiceId = "service_id";
+const std::string kPolicyAppId = "p_app_id";
+const uint32_t kConnectionKey = 43629;
+const uint32_t kHMIConnectionKey = 0;
+
+MATCHER_P(CapabilityUpdateMatcher, reason, "") {
+ smart_objects::SmartObject& services_updated =
+ arg[am::strings::system_capability]
+ [am::strings::app_services_capabilities][am::strings::app_services];
+ if (smart_objects::SmartType_Array != services_updated.getType()) {
+ return false;
+ }
+ for (size_t i = 0; i < services_updated.length(); i++) {
+ smart_objects::SmartObject& service_cap = services_updated[i];
+ if (reason == service_cap[am::strings::update_reason].asInt()) {
+ return true;
+ }
+ }
+ return false;
+}
+
+class AppServiceManagerTest : public testing::Test {
+ public:
+ AppServiceManagerTest()
+ : mock_app_ptr_(new MockApplication)
+ , app_service_manager_(mock_app_manager_, mock_last_state_)
+ , mock_message_helper_(
+ application_manager::MockMessageHelper::message_helper_mock()) {
+ Mock::VerifyAndClearExpectations(mock_message_helper_);
+ }
+ ~AppServiceManagerTest() {
+ Mock::VerifyAndClearExpectations(mock_message_helper_);
+ }
+
+ void SetUp() OVERRIDE {
+ ON_CALL(*mock_message_helper_, BroadcastCapabilityUpdate(_, _))
+ .WillByDefault(Return());
+ ON_CALL(mock_settings_, embedded_services())
+ .WillByDefault(ReturnRef(embedded_services_));
+ ON_CALL(mock_app_manager_, get_settings())
+ .WillByDefault(ReturnRef(mock_settings_));
+ ON_CALL(*mock_app_ptr_, policy_app_id())
+ .WillByDefault(Return(kPolicyAppId));
+ ON_CALL(mock_last_state_, get_dictionary()).WillByDefault(ReturnRef(dict_));
+ auto app_ptr = std::static_pointer_cast<am::Application>(mock_app_ptr_);
+ ON_CALL(mock_app_manager_, application(kConnectionKey))
+ .WillByDefault(Return(app_ptr));
+ }
+
+ protected:
+ smart_objects::SmartObject GenerateMediaManifest(
+ bool allow_app_consumers, std::string app_service_name = kServiceName) {
+ smart_objects::SmartObject manifest(smart_objects::SmartType_Map);
+ manifest[am::strings::service_type] = "MEDIA";
+ manifest[am::strings::service_name] = app_service_name;
+ manifest[am::strings::allow_app_consumers] = allow_app_consumers;
+ manifest[am::strings::media_service_manifest] =
+ smart_objects::SmartObject(smart_objects::SmartType_Map);
+ return manifest;
+ }
+
+ smart_objects::SmartObject PublishService(
+ uint32_t connection_key = kConnectionKey, bool first_run = true) {
+ smart_objects::SmartObject manifest = GenerateMediaManifest(true);
+
+ Json::Value empty_json;
+ EXPECT_CALL(mock_last_state_, get_dictionary())
+ .WillOnce(ReturnRef(empty_json));
+
+ EXPECT_CALL(*mock_message_helper_,
+ BroadcastCapabilityUpdate(
+ CapabilityUpdateMatcher(
+ mobile_apis::ServiceUpdateReason::PUBLISHED),
+ _)).WillOnce(Return());
+ if (first_run) {
+ EXPECT_CALL(*mock_message_helper_,
+ BroadcastCapabilityUpdate(
+ CapabilityUpdateMatcher(
+ mobile_apis::ServiceUpdateReason::ACTIVATED),
+ _)).WillOnce(Return());
+ }
+ bool mobile_service = connection_key != kHMIConnectionKey;
+ return app_service_manager_.PublishAppService(
+ manifest, mobile_service, connection_key);
+ }
+
+ void CheckCapabilityUpdate(smart_objects::SmartObject& msg_params,
+ size_t length,
+ std::string service_id,
+ mobile_apis::ServiceUpdateReason::eType reason,
+ bool published,
+ bool active) {
+ smart_objects::SmartObject& services_updated = msg_params
+ [am::strings::system_capability][am::strings::app_services_capabilities]
+ [am::strings::app_services];
+ ASSERT_EQ(smart_objects::SmartType_Array, services_updated.getType());
+ EXPECT_EQ(length, services_updated.length());
+ for (size_t i = 0; i < services_updated.length(); i++) {
+ smart_objects::SmartObject& service_cap = services_updated[i];
+ if (service_id ==
+ service_cap[am::strings::updated_app_service_record]
+ [am::strings::service_id].asString()) {
+ CheckCapability(service_cap, service_id, reason, published, active);
+ return;
+ }
+ }
+ FAIL() << "Unable to find service in capability update with service_id: "
+ << service_id;
+ }
+
+ void CheckCapability(smart_objects::SmartObject& app_service_capability,
+ std::string service_id,
+ mobile_apis::ServiceUpdateReason::eType reason,
+ bool published,
+ bool active) {
+ EXPECT_EQ(reason,
+ app_service_capability[am::strings::update_reason].asInt());
+ smart_objects::SmartObject& updated_record =
+ app_service_capability[am::strings::updated_app_service_record];
+ EXPECT_EQ(service_id, updated_record[am::strings::service_id].asString());
+ EXPECT_EQ(published,
+ updated_record[am::strings::service_published].asBool());
+ EXPECT_EQ(active, updated_record[am::strings::service_active].asBool());
+ }
+
+ Json::Value dict_;
+ std::vector<std::string> embedded_services_;
+ std::shared_ptr<MockApplication> mock_app_ptr_;
+ MockApplicationManager mock_app_manager_;
+ resumption_test::MockLastState mock_last_state_;
+ MockApplicationManagerSettings mock_settings_;
+ application_manager::AppServiceManager app_service_manager_;
+ application_manager::MockMessageHelper* mock_message_helper_;
+};
+
+TEST_F(AppServiceManagerTest, PublishAppService_Mobile_SUCCESS) {
+ smart_objects::SmartObject manifest = GenerateMediaManifest(true);
+
+ Json::Value empty_json;
+ // dict[kAppServiceSection][kDefaults][kServiceType] = kPolicyAppId;
+ EXPECT_CALL(mock_last_state_, get_dictionary())
+ .WillOnce(ReturnRef(empty_json));
+
+ smart_objects::SmartObject syscap_update_published;
+ EXPECT_CALL(
+ *mock_message_helper_,
+ BroadcastCapabilityUpdate(
+ CapabilityUpdateMatcher(mobile_apis::ServiceUpdateReason::PUBLISHED),
+ _)).WillOnce(DoAll(SaveArg<0>(&syscap_update_published), Return()));
+
+ smart_objects::SmartObject syscap_update_activated;
+ EXPECT_CALL(
+ *mock_message_helper_,
+ BroadcastCapabilityUpdate(
+ CapabilityUpdateMatcher(mobile_apis::ServiceUpdateReason::ACTIVATED),
+ _)).WillOnce(DoAll(SaveArg<0>(&syscap_update_activated), Return()));
+
+ auto record =
+ app_service_manager_.PublishAppService(manifest, true, kConnectionKey);
+
+ // Check final record
+ std::string service_id = record[am::strings::service_id].asString();
+ EXPECT_EQ(manifest, record[am::strings::service_manifest]);
+ EXPECT_EQ(true, record[am::strings::service_published].asBool());
+ EXPECT_EQ(true, record[am::strings::service_active].asBool());
+
+ // Check first capability update
+ CheckCapabilityUpdate(syscap_update_published,
+ 1,
+ service_id,
+ mobile_apis::ServiceUpdateReason::PUBLISHED,
+ true,
+ false);
+
+ // Check second capability update
+ CheckCapabilityUpdate(syscap_update_activated,
+ 1,
+ service_id,
+ mobile_apis::ServiceUpdateReason::ACTIVATED,
+ true,
+ true);
+}
+
+TEST_F(AppServiceManagerTest, PublishAppService_HMI_SUCCESS) {
+ smart_objects::SmartObject manifest = GenerateMediaManifest(true);
+
+ Json::Value empty_json;
+ EXPECT_CALL(mock_last_state_, get_dictionary())
+ .WillOnce(ReturnRef(empty_json));
+
+ smart_objects::SmartObject syscap_update_published;
+ EXPECT_CALL(
+ *mock_message_helper_,
+ BroadcastCapabilityUpdate(
+ CapabilityUpdateMatcher(mobile_apis::ServiceUpdateReason::PUBLISHED),
+ _)).WillOnce(DoAll(SaveArg<0>(&syscap_update_published), Return()));
+
+ smart_objects::SmartObject syscap_update_activated;
+ EXPECT_CALL(
+ *mock_message_helper_,
+ BroadcastCapabilityUpdate(
+ CapabilityUpdateMatcher(mobile_apis::ServiceUpdateReason::ACTIVATED),
+ _)).WillOnce(DoAll(SaveArg<0>(&syscap_update_activated), Return()));
+
+ auto record = app_service_manager_.PublishAppService(manifest, false);
+
+ // Check final record
+ std::string service_id = record[am::strings::service_id].asString();
+ EXPECT_EQ(manifest, record[am::strings::service_manifest]);
+ EXPECT_EQ(true, record[am::strings::service_published].asBool());
+ EXPECT_EQ(true, record[am::strings::service_active].asBool());
+
+ // Check first capability update
+ CheckCapabilityUpdate(syscap_update_published,
+ 1,
+ service_id,
+ mobile_apis::ServiceUpdateReason::PUBLISHED,
+ true,
+ false);
+
+ // Check second capability update
+ CheckCapabilityUpdate(syscap_update_activated,
+ 1,
+ service_id,
+ mobile_apis::ServiceUpdateReason::ACTIVATED,
+ true,
+ true);
+}
+
+TEST_F(AppServiceManagerTest, UnpublishAppService_SUCCESS) {
+ auto record = PublishService();
+
+ smart_objects::SmartObject syscap_update_unpublished;
+ EXPECT_CALL(
+ *mock_message_helper_,
+ BroadcastCapabilityUpdate(
+ CapabilityUpdateMatcher(mobile_apis::ServiceUpdateReason::REMOVED),
+ _)).WillOnce(DoAll(SaveArg<0>(&syscap_update_unpublished), Return()));
+ std::string service_id = record[am::strings::service_id].asString();
+
+ EXPECT_TRUE(app_service_manager_.UnpublishAppService(service_id));
+
+ // Check removed capability update
+ CheckCapabilityUpdate(syscap_update_unpublished,
+ 1,
+ service_id,
+ mobile_apis::ServiceUpdateReason::REMOVED,
+ false,
+ false);
+}
+
+TEST_F(AppServiceManagerTest, ActivateAppService_AlreadyActivated) {
+ auto record = PublishService();
+
+ // No capability update
+ EXPECT_CALL(
+ *mock_message_helper_,
+ BroadcastCapabilityUpdate(
+ CapabilityUpdateMatcher(mobile_apis::ServiceUpdateReason::ACTIVATED),
+ _)).Times(0);
+ std::string service_id = record[am::strings::service_id].asString();
+
+ EXPECT_TRUE(app_service_manager_.ActivateAppService(service_id));
+}
+
+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);
+
+ // No capability update
+ smart_objects::SmartObject syscap_update_activated;
+ EXPECT_CALL(
+ *mock_message_helper_,
+ BroadcastCapabilityUpdate(
+ CapabilityUpdateMatcher(mobile_apis::ServiceUpdateReason::ACTIVATED),
+ _)).WillOnce(DoAll(SaveArg<0>(&syscap_update_activated), Return()));
+ std::string service_id = record[am::strings::service_id].asString();
+ std::string service_id2 = record2[am::strings::service_id].asString();
+
+ // Activate the second service
+ EXPECT_TRUE(app_service_manager_.ActivateAppService(service_id2));
+
+ // Check that the first service is deactivated
+ CheckCapabilityUpdate(syscap_update_activated,
+ 2,
+ service_id,
+ mobile_apis::ServiceUpdateReason::DEACTIVATED,
+ true,
+ false);
+
+ // Check that the second service is activated
+ CheckCapabilityUpdate(syscap_update_activated,
+ 2,
+ service_id2,
+ mobile_apis::ServiceUpdateReason::ACTIVATED,
+ true,
+ true);
+}
+
+TEST_F(AppServiceManagerTest, DeactivateAppService_SUCCESS) {
+ auto record = PublishService();
+
+ smart_objects::SmartObject syscap_update_deactivated;
+ EXPECT_CALL(*mock_message_helper_,
+ BroadcastCapabilityUpdate(
+ CapabilityUpdateMatcher(
+ mobile_apis::ServiceUpdateReason::DEACTIVATED),
+ _))
+ .WillOnce(DoAll(SaveArg<0>(&syscap_update_deactivated), Return()));
+ std::string service_id = record[am::strings::service_id].asString();
+
+ EXPECT_TRUE(app_service_manager_.DeactivateAppService(service_id));
+
+ // Check deactivated capability update
+ CheckCapabilityUpdate(syscap_update_deactivated,
+ 1,
+ service_id,
+ mobile_apis::ServiceUpdateReason::DEACTIVATED,
+ true,
+ false);
+}
+
+TEST_F(AppServiceManagerTest, ActiveServiceForType_SUCCESS) {
+ auto record = PublishService();
+
+ auto service = app_service_manager_.ActiveServiceForType(kServiceType);
+
+ ASSERT_FALSE(service == NULL);
+ EXPECT_EQ(record, service->record);
+ EXPECT_EQ(kConnectionKey, service->connection_key);
+ EXPECT_EQ(true, service->mobile_service);
+}
+
+TEST_F(AppServiceManagerTest, EmbeddedServiceForType_SUCCESS) {
+ auto record = PublishService(kHMIConnectionKey);
+
+ auto service = app_service_manager_.EmbeddedServiceForType(kServiceType);
+
+ ASSERT_FALSE(service == NULL);
+ EXPECT_EQ(record, service->record);
+ EXPECT_EQ(false, service->mobile_service);
+}
+
+TEST_F(AppServiceManagerTest, FindServiceByID_SUCCESS) {
+ auto record = PublishService();
+
+ std::string service_id = record[am::strings::service_id].asString();
+ auto service = app_service_manager_.FindServiceByID(service_id);
+
+ ASSERT_FALSE(service == NULL);
+ EXPECT_EQ(record, service->record);
+ EXPECT_EQ(kConnectionKey, service->connection_key);
+ EXPECT_EQ(true, service->mobile_service);
+}
+
+TEST_F(AppServiceManagerTest, GetAllServiceRecords_OneService_SUCCESS) {
+ auto record = PublishService();
+
+ auto records = app_service_manager_.GetAllServiceRecords();
+
+ ASSERT_EQ(1u, records.size());
+ EXPECT_EQ(record, records[0]);
+}
+
+TEST_F(AppServiceManagerTest, GetActiveServices_OneService_SUCCESS) {
+ auto record = PublishService();
+
+ auto services = app_service_manager_.GetActiveServices();
+
+ ASSERT_EQ(1u, services.size());
+ EXPECT_EQ(record, services[0].record);
+ EXPECT_EQ(kConnectionKey, services[0].connection_key);
+ EXPECT_EQ(true, services[0].mobile_service);
+}
+
+} // namespace application_manager_test
+} // namespace components
+} // namespace test \ No newline at end of file
diff --git a/src/components/application_manager/test/commands/command_impl_test.cc b/src/components/application_manager/test/commands/command_impl_test.cc
index 222f16ef46..53e8534c2b 100644
--- a/src/components/application_manager/test/commands/command_impl_test.cc
+++ b/src/components/application_manager/test/commands/command_impl_test.cc
@@ -85,11 +85,12 @@ class CommandImplTest : public CommandsTest<CommandsTestMocks::kIsNice> {
using CommandImpl::ReplaceMobileWithHMIAppId;
using CommandImpl::ReplaceHMIWithMobileAppId;
- UnwrappedCommandImpl(const MessageSharedPtr& message,
- ApplicationManager& application_manager,
- app_mngr::rpc_service::RPCService& rpc_service,
- app_mngr::HMICapabilities& hmi_capabilities,
- policy::PolicyHandlerInterface& policy_handler)
+ UnwrappedCommandImpl(
+ const MessageSharedPtr& message,
+ ApplicationManager& application_manager,
+ application_manager::rpc_service::RPCService& rpc_service,
+ application_manager::HMICapabilities& hmi_capabilities,
+ policy::PolicyHandlerInterface& policy_handler)
: CommandImpl(message,
application_manager,
rpc_service,
diff --git a/src/components/application_manager/test/include/application_manager/mock_app_service_manager.h b/src/components/application_manager/test/include/application_manager/mock_app_service_manager.h
index cad71f98ab..f77b5685da 100644
--- a/src/components/application_manager/test/include/application_manager/mock_app_service_manager.h
+++ b/src/components/application_manager/test/include/application_manager/mock_app_service_manager.h
@@ -61,9 +61,8 @@ class MockAppServiceManager : public application_manager::AppServiceManager {
MOCK_METHOD1(ActivateAppService, bool(const std::string service_id));
MOCK_METHOD1(DeactivateAppService, bool(const std::string service_id));
MOCK_METHOD0(GetAllServiceRecords, std::vector<smart_objects::SmartObject>());
- MOCK_METHOD0(
- GetActiveServices,
- std::vector<std::pair<std::string, application_manager::AppService> >());
+ MOCK_METHOD0(GetActiveServices,
+ std::vector<application_manager::AppService>());
MOCK_METHOD4(GetProviderByType,
void(const std::string& service_type,
const bool mobile_consumer,
@@ -82,8 +81,6 @@ class MockAppServiceManager : public application_manager::AppServiceManager {
application_manager::AppService*(const std::string service_type));
MOCK_METHOD1(FindServiceByID,
application_manager::AppService*(const std::string service_id));
- MOCK_METHOD1(DefaultServiceByType,
- std::string(const std::string service_type));
MOCK_METHOD2(SetServicePublished,
void(const std::string service_id,
const bool service_published));
diff --git a/src/components/application_manager/test/message_helper/message_helper_test.cc b/src/components/application_manager/test/message_helper/message_helper_test.cc
index f43062dc53..92be221ec9 100644
--- a/src/components/application_manager/test/message_helper/message_helper_test.cc
+++ b/src/components/application_manager/test/message_helper/message_helper_test.cc
@@ -42,7 +42,7 @@
#include "utils/custom_string.h"
#include "utils/lock.h"
#include "policy/mock_policy_settings.h"
-#include "application_manager/policies/policy_handler.h"
+#include "application_manager/commands/command_impl.h"
#include "application_manager/mock_application_manager.h"
#include "application_manager/mock_rpc_service.h"
#include "application_manager/event_engine/event_dispatcher.h"
diff --git a/src/components/application_manager/test/policy_handler_test.cc b/src/components/application_manager/test/policy_handler_test.cc
index a1471eff36..25024ff50d 100644
--- a/src/components/application_manager/test/policy_handler_test.cc
+++ b/src/components/application_manager/test/policy_handler_test.cc
@@ -81,15 +81,13 @@ using namespace application_manager;
using namespace policy;
using namespace utils::custom_string;
using testing::_;
+using ::testing::DoAll;
using ::testing::Mock;
+using ::testing::NiceMock;
using ::testing::Return;
using ::testing::ReturnRef;
-using ::testing::NiceMock;
-using ::testing::SetArgReferee;
using ::testing::SetArgPointee;
-using ::testing::DoAll;
using ::testing::SetArgReferee;
-using ::testing::Mock;
typedef NiceMock<application_manager_test::MockRPCService> MockRPCService;
@@ -2536,6 +2534,104 @@ TEST_F(PolicyHandlerTest, RemoteAppsUrl_SUCCESS) {
EXPECT_EQ(url, policy_handler_.RemoteAppsUrl());
}
+TEST_F(PolicyHandlerTest, OnSetCloudAppProperties_AllProperties_SUCCESS) {
+ EnablePolicyAndPolicyManagerMock();
+
+ bool enabled = true;
+ std::string app_name = "anAppName";
+ std::string auth_token = "anAuthToken";
+ std::string cloud_transport_type = "aTransportType";
+ mobile_apis::HybridAppPreference::eType hybrid_app_preference =
+ mobile_apis::HybridAppPreference::CLOUD;
+ std::string hybrid_app_preference_str = "CLOUD";
+ std::string endpoint = "anEndpoint";
+
+ StringArray nicknames_vec;
+ nicknames_vec.push_back(app_name);
+
+ smart_objects::SmartObject message(smart_objects::SmartType_Map);
+ smart_objects::SmartObject properties(smart_objects::SmartType_Map);
+ smart_objects::SmartObject nicknames(smart_objects::SmartType_Array);
+
+ properties[strings::app_id] = kPolicyAppId_;
+ nicknames[0] = app_name;
+ properties[strings::nicknames] = nicknames;
+ properties[strings::enabled] = enabled;
+ properties[strings::auth_token] = auth_token;
+ properties[strings::cloud_transport_type] = cloud_transport_type;
+ properties[strings::hybrid_app_preference] = hybrid_app_preference;
+ properties[strings::endpoint] = endpoint;
+ message[strings::msg_params][strings::properties] = properties;
+
+ application_manager_test::MockPolicyHandlerObserver policy_handler_observer;
+ policy_handler_.add_listener(&policy_handler_observer);
+
+ EXPECT_CALL(*mock_policy_manager_, InitCloudApp(kPolicyAppId_));
+ EXPECT_CALL(*mock_policy_manager_,
+ SetCloudAppEnabled(kPolicyAppId_, enabled));
+ EXPECT_CALL(*mock_policy_manager_,
+ SetAppNicknames(kPolicyAppId_, nicknames_vec));
+ EXPECT_CALL(*mock_policy_manager_,
+ SetAppAuthToken(kPolicyAppId_, auth_token));
+ EXPECT_CALL(*mock_policy_manager_,
+ SetAppCloudTransportType(kPolicyAppId_, cloud_transport_type));
+ EXPECT_CALL(*mock_policy_manager_,
+ SetHybridAppPreference(kPolicyAppId_, hybrid_app_preference_str));
+ EXPECT_CALL(*mock_policy_manager_, SetAppEndpoint(kPolicyAppId_, endpoint));
+ EXPECT_CALL(*mock_policy_manager_,
+ GetCloudAppParameters(kPolicyAppId_, _, _, _, _, _, _))
+ .WillOnce(DoAll(SetArgReferee<4>(auth_token), Return(true)));
+ EXPECT_CALL(app_manager_, RefreshCloudAppInformation());
+ EXPECT_CALL(policy_handler_observer,
+ OnAuthTokenUpdated(kPolicyAppId_, auth_token));
+
+ policy_handler_.OnSetCloudAppProperties(message);
+}
+
+TEST_F(PolicyHandlerTest, GetCloudAppParameters_AllProperties_SUCCESS) {
+ EnablePolicyAndPolicyManagerMock();
+
+ bool enabled = true;
+ std::string certificate = "aCertificate";
+ std::string auth_token = "anAuthToken";
+ std::string cloud_transport_type = "aTransportType";
+ std::string hybrid_app_preference_str = "CLOUD";
+ std::string endpoint = "anEndpoint";
+
+ application_manager_test::MockPolicyHandlerObserver policy_handler_observer;
+ policy_handler_.add_listener(&policy_handler_observer);
+
+ EXPECT_CALL(*mock_policy_manager_,
+ GetCloudAppParameters(kPolicyAppId_, _, _, _, _, _, _))
+ .WillOnce(DoAll(SetArgReferee<1>(enabled),
+ SetArgReferee<2>(endpoint),
+ SetArgReferee<3>(certificate),
+ SetArgReferee<4>(auth_token),
+ SetArgReferee<5>(cloud_transport_type),
+ SetArgReferee<6>(hybrid_app_preference_str),
+ Return(true)));
+
+ bool enabled_out;
+ std::string endpoint_out;
+ std::string cert_out;
+ std::string auth_token_out;
+ std::string ctt_out;
+ std::string hap_out;
+ EXPECT_TRUE(policy_handler_.GetCloudAppParameters(kPolicyAppId_,
+ enabled_out,
+ endpoint_out,
+ cert_out,
+ auth_token_out,
+ ctt_out,
+ hap_out));
+ EXPECT_EQ(enabled, enabled_out);
+ EXPECT_EQ(endpoint, endpoint_out);
+ EXPECT_EQ(certificate, cert_out);
+ EXPECT_EQ(auth_token, auth_token_out);
+ EXPECT_EQ(cloud_transport_type, ctt_out);
+ EXPECT_EQ(hybrid_app_preference_str, hap_out);
+}
+
} // namespace policy_handler_test
} // namespace components
} // namespace test