diff options
author | Jacob Keeler <jacob.keeler@livioradio.com> | 2019-03-07 22:43:04 -0500 |
---|---|---|
committer | jacobkeeler <jacob.keeler@livioradio.com> | 2019-03-07 22:45:21 -0500 |
commit | 9a60799a4f119e2411ee0a0a9d94ae1c8fa668f8 (patch) | |
tree | 730bd51dc8503a0d9c24f4e6f5c18ea5c56ddae9 /src/components/application_manager | |
parent | 3be4d6a8384f5422a040121c11b448a7dd6901fc (diff) | |
parent | 3da1fc5cd3a1873400ea28cb9977926ffa56e34c (diff) | |
download | sdl_core-9a60799a4f119e2411ee0a0a9d94ae1c8fa668f8.tar.gz |
Merge branch 'feature/cloud_app_transport' into feature/base_app_services_implementation
Diffstat (limited to 'src/components/application_manager')
33 files changed, 899 insertions, 155 deletions
diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index 7a59263299..b4d8ca857e 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -957,10 +957,10 @@ class Application : public virtual InitialApplicationData, * websocket open. * @return cloud app auth token */ - virtual const std::string& cloud_app_auth_token() const = 0; + virtual const std::string& auth_token() const = 0; /** - * @brief Get cloud app tranpsport type. Defines the type of websocket + * @brief Get cloud app transport type. Defines the type of websocket * connection used. * @return cloud app transport type */ @@ -994,7 +994,7 @@ class Application : public virtual InitialApplicationData, /** * @brief Set cloud app auth token */ - virtual void set_cloud_app_auth_token(const std::string& auth_token) = 0; + virtual void set_auth_token(const std::string& auth_token) = 0; /** * @brief Set cloud app transport type diff --git a/src/components/application_manager/include/application_manager/application_impl.h b/src/components/application_manager/include/application_manager/application_impl.h index 6d627d0c67..ff34d2a96a 100644 --- a/src/components/application_manager/include/application_manager/application_impl.h +++ b/src/components/application_manager/include/application_manager/application_impl.h @@ -420,10 +420,10 @@ class ApplicationImpl : public virtual Application, * websocket open. * @return cloud app auth token */ - const std::string& cloud_app_auth_token() const OVERRIDE; + const std::string& auth_token() const OVERRIDE; /** - * @brief Get cloud app tranpsport type. Defines the type of websocket + * @brief Get cloud app transport type. Defines the type of websocket * connection used. * @return cloud app transport type */ @@ -457,7 +457,7 @@ class ApplicationImpl : public virtual Application, /** * @brief Set cloud app auth token */ - void set_cloud_app_auth_token(const std::string& auth_token) OVERRIDE; + void set_auth_token(const std::string& auth_token) OVERRIDE; /** * @brief Set cloud app transport type diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index 12f2310d36..27be913cd5 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -117,6 +117,14 @@ struct CommandParametersPermissions; typedef std::map<std::string, hmi_apis::Common_TransportType::eType> DeviceTypes; +struct AppIconInfo { + std::string endpoint; + bool pending_request; + AppIconInfo(); + AppIconInfo(std::string ws_endpoint, bool pending) + : endpoint(ws_endpoint), pending_request(pending) {} +}; + CREATE_LOGGERPTR_GLOBAL(logger_, "ApplicationManager") typedef std::shared_ptr<timer::Timer> TimerSPtr; @@ -156,6 +164,7 @@ class ApplicationManagerImpl bool Stop() OVERRIDE; DataAccessor<ApplicationSet> applications() const OVERRIDE; + DataAccessor<AppsWaitRegistrationSet> pending_applications() const OVERRIDE; ApplicationSharedPtr application(uint32_t app_id) const OVERRIDE; ApplicationSharedPtr active_application() const OVERRIDE; @@ -164,6 +173,10 @@ class ApplicationManagerImpl uint32_t hmi_app_id) const OVERRIDE; ApplicationSharedPtr application_by_policy_id( const std::string& policy_app_id) const OVERRIDE; + ApplicationSharedPtr application_by_name( + const std::string& app_name) const OVERRIDE; + ApplicationSharedPtr pending_application_by_policy_id( + const std::string& policy_app_id) const OVERRIDE; std::vector<ApplicationSharedPtr> applications_by_button( uint32_t button) OVERRIDE; @@ -194,6 +207,9 @@ class ApplicationManagerImpl void SendDriverDistractionState(ApplicationSharedPtr application); + void SendGetIconUrlNotifications(const uint32_t connection_key, + ApplicationSharedPtr application); + ApplicationSharedPtr application( const std::string& device_id, const std::string& policy_app_id) const OVERRIDE; @@ -365,6 +381,8 @@ class ApplicationManagerImpl void ConnectToDevice(const std::string& device_mac) OVERRIDE; void OnHMIStartedCooperation() OVERRIDE; + void DisconnectCloudApp(ApplicationSharedPtr app) OVERRIDE; + void RefreshCloudAppInformation() OVERRIDE; void CreatePendingApplication( @@ -372,6 +390,14 @@ class ApplicationManagerImpl const transport_manager::DeviceInfo& device_info, connection_handler::DeviceHandle device_id); + void SetPendingApplicationState( + const transport_manager::ConnectionUID connection_id, + const transport_manager::DeviceInfo& device_info); + + std::string PolicyIDByIconUrl(const std::string url) OVERRIDE; + + void SetIconFileFromSystemRequest(const std::string policy_id) OVERRIDE; + /** * @brief Notifies the applicaiton manager that a cloud connection status has * updated and should trigger an UpdateAppList RPC to the HMI @@ -383,7 +409,6 @@ class ApplicationManagerImpl * @param app A cloud application * @return The current CloudConnectionStatus of app */ - hmi_apis::Common_CloudConnectionStatus::eType GetCloudAppConnectionStatus( ApplicationConstSharedPtr app) const; @@ -510,9 +535,6 @@ class ApplicationManagerImpl // typedef for Applications list typedef std::set<ApplicationSharedPtr, ApplicationsAppIdSorter> ApplictionSet; - typedef std::set<ApplicationSharedPtr, ApplicationsPolicyAppIdSorter> - AppsWaitRegistrationSet; - // typedef for Applications list iterator typedef ApplictionSet::iterator ApplictionSetIt; @@ -1002,6 +1024,14 @@ class ApplicationManagerImpl } }; + struct AppNamePredicate { + std::string app_name_; + AppNamePredicate(const std::string& app_name) : app_name_(app_name) {} + bool operator()(const ApplicationSharedPtr app) const { + return app ? app->name() == app_name_ : false; + } + }; + /** * @brief Sends UpdateAppList notification to HMI */ @@ -1496,6 +1526,9 @@ class ApplicationManagerImpl pending_device_map_lock_ptr_; std::map<std::string, std::string> pending_device_map_; + sync_primitives::Lock app_icon_map_lock_ptr_; + std::map<std::string, AppIconInfo> app_icon_map_; + #ifdef TELEMETRY_MONITOR AMTelemetryObserver* metric_observer_; #endif // TELEMETRY_MONITOR diff --git a/src/components/application_manager/include/application_manager/helpers/application_helper.h b/src/components/application_manager/include/application_manager/helpers/application_helper.h index 145bef659e..18267c9e7f 100644 --- a/src/components/application_manager/include/application_manager/helpers/application_helper.h +++ b/src/components/application_manager/include/application_manager/helpers/application_helper.h @@ -57,6 +57,18 @@ ApplicationSharedPtr FindApp(DataAccessor<ApplicationSet> accessor, return app; } +template <class UnaryPredicate> +ApplicationSharedPtr FindPendingApp( + DataAccessor<AppsWaitRegistrationSet> accessor, UnaryPredicate finder) { + AppsWaitRegistrationSet::iterator it = std::find_if( + accessor.GetData().begin(), accessor.GetData().end(), finder); + if (accessor.GetData().end() == it) { + return ApplicationSharedPtr(); + } + ApplicationSharedPtr app = *it; + return app; +} + /** * Helper function for lookup through applications list and returning all * applications satisfying predicate logic diff --git a/src/components/application_manager/include/application_manager/hmi_state.h b/src/components/application_manager/include/application_manager/hmi_state.h index 07d9c8dc23..774376b249 100644 --- a/src/components/application_manager/include/application_manager/hmi_state.h +++ b/src/components/application_manager/include/application_manager/hmi_state.h @@ -207,7 +207,7 @@ class HmiState { } protected: - std::shared_ptr<Application> app_; + uint32_t hmi_app_id_; StateID state_id_; const ApplicationManager& app_mngr_; HmiStatePtr parent_; diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h index 8a8e50bf1c..ac84bcfaa5 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -786,6 +786,14 @@ class MessageHelper { static hmi_apis::Common_Language::eType CommonLanguageFromString( const std::string& language); + /** + * @brief CommonLightNameFromString convert string to LightName enum value + * @param lightName string to convert + * @return value LightName enum value + */ + static hmi_apis::Common_LightName::eType CommonLightNameFromString( + const std::string& lightName); + static smart_objects::SmartObjectSPtr GetOnAppInterfaceUnregisteredNotificationToMobile( int32_t connection_key, diff --git a/src/components/application_manager/include/application_manager/policies/policy_handler.h b/src/components/application_manager/include/application_manager/policies/policy_handler.h index df96ade313..abc98876a2 100644 --- a/src/components/application_manager/include/application_manager/policies/policy_handler.h +++ b/src/components/application_manager/include/application_manager/policies/policy_handler.h @@ -187,6 +187,8 @@ class PolicyHandler : public PolicyHandlerInterface, void GetUpdateUrls(const uint32_t service_type, EndpointUrls& out_end_points) OVERRIDE; virtual std::string GetLockScreenIconUrl() const OVERRIDE; + virtual std::string GetIconUrl( + const std::string& policy_app_id) const OVERRIDE; uint32_t NextRetryTimeout() OVERRIDE; /** @@ -431,7 +433,7 @@ class PolicyHandler : public PolicyHandlerInterface, * @param hybrid_app_preference Filled with the hybrid app preference for the * cloud application set by the user */ - void GetCloudAppParameters(const std::string& policy_app_id, + bool GetCloudAppParameters(const std::string& policy_app_id, bool& enabled, std::string& endpoint, std::string& certificate, @@ -480,6 +482,9 @@ class PolicyHandler : public PolicyHandlerInterface, #ifdef EXTERNAL_PROPRIETARY_MODE void OnCertificateDecrypted(bool is_succeeded) OVERRIDE; #endif // EXTERNAL_PROPRIETARY_MODE + void OnAuthTokenUpdated(const std::string& policy_app_id, + const std::string& auth_token); + virtual bool CanUpdate() OVERRIDE; virtual void OnDeviceConsentChanged(const std::string& device_id, diff --git a/src/components/application_manager/include/application_manager/policies/regular/policy_handler_observer.h b/src/components/application_manager/include/application_manager/policies/regular/policy_handler_observer.h index 07d234f036..68e7511b43 100644 --- a/src/components/application_manager/include/application_manager/policies/regular/policy_handler_observer.h +++ b/src/components/application_manager/include/application_manager/policies/regular/policy_handler_observer.h @@ -48,6 +48,9 @@ class PolicyHandlerObserver { return false; } + virtual void OnAuthTokenUpdated(const std::string& policy_app_id, + const std::string& auth_token) {} + virtual void OnPTUFinished(const bool ptu_result) {} virtual ~PolicyHandlerObserver() {} diff --git a/src/components/application_manager/include/application_manager/smart_object_keys.h b/src/components/application_manager/include/application_manager/smart_object_keys.h index 5d030dace6..67c849c8fc 100644 --- a/src/components/application_manager/include/application_manager/smart_object_keys.h +++ b/src/components/application_manager/include/application_manager/smart_object_keys.h @@ -190,12 +190,14 @@ extern const char* green; extern const char* blue; extern const char* display_layout; extern const char* icon_resumed; +extern const char* nicknames; extern const char* enabled; -extern const char* cloud_app_auth_token; +extern const char* auth_token; extern const char* cloud_transport_type; extern const char* hybrid_app_preference; extern const char* is_cloud_application; extern const char* cloud_connection_status; +extern const char* endpoint; // PutFile extern const char* sync_file_name; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/get_cloud_app_properties_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/get_cloud_app_properties_request.h new file mode 100644 index 0000000000..3d74a80dc2 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/get_cloud_app_properties_request.h @@ -0,0 +1,31 @@ +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_GET_CLOUD_APP_PROPERTIES_REQUEST_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_GET_CLOUD_APP_PROPERTIES_REQUEST_H_ + +#include "application_manager/commands/command_request_impl.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +class GetCloudAppPropertiesRequest + : public app_mngr::commands::CommandRequestImpl { + public: + GetCloudAppPropertiesRequest( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler); + virtual ~GetCloudAppPropertiesRequest(); + virtual void Run(); + virtual void on_event(const app_mngr::event_engine::Event& event); + + private: + DISALLOW_COPY_AND_ASSIGN(GetCloudAppPropertiesRequest); +}; // GetCloudAppPropertiesRequest + +} // namespace commands +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_GET_CLOUD_APP_PROPERTIES_REQUEST_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/get_cloud_app_properties_response.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/get_cloud_app_properties_response.h new file mode 100644 index 0000000000..f716c7dcb5 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/get_cloud_app_properties_response.h @@ -0,0 +1,31 @@ +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_GET_CLOUD_APP_PROPERTIES_RESPONSE_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_GET_CLOUD_APP_PROPERTIES_RESPONSE_H_ + +#include "application_manager/commands/command_response_impl.h" + +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; + +namespace commands { + +class GetCloudAppPropertiesResponse + : public app_mngr::commands::CommandResponseImpl { + public: + GetCloudAppPropertiesResponse( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler); + virtual ~GetCloudAppPropertiesResponse(); + virtual void Run(); + + private: + DISALLOW_COPY_AND_ASSIGN(GetCloudAppPropertiesResponse); + +}; // GetCloudAppPropertiesResponse + +} // namespace commands +} // namespace sdl_rpc_plugin + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_MOBILE_GET_CLOUD_APP_PROPERTIES_RESPONSE_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h index f8be896996..91ee8ea813 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/register_app_interface_request.h @@ -144,11 +144,14 @@ class RegisterAppInterfaceRequest /* * @brief Check new application parameters (name, tts, vr) for * coincidence with already known parameters of registered applications + * @param out_duplicate_apps In the case other apps was found with duplicate + * names, this field will be filled with a list of said apps * * return SUCCESS if there is no coincidence of app.name/TTS/VR synonyms, * otherwise appropriate error code returns - */ - mobile_apis::Result::eType CheckCoincidence(); + */ + mobile_apis::Result::eType CheckCoincidence( + std::vector<app_mngr::ApplicationSharedPtr>& out_duplicate_apps); /* * @brief Predicate for using with CheckCoincidence method to compare with VR diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_exit_application_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_exit_application_notification.cc index 681390fbf4..b6d44a4511 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_exit_application_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_exit_application_notification.cc @@ -106,6 +106,10 @@ void OnExitApplicationNotification::Run() { application_manager_.UnregisterApplication(app_id, Result::SUCCESS); return; } + case Common_ApplicationExitReason::CLOSE_CLOUD_CONNECTION: { + application_manager_.DisconnectCloudApp(app_impl); + break; + } default: { LOG4CXX_WARN(logger_, "Unhandled reason"); return; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_cloud_app_properties_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_cloud_app_properties_request.cc new file mode 100644 index 0000000000..34ed30c243 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_cloud_app_properties_request.cc @@ -0,0 +1,98 @@ +#include "sdl_rpc_plugin/commands/mobile/get_cloud_app_properties_request.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +GetCloudAppPropertiesRequest::GetCloudAppPropertiesRequest( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandRequestImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +GetCloudAppPropertiesRequest::~GetCloudAppPropertiesRequest() {} + +void GetCloudAppPropertiesRequest::Run() { + LOG4CXX_AUTO_TRACE(logger_); + ApplicationSharedPtr app = application_manager_.application(connection_key()); + + if (!app) { + LOG4CXX_ERROR(logger_, "Application is not registered"); + SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED); + return; + } + + std::string policy_app_id = + (*message_)[strings::msg_params][strings::app_id].asString(); + + bool enabled = true; + std::string endpoint; + std::string auth_token; + std::string certificate; + std::string cloud_transport_type; + std::string hybrid_app_preference; + + bool result = policy_handler_.GetCloudAppParameters(policy_app_id, + enabled, + endpoint, + certificate, + auth_token, + cloud_transport_type, + hybrid_app_preference); + + if (!result) { + SendResponse(false, + mobile_apis::Result::DATA_NOT_AVAILABLE, + "Cloud app does not exist on module"); + return; + } + + policy::StringArray nicknames; + policy::StringArray app_hmi_types; + + policy_handler_.GetInitialAppData(policy_app_id, &nicknames, &app_hmi_types); + + smart_objects::SmartObject response_params(smart_objects::SmartType_Map); + smart_objects::SmartObject properties(smart_objects::SmartType_Map); + smart_objects::SmartObject nicknames_array(smart_objects::SmartType_Array); + size_t i = 0; + for (std::string nickname : nicknames) { + nicknames_array[i] = nickname; + ++i; + } + properties[strings::nicknames] = nicknames_array; + properties[strings::app_id] = policy_app_id; + properties[strings::enabled] = enabled; + + if (!auth_token.empty()) { + properties[strings::auth_token] = auth_token; + } + if (!cloud_transport_type.empty()) { + properties[strings::cloud_transport_type] = cloud_transport_type; + } + if (!hybrid_app_preference.empty()) { + properties[strings::hybrid_app_preference] = hybrid_app_preference; + } + if (!endpoint.empty()) { + properties[strings::endpoint] = endpoint; + } + + response_params[strings::properties] = properties; + + SendResponse(true, mobile_apis::Result::SUCCESS, NULL, &response_params); +} + +void GetCloudAppPropertiesRequest::on_event( + const app_mngr::event_engine::Event& event) { + LOG4CXX_INFO(logger_, "GetCloudAppPropertiesRequest on_event"); +} + +} // namespace commands +} // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_cloud_app_properties_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_cloud_app_properties_response.cc new file mode 100644 index 0000000000..813a9e7006 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/get_cloud_app_properties_response.cc @@ -0,0 +1,31 @@ +#include "application_manager/application_manager.h" +#include "application_manager/rpc_service.h" +#include "sdl_rpc_plugin/commands/mobile/get_cloud_app_properties_response.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +GetCloudAppPropertiesResponse::GetCloudAppPropertiesResponse( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandResponseImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + +GetCloudAppPropertiesResponse::~GetCloudAppPropertiesResponse() {} + +void GetCloudAppPropertiesResponse::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + rpc_service_.SendMessageToMobile(message_); +} + +} // namespace commands +} // namespace sdl_rpc_plugins diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc index b346ee5798..924705f82b 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_request.cc @@ -281,17 +281,51 @@ void RegisterAppInterfaceRequest::Run() { return; } - mobile_apis::Result::eType coincidence_result = CheckCoincidence(); + std::vector<ApplicationSharedPtr> duplicate_apps; + mobile_apis::Result::eType coincidence_result = + CheckCoincidence(duplicate_apps); + + if (mobile_apis::Result::DUPLICATE_NAME == coincidence_result && + duplicate_apps.size() == 1) { + ApplicationSharedPtr duplicate_app = duplicate_apps.front(); + bool error_response = true; + if (duplicate_app->is_cloud_app()) { + if (duplicate_app->hybrid_app_preference() == + mobile_apis::HybridAppPreference::MOBILE) { + // Unregister cloud application and allow mobile application to register + // in it's place + application_manager_.UnregisterApplication( + duplicate_app->app_id(), mobile_apis::Result::USER_DISALLOWED); + error_response = false; + } + } else { + ApplicationSharedPtr cloud_app = + application_manager_.pending_application_by_policy_id(policy_app_id); + // If the duplicate name was not because of a mobile/cloud app pair, go + // through the normal process for handling duplicate names + if (cloud_app.use_count() == 0 || !cloud_app->is_cloud_app()) { + usage_statistics::AppCounter count_of_rejections_duplicate_name( + GetPolicyHandler().GetStatisticManager(), + policy_app_id, + usage_statistics::REJECTIONS_DUPLICATE_NAME); + ++count_of_rejections_duplicate_name; + } else if (cloud_app->hybrid_app_preference() == + mobile_apis::HybridAppPreference::CLOUD) { + // Unregister mobile application and allow cloud application to + // register in it's place + application_manager_.UnregisterApplication( + duplicate_app->app_id(), mobile_apis::Result::USER_DISALLOWED); + error_response = false; + } + } - if (mobile_apis::Result::SUCCESS != coincidence_result) { - LOG4CXX_ERROR(logger_, "Coincidence check failed."); - if (mobile_apis::Result::DUPLICATE_NAME == coincidence_result) { - usage_statistics::AppCounter count_of_rejections_duplicate_name( - GetPolicyHandler().GetStatisticManager(), - policy_app_id, - usage_statistics::REJECTIONS_DUPLICATE_NAME); - ++count_of_rejections_duplicate_name; + if (error_response) { + LOG4CXX_ERROR(logger_, "Coincidence check failed."); + SendResponse(false, coincidence_result); + return; } + } else if (mobile_apis::Result::SUCCESS != coincidence_result) { + LOG4CXX_ERROR(logger_, "Coincidence check failed."); SendResponse(false, coincidence_result); return; } @@ -447,6 +481,9 @@ void RegisterAppInterfaceRequest::Run() { GetLockScreenIconUrlNotification(connection_key(), application); rpc_service_.ManageMobileCommand(so, SOURCE_SDL); application_manager_.SendDriverDistractionState(application); + // Create onSystemRequest to mobile to obtain cloud app icons + application_manager_.SendGetIconUrlNotifications(connection_key(), + application); } smart_objects::SmartObjectSPtr @@ -919,7 +956,8 @@ void RegisterAppInterfaceRequest::SendOnAppRegisteredNotificationToHMI( DCHECK(rpc_service_.ManageHMICommand(notification)); } -mobile_apis::Result::eType RegisterAppInterfaceRequest::CheckCoincidence() { +mobile_apis::Result::eType RegisterAppInterfaceRequest::CheckCoincidence( + std::vector<ApplicationSharedPtr>& out_duplicate_apps) { LOG4CXX_AUTO_TRACE(logger_); const smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params]; @@ -935,7 +973,8 @@ mobile_apis::Result::eType RegisterAppInterfaceRequest::CheckCoincidence() { const custom_str::CustomString& cur_name = (*it)->name(); if (app_name.CompareIgnoreCase(cur_name)) { LOG4CXX_ERROR(logger_, "Application name is known already."); - return mobile_apis::Result::DUPLICATE_NAME; + out_duplicate_apps.push_back(*it); + continue; } const smart_objects::SmartObject* vr = (*it)->vr_synonyms(); @@ -946,7 +985,8 @@ mobile_apis::Result::eType RegisterAppInterfaceRequest::CheckCoincidence() { if (0 != std::count_if(curr_vr->begin(), curr_vr->end(), v)) { LOG4CXX_ERROR(logger_, "Application name is known already."); - return mobile_apis::Result::DUPLICATE_NAME; + out_duplicate_apps.push_back(*it); + continue; } } @@ -958,12 +998,16 @@ mobile_apis::Result::eType RegisterAppInterfaceRequest::CheckCoincidence() { CoincidencePredicateVR v(cur_name); if (0 != std::count_if(new_vr->begin(), new_vr->end(), v)) { LOG4CXX_ERROR(logger_, "vr_synonyms duplicated with app_name ."); - return mobile_apis::Result::DUPLICATE_NAME; + out_duplicate_apps.push_back(*it); + continue; } } // end vr check } // application for end + if (!out_duplicate_apps.empty()) { + return mobile_apis::Result::DUPLICATE_NAME; + } return mobile_apis::Result::SUCCESS; } // method end diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloud_app_properties_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloud_app_properties_request.cc index 663881a2ea..5173be56d6 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloud_app_properties_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_cloud_app_properties_request.cc @@ -29,12 +29,6 @@ void SetCloudAppPropertiesRequest::Run() { return; } - if ((*message_)[strings::msg_params].empty()) { - LOG4CXX_ERROR(logger_, strings::msg_params << " is empty."); - SendResponse(false, mobile_apis::Result::INVALID_DATA); - return; - } - policy_handler_.OnSetCloudAppProperties(*message_); SendResponse(true, mobile_apis::Result::SUCCESS); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/system_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/system_request.cc index cea00a9d5e..da39aefd6a 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/system_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/system_request.cc @@ -511,7 +511,8 @@ void SystemRequest::Run() { return; } - if (!file_system::IsFileNameValid(file_name)) { + if (!file_system::IsFileNameValid(file_name) && + mobile_apis::RequestType::ICON_URL != request_type) { const std::string err_msg = "Sync file name contains forbidden symbols."; LOG4CXX_ERROR(logger_, err_msg); SendResponse(false, mobile_apis::Result::INVALID_DATA, err_msg.c_str()); @@ -533,8 +534,21 @@ void SystemRequest::Run() { std::string binary_data_folder; if ((*message_)[strings::params].keyExists(strings::binary_data)) { binary_data = (*message_)[strings::params][strings::binary_data].asBinary(); - binary_data_folder = - application_manager_.get_settings().system_files_path(); + if (mobile_apis::RequestType::ICON_URL == request_type) { + binary_data_folder = + application_manager_.get_settings().app_icons_folder(); + // Use the URL file name to identify the policy id. + // Save the icon file with the policy id as the name. + file_name = application_manager_.PolicyIDByIconUrl(file_name); + if (file_name.empty()) { + const std::string err_msg = "Invalid file name"; + SendResponse(false, mobile_apis::Result::INVALID_DATA, err_msg.c_str()); + } + LOG4CXX_DEBUG(logger_, "Got ICON_URL Request. File name: " << file_name); + } else { + binary_data_folder = + application_manager_.get_settings().system_files_path(); + } } else { binary_data_folder = application_manager_.get_settings().app_storage_folder(); @@ -581,6 +595,12 @@ void SystemRequest::Run() { LOG4CXX_DEBUG(logger_, "Binary data ok."); + if (mobile_apis::RequestType::ICON_URL == request_type) { + application_manager_.SetIconFileFromSystemRequest(file_name); + SendResponse(true, mobile_apis::Result::SUCCESS); + return; + } + if (mobile_apis::RequestType::HTTP == request_type && (*message_)[strings::msg_params].keyExists(strings::file_name)) { const std::string& file = diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc index f12dcbb485..554d004360 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/mobile_command_factory.cc @@ -127,6 +127,8 @@ #include "sdl_rpc_plugin/commands/mobile/send_haptic_data_response.h" #include "sdl_rpc_plugin/commands/mobile/set_cloud_app_properties_request.h" #include "sdl_rpc_plugin/commands/mobile/set_cloud_app_properties_response.h" +#include "sdl_rpc_plugin/commands/mobile/get_cloud_app_properties_request.h" +#include "sdl_rpc_plugin/commands/mobile/get_cloud_app_properties_response.h" #include "sdl_rpc_plugin/commands/mobile/get_file_request.h" #include "sdl_rpc_plugin/commands/mobile/get_file_response.h" #include "interfaces/MOBILE_API.h" @@ -353,6 +355,12 @@ CommandCreator& MobileCommandFactory::get_creator_factory( : factory .GetCreator<commands::SetCloudAppPropertiesResponse>(); } + case mobile_apis::FunctionID::GetCloudAppPropertiesID: { + return mobile_api::messageType::request == message_type + ? factory.GetCreator<commands::GetCloudAppPropertiesRequest>() + : factory + .GetCreator<commands::GetCloudAppPropertiesResponse>(); + } case mobile_apis::FunctionID::OnButtonEventID: { return factory.GetCreator<commands::mobile::OnButtonEventNotification>(); } diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index 02bf5b49fe..3d17da51ce 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -1167,7 +1167,7 @@ const std::string& ApplicationImpl::cloud_app_endpoint() const { return endpoint_; } -const std::string& ApplicationImpl::cloud_app_auth_token() const { +const std::string& ApplicationImpl::auth_token() const { return auth_token_; } @@ -1185,15 +1185,14 @@ const std::string& ApplicationImpl::cloud_app_certificate() const { } bool ApplicationImpl::is_cloud_app() const { - return !endpoint_.empty() && - hybrid_app_preference_ != mobile_apis::HybridAppPreference::MOBILE; + return !endpoint_.empty(); } void ApplicationImpl::set_cloud_app_endpoint(const std::string& endpoint) { endpoint_ = endpoint; } -void ApplicationImpl::set_cloud_app_auth_token(const std::string& auth_token) { +void ApplicationImpl::set_auth_token(const std::string& auth_token) { auth_token_ = auth_token; } diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index f9da143720..9d16c366d5 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -73,6 +73,7 @@ #include "policy/usage_statistics/counter.h" #include "utils/custom_string.h" #include <time.h> +#include <boost/filesystem.hpp> namespace { int get_rand_from_range(uint32_t from = 0, int to = RAND_MAX) { @@ -241,6 +242,13 @@ DataAccessor<ApplicationSet> ApplicationManagerImpl::applications() const { return accessor; } +DataAccessor<AppsWaitRegistrationSet> +ApplicationManagerImpl::pending_applications() const { + DataAccessor<AppsWaitRegistrationSet> accessor( + apps_to_register_, apps_to_register_list_lock_ptr_); + return accessor; +} + ApplicationSharedPtr ApplicationManagerImpl::application( uint32_t app_id) const { AppIdPredicate finder(app_id); @@ -262,6 +270,20 @@ ApplicationSharedPtr ApplicationManagerImpl::application_by_policy_id( return FindApp(accessor, finder); } +ApplicationSharedPtr ApplicationManagerImpl::application_by_name( + const std::string& app_name) const { + AppNamePredicate finder(app_name); + DataAccessor<ApplicationSet> accessor = applications(); + return FindApp(accessor, finder); +} + +ApplicationSharedPtr ApplicationManagerImpl::pending_application_by_policy_id( + const std::string& policy_app_id) const { + PolicyAppIdPredicate finder(policy_app_id); + DataAccessor<AppsWaitRegistrationSet> accessor = pending_applications(); + return FindPendingApp(accessor, finder); +} + bool ActiveAppPredicate(const ApplicationSharedPtr app) { return app ? app->IsFullscreen() : false; } @@ -618,7 +640,7 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( // Set cloud app parameters application->set_cloud_app_endpoint((*it)->cloud_app_endpoint()); application->set_cloud_app_certificate((*it)->cloud_app_certificate()); - application->set_cloud_app_auth_token((*it)->cloud_app_auth_token()); + application->set_auth_token((*it)->auth_token()); application->set_cloud_app_transport_type( (*it)->cloud_app_transport_type()); application->set_hybrid_app_preference((*it)->hybrid_app_preference()); @@ -676,6 +698,10 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( apps_size_ = applications_.size(); applications_list_lock_ptr_->Release(); + // Update cloud app information, in case any pending apps are unable to be + // registered due to a mobile app taking precedence + RefreshCloudAppInformation(); + // It is possible that secondary transport of this app has been already // established. Make sure that the information is reflected to application // instance. @@ -811,21 +837,116 @@ void ApplicationManagerImpl::OnHMIStartedCooperation() { RefreshCloudAppInformation(); } +std::string ApplicationManagerImpl::PolicyIDByIconUrl(const std::string url) { + sync_primitives::AutoLock lock(app_icon_map_lock_ptr_); + for (auto& x : app_icon_map_) { + auto policy_id = x.first; + std::string icon_url = GetPolicyHandler().GetIconUrl(policy_id); + if (icon_url == url) { + LOG4CXX_DEBUG(logger_, "Matched icon url: " << url); + x.second.pending_request = false; + return policy_id; + } + } + return std::string(""); +} + +void ApplicationManagerImpl::SetIconFileFromSystemRequest( + const std::string policy_id) { + app_icon_map_lock_ptr_.Acquire(); + auto app_icon_it = app_icon_map_.find(policy_id); + if (app_icon_it != app_icon_map_.end()) { + app_icon_map_.erase(app_icon_it); + } + app_icon_map_lock_ptr_.Release(); + + // Find pending application and set icon path + auto app = pending_application_by_policy_id(policy_id); + if (!app) { + return; + } + const std::string app_icon_dir(settings_.app_icons_folder()); + const std::string full_icon_path(app_icon_dir + "/" + policy_id); + if (file_system::FileExists(full_icon_path)) { + LOG4CXX_DEBUG(logger_, "Set Icon Path: " << full_icon_path); + AppFile file; + file.is_persistent = true; + file.is_download_complete = true; + file.file_name = full_icon_path; + + std::string icon_url = GetPolicyHandler().GetIconUrl(policy_id); + std::string extension = boost::filesystem::extension(icon_url); + if (extension == "bmp" || extension == "BMP") { + file.file_type = mobile_apis::FileType::GRAPHIC_BMP; + } else if (extension == "JPEG" || extension == "jpeg" || + extension == "JPG" || extension == "jpg") { + file.file_type = mobile_apis::FileType::GRAPHIC_JPEG; + } else { + file.file_type = mobile_apis::FileType::GRAPHIC_PNG; + } + + app->AddFile(file); + app->set_app_icon_path(full_icon_path); + } + SendUpdateAppList(); +} + +void ApplicationManagerImpl::DisconnectCloudApp(ApplicationSharedPtr app) { + std::string endpoint; + std::string certificate; + std::string auth_token; + std::string cloud_transport_type; + std::string hybrid_app_preference; + bool enabled = true; + std::string policy_app_id = app->policy_app_id(); + GetPolicyHandler().GetCloudAppParameters(policy_app_id, + enabled, + endpoint, + certificate, + auth_token, + cloud_transport_type, + hybrid_app_preference); + if (app->IsRegistered() && app->is_cloud_app()) { + LOG4CXX_DEBUG(logger_, "Disabled app is registered, unregistering now"); + GetRPCService().ManageMobileCommand( + MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( + app->app_id(), + mobile_api::AppInterfaceUnregisteredReason::APP_UNAUTHORIZED), + commands::Command::SOURCE_SDL); + + OnAppUnauthorized(app->app_id()); + } + // Delete the cloud device + connection_handler().RemoveCloudAppDevice(app->device()); + + transport_manager::transport_adapter::CloudAppProperties properties{ + endpoint, + certificate, + enabled, + auth_token, + cloud_transport_type, + hybrid_app_preference}; + // Create device in pending state + LOG4CXX_DEBUG(logger_, "Re-adding the cloud app device"); + connection_handler().AddCloudAppDevice(policy_app_id, properties); +} + void ApplicationManagerImpl::RefreshCloudAppInformation() { LOG4CXX_AUTO_TRACE(logger_); std::vector<std::string> enabled_apps; GetPolicyHandler().GetEnabledCloudApps(enabled_apps); std::vector<std::string>::iterator enabled_it = enabled_apps.begin(); std::vector<std::string>::iterator enabled_end = enabled_apps.end(); - std::string endpoint = ""; - std::string certificate = ""; - std::string auth_token = ""; - std::string cloud_transport_type = ""; - std::string hybrid_app_preference = ""; + std::string endpoint; + std::string certificate; + std::string auth_token; + std::string cloud_transport_type; + std::string hybrid_app_preference_str; bool enabled = true; // Store old device map and clear the current map pending_device_map_lock_ptr_->Acquire(); + app_icon_map_lock_ptr_.Acquire(); std::map<std::string, std::string> old_device_map = pending_device_map_; pending_device_map_ = std::map<std::string, std::string>(); // Create a device for each newly enabled cloud app @@ -836,21 +957,82 @@ void ApplicationManagerImpl::RefreshCloudAppInformation() { certificate, auth_token, cloud_transport_type, - hybrid_app_preference); + hybrid_app_preference_str); + + mobile_apis::HybridAppPreference::eType hybrid_app_preference = + mobile_apis::HybridAppPreference::INVALID_ENUM; + smart_objects::EnumConversionHelper< + mobile_apis::HybridAppPreference::eType>:: + StringToEnum(hybrid_app_preference_str, &hybrid_app_preference); + + auto policy_id = *enabled_it; + policy::StringArray nicknames; + policy::StringArray app_hmi_types; + GetPolicyHandler().GetInitialAppData(policy_id, &nicknames, &app_hmi_types); + + if (nicknames.empty()) { + LOG4CXX_ERROR(logger_, "Cloud App missing nickname"); + continue; + } else if (mobile_apis::HybridAppPreference::MOBILE == + hybrid_app_preference) { + auto nickname_it = nicknames.begin(); + for (; nickname_it != nicknames.end(); ++nickname_it) { + auto app = application_by_name(*nickname_it); + if (app.use_count() != 0) { + LOG4CXX_ERROR( + logger_, + "Mobile app already registered for cloud app: " << *nickname_it); + continue; + } + } + } pending_device_map_.insert( - std::pair<std::string, std::string>(endpoint, *enabled_it)); + std::pair<std::string, std::string>(endpoint, policy_id)); // Determine which endpoints were disabled by erasing all enabled apps from // the old device list auto old_device_it = old_device_map.find(endpoint); if (old_device_it != old_device_map.end()) { old_device_map.erase(old_device_it); + } + + transport_manager::transport_adapter::CloudAppProperties properties{ + endpoint, + certificate, + enabled, + auth_token, + cloud_transport_type, + hybrid_app_preference_str}; + + // If the device was disconnected, this will reinitialize the device + connection_handler().AddCloudAppDevice(policy_id, properties); + + // Look for app icon url data and add to app_icon_url_map + std::string url = GetPolicyHandler().GetIconUrl(policy_id); + + if (url.empty()) { + LOG4CXX_DEBUG(logger_, "No Icon Url for cloud app"); + continue; + } + + auto app_icon_it = app_icon_map_.find(policy_id); + if (app_icon_it != app_icon_map_.end()) { + LOG4CXX_DEBUG(logger_, "Cloud App Already Exists in Icon Map"); continue; } - connection_handler().AddCloudAppDevice( - *enabled_it, endpoint, cloud_transport_type); + const std::string app_icon_dir(settings_.app_icons_folder()); + const std::string full_icon_path(app_icon_dir + "/" + policy_id); + if (!file_system::FileExists(full_icon_path)) { + int icon_map_size = app_icon_map_.size(); + AppIconInfo icon_info(endpoint, false); + LOG4CXX_DEBUG(logger_, + "Inserting cloud app into icon map: " << icon_map_size); + app_icon_map_.insert( + std::pair<std::string, AppIconInfo>(policy_id, icon_info)); + } } + app_icon_map_lock_ptr_.Release(); pending_device_map_lock_ptr_->Release(); int removed_app_count = 0; @@ -905,16 +1087,17 @@ void ApplicationManagerImpl::CreatePendingApplication( connection_handler::DeviceHandle device_id) { LOG4CXX_AUTO_TRACE(logger_); - std::string endpoint = ""; - std::string certificate = ""; - std::string auth_token = ""; - std::string cloud_transport_type = ""; - std::string hybrid_app_preference_str = ""; + std::string endpoint; + std::string certificate; + std::string auth_token; + std::string cloud_transport_type; + std::string hybrid_app_preference_str; bool enabled = true; std::string name = device_info.name(); pending_device_map_lock_ptr_->Acquire(); auto it = pending_device_map_.find(name); if (it == pending_device_map_.end()) { + pending_device_map_lock_ptr_->Release(); return; } pending_device_map_lock_ptr_->Release(); @@ -927,7 +1110,7 @@ void ApplicationManagerImpl::CreatePendingApplication( GetPolicyHandler().GetInitialAppData( policy_app_id, &nicknames, &app_hmi_types); - if (!nicknames.size()) { + if (nicknames.empty()) { LOG4CXX_ERROR(logger_, "Cloud App missing nickname"); return; } @@ -968,7 +1151,7 @@ void ApplicationManagerImpl::CreatePendingApplication( mobile_apis::HybridAppPreference::eType>:: StringToEnum(hybrid_app_preference_str, &hybrid_app_preference_enum); - if (!convert_result) { + if (!hybrid_app_preference_str.empty() && !convert_result) { LOG4CXX_ERROR( logger_, "Could not convert string to enum: " << hybrid_app_preference_str); @@ -977,7 +1160,7 @@ void ApplicationManagerImpl::CreatePendingApplication( application->set_hmi_application_id(GenerateNewHMIAppID()); application->set_cloud_app_endpoint(endpoint); - application->set_cloud_app_auth_token(auth_token); + application->set_auth_token(auth_token); application->set_cloud_app_transport_type(cloud_transport_type); application->set_hybrid_app_preference(hybrid_app_preference_enum); application->set_cloud_app_certificate(certificate); @@ -992,6 +1175,36 @@ void ApplicationManagerImpl::CreatePendingApplication( SendUpdateAppList(); } +void ApplicationManagerImpl::SetPendingApplicationState( + const transport_manager::ConnectionUID connection_id, + const transport_manager::DeviceInfo& device_info) { + std::string name = device_info.name(); + pending_device_map_lock_ptr_->Acquire(); + auto it = pending_device_map_.find(name); + if (it == pending_device_map_.end()) { + pending_device_map_lock_ptr_->Release(); + return; + } + pending_device_map_lock_ptr_->Release(); + + const std::string policy_app_id = it->second; + auto app = application_by_policy_id(policy_app_id); + + if (!app) { + return; + } + LOG4CXX_DEBUG(logger_, + "Unregister application and move into apps_to_register"); + { + sync_primitives::AutoLock lock(apps_to_register_list_lock_ptr_); + apps_to_register_.insert(app); + } + + UnregisterApplication( + app->app_id(), mobile_apis::Result::INVALID_ENUM, true, true); + app->MarkUnregistered(); +} + void ApplicationManagerImpl::OnConnectionStatusUpdated() { SendUpdateAppList(); } @@ -1246,6 +1459,7 @@ void ApplicationManagerImpl::OnDeviceListUpdated( so_to_send[jhs::S_PARAMS][jhs::S_CORRELATION_ID] = GetNextHMICorrelationID(); so_to_send[jhs::S_MSG_PARAMS] = *msg_params; rpc_service_->ManageHMICommand(update_list); + RefreshCloudAppInformation(); } void ApplicationManagerImpl::OnFindNewApplicationsRequest() { @@ -2741,6 +2955,7 @@ void ApplicationManagerImpl::UnregisterApplication( logger_, "There is no more SDL4 apps with device handle: " << handle); RemoveAppsWaitingForRegistration(handle); + RefreshCloudAppInformation(); SendUpdateAppList(); } } @@ -3625,7 +3840,15 @@ void ApplicationManagerImpl::OnPTUFinished(const bool ptu_result) { if (!ptu_result) { return; } + RefreshCloudAppInformation(); + + auto app_id = policy_handler_->GetAppIdForSending(); + auto app = application(app_id); + if (app) { + SendGetIconUrlNotifications(app->app_id(), app); + } + auto on_app_policy_updated = [](plugin_manager::RPCPlugin& plugin) { plugin.OnPolicyEvent(plugin_manager::kApplicationPolicyUpdated); }; @@ -3668,6 +3891,58 @@ void ApplicationManagerImpl::SendDriverDistractionState( } } +void ApplicationManagerImpl::SendGetIconUrlNotifications( + const uint32_t connection_key, ApplicationSharedPtr application) { + LOG4CXX_AUTO_TRACE(logger_); + std::vector<std::string> enabled_apps; + GetPolicyHandler().GetEnabledCloudApps(enabled_apps); + std::vector<std::string>::iterator enabled_it = enabled_apps.begin(); + std::vector<std::string>::iterator enabled_end = enabled_apps.end(); + sync_primitives::AutoLock lock(app_icon_map_lock_ptr_); + for (; enabled_it != enabled_end; ++enabled_it) { + auto app_icon_it = app_icon_map_.find(*enabled_it); + if (app_icon_it == app_icon_map_.end()) { + LOG4CXX_WARN(logger_, "Could not find cloud app in icon map"); + continue; + } + + std::string endpoint = app_icon_it->second.endpoint; + bool pending_request = app_icon_it->second.pending_request; + + if (pending_request) { + LOG4CXX_DEBUG(logger_, "Cloud app has already sent request"); + continue; + } + + std::string url = GetPolicyHandler().GetIconUrl(*enabled_it); + + if (url.empty()) { + LOG4CXX_DEBUG(logger_, "No Icon Url for cloud app"); + continue; + } + + LOG4CXX_DEBUG(logger_, "Creating Get Icon Request"); + + smart_objects::SmartObjectSPtr message = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); + (*message)[strings::params][strings::function_id] = + mobile_apis::FunctionID::OnSystemRequestID; + (*message)[strings::params][strings::connection_key] = connection_key; + (*message)[strings::params][strings::message_type] = + mobile_apis::messageType::notification; + (*message)[strings::params][strings::protocol_version] = + application->protocol_version(); + (*message)[strings::msg_params][strings::request_type] = + mobile_apis::RequestType::ICON_URL; + (*message)[strings::msg_params][strings::url] = url; + + app_icon_it->second.pending_request = true; + + rpc_service_->ManageMobileCommand(message, commands::Command::SOURCE_SDL); + } +} + protocol_handler::MajorProtocolVersion ApplicationManagerImpl::SupportedSDLVersion() const { LOG4CXX_AUTO_TRACE(logger_); diff --git a/src/components/application_manager/src/hmi_capabilities_impl.cc b/src/components/application_manager/src/hmi_capabilities_impl.cc index f67590543d..6cd6747e99 100644 --- a/src/components/application_manager/src/hmi_capabilities_impl.cc +++ b/src/components/application_manager/src/hmi_capabilities_impl.cc @@ -1170,6 +1170,20 @@ bool HMICapabilitiesImpl::load_capabilities_from_file() { smart_objects::SmartObject rc_capability_so; formatters::CFormatterJsonBase::jsonValueToObj(rc_capability, rc_capability_so); + if (rc_capability_so.keyExists("lightControlCapabilities")) { + if (rc_capability_so["lightControlCapabilities"].keyExists( + "supportedLights")) { + auto& lights = rc_capability_so["lightControlCapabilities"] + ["supportedLights"]; + auto it = lights.asArray()->begin(); + for (; it != lights.asArray()->end(); ++it) { + smart_objects::SmartObject& light_name_so = (*it)["name"]; + auto light_name = MessageHelper::CommonLightNameFromString( + light_name_so.asString()); + light_name_so = light_name; + } + } + } set_rc_capability(rc_capability_so); if (!rc_capability_so.empty()) { set_rc_supported(true); diff --git a/src/components/application_manager/src/hmi_state.cc b/src/components/application_manager/src/hmi_state.cc index 7be9668543..e220988f0e 100644 --- a/src/components/application_manager/src/hmi_state.cc +++ b/src/components/application_manager/src/hmi_state.cc @@ -45,7 +45,7 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "HmiState") HmiState::HmiState(std::shared_ptr<Application> app, const ApplicationManager& app_mngr, StateID state_id) - : app_(app) + : hmi_app_id_(app->hmi_app_id()) , state_id_(state_id) , app_mngr_(app_mngr) , hmi_level_(mobile_apis::HMILevel::INVALID_ENUM) @@ -57,7 +57,7 @@ HmiState::HmiState(std::shared_ptr<Application> app, HmiState::HmiState(std::shared_ptr<Application> app, const ApplicationManager& app_mngr) - : app_(app) + : hmi_app_id_(app->hmi_app_id()) , state_id_(STATE_ID_REGULAR) , app_mngr_(app_mngr) , hmi_level_(mobile_apis::HMILevel::INVALID_ENUM) @@ -73,19 +73,27 @@ void HmiState::set_parent(HmiStatePtr parent) { } bool HmiState::is_navi_app() const { - return app_->is_navi(); + const ApplicationSharedPtr app = + app_mngr_.application_by_hmi_app(hmi_app_id_); + return app ? app->is_navi() : false; } bool HmiState::is_media_app() const { - return app_->is_media_application(); + const ApplicationSharedPtr app = + app_mngr_.application_by_hmi_app(hmi_app_id_); + return app ? app->is_media_application() : false; } bool HmiState::is_voice_communication_app() const { - return app_->is_voice_communication_supported(); + const ApplicationSharedPtr app = + app_mngr_.application_by_hmi_app(hmi_app_id_); + return app ? app->is_voice_communication_supported() : false; } bool HmiState::is_mobile_projection_app() const { - return app_->mobile_projection_enabled(); + const ApplicationSharedPtr app = + app_mngr_.application_by_hmi_app(hmi_app_id_); + return app ? app->mobile_projection_enabled() : false; } mobile_apis::AudioStreamingState::eType VRHmiState::audio_streaming_state() @@ -123,7 +131,9 @@ VideoStreamingHmiState::VideoStreamingHmiState( mobile_apis::VideoStreamingState::eType VideoStreamingHmiState::video_streaming_state() const { - if (app_->IsVideoApplication()) { + const ApplicationSharedPtr app = + app_mngr_.application_by_hmi_app(hmi_app_id_); + if (app && app->IsVideoApplication()) { return parent()->video_streaming_state(); } @@ -201,7 +211,7 @@ AudioSource::AudioSource(std::shared_ptr<Application> app, const ApplicationManager& app_mngr) : HmiState(app, app_mngr, STATE_ID_AUDIO_SOURCE) , keep_context_(app->keep_context()) { - app_->set_keep_context(false); + app->set_keep_context(false); } mobile_apis::HMILevel::eType AudioSource::hmi_level() const { @@ -260,7 +270,15 @@ std::ostream& operator<<(std::ostream& os, const HmiState::StateID src) { } std::ostream& operator<<(std::ostream& os, const HmiState& src) { - os << "HMIState(app id:" << src.app_->app_id() << ", state:" << src.state_id() + const ApplicationSharedPtr app = + src.app_mngr_.application_by_hmi_app(src.hmi_app_id_); + os << "HMIState(app id:"; + if (app) { + os << app->app_id(); + } else { + os << "(none)"; + } + os << ", hmi app id:" << src.hmi_app_id_ << ", state:" << src.state_id() << ", hmi_level:" << src.hmi_level() << ", audio:" << src.audio_streaming_state() << ", video:" << src.video_streaming_state() diff --git a/src/components/application_manager/src/message_helper/message_helper.cc b/src/components/application_manager/src/message_helper/message_helper.cc index 7db2308c2c..0e44a53c6f 100644 --- a/src/components/application_manager/src/message_helper/message_helper.cc +++ b/src/components/application_manager/src/message_helper/message_helper.cc @@ -290,6 +290,17 @@ hmi_apis::Common_Language::eType MessageHelper::CommonLanguageFromString( return hmi_apis::Common_Language::INVALID_ENUM; } +hmi_apis::Common_LightName::eType MessageHelper::CommonLightNameFromString( + const std::string& lightName) { + using namespace ns_smart_device_link::ns_smart_objects; + hmi_apis::Common_LightName::eType value; + if (EnumConversionHelper<hmi_apis::Common_LightName::eType>::StringToEnum( + lightName, &value)) { + return value; + } + return hmi_apis::Common_LightName::INVALID_ENUM; +} + std::string MessageHelper::GetDeviceMacAddressForHandle( const transport_manager::DeviceHandle device_handle, const ApplicationManager& app_mngr) { @@ -1592,6 +1603,7 @@ bool MessageHelper::CreateHMIApplicationStruct( message[hmi_response::policy_app_id] = policy_app_id; const std::string icon_path = app->app_icon_path(); + if (file_system::FileExists(app->app_icon_path())) { message[strings::icon] = icon_path; } diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index c267ac5de9..6a164d196a 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -91,7 +91,8 @@ RequestTypeMap TypeToString = { {mobile_apis::RequestType::EMERGENCY, "EMERGENCY"}, {mobile_apis::RequestType::MEDIA, "MEDIA"}, {mobile_apis::RequestType::FOTA, "FOTA"}, - {mobile_apis::RequestType::OEM_SPECIFIC, "OEM_SPECIFIC"}}; + {mobile_apis::RequestType::OEM_SPECIFIC, "OEM_SPECIFIC"}, + {mobile_apis::RequestType::ICON_URL, "ICON_URL"}}; const std::string RequestTypeToString(mobile_apis::RequestType::eType type) { RequestTypeMap::const_iterator it = TypeToString.find(type); @@ -1576,6 +1577,11 @@ std::string PolicyHandler::GetLockScreenIconUrl() const { return policy_manager_->GetLockScreenIconUrl(); } +std::string PolicyHandler::GetIconUrl(const std::string& policy_app_id) const { + POLICY_LIB_CHECK(std::string("")); + return policy_manager_->GetIconUrl(policy_app_id); +} + uint32_t PolicyHandler::NextRetryTimeout() { POLICY_LIB_CHECK(0); LOG4CXX_AUTO_TRACE(logger_); @@ -1771,6 +1777,17 @@ void PolicyHandler::OnCertificateUpdated(const std::string& certificate_data) { } #endif // EXTERNAL_PROPRIETARY_MODE +void PolicyHandler::OnAuthTokenUpdated(const std::string& policy_app_id, + const std::string& auth_token) { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(listeners_lock_); + HandlersCollection::const_iterator it = listeners_.begin(); + for (; it != listeners_.end(); ++it) { + PolicyHandlerObserver* observer = *it; + observer->OnAuthTokenUpdated(policy_app_id, auth_token); + } +} + void PolicyHandler::OnPTUFinished(const bool ptu_result) { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(listeners_lock_); @@ -1852,7 +1869,7 @@ void PolicyHandler::GetEnabledCloudApps( policy_manager_->GetEnabledCloudApps(enabled_apps); } -void PolicyHandler::GetCloudAppParameters( +bool PolicyHandler::GetCloudAppParameters( const std::string& policy_app_id, bool& enabled, std::string& endpoint, @@ -1860,14 +1877,14 @@ void PolicyHandler::GetCloudAppParameters( std::string& auth_token, std::string& cloud_transport_type, std::string& hybrid_app_preference) const { - POLICY_LIB_CHECK_VOID(); - policy_manager_->GetCloudAppParameters(policy_app_id, - enabled, - endpoint, - certificate, - auth_token, - cloud_transport_type, - hybrid_app_preference); + POLICY_LIB_CHECK(false); + return policy_manager_->GetCloudAppParameters(policy_app_id, + enabled, + endpoint, + certificate, + auth_token, + cloud_transport_type, + hybrid_app_preference); } const bool PolicyHandler::CheckCloudAppEnabled( @@ -1898,43 +1915,76 @@ void PolicyHandler::OnSetCloudAppProperties( << strings::msg_params); return; } - const smart_objects::SmartObject& msg_params = message[strings::msg_params]; - if (!msg_params.keyExists(strings::app_id)) { + if (!message[strings::msg_params].keyExists(strings::properties)) { + LOG4CXX_ERROR(logger_, + "Message does not contain app properties " + << strings::msg_params); + return; + } + + const smart_objects::SmartObject& properties = + message[strings::msg_params][strings::properties]; + if (!properties.keyExists(strings::app_id)) { LOG4CXX_ERROR(logger_, "Message does not contain mandatory parameter " << strings::app_id); return; } - std::string policy_app_id(msg_params[strings::app_id].asString()); + std::string policy_app_id(properties[strings::app_id].asString()); policy_manager_->InitCloudApp(policy_app_id); - if (msg_params.keyExists(strings::enabled)) { - policy_manager_->SetCloudAppEnabled(policy_app_id, - msg_params[strings::enabled].asBool()); - + bool auth_token_update = false; + if (properties.keyExists(strings::enabled)) { + bool enabled = properties[strings::enabled].asBool(); + policy_manager_->SetCloudAppEnabled(policy_app_id, enabled); + auth_token_update = enabled; application_manager_.RefreshCloudAppInformation(); } - if (msg_params.keyExists(strings::cloud_app_auth_token)) { - policy_manager_->SetAppAuthToken( - policy_app_id, msg_params[strings::cloud_app_auth_token].asString()); + if (properties.keyExists(strings::auth_token)) { + std::string auth_token = properties[strings::auth_token].asString(); + policy_manager_->SetAppAuthToken(policy_app_id, auth_token); + auth_token_update = true; } - if (msg_params.keyExists(strings::cloud_transport_type)) { + if (properties.keyExists(strings::cloud_transport_type)) { policy_manager_->SetAppCloudTransportType( - policy_app_id, msg_params[strings::cloud_transport_type].asString()); + policy_app_id, properties[strings::cloud_transport_type].asString()); + } + if (properties.keyExists(strings::endpoint)) { + policy_manager_->SetAppEndpoint(policy_app_id, + properties[strings::endpoint].asString()); + } + if (properties.keyExists(strings::nicknames)) { + StringArray nicknames; + const smart_objects::SmartObject& nicknames_array = + properties[strings::nicknames]; + for (size_t i = 0; i < nicknames_array.length(); ++i) { + nicknames.push_back(nicknames_array[i].asString()); + } + policy_manager_->SetAppNicknames(policy_app_id, nicknames); } - if (msg_params.keyExists(strings::hybrid_app_preference)) { + if (properties.keyExists(strings::hybrid_app_preference)) { std::string hybrid_app_preference; mobile_apis::HybridAppPreference::eType value = static_cast<mobile_apis::HybridAppPreference::eType>( - msg_params[strings::hybrid_app_preference].asUInt()); + properties[strings::hybrid_app_preference].asUInt()); smart_objects::EnumConversionHelper< mobile_apis::HybridAppPreference::eType>:: EnumToString(value, &hybrid_app_preference); policy_manager_->SetHybridAppPreference(policy_app_id, hybrid_app_preference); } + + if (auth_token_update) { + bool enabled; + std::string end, cert, ctt, hap; + std::string auth_token; + + policy_manager_->GetCloudAppParameters( + policy_app_id, enabled, end, cert, auth_token, ctt, hap); + OnAuthTokenUpdated(policy_app_id, auth_token); + } } void PolicyHandler::GetAppServiceParameters( diff --git a/src/components/application_manager/src/smart_object_keys.cc b/src/components/application_manager/src/smart_object_keys.cc index 402a15ae60..a1dedd1d64 100644 --- a/src/components/application_manager/src/smart_object_keys.cc +++ b/src/components/application_manager/src/smart_object_keys.cc @@ -157,12 +157,14 @@ const char* green = "green"; const char* blue = "blue"; const char* display_layout = "displayLayout"; const char* icon_resumed = "iconResumed"; +const char* nicknames = "nicknames"; const char* enabled = "enabled"; -const char* cloud_app_auth_token = "cloudAppAuthToken"; +const char* auth_token = "authToken"; const char* cloud_transport_type = "cloudTransportType"; const char* hybrid_app_preference = "hybridAppPreference"; const char* is_cloud_application = "isCloudApplication"; const char* cloud_connection_status = "cloudConnectionStatus"; +const char* endpoint = "endpoint"; // PutFile const char* sync_file_name = "syncFileName"; diff --git a/src/components/application_manager/test/application_impl_test.cc b/src/components/application_manager/test/application_impl_test.cc index 301ed227b8..437f567538 100644 --- a/src/components/application_manager/test/application_impl_test.cc +++ b/src/components/application_manager/test/application_impl_test.cc @@ -118,6 +118,13 @@ class ApplicationImplTest : public ::testing::Test { AddSet hmi_action); void CheckCurrentHMIState(); + // 'directory_name' has to be declared prior to 'app_impl' so that when + // deleting ApplicationImplTest class, 'directory_name' will be removed + // after 'app_impl' runs its destructor. + // (ApplicationImpl's destructor calls CleanupFiles(), which will call + // application_manager_.get_settings().app_storage_folder() and will + // access 'directory_name'.) + const std::string directory_name = "./test_storage"; MockApplicationManagerSettings mock_application_manager_settings_; MockApplicationManager mock_application_manager_; std::shared_ptr<ApplicationImpl> app_impl; @@ -126,7 +133,6 @@ class ApplicationImplTest : public ::testing::Test { std::string mac_address; connection_handler::DeviceHandle device_handle; custom_str::CustomString app_name; - const std::string directory_name = "./test_storage"; HmiState::StateID state_id; HmiStatePtr testHmiState; HMILevel::eType test_lvl; diff --git a/src/components/application_manager/test/application_manager_impl_test.cc b/src/components/application_manager/test/application_manager_impl_test.cc index 389f092e50..f27e252142 100644 --- a/src/components/application_manager/test/application_manager_impl_test.cc +++ b/src/components/application_manager/test/application_manager_impl_test.cc @@ -1435,8 +1435,7 @@ TEST_F(ApplicationManagerImplTest, ON_CALL(*waiting_app, device()).WillByDefault(Return(kDeviceId)); EXPECT_CALL(*waiting_app, cloud_app_endpoint()) .WillOnce(ReturnRef(kEndpoint)); - EXPECT_CALL(*waiting_app, cloud_app_auth_token()) - .WillOnce(ReturnRef(kAuthToken)); + EXPECT_CALL(*waiting_app, auth_token()).WillOnce(ReturnRef(kAuthToken)); EXPECT_CALL(*waiting_app, cloud_app_certificate()) .WillOnce(ReturnRef(kCertificate)); EXPECT_CALL(*waiting_app, cloud_app_transport_type()) @@ -1489,7 +1488,7 @@ TEST_F(ApplicationManagerImplTest, EXPECT_EQ(APIVersion::kAPIV3, application->version().max_supported_api_version); EXPECT_EQ(kEndpoint, application->cloud_app_endpoint()); - EXPECT_EQ(kAuthToken, application->cloud_app_auth_token()); + EXPECT_EQ(kAuthToken, application->auth_token()); EXPECT_EQ(kCertificate, application->cloud_app_certificate()); EXPECT_EQ(kTransportType, application->cloud_app_transport_type()); EXPECT_EQ(kHybridAppPreference, application->hybrid_app_preference()); diff --git a/src/components/application_manager/test/help_prompt_manager_test.cc b/src/components/application_manager/test/help_prompt_manager_test.cc index f921eb1dde..dc6635b049 100644 --- a/src/components/application_manager/test/help_prompt_manager_test.cc +++ b/src/components/application_manager/test/help_prompt_manager_test.cc @@ -136,10 +136,12 @@ class HelpPromptManagerTest : public ::testing::Test { typedef CommandsTest<CommandsTestMocks::kIsNice>::MockAppManager MockAppManager; MockAppManager app_mngr_; + // put this before ApplicationImplTest instance, so that app_mngr_settings_ + // will still exist during app_impl_'s destructor. + NiceMock<MockApplicationManagerSettings> app_mngr_settings_; std::shared_ptr<ApplicationImplTest> app_impl_; MockHmiInterfaces mock_hmi_interfaces_; NiceMock<event_engine_test::MockEventDispatcher> mock_event_dispatcher_; - NiceMock<MockApplicationManagerSettings> app_mngr_settings_; std::shared_ptr<application_manager_test::MockApplication> mock_app_; sync_primitives::Lock app_lock_; MockRPCService mock_rpc_service_; @@ -175,11 +177,6 @@ void HelpPromptManagerTest::SetUp() { mock_help_prompt_manager_ = std::shared_ptr<MockHelpPromptManager>(new MockHelpPromptManager()); - HmiStatePtr state = std::make_shared<HmiState>( - static_cast<std::shared_ptr<Application> >(mock_app_), - app_mngr_, - HmiState::STATE_ID_REGULAR); - std::string path = file_system::CreateDirectory("storage"); file_system::CreateFile(path + "/" + "certificate"); diff --git a/src/components/application_manager/test/include/application_manager/mock_application.h b/src/components/application_manager/test/include/application_manager/mock_application.h index d5b3752936..36d20f227d 100644 --- a/src/components/application_manager/test/include/application_manager/mock_application.h +++ b/src/components/application_manager/test/include/application_manager/mock_application.h @@ -343,14 +343,14 @@ class MockApplication : public ::application_manager::Application { MOCK_CONST_METHOD0(is_remote_control_supported, bool()); MOCK_METHOD1(set_remote_control_supported, void(const bool allow)); MOCK_CONST_METHOD0(cloud_app_endpoint, const std::string&()); - MOCK_CONST_METHOD0(cloud_app_auth_token, const std::string&()); + MOCK_CONST_METHOD0(auth_token, const std::string&()); MOCK_CONST_METHOD0(cloud_app_transport_type, const std::string&()); MOCK_CONST_METHOD0(hybrid_app_preference, const mobile_apis::HybridAppPreference::eType&()); MOCK_CONST_METHOD0(cloud_app_certificate, const std::string&()); MOCK_CONST_METHOD0(is_cloud_app, bool()); MOCK_METHOD1(set_cloud_app_endpoint, void(const std::string& endpoint)); - MOCK_METHOD1(set_cloud_app_auth_token, void(const std::string& auth_token)); + MOCK_METHOD1(set_auth_token, void(const std::string& auth_token)); MOCK_METHOD1(set_cloud_app_transport_type, void(const std::string& transport_type)); MOCK_METHOD1(set_hybrid_app_preference, diff --git a/src/components/application_manager/test/include/application_manager/mock_message_helper.h b/src/components/application_manager/test/include/application_manager/mock_message_helper.h index 7889774fae..ac39c39f22 100644 --- a/src/components/application_manager/test/include/application_manager/mock_message_helper.h +++ b/src/components/application_manager/test/include/application_manager/mock_message_helper.h @@ -164,6 +164,8 @@ class MockMessageHelper { ApplicationManager& app_mngr)); MOCK_METHOD1(CommonLanguageFromString, hmi_apis::Common_Language::eType(const std::string& language)); + MOCK_METHOD1(CommonLightNameFromString, + hmi_apis::Common_LightName::eType(const std::string& lightName)); MOCK_METHOD1(CommonLanguageToString, std::string(hmi_apis::Common_Language::eType)); MOCK_METHOD2(CreateModuleInfoSO, diff --git a/src/components/application_manager/test/mock_message_helper.cc b/src/components/application_manager/test/mock_message_helper.cc index b3b3327ca9..518761c315 100644 --- a/src/components/application_manager/test/mock_message_helper.cc +++ b/src/components/application_manager/test/mock_message_helper.cc @@ -277,6 +277,12 @@ hmi_apis::Common_Language::eType MessageHelper::CommonLanguageFromString( language); } +hmi_apis::Common_LightName::eType MessageHelper::CommonLightNameFromString( + const std::string& lightName) { + return MockMessageHelper::message_helper_mock()->CommonLightNameFromString( + lightName); +} + smart_objects::SmartObjectSPtr MessageHelper::CreateModuleInfoSO( uint32_t function_id, ApplicationManager& app_mngr) { return MockMessageHelper::message_helper_mock()->CreateModuleInfoSO( diff --git a/src/components/application_manager/test/state_controller/state_controller_test.cc b/src/components/application_manager/test/state_controller/state_controller_test.cc index 58fea00f82..9574f8d00f 100644 --- a/src/components/application_manager/test/state_controller/state_controller_test.cc +++ b/src/components/application_manager/test/state_controller/state_controller_test.cc @@ -170,34 +170,42 @@ class StateControllerImplTest : public ::testing::Test { am::ApplicationSharedPtr simple_app_; NiceMock<application_manager_test::MockApplication>* simple_app_ptr_; uint32_t simple_app_id_ = 1721; + uint32_t simple_hmi_app_id_ = 22770; // random number am::ApplicationSharedPtr navi_app_; NiceMock<application_manager_test::MockApplication>* navi_app_ptr_; uint32_t navi_app_id_ = 1762; + uint32_t navi_hmi_app_id_ = 17559; am::ApplicationSharedPtr media_app_; NiceMock<application_manager_test::MockApplication>* media_app_ptr_; uint32_t media_app_id_ = 1801; + uint32_t media_hmi_app_id_ = 12751; am::ApplicationSharedPtr vc_app_; NiceMock<application_manager_test::MockApplication>* vc_app_ptr_; uint32_t vc_app_id_ = 1825; + uint32_t vc_hmi_app_id_ = 14986; am::ApplicationSharedPtr media_navi_app_; NiceMock<application_manager_test::MockApplication>* media_navi_app_ptr_; uint32_t media_navi_app_id_ = 1855; + uint32_t media_navi_hmi_app_id_ = 16194; am::ApplicationSharedPtr media_vc_app_; NiceMock<application_manager_test::MockApplication>* media_vc_app_ptr_; uint32_t media_vc_app_id_ = 1881; + uint32_t media_vc_hmi_app_id_ = 12798; am::ApplicationSharedPtr navi_vc_app_; NiceMock<application_manager_test::MockApplication>* navi_vc_app_ptr_; uint32_t navi_vc_app_id_ = 1894; + uint32_t navi_vc_hmi_app_id_ = 10807; am::ApplicationSharedPtr media_navi_vc_app_; NiceMock<application_manager_test::MockApplication>* media_navi_vc_app_ptr_; uint32_t media_navi_vc_app_id_ = 1922; + uint32_t media_navi_vc_hmi_app_id_ = 21419; std::vector<am::HmiStatePtr> valid_states_for_audio_app_; std::vector<am::HmiStatePtr> valid_states_for_not_audio_app_; @@ -661,6 +669,7 @@ class StateControllerImplTest : public ::testing::Test { am::ApplicationSharedPtr ConfigureApp( NiceMock<application_manager_test::MockApplication>** app_mock, uint32_t app_id, + uint32_t hmi_app_id, bool media, bool navi, bool vc) { @@ -670,6 +679,7 @@ class StateControllerImplTest : public ::testing::Test { am::ApplicationSharedPtr app(*app_mock); ON_CALL(**app_mock, app_id()).WillByDefault(Return(app_id)); + ON_CALL(**app_mock, hmi_app_id()).WillByDefault(Return(hmi_app_id)); ON_CALL(**app_mock, is_media_application()).WillByDefault(Return(media)); ON_CALL(**app_mock, is_navi()).WillByDefault(Return(navi)); ON_CALL(**app_mock, is_voice_communication_supported()) @@ -871,21 +881,50 @@ class StateControllerImplTest : public ::testing::Test { } void ConfigureApps() { - simple_app_ = ConfigureApp( - &simple_app_ptr_, simple_app_id_, NOT_MEDIA, NOT_NAVI, NOT_VC); - media_app_ = - ConfigureApp(&media_app_ptr_, media_app_id_, MEDIA, NOT_NAVI, NOT_VC); - navi_app_ = - ConfigureApp(&navi_app_ptr_, navi_app_id_, NOT_MEDIA, NAVI, NOT_VC); - vc_app_ = ConfigureApp(&vc_app_ptr_, vc_app_id_, NOT_MEDIA, NOT_NAVI, VC); - media_navi_app_ = ConfigureApp( - &media_navi_app_ptr_, media_navi_app_id_, MEDIA, NAVI, NOT_VC); - media_vc_app_ = - ConfigureApp(&media_vc_app_ptr_, media_vc_app_id_, MEDIA, NOT_NAVI, VC); - navi_vc_app_ = - ConfigureApp(&navi_vc_app_ptr_, navi_vc_app_id_, NOT_MEDIA, NAVI, VC); - media_navi_vc_app_ = ConfigureApp( - &media_navi_vc_app_ptr_, media_navi_vc_app_id_, MEDIA, NAVI, VC); + simple_app_ = ConfigureApp(&simple_app_ptr_, + simple_app_id_, + simple_hmi_app_id_, + NOT_MEDIA, + NOT_NAVI, + NOT_VC); + media_app_ = ConfigureApp(&media_app_ptr_, + media_app_id_, + media_hmi_app_id_, + MEDIA, + NOT_NAVI, + NOT_VC); + navi_app_ = ConfigureApp(&navi_app_ptr_, + navi_app_id_, + navi_hmi_app_id_, + NOT_MEDIA, + NAVI, + NOT_VC); + vc_app_ = ConfigureApp( + &vc_app_ptr_, vc_app_id_, vc_hmi_app_id_, NOT_MEDIA, NOT_NAVI, VC); + media_navi_app_ = ConfigureApp(&media_navi_app_ptr_, + media_navi_app_id_, + media_navi_hmi_app_id_, + MEDIA, + NAVI, + NOT_VC); + media_vc_app_ = ConfigureApp(&media_vc_app_ptr_, + media_vc_app_id_, + media_vc_hmi_app_id_, + MEDIA, + NOT_NAVI, + VC); + navi_vc_app_ = ConfigureApp(&navi_vc_app_ptr_, + navi_vc_app_id_, + navi_vc_hmi_app_id_, + NOT_MEDIA, + NAVI, + VC); + media_navi_vc_app_ = ConfigureApp(&media_navi_vc_app_ptr_, + media_navi_vc_app_id_, + media_navi_vc_hmi_app_id_, + MEDIA, + NAVI, + VC); applications_list_.push_back(simple_app_); applications_list_.push_back(media_app_); applications_list_.push_back(navi_app_); @@ -914,6 +953,15 @@ class StateControllerImplTest : public ::testing::Test { ASSERT_EQ(navi_vc_app_->app_id(), navi_vc_app_id_); ASSERT_EQ(media_navi_vc_app_->app_id(), media_navi_vc_app_id_); + ASSERT_EQ(simple_app_->hmi_app_id(), simple_hmi_app_id_); + ASSERT_EQ(media_app_->hmi_app_id(), media_hmi_app_id_); + ASSERT_EQ(navi_app_->hmi_app_id(), navi_hmi_app_id_); + ASSERT_EQ(vc_app_->hmi_app_id(), vc_hmi_app_id_); + ASSERT_EQ(media_navi_app_->hmi_app_id(), media_navi_hmi_app_id_); + ASSERT_EQ(media_vc_app_->hmi_app_id(), media_vc_hmi_app_id_); + ASSERT_EQ(navi_vc_app_->hmi_app_id(), navi_vc_hmi_app_id_); + ASSERT_EQ(media_navi_vc_app_->hmi_app_id(), media_navi_vc_hmi_app_id_); + ASSERT_FALSE(simple_app_->IsAudioApplication()); ASSERT_TRUE(media_app_->IsAudioApplication()); ASSERT_TRUE(navi_app_->IsAudioApplication()); @@ -1040,6 +1088,8 @@ class StateControllerImplTest : public ::testing::Test { application_set_.insert(app); ON_CALL(app_manager_mock_, application(app->app_id())) .WillByDefault(Return(app)); + ON_CALL(app_manager_mock_, application_by_hmi_app(app->hmi_app_id())) + .WillByDefault(Return(app)); } am::HmiStatePtr NoneNotAudibleState() { @@ -1475,9 +1525,9 @@ TEST_F(StateControllerImplTest, NiceMock<application_manager_test::MockApplication>* app_moved_to_full_mock; app_in_full = - ConfigureApp(&app_in_full_mock, 1761, NOT_MEDIA, NOT_NAVI, NOT_VC); - app_moved_to_full = - ConfigureApp(&app_moved_to_full_mock, 1796, NOT_MEDIA, NOT_NAVI, NOT_VC); + ConfigureApp(&app_in_full_mock, 1761, 15685, NOT_MEDIA, NOT_NAVI, NOT_VC); + app_moved_to_full = ConfigureApp( + &app_moved_to_full_mock, 1796, 30093, NOT_MEDIA, NOT_NAVI, NOT_VC); InsertApplication(app_in_full); InsertApplication(app_moved_to_full); @@ -1549,11 +1599,11 @@ TEST_F(StateControllerImplTest, namespace SystemContext = mobile_apis::SystemContext; NiceMock<application_manager_test::MockApplication>* app_in_full_mock; am::ApplicationSharedPtr app_in_full = - ConfigureApp(&app_in_full_mock, 1761, MEDIA, NOT_NAVI, NOT_VC); + ConfigureApp(&app_in_full_mock, 1761, 15685, MEDIA, NOT_NAVI, NOT_VC); NiceMock<application_manager_test::MockApplication>* app_moved_to_full_mock; - am::ApplicationSharedPtr app_moved_to_full = - ConfigureApp(&app_moved_to_full_mock, 1796, MEDIA, NOT_NAVI, NOT_VC); + am::ApplicationSharedPtr app_moved_to_full = ConfigureApp( + &app_moved_to_full_mock, 1796, 30093, MEDIA, NOT_NAVI, NOT_VC); InsertApplication(app_in_full); InsertApplication(app_moved_to_full); @@ -1575,11 +1625,11 @@ TEST_F(StateControllerImplTest, NiceMock<application_manager_test::MockApplication>* app_in_limited_mock; am::ApplicationSharedPtr app_in_limited = - ConfigureApp(&app_in_limited_mock, 1761, NOT_MEDIA, NAVI, NOT_VC); + ConfigureApp(&app_in_limited_mock, 1761, 15685, NOT_MEDIA, NAVI, NOT_VC); NiceMock<application_manager_test::MockApplication>* app_moved_to_full_mock; am::ApplicationSharedPtr app_moved_to_full = - ConfigureApp(&app_moved_to_full_mock, 1796, NOT_MEDIA, NAVI, VC); + ConfigureApp(&app_moved_to_full_mock, 1796, 30093, NOT_MEDIA, NAVI, VC); InsertApplication(app_in_limited); InsertApplication(app_moved_to_full); @@ -1600,12 +1650,12 @@ TEST_F(StateControllerImplTest, namespace SystemContext = mobile_apis::SystemContext; NiceMock<application_manager_test::MockApplication>* app_in_limited_mock; am::ApplicationSharedPtr app_in_limited = - ConfigureApp(&app_in_limited_mock, 1761, NOT_MEDIA, NOT_NAVI, VC); + ConfigureApp(&app_in_limited_mock, 1761, 15685, NOT_MEDIA, NOT_NAVI, VC); NiceMock<application_manager_test::MockApplication>* app_moved_to_limited_mock; - am::ApplicationSharedPtr app_moved_to_limited = - ConfigureApp(&app_moved_to_limited_mock, 1796, NOT_MEDIA, NOT_NAVI, VC); + am::ApplicationSharedPtr app_moved_to_limited = ConfigureApp( + &app_moved_to_limited_mock, 1796, 30093, NOT_MEDIA, NOT_NAVI, VC); InsertApplication(app_in_limited); InsertApplication(app_moved_to_limited); @@ -1749,8 +1799,8 @@ TEST_F(StateControllerImplTest, namespace SystemContext = mobile_apis::SystemContext; NiceMock<application_manager_test::MockApplication>* app_moved_to_full_mock; - am::ApplicationSharedPtr app_moved_to_full = - ConfigureApp(&app_moved_to_full_mock, 1761, NOT_MEDIA, NOT_NAVI, NOT_VC); + am::ApplicationSharedPtr app_moved_to_full = ConfigureApp( + &app_moved_to_full_mock, 1761, 15685, NOT_MEDIA, NOT_NAVI, NOT_VC); am::ApplicationSharedPtr limited_app = media_app_; NiceMock<application_manager_test::MockApplication>* limited_app_mock = @@ -1758,7 +1808,7 @@ TEST_F(StateControllerImplTest, NiceMock<application_manager_test::MockApplication>* full_app_mock; am::ApplicationSharedPtr full_app = - ConfigureApp(&full_app_mock, 1796, NOT_MEDIA, NOT_NAVI, NOT_VC); + ConfigureApp(&full_app_mock, 1796, 30093, NOT_MEDIA, NOT_NAVI, NOT_VC); InsertApplication(app_moved_to_full); InsertApplication(limited_app); @@ -1786,16 +1836,16 @@ TEST_F( namespace SystemContext = mobile_apis::SystemContext; NiceMock<application_manager_test::MockApplication>* app_moved_to_full_mock; - am::ApplicationSharedPtr app_moved_to_full = - ConfigureApp(&app_moved_to_full_mock, 1761, MEDIA, NOT_NAVI, NOT_VC); + am::ApplicationSharedPtr app_moved_to_full = ConfigureApp( + &app_moved_to_full_mock, 1761, 15685, MEDIA, NOT_NAVI, NOT_VC); NiceMock<application_manager_test::MockApplication>* limited_app_mock; am::ApplicationSharedPtr limited_app = - ConfigureApp(&limited_app_mock, 1762, MEDIA, NOT_NAVI, NOT_VC); + ConfigureApp(&limited_app_mock, 1762, 17559, MEDIA, NOT_NAVI, NOT_VC); NiceMock<application_manager_test::MockApplication>* full_app_mock; am::ApplicationSharedPtr full_app = - ConfigureApp(&full_app_mock, 1796, NOT_MEDIA, NOT_NAVI, NOT_VC); + ConfigureApp(&full_app_mock, 1796, 30093, NOT_MEDIA, NOT_NAVI, NOT_VC); InsertApplication(app_moved_to_full); InsertApplication(limited_app); @@ -1823,16 +1873,16 @@ TEST_F( namespace SystemContext = mobile_apis::SystemContext; NiceMock<application_manager_test::MockApplication>* app_moved_to_full_mock; - am::ApplicationSharedPtr app_moved_to_full = - ConfigureApp(&app_moved_to_full_mock, 1761, MEDIA, NOT_NAVI, NOT_VC); + am::ApplicationSharedPtr app_moved_to_full = ConfigureApp( + &app_moved_to_full_mock, 1761, 15685, MEDIA, NOT_NAVI, NOT_VC); NiceMock<application_manager_test::MockApplication>* limited_app_mock; am::ApplicationSharedPtr limited_app = - ConfigureApp(&limited_app_mock, 1762, MEDIA, NOT_NAVI, NOT_VC); + ConfigureApp(&limited_app_mock, 1762, 17559, MEDIA, NOT_NAVI, NOT_VC); NiceMock<application_manager_test::MockApplication>* full_app_mock; am::ApplicationSharedPtr full_app = - ConfigureApp(&full_app_mock, 1796, NOT_MEDIA, NAVI, NOT_VC); + ConfigureApp(&full_app_mock, 1796, 30093, NOT_MEDIA, NAVI, NOT_VC); InsertApplication(app_moved_to_full); InsertApplication(limited_app); @@ -2845,14 +2895,7 @@ TEST_F(StateControllerImplTest, am::event_engine::Event event(event_id); event.set_smart_object(msg); - const HmiStatePtr state = - createHmiState(mobile_apis::HMILevel::HMI_FULL, - mobile_apis::AudioStreamingState::AUDIBLE, - mobile_apis::VideoStreamingState::NOT_STREAMABLE, - mobile_apis::SystemContext::SYSCTXT_MAIN); - EXPECT_CALL(*simple_app_ptr_, keep_context()).WillOnce(Return(true)); - EXPECT_CALL(*simple_app_ptr_, RegularHmiState()).WillOnce(Return(state)); EXPECT_CALL(*simple_app_ptr_, IsAudioApplication()) .WillRepeatedly(Return(true)); EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) @@ -2884,12 +2927,6 @@ TEST_F(StateControllerImplTest, OnEventChangedAudioSourceAppToBackground) { am::event_engine::Event event(event_id); event.set_smart_object(msg); - const HmiStatePtr state = - createHmiState(mobile_apis::HMILevel::HMI_LIMITED, - mobile_apis::AudioStreamingState::AUDIBLE, - mobile_apis::VideoStreamingState::NOT_STREAMABLE, - mobile_apis::SystemContext::SYSCTXT_MAIN); - EXPECT_CALL(*simple_app_ptr_, RegularHmiState()).WillOnce(Return(state)); EXPECT_CALL(*simple_app_ptr_, IsAudioApplication()) .WillRepeatedly(Return(true)); EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) |