diff options
Diffstat (limited to 'src/components/application_manager')
174 files changed, 8131 insertions, 2729 deletions
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 0bab0243d0..5bdebc441e 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 @@ -271,12 +271,29 @@ class ApplicationManagerImpl /** * @brief Checks if Application is subscribed for way points + * @param Application id + * @return true if Application is subscribed for way points + * otherwise false + */ + bool IsAppSubscribedForWayPoints(uint32_t app_id) const OVERRIDE; + + /** + * @brief Checks if Application is subscribed for way points * @param Application pointer * @return true if Application is subscribed for way points * otherwise false */ bool IsAppSubscribedForWayPoints(ApplicationSharedPtr app) const OVERRIDE; + void SaveWayPointsMessage( + smart_objects::SmartObjectSPtr way_points_message) OVERRIDE; + + /** + * @brief Subscribe Application for way points + * @param Application id + */ + void SubscribeAppForWayPoints(uint32_t app_id) OVERRIDE; + /** * @brief Subscribe Application for way points * @param Application pointer @@ -285,6 +302,12 @@ class ApplicationManagerImpl /** * @brief Unsubscribe Application for way points + * @param Application id + */ + void UnsubscribeAppFromWayPoints(uint32_t app_id) OVERRIDE; + + /** + * @brief Unsubscribe Application for way points * @param Application pointer */ void UnsubscribeAppFromWayPoints(ApplicationSharedPtr app) OVERRIDE; @@ -400,7 +423,10 @@ class ApplicationManagerImpl mobile_api::HMILevel::eType IsHmiLevelFullAllowed(ApplicationSharedPtr app); void ConnectToDevice(const std::string& device_mac) OVERRIDE; - void OnHMIStartedCooperation() OVERRIDE; + + void OnHMIReady() OVERRIDE; + + void RequestForInterfacesAvailability() OVERRIDE; void DisconnectCloudApp(ApplicationSharedPtr app) OVERRIDE; @@ -834,12 +860,12 @@ class ApplicationManagerImpl */ void EndNaviServices(uint32_t app_id) OVERRIDE; - /** - * @brief ForbidStreaming forbid the stream over the certain application. - * @param app_id the application's id which should stop streaming. - */ + DEPRECATED void ForbidStreaming(uint32_t app_id) OVERRIDE; + void ForbidStreaming(uint32_t app_id, + protocol_handler::ServiceType service_type) OVERRIDE; + /** * @brief Called when application completes streaming configuration * @param app_id Streaming application id @@ -934,6 +960,7 @@ class ApplicationManagerImpl */ bool IsHMICooperating() const OVERRIDE; + void SetHMICooperating(const bool hmi_cooperating) OVERRIDE; /** * @brief Method used to send default app tts globalProperties * in case they were not provided from mobile side after defined time @@ -1510,6 +1537,8 @@ class ApplicationManagerImpl */ std::set<uint32_t> subscribed_way_points_apps_list_; + smart_objects::SmartObjectSPtr way_points_data_; + /** * @brief Map contains applications which * will send TTS global properties to HMI after timeout @@ -1579,6 +1608,7 @@ class ApplicationManagerImpl NaviServiceStatusMap navi_service_status_; sync_primitives::Lock navi_service_status_lock_; std::deque<uint32_t> navi_app_to_stop_; + sync_primitives::Lock navi_app_to_stop_lock_; std::deque<uint32_t> navi_app_to_end_stream_; uint32_t navi_close_app_timeout_; uint32_t navi_end_stream_timeout_; diff --git a/src/components/application_manager/include/application_manager/commands/command.h b/src/components/application_manager/include/application_manager/commands/command.h index 0536c7aee1..a7241ce16d 100644 --- a/src/components/application_manager/include/application_manager/commands/command.h +++ b/src/components/application_manager/include/application_manager/commands/command.h @@ -98,6 +98,18 @@ class Command { */ virtual WindowID window_id() const = 0; + /** + * @brief Set warning info string, to be sent on a successful response + * @param info Warning info string + */ + virtual void set_warning_info(const std::string info) = 0; + + /** + * @brief Returns warning info string + * @return Warning info string + */ + virtual std::string warning_info() const = 0; + /* * @brief Function is called by RequestController when request execution time * has exceed it's limit diff --git a/src/components/application_manager/include/application_manager/commands/command_impl.h b/src/components/application_manager/include/application_manager/commands/command_impl.h index d57568dd6a..151c4d7874 100644 --- a/src/components/application_manager/include/application_manager/commands/command_impl.h +++ b/src/components/application_manager/include/application_manager/commands/command_impl.h @@ -122,6 +122,10 @@ class CommandImpl : public Command { */ WindowID window_id() const OVERRIDE; + void set_warning_info(const std::string info) OVERRIDE; + + std::string warning_info() const OVERRIDE; + /* * @brief Function is called by RequestController when request execution time * has exceed it's limit @@ -155,6 +159,14 @@ class CommandImpl : public Command { static uint32_t CalcCommandInternalConsecutiveNumber( application_manager::ApplicationConstSharedPtr app); + /** + * @brief Check syntax of string from mobile + * @param str - string that need to be checked + * @param allow_empty_string if true methods allow empty sting + * @return true if success otherwise return false + */ + bool CheckSyntax(const std::string& str, bool allow_empty_line = false) const; + // members static const int32_t hmi_protocol_type_; static const int32_t mobile_protocol_type_; @@ -162,6 +174,20 @@ class CommandImpl : public Command { protected: /** + * @brief Checks message permissions and parameters according to policy table + * permissions + * @param source The source of the command (used to determine if a response + * should be sent on failure) + * @return true if the RPC is allowed, false otherwise + */ + bool CheckAllowedParameters(const Command::CommandSource source); + + /** + * @brief Remove from current message parameters disallowed by policy table + */ + void RemoveDisallowedParameters(); + + /** * @brief Parses mobile message and replaces mobile app id with HMI app id * @param message Message to replace its ids * @return True if replacement succeeded, otherwise - false @@ -183,6 +209,15 @@ class CommandImpl : public Command { HMICapabilities& hmi_capabilities_; policy::PolicyHandlerInterface& policy_handler_; + /** + * @brief warning_info_ Defines a warning message to send in the case of a + * successful response + */ + std::string warning_info_; + + CommandParametersPermissions parameters_permissions_; + CommandParametersPermissions removed_parameters_permissions_; + #ifdef ENABLE_LOG static log4cxx::LoggerPtr logger_; #endif // ENABLE_LOG diff --git a/src/components/application_manager/include/application_manager/commands/command_notification_from_mobile_impl.h b/src/components/application_manager/include/application_manager/commands/command_notification_from_mobile_impl.h index e8485a3abc..4a1d6efbc5 100644 --- a/src/components/application_manager/include/application_manager/commands/command_notification_from_mobile_impl.h +++ b/src/components/application_manager/include/application_manager/commands/command_notification_from_mobile_impl.h @@ -50,6 +50,7 @@ class CommandNotificationFromMobileImpl : public CommandImpl { policy::PolicyHandlerInterface& policy_handler); virtual ~CommandNotificationFromMobileImpl(); virtual bool Init(); + bool CheckPermissions() OVERRIDE; virtual bool CleanUp(); virtual void Run(); void SendNotification(); diff --git a/src/components/application_manager/include/application_manager/commands/command_request_impl.h b/src/components/application_manager/include/application_manager/commands/command_request_impl.h index 293366f91a..87c19ca1d1 100644 --- a/src/components/application_manager/include/application_manager/commands/command_request_impl.h +++ b/src/components/application_manager/include/application_manager/commands/command_request_impl.h @@ -166,14 +166,6 @@ class CommandRequestImpl : public CommandImpl, const smart_objects::SmartObject* response_params = NULL, const std::vector<uint8_t> binary_data = std::vector<uint8_t>()); - /** - * @brief Check syntax of string from mobile - * @param str - string that need to be checked - * @param allow_empty_string if true methods allow empty sting - * @return true if success otherwise return false - */ - bool CheckSyntax(const std::string& str, bool allow_empty_line = false); - void SendProviderRequest( const mobile_apis::FunctionID::eType& mobile_function_id, const hmi_apis::FunctionID::eType& hmi_function_id, @@ -236,8 +228,11 @@ class CommandRequestImpl : public CommandImpl, /** * @brief Checks message permissions and parameters according to policy table * permissions + * @param source The source of the command (used to determine if a response + * should be sent on failure) + * @return true if the RPC is allowed, false otherwise */ - bool CheckAllowedParameters(); + bool CheckAllowedParameters(const Command::CommandSource source); /** * @brief Checks HMI capabilities for specified button support @@ -248,11 +243,6 @@ class CommandRequestImpl : public CommandImpl, bool CheckHMICapabilities(const mobile_apis::ButtonName::eType button) const; /** - * @brief Remove from current message parameters disallowed by policy table - */ - void RemoveDisallowedParameters(); - - /** * @brief Adds disallowed parameters back to response with appropriate * reasons * @param response Response message, which should be extended with blocked @@ -375,8 +365,6 @@ class CommandRequestImpl : public CommandImpl, RequestState current_state_; sync_primitives::Lock state_lock_; - CommandParametersPermissions parameters_permissions_; - CommandParametersPermissions removed_parameters_permissions_; /** * @brief hash_update_mode_ Defines whether request must update hash value of @@ -392,7 +380,7 @@ class CommandRequestImpl : public CommandImpl, * @param info string with disallowed params enumeration * @param param disallowed param */ - void AddDissalowedParameterToInfoString(std::string& info, + void AddDisallowedParameterToInfoString(std::string& info, const std::string& param) const; /** diff --git a/src/components/application_manager/include/application_manager/commands/command_request_to_mobile.h b/src/components/application_manager/include/application_manager/commands/command_request_to_mobile.h index 430e549523..6b6dbde141 100644 --- a/src/components/application_manager/include/application_manager/commands/command_request_to_mobile.h +++ b/src/components/application_manager/include/application_manager/commands/command_request_to_mobile.h @@ -51,6 +51,7 @@ class CommandRequestToMobile : public CommandImpl { policy::PolicyHandlerInterface& policy_handler); ~CommandRequestToMobile(); bool Init() OVERRIDE; + bool CheckPermissions() OVERRIDE; bool CleanUp() OVERRIDE; void Run() OVERRIDE; void SendRequest(); diff --git a/src/components/application_manager/include/application_manager/commands/command_response_from_mobile.h b/src/components/application_manager/include/application_manager/commands/command_response_from_mobile.h index 1401888890..f428d8561b 100644 --- a/src/components/application_manager/include/application_manager/commands/command_response_from_mobile.h +++ b/src/components/application_manager/include/application_manager/commands/command_response_from_mobile.h @@ -51,6 +51,7 @@ class CommandResponseFromMobile : public CommandImpl { policy::PolicyHandlerInterface& policy_handler); ~CommandResponseFromMobile(); bool Init() OVERRIDE; + bool CheckPermissions() OVERRIDE; bool CleanUp() OVERRIDE; void Run() OVERRIDE; void SendResponse(); diff --git a/src/components/application_manager/include/application_manager/commands/request_to_hmi.h b/src/components/application_manager/include/application_manager/commands/request_to_hmi.h index e8850fbe8d..3057476937 100644 --- a/src/components/application_manager/include/application_manager/commands/request_to_hmi.h +++ b/src/components/application_manager/include/application_manager/commands/request_to_hmi.h @@ -74,6 +74,21 @@ class RequestToHMI : public CommandImpl { virtual void Run(); void SendRequest(); + /** + * @brief Updates required requests that should be send to the HMI to get + * required HMI capabilities + * @param interface_name Interface name (e.g. UI, TTS, VR, RC or VehicleInfo) + */ + void UpdateRequiredInterfaceCapabilitiesRequests( + const std::string& interface_name); + + /** + * @brief According to the specified interface sends appropriate requests to + * HMI for fetching of capabilities + * @param interface_name Interface name (e.g. UI, TTS, VR, RC or VehicleInfo) + */ + void RequestInterfaceCapabilities(const char* interface_name); + /* * @brief Retrieves application ID */ @@ -83,6 +98,22 @@ class RequestToHMI : public CommandImpl { private: DISALLOW_COPY_AND_ASSIGN(RequestToHMI); + + /** + * @brief Updates required requests that should be send to + * the HMI to get required HMI capabilities according to the passed function + * ids + * @param requests_to_send_to_hmi Collection of the function ids + */ + void UpdateRequestsRequiredForCapabilities( + const std::set<hmi_apis::FunctionID::eType>& requests_to_send_to_hmi); + + /** + * @brief Sends request to HMI for fetching of capabilities according to the + * passed function ids + */ + void RequestCapabilities( + const std::set<hmi_apis::FunctionID::eType>& requests_to_send_to_hmi); }; } // namespace commands diff --git a/src/components/application_manager/include/application_manager/hmi_capabilities_impl.h b/src/components/application_manager/include/application_manager/hmi_capabilities_impl.h index b7f41ca297..089105fdba 100644 --- a/src/components/application_manager/include/application_manager/hmi_capabilities_impl.h +++ b/src/components/application_manager/include/application_manager/hmi_capabilities_impl.h @@ -38,7 +38,6 @@ #include "interfaces/HMI_API.h" #include "interfaces/MOBILE_API.h" #include "json/json.h" -#include "smart_objects/smart_object.h" #include "utils/macro.h" namespace application_manager { @@ -46,32 +45,19 @@ class ApplicationManager; class HMICapabilitiesImpl : public HMICapabilities { public: - /* + /** * @ Class constructor - * * @param app_mngr Application manager pointer */ explicit HMICapabilitiesImpl(ApplicationManager& app_mngr); - /* + /** * @brief Class destructor - * */ virtual ~HMICapabilitiesImpl(); - /* - * @brief Checks is image type(Static/Dynamic) requested by - * Mobile Device is supported on current HMI. - * @param image_type recieved type of image from Enum. - * @return Bool true if supported - */ bool VerifyImageType(const int32_t image_type) const OVERRIDE; - /** - * @brief Checks if all HMI capabilities received - * - * @return TRUE if all information received, otherwise FALSE - */ bool is_vr_cooperating() const OVERRIDE; void set_is_vr_cooperating(const bool value) OVERRIDE; @@ -90,491 +76,339 @@ class HMICapabilitiesImpl : public HMICapabilities { bool is_rc_cooperating() const OVERRIDE; void set_is_rc_cooperating(const bool value) OVERRIDE; - /* - * @brief Interface used to store information about software version of the - *target - * - * @param ccpu_version Received system/hmi software version - */ void set_ccpu_version(const std::string& ccpu_version) OVERRIDE; - /* - * @brief Returns software version of the target - * - * @return TRUE if it supported, otherwise FALSE - */ const std::string& ccpu_version() const OVERRIDE; - /* - * @brief Retrieves if mixing audio is supported by HMI - * (ie recording TTS command and playing audio) - * - * @return Current state of the mixing audio flag - */ bool attenuated_supported() const OVERRIDE; - /* - * @brief Sets state for mixing audio - * - * @param state New state to be set - */ void set_attenuated_supported(const bool state) OVERRIDE; - /* - * @brief Retrieves currently active UI language - * - * @return Currently active UI language - */ const hmi_apis::Common_Language::eType active_ui_language() const OVERRIDE; - /* - * @brief Sets currently active UI language - * - * @param language Currently active UI language - */ void set_active_ui_language( const hmi_apis::Common_Language::eType language) OVERRIDE; - /* - * @brief Retrieves UI supported languages - * - * @return Currently supported UI languages - */ - const smart_objects::SmartObject* ui_supported_languages() const OVERRIDE; + const smart_objects::SmartObjectSPtr ui_supported_languages() const OVERRIDE; - /* - * @brief Sets supported UI languages - * - * @param supported_languages Supported UI languages - */ void set_ui_supported_languages( const smart_objects::SmartObject& supported_languages) OVERRIDE; - /* - * @brief Retrieves currently active VR language - * - * @return Currently active VR language - */ const hmi_apis::Common_Language::eType active_vr_language() const OVERRIDE; - /* - * @brief Sets currently active VR language - * - * @param language Currently active VR language - */ void set_active_vr_language( const hmi_apis::Common_Language::eType language) OVERRIDE; - /* - * @brief Retrieves VR supported languages - * - * @return Currently supported VR languages - */ - const smart_objects::SmartObject* vr_supported_languages() const OVERRIDE; + const smart_objects::SmartObjectSPtr vr_supported_languages() const OVERRIDE; - /* - * @brief Sets supported VR languages - * - * @param supported_languages Supported VR languages - */ void set_vr_supported_languages( const smart_objects::SmartObject& supported_languages) OVERRIDE; - /* - * @brief Retrieves currently active TTS language - * - * @return Currently active TTS language - */ const hmi_apis::Common_Language::eType active_tts_language() const OVERRIDE; - /* - * @brief Sets currently active TTS language - * - * @param language Currently active TTS language - */ void set_active_tts_language( const hmi_apis::Common_Language::eType language) OVERRIDE; - /* - * @brief Retrieves TTS supported languages - * - * @return Currently supported TTS languages - */ - const smart_objects::SmartObject* tts_supported_languages() const OVERRIDE; + const smart_objects::SmartObjectSPtr tts_supported_languages() const OVERRIDE; - /* - * @brief Sets supported TTS languages - * - * @param supported_languages Supported TTS languages - */ void set_tts_supported_languages( const smart_objects::SmartObject& supported_languages) OVERRIDE; - /* - * @brief Retrieves information about the display capabilities - * - * @return Currently supported display capabilities - */ const smart_objects::SmartObjectSPtr display_capabilities() const OVERRIDE; - /* - * @brief Sets supported display capabilities - * - * @param display_capabilities supported display capabilities - */ void set_display_capabilities( const smart_objects::SmartObject& display_capabilities) OVERRIDE; - /* - * @brief Retrieves information about the display capability - * @return Currently supported display capability - */ const smart_objects::SmartObjectSPtr system_display_capabilities() const OVERRIDE; - /* - * @brief Sets supported display capability - * @param display_capabilities supported display capability - */ void set_system_display_capabilities( const smart_objects::SmartObject& display_capabilities); - /* - * @brief Retrieves information about the HMI zone capabilities - * - * @return Currently supported HMI zone capabilities - */ const smart_objects::SmartObjectSPtr hmi_zone_capabilities() const OVERRIDE; - /* - * @brief Sets supported HMI zone capabilities - * - * @param hmi_zone_capabilities supported HMI zone capabilities - */ void set_hmi_zone_capabilities( const smart_objects::SmartObject& hmi_zone_capabilities) OVERRIDE; - /* - * @brief Retrieves information about the SoftButton's capabilities - * - * @return Currently supported SoftButton's capabilities - */ const smart_objects::SmartObjectSPtr soft_button_capabilities() const OVERRIDE; - /* - * @brief Sets supported SoftButton's capabilities - * - * @param soft_button_capabilities supported SoftButton's capabilities - */ void set_soft_button_capabilities( const smart_objects::SmartObject& soft_button_capabilities) OVERRIDE; - /* - * @brief Retrieves information about the Button's capabilities - * - * @return Currently supported Button's capabilities - */ const smart_objects::SmartObjectSPtr button_capabilities() const OVERRIDE; - /* - * @brief Sets supported Button's capabilities - * - * @param soft_button_capabilities supported Button's capabilities - */ void set_button_capabilities( const smart_objects::SmartObject& button_capabilities) OVERRIDE; - /* - * @brief Sets supported speech capabilities - * - * @param speech_capabilities supported speech capabilities - */ void set_speech_capabilities( const smart_objects::SmartObject& speech_capabilities) OVERRIDE; - /* - * @brief Retrieves information about the speech capabilities - * - * @return Currently supported speech capabilities - */ const smart_objects::SmartObjectSPtr speech_capabilities() const OVERRIDE; - /* - * @brief Sets supported VR capabilities - * - * @param vr_capabilities supported VR capabilities - */ void set_vr_capabilities( const smart_objects::SmartObject& vr_capabilities) OVERRIDE; - /* - * @brief Retrieves information about the VR capabilities - * - * @return Currently supported VR capabilities - */ const smart_objects::SmartObjectSPtr vr_capabilities() const OVERRIDE; - /* - * @brief Sets supported audio_pass_thru capabilities - * - * @param vr_capabilities supported audio_pass_thru capabilities - */ void set_audio_pass_thru_capabilities( const smart_objects::SmartObject& audio_pass_thru_capabilities) OVERRIDE; - /* - * @brief Retrieves information about the audio_pass_thru capabilities - * - * @return Currently supported audio_pass_thru capabilities - */ const smart_objects::SmartObjectSPtr audio_pass_thru_capabilities() const OVERRIDE; - /* - * @brief Sets supported pcm_stream capabilities - * - * @param supported pcm_stream capabilities - */ void set_pcm_stream_capabilities( const smart_objects::SmartObject& pcm_stream_capabilities) OVERRIDE; - /* - * @brief Retrieves information about the pcm_stream capabilities - * - * @return Currently supported pcm_streaming capabilities - */ const smart_objects::SmartObjectSPtr pcm_stream_capabilities() const OVERRIDE; - /* - * @brief Retrieves information about the preset bank capabilities - * - * @return Currently supported preset bank capabilities - */ const smart_objects::SmartObjectSPtr preset_bank_capabilities() const OVERRIDE; - /* - * @brief Sets supported preset bank capabilities - * - * @param soft_button_capabilities supported preset bank capabilities - */ void set_preset_bank_capabilities( const smart_objects::SmartObject& preset_bank_capabilities) OVERRIDE; - /* - * @brief Sets vehicle information(make, model, modelYear) - * - * @param vehicle_type Cuurent vehicle information - */ void set_vehicle_type( const smart_objects::SmartObject& vehicle_type) OVERRIDE; - /* - * @brief Retrieves vehicle information(make, model, modelYear) - * - * @param vehicle_type Cuurent vehicle information - */ const smart_objects::SmartObjectSPtr vehicle_type() const OVERRIDE; - /* - * @brief Retrieves information about the prerecorded speech - * - * @return Currently supported prerecorded speech - */ const smart_objects::SmartObjectSPtr prerecorded_speech() const OVERRIDE; - /* - * @brief Sets supported prerecorded speech - * - * @param prerecorded_speech supported prerecorded speech - */ void set_prerecorded_speech( const smart_objects::SmartObject& prerecorded_speech) OVERRIDE; - /* - * @brief Interface used to store information if navigation - * supported by the system - * - * @param supported Indicates if navigation supported by the system - */ void set_navigation_supported(const bool supported) OVERRIDE; - /* - * @brief Retrieves information if navi supported by the system - * - * @return TRUE if it supported, otherwise FALSE - */ bool navigation_supported() const OVERRIDE; - /* - * @brief Interface used to store information if phone call - * supported by the system - * - * @param supported Indicates if navigation supported by the sustem - */ void set_phone_call_supported(const bool supported) OVERRIDE; - /* - * @brief Retrieves information if phone call supported by the system - * - * @return TRUE if it supported, otherwise FALSE - */ bool phone_call_supported() const OVERRIDE; - /* - * @brief Interface to store whether HMI supports video streaming - * - * @param supported Indicates whether video streaming is supported by HMI - */ void set_video_streaming_supported(const bool supported) OVERRIDE; - /* - * @brief Retrieves whether HMI supports video streaming - * - * @return TRUE if it supported, otherwise FALSE - */ bool video_streaming_supported() const OVERRIDE; - /* - * @brief Interface to store whether HMI supports remote control - * - * @param supported Indicates whether video streaming is supported by HMI - */ void set_rc_supported(const bool supported) OVERRIDE; - /* - * @brief Retrieves whether HMI supports remote control - * - * @return TRUE if it supported, otherwise FALSE - */ bool rc_supported() const OVERRIDE; - /* - * @brief Interface used to store information regarding - * the navigation "System Capability" - * - * @param navigation_capability contains information related - * to the navigation system capability. - */ void set_navigation_capability( const smart_objects::SmartObject& navigation_capability) OVERRIDE; - /* - * @brief Retrieves information regarding the navigation system capability - * - * @return NAVIGATION system capability - */ - const smart_objects::SmartObject* navigation_capability() const OVERRIDE; + const smart_objects::SmartObjectSPtr navigation_capability() const OVERRIDE; - /* - * @brief Interface used to store information regarding - * the phone "System Capability" - * - * @param phone_capability contains information related - * to the phone system capability. - */ void set_phone_capability( const smart_objects::SmartObject& phone_capability) OVERRIDE; - /* - * @brief Retrieves information regarding the phone call system capability - * - * @return PHONE_CALL system capability - */ + const smart_objects::SmartObjectSPtr phone_capability() const OVERRIDE; - const smart_objects::SmartObject* phone_capability() const OVERRIDE; - - /* - * @brief Sets HMI's video streaming related capability information - * - * @param video_streaming_capability the video streaming related capabilities - */ void set_video_streaming_capability( const smart_objects::SmartObject& video_streaming_capability) OVERRIDE; - /* - * @brief Retrieves HMI's video streaming related capabilities - * - * @return HMI's video streaming related capability information - */ - const smart_objects::SmartObject* video_streaming_capability() const OVERRIDE; + const smart_objects::SmartObjectSPtr video_streaming_capability() + const OVERRIDE; void set_rc_capability( const smart_objects::SmartObject& rc_capability) OVERRIDE; - const smart_objects::SmartObject* rc_capability() const OVERRIDE; + const smart_objects::SmartObjectSPtr rc_capability() const OVERRIDE; void set_seat_location_capability( const smart_objects::SmartObject& seat_location_capability) OVERRIDE; - const smart_objects::SmartObject* seat_location_capability() const OVERRIDE; + const smart_objects::SmartObjectSPtr seat_location_capability() + const OVERRIDE; void Init(resumption::LastStateWrapperPtr last_state_wrapper) OVERRIDE; DEPRECATED void Init(resumption::LastState* last_state) OVERRIDE; - /* - * @brief return component which follows for correctness of - * languages - * @return HMI language handler - */ HMILanguageHandler& get_hmi_language_handler() OVERRIDE; - /** - * @brief Trigger waiting for response - * @param request Request object - */ void set_handle_response_for( const smart_objects::SmartObject& request) OVERRIDE; + bool SaveCachedCapabilitiesToFile( + const std::string& interface_name, + const std::vector<std::string>& sections_to_update, + const smart_objects::CSmartSchema& schema) OVERRIDE; + + bool DeleteCachedCapabilitiesFile() const OVERRIDE; + + bool IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::eType function_id) const OVERRIDE; + + void UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::eType requested_interface) OVERRIDE; + + void OnSoftwareVersionReceived(const std::string& ccpu_version) OVERRIDE; + + void UpdateCachedCapabilities() OVERRIDE; + protected: - /* + /** * @brief Loads capabilities from local file in case SDL was launched * without HMI * * @return TRUE if capabilities loaded successfully, otherwise FALSE. */ - bool load_capabilities_from_file(); - - /* - * @brief function checks if json member exists - * - * @param json_member from file hmi_capabilities.json - * @param name_of_member name which we should check - * hmi_capabilities.json - * - * @returns TRUE if member exists and returns FALSE if - * member does not exist. - */ - bool check_existing_json_member(const Json::Value& json_member, - const char* name_of_member) const OVERRIDE; + bool LoadCapabilitiesFromFile(); - /* + /** * @brief function converts json object "languages" to smart object - * * @param json_languages from file hmi_capabilities.json * @param languages - the converted object * */ void convert_json_languages_to_obj( const Json::Value& json_languages, - smart_objects::SmartObject& languages) const OVERRIDE; + smart_objects::SmartObject& languages) const; - /* + /** * @brief function that converts a single entry of audio pass thru capability * to smart object - * * @param capability json object that represents a single entry of audio pass * thru capability * @param output_so the converted object */ void convert_audio_capability_to_obj( const Json::Value& capability, - smart_objects::SmartObject& output_so) const OVERRIDE; + smart_objects::SmartObject& output_so) const; private: + /** + * @brief Checks are all updating fields are currently saved in the JSON + * structure + * @param root_node reference to root node of JSON structure + * @param interface_name name of interface to check + * @param sections_to_check reference to list of fields to check + * @return true if all fields from the list are saved in the JSON structure, + * otherwise returns false + */ + bool AllFieldsSaved(const Json::Value& root_node, + const std::string& interface_name, + const std::vector<std::string>& sections_to_check) const; + + /** + * @brief Remove received interface from default initialized capabilities + * @param requested_interface interface which should be removed + */ + void RemoveFromRequestsRequiredForCapabilities( + hmi_apis::FunctionID::eType requested_interface); + + /** + * @brief Gets the currently active language depending on interface + * @param interface_name name of interface of currently active language + * @return active language for specified interface + * + */ + hmi_apis::Common_Language::eType GetActiveLanguageForInterface( + const std::string& interface_name) const; + + /** + * @brief Prepares specified JSON structure according to sections which + * should be updated + * @param interface_name name of interface to prepare + * @param sections_to_update reference to list of fields to update + * @param schema reference to schema which should be unapplied before field + * updating + * @param out_root_node reference to JSON structure to update + */ + void PrepareJsonValueForSaving( + const char* interface_name, + const std::vector<std::string>& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_root_node) const; + + /** + * @brief Prepares specified JSON structure for UI interface according to + * sections which should be updated + * @param sections_to_update reference to list of fields to update + * @param schema reference to schema which should be unapplied before field + * updating + * @param out_node reference to JSON structure to update + */ + void PrepareUiJsonValueForSaving( + const std::vector<std::string>& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const; + + /** + * @brief Prepares specified JSON structure for VR interface according to + * sections which should be updated + * @param sections_to_update reference to list of fields to update + * @param schema reference to schema which should be unapplied before field + * updating + * @param out_node reference to JSON structure to update + */ + void PrepareVrJsonValueForSaving( + const std::vector<std::string>& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const; + + /** + * @brief Prepares specified JSON structure for TTS interface according to + * sections which should be updated + * @param sections_to_update reference to list of fields to update + * @param schema reference to schema which should be unapplied before field + * updating + * @param out_node reference to JSON structure to update + */ + void PrepareTtsJsonValueForSaving( + const std::vector<std::string>& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const; + + /** + * @brief Prepares specified JSON structure for Buttons interface according to + * sections which should be updated + * @param sections_to_update reference to list of fields to update + * @param schema reference to schema which should be unapplied before field + * updating + * @param out_node reference to JSON structure to update + */ + void PrepareButtonsJsonValueForSaving( + const std::vector<std::string>& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const; + + /** + * @brief Prepares specified JSON structure for VehicleInfo interface + * according to sections which should be updated + * @param sections_to_update reference to list of fields to update + * @param schema reference to schema which should be unapplied before field + * updating + * @param out_node reference to JSON structure to update + */ + void PrepareVehicleInfoJsonValueForSaving( + const std::vector<std::string>& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const; + + /** + * @brief Prepares specified JSON structure for RC interface according to + * sections which should be updated + * @param sections_to_update reference to list of fields to update + * @param schema reference to schema which should be unapplied before field + * updating + * @param out_node reference to JSON structure to update + */ + void PrepareRCJsonValueForSaving( + const std::vector<std::string>& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const; + + /** + * @brief Adds appropriate request IDs to the requested required collection + * according to an interface name + * @param interface_name An interface name which requests required to send to + * the HMI + */ + void AddRequiredRequestsForCapabilities(const std::string& interface_name); + bool is_vr_cooperating_; bool is_tts_cooperating_; bool is_ui_cooperating_; @@ -587,9 +421,9 @@ class HMICapabilitiesImpl : public HMICapabilities { hmi_apis::Common_Language::eType vr_language_; hmi_apis::Common_Language::eType tts_language_; smart_objects::SmartObjectSPtr vehicle_type_; - smart_objects::SmartObject* ui_supported_languages_; - smart_objects::SmartObject* tts_supported_languages_; - smart_objects::SmartObject* vr_supported_languages_; + smart_objects::SmartObjectSPtr ui_supported_languages_; + smart_objects::SmartObjectSPtr tts_supported_languages_; + smart_objects::SmartObjectSPtr vr_supported_languages_; /* * display_capabilities_ is deprecated and replaced by * system_display_capabilities_. For backward compatibility @@ -611,15 +445,17 @@ class HMICapabilitiesImpl : public HMICapabilities { bool is_video_streaming_supported_; bool is_rc_supported_; std::string ccpu_version_; - smart_objects::SmartObject* navigation_capability_; - smart_objects::SmartObject* phone_capability_; - smart_objects::SmartObject* video_streaming_capability_; - smart_objects::SmartObject* rc_capability_; - smart_objects::SmartObject* seat_location_capability_; + smart_objects::SmartObjectSPtr navigation_capability_; + smart_objects::SmartObjectSPtr phone_capability_; + smart_objects::SmartObjectSPtr video_streaming_capability_; + smart_objects::SmartObjectSPtr rc_capability_; + smart_objects::SmartObjectSPtr seat_location_capability_; ApplicationManager& app_mngr_; HMILanguageHandler hmi_language_handler_; + std::set<hmi_apis::FunctionID::eType> requests_required_for_capabilities_; + DISALLOW_COPY_AND_ASSIGN(HMICapabilitiesImpl); }; 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 5d95a2468d..09d225a120 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -491,9 +491,23 @@ class MessageHelper { * @brief Send notification for Update of Policy Table * with PT Snapshot. * @param connection_key Id of application to send message to + * @param snapshot_file_path path to PT Snapshot + * @param url If empty string, no URL is provided + * @param timeout If -1 no timeout is provided + */ + static void SendPolicySnapshotNotification( + uint32_t connection_key, + const std::string& snapshot_file_path, + const std::string& url, + ApplicationManager& app_mngr); + + /* + * @brief Send notification for Update of Policy Table + * with PT Snapshot. + * @param connection_key Id of application to send message to * @param policy_data PT Snapshot * @param url If empty string, no URL is provided - * @param timeout If -1 no timeout is provdied + * @param timeout If -1 no timeout is provided */ static void SendPolicySnapshotNotification( uint32_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 eaba6fd5fc..2f50fd4a6b 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 @@ -86,8 +86,8 @@ class PolicyHandler : public PolicyHandlerInterface, bool InitPolicyTable() OVERRIDE; bool ResetPolicyTable() OVERRIDE; bool ClearUserConsent() OVERRIDE; - bool SendMessageToSDK(const BinaryMessage& pt_string, - const std::string& url) OVERRIDE; + DEPRECATED bool SendMessageToSDK(const BinaryMessage& pt_string, + const std::string& url) OVERRIDE; bool ReceiveMessageFromSDK(const std::string& file, const BinaryMessage& pt_string) OVERRIDE; bool UnloadPolicyLibrary() OVERRIDE; @@ -110,6 +110,8 @@ class PolicyHandler : public PolicyHandlerInterface, #else // EXTERNAL_PROPRIETARY_MODE void OnSnapshotCreated(const BinaryMessage& pt_string, const PTUIterationType iteration_type) OVERRIDE; + std::string GetNextUpdateUrl(const PTUIterationType iteration_type, + uint32_t& app_id) OVERRIDE; #endif // EXTERNAL_PROPRIETARY_MODE virtual bool GetPriority(const std::string& policy_app_id, std::string* priority) const OVERRIDE; @@ -201,10 +203,11 @@ class PolicyHandler : public PolicyHandlerInterface, StringArray* nicknames = NULL, StringArray* app_hmi_types = NULL) OVERRIDE; void GetUpdateUrls(const std::string& service_type, - EndpointUrls& out_end_points) OVERRIDE; + EndpointUrls& out_end_points) const OVERRIDE; void GetUpdateUrls(const uint32_t service_type, - EndpointUrls& out_end_points) OVERRIDE; - virtual std::string GetLockScreenIconUrl() const OVERRIDE; + EndpointUrls& out_end_points) const OVERRIDE; + virtual std::string GetLockScreenIconUrl( + const std::string& policy_app_id = kDefaultId) const OVERRIDE; virtual std::string GetIconUrl( const std::string& policy_app_id) const OVERRIDE; uint32_t NextRetryTimeout() OVERRIDE; @@ -221,7 +224,6 @@ class PolicyHandler : public PolicyHandlerInterface, */ uint32_t TimeoutExchangeMSec() const OVERRIDE; void OnExceededTimeout() OVERRIDE; - void OnSystemReady() OVERRIDE; const boost::optional<bool> LockScreenDismissalEnabledState() const OVERRIDE; const boost::optional<std::string> LockScreenDismissalWarningMessage( const std::string& language) const OVERRIDE; @@ -322,6 +324,8 @@ class PolicyHandler : public PolicyHandlerInterface, void OnSystemRequestReceived() const OVERRIDE; + void TriggerPTUOnStartupIfRequired() OVERRIDE; + /** * @brief Get appropriate message parameters and send them with response * to HMI @@ -381,10 +385,9 @@ class PolicyHandler : public PolicyHandlerInterface, const std::string& wers_country_code, const std::string& language) OVERRIDE; - /** - * @brief Send request to HMI to get update on system parameters - */ - virtual void OnSystemInfoUpdateRequired() OVERRIDE; + void SetPreloadedPtFlag(const bool is_preloaded) OVERRIDE; + + std::string GetCCPUVersionFromPT() const OVERRIDE; /** * @brief Sends GetVehicleData request in case when Vechicle info is ready. @@ -416,11 +419,15 @@ class PolicyHandler : public PolicyHandlerInterface, */ void OnSystemError(int code) OVERRIDE; - /** - * @brief Chooses random application id to be used for snapshot sending - * considering HMI level - * @return Application id or 0, if there are no suitable applications - */ +#ifndef EXTERNAL_PROPRIETARY_MODE + uint32_t ChoosePTUApplication( + const PTUIterationType iteration_type = + PTUIterationType::DefaultIteration) OVERRIDE; + void CacheRetryInfo(const uint32_t app_id = 0, + const std::string url = std::string(), + const std::string snapshot_path = std::string()) OVERRIDE; +#endif // EXTERNAL_PROPRIETARY_MODE + uint32_t GetAppIdForSending() const OVERRIDE; /** @@ -882,6 +889,10 @@ class PolicyHandler : public PolicyHandlerInterface, private: static const std::string kLibrary; + bool SendMessageToSDK(const BinaryMessage& pt_string, + const std::string& url, + const uint32_t app_id); + /** * @brief Collects currently registered applications ids linked to their * device id @@ -894,6 +905,13 @@ class PolicyHandler : public PolicyHandlerInterface, std::shared_ptr<PolicyEventObserver> event_observer_; uint32_t last_activated_app_id_; +#ifndef EXTERNAL_PROPRIETARY_MODE + // PTU retry information + uint32_t last_ptu_app_id_; + std::string retry_update_url_; + std::string policy_snapshot_path_; +#endif // EXTERNAL_PROPRIETARY_MODE + /** * @brief Contains device handles, which were sent for user consent to HMI */ @@ -924,15 +942,16 @@ class PolicyHandler : public PolicyHandlerInterface, friend class AppPermissionDelegate; /** - * @brief Checks if the application with the given policy - * application id is registered or it is default id - * @param app_idx Application idx from EndpointUrls vector - * @param urls EndpointUrls vector + * @brief Checks if an application is able to perform a PTU using the + * specified URL list + * @param app_id ID of application used for PTU + * @param app_data EndpointData struct with list of URLs * @return TRUE if the vector with URLs with given idx is not empty - * and is related to a registered application or these are default URLs, + * and is related to the provided application or if these are default URLs, * otherwise FALSE */ - bool IsUrlAppIdValid(const uint32_t app_idx, const EndpointUrls& urls) const; + bool IsUrlAppIdValid(const std::string app_id, + const EndpointData& app_data) const; DISALLOW_COPY_AND_ASSIGN(PolicyHandler); }; diff --git a/src/components/application_manager/include/application_manager/rpc_handler_impl.h b/src/components/application_manager/include/application_manager/rpc_handler_impl.h index 11ac1745ee..ab140dbd8a 100644 --- a/src/components/application_manager/include/application_manager/rpc_handler_impl.h +++ b/src/components/application_manager/include/application_manager/rpc_handler_impl.h @@ -176,6 +176,7 @@ class RPCHandlerImpl : public RPCHandler, bool ConvertMessageToSO(const Message& message, smart_objects::SmartObject& output, + std::string& out_warning_info, const bool allow_unknown_parameters = false, const bool validate_params = true); std::shared_ptr<Message> ConvertRawMsgToMessage( diff --git a/src/components/application_manager/include/application_manager/rpc_service_impl.h b/src/components/application_manager/include/application_manager/rpc_service_impl.h index 3e3d83a519..a535198ca1 100644 --- a/src/components/application_manager/include/application_manager/rpc_service_impl.h +++ b/src/components/application_manager/include/application_manager/rpc_service_impl.h @@ -122,9 +122,15 @@ class RPCServiceImpl : public RPCService, bool ManageMobileCommand(const commands::MessageSharedPtr message, commands::Command::CommandSource source) OVERRIDE; + bool ManageMobileCommand(const commands::MessageSharedPtr message, + commands::Command::CommandSource source, + const std::string warning_info) OVERRIDE; bool ManageHMICommand(const commands::MessageSharedPtr message, commands::Command::CommandSource source = commands::Command::SOURCE_HMI) OVERRIDE; + bool ManageHMICommand(const commands::MessageSharedPtr message, + commands::Command::CommandSource source, + const std::string warning_info) OVERRIDE; // CALLED ON messages_to_hmi_ thread! void Handle(const impl::MessageToHmi message) OVERRIDE; 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 19dd6fbe3b..74cf37513b 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 @@ -479,6 +479,19 @@ extern const char* const x; extern const char* const y; } // namespace strings +namespace hmi_interface { +extern const char* basic_communication; +extern const char* buttons; +extern const char* navigation; +extern const char* sdl; +extern const char* tts; +extern const char* ui; +extern const char* vr; +extern const char* rc; +extern const char* vehicle_info; +extern const char* app_service; +} // namespace hmi_interface + namespace json { extern const char* appId; extern const char* name; @@ -590,6 +603,7 @@ extern const char* capabilities; extern const char* speech_capabilities; extern const char* prerecorded_speech_capabilities; extern const char* preset_bank_capabilities; +extern const char* on_screen_presets_available; extern const char* allowed; extern const char* vehicle_type; extern const char* did_result; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_capabilities_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_capabilities_manager.h index 36fd8bbbf9..743cf69a28 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_capabilities_manager.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_capabilities_manager.h @@ -37,7 +37,13 @@ namespace rc_rpc_plugin { -enum capabilitiesStatus { success, missedLightName, missedParam, readOnly }; +enum capabilitiesStatus { + kInvalidStatus, + kSuccess, + kMissedLightName, + kMissedParam, + kReadOnly +}; typedef std::pair<std::string, capabilitiesStatus> ModuleTypeCapability; class RCCapabilitiesManager { diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h index 5ee2e0725c..6625641f54 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h @@ -65,8 +65,6 @@ const char kGrid[] = "grid"; const char kAllowMultipleAccess[] = "allowMultipleAccess"; -const char kSupportedLights[] = "supportedLights"; - // ClimateControlCapabilities const char kFanSpeedAvailable[] = "fanSpeedAvailable"; const char kCurrentTemperatureAvailable[] = "currentTemperatureAvailable"; @@ -88,6 +86,7 @@ const char kName[] = "name"; const char kStatusAvailable[] = "statusAvailable"; const char kDensityAvailable[] = "densityAvailable"; const char kRGBColorSpaceAvailable[] = "rgbColorSpaceAvailable"; +const char kSupportedLights[] = "supportedLights"; // RadioControlCapabilities const char kRadioBandAvailable[] = "radioBandAvailable"; @@ -100,6 +99,7 @@ const char kSignalChangeThresholdAvailable[] = "signalChangeThresholdAvailable"; const char kRadioEnableAvailable[] = "radioEnableAvailable"; const char kStateAvailable[] = "stateAvailable"; const char kSisDataAvailable[] = "sisDataAvailable"; +const char kHdChannelAvailable[] = "hdChannelAvailable"; const char kSiriusxmRadioAvailable[] = "siriusxmRadioAvailable"; @@ -128,6 +128,7 @@ const char kSourceAvailable[] = "sourceAvailable"; const char kKeepContextAvailable[] = "keepContextAvailable"; const char kVolumeAvailable[] = "volumeAvailable"; const char kEqualizerAvailable[] = "equalizerAvailable"; +const char kEqualizerMaxChannelId[] = "equalizerMaxChannelId"; // HmiSettingsCapabilities const char kDistanceUnitAvailable[] = "distanceUnitAvailable"; @@ -358,6 +359,7 @@ const char kNotFound[] = "NOT_FOUND"; const char kFront[] = "FRONT"; const char kRear[] = "REAR"; const char kAll[] = "ALL"; +const char kNone[] = "NONE"; // DefrostZone enum // TemperatureUnit enum @@ -387,8 +389,9 @@ const char kRepeat[] = "REPEAT"; // ButtonName enum // ButtonPressMode enum -const char kLong[] = "LONG"; -const char kShort[] = "SHORT"; +const char kShortPressAvailable[] = "shortPressAvailable"; +const char kLongPressAvailable[] = "longPressAvailable"; +const char kUpDownAvailable[] = "upDownAvailable"; // ButtonPressMode enum // Access mode enum diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_request.cc index 10f6303ac9..e89b260dca 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/get_interior_vehicle_data_request.cc @@ -54,13 +54,12 @@ GetInteriorVehicleDataRequest::GetInteriorVehicleDataRequest( bool GetInteriorVehicleDataRequest::ProcessCapabilities() { LOG4CXX_AUTO_TRACE(logger_); - const smart_objects::SmartObject* rc_capabilities = - hmi_capabilities_.rc_capability(); + const auto rc_capability = hmi_capabilities_.rc_capability(); const std::string module_type = ModuleType(); const std::string module_id = ModuleId(); const ModuleUid module(module_type, module_id); - if (rc_capabilities && + if (rc_capability && !rc_capabilities_manager_.CheckIfModuleExistsInCapabilities(module)) { LOG4CXX_WARN( logger_, diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/release_interior_vehicle_data_module_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/release_interior_vehicle_data_module_request.cc index e30d7869bd..375db9cd9d 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/release_interior_vehicle_data_module_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/release_interior_vehicle_data_module_request.cc @@ -91,13 +91,12 @@ ReleaseInteriorVehicleDataModuleRequest:: bool ReleaseInteriorVehicleDataModuleRequest::ProcessCapabilities() { LOG4CXX_AUTO_TRACE(logger_); - const smart_objects::SmartObject* rc_capabilities = - hmi_capabilities_.rc_capability(); + const auto rc_capability = hmi_capabilities_.rc_capability(); const std::string module_type = ModuleType(); const std::string module_id = ModuleId(); const ModuleUid module(module_type, module_id); - if (rc_capabilities && + if (rc_capability && !rc_capabilities_manager_.CheckIfModuleExistsInCapabilities(module)) { LOG4CXX_WARN( logger_, diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc index c3e5e807d7..dfcc6205b1 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc @@ -84,22 +84,24 @@ mobile_apis::Result::eType PrepareResultCodeAndInfo( mobile_apis::Result::UNSUPPORTED_RESOURCE; if (message_params::kLightState == module_data_capabilities.first) { switch (module_data_capabilities.second) { - case capabilitiesStatus::missedLightName: + case capabilitiesStatus::kMissedLightName: info = "The requested LightName is not supported by the vehicle."; break; - case capabilitiesStatus::missedParam: + case capabilitiesStatus::kMissedParam: info = "The requested parameter of the given LightName is not supported " "by the vehicle."; break; - case capabilitiesStatus::readOnly: + case capabilitiesStatus::kReadOnly: info = "The requested parameter is read-only."; result_code = mobile_apis::Result::READ_ONLY; break; default: break; } - + } else if (module_data_capabilities.second == + capabilitiesStatus::kInvalidStatus) { + info = "The RC Capability is not available"; } else { info = "Accessing not supported module data."; } @@ -133,7 +135,7 @@ void SetInteriorVehicleDataRequest::Execute() { rc_capabilities_manager_.GetModuleDataCapabilities(module_data, module_id); - if (capabilitiesStatus::success != module_data_capabilities.second) { + if (capabilitiesStatus::kSuccess != module_data_capabilities.second) { SetResourceState(ModuleType(), ResourceState::FREE); std::string info; mobile_apis::Result::eType result = @@ -152,14 +154,14 @@ void SetInteriorVehicleDataRequest::Execute() { return; } - module_data_capabilities = std::make_pair("", capabilitiesStatus::success); + module_data_capabilities = std::make_pair("", capabilitiesStatus::kSuccess); if (rc_capabilities_manager_.AreReadOnlyParamsPresent( module_data, module_type, module_data_capabilities)) { LOG4CXX_DEBUG(logger_, "Request module type has READ ONLY parameters"); if (enums_value::kLight == module_data_capabilities.first && - capabilitiesStatus::success != module_data_capabilities.second) { + capabilitiesStatus::kSuccess != module_data_capabilities.second) { SetResourceState(ModuleType(), ResourceState::FREE); SendResponse( false, diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc index 885c5ac0dd..fc342a6d86 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc @@ -157,8 +157,8 @@ void RCCommandRequest::Run() { "Remote control is disabled by user"); return; } - auto rc_capabilities = hmi_capabilities_.rc_capability(); - if (!rc_capabilities || rc_capabilities->empty()) { + auto rc_capability = hmi_capabilities_.rc_capability(); + if (!rc_capability || rc_capability->empty()) { LOG4CXX_WARN(logger_, "Accessing not supported module: " << ModuleType()); SetResourceState(ModuleType(), ResourceState::FREE); SendResponse(false, diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_capabilities_manager_impl.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_capabilities_manager_impl.cc index dbedd0167f..0f68769b38 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_capabilities_manager_impl.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_capabilities_manager_impl.cc @@ -92,7 +92,13 @@ RCCapabilitiesManagerImpl::GetDefaultModuleIdFromCapabilitiesArray( const std::string RCCapabilitiesManagerImpl::GetDefaultModuleIdFromCapabilities( const std::string& module_type) const { LOG4CXX_AUTO_TRACE(logger_); - auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + auto rc_capabilities_ptr = hmi_capabilities_.rc_capability(); + if (!rc_capabilities_ptr) { + LOG4CXX_WARN(logger_, "RC capability is not initialized"); + return std::string(); + } + + auto rc_capabilities = *rc_capabilities_ptr; const auto& mapping = RCHelpers::GetModuleTypeToCapabilitiesMapping(); if (!rc_capabilities.keyExists(mapping(module_type))) { LOG4CXX_WARN( @@ -165,7 +171,14 @@ const bool RCCapabilitiesManagerImpl::CheckModuleIdWithCapabilities( bool RCCapabilitiesManagerImpl::CheckIfModuleExistsInCapabilities( const ModuleUid& module) const { LOG4CXX_AUTO_TRACE(logger_); - auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + + auto rc_capabilities_ptr = hmi_capabilities_.rc_capability(); + if (!rc_capabilities_ptr) { + LOG4CXX_WARN(logger_, "RC capability is not initialized"); + return false; + } + + auto rc_capabilities = *rc_capabilities_ptr; const auto& mapping = RCHelpers::GetModuleTypeToCapabilitiesMapping(); const auto& resource_list = GetResources(); bool is_module_type_valid = false; @@ -252,7 +265,13 @@ void RCCapabilitiesManagerImpl::GetResourcesFromCapabilitiesArray( const std::vector<ModuleUid> RCCapabilitiesManagerImpl::GetResources() const { LOG4CXX_AUTO_TRACE(logger_); std::vector<ModuleUid> resources; - auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + auto rc_capabilities_ptr = hmi_capabilities_.rc_capability(); + if (!rc_capabilities_ptr) { + LOG4CXX_WARN(logger_, "RC capability is not initialized"); + return resources; + } + + auto rc_capabilities = *rc_capabilities_ptr; const auto& control_caps_list = GetCapabilitiesList(); for (const auto& capability_key : control_caps_list) { if (rc_capabilities.keyExists(capability_key)) { @@ -272,7 +291,14 @@ const std::vector<ModuleUid> RCCapabilitiesManagerImpl::GetResources() const { const std::string RCCapabilitiesManagerImpl::GetModuleIdForSeatLocation( const mobile_apis::SupportedSeat::eType id) const { LOG4CXX_AUTO_TRACE(logger_); - auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + + auto rc_capabilities_ptr = hmi_capabilities_.rc_capability(); + if (!rc_capabilities_ptr) { + LOG4CXX_WARN(logger_, "RC capability is not initialized."); + return std::string(); + } + + auto rc_capabilities = *rc_capabilities_ptr; const auto seat_capabilities = rc_capabilities[strings::kseatControlCapabilities]; if (seat_capabilities.length() > 0) { @@ -294,7 +320,13 @@ const std::string RCCapabilitiesManagerImpl::GetModuleIdForSeatLocation( bool RCCapabilitiesManagerImpl::CheckIfButtonExistInRCCaps( const mobile_apis::ButtonName::eType button) const { - auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + auto rc_capabilities_ptr = hmi_capabilities_.rc_capability(); + if (!rc_capabilities_ptr) { + LOG4CXX_WARN(logger_, "RC capability is not initialized"); + return false; + } + + auto rc_capabilities = *rc_capabilities_ptr; if (rc_capabilities.keyExists(strings::kbuttonCapabilities)) { const smart_objects::SmartObject& button_caps = rc_capabilities[strings::kbuttonCapabilities]; @@ -453,14 +485,20 @@ ModuleTypeCapability RCCapabilitiesManagerImpl::GetModuleDataCapabilities( const smart_objects::SmartObject& module_data, const std::string& module_id) const { LOG4CXX_AUTO_TRACE(logger_); - auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + auto rc_capabilities_ptr = hmi_capabilities_.rc_capability(); + if (!rc_capabilities_ptr) { + LOG4CXX_WARN(logger_, "RC capability is not initialized"); + return {std::string(), capabilitiesStatus::kInvalidStatus}; + } + + auto rc_capabilities = *rc_capabilities_ptr; const auto& all_module_types = RCHelpers::GetModuleTypesList(); const auto& get_module_data_key = RCHelpers::GetModuleTypeToDataMapping(); const auto& get_capabilities_key = RCHelpers::GetModuleTypeToCapabilitiesMapping(); ModuleTypeCapability module_data_capabilities = - std::make_pair("", capabilitiesStatus::missedParam); + std::make_pair("", capabilitiesStatus::kMissedParam); for (const auto& module_type : all_module_types) { const auto module_data_key = get_module_data_key(module_type); @@ -501,13 +539,13 @@ ModuleTypeCapability RCCapabilitiesManagerImpl::GetControlDataCapabilities( } if (message_params::kLightState == request_parameter) { ModuleTypeCapability light_capability = - std::make_pair("", capabilitiesStatus::success); + std::make_pair("", capabilitiesStatus::kSuccess); for (auto& light_data : *(control_data[request_parameter].asArray())) { light_capability = GetLightNameCapabilities( capabilities[strings::kSupportedLights], light_data); - if (capabilitiesStatus::success != light_capability.second) { + if (capabilitiesStatus::kSuccess != light_capability.second) { return light_capability; } } @@ -517,7 +555,7 @@ ModuleTypeCapability RCCapabilitiesManagerImpl::GetControlDataCapabilities( if (message_params::kBand == request_parameter) { ModuleTypeCapability radio_capability = GetRadioBandByCapabilities( capabilities, control_data[request_parameter]); - if (capabilitiesStatus::success != radio_capability.second) { + if (capabilitiesStatus::kSuccess != radio_capability.second) { return radio_capability; } } @@ -528,12 +566,12 @@ ModuleTypeCapability RCCapabilitiesManagerImpl::GetControlDataCapabilities( request_parameter, mobile_apis::Result::UNSUPPORTED_RESOURCE); - if (capabilitiesStatus::success != status_item_capability) { + if (capabilitiesStatus::kSuccess != status_item_capability) { return std::make_pair("", status_item_capability); } } - return std::make_pair("", capabilitiesStatus::success); + return std::make_pair("", capabilitiesStatus::kSuccess); } capabilitiesStatus RCCapabilitiesManagerImpl::GetItemCapability( @@ -547,7 +585,7 @@ capabilitiesStatus RCCapabilitiesManagerImpl::GetItemCapability( LOG4CXX_DEBUG( logger_, "Parameter " << request_parameter << " doesn't exist in capabilities."); - return capabilitiesStatus::missedParam; + return capabilitiesStatus::kMissedParam; } const std::string& caps_key = it->second; @@ -561,7 +599,7 @@ capabilitiesStatus RCCapabilitiesManagerImpl::GetItemCapability( LOG4CXX_DEBUG(logger_, "Capability " << caps_key << " is missed in RemoteControl capabilities"); - return capabilitiesStatus::missedParam; + return capabilitiesStatus::kMissedParam; } if (!capabilities[caps_key].asBool()) { @@ -569,14 +607,14 @@ capabilitiesStatus RCCapabilitiesManagerImpl::GetItemCapability( "Capability " << caps_key << " is switched off in RemoteControl capabilities"); - capabilitiesStatus status = capabilitiesStatus::missedParam; + capabilitiesStatus status = capabilitiesStatus::kMissedParam; if (mobile_apis::Result::READ_ONLY == switched_off_result) { - status = capabilitiesStatus::readOnly; + status = capabilitiesStatus::kReadOnly; } return status; } - return capabilitiesStatus::success; + return capabilitiesStatus::kSuccess; } ModuleTypeCapability RCCapabilitiesManagerImpl::GetLightDataCapabilities( @@ -598,13 +636,13 @@ ModuleTypeCapability RCCapabilitiesManagerImpl::GetLightDataCapabilities( request_parameter, mobile_apis::Result::READ_ONLY); - if (capabilitiesStatus::success != status_item_capability) { + if (capabilitiesStatus::kSuccess != status_item_capability) { return std::make_pair(message_params::kLightState, status_item_capability); } } - return std::make_pair("", capabilitiesStatus::success); + return std::make_pair("", capabilitiesStatus::kSuccess); } ModuleTypeCapability RCCapabilitiesManagerImpl::GetLightNameCapabilities( @@ -619,7 +657,7 @@ ModuleTypeCapability RCCapabilitiesManagerImpl::GetLightNameCapabilities( } LOG4CXX_DEBUG(logger_, "There is no such light name in capabilities"); return std::make_pair(message_params::kLightState, - capabilitiesStatus::missedLightName); + capabilitiesStatus::kMissedLightName); } ModuleTypeCapability RCCapabilitiesManagerImpl::GetRadioBandByCapabilities( @@ -634,7 +672,7 @@ ModuleTypeCapability RCCapabilitiesManagerImpl::GetRadioBandByCapabilities( << strings::kSiriusxmRadioAvailable << " is missed in RemoteControl capabilities"); return std::make_pair(strings::kSiriusxmRadioAvailable, - capabilitiesStatus::missedParam); + capabilitiesStatus::kMissedParam); } if (!capabilities_status[strings::kSiriusxmRadioAvailable].asBool()) { LOG4CXX_DEBUG(logger_, @@ -642,10 +680,10 @@ ModuleTypeCapability RCCapabilitiesManagerImpl::GetRadioBandByCapabilities( << strings::kSiriusxmRadioAvailable << " is switched off in RemoteControl capabilities"); return std::make_pair(strings::kSiriusxmRadioAvailable, - capabilitiesStatus::missedParam); + capabilitiesStatus::kMissedParam); } } - return std::make_pair("", capabilitiesStatus::success); + return std::make_pair("", capabilitiesStatus::kSuccess); } const smart_objects::SmartObject& RCCapabilitiesManagerImpl::ControlDataForType( @@ -729,7 +767,7 @@ bool RCCapabilitiesManagerImpl::AreReadOnlyParamsPresent( if (result) { module_data_capabilities = - std::make_pair(module_type, capabilitiesStatus::readOnly); + std::make_pair(module_type, capabilitiesStatus::kReadOnly); } return result; } @@ -869,7 +907,13 @@ Grid RCCapabilitiesManagerImpl::GetModuleServiceAreaFromControlCapability( Grid RCCapabilitiesManagerImpl::GetModuleServiceArea( const ModuleUid& module) const { - auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + auto rc_capabilities_ptr = hmi_capabilities_.rc_capability(); + if (!rc_capabilities_ptr) { + LOG4CXX_WARN(logger_, "RC capability is not initialized"); + return Grid(); + } + + auto rc_capabilities = *rc_capabilities_ptr; const auto& mapping = RCHelpers::GetModuleTypeToCapabilitiesMapping(); const auto& module_type = module.first; const auto& capabilities_key = mapping(module_type); @@ -903,7 +947,13 @@ bool RCCapabilitiesManagerImpl::IsMultipleAccessAllowedInControlCaps( bool RCCapabilitiesManagerImpl::IsMultipleAccessAllowed( const ModuleUid& module) const { - auto rc_capabilities = *(hmi_capabilities_.rc_capability()); + auto rc_capabilities_ptr = hmi_capabilities_.rc_capability(); + if (!rc_capabilities_ptr) { + LOG4CXX_ERROR(logger_, "RC capability is not initialized"); + return false; + } + + auto rc_capabilities = *rc_capabilities_ptr; const auto& mapping = RCHelpers::GetModuleTypeToCapabilitiesMapping(); const auto& module_type = module.first; const auto& capabilities_key = mapping(module_type); diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc index fb8de0bb9c..625b2d6312 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc @@ -79,14 +79,15 @@ class ButtonPressRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: ButtonPressRequestTest() - : rc_capabilities_(smart_objects::SmartType_Map) + : rc_capabilities_(std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Map)) , mock_app_(std::make_shared<NiceMock<MockApplication> >()) , rc_app_extention_( std::make_shared<rc_rpc_plugin::RCAppExtension>(kModuleId)) {} void SetUp() OVERRIDE { smart_objects::SmartObject control_caps((smart_objects::SmartType_Array)); - rc_capabilities_[strings::kradioControlCapabilities] = control_caps; + (*rc_capabilities_)[strings::kradioControlCapabilities] = control_caps; ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); ON_CALL(*mock_app_, QueryInterface(RCRPCPlugin::kRCPluginID)) .WillByDefault(Return(rc_app_extention_)); @@ -95,7 +96,7 @@ class ButtonPressRequestTest ON_CALL(app_mngr_, hmi_capabilities()) .WillByDefault(ReturnRef(mock_hmi_capabilities_)); ON_CALL(mock_hmi_capabilities_, rc_capability()) - .WillByDefault(Return(&rc_capabilities_)); + .WillByDefault(Return(rc_capabilities_)); ON_CALL(*mock_app_, policy_app_id()).WillByDefault(Return(kPolicyAppId)); ON_CALL(mock_policy_handler_, CheckHMIType(kPolicyAppId, @@ -140,7 +141,7 @@ class ButtonPressRequestTest } protected: - smart_objects::SmartObject rc_capabilities_; + smart_objects::SmartObjectSPtr rc_capabilities_; std::shared_ptr<MockApplication> mock_app_; std::shared_ptr<rc_rpc_plugin::RCAppExtension> rc_app_extention_; test::components::policy_test::MockPolicyHandlerInterface diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc index 532a62df3b..82b71f1be4 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc @@ -96,7 +96,8 @@ class GetInteriorVehicleDataRequestTest , rc_app_extention2_(std::make_shared<RCAppExtension>(kModuleId)) , apps_lock_(std::make_shared<sync_primitives::Lock>()) , apps_da_(apps_, apps_lock_) - , rc_capabilities_(smart_objects::SmartType::SmartType_Array) { + , rc_capabilities_(std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType::SmartType_Array)) { ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId)); ON_CALL(*mock_app2_, app_id()).WillByDefault(Return(kAppId2)); ON_CALL(*mock_app_, is_remote_control_supported()) @@ -131,7 +132,7 @@ class GetInteriorVehicleDataRequestTest frequency.first = max_request_in_time_frame; frequency.second = time_frame_of_allowed_requests; smart_objects::SmartObject control_caps((smart_objects::SmartType_Array)); - rc_capabilities_[strings::kradioControlCapabilities] = control_caps; + (*rc_capabilities_)[strings::kradioControlCapabilities] = control_caps; ON_CALL(app_mngr_, get_settings()) .WillByDefault(ReturnRef(app_mngr_settings_)); ON_CALL(app_mngr_settings_, get_interior_vehicle_data_frequency()) @@ -151,7 +152,7 @@ class GetInteriorVehicleDataRequestTest ON_CALL(app_mngr_, hmi_capabilities()) .WillByDefault(ReturnRef(mock_hmi_capabilities_)); ON_CALL(mock_hmi_capabilities_, rc_capability()) - .WillByDefault(Return(&rc_capabilities_)); + .WillByDefault(Return(rc_capabilities_)); ON_CALL(mock_policy_handler_, CheckHMIType( _, mobile_apis::AppHMIType::eType::REMOTE_CONTROL, nullptr)) @@ -195,7 +196,7 @@ class GetInteriorVehicleDataRequestTest DataAccessor<application_manager::ApplicationSet> apps_da_; testing::NiceMock<rc_rpc_plugin_test::MockRCCapabilitiesManager> mock_rc_capabilities_manager_; - smart_objects::SmartObject rc_capabilities_; + smart_objects::SmartObjectSPtr rc_capabilities_; testing::NiceMock<MockRCConsentManager> mock_rc_consent_manger_; }; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc index 55be43f37b..e5f96215eb 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc @@ -106,7 +106,8 @@ class RCGetInteriorVehicleDataConsentTest RCGetInteriorVehicleDataConsentTest() : mock_app_(std::make_shared<NiceMock<MockApplication> >()) , command_holder(app_mngr_) - , rc_capabilities_(smart_objects::SmartType::SmartType_Array) + , rc_capabilities_(std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType::SmartType_Array)) , request_controller(mock_request_controler) , rpc_protection_manager_( std::make_shared<application_manager::MockRPCProtectionManager>()) @@ -124,7 +125,7 @@ class RCGetInteriorVehicleDataConsentTest , rpc_plugin(mock_rpc_plugin) , optional_mock_rpc_plugin(mock_rpc_plugin) { smart_objects::SmartObject control_caps((smart_objects::SmartType_Array)); - rc_capabilities_[strings::kradioControlCapabilities] = control_caps; + (*rc_capabilities_)[strings::kradioControlCapabilities] = control_caps; ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId)); ON_CALL(app_mngr_, hmi_interfaces()) .WillByDefault(ReturnRef(mock_hmi_interfaces_)); @@ -143,7 +144,7 @@ class RCGetInteriorVehicleDataConsentTest ON_CALL(app_mngr_, hmi_capabilities()) .WillByDefault(ReturnRef(mock_hmi_capabilities_)); ON_CALL(mock_hmi_capabilities_, rc_capability()) - .WillByDefault(Return(&rc_capabilities_)); + .WillByDefault(Return(rc_capabilities_)); ON_CALL(mock_policy_handler_, CheckHMIType( _, mobile_apis::AppHMIType::eType::REMOTE_CONTROL, nullptr)) @@ -209,7 +210,7 @@ class RCGetInteriorVehicleDataConsentTest mock_interior_data_cache_; testing::NiceMock<rc_rpc_plugin_test::MockInteriorDataManager> mock_interior_data_manager_; - smart_objects::SmartObject rc_capabilities_; + smart_objects::SmartObjectSPtr rc_capabilities_; MockRPCPlugin mock_rpc_plugin; MockCommandFactory mock_command_factory; am::request_controller::RequestController request_controller; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/release_interior_vehicle_data_module_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/release_interior_vehicle_data_module_request_test.cc index 200e458c17..81e0fa87af 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/release_interior_vehicle_data_module_request_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/release_interior_vehicle_data_module_request_test.cc @@ -84,16 +84,10 @@ using namespace rc_rpc_plugin; class ReleaseInteriorVehicleDataModuleRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: - ReleaseInteriorVehicleDataModuleRequestTest() : mock_app_(CreateMockApp()) {} - - void SetUp() OVERRIDE { - TestPreCondition(); - ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app_)); - ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppID)); - ON_CALL(mock_rc_capabilities_manager_, - GetDefaultModuleIdFromCapabilities(kModuleType)) - .WillByDefault(Return(kDefaultModuleID)); - } + ReleaseInteriorVehicleDataModuleRequestTest() + : mock_app_(CreateMockApp()) + , rc_capabilities_(std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType::SmartType_Array)) {} MessageSharedPtr CreateBasicMessage() { MessageSharedPtr message = CreateMessage(); @@ -111,13 +105,6 @@ class ReleaseInteriorVehicleDataModuleRequestTest return message; } - void TestPreCondition() { - message_ = CreateBasicMessage(); - command_ = - CreateRCCommand<commands::ReleaseInteriorVehicleDataModuleRequest>( - message_); - } - template <class Command> std::shared_ptr<Command> CreateRCCommand(MessageSharedPtr& msg) { InitCommand(kDefaultTimeout_); @@ -134,6 +121,26 @@ class ReleaseInteriorVehicleDataModuleRequestTest } protected: + void SetUp() OVERRIDE { + TestPreCondition(); + ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppID)); + ON_CALL(mock_hmi_capabilities_, rc_capability()) + .WillByDefault(Return(rc_capabilities_)); + ON_CALL(mock_rc_capabilities_manager_, CheckIfModuleExistsInCapabilities(_)) + .WillByDefault(Return(true)); + ON_CALL(mock_rc_capabilities_manager_, + GetDefaultModuleIdFromCapabilities(kModuleType)) + .WillByDefault(Return(kDefaultModuleID)); + } + + void TestPreCondition() { + message_ = CreateBasicMessage(); + command_ = + CreateRCCommand<commands::ReleaseInteriorVehicleDataModuleRequest>( + message_); + } + MessageSharedPtr message_; ReleaseCommandPtr command_; @@ -143,6 +150,7 @@ class ReleaseInteriorVehicleDataModuleRequestTest MockInteriorDataManager mock_interior_data_manager_; NiceMock<MockRCCapabilitiesManager> mock_rc_capabilities_manager_; MockRCConsentManager mock_rc_consent_manger_; + smart_objects::SmartObjectSPtr rc_capabilities_; }; TEST_F(ReleaseInteriorVehicleDataModuleRequestTest, diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc index 5a822a2fe4..1e4da625b2 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc @@ -74,11 +74,12 @@ class SetInteriorVehicleDataRequestTest SetInteriorVehicleDataRequestTest() : mock_app_(std::make_shared<NiceMock<MockApplication> >()) , rc_app_extention_(std::make_shared<RCAppExtension>(kModuleId)) - , rc_capabilities_(smart_objects::SmartType::SmartType_Array) {} + , rc_capabilities_(std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType::SmartType_Array)) {} void SetUp() OVERRIDE { smart_objects::SmartObject control_caps((smart_objects::SmartType_Array)); - rc_capabilities_[strings::kradioControlCapabilities] = control_caps; + (*rc_capabilities_)[strings::kradioControlCapabilities] = control_caps; ON_CALL(app_mngr_, hmi_interfaces()) .WillByDefault(ReturnRef(mock_hmi_interfaces_)); ON_CALL( @@ -102,13 +103,14 @@ class SetInteriorVehicleDataRequestTest nullptr)) .WillByDefault(Return(true)); ON_CALL(mock_hmi_capabilities_, rc_capability()) - .WillByDefault(Return(&rc_capabilities_)); + .WillByDefault(Return(rc_capabilities_)); ON_CALL(mock_allocation_manager_, is_rc_enabled()) .WillByDefault(Return(true)); ON_CALL(mock_rc_capabilities_manager_, CheckIfModuleExistsInCapabilities(_)) .WillByDefault(Return(true)); ON_CALL(mock_rc_capabilities_manager_, GetModuleDataCapabilities(_, _)) - .WillByDefault(Return(std::make_pair("", capabilitiesStatus::success))); + .WillByDefault( + Return(std::make_pair("", capabilitiesStatus::kSuccess))); } MessageSharedPtr CreateBasicMessage() { @@ -149,7 +151,7 @@ class SetInteriorVehicleDataRequestTest std::shared_ptr<RCAppExtension> rc_app_extention_; testing::NiceMock<rc_rpc_plugin_test::MockRCCapabilitiesManager> mock_rc_capabilities_manager_; - smart_objects::SmartObject rc_capabilities_; + smart_objects::SmartObjectSPtr rc_capabilities_; testing::NiceMock<MockRCConsentManager> mock_rc_consent_manger_; }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/button_get_capabilities_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/button_get_capabilities_request.h index 9bb3d9a6fb..62be7e8836 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/button_get_capabilities_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/button_get_capabilities_request.h @@ -62,10 +62,9 @@ class ButtonGetCapabilitiesRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~ButtonGetCapabilitiesRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(ButtonGetCapabilitiesRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_system_info_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_system_info_request.h index 8d3be68539..0b82feb1c5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_system_info_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_system_info_request.h @@ -64,7 +64,12 @@ class GetSystemInfoRequest : public app_mngr::commands::RequestToHMI { /** * @brief Execute command **/ - virtual void Run(); + void Run() OVERRIDE; + + /** + * @brief onTimeOut from request controller + */ + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(GetSystemInfoRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_system_info_response.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_system_info_response.h index d4f35a4e2a..2d3c40c3f3 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_system_info_response.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/get_system_info_response.h @@ -74,8 +74,7 @@ class GetSystemInfoResponse : public app_mngr::commands::ResponseFromHMI { virtual void Run(); private: - const SystemInfo GetSystemInfo( - const hmi_apis::Common_Result::eType code) const; + const SystemInfo GetSystemInfo() const; DISALLOW_COPY_AND_ASSIGN(GetSystemInfoResponse); }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/rc_get_capabilities_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/rc_get_capabilities_request.h index 57a90955f4..6dd06f283d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/rc_get_capabilities_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/rc_get_capabilities_request.h @@ -61,10 +61,9 @@ class RCGetCapabilitiesRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~RCGetCapabilitiesRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(RCGetCapabilitiesRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/rc_is_ready_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/rc_is_ready_request.h index 305a866659..15b2e13867 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/rc_is_ready_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/rc_is_ready_request.h @@ -34,7 +34,6 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_RC_IS_READY_REQUEST_H_ #include "application_manager/commands/request_to_hmi.h" -#include "application_manager/message_helper.h" namespace sdl_rpc_plugin { namespace app_mngr = application_manager; @@ -78,11 +77,6 @@ class RCIsReadyRequest : public app_mngr::commands::RequestToHMI, */ void onTimeOut() OVERRIDE; - /** - * @brief Send request to HMI for fetching of cappabilities - */ - void SendMessageToHMI(); - private: DISALLOW_COPY_AND_ASSIGN(RCIsReadyRequest); }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_capabilities_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_capabilities_request.h index d636485915..4ddd6f25fc 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_capabilities_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_capabilities_request.h @@ -61,10 +61,9 @@ class TTSGetCapabilitiesRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~TTSGetCapabilitiesRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(TTSGetCapabilitiesRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_language_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_language_request.h index 73ef8c5234..b00fc9cffa 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_language_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_language_request.h @@ -61,10 +61,9 @@ class TTSGetLanguageRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~TTSGetLanguageRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(TTSGetLanguageRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_supported_languages_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_supported_languages_request.h index a24a6446b3..802a196c46 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_supported_languages_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_get_supported_languages_request.h @@ -63,10 +63,9 @@ class TTSGetSupportedLanguagesRequest **/ virtual ~TTSGetSupportedLanguagesRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(TTSGetSupportedLanguagesRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_is_ready_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_is_ready_request.h index dd360eeb4a..039df31972 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_is_ready_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/tts_is_ready_request.h @@ -35,6 +35,8 @@ #include "application_manager/commands/request_to_hmi.h" +#include <set> + namespace sdl_rpc_plugin { namespace app_mngr = application_manager; @@ -77,11 +79,6 @@ class TTSIsReadyRequest : public app_mngr::commands::RequestToHMI, */ void onTimeOut() OVERRIDE; - /** - * @brief Send request to HMI for fetching of cappabilities - */ - void SendMessageToHMI(); - private: DISALLOW_COPY_AND_ASSIGN(TTSIsReadyRequest); }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_capabilities_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_capabilities_request.h index 58d8d0f732..32e878e733 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_capabilities_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_capabilities_request.h @@ -61,10 +61,9 @@ class UIGetCapabilitiesRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~UIGetCapabilitiesRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(UIGetCapabilitiesRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_language_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_language_request.h index 842a97a717..d642beb341 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_language_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_language_request.h @@ -61,10 +61,9 @@ class UIGetLanguageRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~UIGetLanguageRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(UIGetLanguageRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_supported_languages_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_supported_languages_request.h index 42ea555358..9c2492b9fe 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_supported_languages_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_get_supported_languages_request.h @@ -62,10 +62,9 @@ class UIGetSupportedLanguagesRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~UIGetSupportedLanguagesRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(UIGetSupportedLanguagesRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_is_ready_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_is_ready_request.h index 18536032b7..9bcde383e0 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_is_ready_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/ui_is_ready_request.h @@ -35,6 +35,8 @@ #include "application_manager/commands/request_to_hmi.h" +#include <set> + namespace sdl_rpc_plugin { namespace app_mngr = application_manager; @@ -77,11 +79,6 @@ class UIIsReadyRequest : public app_mngr::commands::RequestToHMI, */ virtual void onTimeOut() OVERRIDE; - /** - * @brief Send request to HMI for fetching of cappabilities - */ - void SendMessageToHMI(); - private: DISALLOW_COPY_AND_ASSIGN(UIIsReadyRequest); }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_capabilities_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_capabilities_request.h index 254d00452f..7f8485ffa0 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_capabilities_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_capabilities_request.h @@ -61,10 +61,9 @@ class VRGetCapabilitiesRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~VRGetCapabilitiesRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(VRGetCapabilitiesRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_language_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_language_request.h index 441795cfb5..abcaa35726 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_language_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_language_request.h @@ -61,10 +61,9 @@ class VRGetLanguageRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~VRGetLanguageRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(VRGetLanguageRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_supported_languages_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_supported_languages_request.h index ad87415a87..fb6d05b0aa 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_supported_languages_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_get_supported_languages_request.h @@ -62,10 +62,9 @@ class VRGetSupportedLanguagesRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~VRGetSupportedLanguagesRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(VRGetSupportedLanguagesRequest); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_is_ready_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_is_ready_request.h index 2dba80065a..cbd77087b2 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_is_ready_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/vr_is_ready_request.h @@ -34,7 +34,8 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_VR_IS_READY_REQUEST_H_ #include "application_manager/commands/request_to_hmi.h" -#include "application_manager/message_helper.h" + +#include <set> namespace sdl_rpc_plugin { namespace app_mngr = application_manager; @@ -78,11 +79,6 @@ class VRIsReadyRequest : public app_mngr::commands::RequestToHMI, */ void onTimeOut() OVERRIDE; - /** - * @brief Send request to HMI for fetching of cappabilities - */ - void SendMessageToHMI(); - private: DISALLOW_COPY_AND_ASSIGN(VRIsReadyRequest); }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/button_get_capabilities_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/button_get_capabilities_request.cc index 6696689174..c0d22dcb89 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/button_get_capabilities_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/button_get_capabilities_request.cc @@ -58,6 +58,12 @@ void ButtonGetCapabilitiesRequest::Run() { SendRequest(); } +void ButtonGetCapabilitiesRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::Buttons_GetCapabilities); +} + } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/button_get_capabilities_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/button_get_capabilities_response.cc index b6ab822c47..cc3a61a9df 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/button_get_capabilities_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/button_get_capabilities_response.cc @@ -58,22 +58,32 @@ void ButtonGetCapabilitiesResponse::Run() { static_cast<hmi_apis::Common_Result::eType>( (*message_)[strings::params][hmi_response::code].asInt()); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::Buttons_GetCapabilities); + if (hmi_apis::Common_Result::SUCCESS != code) { LOG4CXX_ERROR(logger_, "Error is returned. Capabilities won't be updated."); return; } - HMICapabilities& hmi_capabilities = hmi_capabilities_; - - hmi_capabilities.set_button_capabilities( + std::vector<std::string> sections_to_update{ + hmi_response::button_capabilities}; + hmi_capabilities_.set_button_capabilities( (*message_)[strings::msg_params][hmi_response::capabilities]); if ((*message_)[strings::msg_params].keyExists( hmi_response::preset_bank_capabilities)) { - hmi_capabilities.set_preset_bank_capabilities( + sections_to_update.push_back(hmi_response::preset_bank_capabilities); + hmi_capabilities_.set_preset_bank_capabilities( (*message_)[strings::msg_params] [hmi_response::preset_bank_capabilities]); } + + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::buttons, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save Buttons.GetCapabilities response to cache"); + } } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_request.cc index 8546252119..7a505a46f3 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_request.cc @@ -59,6 +59,11 @@ void GetSystemInfoRequest::Run() { SendRequest(); } +void GetSystemInfoRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateCachedCapabilities(); +} + } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_response.cc index baff925a4e..7a7d015e21 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/get_system_info_response.cc @@ -53,38 +53,38 @@ GetSystemInfoResponse::~GetSystemInfoResponse() {} void GetSystemInfoResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); - const hmi_apis::Common_Result::eType code = - static_cast<hmi_apis::Common_Result::eType>( - (*message_)[strings::params][hmi_response::code].asInt()); + const auto code = static_cast<hmi_apis::Common_Result::eType>( + (*message_)[strings::params][hmi_response::code].asInt()); - const SystemInfo& info = GetSystemInfo(code); + hmi_capabilities_.set_ccpu_version(policy_handler_.GetCCPUVersionFromPT()); + + if (hmi_apis::Common_Result::SUCCESS != code) { + LOG4CXX_WARN(logger_, "GetSystemError returns an error code " << code); + hmi_capabilities_.UpdateCachedCapabilities(); + policy_handler_.SetPreloadedPtFlag(false); + return; + } + + const SystemInfo& info = GetSystemInfo(); - // We have to set preloaded flag as false in policy table on any response - // of GetSystemInfo (SDLAQ-CRS-2365) policy_handler_.OnGetSystemInfo( info.ccpu_version, info.wers_country_code, info.language); + + hmi_capabilities_.OnSoftwareVersionReceived(info.ccpu_version); } -const SystemInfo GetSystemInfoResponse::GetSystemInfo( - const hmi_apis::Common_Result::eType code) const { +const SystemInfo GetSystemInfoResponse::GetSystemInfo() const { SystemInfo info; - if (hmi_apis::Common_Result::SUCCESS != code) { - LOG4CXX_WARN(logger_, "GetSystemError returns an error code " << code); - return info; - } info.ccpu_version = (*message_)[strings::msg_params]["ccpu_version"].asString(); info.wers_country_code = (*message_)[strings::msg_params]["wersCountryCode"].asString(); - const uint32_t lang_code = - (*message_)[strings::msg_params]["language"].asUInt(); - info.language = application_manager::MessageHelper::CommonLanguageToString( - static_cast<hmi_apis::Common_Language::eType>(lang_code)); - - hmi_capabilities_.set_ccpu_version(info.ccpu_version); + const auto lang_code = static_cast<hmi_apis::Common_Language::eType>( + (*message_)[strings::msg_params]["language"].asUInt()); + info.language = MessageHelper::CommonLanguageToString(lang_code); return info; } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_audio_start_stream_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_audio_start_stream_request.cc index 060a2bda34..47f2f2505e 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_audio_start_stream_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_audio_start_stream_request.cc @@ -171,11 +171,11 @@ void AudioStartStreamRequest::RetryStartSession() { } uint32_t curr_retry_number = app->audio_stream_retry_number(); - LOG4CXX_DEBUG( - logger_, "Retry number " << curr_retry_number << " of " << retry_number_); - if (curr_retry_number < retry_number_) { - LOG4CXX_DEBUG(logger_, "Send AudioStartStream retry"); + if (curr_retry_number <= retry_number_) { + LOG4CXX_DEBUG( + logger_, + "Retry number " << curr_retry_number << " of " << retry_number_); MessageHelper::SendAudioStartStream(app->app_id(), application_manager_); app->set_audio_stream_retry_number(++curr_retry_number); } else { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_start_stream_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_start_stream_request.cc index 4228eb8859..00974085c3 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_start_stream_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_start_stream_request.cc @@ -173,11 +173,11 @@ void NaviStartStreamRequest::RetryStartSession() { } uint32_t curr_retry_number = app->video_stream_retry_number(); - LOG4CXX_DEBUG( - logger_, "Retry number " << curr_retry_number << " of " << retry_number_); - if (curr_retry_number < retry_number_) { - LOG4CXX_DEBUG(logger_, "Send NaviStartStream retry"); + if (curr_retry_number <= retry_number_) { + LOG4CXX_DEBUG( + logger_, + "Retry number " << curr_retry_number << " of " << retry_number_); MessageHelper::SendNaviStartStream(app->app_id(), application_manager_); app->set_video_stream_retry_number(++curr_retry_number); } else { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ready_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ready_notification.cc index da3612b043..c9270fd80b 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ready_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ready_notification.cc @@ -54,7 +54,7 @@ OnReadyNotification::~OnReadyNotification() {} void OnReadyNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); - application_manager_.OnHMIStartedCooperation(); + application_manager_.OnHMIReady(); event_engine::Event event(hmi_apis::FunctionID::BasicCommunication_OnReady); event.set_smart_object(*message_); event.raise(application_manager_.event_dispatcher()); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_request_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_request_notification.cc index e11eda165c..4f83e3e653 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_request_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_request_notification.cc @@ -71,6 +71,39 @@ void OnSystemRequestNotification::Run() { params[strings::function_id] = static_cast<int32_t>(mobile_apis::FunctionID::eType::OnSystemRequestID); + using namespace rpc::policy_table_interface_base; + const auto request_type = + static_cast<rpc::policy_table_interface_base::RequestType>( + (*message_)[strings::msg_params][strings::request_type].asUInt()); + +#ifdef PROPRIETARY_MODE + if (RequestType::RT_PROPRIETARY == request_type) { + if (msg_params.keyExists(strings::url)) { + // For backward-compatibility, the URL is cached for retries if provided + // by HMI + policy_handler_.CacheRetryInfo(msg_params.keyExists(strings::app_id) + ? msg_params[strings::app_id].asUInt() + : 0, + msg_params[strings::url].asString(), + msg_params[strings::file_name].asString()); + } else { + // Clear cached retry info + policy_handler_.CacheRetryInfo( + 0, std::string(), msg_params[strings::file_name].asString()); + + // URL and app are chosen by Core for PROPRIETARY mode normally + uint32_t app_id = 0; + msg_params[strings::url] = policy_handler_.GetNextUpdateUrl( + policy::PTUIterationType::DefaultIteration, app_id); + if (0 == app_id) { + LOG4CXX_WARN(logger_, + "Can't select application to forward OnSystemRequest."); + return; + } + msg_params[strings::app_id] = app_id; + } + } +#endif // According to HMI API, this should be HMI unique id, but during processing // messages from HMI this param is replaced by connection key, so below it // will be treated as connection key @@ -85,8 +118,7 @@ void OnSystemRequestNotification::Run() { "Received OnSystemRequest without appID." " One of registered apps will be used."); LOG4CXX_DEBUG(logger_, "Searching registered app to send OnSystemRequest."); - const PolicyHandlerInterface& policy_handler = policy_handler_; - const uint32_t selected_app_id = policy_handler.GetAppIdForSending(); + const uint32_t selected_app_id = policy_handler_.GetAppIdForSending(); if (0 == selected_app_id) { LOG4CXX_WARN(logger_, "Can't select application to forward OnSystemRequest."); @@ -121,11 +153,6 @@ void OnSystemRequestNotification::Run() { params[strings::connection_key] = app->app_id(); - using namespace rpc::policy_table_interface_base; - const auto request_type = - static_cast<rpc::policy_table_interface_base::RequestType>( - (*message_)[strings::msg_params][strings::request_type].asUInt()); - if (helpers::Compare<RequestType, helpers::EQ, helpers::ONE>( request_type, RequestType::RT_PROPRIETARY, RequestType::RT_HTTP)) { policy_handler_.OnSystemRequestReceived(); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_tts_language_change_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_tts_language_change_notification.cc index f89baad737..293857f8d5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_tts_language_change_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_tts_language_change_notification.cc @@ -59,20 +59,31 @@ OnTTSLanguageChangeNotification::~OnTTSLanguageChangeNotification() {} void OnTTSLanguageChangeNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); - HMICapabilities& hmi_capabilities = hmi_capabilities_; - - hmi_capabilities.set_active_tts_language( + hmi_capabilities_.set_active_tts_language( static_cast<hmi_apis::Common_Language::eType>( (*message_)[strings::msg_params][strings::language].asInt())); /* need to clarify, because unchanged VR cause WRONG_LANGUAGE on Register */ - hmi_capabilities.set_active_vr_language( + hmi_capabilities_.set_active_vr_language( static_cast<hmi_apis::Common_Language::eType>( (*message_)[strings::msg_params][strings::language].asInt())); + std::vector<std::string> sections_to_update{hmi_response::language}; + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save TTS.OnLanguageChange response to cache"); + } + + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::vr, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save VR.OnLanguageChange response to cache"); + } + (*message_)[strings::msg_params][strings::hmi_display_language] = - hmi_capabilities.active_ui_language(); + hmi_capabilities_.active_ui_language(); (*message_)[strings::params][strings::function_id] = static_cast<int32_t>(mobile_apis::FunctionID::OnLanguageChangeID); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ui_language_change_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ui_language_change_notification.cc index 697b2036c4..995d69cc45 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ui_language_change_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_ui_language_change_notification.cc @@ -59,17 +59,22 @@ OnUILanguageChangeNotification::~OnUILanguageChangeNotification() {} void OnUILanguageChangeNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); - HMICapabilities& hmi_capabilities = hmi_capabilities_; - - hmi_capabilities.set_active_ui_language( + hmi_capabilities_.set_active_ui_language( static_cast<hmi_apis::Common_Language::eType>( (*message_)[strings::msg_params][strings::language].asInt())); + std::vector<std::string> sections_to_update{hmi_response::language}; + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::ui, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save UI.OnLanguageChange response to cache"); + } + (*message_)[strings::msg_params][strings::hmi_display_language] = (*message_)[strings::msg_params][strings::language]; (*message_)[strings::msg_params][strings::language] = - hmi_capabilities.active_vr_language(); + hmi_capabilities_.active_vr_language(); (*message_)[strings::params][strings::function_id] = static_cast<int32_t>(mobile_apis::FunctionID::OnLanguageChangeID); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_language_change_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_language_change_notification.cc index c308af9b92..1500f272ab 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_language_change_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_language_change_notification.cc @@ -60,14 +60,19 @@ OnVRLanguageChangeNotification::~OnVRLanguageChangeNotification() {} void OnVRLanguageChangeNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); - HMICapabilities& hmi_capabilities = hmi_capabilities_; - - hmi_capabilities.set_active_vr_language( + hmi_capabilities_.set_active_vr_language( static_cast<hmi_apis::Common_Language::eType>( (*message_)[strings::msg_params][strings::language].asInt())); + std::vector<std::string> sections_to_update{hmi_response::language}; + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::vr, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save VR.OnLanguageChange response to cache"); + } + (*message_)[strings::msg_params][strings::hmi_display_language] = - hmi_capabilities.active_ui_language(); + hmi_capabilities_.active_ui_language(); (*message_)[strings::params][strings::function_id] = static_cast<int32_t>(mobile_apis::FunctionID::OnLanguageChangeID); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_request.cc index d8ad6087a6..d882dcd6e7 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_request.cc @@ -57,6 +57,12 @@ void RCGetCapabilitiesRequest::Run() { SendRequest(); } +void RCGetCapabilitiesRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::RC_GetCapabilities); +} + } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_response.cc index 128b111c5e..910c12e979 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_get_capabilities_response.cc @@ -53,13 +53,26 @@ RCGetCapabilitiesResponse::~RCGetCapabilitiesResponse() {} void RCGetCapabilitiesResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); - HMICapabilities& hmi_capabilities = hmi_capabilities_; + const auto result_code = static_cast<hmi_apis::Common_Result::eType>( + (*message_)[strings::params][hmi_response::code].asInt()); + + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::RC_GetCapabilities); + + if (hmi_apis::Common_Result::SUCCESS != result_code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } + + std::vector<std::string> sections_to_update; bool rc_capability_exists = (*message_)[strings::msg_params].keyExists(strings::rc_capability); if (rc_capability_exists) { - hmi_capabilities.set_rc_capability( + hmi_capabilities_.set_rc_capability( (*message_)[strings::msg_params][strings::rc_capability]); + sections_to_update.push_back(strings::rc_capability); } bool seat_location_capability_exists = @@ -67,11 +80,18 @@ void RCGetCapabilitiesResponse::Run() { strings::seat_location_capability); if (seat_location_capability_exists) { - hmi_capabilities.set_seat_location_capability( + hmi_capabilities_.set_seat_location_capability( (*message_)[strings::msg_params][strings::seat_location_capability]); + sections_to_update.push_back(strings::seat_location_capability); } - hmi_capabilities.set_rc_supported(rc_capability_exists); + hmi_capabilities_.set_rc_supported(rc_capability_exists); + + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::rc, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save RC.GetCapabilities response to cache"); + } } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_is_ready_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_is_ready_request.cc index 5e4af1503a..4ea0d43dc3 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_is_ready_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/rc_is_ready_request.cc @@ -31,6 +31,9 @@ */ #include "sdl_rpc_plugin/commands/hmi/rc_is_ready_request.h" + +#include <set> + #include "application_manager/rpc_service.h" namespace sdl_rpc_plugin { @@ -77,11 +80,13 @@ void RCIsReadyRequest::on_event(const event_engine::Event& event) { if (!app_mngr::commands::CheckAvailabilityHMIInterfaces( application_manager_, HmiInterfaces::HMI_INTERFACE_RC)) { + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::RC_GetCapabilities); LOG4CXX_INFO(logger_, "HmiInterfaces::HMI_INTERFACE_RC isn't available"); return; } - SendMessageToHMI(); + RequestInterfaceCapabilities(hmi_interface::rc); break; } default: { @@ -93,14 +98,7 @@ void RCIsReadyRequest::on_event(const event_engine::Event& event) { void RCIsReadyRequest::onTimeOut() { // Note(dtrunov): According to new requirment APPLINK-27956 - SendMessageToHMI(); -} - -void RCIsReadyRequest::SendMessageToHMI() { - std::shared_ptr<smart_objects::SmartObject> get_capabilities( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::RC_GetCapabilities, application_manager_)); - rpc_service_.ManageHMICommand(get_capabilities); + RequestInterfaceCapabilities(hmi_interface::rc); } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_user_friendly_message_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_user_friendly_message_request.cc index 38a63611fa..f853cf814c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_user_friendly_message_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/sdl_get_user_friendly_message_request.cc @@ -69,7 +69,16 @@ void SDLGetUserFriendlyMessageRequest::Run() { smart_objects::SmartArray::const_iterator it = msg->begin(); smart_objects::SmartArray::const_iterator it_end = msg->end(); for (; it != it_end; ++it) { - msg_codes.push_back((*it).asString()); + std::string str = (*it).asString(); + if (!CheckSyntax(str)) { + LOG4CXX_WARN(logger_, "Invalid data"); + SendErrorResponse(correlation_id(), + static_cast<hmi_apis::FunctionID::eType>(function_id()), + hmi_apis::Common_Result::INVALID_DATA, + "invalid messageCode syntax"); + return; + } + msg_codes.push_back(str); } std::string required_language; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_capabilities_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_capabilities_request.cc index 9baaabf401..85f0b93b8c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_capabilities_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_capabilities_request.cc @@ -57,6 +57,11 @@ void TTSGetCapabilitiesRequest::Run() { SendRequest(); } +void TTSGetCapabilitiesRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetCapabilities); +} } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_capabilities_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_capabilities_response.cc index c0581a6380..e6edcdb365 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_capabilities_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_capabilities_response.cc @@ -52,19 +52,38 @@ TTSGetCapabilitiesResponse::~TTSGetCapabilitiesResponse() {} void TTSGetCapabilitiesResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); + const auto result_code = static_cast<hmi_apis::Common_Result::eType>( + (*message_)[strings::params][hmi_response::code].asInt()); - HMICapabilities& hmi_capabilities = hmi_capabilities_; + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetCapabilities); + + if (hmi_apis::Common_Result::SUCCESS != result_code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } + + std::vector<std::string> sections_to_update; if ((*message_)[strings::msg_params].keyExists( hmi_response::speech_capabilities)) { - hmi_capabilities.set_speech_capabilities( + sections_to_update.push_back(hmi_response::speech_capabilities); + hmi_capabilities_.set_speech_capabilities( (*message_)[strings::msg_params][hmi_response::speech_capabilities]); } if ((*message_)[strings::msg_params].keyExists( hmi_response::prerecorded_speech_capabilities)) { - hmi_capabilities.set_prerecorded_speech( + sections_to_update.push_back(hmi_response::prerecorded_speech_capabilities); + hmi_capabilities_.set_prerecorded_speech( (*message_)[strings::msg_params] [hmi_response::prerecorded_speech_capabilities]); } + + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save TTS.GetCapabilities response to cache"); + } } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_language_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_language_request.cc index 7d2c15a9bf..d62c9627f5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_language_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_language_request.cc @@ -57,6 +57,11 @@ void TTSGetLanguageRequest::Run() { SendRequest(); } +void TTSGetLanguageRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetLanguage); +} } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_language_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_language_response.cc index 627056dce1..1487fd7915 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_language_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_language_response.cc @@ -56,6 +56,18 @@ void TTSGetLanguageResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); using namespace hmi_apis; + const Common_Result::eType result_code = static_cast<Common_Result::eType>( + (*message_)[strings::params][hmi_response::code].asInt()); + + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetLanguage); + + if (Common_Result::SUCCESS != result_code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } + Common_Language::eType language = Common_Language::INVALID_ENUM; if ((*message_).keyExists(strings::msg_params) && @@ -66,6 +78,12 @@ void TTSGetLanguageResponse::Run() { hmi_capabilities_.set_active_tts_language(language); + std::vector<std::string> sections_to_update{hmi_response::language}; + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, message_->getSchema())) { + LOG4CXX_DEBUG(logger_, "Failed to save TTS.GetLanguage response to cache"); + } + LOG4CXX_DEBUG(logger_, "Raising event for function_id " << function_id() << " and correlation_id " diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_supported_languages_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_supported_languages_request.cc index 2cb47380d5..5d758c84b7 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_supported_languages_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_supported_languages_request.cc @@ -57,6 +57,11 @@ void TTSGetSupportedLanguagesRequest::Run() { SendRequest(); } +void TTSGetSupportedLanguagesRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetSupportedLanguages); +} } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_supported_languages_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_supported_languages_response.cc index a70d1c89a3..baa10394c5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_supported_languages_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_get_supported_languages_response.cc @@ -59,11 +59,23 @@ void TTSGetSupportedLanguagesResponse::Run() { static_cast<hmi_apis::Common_Result::eType>( (*message_)[strings::params][hmi_response::code].asInt()); - if (hmi_apis::Common_Result::SUCCESS == code) { - HMICapabilities& hmi_capabilities = hmi_capabilities_; + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetSupportedLanguages); - hmi_capabilities.set_tts_supported_languages( - (*message_)[strings::msg_params][hmi_response::languages]); + if (hmi_apis::Common_Result::SUCCESS != code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } + + hmi_capabilities_.set_tts_supported_languages( + (*message_)[strings::msg_params][hmi_response::languages]); + + std::vector<std::string> sections_to_update{hmi_response::languages}; + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save TTS.GetSupportedLanguages response to cache"); } } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_is_ready_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_is_ready_request.cc index 89b5961895..4ae737bec4 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_is_ready_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/tts_is_ready_request.cc @@ -31,7 +31,6 @@ */ #include "sdl_rpc_plugin/commands/hmi/tts_is_ready_request.h" -#include "application_manager/message_helper.h" #include "application_manager/rpc_service.h" namespace sdl_rpc_plugin { @@ -74,11 +73,13 @@ void TTSIsReadyRequest::on_event(const event_engine::Event& event) { hmi_capabilities.set_is_tts_cooperating(is_available); if (!app_mngr::commands::CheckAvailabilityHMIInterfaces( application_manager_, HmiInterfaces::HMI_INTERFACE_TTS)) { + UpdateRequiredInterfaceCapabilitiesRequests(hmi_interface::tts); LOG4CXX_INFO(logger_, "HmiInterfaces::HMI_INTERFACE_TTS isn't available"); return; } - SendMessageToHMI(); + + RequestInterfaceCapabilities(hmi_interface::tts); break; } default: { @@ -90,25 +91,7 @@ void TTSIsReadyRequest::on_event(const event_engine::Event& event) { void TTSIsReadyRequest::onTimeOut() { // Note(dtrunov): According to new requirment APPLINK-27956 - SendMessageToHMI(); -} - -void TTSIsReadyRequest::SendMessageToHMI() { - std::shared_ptr<smart_objects::SmartObject> get_language( - MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::TTS_GetLanguage, - application_manager_)); - HMICapabilities& hmi_capabilities = hmi_capabilities_; - hmi_capabilities.set_handle_response_for(*get_language); - rpc_service_.ManageHMICommand(get_language); - std::shared_ptr<smart_objects::SmartObject> get_all_languages( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::TTS_GetSupportedLanguages, - application_manager_)); - rpc_service_.ManageHMICommand(get_all_languages); - std::shared_ptr<smart_objects::SmartObject> get_capabilities( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::TTS_GetCapabilities, application_manager_)); - rpc_service_.ManageHMICommand(get_capabilities); + RequestInterfaceCapabilities(hmi_interface::tts); } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_request.cc index 5f8704b3e5..32c19eabcd 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_request.cc @@ -57,6 +57,11 @@ void UIGetCapabilitiesRequest::Run() { SendRequest(); } +void UIGetCapabilitiesRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetCapabilities); +} } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_response.cc index a3eb9244bd..c5a76612f6 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_capabilities_response.cc @@ -53,81 +53,112 @@ UIGetCapabilitiesResponse::~UIGetCapabilitiesResponse() {} void UIGetCapabilitiesResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); - HMICapabilities& hmi_capabilities = hmi_capabilities_; + const auto result_code = static_cast<hmi_apis::Common_Result::eType>( + (*message_)[strings::params][hmi_response::code].asInt()); + + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetCapabilities); + + if (hmi_apis::Common_Result::SUCCESS != result_code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } + + std::vector<std::string> sections_to_update; const smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params]; if (msg_params.keyExists(hmi_response::display_capabilities)) { - hmi_capabilities.set_display_capabilities( + sections_to_update.push_back(hmi_response::display_capabilities); + hmi_capabilities_.set_display_capabilities( msg_params[hmi_response::display_capabilities]); } if (msg_params.keyExists(hmi_response::hmi_zone_capabilities)) { - hmi_capabilities.set_hmi_zone_capabilities( + sections_to_update.push_back(hmi_response::hmi_zone_capabilities); + hmi_capabilities_.set_hmi_zone_capabilities( msg_params[hmi_response::hmi_zone_capabilities]); } if (msg_params.keyExists(hmi_response::soft_button_capabilities)) { - hmi_capabilities.set_soft_button_capabilities( + sections_to_update.push_back(hmi_response::soft_button_capabilities); + hmi_capabilities_.set_soft_button_capabilities( msg_params[hmi_response::soft_button_capabilities]); } // use newer parameter "audioPassThruCapabilitiesList" when available if (msg_params.keyExists(strings::audio_pass_thru_capabilities_list)) { - hmi_capabilities.set_audio_pass_thru_capabilities( + sections_to_update.push_back(strings::audio_pass_thru_capabilities); + hmi_capabilities_.set_audio_pass_thru_capabilities( msg_params[strings::audio_pass_thru_capabilities_list]); } else if (msg_params.keyExists(strings::audio_pass_thru_capabilities)) { smart_objects::SmartObject audio_pass_thru_capabilities_list( smart_objects::SmartType_Array); audio_pass_thru_capabilities_list[0] = msg_params[strings::audio_pass_thru_capabilities]; - hmi_capabilities.set_audio_pass_thru_capabilities( + sections_to_update.push_back(strings::audio_pass_thru_capabilities); + hmi_capabilities_.set_audio_pass_thru_capabilities( audio_pass_thru_capabilities_list); } if (msg_params.keyExists(strings::hmi_capabilities)) { if (msg_params[strings::hmi_capabilities].keyExists(strings::navigation)) { - hmi_capabilities.set_navigation_supported( + sections_to_update.push_back(strings::navigation); + hmi_capabilities_.set_navigation_supported( msg_params[strings::hmi_capabilities][strings::navigation].asBool()); } if (msg_params[strings::hmi_capabilities].keyExists(strings::phone_call)) { - hmi_capabilities.set_phone_call_supported( + sections_to_update.push_back(strings::phone_call); + hmi_capabilities_.set_phone_call_supported( msg_params[strings::hmi_capabilities][strings::phone_call].asBool()); } if (msg_params[strings::hmi_capabilities].keyExists( strings::video_streaming)) { - hmi_capabilities.set_video_streaming_supported( + sections_to_update.push_back(strings::video_streaming); + hmi_capabilities_.set_video_streaming_supported( msg_params[strings::hmi_capabilities][strings::video_streaming] .asBool()); } } if (msg_params.keyExists(strings::system_capabilities)) { - if (msg_params[strings::system_capabilities].keyExists( - strings::navigation_capability)) { - hmi_capabilities.set_navigation_capability( - msg_params[strings::system_capabilities] - [strings::navigation_capability]); + auto& system_capabilities_so = msg_params[strings::system_capabilities]; + + if (system_capabilities_so.keyExists(strings::navigation_capability)) { + sections_to_update.push_back(strings::navigation_capability); + hmi_capabilities_.set_navigation_capability( + system_capabilities_so[strings::navigation_capability]); } - if (msg_params[strings::system_capabilities].keyExists( - strings::phone_capability)) { - hmi_capabilities.set_phone_capability( - msg_params[strings::system_capabilities][strings::phone_capability]); + if (system_capabilities_so.keyExists(strings::phone_capability)) { + sections_to_update.push_back(strings::phone_capability); + hmi_capabilities_.set_phone_capability( + system_capabilities_so[strings::phone_capability]); } - if (msg_params[strings::system_capabilities].keyExists( - strings::video_streaming_capability)) { - hmi_capabilities.set_video_streaming_capability( - msg_params[strings::system_capabilities] - [strings::video_streaming_capability]); + if (system_capabilities_so.keyExists(strings::video_streaming_capability)) { + sections_to_update.push_back(strings::video_streaming_capability); + hmi_capabilities_.set_video_streaming_capability( + system_capabilities_so[strings::video_streaming_capability]); } - if (msg_params[strings::system_capabilities].keyExists( - strings::display_capabilities)) { - hmi_capabilities.set_system_display_capabilities( - msg_params[strings::system_capabilities] - [strings::display_capabilities]); + if (system_capabilities_so.keyExists(strings::display_capabilities)) { + sections_to_update.push_back(strings::display_capabilities); + hmi_capabilities_.set_system_display_capabilities( + system_capabilities_so[strings::display_capabilities]); } } + + if (msg_params.keyExists(strings::pcm_stream_capabilities)) { + sections_to_update.push_back(strings::pcm_stream_capabilities); + hmi_capabilities_.set_pcm_stream_capabilities( + msg_params[strings::pcm_stream_capabilities]); + } + + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::ui, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save UI.GetCapabilities response to cache"); + } } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_language_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_language_request.cc index d3b44d1168..948adbdece 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_language_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_language_request.cc @@ -57,6 +57,11 @@ void UIGetLanguageRequest::Run() { SendRequest(); } +void UIGetLanguageRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetLanguage); +} } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_language_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_language_response.cc index 2a5c0ab016..e32dbf3c47 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_language_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_language_response.cc @@ -56,6 +56,17 @@ UIGetLanguageResponse::~UIGetLanguageResponse() {} void UIGetLanguageResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); using namespace hmi_apis; + const Common_Result::eType result_code = static_cast<Common_Result::eType>( + (*message_)[strings::params][hmi_response::code].asInt()); + + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetLanguage); + + if (Common_Result::SUCCESS != result_code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } Common_Language::eType language = Common_Language::INVALID_ENUM; @@ -67,6 +78,12 @@ void UIGetLanguageResponse::Run() { hmi_capabilities_.set_active_ui_language(language); + std::vector<std::string> sections_to_update{hmi_response::language}; + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::ui, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, "Failed to save UI.GetLanguage response to cache"); + } + LOG4CXX_DEBUG(logger_, "Raising event for function_id " << function_id() << " and correlation_id " diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_supported_languages_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_supported_languages_request.cc index 0665612525..0001af9203 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_supported_languages_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_supported_languages_request.cc @@ -57,6 +57,11 @@ void UIGetSupportedLanguagesRequest::Run() { SendRequest(); } +void UIGetSupportedLanguagesRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetSupportedLanguages); +} } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_supported_languages_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_supported_languages_response.cc index 19ee62e51d..53704b3705 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_supported_languages_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_get_supported_languages_response.cc @@ -59,11 +59,23 @@ void UIGetSupportedLanguagesResponse::Run() { static_cast<hmi_apis::Common_Result::eType>( (*message_)[strings::params][hmi_response::code].asInt()); - if (hmi_apis::Common_Result::SUCCESS == code) { - HMICapabilities& hmi_capabilities = hmi_capabilities_; + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetSupportedLanguages); - hmi_capabilities.set_ui_supported_languages( - (*message_)[strings::msg_params][hmi_response::languages]); + if (hmi_apis::Common_Result::SUCCESS != code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } + + hmi_capabilities_.set_ui_supported_languages( + (*message_)[strings::msg_params][hmi_response::languages]); + + std::vector<std::string> sections_to_update{hmi_response::languages}; + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::ui, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save UI.GetSupportedLanguages response to cache"); } } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_is_ready_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_is_ready_request.cc index 2546b704b2..4882095d42 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_is_ready_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/ui_is_ready_request.cc @@ -31,7 +31,6 @@ */ #include "sdl_rpc_plugin/commands/hmi/ui_is_ready_request.h" -#include "application_manager/message_helper.h" #include "application_manager/rpc_service.h" namespace sdl_rpc_plugin { @@ -73,11 +72,13 @@ void UIIsReadyRequest::on_event(const event_engine::Event& event) { hmi_capabilities.set_is_ui_cooperating(is_available); if (!app_mngr::commands::CheckAvailabilityHMIInterfaces( application_manager_, HmiInterfaces::HMI_INTERFACE_UI)) { + UpdateRequiredInterfaceCapabilitiesRequests(hmi_interface::ui); LOG4CXX_INFO(logger_, "HmiInterfaces::HMI_INTERFACE_UI isn't available"); return; } - SendMessageToHMI(); + + RequestInterfaceCapabilities(hmi_interface::ui); break; } default: { @@ -89,25 +90,7 @@ void UIIsReadyRequest::on_event(const event_engine::Event& event) { void UIIsReadyRequest::onTimeOut() { // Note(dtrunov): According to new requirment APPLINK-27956 - SendMessageToHMI(); -} - -void UIIsReadyRequest::SendMessageToHMI() { - std::shared_ptr<smart_objects::SmartObject> get_language( - MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::UI_GetLanguage, - application_manager_)); - HMICapabilities& hmi_capabilities = hmi_capabilities_; - hmi_capabilities.set_handle_response_for(*get_language); - rpc_service_.ManageHMICommand(get_language); - std::shared_ptr<smart_objects::SmartObject> get_all_languages( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::UI_GetSupportedLanguages, - application_manager_)); - rpc_service_.ManageHMICommand(get_all_languages); - std::shared_ptr<smart_objects::SmartObject> get_capabilities( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::UI_GetCapabilities, application_manager_)); - rpc_service_.ManageHMICommand(get_capabilities); + RequestInterfaceCapabilities(hmi_interface::ui); } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_capabilities_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_capabilities_request.cc index b06bfa0e77..dd0d78cf2d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_capabilities_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_capabilities_request.cc @@ -57,6 +57,11 @@ void VRGetCapabilitiesRequest::Run() { SendRequest(); } +void VRGetCapabilitiesRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetCapabilities); +} } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_capabilities_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_capabilities_response.cc index 80c308ea40..79d532bff8 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_capabilities_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_capabilities_response.cc @@ -52,11 +52,32 @@ VRGetCapabilitiesResponse::~VRGetCapabilitiesResponse() {} void VRGetCapabilitiesResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); + const auto result_code = static_cast<hmi_apis::Common_Result::eType>( + (*message_)[strings::params][hmi_response::code].asInt()); - HMICapabilities& hmi_capabilities = hmi_capabilities_; + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetCapabilities); - hmi_capabilities.set_vr_capabilities( - (*message_)[strings::msg_params][strings::vr_capabilities]); + if (hmi_apis::Common_Result::SUCCESS != result_code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } + + const smart_objects::SmartObject& msg_params = + (*message_)[strings::msg_params]; + + std::vector<std::string> sections_to_update; + if (msg_params.keyExists(strings::vr_capabilities)) { + sections_to_update.push_back(strings::vr_capabilities); + hmi_capabilities_.set_vr_capabilities(msg_params[strings::vr_capabilities]); + } + + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::vr, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, + "Failed to save VR.GetCapabilities response to cache"); + } } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_language_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_language_request.cc index 84179f6357..3aa36aee33 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_language_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_language_request.cc @@ -57,6 +57,11 @@ void VRGetLanguageRequest::Run() { SendRequest(); } +void VRGetLanguageRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetLanguage); +} } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_language_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_language_response.cc index 6b7fec736d..462ccc529c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_language_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_language_response.cc @@ -56,6 +56,17 @@ VRGetLanguageResponse::~VRGetLanguageResponse() {} void VRGetLanguageResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); using namespace hmi_apis; + const Common_Result::eType result_code = static_cast<Common_Result::eType>( + (*message_)[strings::params][hmi_response::code].asInt()); + + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetLanguage); + + if (Common_Result::SUCCESS != result_code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } Common_Language::eType language = Common_Language::INVALID_ENUM; @@ -67,6 +78,12 @@ void VRGetLanguageResponse::Run() { hmi_capabilities_.set_active_vr_language(language); + std::vector<std::string> sections_to_update{hmi_response::language}; + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::vr, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR(logger_, "Failed to save VR.GetLanguage response to cache"); + } + LOG4CXX_DEBUG(logger_, "Raising event for function_id " << function_id() << " and correlation_id " diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_supported_languages_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_supported_languages_request.cc index 351940bf68..5755b91ab6 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_supported_languages_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_supported_languages_request.cc @@ -57,6 +57,11 @@ void VRGetSupportedLanguagesRequest::Run() { SendRequest(); } +void VRGetSupportedLanguagesRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetSupportedLanguages); +} } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_supported_languages_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_supported_languages_response.cc index 4c725267fa..59602cf10a 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_supported_languages_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_get_supported_languages_response.cc @@ -60,10 +60,20 @@ void VRGetSupportedLanguagesResponse::Run() { static_cast<hmi_apis::Common_Result::eType>( (*message_)[strings::params][hmi_response::code].asInt()); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetSupportedLanguages); + if (hmi_apis::Common_Result::SUCCESS == code) { HMICapabilities& hmi_capabilities = hmi_capabilities_; hmi_capabilities.set_vr_supported_languages( (*message_)[strings::msg_params][hmi_response::languages]); + + std::vector<std::string> sections_to_update{hmi_response::languages}; + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::vr, sections_to_update, message_->getSchema())) { + LOG4CXX_ERROR( + logger_, "Failed to save VR.GetSupportedLanguages response to cache"); + } } } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_is_ready_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_is_ready_request.cc index 12414eab10..f65f58f423 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_is_ready_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/vr_is_ready_request.cc @@ -73,11 +73,13 @@ void VRIsReadyRequest::on_event(const event_engine::Event& event) { hmi_capabilities.set_is_vr_cooperating(is_available); if (!app_mngr::commands::CheckAvailabilityHMIInterfaces( application_manager_, HmiInterfaces::HMI_INTERFACE_VR)) { + UpdateRequiredInterfaceCapabilitiesRequests(hmi_interface::vr); LOG4CXX_INFO(logger_, "HmiInterfaces::HMI_INTERFACE_VR isn't available"); return; } - SendMessageToHMI(); + + RequestInterfaceCapabilities(hmi_interface::vr); break; } default: { @@ -89,25 +91,7 @@ void VRIsReadyRequest::on_event(const event_engine::Event& event) { void VRIsReadyRequest::onTimeOut() { // Note(dtrunov): According to new requirment APPLINK-27956 - SendMessageToHMI(); -} - -void VRIsReadyRequest::SendMessageToHMI() { - std::shared_ptr<smart_objects::SmartObject> get_language( - MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetLanguage, - application_manager_)); - HMICapabilities& hmi_capabilities = hmi_capabilities_; - hmi_capabilities.set_handle_response_for(*get_language); - rpc_service_.ManageHMICommand(get_language); - std::shared_ptr<smart_objects::SmartObject> get_all_languages( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::VR_GetSupportedLanguages, - application_manager_)); - rpc_service_.ManageHMICommand(get_all_languages); - std::shared_ptr<smart_objects::SmartObject> get_capabilities( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::VR_GetCapabilities, application_manager_)); - rpc_service_.ManageHMICommand(get_capabilities); + RequestInterfaceCapabilities(hmi_interface::vr); } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc index 50217a9c8a..27cac83fad 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/change_registration_request.cc @@ -177,7 +177,7 @@ void ChangeRegistrationRequest::Run() { IsLanguageSupportedByVR(language) && IsLanguageSupportedByTTS(language))) { LOG4CXX_ERROR(logger_, "Language is not supported"); - SendResponse(false, mobile_apis::Result::REJECTED); + SendResponse(false, mobile_apis::Result::UNSUPPORTED_RESOURCE); return; } @@ -460,8 +460,7 @@ bool ChangeRegistrationRequest::PrepareResponseParameters( bool ChangeRegistrationRequest::IsLanguageSupportedByUI( const int32_t& hmi_display_lang) { const HMICapabilities& hmi_capabilities = hmi_capabilities_; - const smart_objects::SmartObject* ui_languages = - hmi_capabilities.ui_supported_languages(); + const auto ui_languages = hmi_capabilities.ui_supported_languages(); if (!ui_languages) { LOG4CXX_ERROR(logger_, "NULL pointer"); @@ -482,8 +481,7 @@ bool ChangeRegistrationRequest::IsLanguageSupportedByUI( bool ChangeRegistrationRequest::IsLanguageSupportedByVR( const int32_t& hmi_display_lang) { const HMICapabilities& hmi_capabilities = hmi_capabilities_; - const smart_objects::SmartObject* vr_languages = - hmi_capabilities.vr_supported_languages(); + const auto vr_languages = hmi_capabilities.vr_supported_languages(); if (!vr_languages) { LOG4CXX_ERROR(logger_, "NULL pointer"); @@ -504,8 +502,7 @@ bool ChangeRegistrationRequest::IsLanguageSupportedByVR( bool ChangeRegistrationRequest::IsLanguageSupportedByTTS( const int32_t& hmi_display_lang) { const HMICapabilities& hmi_capabilities = hmi_capabilities_; - const smart_objects::SmartObject* tts_languages = - hmi_capabilities.tts_supported_languages(); + const auto tts_languages = hmi_capabilities.tts_supported_languages(); if (!tts_languages) { LOG4CXX_ERROR(logger_, "NULL pointer"); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc index c51991742d..a205660e23 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_button_press_notification.cc @@ -67,6 +67,10 @@ void OnButtonPressNotification::Run() { const bool is_app_id_exists = (*message_)[strings::msg_params].keyExists(strings::app_id); ApplicationSharedPtr app; + if (is_app_id_exists) { + app = application_manager_.application( + (*message_)[strings::msg_params][strings::app_id].asUInt()); + } // CUSTOM_BUTTON notification if (static_cast<uint32_t>(mobile_apis::ButtonName::CUSTOM_BUTTON) == btn_id) { @@ -76,9 +80,6 @@ void OnButtonPressNotification::Run() { return; } - app = application_manager_.application( - (*message_)[strings::msg_params][strings::app_id].asUInt()); - // custom_button_id is mandatory for CUSTOM_BUTTON notification if (false == (*message_)[strings::msg_params].keyExists( hmi_response::custom_button_id)) { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_request_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_request_notification.cc index b340055c50..9c868172f5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_request_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_system_request_notification.cc @@ -118,10 +118,14 @@ void OnSystemRequestNotification::Run() { mobile_apis::RequestType::OEM_SPECIFIC); BinaryMessage binary_data; - if (binary_data_is_required) { + if (binary_data_is_required && + (*message_)[strings::msg_params].keyExists(strings::file_name)) { const std::string filename = (*message_)[strings::msg_params][strings::file_name].asString(); file_system::ReadBinaryFile(filename, binary_data); + } else if ((*message_)[strings::params].keyExists(strings::binary_data)) { + // Binary data may already be attached to the message + binary_data = (*message_)[strings::params][strings::binary_data].asBinary(); } if (mobile_apis::RequestType::OEM_SPECIFIC == request_type) { @@ -130,8 +134,7 @@ void OnSystemRequestNotification::Run() { /* According to requirements: "If the requestType = PROPRIETARY, add to mobile API fileType = JSON If the requestType = HTTP, add to mobile API fileType = BINARY" - Also in Genivi SDL we don't save the PT to file - we put it directly in - binary_data */ + Also we don't save the PT to file - we put it directly in binary_data */ #if defined(PROPRIETARY_MODE) AddHeader(binary_data); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_way_point_change_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_way_point_change_notification.cc index e89ede53b9..39e0735013 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_way_point_change_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/on_way_point_change_notification.cc @@ -65,6 +65,7 @@ void OnWayPointChangeNotification::Run() { (*message_)[strings::params][strings::connection_key] = *app_id; SendNotification(); } + application_manager_.SaveWayPointsMessage(message_); } } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_audio_pass_thru_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_audio_pass_thru_request.cc index 0481542565..2f3d38f0b0 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_audio_pass_thru_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_audio_pass_thru_request.cc @@ -287,20 +287,22 @@ void PerformAudioPassThruRequest::SendPerformAudioPassThruRequest() { msg_params[hmi_request::audio_pass_display_texts] = smart_objects::SmartObject(smart_objects::SmartType_Array); + int32_t index = 0; if ((*message_)[str::msg_params].keyExists(str::audio_pass_display_text1)) { - msg_params[hmi_request::audio_pass_display_texts][0] + msg_params[hmi_request::audio_pass_display_texts][index] [hmi_request::field_name] = static_cast<int32_t>( hmi_apis::Common_TextFieldName::audioPassThruDisplayText1); - msg_params[hmi_request::audio_pass_display_texts][0] + msg_params[hmi_request::audio_pass_display_texts][index] [hmi_request::field_text] = (*message_)[str::msg_params][str::audio_pass_display_text1]; + ++index; } if ((*message_)[str::msg_params].keyExists(str::audio_pass_display_text2)) { - msg_params[hmi_request::audio_pass_display_texts][1] + msg_params[hmi_request::audio_pass_display_texts][index] [hmi_request::field_name] = static_cast<int32_t>( hmi_apis::Common_TextFieldName::audioPassThruDisplayText2); - msg_params[hmi_request::audio_pass_display_texts][1] + msg_params[hmi_request::audio_pass_display_texts][index] [hmi_request::field_text] = (*message_)[str::msg_params][str::audio_pass_display_text2]; } 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 cbdaa713b8..5fb66c25ac 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 @@ -551,13 +551,16 @@ RegisterAppInterfaceRequest::GetLockScreenIconUrlNotification( (*message)[strings::msg_params][strings::request_type] = mobile_apis::RequestType::LOCK_SCREEN_ICON_URL; (*message)[strings::msg_params][strings::url] = - GetPolicyHandler().GetLockScreenIconUrl(); + GetPolicyHandler().GetLockScreenIconUrl(app->policy_app_id()); return message; } void FillVRRelatedFields(smart_objects::SmartObject& response_params, const HMICapabilities& hmi_capabilities) { - response_params[strings::language] = hmi_capabilities.active_vr_language(); + auto active_vr_lang = hmi_capabilities.active_vr_language(); + if (hmi_apis::Common_Language::INVALID_ENUM != active_vr_lang) { + response_params[strings::language] = active_vr_lang; + } auto vr_capabilities = hmi_capabilities.vr_capabilities(); if (vr_capabilities) { response_params[strings::vr_capabilities] = *vr_capabilities; @@ -574,7 +577,10 @@ void FillVIRelatedFields(smart_objects::SmartObject& response_params, void FillTTSRelatedFields(smart_objects::SmartObject& response_params, const HMICapabilities& hmi_capabilities) { - response_params[strings::language] = hmi_capabilities.active_tts_language(); + auto active_tts_lang = hmi_capabilities.active_tts_language(); + if (hmi_apis::Common_Language::INVALID_ENUM != active_tts_lang) { + response_params[strings::language] = active_tts_lang; + } auto speech_capabilities = hmi_capabilities.speech_capabilities(); if (speech_capabilities) { response_params[strings::speech_capabilities] = *speech_capabilities; @@ -587,8 +593,10 @@ void FillTTSRelatedFields(smart_objects::SmartObject& response_params, void FillUIRelatedFields(smart_objects::SmartObject& response_params, const HMICapabilities& hmi_capabilities) { - response_params[strings::hmi_display_language] = - hmi_capabilities.active_ui_language(); + auto active_ui_lang = hmi_capabilities.active_ui_language(); + if (hmi_apis::Common_Language::INVALID_ENUM != active_ui_lang) { + response_params[strings::hmi_display_language] = active_ui_lang; + } auto display_capabilities = hmi_capabilities.display_capabilities(); if (display_capabilities) { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/reset_global_properties_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/reset_global_properties_request.cc index ffd8a7dc81..a0e178d0e2 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/reset_global_properties_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/reset_global_properties_request.cc @@ -198,8 +198,21 @@ bool ResetGlobalPropertiesRequest::ResetHelpPromt( SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED); return false; } + const std::vector<std::string>& help_prompt = + application_manager_.get_settings().help_prompt(); + smart_objects::SmartObject so_help_prompt = smart_objects::SmartObject(smart_objects::SmartType_Array); + + for (size_t i = 0; i < help_prompt.size(); ++i) { + smart_objects::SmartObject help_prompt_item = + smart_objects::SmartObject(smart_objects::SmartType_Map); + help_prompt_item[strings::text] = help_prompt[i]; + help_prompt_item[strings::type] = + hmi_apis::Common_SpeechCapabilities::SC_TEXT; + so_help_prompt[i] = help_prompt_item; + } + app->set_help_prompt(so_help_prompt); return true; } @@ -218,7 +231,7 @@ bool ResetGlobalPropertiesRequest::ResetTimeoutPromt( smart_objects::SmartObject so_time_out_promt = smart_objects::SmartObject(smart_objects::SmartType_Array); - for (uint32_t i = 0; i < time_out_promt.size(); ++i) { + for (size_t i = 0; i < time_out_promt.size(); ++i) { smart_objects::SmartObject timeoutPrompt = smart_objects::SmartObject(smart_objects::SmartType_Map); timeoutPrompt[strings::text] = time_out_promt[i]; @@ -238,8 +251,16 @@ bool ResetGlobalPropertiesRequest::ResetVrHelpTitleItems( SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED); return false; } + + const std::string& vr_help_title = + application_manager_.get_settings().vr_help_title(); + smart_objects::SmartObject so_vr_help_title = + smart_objects::SmartObject(smart_objects::SmartType_String); + so_vr_help_title = vr_help_title; + app->reset_vr_help_title(); app->reset_vr_help(); + app->set_vr_help_title(so_vr_help_title); return true; } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc index acf312d532..ed77d8a550 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_app_icon_request.cc @@ -60,6 +60,14 @@ SetAppIconRequest::SetAppIconRequest( , is_icons_saving_enabled_(false) { const std::string path = application_manager_.get_settings().app_icons_folder(); + + if (!file_system::DirectoryExists(path)) { + LOG4CXX_WARN(logger_, "App icons folder doesn't exist."); + if (!file_system::CreateDirectoryRecursively(path)) { + LOG4CXX_ERROR(logger_, "Unable to create app icons directory: " << path); + } + } + is_icons_saving_enabled_ = file_system::IsWritingAllowed(path) && file_system::IsReadingAllowed(path); } @@ -162,11 +170,6 @@ void SetAppIconRequest::CopyToIconStorage( const uint64_t storage_size = static_cast<uint64_t>(file_system::DirectorySize(icon_storage)); - if (0 == storage_size) { - LOG4CXX_ERROR(logger_, "Can't get the folder size: " << icon_storage); - return; - } - if (storage_max_size < (file_size + storage_size)) { const uint32_t icons_amount = application_manager_.get_settings().app_icons_amount_to_remove(); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/subscribe_button_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/subscribe_button_request.cc index 1acb2a7438..3797913f5b 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/subscribe_button_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/subscribe_button_request.cc @@ -107,8 +107,8 @@ void SubscribeButtonRequest::Run() { app->SubscribeToButton(static_cast<mobile_apis::ButtonName::eType>(btn_id)); SendSubscribeButtonNotification(); - const bool is_succedeed = true; - SendResponse(is_succedeed, mobile_apis::Result::SUCCESS); + const bool is_succeeded = true; + SendResponse(is_succeeded, mobile_apis::Result::SUCCESS); } bool SubscribeButtonRequest::Init() { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_request_test.cc new file mode 100644 index 0000000000..f3d8dd4f93 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_request_test.cc @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2020, 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 "hmi/button_get_capabilities_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace button_get_capabilities_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::ButtonGetCapabilitiesRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class ButtonGetCapabilitiesRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(ButtonGetCapabilitiesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand<ButtonGetCapabilitiesRequest>(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(ButtonGetCapabilitiesRequestTest, + onTimeOut_ButtonsGetCapabilitiesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand<ButtonGetCapabilitiesRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::Buttons_GetCapabilities)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace button_get_capabilities_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_response_test.cc index 7d9ed899a6..f90611f58d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_response_test.cc @@ -86,6 +86,7 @@ TEST_F(ButtonGetCapabilitiesResponseTest, Run_CodeSuccess_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_button_capabilities(capabilities_)); EXPECT_CALL(mock_hmi_capabilities_, set_preset_bank_capabilities(preset_bank_capabilities_)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -102,6 +103,23 @@ TEST_F(ButtonGetCapabilitiesResponseTest, Run_CodeAborted_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_preset_bank_capabilities(preset_bank_capabilities_)) .Times(0); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +TEST_F(ButtonGetCapabilitiesResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr msg = CreateMsgParams(); + (*msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + ResponsePtr command(CreateCommand<ButtonGetCapabilitiesResponse>(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::Buttons_GetCapabilities)); + ASSERT_TRUE(command->Init()); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_response_test.cc index 11589683be..30d125ff46 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_response_test.cc @@ -126,11 +126,27 @@ TEST_F(GetSystemInfoResponseTest, GetSystemInfo_UNSUCCESS) { static_cast<hmi_apis::Common_Language::eType>(lang_code))) .Times(0); - EXPECT_CALL(mock_policy_handler_, OnGetSystemInfo("", "", "")); + EXPECT_CALL(mock_hmi_capabilities_, UpdateCachedCapabilities()); + EXPECT_CALL(mock_policy_handler_, SetPreloadedPtFlag(false)); command->Run(); } +TEST_F(GetSystemInfoResponseTest, GetSystemInfo_UpdateCapabilities_Called) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + + ResponseFromHMIPtr command(CreateCommand<GetSystemInfoResponse>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, OnSoftwareVersionReceived(ccpu_version)); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + } // namespace get_system_info_response } // namespace hmi_commands_test } // namespace commands_test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc index 26f7a63872..3819c720f8 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc @@ -545,7 +545,7 @@ TEST_F(HMICommandsNotificationsTest, OnReadyNotificationEventDispatcher) { std::shared_ptr<Command> command = CreateCommand<OnReadyNotification>(message); - EXPECT_CALL(app_mngr_, OnHMIStartedCooperation()); + EXPECT_CALL(app_mngr_, OnHMIReady()); EXPECT_CALL(app_mngr_, event_dispatcher()); EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) .WillOnce(GetEventId(&event_id)); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_request_test.cc new file mode 100644 index 0000000000..f7da89df0b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_request_test.cc @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2020, 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 "hmi/rc_get_capabilities_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace rc_get_capabilities_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::RCGetCapabilitiesRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class RCGetCapabilitiesRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(RCGetCapabilitiesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::number] = kStrNumber; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + RequestToHMIPtr command(CreateCommand<RCGetCapabilitiesRequest>(command_msg)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(RCGetCapabilitiesRequestTest, + onTimeOut_OnCapabilityInitialized_RemoveRCGetCapabilities) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + RequestToHMIPtr command(CreateCommand<RCGetCapabilitiesRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::RC_GetCapabilities)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); +} + +} // namespace rc_get_capabilities_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_response_test.cc index 67c36dce9c..22ecb014b0 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_response_test.cc @@ -166,6 +166,24 @@ TEST_F(RCGetCapabilitiesResponseTest, RUN_SUCCESSS) { EXPECT_CALL(mock_hmi_capabilities_, set_rc_capability(rc_capability_so)); EXPECT_CALL(mock_hmi_capabilities_, set_rc_supported(true)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +TEST_F(RCGetCapabilitiesResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + RCGetCapabilitiesResponsePtr command( + CreateCommand<RCGetCapabilitiesResponse>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::RC_GetCapabilities)); + ASSERT_TRUE(command->Init()); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_request_test.cc index 539c0efeb3..b569ecb83f 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_request_test.cc @@ -113,8 +113,14 @@ class RCIsReadyRequestTest event.set_smart_object(*msg); } + void HMICapabilitiesExpectations() { + EXPECT_CALL(mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::RC_GetCapabilities)) + .WillOnce(Return(true)); + } + RCIsReadyRequestPtr command_; - am::MockHmiInterfaces mock_hmi_interfaces_; }; TEST_F(RCIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { @@ -123,6 +129,7 @@ TEST_F(RCIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { const bool is_message_contain_param = false; Event event(hmi_apis::FunctionID::RC_IsReady); PrepareEvent(is_message_contain_param, event); + HMICapabilitiesExpectations(); SetUpExpectations(is_rc_cooperating_available, is_send_message_to_hmi, is_message_contain_param, @@ -149,6 +156,7 @@ TEST_F(RCIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { const bool is_message_contain_param = true; Event event(hmi_apis::FunctionID::RC_IsReady); PrepareEvent(is_message_contain_param, event, is_rc_cooperating_available); + HMICapabilitiesExpectations(); SetUpExpectations(is_rc_cooperating_available, is_send_message_to_hmi, is_message_contain_param, @@ -157,6 +165,7 @@ TEST_F(RCIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { } TEST_F(RCIsReadyRequestTest, Run_HMIDoestRespond_SendMessageToHMIByTimeout) { + HMICapabilitiesExpectations(); ExpectSendMessagesToHMI(); command_->onTimeOut(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc index 5cac1c823f..0e87acef1f 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc @@ -110,6 +110,7 @@ TEST_F(SDLGetUserFriendlyMessageRequestTest, Run_LanguageSet_SUCCESS) { EXPECT_CALL(mock_policy_handler_, OnGetUserFriendlyMessage(msg_codes, kLanguageEn, kCorrelationID)); + command->Init(); command->Run(); } @@ -136,6 +137,7 @@ TEST_F(SDLGetUserFriendlyMessageRequestTest, Run_LanguageNotSet_SUCCESS) { EXPECT_CALL(mock_policy_handler_, OnGetUserFriendlyMessage(msg_codes, kLanguageEn, kCorrelationID)); + command->Init(); command->Run(); } @@ -150,6 +152,39 @@ TEST_F(SDLGetUserFriendlyMessageRequestTest, Run_NoMsgCodes_Canceled) { EXPECT_CALL(mock_message_helper_, CommonLanguageToString(_)).Times(0); EXPECT_CALL(mock_policy_handler_, OnGetUserFriendlyMessage(_, _, _)).Times(0); + command->Init(); + command->Run(); +} + +MATCHER_P(HMIRequestResultCodeIs, result_code, "") { + return result_code == + static_cast<hmi_apis::Common_Result::eType>( + (*arg)[strings::params][am::hmi_response::code].asInt()); +} + +TEST_F( + SDLGetUserFriendlyMessageRequestTest, + RUN_InvalidRequestInvalidSymbolsStringMandatoryParam_SendInvalidDataErrorResponse) { + const std::string kInvalidSyntaxString = "\n\t "; + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::correlation_id] = kCorrelationID; + (*msg)[strings::msg_params][strings::app_id] = kAppID; + + (*msg)[strings::msg_params][kMessageCodes] = + SmartObject(smart_objects::SmartType_Array); + (*msg)[strings::msg_params][kMessageCodes][0] = + SmartObject(kInvalidSyntaxString); + (*msg)[strings::msg_params][kMessageCodes][1] = SmartObject(kLanguageEn); + + (*msg)[strings::msg_params][strings::language] = kLanguage; + + std::shared_ptr<SDLGetUserFriendlyMessageRequest> command( + CreateCommand<SDLGetUserFriendlyMessageRequest>(msg)); + + EXPECT_CALL(mock_message_helper_, CommonLanguageToString(_)).Times(0); + EXPECT_CALL(mock_policy_handler_, OnGetUserFriendlyMessage(_, _, _)).Times(0); + + command->Init(); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_request_test.cc new file mode 100644 index 0000000000..bae6b6082e --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_request_test.cc @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2020, 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 "hmi/tts_get_capabilities_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_get_capabilities_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::TTSGetCapabilitiesRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class TTSGetCapabilitiesRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(TTSGetCapabilitiesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand<TTSGetCapabilitiesRequest>(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(TTSGetCapabilitiesRequestTest, onTimeOut_TTSGetCapabilitiesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand<TTSGetCapabilitiesRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetCapabilities)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace tts_get_capabilities_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_response_test.cc index c7b96f1acf..2479b0a28e 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_response_test.cc @@ -52,16 +52,20 @@ using testing::_; namespace strings = ::application_manager::strings; namespace hmi_response = ::application_manager::hmi_response; +namespace hmi_interface = ::application_manager::hmi_interface; namespace { -const std::string kText = "TEXT"; -} +const std::string kText{"TEXT"}; +const hmi_apis::Common_Result::eType kSuccess = + hmi_apis::Common_Result::SUCCESS; +} // namespace class TTSGetCapabilitiesResponseTest : public CommandsTest<CommandsTestMocks::kIsNice> {}; TEST_F(TTSGetCapabilitiesResponseTest, Run_BothExist_SUCCESS) { MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = kSuccess; (*msg)[strings::msg_params][hmi_response::speech_capabilities] = kText; (*msg)[strings::msg_params][hmi_response::prerecorded_speech_capabilities] = kText; @@ -70,50 +74,82 @@ TEST_F(TTSGetCapabilitiesResponseTest, Run_BothExist_SUCCESS) { set_speech_capabilities(SmartObject(kText))); EXPECT_CALL(mock_hmi_capabilities_, set_prerecorded_speech(SmartObject(kText))); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::tts, _, _)); std::shared_ptr<TTSGetCapabilitiesResponse> command( CreateCommand<TTSGetCapabilitiesResponse>(msg)); + ASSERT_TRUE(command->Init()); command->Run(); } TEST_F(TTSGetCapabilitiesResponseTest, Run_OnlySpeech_SUCCESS) { MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = kSuccess; (*msg)[strings::msg_params][hmi_response::speech_capabilities] = kText; EXPECT_CALL(mock_hmi_capabilities_, set_speech_capabilities(SmartObject(kText))); EXPECT_CALL(mock_hmi_capabilities_, set_prerecorded_speech(_)).Times(0); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::tts, _, _)); std::shared_ptr<TTSGetCapabilitiesResponse> command( CreateCommand<TTSGetCapabilitiesResponse>(msg)); + ASSERT_TRUE(command->Init()); command->Run(); } TEST_F(TTSGetCapabilitiesResponseTest, Run_OnlyPrerecorded_SUCCESS) { MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = kSuccess; (*msg)[strings::msg_params][hmi_response::prerecorded_speech_capabilities] = kText; EXPECT_CALL(mock_hmi_capabilities_, set_speech_capabilities(_)).Times(0); EXPECT_CALL(mock_hmi_capabilities_, set_prerecorded_speech(SmartObject(kText))); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::tts, _, _)); std::shared_ptr<TTSGetCapabilitiesResponse> command( CreateCommand<TTSGetCapabilitiesResponse>(msg)); + ASSERT_TRUE(command->Init()); command->Run(); } TEST_F(TTSGetCapabilitiesResponseTest, Run_Nothing_SUCCESS) { MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = kSuccess; EXPECT_CALL(mock_hmi_capabilities_, set_speech_capabilities(_)).Times(0); EXPECT_CALL(mock_hmi_capabilities_, set_prerecorded_speech(_)).Times(0); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::tts, _, _)); std::shared_ptr<TTSGetCapabilitiesResponse> command( CreateCommand<TTSGetCapabilitiesResponse>(msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +TEST_F(TTSGetCapabilitiesResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + std::shared_ptr<TTSGetCapabilitiesResponse> command( + CreateCommand<TTSGetCapabilitiesResponse>(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetCapabilities)); + ASSERT_TRUE(command->Init()); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_request_test.cc new file mode 100644 index 0000000000..a0bf0887db --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_request_test.cc @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020, 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 "hmi/tts_get_language_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_get_language_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::TTSGetLanguageRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class TTSGetLanguageRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(TTSGetLanguageRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<TTSGetLanguageRequest>(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(TTSGetLanguageRequestTest, onTimeOut_TTSGetLanguageUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<TTSGetLanguageRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetLanguage)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace tts_get_language_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_response_test.cc index c0d23cb34b..4aeef5198b 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_response_test.cc @@ -51,10 +51,13 @@ using testing::ReturnRef; namespace strings = application_manager::strings; namespace hmi_response = application_manager::hmi_response; +namespace hmi_interface = application_manager::hmi_interface; using namespace hmi_apis; namespace { const Common_Language::eType kLanguage = Common_Language::EN_GB; +const hmi_apis::Common_Result::eType kSuccess = + hmi_apis::Common_Result::SUCCESS; } // namespace class TTSGetLanguageResponseTest @@ -63,22 +66,28 @@ class TTSGetLanguageResponseTest TEST_F(TTSGetLanguageResponseTest, Run_LanguageSet_SUCCESS) { MessageSharedPtr msg = CreateMessage(); (*msg)[strings::msg_params][hmi_response::language] = kLanguage; + (*msg)[strings::params][hmi_response::code] = kSuccess; std::shared_ptr<TTSGetLanguageResponse> command( CreateCommand<TTSGetLanguageResponse>(msg)); EXPECT_CALL(mock_hmi_capabilities_, set_active_tts_language(kLanguage)); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::tts, _, _)); + MockEventDispatcher mock_event_dispatcher; EXPECT_CALL(app_mngr_, event_dispatcher()) .WillOnce(ReturnRef(mock_event_dispatcher)); EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + ASSERT_TRUE(command->Init()); command->Run(); } TEST_F(TTSGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = kSuccess; std::shared_ptr<TTSGetLanguageResponse> command( CreateCommand<TTSGetLanguageResponse>(msg)); @@ -86,10 +95,31 @@ TEST_F(TTSGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_active_tts_language(Common_Language::INVALID_ENUM)); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::tts, _, _)); + MockEventDispatcher mock_event_dispatcher; EXPECT_CALL(app_mngr_, event_dispatcher()) .WillOnce(ReturnRef(mock_event_dispatcher)); EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +TEST_F(TTSGetLanguageResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + std::shared_ptr<TTSGetLanguageResponse> command( + CreateCommand<TTSGetLanguageResponse>(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetLanguage)); + ASSERT_TRUE(command->Init()); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_request_test.cc new file mode 100644 index 0000000000..1561e1def5 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_request_test.cc @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2020, 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 "hmi/tts_get_supported_languages_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_get_supported_languages_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::TTSGetSupportedLanguagesRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class TTSGetSupportedLanguagesRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(TTSGetSupportedLanguagesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand<TTSGetSupportedLanguagesRequest>(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(TTSGetSupportedLanguagesRequestTest, + onTimeOut_TTSGetSupportedLanguagesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand<TTSGetSupportedLanguagesRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetSupportedLanguages)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace tts_get_supported_languages_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_response_test.cc index c0f187a85f..e09d3198d7 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_response_test.cc @@ -57,6 +57,7 @@ using ::testing::Return; namespace am = ::application_manager; namespace strings = ::application_manager::strings; namespace hmi_response = am::hmi_response; +namespace hmi_interface = ::application_manager::hmi_interface; using am::commands::CommandImpl; using application_manager::commands::ResponseFromHMI; using sdl_rpc_plugin::commands::TTSGetSupportedLanguagesResponse; @@ -95,6 +96,9 @@ TEST_F(TTSGetSupportedLanguageResponseTest, RUN_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_tts_supported_languages(( *command_msg)[strings::msg_params][hmi_response::languages])); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::tts, _, _)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -115,6 +119,7 @@ TEST_F(TTSGetSupportedLanguageResponseTest, RUN_UNSUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_tts_supported_languages(supported_languages)) .Times(0); + ASSERT_TRUE(command->Init()); command->Run(); @@ -122,6 +127,23 @@ TEST_F(TTSGetSupportedLanguageResponseTest, RUN_UNSUCCESS) { am::hmi_response::languages)); } +TEST_F(TTSGetSupportedLanguageResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + ResponseFromHMIPtr command( + CreateCommand<TTSGetSupportedLanguagesResponse>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetSupportedLanguages)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + } // namespace tts_get_supported_languages_response } // namespace hmi_commands_test } // namespace commands_test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_is_ready_request_test.cc new file mode 100644 index 0000000000..e758bfca1f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_is_ready_request_test.cc @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2020, 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 "hmi/tts_is_ready_request.h" + +#include <memory> +#include <set> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/hmi_interfaces.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_is_ready_request { + +using ::testing::_; +using ::testing::ReturnRef; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::commands::RequestToHMI; +using am::event_engine::Event; +using sdl_rpc_plugin::commands::TTSIsReadyRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; +typedef std::shared_ptr<TTSIsReadyRequest> TTSIsReadyRequestPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class TTSIsReadyRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + TTSIsReadyRequestTest() : command_(CreateCommand<TTSIsReadyRequest>()) {} + + void SetUpExpectations(const bool is_tts_cooperating_available, + const bool should_message_be_sent, + const bool message_contains_param, + const am::HmiInterfaces::InterfaceState state) { + if (should_message_be_sent) { + ExpectSendMessagesToHMI(); + } + EXPECT_CALL(mock_hmi_capabilities_, + set_is_tts_cooperating(is_tts_cooperating_available)); + + if (message_contains_param) { + ON_CALL(app_mngr_, hmi_interfaces()) + .WillByDefault(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL( + mock_hmi_interfaces_, + SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS, state)); + } else { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillOnce(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL(mock_hmi_interfaces_, SetInterfaceState(_, _)).Times(0); + } + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillOnce(Return(state)); + } + + void ExpectSendMessagesToHMI() { + smart_objects::SmartObjectSPtr language = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); + EXPECT_CALL(mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::TTS_GetLanguage, _)) + .WillOnce(Return(language)); + EXPECT_CALL(mock_hmi_capabilities_, set_handle_response_for(*language)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(language, _)); + + smart_objects::SmartObjectSPtr support_language = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); + EXPECT_CALL( + mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::TTS_GetSupportedLanguages, _)) + .WillOnce(Return(support_language)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(support_language, _)); + + smart_objects::SmartObjectSPtr capabilities = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); + EXPECT_CALL( + mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::TTS_GetCapabilities, _)) + .WillOnce(Return(capabilities)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(capabilities, _)); + } + + void PrepareEvent(const bool message_contains_param, + const bool is_tts_cooperating_available, + Event& out_event) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + if (message_contains_param) { + (*msg)[am::strings::msg_params][am::strings::available] = + is_tts_cooperating_available; + } + out_event.set_smart_object(*msg); + } + + void HMICapabilitiesExpectations() { + EXPECT_CALL(mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetLanguage)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetSupportedLanguages)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetCapabilities)) + .WillOnce(Return(true)); + } + + TTSIsReadyRequestPtr command_; +}; + +TEST_F(TTSIsReadyRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::number] = kStrNumber; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + RequestToHMIPtr command(CreateCommand<TTSIsReadyRequest>(command_msg)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(TTSIsReadyRequestTest, + Run_NoKeyAvailableInMessage_HmiInterfacesIgnored_CacheIsAbsent) { + const bool is_tts_cooperating_available = false; + const bool should_message_be_sent = true; + const bool message_contains_param = false; + const auto state = am::HmiInterfaces::STATE_NOT_RESPONSE; + Event event(hmi_apis::FunctionID::TTS_IsReady); + PrepareEvent(message_contains_param, is_tts_cooperating_available, event); + HMICapabilitiesExpectations(); + SetUpExpectations(is_tts_cooperating_available, + should_message_be_sent, + message_contains_param, + state); + ASSERT_TRUE(command_->Init()); + + command_->Run(); + command_->on_event(event); +} + +TEST_F(TTSIsReadyRequestTest, + Run_KeyAvailableEqualToFalse_StateNotAvailable_CacheIsAbsent) { + const bool is_tts_cooperating_available = false; + const bool should_message_be_sent = false; + const bool message_contains_param = true; + const auto state = am::HmiInterfaces::STATE_NOT_AVAILABLE; + Event event(hmi_apis::FunctionID::TTS_IsReady); + PrepareEvent(message_contains_param, is_tts_cooperating_available, event); + SetUpExpectations(is_tts_cooperating_available, + should_message_be_sent, + message_contains_param, + state); + ASSERT_TRUE(command_->Init()); + + command_->Run(); + command_->on_event(event); +} + +TEST_F(TTSIsReadyRequestTest, + Run_KeyAvailableEqualToTrue_StateAvailable_CacheIsAbsnet) { + const bool is_tts_cooperating_available = true; + const bool should_message_be_sent = true; + const bool message_contains_param = true; + const auto state = am::HmiInterfaces::STATE_AVAILABLE; + Event event(hmi_apis::FunctionID::TTS_IsReady); + PrepareEvent(message_contains_param, is_tts_cooperating_available, event); + HMICapabilitiesExpectations(); + SetUpExpectations(is_tts_cooperating_available, + should_message_be_sent, + message_contains_param, + state); + ASSERT_TRUE(command_->Init()); + + command_->Run(); + command_->on_event(event); +} + +TEST_F(TTSIsReadyRequestTest, + Run_HMIDoestRespond_SendMessageToHMIByTimeout_CacheIsAbsent) { + HMICapabilitiesExpectations(); + ExpectSendMessagesToHMI(); + ASSERT_TRUE(command_->Init()); + + command_->Run(); + command_->onTimeOut(); +} + +} // namespace tts_is_ready_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_request_test.cc new file mode 100644 index 0000000000..1057a89cc6 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_request_test.cc @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020, 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 "hmi/ui_get_capabilities_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace ui_get_capabilities_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::UIGetCapabilitiesRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class UIGetCapabilitiesRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(UIGetCapabilitiesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<UIGetCapabilitiesRequest>(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(UIGetCapabilitiesRequestTest, onTimeOut_UIGetCapabilitiesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<UIGetCapabilitiesRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetCapabilities)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace ui_get_capabilities_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc index 4683fc62c7..cf701caf51 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc @@ -51,6 +51,7 @@ using ::testing::NiceMock; namespace am = ::application_manager; namespace strings = am::strings; namespace hmi_response = am::hmi_response; +namespace hmi_interface = ::application_manager::hmi_interface; using am::commands::CommandImpl; using application_manager::commands::ResponseFromHMI; using sdl_rpc_plugin::commands::UIGetCapabilitiesResponse; @@ -99,6 +100,7 @@ TEST_F(UIGetCapabilitiesResponseTest, RUN_SetDisplay_SUCCESSS) { EXPECT_CALL(mock_hmi_capabilities_, set_display_capabilities(display_capabilities_so)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -119,6 +121,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetSoftButton_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_soft_button_capabilities(soft_button_capabilities_so)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -138,6 +141,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetHmiZone_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_hmi_zone_capabilities(hmi_zone_capabilities_so)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -162,6 +166,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetAudioPassThru_SUCCESS) { EXPECT_CALL( mock_hmi_capabilities_, set_audio_pass_thru_capabilities(audio_pass_thru_capabilities_list_so)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -187,6 +192,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetAudioPassThruList_SUCCESS) { EXPECT_CALL( mock_hmi_capabilities_, set_audio_pass_thru_capabilities(audio_pass_thru_capabilities_list_so)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -206,6 +212,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetNavigation_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_navigation_supported( hmi_capabilities_so[strings::navigation].asBool())); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -225,6 +232,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetPhoneCall_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_phone_call_supported( hmi_capabilities_so[strings::phone_call].asBool())); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -244,6 +252,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetVideoStreaming_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_video_streaming_supported( hmi_capabilities_so[strings::video_streaming].asBool())); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -268,6 +277,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetNavigationCapability_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_navigation_capability(navigation_capability_so)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -289,6 +299,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetPhonenCapability_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_phone_capability(phone_capability_so)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -339,6 +350,7 @@ TEST_F(UIGetCapabilitiesResponseTest, SetVideoStreamingCapability_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_video_streaming_capability(video_streaming_capability)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -362,6 +374,39 @@ TEST_F(UIGetCapabilitiesResponseTest, SetSystemDisplayCapabilities_SUCCESS) { command->Run(); } +TEST_F(UIGetCapabilitiesResponseTest, + SaveCachedCapabilitiesToFileCall_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::system_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + ResponseFromHMIPtr command( + CreateCommand<UIGetCapabilitiesResponse>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::ui, _, _)); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + ResponseFromHMIPtr command( + CreateCommand<UIGetCapabilitiesResponse>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetCapabilities)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + } // namespace ui_get_capabilities_response } // namespace hmi_commands_test } // namespace commands_test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_request_test.cc new file mode 100644 index 0000000000..c944f1b49b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_request_test.cc @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020, 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 "hmi/ui_get_language_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace ui_get_language_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::UIGetLanguageRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class UIGetLanguageRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(UIGetLanguageRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<UIGetLanguageRequest>(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(UIGetLanguageRequestTest, onTimeOut_UIGetLanguageUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<UIGetLanguageRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetLanguage)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace ui_get_language_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_response_test.cc index 7e8040543d..d3edf074bd 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_response_test.cc @@ -52,6 +52,7 @@ using testing::ReturnRef; namespace strings = application_manager::strings; namespace hmi_response = application_manager::hmi_response; +namespace hmi_interface = application_manager::hmi_interface; using namespace hmi_apis; typedef NiceMock< @@ -60,6 +61,8 @@ typedef NiceMock< namespace { const hmi_apis::Common_Language::eType kLanguage = Common_Language::EN_GB; +const hmi_apis::Common_Result::eType kSuccess = + hmi_apis::Common_Result::SUCCESS; } // namespace class UIGetLanguageResponseTest @@ -68,33 +71,58 @@ class UIGetLanguageResponseTest TEST_F(UIGetLanguageResponseTest, Run_LanguageSet_SUCCESS) { MessageSharedPtr msg = CreateMessage(); (*msg)[strings::msg_params][hmi_response::language] = kLanguage; + (*msg)[strings::params][hmi_response::code] = kSuccess; std::shared_ptr<UIGetLanguageResponse> command( CreateCommand<UIGetLanguageResponse>(msg)); EXPECT_CALL(mock_hmi_capabilities_, set_active_ui_language(kLanguage)); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::ui, _, _)); MockEventDispatcher mock_event_dispatcher; EXPECT_CALL(app_mngr_, event_dispatcher()) .WillOnce(ReturnRef(mock_event_dispatcher)); EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + ASSERT_TRUE(command->Init()); command->Run(); } TEST_F(UIGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = kSuccess; std::shared_ptr<UIGetLanguageResponse> command( CreateCommand<UIGetLanguageResponse>(msg)); EXPECT_CALL(mock_hmi_capabilities_, set_active_ui_language(Common_Language::INVALID_ENUM)); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::ui, _, _)); MockEventDispatcher mock_event_dispatcher; EXPECT_CALL(app_mngr_, event_dispatcher()) .WillOnce(ReturnRef(mock_event_dispatcher)); EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +TEST_F(UIGetLanguageResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + std::shared_ptr<UIGetLanguageResponse> command( + CreateCommand<UIGetLanguageResponse>(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetLanguage)); + ASSERT_TRUE(command->Init()); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_request_test.cc new file mode 100644 index 0000000000..251b6b7d58 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_request_test.cc @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2020, 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 "hmi/ui_get_supported_languages_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace ui_get_supported_languages_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::UIGetSupportedLanguagesRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class UIGetSupportedLanguagesRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(UIGetSupportedLanguagesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand<UIGetSupportedLanguagesRequest>(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(UIGetSupportedLanguagesRequestTest, + onTimeOut_UIGetSupportedLanguagesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand<UIGetSupportedLanguagesRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetSupportedLanguages)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace ui_get_supported_languages_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_response_test.cc index 10cf244bcf..d73519734d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_response_test.cc @@ -54,6 +54,7 @@ using ::testing::Return; namespace am = ::application_manager; namespace strings = ::application_manager::strings; namespace hmi_response = am::hmi_response; +namespace hmi_interface = ::application_manager::hmi_interface; using sdl_rpc_plugin::commands::UIGetSupportedLanguagesResponse; typedef std::shared_ptr<UIGetSupportedLanguagesResponse> @@ -91,6 +92,9 @@ TEST_F(UIGetSupportedLanguagesResponseTest, RUN_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_ui_supported_languages((supported_languages))); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::ui, _, _)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -109,6 +113,7 @@ TEST_F(UIGetSupportedLanguagesResponseTest, RUN_UNSUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_ui_supported_languages(supported_languages)) .Times(0); + ASSERT_TRUE(command->Init()); command->Run(); @@ -116,6 +121,23 @@ TEST_F(UIGetSupportedLanguagesResponseTest, RUN_UNSUCCESS) { am::hmi_response::languages)); } +TEST_F(UIGetSupportedLanguagesResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + UIGetSupportedLanguagesResponsePtr command( + CreateCommand<UIGetSupportedLanguagesResponse>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetSupportedLanguages)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + } // namespace ui_get_supported_languages_response } // namespace hmi_commands_test } // namespace commands_test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_request_test.cc index 837b8438dc..a82ad39d83 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_request_test.cc @@ -141,17 +141,33 @@ class UIIsReadyRequestTest event.set_smart_object(*msg); } + void HMICapabilitiesExpectations() { + EXPECT_CALL( + mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities(hmi_apis::FunctionID::UI_GetLanguage)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetSupportedLanguages)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetCapabilities)) + .WillOnce(Return(true)); + } + UIIsReadyRequestPtr command_; policy_test::MockPolicyHandlerInterface mock_policy_handler_interface_; }; TEST_F(UIIsReadyRequestTest, - OnEvent_NoKeyAvailableInMessage_HmiInterfacesIgnored) { + OnEvent_NoKeyAvailableInMessage_HmiInterfacesIgnored_CacheIsAbsent) { const bool is_ui_cooperating_available = false; const bool is_send_message_to_hmi = true; const bool is_message_contain_param = false; Event event(hmi_apis::FunctionID::UI_IsReady); PrepareEvent(is_message_contain_param, event); + HMICapabilitiesExpectations(); SetUpExpectations(is_ui_cooperating_available, is_send_message_to_hmi, is_message_contain_param, @@ -161,7 +177,7 @@ TEST_F(UIIsReadyRequestTest, } TEST_F(UIIsReadyRequestTest, - OnEvent_KeyAvailableEqualToFalse_StateNotAvailable) { + OnEvent_KeyAvailableEqualToFalse_StateNotAvailable_CacheIsAbsent) { const bool is_ui_cooperating_available = false; const bool is_send_message_to_hmi = false; const bool is_message_contain_param = true; @@ -174,12 +190,14 @@ TEST_F(UIIsReadyRequestTest, command_->on_event(event); } -TEST_F(UIIsReadyRequestTest, OnEvent_KeyAvailableEqualToTrue_StateAvailable) { +TEST_F(UIIsReadyRequestTest, + OnEvent_KeyAvailableEqualToTrue_StateAvailable_CacheIsAbsent) { const bool is_ui_cooperating_available = true; const bool is_send_message_to_hmi = true; const bool is_message_contain_param = true; Event event(hmi_apis::FunctionID::UI_IsReady); PrepareEvent(is_message_contain_param, event, is_ui_cooperating_available); + HMICapabilitiesExpectations(); SetUpExpectations(is_ui_cooperating_available, is_send_message_to_hmi, is_message_contain_param, @@ -187,7 +205,8 @@ TEST_F(UIIsReadyRequestTest, OnEvent_KeyAvailableEqualToTrue_StateAvailable) { command_->on_event(event); } -TEST_F(UIIsReadyRequestTest, OnTimeout_SUCCESS) { +TEST_F(UIIsReadyRequestTest, OnTimeout_SUCCESS_CacheIsAbsent) { + HMICapabilitiesExpectations(); ExpectSendMessagesToHMI(); command_->onTimeOut(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_request_test.cc index 96f3b38fbf..92e3fa1187 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_request_test.cc @@ -58,7 +58,7 @@ typedef std::shared_ptr<UpdateSDLRequest> UpdateSDLRequestPtr; namespace { const uint32_t kConnectionKey = 2u; const uint32_t kCorrelationId = 1u; -const std::string kStrNumber = "123"; +const std::string kStrNumber{"123"}; } // namespace class UpdateSDLRequestTest : public CommandsTest<CommandsTestMocks::kIsNice> {}; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_response_test.cc index 62ffc6be4d..f0d431ac86 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_response_test.cc @@ -55,7 +55,7 @@ typedef std::shared_ptr<UpdateSDLResponse> UpdateSDLResponsePtr; namespace { const uint32_t kConnectionKey = 2u; -const std::string kStrNumber = "123"; +const std::string kStrNumber{"123"}; } // namespace class UpdateSDLResponseTest : public CommandsTest<CommandsTestMocks::kIsNice> { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_request_test.cc new file mode 100644 index 0000000000..cef87f06b4 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_request_test.cc @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020, 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 "hmi/vr_get_capabilities_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_get_capabilities_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::VRGetCapabilitiesRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class VRGetCapabilitiesRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(VRGetCapabilitiesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<VRGetCapabilitiesRequest>(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(VRGetCapabilitiesRequestTest, onTimeOut_VRGetCapabilitiesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<VRGetCapabilitiesRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetCapabilities)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace vr_get_capabilities_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_response_test.cc index 21acf2bb70..99024df485 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_response_test.cc @@ -51,6 +51,7 @@ using ::testing::NiceMock; namespace am = ::application_manager; namespace strings = am::strings; namespace hmi_response = am::hmi_response; +namespace hmi_interface = ::application_manager::hmi_interface; using am::commands::CommandImpl; using sdl_rpc_plugin::commands::VRGetCapabilitiesResponse; @@ -95,6 +96,26 @@ TEST_F(VRGetCapabilitiesResponseTest, RUN_SUCCESSS) { (*command_msg)[strings::msg_params][strings::vr_capabilities]; EXPECT_CALL(mock_hmi_capabilities_, set_vr_capabilities(vr_capabilities_so)); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::vr, _, _)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +TEST_F(VRGetCapabilitiesResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + VRGetCapabilitiesResponsePtr command( + CreateCommand<VRGetCapabilitiesResponse>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetCapabilities)); + ASSERT_TRUE(command->Init()); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_request_test.cc new file mode 100644 index 0000000000..6235b41691 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_request_test.cc @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020, 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 "hmi/vr_get_language_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_get_language_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::VRGetLanguageRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class VRGetLanguageRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(VRGetLanguageRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<VRGetLanguageRequest>(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(VRGetLanguageRequestTest, onTimeOut_VRGetLanguageUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<VRGetLanguageRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetLanguage)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace vr_get_language_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_response_test.cc index 8b00b4dded..d927195fd5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_response_test.cc @@ -52,6 +52,7 @@ using testing::ReturnRef; namespace strings = application_manager::strings; namespace hmi_response = application_manager::hmi_response; +namespace hmi_interface = application_manager::hmi_interface; using namespace hmi_apis; typedef NiceMock< @@ -60,6 +61,8 @@ typedef NiceMock< namespace { const hmi_apis::Common_Language::eType kLanguage = Common_Language::EN_GB; +const hmi_apis::Common_Result::eType kSuccess = + hmi_apis::Common_Result::SUCCESS; } // namespace class VRGetLanguageResponseTest @@ -68,22 +71,28 @@ class VRGetLanguageResponseTest TEST_F(VRGetLanguageResponseTest, Run_LanguageSet_SUCCESS) { MessageSharedPtr msg = CreateMessage(); (*msg)[strings::msg_params][hmi_response::language] = kLanguage; + (*msg)[strings::params][hmi_response::code] = kSuccess; std::shared_ptr<VRGetLanguageResponse> command( CreateCommand<VRGetLanguageResponse>(msg)); EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(kLanguage)); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::vr, _, _)); + MockEventDispatcher mock_event_dispatcher; EXPECT_CALL(app_mngr_, event_dispatcher()) .WillOnce(ReturnRef(mock_event_dispatcher)); EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + ASSERT_TRUE(command->Init()); command->Run(); } TEST_F(VRGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = kSuccess; std::shared_ptr<VRGetLanguageResponse> command( CreateCommand<VRGetLanguageResponse>(msg)); @@ -91,10 +100,31 @@ TEST_F(VRGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(Common_Language::INVALID_ENUM)); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::vr, _, _)); + MockEventDispatcher mock_event_dispatcher; EXPECT_CALL(app_mngr_, event_dispatcher()) .WillOnce(ReturnRef(mock_event_dispatcher)); EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +TEST_F(VRGetLanguageResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + std::shared_ptr<VRGetLanguageResponse> command( + CreateCommand<VRGetLanguageResponse>(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetLanguage)); + ASSERT_TRUE(command->Init()); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_request_test.cc new file mode 100644 index 0000000000..73657528e9 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_request_test.cc @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2020, 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 "hmi/vr_get_supported_languages_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_get_supported_languages_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::VRGetSupportedLanguagesRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class VRGetSupportedLanguagesRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(VRGetSupportedLanguagesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + + RequestToHMIPtr command( + CreateCommand<VRGetSupportedLanguagesRequest>(command_msg)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(VRGetSupportedLanguagesRequestTest, + onTimeOut_VRGetSupportedLanguagesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand<VRGetSupportedLanguagesRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetSupportedLanguages)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace vr_get_supported_languages_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_response_test.cc index b81823624c..2d51ee9d8a 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_response_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_response_test.cc @@ -54,6 +54,7 @@ using ::testing::Return; namespace am = ::application_manager; namespace strings = ::application_manager::strings; namespace hmi_response = am::hmi_response; +namespace hmi_interface = ::application_manager::hmi_interface; using sdl_rpc_plugin::commands::VRGetSupportedLanguagesResponse; typedef std::shared_ptr<VRGetSupportedLanguagesResponse> @@ -91,6 +92,9 @@ TEST_F(VRGetSupportedLanguagesResponseTest, RUN_SUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_vr_supported_languages((supported_languages))); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::vr, _, _)); + ASSERT_TRUE(command->Init()); command->Run(); } @@ -109,6 +113,7 @@ TEST_F(VRGetSupportedLanguagesResponseTest, RUN_UNSUCCESS) { EXPECT_CALL(mock_hmi_capabilities_, set_vr_supported_languages(supported_languages)) .Times(0); + ASSERT_TRUE(command->Init()); command->Run(); @@ -116,6 +121,23 @@ TEST_F(VRGetSupportedLanguagesResponseTest, RUN_UNSUCCESS) { am::hmi_response::languages)); } +TEST_F(VRGetSupportedLanguagesResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + VRGetSupportedLanguagesResponsePtr command( + CreateCommand<VRGetSupportedLanguagesResponse>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetSupportedLanguages)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + } // namespace vr_get_supported_languages_response } // namespace hmi_commands_test } // namespace commands_test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_request_test.cc index 9bb8e4c2d5..3d2a46707e 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_request_test.cc @@ -68,9 +68,8 @@ class VRIsReadyRequestTest bool is_send_message_to_hmi, bool is_message_contain_param, am::HmiInterfaces::InterfaceState state) { - const bool is_send_message_by_timeout = false; if (is_send_message_to_hmi) { - ExpectSendMessagesToHMI(is_send_message_by_timeout); + ExpectSendMessagesToHMI(); } EXPECT_CALL(mock_hmi_capabilities_, set_is_vr_cooperating(is_vr_cooperating_available)); @@ -91,7 +90,7 @@ class VRIsReadyRequestTest .WillOnce(Return(state)); } - void ExpectSendMessagesToHMI(bool is_send_message_by_timeout) { + void ExpectSendMessagesToHMI() { smart_objects::SmartObjectSPtr language( new smart_objects::SmartObject(smart_objects::SmartType_Map)); EXPECT_CALL(mock_message_helper_, @@ -127,15 +126,32 @@ class VRIsReadyRequestTest event.set_smart_object(*msg); } + void HMICapabilitiesExpectations() { + EXPECT_CALL( + mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities(hmi_apis::FunctionID::VR_GetLanguage)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetSupportedLanguages)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetCapabilities)) + .WillOnce(Return(true)); + } + VRIsReadyRequestPtr command_; }; -TEST_F(VRIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { +TEST_F(VRIsReadyRequestTest, + Run_NoKeyAvailableInMessage_HmiInterfacesIgnored_CacheIsAbsent) { const bool is_vr_cooperating_available = false; const bool is_send_message_to_hmi = true; const bool is_message_contain_param = false; Event event(hmi_apis::FunctionID::VR_IsReady); PrepareEvent(is_message_contain_param, event); + HMICapabilitiesExpectations(); SetUpExpectations(is_vr_cooperating_available, is_send_message_to_hmi, is_message_contain_param, @@ -143,7 +159,8 @@ TEST_F(VRIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { command_->on_event(event); } -TEST_F(VRIsReadyRequestTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { +TEST_F(VRIsReadyRequestTest, + Run_KeyAvailableEqualToFalse_StateNotAvailable_CacheIsAbsent) { const bool is_vr_cooperating_available = false; const bool is_send_message_to_hmi = false; const bool is_message_contain_param = true; @@ -156,12 +173,14 @@ TEST_F(VRIsReadyRequestTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { command_->on_event(event); } -TEST_F(VRIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { +TEST_F(VRIsReadyRequestTest, + Run_KeyAvailableEqualToTrue_StateAvailable_CacheIsAbsnet) { const bool is_vr_cooperating_available = true; const bool is_send_message_to_hmi = true; const bool is_message_contain_param = true; Event event(hmi_apis::FunctionID::VR_IsReady); PrepareEvent(is_message_contain_param, event, is_vr_cooperating_available); + HMICapabilitiesExpectations(); SetUpExpectations(is_vr_cooperating_available, is_send_message_to_hmi, is_message_contain_param, @@ -169,9 +188,10 @@ TEST_F(VRIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { command_->on_event(event); } -TEST_F(VRIsReadyRequestTest, Run_HMIDoestRespond_SendMessageToHMIByTimeout) { - const bool is_send_message_by_timeout = true; - ExpectSendMessagesToHMI(is_send_message_by_timeout); +TEST_F(VRIsReadyRequestTest, + Run_HMIDoestRespond_SendMessageToHMIByTimeout_CacheIsAbsent) { + HMICapabilitiesExpectations(); + ExpectSendMessagesToHMI(); command_->onTimeOut(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/change_registration_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/change_registration_test.cc index 4394c6fe5e..9736bb380b 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/change_registration_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/change_registration_test.cc @@ -103,11 +103,11 @@ class ChangeRegistrationRequestTest (*supported_languages_)[0] = static_cast<int32_t>(mobile_apis::Language::EN_US); EXPECT_CALL(mock_hmi_capabilities_, ui_supported_languages()) - .WillOnce(Return(supported_languages_.get())); + .WillOnce(Return(supported_languages_)); EXPECT_CALL(mock_hmi_capabilities_, vr_supported_languages()) - .WillOnce(Return(supported_languages_.get())); + .WillOnce(Return(supported_languages_)); EXPECT_CALL(mock_hmi_capabilities_, tts_supported_languages()) - .WillOnce(Return(supported_languages_.get())); + .WillOnce(Return(supported_languages_)); EXPECT_CALL(app_mngr_, hmi_interfaces()) .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); @@ -242,11 +242,11 @@ class ChangeRegistrationRequestTest void ExpectationsHmiCapabilities( smart_objects::SmartObjectSPtr supported_languages) { EXPECT_CALL(mock_hmi_capabilities_, ui_supported_languages()) - .WillOnce(Return(supported_languages.get())); + .WillOnce(Return(supported_languages)); EXPECT_CALL(mock_hmi_capabilities_, vr_supported_languages()) - .WillOnce(Return(supported_languages.get())); + .WillOnce(Return(supported_languages)); EXPECT_CALL(mock_hmi_capabilities_, tts_supported_languages()) - .WillOnce(Return(supported_languages.get())); + .WillOnce(Return(supported_languages)); } void ResultCommandExpectations(MessageSharedPtr msg, @@ -381,11 +381,11 @@ TEST_F(ChangeRegistrationRequestTest, (*supported_languages_)[0] = static_cast<int32_t>(mobile_apis::Language::EN_US); EXPECT_CALL(mock_hmi_capabilities_, ui_supported_languages()) - .WillOnce(Return(supported_languages_.get())); + .WillOnce(Return(supported_languages_)); EXPECT_CALL(mock_hmi_capabilities_, vr_supported_languages()) - .WillOnce(Return(supported_languages_.get())); + .WillOnce(Return(supported_languages_)); EXPECT_CALL(mock_hmi_capabilities_, tts_supported_languages()) - .WillOnce(Return(supported_languages_.get())); + .WillOnce(Return(supported_languages_)); EXPECT_CALL(app_mngr_, hmi_interfaces()) .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc index aa48e8916b..e4536ddeea 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc @@ -351,6 +351,7 @@ TYPED_TEST(OnButtonNotificationCommandsTest, Run_SUCCESS) { .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL)); ON_CALL(*mock_app, IsFullscreen()).WillByDefault(Return(true)); + ON_CALL(this->app_mngr_, application(kAppId)).WillByDefault(Return(mock_app)); EXPECT_CALL(this->app_mngr_, applications_by_button(kButtonName)) .WillOnce(Return(subscribed_apps_list)); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc index 83958954cd..ec401ae2a8 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc @@ -59,19 +59,40 @@ using sdl_rpc_plugin::commands::OnWayPointChangeNotification; typedef std::shared_ptr<OnWayPointChangeNotification> NotificationPtr; namespace { -const uint32_t kAppId = 1u; +const uint32_t kApp1Id = 1u; +const uint32_t kApp2Id = 2u; } // namespace class OnWayPointChangeNotificationTest : public CommandsTest<CommandsTestMocks::kIsNice> { public: - OnWayPointChangeNotificationTest() - : command_(CreateCommand<OnWayPointChangeNotification>()) {} + OnWayPointChangeNotificationTest() {} + + void SetUp() OVERRIDE { + command_ = CreateCommand(); + } + + std::shared_ptr<OnWayPointChangeNotification> CreateCommand() { + InitCommand(CommandsTest<CommandsTestMocks::kIsNice>::kDefaultTimeout_); + message_ = CreateMessage(); + return std::make_shared<OnWayPointChangeNotification>( + message_, + app_mngr_, + mock_rpc_service_, + mock_hmi_capabilities_, + mock_policy_handler_); + } + + MessageSharedPtr CreateMessage( + const smart_objects::SmartType type = smart_objects::SmartType_Null) { + return std::make_shared<SmartObject>(type); + } NotificationPtr command_; + MessageSharedPtr message_; }; -MATCHER(CheckMessageData, "") { +MATCHER_P(CheckMessageData, appID, "") { const bool kIsMobileProtocolTypeCorrect = (*arg)[am::strings::params][am::strings::protocol_type].asInt() == am::commands::CommandImpl::mobile_protocol_type_; @@ -86,7 +107,7 @@ MATCHER(CheckMessageData, "") { const bool kIsConnectionKeyCorrect = (*arg)[am::strings::params][am::strings::connection_key].asUInt() == - kAppId; + appID; using namespace helpers; return Compare<bool, EQ, ALL>(true, @@ -99,11 +120,42 @@ MATCHER(CheckMessageData, "") { TEST_F(OnWayPointChangeNotificationTest, Run_NotEmptyListOfAppsSubscribedForWayPoints_SUCCESS) { std::set<uint32_t> apps_subscribed_for_way_points; - apps_subscribed_for_way_points.insert(kAppId); + apps_subscribed_for_way_points.insert(kApp1Id); EXPECT_CALL(app_mngr_, GetAppsSubscribedForWayPoints()) .WillOnce(Return(apps_subscribed_for_way_points)); - EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(CheckMessageData(), _)); + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageData(kApp1Id), _)); + + command_->Run(); +} + +TEST_F(OnWayPointChangeNotificationTest, + Run_StoreWayPointsDuringNotification_SUCCESS) { + std::set<uint32_t> apps_subscribed_for_way_points; + apps_subscribed_for_way_points.insert(kApp1Id); + + EXPECT_CALL(app_mngr_, GetAppsSubscribedForWayPoints()) + .WillOnce(Return(apps_subscribed_for_way_points)); + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageData(kApp1Id), _)); + EXPECT_CALL(app_mngr_, SaveWayPointsMessage(message_)); + + command_->Run(); +} + +TEST_F(OnWayPointChangeNotificationTest, + Run_BroadcastingWayPointsToAllApps_SUCCESS) { + std::set<uint32_t> apps_subscribed_for_way_points; + apps_subscribed_for_way_points.insert(kApp1Id); + apps_subscribed_for_way_points.insert(kApp2Id); + + EXPECT_CALL(app_mngr_, GetAppsSubscribedForWayPoints()) + .WillOnce(Return(apps_subscribed_for_way_points)); + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageData(kApp1Id), _)); + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageData(kApp2Id), _)); command_->Run(); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc index 6376570106..a42aa61400 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc @@ -201,6 +201,8 @@ class RegisterAppInterfaceRequestTest .WillByDefault(Return(smart_objects::SmartObjectSPtr())); ON_CALL(mock_hmi_capabilities_, pcm_stream_capabilities()) .WillByDefault(Return(smart_objects::SmartObjectSPtr())); + ON_CALL(mock_hmi_capabilities_, seat_location_capability()) + .WillByDefault(Return(smart_objects::SmartObjectSPtr())); ON_CALL(app_mngr_settings_, supported_diag_modes()) .WillByDefault(ReturnRef(kDummyDiagModes)); ON_CALL(mock_policy_handler_, GetAppRequestTypes(_, _)) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/reset_global_properties_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/reset_global_properties_test.cc index 98c0ad098a..4b43c302e4 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/reset_global_properties_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/reset_global_properties_test.cc @@ -139,8 +139,21 @@ TEST_F(ResetGlobalPropertiesRequestTest, Run_InvalidVrHelp_UNSUCCESS) { mobile_apis::GlobalProperty::KEYBOARDPROPERTIES; EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + std::vector<std::string> help_prompt = {"help_prompt"}; + + EXPECT_CALL(app_mngr_settings_, help_prompt()) + .WillOnce(ReturnRef(help_prompt)); + + smart_objects::SmartObject so_help_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Map); + so_help_prompt[am::strings::text] = help_prompt[0]; + so_help_prompt[am::strings::type] = + hmi_apis::Common_SpeechCapabilities::SC_TEXT; + smart_objects::SmartObject so_prompt = smart_objects::SmartObject(smart_objects::SmartType_Array); + so_prompt[0] = so_help_prompt; + EXPECT_CALL(*mock_app_, set_help_prompt(so_prompt)); std::vector<std::string> time_out_prompt; @@ -161,6 +174,15 @@ TEST_F(ResetGlobalPropertiesRequestTest, Run_InvalidVrHelp_UNSUCCESS) { EXPECT_CALL(*mock_app_, set_timeout_prompt(so_time_out_prompt)); + std::string vr_help_title("vr_help_title"); + EXPECT_CALL(app_mngr_settings_, vr_help_title()) + .WillOnce(ReturnRef(vr_help_title)); + + smart_objects::SmartObject so_vr_help_title = + smart_objects::SmartObject(smart_objects::SmartType_String); + so_vr_help_title = vr_help_title; + EXPECT_CALL(*mock_app_, set_vr_help_title(so_vr_help_title)); + EXPECT_CALL(*mock_app_, reset_vr_help_title()); EXPECT_CALL(*mock_app_, reset_vr_help()); @@ -190,8 +212,21 @@ TEST_F(ResetGlobalPropertiesRequestTest, Run_SUCCESS) { mobile_apis::GlobalProperty::KEYBOARDPROPERTIES; EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + + std::vector<std::string> help_prompt = {"help_prompt"}; + + EXPECT_CALL(app_mngr_settings_, help_prompt()) + .WillOnce(ReturnRef(help_prompt)); + + smart_objects::SmartObject so_help_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Map); + so_help_prompt[am::strings::text] = help_prompt[0]; + so_help_prompt[am::strings::type] = + hmi_apis::Common_SpeechCapabilities::SC_TEXT; + smart_objects::SmartObject so_prompt = smart_objects::SmartObject(smart_objects::SmartType_Array); + so_prompt[0] = so_help_prompt; EXPECT_CALL(*mock_app_, set_help_prompt(so_prompt)); std::vector<std::string> time_out_prompt; @@ -212,6 +247,15 @@ TEST_F(ResetGlobalPropertiesRequestTest, Run_SUCCESS) { EXPECT_CALL(*mock_app_, set_timeout_prompt(so_time_out_prompt)); + std::string vr_help_title("vr_help_title"); + EXPECT_CALL(app_mngr_settings_, vr_help_title()) + .WillOnce(ReturnRef(vr_help_title)); + + smart_objects::SmartObject so_vr_help_title = + smart_objects::SmartObject(smart_objects::SmartType_String); + so_vr_help_title = vr_help_title; + EXPECT_CALL(*mock_app_, set_vr_help_title(so_vr_help_title)); + EXPECT_CALL(*mock_app_, reset_vr_help_title()); EXPECT_CALL(*mock_app_, reset_vr_help()); @@ -230,12 +274,8 @@ TEST_F(ResetGlobalPropertiesRequestTest, Run_SUCCESS) { EXPECT_CALL(*mock_app_, set_menu_title(msg_params[am::hmi_request::menu_title])); - const smart_objects::SmartObjectSPtr so_help_prompt = - std::make_shared<smart_objects::SmartObject>( - smart_objects::SmartType_Map); - EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(so_help_prompt.get())); - EXPECT_CALL(*mock_app_, timeout_prompt()) - .WillOnce(Return(so_help_prompt.get())); + EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(&so_help_prompt)); + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(&so_help_prompt)); EXPECT_CALL( mock_rpc_service_, @@ -267,6 +307,15 @@ TEST_F(ResetGlobalPropertiesRequestTest, (*msg_)[am::strings::msg_params][am::strings::properties][0] = mobile_apis::GlobalProperty::VRHELPTITLE; + std::string vr_help_title("vr_help_title"); + EXPECT_CALL(app_mngr_settings_, vr_help_title()) + .WillOnce(ReturnRef(vr_help_title)); + + smart_objects::SmartObject so_vr_help_title = + smart_objects::SmartObject(smart_objects::SmartType_String); + so_vr_help_title = vr_help_title; + EXPECT_CALL(*mock_app_, set_vr_help_title(so_vr_help_title)); + EXPECT_CALL(*mock_app_, reset_vr_help_title()); EXPECT_CALL(*mock_app_, reset_vr_help()); EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); @@ -363,6 +412,15 @@ TEST_F(ResetGlobalPropertiesRequestTest, OnEvent_InvalidApp_NoHashUpdate) { (*msg_)[am::strings::msg_params][am::strings::properties][0] = mobile_apis::GlobalProperty::VRHELPTITLE; + std::string vr_help_title("vr_help_title"); + EXPECT_CALL(app_mngr_settings_, vr_help_title()) + .WillOnce(ReturnRef(vr_help_title)); + + smart_objects::SmartObject so_vr_help_title = + smart_objects::SmartObject(smart_objects::SmartType_String); + so_vr_help_title = vr_help_title; + EXPECT_CALL(*mock_app_, set_vr_help_title(so_vr_help_title)); + EXPECT_CALL(*mock_app_, reset_vr_help_title()); EXPECT_CALL(*mock_app_, reset_vr_help()); diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_type_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_type_request.h index 7f2e8389ad..74f12c07d4 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_type_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_get_vehicle_type_request.h @@ -59,10 +59,9 @@ class VIGetVehicleTypeRequest : public app_mngr::commands::RequestToHMI { **/ virtual ~VIGetVehicleTypeRequest(); - /** - * @brief Execute command - **/ - virtual void Run(); + void Run() OVERRIDE; + + void onTimeOut() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(VIGetVehicleTypeRequest); diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_is_ready_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_is_ready_request.h index fa9bfebad4..96f8c8ecb8 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_is_ready_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/hmi/vi_is_ready_request.h @@ -75,11 +75,6 @@ class VIIsReadyRequest : public app_mngr::commands::RequestToHMI, */ void onTimeOut() OVERRIDE; - /** - * @brief Send request to HMI for fetching of cappabilities - */ - void SendMessageToHMI(); - private: DISALLOW_COPY_AND_ASSIGN(VIIsReadyRequest); }; diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/subscribe_vehicle_data_request.h b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/subscribe_vehicle_data_request.h index deac8a8295..663e64f2a0 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/subscribe_vehicle_data_request.h +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/mobile/subscribe_vehicle_data_request.h @@ -108,9 +108,8 @@ class SubscribeVehicleDataRequest * @param app Pointer to application sent subscribe request * @param msg_params 'message_parameters' response section reference */ - bool SubscribePendingVehicleData( - app_mngr::ApplicationSharedPtr app, - const smart_objects::SmartObject& msg_params); + bool SubscribePendingVehicleData(app_mngr::ApplicationSharedPtr app, + smart_objects::SmartObject& msg_params); /** * @brief Checks if current application and other applications diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_data_response.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_data_response.cc index 6a60cc968e..763ddf1cfa 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_data_response.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_data_response.cc @@ -55,32 +55,14 @@ void VIGetVehicleDataResponse::Run() { event_engine::Event event(hmi_apis::FunctionID::VehicleInfo_GetVehicleData); - if ((*message_)[strings::params][strings::message_type] == - static_cast<int32_t>(hmi_apis::messageType::error_response)) { - smart_objects::SmartObject result(smart_objects::SmartType_Map); - - if ((*message_)[strings::params].keyExists(strings::data)) { - result[strings::msg_params] = (*message_)[strings::params][strings::data]; - result[strings::params][hmi_response::code] = - (*message_)[strings::params][hmi_response::code]; - result[strings::params][strings::correlation_id] = - (*message_)[strings::params][strings::correlation_id]; - result[strings::params][strings::error_msg] = - (*message_)[strings::params][strings::error_msg]; - result[strings::params][strings::message_type] = - (*message_)[strings::params][strings::message_type]; - result[strings::params][strings::protocol_type] = - (*message_)[strings::params][strings::protocol_type]; - result[strings::params][strings::protocol_version] = - (*message_)[strings::params][strings::protocol_version]; - } - - event.set_smart_object(result); - } else { - event.set_smart_object(*message_); + const bool error_response = + (*message_)[strings::params][strings::message_type] == + static_cast<int32_t>(hmi_apis::messageType::error_response); + if (!error_response) { policy_handler_.OnVehicleDataUpdated(*message_); } + event.set_smart_object(*message_); event.raise(application_manager_.event_dispatcher()); } diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_request.cc index 250584bd12..e8df12ca5c 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_request.cc @@ -54,6 +54,12 @@ void VIGetVehicleTypeRequest::Run() { SendRequest(); } +void VIGetVehicleTypeRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VehicleInfo_GetVehicleType); +} + } // namespace commands } // namespace vehicle_info_plugin diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_response.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_response.cc index fb6eadf747..dcc73d26f3 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_response.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_get_vehicle_type_response.cc @@ -50,10 +50,29 @@ VIGetVehicleTypeResponse::~VIGetVehicleTypeResponse() {} void VIGetVehicleTypeResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); - HMICapabilities& hmi_capabilities = hmi_capabilities_; + const auto result_code = static_cast<hmi_apis::Common_Result::eType>( + (*message_)[strings::params][hmi_response::code].asInt()); - hmi_capabilities.set_vehicle_type( + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VehicleInfo_GetVehicleType); + + if (hmi_apis::Common_Result::SUCCESS != result_code) { + LOG4CXX_DEBUG(logger_, + "Request was not successful. Don't change HMI capabilities"); + return; + } + + std::vector<std::string> sections_to_update{hmi_response::vehicle_type}; + hmi_capabilities_.set_vehicle_type( (*message_)[strings::msg_params][hmi_response::vehicle_type]); + + if (!hmi_capabilities_.SaveCachedCapabilitiesToFile( + hmi_interface::vehicle_info, + sections_to_update, + message_->getSchema())) { + LOG4CXX_ERROR( + logger_, "Failed to save VehicleInfo.GetVehicleType response to cache"); + } } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_is_ready_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_is_ready_request.cc index 93781a7420..3525be059d 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_is_ready_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/hmi/vi_is_ready_request.cc @@ -31,7 +31,9 @@ */ #include "vehicle_info_plugin/commands/hmi/vi_is_ready_request.h" -#include "application_manager/message_helper.h" + +#include <set> + #include "application_manager/policies/policy_handler_interface.h" #include "application_manager/rpc_service.h" @@ -79,10 +81,12 @@ void VIIsReadyRequest::on_event(const event_engine::Event& event) { LOG4CXX_INFO( logger_, "HmiInterfaces::HMI_INTERFACE_VehicleInfo isn't available"); + hmi_capabilities_.UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VehicleInfo_GetVehicleType); return; } - SendMessageToHMI(); + RequestInterfaceCapabilities(hmi_interface ::vehicle_info); break; } default: { @@ -94,15 +98,7 @@ void VIIsReadyRequest::on_event(const event_engine::Event& event) { void VIIsReadyRequest::onTimeOut() { // Note(dtrunov): According to new requirment APPLINK-27956 - SendMessageToHMI(); -} - -void VIIsReadyRequest::SendMessageToHMI() { - std::shared_ptr<smart_objects::SmartObject> get_type( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::VehicleInfo_GetVehicleType, - application_manager_)); - rpc_service_.ManageHMICommand(get_type); + RequestInterfaceCapabilities(hmi_interface ::vehicle_info); } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/subscribe_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/subscribe_vehicle_data_request.cc index b125a7de7d..36d972d5fd 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/subscribe_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/commands/mobile/subscribe_vehicle_data_request.cc @@ -36,6 +36,8 @@ #include "utils/helpers.h" #include "vehicle_info_plugin/vehicle_info_app_extension.h" +namespace VD_ResultCode = hmi_apis::Common_VehicleDataResultCode; + namespace vehicle_info_plugin { using namespace application_manager; namespace commands { @@ -189,9 +191,8 @@ bool SubscribeVehicleDataRequest::CheckSubscriptionStatus( } auto res_code = msg_params[vi_name][strings::result_code].asInt(); - if (hmi_apis::Common_VehicleDataResultCode::VDRC_SUCCESS != res_code && - hmi_apis::Common_VehicleDataResultCode::VDRC_DATA_ALREADY_SUBSCRIBED != - res_code) { + if (VD_ResultCode::VDRC_SUCCESS != res_code && + VD_ResultCode::VDRC_DATA_ALREADY_SUBSCRIBED != res_code) { LOG4CXX_WARN(logger_, "Subscription to " << vi_name << " for " << connection_key() << " failed."); @@ -201,20 +202,39 @@ bool SubscribeVehicleDataRequest::CheckSubscriptionStatus( } bool SubscribeVehicleDataRequest::SubscribePendingVehicleData( - ApplicationSharedPtr app, const smart_objects::SmartObject& msg_params) { + ApplicationSharedPtr app, smart_objects::SmartObject& msg_params) { LOG4CXX_DEBUG(logger_, "Subscribing to all pending VehicleData"); - for (const auto& vi_name : vi_waiting_for_subscribe_) { + std::set<hmi_apis::Common_VehicleDataResultCode::eType> skiped_result_codes( + {VD_ResultCode::VDRC_TRUNCATED_DATA, + VD_ResultCode::VDRC_DISALLOWED, + VD_ResultCode::VDRC_USER_DISALLOWED, + VD_ResultCode::VDRC_INVALID_ID, + VD_ResultCode::VDRC_DATA_NOT_AVAILABLE, + VD_ResultCode::VDRC_DATA_NOT_SUBSCRIBED, + VD_ResultCode::VDRC_IGNORED}); + + for (auto vi_name = vi_waiting_for_subscribe_.begin(); + vi_name != vi_waiting_for_subscribe_.end();) { const bool is_subscription_successful = CheckSubscriptionStatus( - ConvertRequestToResponseName(vi_name), msg_params); + ConvertRequestToResponseName(*vi_name), msg_params); if (is_subscription_successful) { auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); - ext.subscribeToVehicleInfo(vi_name); - vi_waiting_for_subscribe_.erase(vi_name); + ext.subscribeToVehicleInfo(*vi_name); + vi_name = vi_waiting_for_subscribe_.erase(vi_name); + } else { + auto res_code = + static_cast<hmi_apis::Common_VehicleDataResultCode::eType>( + msg_params[*vi_name][strings::result_code].asInt()); + if (skiped_result_codes.find(res_code) != skiped_result_codes.end()) { + msg_params[*vi_name][strings::result_code] = res_code; + vi_name = vi_waiting_for_subscribe_.erase(vi_name); + } else { + ++vi_name; + } } } - return vi_waiting_for_subscribe_.empty(); } diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc index 3e8ef6b29d..1c553fb84d 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/src/vehicle_info_plugin.cc @@ -154,28 +154,50 @@ void VehicleInfoPlugin::UnsubscribeFromRemovedVDItems() { application_manager_->GetRPCService().ManageHMICommand(message); } +bool IsOtherAppAlreadySubscribedFor( + const std::string& ivi_name, + const application_manager::ApplicationManager& app_mngr, + const uint32_t current_app_id) { + auto applications = app_mngr.applications(); + + for (auto& app : applications.GetData()) { + auto& ext = VehicleInfoAppExtension::ExtractVIExtension(*app); + if (ext.isSubscribedToVehicleInfo(ivi_name) && + (app->app_id() != current_app_id)) { + return true; + } + } + return false; +} + void VehicleInfoPlugin::ProcessResumptionSubscription( application_manager::Application& app, VehicleInfoAppExtension& ext) { LOG4CXX_AUTO_TRACE(logger_); smart_objects::SmartObject msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[strings::app_id] = app.app_id(); + const auto& subscriptions = ext.Subscriptions(); + if (subscriptions.empty()) { LOG4CXX_DEBUG(logger_, "No vehicle data to subscribe. Exiting"); return; } - for (const auto& item : subscriptions) { - msg_params[item] = true; + for (auto& ivi : subscriptions) { + if (!IsOtherAppAlreadySubscribedFor( + ivi, *application_manager_, app.app_id())) { + msg_params[ivi] = true; + } } - smart_objects::SmartObjectSPtr request = - application_manager::MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::VehicleInfo_SubscribeVehicleData, - *application_manager_); - (*request)[strings::msg_params] = msg_params; - application_manager_->GetRPCService().ManageHMICommand(request); + if (!msg_params.empty()) { + auto request = application_manager::MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::VehicleInfo_SubscribeVehicleData, + *application_manager_); + msg_params[strings::app_id] = app.app_id(); + (*request)[strings::msg_params] = msg_params; + application_manager_->GetRPCService().ManageHMICommand(request); + } } application_manager::ApplicationSharedPtr FindAppSubscribedToIVI( diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc index 45bc748df4..48df3d03bd 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc @@ -70,7 +70,7 @@ typedef std::shared_ptr<VIGetVehicleDataResponse> VIGetVehicleDataResponsePtr; namespace { const uint32_t kConnectionKey = 2u; const uint32_t kCorrelationId = 1u; -const std::string kStrNumber = "123"; +const std::string kStrNumber{"123"}; } // namespace class VIGetVehicleDataResponseTest @@ -97,10 +97,12 @@ TEST_F(VIGetVehicleDataResponseTest, RUN_SUCCESS) { .WillOnce(ReturnRef(mock_event_dispatcher)); EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + ASSERT_TRUE(command->Init()); command->Run(); } -TEST_F(VIGetVehicleDataResponseTest, ErrorResponse_SUCCESS) { +TEST_F(VIGetVehicleDataResponseTest, + ErrorResponse_OnVehicleDataUpdated_NotCalled) { MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); (*command_msg)[strings::msg_params][strings::number] = kStrNumber; (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; @@ -108,7 +110,7 @@ TEST_F(VIGetVehicleDataResponseTest, ErrorResponse_SUCCESS) { hmi_apis::messageType::error_response; (*command_msg)[strings::params][strings::data][strings::slider_position] = 1; (*command_msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; + hmi_apis::Common_Result::ABORTED; (*command_msg)[strings::params][strings::correlation_id] = kCorrelationId; (*command_msg)[am::strings::params][am::strings::error_msg] = "test_error"; (*command_msg)[am::strings::params][am::strings::protocol_type] = @@ -116,33 +118,18 @@ TEST_F(VIGetVehicleDataResponseTest, ErrorResponse_SUCCESS) { (*command_msg)[strings::params][strings::protocol_version] = am::commands::CommandImpl::protocol_version_; - smart_objects::SmartObject result(smart_objects::SmartType_Map); - result[strings::msg_params] = (*command_msg)[strings::params][strings::data]; - result[strings::params][hmi_response::code] = - (*command_msg)[strings::params][hmi_response::code]; - result[strings::params][strings::correlation_id] = - (*command_msg)[strings::params][strings::correlation_id]; - result[strings::params][strings::error_msg] = - (*command_msg)[strings::params][strings::error_msg]; - result[strings::params][strings::message_type] = - (*command_msg)[strings::params][strings::message_type]; - result[strings::params][strings::protocol_type] = - (*command_msg)[strings::params][strings::protocol_type]; - result[strings::params][strings::protocol_version] = - (*command_msg)[strings::params][strings::protocol_version]; - VIGetVehicleDataResponsePtr command( CreateCommandVI<VIGetVehicleDataResponse>(command_msg)); - am::event_engine::Event event( - hmi_apis::FunctionID::VehicleInfo_GetVehicleData); - event.set_smart_object(result); + EXPECT_CALL(mock_policy_handler_, OnVehicleDataUpdated(*command_msg)) + .Times(0); MockEventDispatcher mock_event_dispatcher; EXPECT_CALL(app_mngr_, event_dispatcher()) .WillOnce(ReturnRef(mock_event_dispatcher)); EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + ASSERT_TRUE(command->Init()); command->Run(); } diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_type_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_type_request_test.cc new file mode 100644 index 0000000000..20bf34f2ca --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_type_request_test.cc @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2020, 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 "hmi/vi_get_vehicle_type_request.h" + +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" +#include "vehicle_info_plugin/commands/vi_command_request_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vi_get_vehicle_type_request { + +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using ::testing::_; +using vehicle_info_plugin::commands::VIGetVehicleTypeRequest; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber{"123"}; +} // namespace + +class VIGetVehicleTypeRequestTest + : public VICommandRequestTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + auto command_msg = CreateMessage(smart_objects::SmartType_Map); + (*command_msg)[am::strings::msg_params][am::strings::number] = kStrNumber; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + return command_msg; + } +}; + +TEST_F(VIGetVehicleTypeRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + auto command = CreateCommandVI<VIGetVehicleTypeRequest>(command_msg); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F( + VIGetVehicleTypeRequestTest, + onTimeOut_VIGetVehicleTypeRequestTimeoutExpired_UpdateRequestsRequiredForVIGetVehicleType) { + MessageSharedPtr command_msg = CreateCommandMsg(); + auto command(CreateCommandVI<VIGetVehicleTypeRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VehicleInfo_GetVehicleType)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); +} + +} // namespace vi_get_vehicle_type_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_type_response_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_type_response_test.cc new file mode 100644 index 0000000000..8239905df7 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_type_response_test.cc @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2020, 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 "hmi/vi_get_vehicle_type_response.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/application.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/response_from_hmi.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" +#include "vehicle_info_plugin/commands/vi_command_request_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vi_get_vehicle_type_response { + +using ::testing::_; +using ::testing::NiceMock; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +namespace hmi_interface = ::application_manager::hmi_interface; +using vehicle_info_plugin::commands::VIGetVehicleTypeResponse; + +typedef std::shared_ptr<VIGetVehicleTypeResponse> VIGetVehicleTypeResponsePtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kVehicleType{"vehicle_type"}; +} // namespace + +class VIGetVehicleTypeResponseTest + : public VICommandRequestTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(VIGetVehicleTypeResponseTest, + RUN_ResultCodeSuccess_ChangeHMICapabilities) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][hmi_response::vehicle_type] = kVehicleType; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + VIGetVehicleTypeResponsePtr command = + CreateCommandVI<VIGetVehicleTypeResponse>(command_msg); + + EXPECT_CALL( + mock_hmi_capabilities_, + set_vehicle_type( + (*command_msg)[strings::msg_params][hmi_response::vehicle_type])); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::vehicle_info, _, _)); + ASSERT_TRUE(command->Init()); + + command->Run(); + EXPECT_TRUE((*command_msg)[am::strings::msg_params].keyExists( + hmi_response::vehicle_type)); +} + +TEST_F(VIGetVehicleTypeResponseTest, + RUN_ResultCodeNotSuccess_DontChangeHMICapabilities) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + (*command_msg)[strings::params][hmi_response::vehicle_type] = kVehicleType; + + VIGetVehicleTypeResponsePtr command = + CreateCommandVI<VIGetVehicleTypeResponse>(command_msg); + + EXPECT_CALL(mock_hmi_capabilities_, set_vehicle_type(_)).Times(0); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_FALSE((*command_msg)[am::strings::msg_params].keyExists( + hmi_response::vehicle_type)); +} + +TEST_F(VIGetVehicleTypeResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + VIGetVehicleTypeResponsePtr command = + CreateCommandVI<VIGetVehicleTypeResponse>(command_msg); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VehicleInfo_GetVehicleType)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +} // namespace vi_get_vehicle_type_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc index c083bf4d60..f207faad77 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc @@ -32,6 +32,9 @@ #include "hmi/vi_is_ready_request.h" +#include <memory> +#include <set> + #include "gtest/gtest.h" #include "application_manager/event_engine/event.h" @@ -55,25 +58,32 @@ using ::testing::_; using ::testing::Return; using ::testing::ReturnRef; namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; using am::commands::MessageSharedPtr; +using am::commands::RequestToHMI; using am::event_engine::Event; using vehicle_info_plugin::commands::VIIsReadyRequest; typedef std::shared_ptr<VIIsReadyRequest> VIIsReadyRequestPtr; +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + class VIIsReadyRequestTest : public VICommandRequestTest<CommandsTestMocks::kIsNice> { public: VIIsReadyRequestTest() : command_(CreateCommandVI<VIIsReadyRequest>()) {} void SetUpExpectations(bool is_vi_cooperating_available, - bool is_send_message_to_hmi, - bool is_message_contain_param, + bool should_message_be_sent, + bool message_contains_param, am::HmiInterfaces::InterfaceState state) { EXPECT_CALL(mock_hmi_capabilities_, set_is_ivi_cooperating(is_vi_cooperating_available)); - if (is_message_contain_param) { + if (message_contains_param) { EXPECT_CALL(app_mngr_, hmi_interfaces()) .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); EXPECT_CALL(mock_hmi_interfaces_, @@ -90,7 +100,7 @@ class VIIsReadyRequestTest GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VehicleInfo)) .WillOnce(Return(state)); - if (is_send_message_to_hmi) { + if (should_message_be_sent) { ExpectSendMessagesToHMI(); } } @@ -104,61 +114,102 @@ class VIIsReadyRequestTest EXPECT_CALL(mock_rpc_service_, ManageHMICommand(ivi_type, _)); } - void PrepareEvent(bool is_message_contain_param, - Event& event, - bool is_vi_cooperating_available = false) { + void PrepareEvent(bool message_contains_param, + bool is_vi_cooperating_available, + Event& out_event) { MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - if (is_message_contain_param) { + if (message_contains_param) { (*msg)[am::strings::msg_params][am::strings::available] = is_vi_cooperating_available; } - event.set_smart_object(*msg); + out_event.set_smart_object(*msg); + } + + void HMICapabilitiesExpectations() { + EXPECT_CALL(mock_hmi_capabilities_, + IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VehicleInfo_GetVehicleType)) + .WillOnce(Return(true)); } VIIsReadyRequestPtr command_; }; +TEST_F(VIIsReadyRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + VIIsReadyRequestPtr command = CreateCommandVI<VIIsReadyRequest>(command_msg); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + TEST_F(VIIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { const bool is_vi_cooperating_available = false; - const bool is_send_message_to_hmi = true; - const bool is_message_contain_param = false; + const bool should_message_be_sent = true; + const bool message_contains_param = false; + const auto state = am::HmiInterfaces::STATE_NOT_RESPONSE; Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); - PrepareEvent(is_message_contain_param, event); + PrepareEvent(message_contains_param, is_vi_cooperating_available, event); + HMICapabilitiesExpectations(); SetUpExpectations(is_vi_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_NOT_RESPONSE); + should_message_be_sent, + message_contains_param, + state); + ASSERT_TRUE(command_->Init()); + + command_->Run(); command_->on_event(event); } TEST_F(VIIsReadyRequestTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { const bool is_vi_cooperating_available = false; - const bool is_send_message_to_hmi = false; - const bool is_message_contain_param = true; + const bool should_message_be_sent = false; + const bool message_contains_param = true; + const auto state = am::HmiInterfaces::STATE_NOT_AVAILABLE; Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); - PrepareEvent(is_message_contain_param, event); + PrepareEvent(message_contains_param, is_vi_cooperating_available, event); SetUpExpectations(is_vi_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_NOT_AVAILABLE); + should_message_be_sent, + message_contains_param, + state); + ASSERT_TRUE(command_->Init()); + + command_->Run(); command_->on_event(event); } TEST_F(VIIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { const bool is_vi_cooperating_available = true; - const bool is_send_message_to_hmi = true; - const bool is_message_contain_param = true; + const bool should_message_be_sent = true; + const bool message_contains_param = true; + const auto state = am::HmiInterfaces::STATE_AVAILABLE; Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); - PrepareEvent(is_message_contain_param, event, is_vi_cooperating_available); + HMICapabilitiesExpectations(); + PrepareEvent(message_contains_param, is_vi_cooperating_available, event); SetUpExpectations(is_vi_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_AVAILABLE); + should_message_be_sent, + message_contains_param, + state); + ASSERT_TRUE(command_->Init()); + + command_->Run(); command_->on_event(event); } TEST_F(VIIsReadyRequestTest, Run_HMIDoestRespond_SendMessageToHMIByTimeout) { + HMICapabilitiesExpectations(); ExpectSendMessagesToHMI(); + ASSERT_TRUE(command_->Init()); + + command_->Run(); command_->onTimeOut(); } diff --git a/src/components/application_manager/src/application_data_impl.cc b/src/components/application_manager/src/application_data_impl.cc index 9f30c00014..a5b5827f2f 100644 --- a/src/components/application_manager/src/application_data_impl.cc +++ b/src/components/application_manager/src/application_data_impl.cc @@ -244,6 +244,21 @@ DynamicApplicationDataImpl::~DynamicApplicationDataImpl() { show_command_ = NULL; } + if (keyboard_props_) { + delete keyboard_props_; + keyboard_props_ = NULL; + } + + if (menu_title_) { + delete menu_title_; + menu_title_ = NULL; + } + + if (menu_icon_) { + delete menu_icon_; + menu_icon_ = NULL; + } + if (tbt_show_command_) { delete tbt_show_command_; tbt_show_command_ = NULL; @@ -263,6 +278,11 @@ DynamicApplicationDataImpl::~DynamicApplicationDataImpl() { } sub_menu_.clear(); + for (auto command : choice_set_map_) { + delete command.second; + } + choice_set_map_.clear(); + PerformChoiceSetMap::iterator it = performinteraction_choice_set_map_.begin(); for (; performinteraction_choice_set_map_.end() != it; ++it) { PerformChoice::iterator choice_it = @@ -568,28 +588,35 @@ void DynamicApplicationDataImpl::set_display_capabilities( display_capabilities_.reset( new smart_objects::SmartObject(display_capabilities)); - auto has_window_id = [&tmp_window_capabilities](const WindowID window_id) { + auto get_window_index = [&tmp_window_capabilities](const WindowID window_id) { const auto tmp_window_capabilities_arr = tmp_window_capabilities.asArray(); if (!tmp_window_capabilities_arr) { - return false; + return -1; } + int index = 0; for (auto element : *tmp_window_capabilities_arr) { if (element.keyExists(strings::window_id)) { if (window_id == element[strings::window_id].asInt()) - return true; + return index; } else if (window_id == 0) { - return true; + return index; } + index++; } - - return false; + return -1; }; for (uint32_t i = 0; i < incoming_window_capabilities.length(); ++i) { - const auto window_id = - incoming_window_capabilities[i][strings::window_id].asInt(); - if (!has_window_id(window_id)) { + int64_t window_id = 0; + if (incoming_window_capabilities[i].keyExists(strings::window_id)) { + window_id = incoming_window_capabilities[i][strings::window_id].asInt(); + } + int found_index = get_window_index(window_id); + if (0 <= found_index) { + // Update the existing window capability + tmp_window_capabilities[found_index] = incoming_window_capabilities[i]; + } else { tmp_window_capabilities[tmp_window_capabilities.length()] = incoming_window_capabilities[i]; } diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 303dca3b65..5e1ae3bc3a 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -257,7 +257,11 @@ ApplicationManagerImpl::~ApplicationManagerImpl() { end_stream_timer_pool_.clear(); } - navi_app_to_stop_.clear(); + { + sync_primitives::AutoLock lock(navi_app_to_stop_lock_); + navi_app_to_stop_.clear(); + } + navi_app_to_end_stream_.clear(); secondary_transport_devices_cache_.clear(); @@ -841,9 +845,8 @@ void ApplicationManagerImpl::ConnectToDevice(const std::string& device_mac) { connection_handler().ConnectToDevice(handle); } -void ApplicationManagerImpl::OnHMIStartedCooperation() { +void ApplicationManagerImpl::OnHMIReady() { LOG4CXX_AUTO_TRACE(logger_); - hmi_cooperating_ = true; #ifdef WEBSOCKET_SERVER_TRANSPORT_SUPPORT connection_handler_->CreateWebEngineDevice(); @@ -851,6 +854,29 @@ void ApplicationManagerImpl::OnHMIStartedCooperation() { MessageHelper::SendGetSystemInfoRequest(*this); + std::shared_ptr<smart_objects::SmartObject> is_navi_ready( + MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::Navigation_IsReady, *this)); + rpc_service_->ManageHMICommand(is_navi_ready); + + std::shared_ptr<smart_objects::SmartObject> mixing_audio_supported_request( + MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::BasicCommunication_MixingAudioSupported, + *this)); + rpc_service_->ManageHMICommand(mixing_audio_supported_request); + resume_controller().ResetLaunchTime(); + + RefreshCloudAppInformation(); + policy_handler_->TriggerPTUOnStartupIfRequired(); +} + +void ApplicationManagerImpl::RequestForInterfacesAvailability() { + LOG4CXX_AUTO_TRACE(logger_); + std::shared_ptr<smart_objects::SmartObject> is_ivi_ready( + MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::VehicleInfo_IsReady, *this)); + rpc_service_->ManageHMICommand(is_ivi_ready); + std::shared_ptr<smart_objects::SmartObject> is_vr_ready( MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::VR_IsReady, *this)); @@ -866,34 +892,18 @@ void ApplicationManagerImpl::OnHMIStartedCooperation() { *this)); rpc_service_->ManageHMICommand(is_ui_ready); - std::shared_ptr<smart_objects::SmartObject> is_navi_ready( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::Navigation_IsReady, *this)); - rpc_service_->ManageHMICommand(is_navi_ready); - - std::shared_ptr<smart_objects::SmartObject> is_ivi_ready( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::VehicleInfo_IsReady, *this)); - rpc_service_->ManageHMICommand(is_ivi_ready); - std::shared_ptr<smart_objects::SmartObject> is_rc_ready( MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::RC_IsReady, *this)); rpc_service_->ManageHMICommand(is_rc_ready); - std::shared_ptr<smart_objects::SmartObject> button_capabilities( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::Buttons_GetCapabilities, *this)); - rpc_service_->ManageHMICommand(button_capabilities); - - std::shared_ptr<smart_objects::SmartObject> mixing_audio_supported_request( - MessageHelper::CreateModuleInfoSO( - hmi_apis::FunctionID::BasicCommunication_MixingAudioSupported, - *this)); - rpc_service_->ManageHMICommand(mixing_audio_supported_request); - resume_controller().ResetLaunchTime(); - - RefreshCloudAppInformation(); + if (hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::Buttons_GetCapabilities)) { + std::shared_ptr<smart_objects::SmartObject> button_capabilities( + MessageHelper::CreateModuleInfoSO( + hmi_apis::FunctionID::Buttons_GetCapabilities, *this)); + rpc_service_->ManageHMICommand(button_capabilities); + } } std::string ApplicationManagerImpl::PolicyIDByIconUrl(const std::string url) { @@ -1466,7 +1476,12 @@ void ApplicationManagerImpl::StartAudioPassThruThread(int32_t session_key, LOG4CXX_INFO(logger_, "START MICROPHONE RECORDER"); DCHECK_OR_RETURN_VOID(media_manager_); media_manager_->StartMicrophoneRecording( - session_key, get_settings().recording_file_name(), max_duration); + session_key, + get_settings().recording_file_name(), + max_duration, + static_cast<mobile_apis::SamplingRate::eType>(sampling_rate), + static_cast<mobile_apis::BitsPerSample::eType>(bits_per_sample), + static_cast<mobile_apis::AudioType::eType>(audio_type)); } void ApplicationManagerImpl::StopAudioPassThru(int32_t application_key) { @@ -1983,18 +1998,29 @@ void ApplicationManagerImpl::OnStreamingConfigured( service_type == ServiceType::kMobileNav ? it->second.first = true : it->second.second = true; - for (size_t i = 0; i < navi_app_to_stop_.size(); ++i) { - if (app_id == navi_app_to_stop_[i]) { - sync_primitives::AutoLock lock(close_app_timer_pool_lock_); - close_app_timer_pool_.erase(close_app_timer_pool_.begin() + i); - navi_app_to_stop_.erase(navi_app_to_stop_.begin() + i); - break; + { + sync_primitives::AutoLock lock(navi_app_to_stop_lock_); + for (size_t i = 0; i < navi_app_to_stop_.size(); ++i) { + if (app_id == navi_app_to_stop_[i]) { + sync_primitives::AutoLock lock(close_app_timer_pool_lock_); + close_app_timer_pool_.erase(close_app_timer_pool_.begin() + i); + navi_app_to_stop_.erase(navi_app_to_stop_.begin() + i); + break; + } } } } application(app_id)->StartStreaming(service_type); connection_handler().NotifyServiceStartedResult(app_id, true, empty); + + // Fix: For wifi Secondary + // Should erase appid from deque of ForbidStreaming() push in the last time + std::deque<uint32_t>::const_iterator iter = std::find( + navi_app_to_end_stream_.begin(), navi_app_to_end_stream_.end(), app_id); + if (navi_app_to_end_stream_.end() != iter) { + navi_app_to_end_stream_.erase(iter); + } } else { std::vector<std::string> converted_params = ConvertRejectedParamList(rejected_params); @@ -2039,6 +2065,22 @@ void ApplicationManagerImpl::StopNaviService( service_type == ServiceType::kMobileNav ? it->second.first = false : it->second.second = false; } + // Fix: For wifi Secondary + // undisposed data active the VPMService restart again, + // because Not set Allowstream flag + ApplicationSharedPtr app = application(app_id); + if (!app || (!app->is_navi() && !app->mobile_projection_enabled())) { + LOG4CXX_ERROR(logger_, "Navi/Projection application not found"); + return; + } + if (service_type == ServiceType::kMobileNav) { + app->set_video_streaming_allowed(false); + } + if (service_type == ServiceType::kAudio) { + app->set_audio_streaming_allowed(false); + } + // push_back for judge in ForbidStreaming(), + StartEndStreamTimer(app_id); } ApplicationSharedPtr app = application(app_id); @@ -2540,8 +2582,12 @@ bool ApplicationManagerImpl::Stop() { stopping_application_mng_lock_.Release(); application_list_update_timer_.Stop(); try { - SetUnregisterAllApplicationsReason( - mobile_api::AppInterfaceUnregisteredReason::IGNITION_OFF); + if (unregister_reason_ == + mobile_api::AppInterfaceUnregisteredReason::INVALID_ENUM) { + SetUnregisterAllApplicationsReason( + mobile_api::AppInterfaceUnregisteredReason::IGNITION_OFF); + } + UnregisterAllApplications(); } catch (...) { LOG4CXX_ERROR(logger_, @@ -2978,7 +3024,9 @@ void ApplicationManagerImpl::HeadUnitReset( GetPolicyHandler().UnloadPolicyLibrary(); resume_controller().StopSavePersistentDataTimer(); - + if (!hmi_capabilities_->DeleteCachedCapabilitiesFile()) { + LOG4CXX_ERROR(logger_, "Failed to remove HMI capabilities cache file"); + } const std::string storage_folder = get_settings().app_storage_folder(); file_system::RemoveDirectory(storage_folder, true); ClearAppsPersistentData(); @@ -2989,7 +3037,9 @@ void ApplicationManagerImpl::HeadUnitReset( GetPolicyHandler().ClearUserConsent(); resume_controller().StopSavePersistentDataTimer(); - + if (!hmi_capabilities_->DeleteCachedCapabilitiesFile()) { + LOG4CXX_ERROR(logger_, "Failed to remove HMI capabilities cache file"); + } ClearAppsPersistentData(); break; } @@ -3088,7 +3138,7 @@ void ApplicationManagerImpl::SendOnSDLClose() { void ApplicationManagerImpl::UnregisterAllApplications() { LOG4CXX_DEBUG(logger_, "Unregister reason " << unregister_reason_); - hmi_cooperating_ = false; + SetHMICooperating(false); bool is_ignition_off = false; using namespace mobile_api::AppInterfaceUnregisteredReason; using namespace helpers; @@ -3175,20 +3225,17 @@ void ApplicationManagerImpl::UnregisterApplication( << "; is_resuming = " << is_resuming << "; is_unexpected_disconnect = " << is_unexpected_disconnect); - size_t subscribed_for_way_points_app_count = 0; GetAppServiceManager().UnpublishServices(app_id); - // SDL sends UnsubscribeWayPoints only for last application - { - sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); - subscribed_for_way_points_app_count = - subscribed_way_points_apps_list_.size(); - } - if (1 == subscribed_for_way_points_app_count) { - LOG4CXX_ERROR(logger_, "Send UnsubscribeWayPoints"); - MessageHelper::SendUnsubscribedWayPoints(*this); + if (IsAppSubscribedForWayPoints(app_id)) { + UnsubscribeAppFromWayPoints(app_id); + if (!IsAnyAppSubscribedForWayPoints()) { + LOG4CXX_ERROR(logger_, "Send UnsubscribeWayPoints"); + MessageHelper::SendUnsubscribedWayPoints(*this); + } } + EndNaviServices(app_id); { sync_primitives::AutoLock lock(navi_service_status_lock_); @@ -3278,6 +3325,11 @@ void ApplicationManagerImpl::UnregisterApplication( RemoveAppsWaitingForRegistration(handle); } } + + MessageHelper::SendOnAppUnregNotificationToHMI( + app_to_remove, is_unexpected_disconnect, *this); + commands_holder_->Clear(app_to_remove); + const auto enabled_local_apps = policy_handler_->GetEnabledLocalApps(); if (helpers::in_range(enabled_local_apps, app_to_remove->policy_app_id())) { LOG4CXX_DEBUG(logger_, @@ -3290,8 +3342,6 @@ void ApplicationManagerImpl::UnregisterApplication( SendUpdateAppList(); } - commands_holder_->Clear(app_to_remove); - if (EndAudioPassThru(app_id)) { // May be better to put this code in MessageHelper? StopAudioPassThru(app_id); @@ -3302,11 +3352,10 @@ void ApplicationManagerImpl::UnregisterApplication( plugin.OnApplicationEvent(plugin_manager::kApplicationUnregistered, app_to_remove); }; - plugin_manager_->ForEachPlugin(on_app_unregistered); - MessageHelper::SendOnAppUnregNotificationToHMI( - app_to_remove, is_unexpected_disconnect, *this); + plugin_manager_->ForEachPlugin(on_app_unregistered); request_ctrl_.terminateAppRequests(app_id); + if (applications_.empty()) { policy_handler_->StopRetrySequence(); } @@ -3479,16 +3528,70 @@ void ApplicationManagerImpl::ForbidStreaming(uint32_t app_id) { return; } - if (navi_app_to_stop_.end() != std::find(navi_app_to_stop_.begin(), - navi_app_to_stop_.end(), - app_id) || - navi_app_to_end_stream_.end() != - std::find(navi_app_to_end_stream_.begin(), - navi_app_to_end_stream_.end(), - app_id)) { + { + sync_primitives::AutoLock lock(navi_app_to_stop_lock_); + if (navi_app_to_stop_.end() != std::find(navi_app_to_stop_.begin(), + navi_app_to_stop_.end(), + app_id) || + navi_app_to_end_stream_.end() != + std::find(navi_app_to_end_stream_.begin(), + navi_app_to_end_stream_.end(), + app_id)) { + return; + } + } + + bool unregister = false; + { + sync_primitives::AutoLock lock(navi_service_status_lock_); + + NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); + if (navi_service_status_.end() == it || + (!it->second.first && !it->second.second)) { + unregister = true; + } + } + if (unregister) { + rpc_service_->ManageMobileCommand( + MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( + app_id, PROTOCOL_VIOLATION), + commands::Command::SOURCE_SDL); + UnregisterApplication(app_id, ABORTED); + return; + } + EndNaviServices(app_id); +} + +void ApplicationManagerImpl::ForbidStreaming( + uint32_t app_id, protocol_handler::ServiceType service_type) { + using namespace mobile_apis::AppInterfaceUnregisteredReason; + using namespace mobile_apis::Result; + using namespace protocol_handler; + + LOG4CXX_AUTO_TRACE(logger_); + + ApplicationSharedPtr app = application(app_id); + if (!app || (!app->is_navi() && !app->mobile_projection_enabled())) { + LOG4CXX_DEBUG( + logger_, + "There is no navi or projection application with id: " << app_id); return; } + { + sync_primitives::AutoLock lock(navi_app_to_stop_lock_); + + if (navi_app_to_stop_.end() != std::find(navi_app_to_stop_.begin(), + navi_app_to_stop_.end(), + app_id) || + navi_app_to_end_stream_.end() != + std::find(navi_app_to_end_stream_.begin(), + navi_app_to_end_stream_.end(), + app_id)) { + return; + } + } + bool unregister = false; { sync_primitives::AutoLock lock(navi_service_status_lock_); @@ -3507,6 +3610,18 @@ void ApplicationManagerImpl::ForbidStreaming(uint32_t app_id) { UnregisterApplication(app_id, ABORTED); return; } + + if (ServiceType::kMobileNav == service_type && + app->video_streaming_allowed()) { + LOG4CXX_DEBUG(logger_, "Video streaming is still allowed"); + return; + } + + if (ServiceType::kAudio == service_type && app->audio_streaming_allowed()) { + LOG4CXX_DEBUG(logger_, "Audio streaming is still allowed"); + return; + } + EndNaviServices(app_id); } @@ -3572,7 +3687,10 @@ void ApplicationManagerImpl::EndNaviServices(uint32_t app_id) { DisallowStreaming(app_id); - navi_app_to_stop_.push_back(app_id); + { + sync_primitives::AutoLock lock(navi_app_to_stop_lock_); + navi_app_to_stop_.push_back(app_id); + } TimerSPtr close_timer(std::make_shared<timer::Timer>( "CloseNaviAppTimer", @@ -3755,16 +3873,21 @@ void ApplicationManagerImpl::ClearTimerPool() { LOG4CXX_AUTO_TRACE(logger_); { sync_primitives::AutoLock lock(close_app_timer_pool_lock_); - std::remove_if(close_app_timer_pool_.begin(), - close_app_timer_pool_.end(), - [](TimerSPtr timer) { return !timer->is_running(); }); + + close_app_timer_pool_.erase( + std::remove_if(close_app_timer_pool_.begin(), + close_app_timer_pool_.end(), + [](TimerSPtr timer) { return !timer->is_running(); }), + close_app_timer_pool_.end()); } { sync_primitives::AutoLock lock(end_stream_timer_pool_lock_); - std::remove_if(end_stream_timer_pool_.begin(), - end_stream_timer_pool_.end(), - [](TimerSPtr timer) { return !timer->is_running(); }); + end_stream_timer_pool_.erase( + std::remove_if(end_stream_timer_pool_.begin(), + end_stream_timer_pool_.end(), + [](TimerSPtr timer) { return !timer->is_running(); }), + end_stream_timer_pool_.end()); } } @@ -3772,9 +3895,14 @@ void ApplicationManagerImpl::CloseNaviApp() { LOG4CXX_AUTO_TRACE(logger_); using namespace mobile_apis::AppInterfaceUnregisteredReason; using namespace mobile_apis::Result; - DCHECK_OR_RETURN_VOID(!navi_app_to_stop_.empty()); - uint32_t app_id = navi_app_to_stop_.front(); - navi_app_to_stop_.pop_front(); + uint32_t app_id; + + { + sync_primitives::AutoLock lock(navi_app_to_stop_lock_); + DCHECK_OR_RETURN_VOID(!navi_app_to_stop_.empty()); + app_id = navi_app_to_stop_.front(); + navi_app_to_stop_.pop_front(); + } bool unregister = false; { @@ -3784,6 +3912,7 @@ void ApplicationManagerImpl::CloseNaviApp() { if (navi_service_status_.end() != it) { if (it->second.first || it->second.second) { unregister = true; + navi_service_status_.erase(it); } } } @@ -3807,9 +3936,13 @@ void ApplicationManagerImpl::EndNaviStreaming() { const uint32_t app_id = navi_app_to_end_stream_.front(); navi_app_to_end_stream_.pop_front(); - if (navi_app_to_stop_.end() == - std::find(navi_app_to_stop_.begin(), navi_app_to_stop_.end(), app_id)) { - DisallowStreaming(app_id); + { + sync_primitives::AutoLock lock(navi_app_to_stop_lock_); + if (navi_app_to_stop_.end() == std::find(navi_app_to_stop_.begin(), + navi_app_to_stop_.end(), + app_id)) { + DisallowStreaming(app_id); + } } } } @@ -3966,13 +4099,23 @@ bool ApplicationManagerImpl::IsHMICooperating() const { return hmi_cooperating_; } +void ApplicationManagerImpl::SetHMICooperating(const bool hmi_cooperating) { + hmi_cooperating_ = hmi_cooperating; +} + void ApplicationManagerImpl::OnApplicationListUpdateTimer() { LOG4CXX_DEBUG(logger_, "Application list update timer finished"); + const bool is_new_app_registered = registered_during_timer_execution_; registered_during_timer_execution_ = false; + apps_to_register_list_lock_ptr_->Acquire(); const bool trigger_ptu = apps_size_ != applications_.size(); apps_to_register_list_lock_ptr_->Release(); - SendUpdateAppList(); + + if (is_new_app_registered) { + SendUpdateAppList(); + } + GetPolicyHandler().OnAppsSearchCompleted(trigger_ptu); } @@ -4505,39 +4648,62 @@ void ApplicationManagerImpl::ClearTTSGlobalPropertiesList() { } bool ApplicationManagerImpl::IsAppSubscribedForWayPoints( - ApplicationSharedPtr app) const { + uint32_t app_id) const { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); LOG4CXX_DEBUG(logger_, "There are applications subscribed: " << subscribed_way_points_apps_list_.size()); - if (subscribed_way_points_apps_list_.find(app->app_id()) == + if (subscribed_way_points_apps_list_.find(app_id) == subscribed_way_points_apps_list_.end()) { return false; } return true; } -void ApplicationManagerImpl::SubscribeAppForWayPoints( - ApplicationSharedPtr app) { +bool ApplicationManagerImpl::IsAppSubscribedForWayPoints( + ApplicationSharedPtr app) const { + return IsAppSubscribedForWayPoints(app->app_id()); +} + +void ApplicationManagerImpl::SubscribeAppForWayPoints(uint32_t app_id) { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); - LOG4CXX_DEBUG(logger_, "Subscribing " << app->app_id()); - subscribed_way_points_apps_list_.insert(app->app_id()); + LOG4CXX_DEBUG(logger_, "Subscribing " << app_id); + subscribed_way_points_apps_list_.insert(app_id); LOG4CXX_DEBUG(logger_, "There are applications subscribed: " << subscribed_way_points_apps_list_.size()); + if (way_points_data_) { + smart_objects::SmartObjectSPtr way_point_notification_ = + std::make_shared<smart_objects::SmartObject>(*way_points_data_); + (*way_point_notification_)[strings::params][strings::connection_key] = + app_id; + GetRPCService().SendMessageToMobile(way_point_notification_); + } } -void ApplicationManagerImpl::UnsubscribeAppFromWayPoints( +void ApplicationManagerImpl::SubscribeAppForWayPoints( ApplicationSharedPtr app) { + SubscribeAppForWayPoints(app->app_id()); +} + +void ApplicationManagerImpl::UnsubscribeAppFromWayPoints(uint32_t app_id) { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); - LOG4CXX_DEBUG(logger_, "Unsubscribing " << app->app_id()); - subscribed_way_points_apps_list_.erase(app->app_id()); + LOG4CXX_DEBUG(logger_, "Unsubscribing " << app_id); + subscribed_way_points_apps_list_.erase(app_id); LOG4CXX_DEBUG(logger_, "There are applications subscribed: " << subscribed_way_points_apps_list_.size()); + if (subscribed_way_points_apps_list_.empty()) { + way_points_data_.reset(); + } +} + +void ApplicationManagerImpl::UnsubscribeAppFromWayPoints( + ApplicationSharedPtr app) { + UnsubscribeAppFromWayPoints(app->app_id()); } bool ApplicationManagerImpl::IsAnyAppSubscribedForWayPoints() const { @@ -4549,6 +4715,12 @@ bool ApplicationManagerImpl::IsAnyAppSubscribedForWayPoints() const { return !subscribed_way_points_apps_list_.empty(); } +void ApplicationManagerImpl::SaveWayPointsMessage( + std::shared_ptr<smart_objects::SmartObject> way_points_message) { + sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); + way_points_data_ = way_points_message; +} + const std::set<uint32_t> ApplicationManagerImpl::GetAppsSubscribedForWayPoints() const { LOG4CXX_AUTO_TRACE(logger_); diff --git a/src/components/application_manager/src/commands/command_impl.cc b/src/components/application_manager/src/commands/command_impl.cc index a9fbff5ece..3872ae45ab 100644 --- a/src/components/application_manager/src/commands/command_impl.cc +++ b/src/components/application_manager/src/commands/command_impl.cc @@ -31,8 +31,10 @@ */ #include "application_manager/commands/command_impl.h" + #include "application_manager/application_impl.h" #include "application_manager/application_manager.h" +#include "application_manager/message_helper.h" namespace application_manager { @@ -109,6 +111,14 @@ uint32_t CommandImpl::connection_key() const { return (*message_)[strings::params][strings::connection_key].asUInt(); } +void CommandImpl::set_warning_info(const std::string info) { + warning_info_ = info; +} + +std::string CommandImpl::warning_info() const { + return warning_info_; +} + void CommandImpl::onTimeOut() {} bool CommandImpl::AllowedToTerminate() { @@ -119,6 +129,111 @@ void CommandImpl::SetAllowedToTerminate(const bool allowed) { allowed_to_terminate_ = allowed; } +bool CommandImpl::CheckAllowedParameters(const Command::CommandSource source) { + LOG4CXX_AUTO_TRACE(logger_); + + const ApplicationSharedPtr app = + application_manager_.application(connection_key()); + if (!app) { + LOG4CXX_ERROR(logger_, + "There is no registered application with " + "connection key '" + << connection_key() << "'"); + return false; + } + + RPCParams params; + + const smart_objects::SmartObject& s_map = (*message_)[strings::msg_params]; + smart_objects::SmartMap::const_iterator iter = s_map.map_begin(); + smart_objects::SmartMap::const_iterator iter_end = s_map.map_end(); + + for (; iter != iter_end; ++iter) { + LOG4CXX_DEBUG(logger_, "Request's param: " << iter->first); + params.insert(iter->first); + } + + mobile_apis::Result::eType check_result = + mobile_apis::Result::eType::INVALID_ID; + const auto current_window_id = window_id(); + if (app->WindowIdExists(current_window_id)) { + check_result = application_manager_.CheckPolicyPermissions( + app, + current_window_id, + MessageHelper::StringifiedFunctionID( + static_cast<mobile_api::FunctionID::eType>(function_id())), + params, + ¶meters_permissions_); + } + + // Check, if RPC is allowed by policy + if (mobile_apis::Result::SUCCESS != check_result) { + mobile_apis::messageType::eType message_type = + static_cast<mobile_apis::messageType::eType>( + (*message_)[strings::params][strings::message_type].asInt()); + if (message_type == mobile_apis::messageType::request && + source == Command::CommandSource::SOURCE_MOBILE) { + smart_objects::SmartObjectSPtr response = + MessageHelper::CreateBlockedByPoliciesResponse( + static_cast<mobile_api::FunctionID::eType>(function_id()), + check_result, + correlation_id(), + app->app_id()); + rpc_service_.SendMessageToMobile(response); + } + + return false; + } + + // If no parameters specified in policy table, no restriction will be + // applied for parameters + if (parameters_permissions_.allowed_params.empty() && + parameters_permissions_.disallowed_params.empty() && + parameters_permissions_.undefined_params.empty()) { + return true; + } + + RemoveDisallowedParameters(); + + return true; +} + +void CommandImpl::RemoveDisallowedParameters() { + LOG4CXX_AUTO_TRACE(logger_); + + smart_objects::SmartObject& params = (*message_)[strings::msg_params]; + + for (const auto& key : params.enumerate()) { + if (parameters_permissions_.disallowed_params.end() != + parameters_permissions_.disallowed_params.find(key)) { + // Remove from request all disallowed parameters + params.erase(key); + removed_parameters_permissions_.disallowed_params.insert(key); + LOG4CXX_INFO(logger_, + "Following parameter is disallowed by user: " << key); + } + + else if (removed_parameters_permissions_.undefined_params.end() != + removed_parameters_permissions_.undefined_params.find(key)) { + // Remove from request all undefined yet parameters + params.erase(key); + removed_parameters_permissions_.undefined_params.insert(key); + LOG4CXX_INFO(logger_, + "Following parameter is disallowed by policy: " << key); + } + + else if (parameters_permissions_.allowed_params.end() == + parameters_permissions_.allowed_params.find(key)) { + // Remove from request all parameters missed in allowed + params.erase(key); + removed_parameters_permissions_.undefined_params.insert(key); + LOG4CXX_INFO(logger_, + "Following parameter is not found among allowed parameters '" + << key << "' and will be treated as disallowed."); + } + } +} + bool CommandImpl::ReplaceMobileWithHMIAppId( ns_smart_device_link::ns_smart_objects::SmartObject& message) { LOG4CXX_AUTO_TRACE(logger_); @@ -223,5 +338,24 @@ uint32_t CommandImpl::CalcCommandInternalConsecutiveNumber( return last_command_number + 1; } +bool CommandImpl::CheckSyntax(const std::string& str, + bool allow_empty_line) const { + if (std::string::npos != str.find_first_of("\t\n")) { + LOG4CXX_ERROR(logger_, "CheckSyntax failed! :" << str); + return false; + } + if (std::string::npos != str.find("\\n") || + std::string::npos != str.find("\\t")) { + LOG4CXX_ERROR(logger_, "CheckSyntax failed! :" << str); + return false; + } + if (!allow_empty_line) { + if ((std::string::npos == str.find_first_not_of(' '))) { + return false; + } + } + return true; +} + } // namespace commands } // namespace application_manager diff --git a/src/components/application_manager/src/commands/command_notification_from_mobile_impl.cc b/src/components/application_manager/src/commands/command_notification_from_mobile_impl.cc index bd4fa58c8f..46c1c87699 100644 --- a/src/components/application_manager/src/commands/command_notification_from_mobile_impl.cc +++ b/src/components/application_manager/src/commands/command_notification_from_mobile_impl.cc @@ -57,6 +57,10 @@ bool CommandNotificationFromMobileImpl::Init() { return true; } +bool CommandNotificationFromMobileImpl::CheckPermissions() { + return CheckAllowedParameters(Command::CommandSource::SOURCE_MOBILE); +} + bool CommandNotificationFromMobileImpl::CleanUp() { return true; } diff --git a/src/components/application_manager/src/commands/command_request_impl.cc b/src/components/application_manager/src/commands/command_request_impl.cc index e9dcd6e4b0..d20039bf70 100644 --- a/src/components/application_manager/src/commands/command_request_impl.cc +++ b/src/components/application_manager/src/commands/command_request_impl.cc @@ -222,7 +222,7 @@ bool CommandRequestImpl::Init() { } bool CommandRequestImpl::CheckPermissions() { - return CheckAllowedParameters(); + return CheckAllowedParameters(Command::CommandSource::SOURCE_MOBILE); } bool CommandRequestImpl::CleanUp() { @@ -298,7 +298,7 @@ void CommandRequestImpl::SendResponse( response[strings::msg_params] = *response_params; } - if (info) { + if (info && *info != '\0') { response[strings::msg_params][strings::info] = std::string(info); } @@ -318,32 +318,23 @@ void CommandRequestImpl::SendResponse( } response[strings::msg_params][strings::success] = success; - response[strings::msg_params][strings::result_code] = result_code; + if ((result_code == mobile_apis::Result::SUCCESS || + result_code == mobile_apis::Result::WARNINGS) && + !warning_info().empty()) { + response[strings::msg_params][strings::info] = + (info && *info != '\0') ? std::string(info) + "\n" + warning_info() + : warning_info(); + response[strings::msg_params][strings::result_code] = + mobile_apis::Result::WARNINGS; + } else { + response[strings::msg_params][strings::result_code] = result_code; + } is_success_result_ = success; rpc_service_.ManageMobileCommand(result, SOURCE_SDL); } -bool CommandRequestImpl::CheckSyntax(const std::string& str, - bool allow_empty_line) { - if (std::string::npos != str.find_first_of("\t\n")) { - LOG4CXX_ERROR(logger_, "CheckSyntax failed! :" << str); - return false; - } - if (std::string::npos != str.find("\\n") || - std::string::npos != str.find("\\t")) { - LOG4CXX_ERROR(logger_, "CheckSyntax failed! :" << str); - return false; - } - if (!allow_empty_line) { - if ((std::string::npos == str.find_first_not_of(' '))) { - return false; - } - } - return true; -} - smart_objects::SmartObject CreateUnsupportedResourceResponse( const hmi_apis::FunctionID::eType function_id, const uint32_t hmi_correlation_id, @@ -691,7 +682,8 @@ mobile_apis::Result::eType CommandRequestImpl::GetMobileResultCode( return mobile_result; } -bool CommandRequestImpl::CheckAllowedParameters() { +bool CommandRequestImpl::CheckAllowedParameters( + const Command::CommandSource source) { LOG4CXX_AUTO_TRACE(logger_); // RegisterAppInterface should always be allowed @@ -700,64 +692,7 @@ bool CommandRequestImpl::CheckAllowedParameters() { return true; } - const ApplicationSharedPtr app = - application_manager_.application(connection_key()); - if (!app) { - LOG4CXX_ERROR(logger_, - "There is no registered application with " - "connection key '" - << connection_key() << "'"); - return false; - } - - RPCParams params; - - const smart_objects::SmartObject& s_map = (*message_)[strings::msg_params]; - smart_objects::SmartMap::const_iterator iter = s_map.map_begin(); - smart_objects::SmartMap::const_iterator iter_end = s_map.map_end(); - - for (; iter != iter_end; ++iter) { - LOG4CXX_DEBUG(logger_, "Request's param: " << iter->first); - params.insert(iter->first); - } - - mobile_apis::Result::eType check_result = - mobile_apis::Result::eType::INVALID_ID; - const auto current_window_id = window_id(); - if (app->WindowIdExists(current_window_id)) { - check_result = application_manager_.CheckPolicyPermissions( - app, - current_window_id, - MessageHelper::StringifiedFunctionID( - static_cast<mobile_api::FunctionID::eType>(function_id())), - params, - ¶meters_permissions_); - } - - // Check, if RPC is allowed by policy - if (mobile_apis::Result::SUCCESS != check_result) { - smart_objects::SmartObjectSPtr response = - MessageHelper::CreateBlockedByPoliciesResponse( - static_cast<mobile_api::FunctionID::eType>(function_id()), - check_result, - correlation_id(), - app->app_id()); - - rpc_service_.SendMessageToMobile(response); - return false; - } - - // If no parameters specified in policy table, no restriction will be - // applied for parameters - if (parameters_permissions_.allowed_params.empty() && - parameters_permissions_.disallowed_params.empty() && - parameters_permissions_.undefined_params.empty()) { - return true; - } - - RemoveDisallowedParameters(); - - return true; + return CommandImpl::CheckAllowedParameters(source); } bool CommandRequestImpl::CheckHMICapabilities( @@ -794,43 +729,7 @@ bool CommandRequestImpl::CheckHMICapabilities( return false; } -void CommandRequestImpl::RemoveDisallowedParameters() { - LOG4CXX_AUTO_TRACE(logger_); - - smart_objects::SmartObject& params = (*message_)[strings::msg_params]; - - for (const auto& key : params.enumerate()) { - if (parameters_permissions_.disallowed_params.end() != - parameters_permissions_.disallowed_params.find(key)) { - // Remove from request all disallowed parameters - params.erase(key); - removed_parameters_permissions_.disallowed_params.insert(key); - LOG4CXX_INFO(logger_, - "Following parameter is disallowed by user: " << key); - } - - else if (removed_parameters_permissions_.undefined_params.end() != - removed_parameters_permissions_.undefined_params.find(key)) { - // Remove from request all undefined yet parameters - params.erase(key); - removed_parameters_permissions_.undefined_params.insert(key); - LOG4CXX_INFO(logger_, - "Following parameter is disallowed by policy: " << key); - } - - else if (parameters_permissions_.allowed_params.end() == - parameters_permissions_.allowed_params.find(key)) { - // Remove from request all parameters missed in allowed - params.erase(key); - removed_parameters_permissions_.undefined_params.insert(key); - LOG4CXX_INFO(logger_, - "Following parameter is not found among allowed parameters '" - << key << "' and will be treated as disallowed."); - } - } -} - -void CommandRequestImpl::AddDissalowedParameterToInfoString( +void CommandRequestImpl::AddDisallowedParameterToInfoString( std::string& info, const std::string& param) const { // prepare disallowed params enumeration for response info string if (info.empty()) { @@ -847,12 +746,12 @@ void CommandRequestImpl::AddDisallowedParametersToInfo( RPCParams::const_iterator it = removed_parameters_permissions_.disallowed_params.begin(); for (; it != removed_parameters_permissions_.disallowed_params.end(); ++it) { - AddDissalowedParameterToInfoString(info, (*it)); + AddDisallowedParameterToInfoString(info, (*it)); } it = removed_parameters_permissions_.undefined_params.begin(); for (; it != removed_parameters_permissions_.undefined_params.end(); ++it) { - AddDissalowedParameterToInfoString(info, (*it)); + AddDisallowedParameterToInfoString(info, (*it)); } if (!info.empty()) { @@ -1028,21 +927,25 @@ std::string GetComponentNameFromInterface( const HmiInterfaces::InterfaceID& interface) { switch (interface) { case HmiInterfaces::HMI_INTERFACE_Buttons: - return "Buttons"; + return hmi_interface::buttons; case HmiInterfaces::HMI_INTERFACE_BasicCommunication: - return "BasicCommunication"; + return hmi_interface::basic_communication; case HmiInterfaces::HMI_INTERFACE_VR: - return "VR"; + return hmi_interface::vr; case HmiInterfaces::HMI_INTERFACE_TTS: - return "TTS"; + return hmi_interface::tts; case HmiInterfaces::HMI_INTERFACE_UI: - return "UI"; + return hmi_interface::ui; case HmiInterfaces::HMI_INTERFACE_Navigation: - return "Navigation"; + return hmi_interface::navigation; case HmiInterfaces::HMI_INTERFACE_VehicleInfo: - return "VehicleInfo"; + return hmi_interface::vehicle_info; case HmiInterfaces::HMI_INTERFACE_SDL: - return "SDL"; + return hmi_interface::sdl; + case HmiInterfaces::HMI_INTERFACE_RC: + return hmi_interface::rc; + case HmiInterfaces::HMI_INTERFACE_AppService: + return hmi_interface::app_service; default: return "Unknown type"; } diff --git a/src/components/application_manager/src/commands/command_request_to_mobile.cc b/src/components/application_manager/src/commands/command_request_to_mobile.cc index e1ed06e887..add58c9973 100644 --- a/src/components/application_manager/src/commands/command_request_to_mobile.cc +++ b/src/components/application_manager/src/commands/command_request_to_mobile.cc @@ -55,6 +55,10 @@ bool CommandRequestToMobile::Init() { return true; } +bool CommandRequestToMobile::CheckPermissions() { + return CheckAllowedParameters(Command::CommandSource::SOURCE_SDL); +} + bool CommandRequestToMobile::CleanUp() { return true; } diff --git a/src/components/application_manager/src/commands/command_response_from_mobile.cc b/src/components/application_manager/src/commands/command_response_from_mobile.cc index dfed65b134..1e31ca8ff5 100644 --- a/src/components/application_manager/src/commands/command_response_from_mobile.cc +++ b/src/components/application_manager/src/commands/command_response_from_mobile.cc @@ -56,6 +56,10 @@ bool CommandResponseFromMobile::Init() { return true; } +bool CommandResponseFromMobile::CheckPermissions() { + return CheckAllowedParameters(Command::CommandSource::SOURCE_MOBILE); +} + bool CommandResponseFromMobile::CleanUp() { return true; } diff --git a/src/components/application_manager/src/commands/request_from_hmi.cc b/src/components/application_manager/src/commands/request_from_hmi.cc index 1cf5c50cdd..eb9d914f00 100644 --- a/src/components/application_manager/src/commands/request_from_hmi.cc +++ b/src/components/application_manager/src/commands/request_from_hmi.cc @@ -96,7 +96,19 @@ void RequestFromHMI::SendResponse( } (*message)[strings::msg_params][strings::success] = success; - (*message)[strings::msg_params][strings::result_code] = result_code; + if ((result_code == hmi_apis::Common_Result::SUCCESS || + result_code == hmi_apis::Common_Result::WARNINGS) && + !warning_info().empty()) { + bool has_info = (*message)[strings::params].keyExists(strings::error_msg); + (*message)[strings::params][strings::error_msg] = + has_info ? (*message)[strings::params][strings::error_msg].asString() + + "\n" + warning_info() + : warning_info(); + (*message)[strings::msg_params][strings::result_code] = + mobile_apis::Result::WARNINGS; + } else { + (*message)[strings::msg_params][strings::result_code] = result_code; + } rpc_service_.ManageHMICommand(message, source); } diff --git a/src/components/application_manager/src/commands/request_to_hmi.cc b/src/components/application_manager/src/commands/request_to_hmi.cc index 1acbc9ace7..ac34d091af 100644 --- a/src/components/application_manager/src/commands/request_to_hmi.cc +++ b/src/components/application_manager/src/commands/request_to_hmi.cc @@ -31,10 +31,43 @@ */ #include "application_manager/commands/request_to_hmi.h" +#include "application_manager/message_helper.h" #include "application_manager/rpc_service.h" namespace application_manager { +namespace { +static const std::set<hmi_apis::FunctionID::eType> tts_request_ids{ + hmi_apis::FunctionID::TTS_GetLanguage, + hmi_apis::FunctionID::TTS_GetCapabilities, + hmi_apis::FunctionID::TTS_GetSupportedLanguages}; + +static const std::set<hmi_apis::FunctionID::eType> vr_request_ids{ + hmi_apis::FunctionID::VR_GetLanguage, + hmi_apis::FunctionID::VR_GetCapabilities, + hmi_apis::FunctionID::VR_GetSupportedLanguages}; + +static const std::set<hmi_apis::FunctionID::eType> ui_request_ids{ + hmi_apis::FunctionID::UI_GetLanguage, + hmi_apis::FunctionID::UI_GetCapabilities, + hmi_apis::FunctionID::UI_GetSupportedLanguages}; + +static const std::set<hmi_apis::FunctionID::eType> rc_request_ids{ + hmi_apis::FunctionID::RC_GetCapabilities}; + +static const std::set<hmi_apis::FunctionID::eType> vehicle_info_request_ids{ + hmi_apis::FunctionID::VehicleInfo_GetVehicleType}; + +static std::map<std::string, std::set<hmi_apis::FunctionID::eType> > + interface_requests{ + {std::string(hmi_interface::ui), ui_request_ids}, + {std::string(hmi_interface::vr), vr_request_ids}, + {std::string(hmi_interface::tts), tts_request_ids}, + {std::string(hmi_interface::rc), rc_request_ids}, + {std::string(hmi_interface::vehicle_info), vehicle_info_request_ids}}; + +} // namespace + namespace commands { bool CheckAvailabilityHMIInterfaces(ApplicationManager& application_manager, @@ -92,6 +125,57 @@ void RequestToHMI::SendRequest() { rpc_service_.SendMessageToHMI(message_); } +void RequestToHMI::RequestInterfaceCapabilities(const char* interface_name) { + LOG4CXX_DEBUG( + logger_, + "Request capabilities for the " << interface_name << " interface"); + + const auto& request_ids = interface_requests[std::string(interface_name)]; + RequestCapabilities(request_ids); +} + +void RequestToHMI::UpdateRequestsRequiredForCapabilities( + const std::set<hmi_apis::FunctionID::eType>& requests_to_send_to_hmi) { + for (auto request_id : requests_to_send_to_hmi) { + hmi_capabilities_.UpdateRequestsRequiredForCapabilities(request_id); + } +} + +void RequestToHMI::UpdateRequiredInterfaceCapabilitiesRequests( + const std::string& interface_name) { + LOG4CXX_DEBUG( + logger_, + "Update requests required for the " << interface_name << " interface"); + + const auto& request_ids = interface_requests[std::string(interface_name)]; + UpdateRequestsRequiredForCapabilities(request_ids); +} + +void RequestToHMI::RequestCapabilities( + const std::set<hmi_apis::FunctionID::eType>& requests_to_send_to_hmi) { + LOG4CXX_DEBUG(logger_, + "There are " << requests_to_send_to_hmi.size() + << " requests to send to the HMI"); + + for (const auto& function_id : requests_to_send_to_hmi) { + if (hmi_capabilities_.IsRequestsRequiredForCapabilities(function_id)) { + std::shared_ptr<smart_objects::SmartObject> request_so( + MessageHelper::CreateModuleInfoSO(function_id, application_manager_)); + + switch (function_id) { + case hmi_apis::FunctionID::UI_GetLanguage: + case hmi_apis::FunctionID::VR_GetLanguage: + case hmi_apis::FunctionID::TTS_GetLanguage: + hmi_capabilities_.set_handle_response_for(*request_so); + break; + default: + break; + } + rpc_service_.ManageHMICommand(request_so); + } + } +} + } // namespace commands } // namespace application_manager diff --git a/src/components/application_manager/src/hmi_capabilities_impl.cc b/src/components/application_manager/src/hmi_capabilities_impl.cc index 6a0fbf78e3..11300bc684 100644 --- a/src/components/application_manager/src/hmi_capabilities_impl.cc +++ b/src/components/application_manager/src/hmi_capabilities_impl.cc @@ -30,17 +30,22 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include "application_manager/hmi_capabilities_impl.h" + #include <map> #include "application_manager/application_manager.h" -#include "application_manager/hmi_capabilities_impl.h" #include "application_manager/message_helper.h" +#include "application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/rc_module_constants.h" #include "application_manager/smart_object_keys.h" #include "config_profile/profile.h" #include "formatters/CFormatterJsonBase.h" #include "interfaces/HMI_API.h" +#include "smart_objects/enum_schema_item.h" #include "smart_objects/smart_object.h" #include "utils/file_system.h" +#include "utils/helpers.h" +#include "utils/jsoncpp_reader_wrapper.h" #include "utils/logger.h" namespace application_manager { @@ -53,6 +58,8 @@ std::map<std::string, hmi_apis::Common_VrCapabilities::eType> vr_enum_capabilities; std::map<std::string, hmi_apis::Common_SpeechCapabilities::eType> tts_enum_capabilities; +std::map<std::string, hmi_apis::Common_PrerecordedSpeech::eType> + tts_enum_prerecorded_speech; std::map<std::string, hmi_apis::Common_ButtonName::eType> button_enum_name; std::map<std::string, hmi_apis::Common_TextFieldName::eType> text_fields_enum_name; @@ -98,6 +105,22 @@ void InitCapabilities() { tts_enum_capabilities.insert(std::make_pair( std::string("FILE"), hmi_apis::Common_SpeechCapabilities::FILE)); + tts_enum_prerecorded_speech.insert( + std::make_pair(std::string("HELP_JINGLE"), + hmi_apis::Common_PrerecordedSpeech::HELP_JINGLE)); + tts_enum_prerecorded_speech.insert( + std::make_pair(std::string("INITIAL_JINGLE"), + hmi_apis::Common_PrerecordedSpeech::INITIAL_JINGLE)); + tts_enum_prerecorded_speech.insert( + std::make_pair(std::string("LISTEN_JINGLE"), + hmi_apis::Common_PrerecordedSpeech::LISTEN_JINGLE)); + tts_enum_prerecorded_speech.insert( + std::make_pair(std::string("POSITIVE_JINGLE"), + hmi_apis::Common_PrerecordedSpeech::POSITIVE_JINGLE)); + tts_enum_prerecorded_speech.insert( + std::make_pair(std::string("NEGATIVE_JINGLE"), + hmi_apis::Common_PrerecordedSpeech::NEGATIVE_JINGLE)); + button_enum_name.insert( std::make_pair(std::string("OK"), hmi_apis::Common_ButtonName::OK)); button_enum_name.insert(std::make_pair( @@ -416,6 +439,33 @@ void InitCapabilities() { } // namespace +namespace { +/** + * @brief Saves smart object content into the JSON node + * @param field_name name of the field to save + * @param schema reference to schema to unapply + * @param object_to_save pointer to object to save + * @param out_json_node JSON node for the output result + */ +void save_hmi_capability_field_to_json( + const std::string& field_name, + smart_objects::CSmartSchema schema, + smart_objects::SmartObjectSPtr object_to_save, + Json::Value& out_json_node) { + if (!object_to_save) { + return; + } + namespace Formatters = ns_smart_device_link::ns_json_handler::formatters; + smart_objects::SmartObject formatted_object(smart_objects::SmartType_Map); + formatted_object[strings::msg_params][field_name] = *object_to_save; + schema.unapplySchema(formatted_object); // converts enums back to strings + Json::Value temp_value; + Formatters::CFormatterJsonBase::objToJsonValue(formatted_object, temp_value); + out_json_node[field_name] = temp_value[strings::msg_params][field_name]; +} + +} // namespace + HMICapabilitiesImpl::HMICapabilitiesImpl(ApplicationManager& app_mngr) : is_vr_cooperating_(false) , is_tts_cooperating_(false) @@ -463,15 +513,7 @@ HMICapabilitiesImpl::HMICapabilitiesImpl(ApplicationManager& app_mngr) } } -HMICapabilitiesImpl::~HMICapabilitiesImpl() { - delete ui_supported_languages_; - delete tts_supported_languages_; - delete vr_supported_languages_; - delete navigation_capability_; - delete phone_capability_; - delete video_streaming_capability_; - delete rc_capability_; -} +HMICapabilitiesImpl::~HMICapabilitiesImpl() {} bool HMICapabilitiesImpl::VerifyImageType(const int32_t image_type) const { auto capabilities = display_capabilities(); @@ -567,27 +609,23 @@ HMICapabilitiesImpl::active_tts_language() const { void HMICapabilitiesImpl::set_ui_supported_languages( const smart_objects::SmartObject& supported_languages) { - if (ui_supported_languages_) { - delete ui_supported_languages_; - } - ui_supported_languages_ = new smart_objects::SmartObject(supported_languages); + auto new_value = + std::make_shared<smart_objects::SmartObject>(supported_languages); + ui_supported_languages_.swap(new_value); } void HMICapabilitiesImpl::set_tts_supported_languages( const smart_objects::SmartObject& supported_languages) { - if (tts_supported_languages_) { - delete tts_supported_languages_; - } - tts_supported_languages_ = - new smart_objects::SmartObject(supported_languages); + auto new_value = + std::make_shared<smart_objects::SmartObject>(supported_languages); + tts_supported_languages_.swap(new_value); } void HMICapabilitiesImpl::set_vr_supported_languages( const smart_objects::SmartObject& supported_languages) { - if (vr_supported_languages_) { - delete vr_supported_languages_; - } - vr_supported_languages_ = new smart_objects::SmartObject(supported_languages); + auto new_value = + std::make_shared<smart_objects::SmartObject>(supported_languages); + vr_supported_languages_.swap(new_value); } void HMICapabilitiesImpl::set_display_capabilities( @@ -595,7 +633,7 @@ void HMICapabilitiesImpl::set_display_capabilities( if (app_mngr_.IsSOStructValid( hmi_apis::StructIdentifiers::Common_DisplayCapabilities, display_capabilities)) { - smart_objects::SmartObjectSPtr new_value = + auto new_value = std::make_shared<smart_objects::SmartObject>(display_capabilities); display_capabilities_.swap(new_value); } @@ -609,71 +647,69 @@ void HMICapabilitiesImpl::set_system_display_capabilities( void HMICapabilitiesImpl::set_hmi_zone_capabilities( const smart_objects::SmartObject& hmi_zone_capabilities) { - smart_objects::SmartObjectSPtr new_value = + auto new_value = std::make_shared<smart_objects::SmartObject>(hmi_zone_capabilities); hmi_zone_capabilities_.swap(new_value); } void HMICapabilitiesImpl::set_soft_button_capabilities( const smart_objects::SmartObject& soft_button_capabilities) { - smart_objects::SmartObjectSPtr new_value = + auto new_value = std::make_shared<smart_objects::SmartObject>(soft_button_capabilities); soft_buttons_capabilities_.swap(new_value); } void HMICapabilitiesImpl::set_button_capabilities( const smart_objects::SmartObject& button_capabilities) { - smart_objects::SmartObjectSPtr new_value = + auto new_value = std::make_shared<smart_objects::SmartObject>(button_capabilities); button_capabilities_.swap(new_value); } void HMICapabilitiesImpl::set_vr_capabilities( const smart_objects::SmartObject& vr_capabilities) { - smart_objects::SmartObjectSPtr new_value = + auto new_value = std::make_shared<smart_objects::SmartObject>(vr_capabilities); vr_capabilities_.swap(new_value); } void HMICapabilitiesImpl::set_speech_capabilities( const smart_objects::SmartObject& speech_capabilities) { - smart_objects::SmartObjectSPtr new_value = + auto new_value = std::make_shared<smart_objects::SmartObject>(speech_capabilities); speech_capabilities_.swap(new_value); } void HMICapabilitiesImpl::set_audio_pass_thru_capabilities( const smart_objects::SmartObject& audio_pass_thru_capabilities) { - smart_objects::SmartObjectSPtr new_value = - std::make_shared<smart_objects::SmartObject>( - audio_pass_thru_capabilities); + auto new_value = std::make_shared<smart_objects::SmartObject>( + audio_pass_thru_capabilities); audio_pass_thru_capabilities_.swap(new_value); } void HMICapabilitiesImpl::set_pcm_stream_capabilities( const smart_objects::SmartObject& pcm_stream_capabilities) { - smart_objects::SmartObjectSPtr new_value = + auto new_value = std::make_shared<smart_objects::SmartObject>(pcm_stream_capabilities); pcm_stream_capabilities_.swap(new_value); } void HMICapabilitiesImpl::set_preset_bank_capabilities( const smart_objects::SmartObject& preset_bank_capabilities) { - smart_objects::SmartObjectSPtr new_value = + auto new_value = std::make_shared<smart_objects::SmartObject>(preset_bank_capabilities); preset_bank_capabilities_.swap(new_value); } void HMICapabilitiesImpl::set_vehicle_type( const smart_objects::SmartObject& vehicle_type) { - smart_objects::SmartObjectSPtr new_value = - std::make_shared<smart_objects::SmartObject>(vehicle_type); + auto new_value = std::make_shared<smart_objects::SmartObject>(vehicle_type); vehicle_type_.swap(new_value); } void HMICapabilitiesImpl::set_prerecorded_speech( const smart_objects::SmartObject& prerecorded_speech) { - smart_objects::SmartObjectSPtr new_value = + auto new_value = std::make_shared<smart_objects::SmartObject>(prerecorded_speech); prerecorded_speech_.swap(new_value); } @@ -695,51 +731,42 @@ void HMICapabilitiesImpl::set_rc_supported(const bool supported) { void HMICapabilitiesImpl::set_navigation_capability( const smart_objects::SmartObject& navigation_capability) { - if (navigation_capability_) { - delete navigation_capability_; - } - navigation_capability_ = - new smart_objects::SmartObject(navigation_capability); + auto new_value = + std::make_shared<smart_objects::SmartObject>(navigation_capability); + navigation_capability_.swap(new_value); } void HMICapabilitiesImpl::set_phone_capability( const smart_objects::SmartObject& phone_capability) { - if (phone_capability_) { - delete phone_capability_; - } - phone_capability_ = new smart_objects::SmartObject(phone_capability); + auto new_value = + std::make_shared<smart_objects::SmartObject>(phone_capability); + phone_capability_.swap(new_value); } void HMICapabilitiesImpl::set_video_streaming_capability( const smart_objects::SmartObject& video_streaming_capability) { - if (video_streaming_capability_) { - delete video_streaming_capability_; - } - video_streaming_capability_ = - new smart_objects::SmartObject(video_streaming_capability); + auto new_value = + std::make_shared<smart_objects::SmartObject>(video_streaming_capability); + video_streaming_capability_.swap(new_value); } void HMICapabilitiesImpl::set_rc_capability( const smart_objects::SmartObject& rc_capability) { - if (rc_capability_) { - delete rc_capability_; - } - rc_capability_ = new smart_objects::SmartObject(rc_capability); + auto new_value = std::make_shared<smart_objects::SmartObject>(rc_capability); + rc_capability_.swap(new_value); } void HMICapabilitiesImpl::set_seat_location_capability( const smart_objects::SmartObject& seat_location_capability) { - if (seat_location_capability_) { - delete seat_location_capability_; - } - seat_location_capability_ = - new smart_objects::SmartObject(seat_location_capability); + auto new_value = + std::make_shared<smart_objects::SmartObject>(seat_location_capability); + seat_location_capability_.swap(new_value); } void HMICapabilitiesImpl::Init( resumption::LastStateWrapperPtr last_state_wrapper) { hmi_language_handler_.Init(last_state_wrapper); - if (false == load_capabilities_from_file()) { + if (!LoadCapabilitiesFromFile()) { LOG4CXX_ERROR(logger_, "file hmi_capabilities.json was not loaded"); } else { LOG4CXX_INFO(logger_, "file hmi_capabilities.json was loaded"); @@ -774,18 +801,18 @@ bool HMICapabilitiesImpl::is_rc_cooperating() const { return is_rc_cooperating_; } -const smart_objects::SmartObject* HMICapabilitiesImpl::ui_supported_languages() - const { +const smart_objects::SmartObjectSPtr +HMICapabilitiesImpl::ui_supported_languages() const { return ui_supported_languages_; } -const smart_objects::SmartObject* HMICapabilitiesImpl::vr_supported_languages() - const { +const smart_objects::SmartObjectSPtr +HMICapabilitiesImpl::vr_supported_languages() const { return vr_supported_languages_; } -const smart_objects::SmartObject* HMICapabilitiesImpl::tts_supported_languages() - const { +const smart_objects::SmartObjectSPtr +HMICapabilitiesImpl::tts_supported_languages() const { return tts_supported_languages_; } @@ -868,33 +895,174 @@ bool HMICapabilitiesImpl::rc_supported() const { return is_rc_supported_; } -const smart_objects::SmartObject* HMICapabilitiesImpl::navigation_capability() - const { +const smart_objects::SmartObjectSPtr +HMICapabilitiesImpl::navigation_capability() const { return navigation_capability_; } -const smart_objects::SmartObject* HMICapabilitiesImpl::phone_capability() +const smart_objects::SmartObjectSPtr HMICapabilitiesImpl::phone_capability() const { return phone_capability_; } -const smart_objects::SmartObject* +const smart_objects::SmartObjectSPtr HMICapabilitiesImpl::video_streaming_capability() const { return video_streaming_capability_; } -const smart_objects::SmartObject* HMICapabilitiesImpl::rc_capability() const { +const smart_objects::SmartObjectSPtr HMICapabilitiesImpl::rc_capability() + const { return rc_capability_; } -const smart_objects::SmartObject* +const smart_objects::SmartObjectSPtr HMICapabilitiesImpl::seat_location_capability() const { return seat_location_capability_; } -bool HMICapabilitiesImpl::load_capabilities_from_file() { +/** + * @brief Checks if JSON member exists + * @param json_member reference to JSON structure to check + * @param name_of_member name which we should be checked + * @returns true if member exists, otherwise returns false + */ +bool JsonIsMemberSafe(const Json::Value& json_member, + const char* name_of_member) { + return !json_member.isNull() && json_member.isMember(name_of_member); +} + +/** + * @brief Converts specified string to appropriate enum value + * according to schema + * @return converted enum value + */ +template <typename EnumType> +EnumType ConvertStringToEnum(const std::string& str) { + using ns_smart_device_link::ns_smart_objects::EnumConversionHelper; + EnumType value; + if (EnumConversionHelper<EnumType>::StringToEnum(str, &value)) { + return value; + } + + return EnumType::INVALID_ENUM; +} + +/** + * @brief Converts the JSON array of string type into the SmartArray of enums + * @param json_array JSON value containing array + * @param out_so_array output SmartArray + */ +template <typename EnumType> +void ConvertJsonArrayToSoArray(const Json::Value& json_array, + smart_objects::SmartObject& out_so_array) { + out_so_array = + smart_objects::SmartObject(smart_objects::SmartType::SmartType_Array); + for (uint32_t i = 0; i < json_array.size(); ++i) { + out_so_array[i] = ConvertStringToEnum<EnumType>(json_array[i].asString()); + } +} + +/** + * @brief Helper class for obtaining proper capabilities JSON value considering + * case if it were overriden by cache + */ +struct JsonCapabilitiesGetter { + public: + /** + * @brief JsonCapabilitiesGetter constructor + * @param json_default_node reference to the main JSON capabilities node + * @param json_cache_node reference to cached JSON capabilities node + */ + JsonCapabilitiesGetter(Json::Value& json_default_node, + Json::Value& json_cache_node) + : json_default_node_(json_default_node) + , json_cache_node_(json_cache_node) {} + + JsonCapabilitiesGetter(JsonCapabilitiesGetter&& other) { + std::swap(json_default_node_, other.json_default_node_); + std::swap(json_cache_node_, other.json_cache_node_); + } + + bool IsInterfaceJsonMemberExists(const char* interface_name) { + return JsonIsMemberSafe(json_cache_node_, interface_name) || + JsonIsMemberSafe(json_default_node_, interface_name); + } + + /** + * @brief GetJsonMember gets JSON value for a specified JSON member from + * cached JSON node if member exists, otherwise main JSON node will be + * taken + * @param member_name name of the JSON member to get + * @return JSON value for specified member or Value::null if not found + */ + Json::Value GetJsonMember( + const char* member_name, + hmi_apis::FunctionID::eType request_id, + std::set<hmi_apis::FunctionID::eType>& default_initialized_capabilities) { + if (JsonIsMemberSafe(json_cache_node_, member_name)) { + return GetCachedJsonMember(member_name); + } + + LOG4CXX_DEBUG(logger_, + "Add request ID: " << request_id + << " for the interface: " << member_name); + default_initialized_capabilities.insert(request_id); + + if (JsonIsMemberSafe(json_default_node_, member_name)) { + return GetMainJsonMember(member_name); + } + + return Json::Value::null; + } + + /** + * @brief GetMainJsonMember gets JSON value for a specified JSON member from + * the main JSON node + * @param member_name name of the JSON member to get + * @return JSON value for specified member or Value::null if not found + */ + Json::Value GetMainJsonMember(const char* member_name) { + return json_default_node_.get(member_name, Json::Value::null); + } + + /** + * @brief GetCachedJsonMember gets JSON value for a specified JSON member + * from the cached JSON node + * @param member_name name of the JSON member to get + * @return JSON value for specified member or Value::null if not found + */ + Json::Value GetCachedJsonMember(const char* member_name) { + return json_cache_node_.get(member_name, Json::Value::null); + } + + private: + Json::Value json_default_node_; + Json::Value json_cache_node_; +}; + +/** + * @brief Gets the JSON node related to the specified interface name. + * @param interface_name Interface name which JSON node should be retreive from + * the main JSON node + * @return JsonCapabilitiesGetter instance initialized by default JSON node and + * cache JSON node for the specified interface + */ + +JsonCapabilitiesGetter GetInterfaceGetter( + const char* interface_name, JsonCapabilitiesGetter& json_root_getter) { + auto interface_default_node = + json_root_getter.GetMainJsonMember(interface_name); + auto interface_cache_node = + json_root_getter.GetCachedJsonMember(interface_name); + + JsonCapabilitiesGetter getter(interface_default_node, interface_cache_node); + return getter; +} + +bool HMICapabilitiesImpl::LoadCapabilitiesFromFile() { std::string json_string; - std::string file_name = app_mngr_.get_settings().hmi_capabilities_file_name(); + const std::string file_name = + app_mngr_.get_settings().hmi_capabilities_file_name(); if (!file_system::FileExists(file_name)) { return false; @@ -904,45 +1072,82 @@ bool HMICapabilitiesImpl::load_capabilities_from_file() { return false; } + const std::string cache_file_name = + app_mngr_.get_settings().hmi_capabilities_cache_file_name(); + Json::Value root_json_override; + + if (file_system::FileExists(cache_file_name)) { + LOG4CXX_DEBUG(logger_, + "HMI capabilities cache was found: " << cache_file_name); + + std::string cache_json_string; + if (!file_system::ReadFile(cache_file_name, cache_json_string)) { + LOG4CXX_DEBUG( + logger_, + "Failed to read data from cache file. Cache will be ignored"); + } + + try { + utils::JsonReader reader; + std::string json(cache_json_string.begin(), cache_json_string.end()); + if (!reader.parse(json, &root_json_override)) { + LOG4CXX_ERROR(logger_, + "Cached JSON file is invalid. Deleting the file"); + file_system::DeleteFile(cache_file_name); + root_json_override = + Json::Value::null; // Just to clear intermediate state of value + } + } catch (...) { + return false; + } + } + try { - Json::CharReaderBuilder reader_builder; - const std::unique_ptr<Json::CharReader> reader_( - reader_builder.newCharReader()); - JSONCPP_STRING err; Json::Value root_json; - const size_t json_len = json_string.length(); - - const bool result = reader_->parse( - json_string.c_str(), json_string.c_str() + json_len, &root_json, &err); - if (!result) { - LOG4CXX_DEBUG(logger_, "Json parsing fails: " << err); + utils::JsonReader reader; + std::string json(json_string.begin(), json_string.end()); + if (!reader.parse(json, &root_json)) { + LOG4CXX_DEBUG(logger_, "Default JSON parsing fails"); return false; } + + JsonCapabilitiesGetter json_root_getter(root_json, root_json_override); // UI - if (check_existing_json_member(root_json, "UI")) { - Json::Value ui = root_json.get("UI", Json::Value::null); - if (check_existing_json_member(ui, "language")) { - const std::string lang = ui.get("language", "EN-US").asString(); + if (json_root_getter.IsInterfaceJsonMemberExists(hmi_interface::ui)) { + auto json_ui_getter = + GetInterfaceGetter(hmi_interface::ui, json_root_getter); + + auto ui_language_node = + json_ui_getter.GetJsonMember(hmi_response::language, + hmi_apis::FunctionID::UI_GetLanguage, + requests_required_for_capabilities_); + + if (!ui_language_node.isNull()) { + const std::string lang = ui_language_node.asString(); set_active_ui_language(MessageHelper::CommonLanguageFromString(lang)); - } else { - set_active_ui_language( - MessageHelper::CommonLanguageFromString("EN-US")); } - if (check_existing_json_member(ui, "languages")) { + auto ui_languages_node = json_ui_getter.GetJsonMember( + hmi_response::languages, + hmi_apis::FunctionID::UI_GetSupportedLanguages, + requests_required_for_capabilities_); + if (!ui_languages_node.isNull()) { smart_objects::SmartObject ui_languages_so( smart_objects::SmartType_Array); - Json::Value languages_ui = ui.get("languages", ""); - convert_json_languages_to_obj(languages_ui, ui_languages_so); + ConvertJsonArrayToSoArray<hmi_apis::Common_Language::eType>( + ui_languages_node, ui_languages_so); set_ui_supported_languages(ui_languages_so); } - if (check_existing_json_member(ui, "displayCapabilities")) { + auto ui_display_capabilities_node = + json_ui_getter.GetJsonMember(hmi_response::display_capabilities, + hmi_apis::FunctionID::UI_GetCapabilities, + requests_required_for_capabilities_); + if (!ui_display_capabilities_node.isNull()) { smart_objects::SmartObject display_capabilities_so; - Json::Value display_capabilities = ui.get("displayCapabilities", ""); - formatters::CFormatterJsonBase::jsonValueToObj(display_capabilities, - display_capabilities_so); + formatters::CFormatterJsonBase::jsonValueToObj( + ui_display_capabilities_node, display_capabilities_so); if (display_capabilities_so.keyExists(hmi_response::display_type)) { std::map<std::string, @@ -1076,55 +1281,73 @@ bool HMICapabilitiesImpl::load_capabilities_from_file() { set_display_capabilities(display_capabilities_so); } - if (check_existing_json_member(ui, "audioPassThruCapabilities")) { - Json::Value audio_capabilities = - ui.get("audioPassThruCapabilities", ""); + auto ui_audio_pass_thru_capabilities_node = + json_ui_getter.GetJsonMember(strings::audio_pass_thru_capabilities, + hmi_apis::FunctionID::UI_GetCapabilities, + requests_required_for_capabilities_); + if (!ui_audio_pass_thru_capabilities_node.isNull()) { smart_objects::SmartObject audio_capabilities_so( smart_objects::SmartType_Array); - if (audio_capabilities.type() == Json::arrayValue) { - for (uint32_t i = 0; i < audio_capabilities.size(); i++) { - convert_audio_capability_to_obj(audio_capabilities[i], - audio_capabilities_so[i]); + if (ui_audio_pass_thru_capabilities_node.type() == Json::arrayValue) { + for (uint32_t i = 0; i < ui_audio_pass_thru_capabilities_node.size(); + i++) { + convert_audio_capability_to_obj( + ui_audio_pass_thru_capabilities_node[i], + audio_capabilities_so[i]); } - } else if (audio_capabilities.type() == Json::objectValue) { - convert_audio_capability_to_obj(audio_capabilities, + } else if (ui_audio_pass_thru_capabilities_node.type() == + Json::objectValue) { + convert_audio_capability_to_obj(ui_audio_pass_thru_capabilities_node, audio_capabilities_so[0]); } set_audio_pass_thru_capabilities(audio_capabilities_so); } - if (check_existing_json_member(ui, "pcmStreamCapabilities")) { - Json::Value pcm_capabilities = ui.get("pcmStreamCapabilities", ""); + auto ui_pcm_stream_capabilities_node = + json_ui_getter.GetJsonMember(strings::pcm_stream_capabilities, + hmi_apis::FunctionID::UI_GetCapabilities, + requests_required_for_capabilities_); + if (!ui_pcm_stream_capabilities_node.isNull()) { smart_objects::SmartObject pcm_capabilities_so = smart_objects::SmartObject(smart_objects::SmartType_Map); - convert_audio_capability_to_obj(pcm_capabilities, pcm_capabilities_so); + convert_audio_capability_to_obj(ui_pcm_stream_capabilities_node, + pcm_capabilities_so); set_pcm_stream_capabilities(pcm_capabilities_so); } - if (check_existing_json_member(ui, "hmiZoneCapabilities")) { + auto ui_hmi_zone_capabilities_node = + json_ui_getter.GetJsonMember(hmi_response::hmi_zone_capabilities, + hmi_apis::FunctionID::UI_GetCapabilities, + requests_required_for_capabilities_); + if (!ui_hmi_zone_capabilities_node.isNull()) { smart_objects::SmartObject hmi_zone_capabilities_so = smart_objects::SmartObject(smart_objects::SmartType_Array); hmi_zone_capabilities_so = - hmi_zone_enum.find(ui.get("hmiZoneCapabilities", "").asString()) + hmi_zone_enum.find(ui_hmi_zone_capabilities_node.asString()) ->second; set_hmi_zone_capabilities(hmi_zone_capabilities_so); } - if (check_existing_json_member(ui, "softButtonCapabilities")) { - Json::Value soft_button_capabilities = - ui.get("softButtonCapabilities", ""); + auto ui_soft_button_capabilities_node = + json_ui_getter.GetJsonMember(hmi_response::soft_button_capabilities, + hmi_apis::FunctionID::UI_GetCapabilities, + requests_required_for_capabilities_); + if (!ui_soft_button_capabilities_node.isNull()) { smart_objects::SmartObject soft_button_capabilities_so; formatters::CFormatterJsonBase::jsonValueToObj( - soft_button_capabilities, soft_button_capabilities_so); + ui_soft_button_capabilities_node, soft_button_capabilities_so); set_soft_button_capabilities(soft_button_capabilities_so); } - if (check_existing_json_member(ui, "systemCapabilities")) { - Json::Value system_capabilities = ui.get("systemCapabilities", ""); - if (check_existing_json_member(system_capabilities, - "navigationCapability")) { - Json::Value navigation_capability = - system_capabilities.get("navigationCapability", ""); + auto ui_system_capabilities_node = + json_ui_getter.GetJsonMember(strings::system_capabilities, + hmi_apis::FunctionID::UI_GetCapabilities, + requests_required_for_capabilities_); + if (!ui_system_capabilities_node.isNull()) { + if (JsonIsMemberSafe(ui_system_capabilities_node, + strings::navigation_capability)) { + Json::Value navigation_capability = ui_system_capabilities_node.get( + strings::navigation_capability, ""); smart_objects::SmartObject navigation_capability_so; formatters::CFormatterJsonBase::jsonValueToObj( navigation_capability, navigation_capability_so); @@ -1133,10 +1356,10 @@ bool HMICapabilitiesImpl::load_capabilities_from_file() { set_navigation_supported(true); } } - if (check_existing_json_member(system_capabilities, - "phoneCapability")) { + if (JsonIsMemberSafe(ui_system_capabilities_node, + strings::phone_capability)) { Json::Value phone_capability = - system_capabilities.get("phoneCapability", ""); + ui_system_capabilities_node.get(strings::phone_capability, ""); smart_objects::SmartObject phone_capability_so; formatters::CFormatterJsonBase::jsonValueToObj(phone_capability, phone_capability_so); @@ -1145,23 +1368,23 @@ bool HMICapabilitiesImpl::load_capabilities_from_file() { set_phone_call_supported(true); } } - if (check_existing_json_member(system_capabilities, - "videoStreamingCapability")) { - Json::Value vs_capability = - system_capabilities.get("videoStreamingCapability", ""); + if (JsonIsMemberSafe(ui_system_capabilities_node, + strings::video_streaming_capability)) { + Json::Value vs_capability = ui_system_capabilities_node.get( + strings::video_streaming_capability, ""); smart_objects::SmartObject vs_capability_so; formatters::CFormatterJsonBase::jsonValueToObj(vs_capability, vs_capability_so); - if (vs_capability_so.keyExists("supportedFormats")) { + if (vs_capability_so.keyExists(strings::supported_formats)) { smart_objects::SmartObject& supported_format_array = - vs_capability_so["supportedFormats"]; + vs_capability_so[strings::supported_formats]; smart_objects::SmartObject converted_array( smart_objects::SmartType_Array); for (uint32_t i = 0, j = 0; i < supported_format_array.length(); i++) { - if (!supported_format_array[i].keyExists("protocol") || - !supported_format_array[i].keyExists("codec")) { + if (!supported_format_array[i].keyExists(strings::protocol) || + !supported_format_array[i].keyExists(strings::codec)) { continue; } @@ -1169,12 +1392,13 @@ bool HMICapabilitiesImpl::load_capabilities_from_file() { hmi_apis::Common_VideoStreamingProtocol::eType>:: const_iterator it_protocol = video_streaming_protocol_enum.find( - supported_format_array[i]["protocol"].asString()); + supported_format_array[i][strings::protocol] + .asString()); std::map<std::string, hmi_apis::Common_VideoStreamingCodec::eType>:: const_iterator it_codec = video_streaming_codec_enum.find( - supported_format_array[i]["codec"].asString()); + supported_format_array[i][strings::codec].asString()); // format is valid only if both protocol and codec are converted // to enum values successfully @@ -1182,128 +1406,188 @@ bool HMICapabilitiesImpl::load_capabilities_from_file() { it_codec != video_streaming_codec_enum.end()) { smart_objects::SmartObject format_so = smart_objects::SmartObject(smart_objects::SmartType_Map); - format_so["protocol"] = it_protocol->second; - format_so["codec"] = it_codec->second; + format_so[strings::protocol] = it_protocol->second; + format_so[strings::codec] = it_codec->second; converted_array[j++] = format_so; } } - vs_capability_so.erase("supportedFormats"); - vs_capability_so["supportedFormats"] = converted_array; + vs_capability_so.erase(strings::supported_formats); + vs_capability_so[strings::supported_formats] = converted_array; } set_video_streaming_capability(vs_capability_so); if (!vs_capability_so.empty()) { set_video_streaming_supported(true); } } - if (check_existing_json_member(system_capabilities, - "remoteControlCapability")) { - Json::Value rc_capability = - system_capabilities.get("remoteControlCapability", ""); - 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; - } + } + } else { + AddRequiredRequestsForCapabilities(hmi_interface::ui); + } // UI end + + // RC + if (json_root_getter.IsInterfaceJsonMemberExists(hmi_interface::rc)) { + auto rc_json_getter = + GetInterfaceGetter(hmi_interface::rc, json_root_getter); + + auto rc_capabilitity_node = + rc_json_getter.GetJsonMember(strings::rc_capability, + hmi_apis::FunctionID::RC_GetCapabilities, + requests_required_for_capabilities_); + if (!rc_capabilitity_node.isNull()) { + smart_objects::SmartObject rc_capability_so; + formatters::CFormatterJsonBase::jsonValueToObj(rc_capabilitity_node, + rc_capability_so); + if (rc_capability_so.keyExists( + rc_rpc_plugin::strings::klightControlCapabilities)) { + if (rc_capability_so + [rc_rpc_plugin::strings::klightControlCapabilities] + .keyExists(rc_rpc_plugin::strings::kSupportedLights)) { + auto& lights = rc_capability_so + [rc_rpc_plugin::strings::klightControlCapabilities] + [rc_rpc_plugin::strings::kSupportedLights]; + auto it = lights.asArray()->begin(); + for (; it != lights.asArray()->end(); ++it) { + smart_objects::SmartObject& light_name_so = (*it)[strings::name]; + auto light_name = MessageHelper::CommonLightNameFromString( + light_name_so.asString()); + light_name_so = light_name; } } + } + if (!rc_capability_so.empty()) { + set_rc_supported(true); set_rc_capability(rc_capability_so); - if (!rc_capability_so.empty()) { - set_rc_supported(true); - } } - if (check_existing_json_member(system_capabilities, - "seatLocationCapability")) { - Json::Value seat_location_capability = - system_capabilities.get("seatLocationCapability", ""); - smart_objects::SmartObject seat_location_capability_so; - formatters::CFormatterJsonBase::jsonValueToObj( - seat_location_capability, seat_location_capability_so); + } + + auto seat_location_capabilitiy_node = + rc_json_getter.GetJsonMember(strings::seat_location_capability, + hmi_apis::FunctionID::RC_GetCapabilities, + requests_required_for_capabilities_); + + if (!seat_location_capabilitiy_node.isNull()) { + smart_objects::SmartObject seat_location_capability_so; + formatters::CFormatterJsonBase::jsonValueToObj( + seat_location_capabilitiy_node, seat_location_capability_so); + + if (!seat_location_capability_so.empty()) { + set_rc_supported(true); set_seat_location_capability(seat_location_capability_so); } } - } // UI end + } else { + AddRequiredRequestsForCapabilities(hmi_interface::rc); + } + // RC end // VR - if (check_existing_json_member(root_json, "VR")) { - Json::Value vr = root_json.get("VR", ""); - if (check_existing_json_member(vr, "language")) { - const std::string lang = vr.get("language", "EN-US").asString(); + if (json_root_getter.IsInterfaceJsonMemberExists(hmi_interface::vr)) { + auto json_vr_getter = + GetInterfaceGetter(hmi_interface::vr, json_root_getter); + + auto vr_language_node = + json_vr_getter.GetJsonMember(hmi_response::language, + hmi_apis::FunctionID::VR_GetLanguage, + requests_required_for_capabilities_); + if (!vr_language_node.isNull()) { + const std::string lang = vr_language_node.asString(); set_active_vr_language(MessageHelper::CommonLanguageFromString(lang)); - } else { - set_active_vr_language( - MessageHelper::CommonLanguageFromString("EN-US")); } - if (check_existing_json_member(vr, "languages")) { - Json::Value languages_vr = vr.get("languages", ""); + auto vr_languages_node = json_vr_getter.GetJsonMember( + hmi_response::languages, + hmi_apis::FunctionID::VR_GetSupportedLanguages, + requests_required_for_capabilities_); + if (!vr_languages_node.isNull()) { smart_objects::SmartObject vr_languages_so = smart_objects::SmartObject(smart_objects::SmartType_Array); - convert_json_languages_to_obj(languages_vr, vr_languages_so); + ConvertJsonArrayToSoArray<hmi_apis::Common_Language::eType>( + vr_languages_node, vr_languages_so); set_vr_supported_languages(vr_languages_so); } - if (check_existing_json_member(vr, "capabilities")) { - Json::Value capabilities = vr.get("capabilities", ""); + auto vr_capabilities_node = + json_vr_getter.GetJsonMember(strings::vr_capabilities, + hmi_apis::FunctionID::VR_GetCapabilities, + requests_required_for_capabilities_); + if (!vr_capabilities_node.isNull()) { smart_objects::SmartObject vr_capabilities_so = smart_objects::SmartObject(smart_objects::SmartType_Array); - for (uint32_t i = 0; i < capabilities.size(); ++i) { - vr_capabilities_so[i] = - vr_enum_capabilities.find(capabilities[i].asString())->second; - } + ConvertJsonArrayToSoArray<hmi_apis::Common_VrCapabilities::eType>( + vr_capabilities_node, vr_capabilities_so); set_vr_capabilities(vr_capabilities_so); } + } else { + AddRequiredRequestsForCapabilities(hmi_interface::vr); } // VR end // TTS - if (check_existing_json_member(root_json, "TTS")) { - Json::Value tts = root_json.get("TTS", ""); - - if (check_existing_json_member(tts, "language")) { - const std::string lang = tts.get("language", "EN-US").asString(); + if (json_root_getter.IsInterfaceJsonMemberExists(hmi_interface::tts)) { + auto json_tts_getter = + GetInterfaceGetter(hmi_interface::tts, json_root_getter); + + auto tts_language_node = + json_tts_getter.GetJsonMember(hmi_response::language, + hmi_apis::FunctionID::TTS_GetLanguage, + requests_required_for_capabilities_); + if (!tts_language_node.isNull()) { + const std::string lang = tts_language_node.asString(); set_active_tts_language(MessageHelper::CommonLanguageFromString(lang)); - } else { - set_active_tts_language( - MessageHelper::CommonLanguageFromString("EN-US")); } - if (check_existing_json_member(tts, "languages")) { - Json::Value languages_tts = tts.get("languages", ""); + auto tts_languages_node = json_tts_getter.GetJsonMember( + hmi_response::languages, + hmi_apis::FunctionID::TTS_GetSupportedLanguages, + requests_required_for_capabilities_); + if (!tts_languages_node.isNull()) { smart_objects::SmartObject tts_languages_so = smart_objects::SmartObject(smart_objects::SmartType_Array); - convert_json_languages_to_obj(languages_tts, tts_languages_so); + ConvertJsonArrayToSoArray<hmi_apis::Common_Language::eType>( + tts_languages_node, tts_languages_so); set_tts_supported_languages(tts_languages_so); } - if (check_existing_json_member(tts, "capabilities")) { - Json::Value capabilities = tts.get("capabilities", ""); + auto tts_speech_capabilities_node = json_tts_getter.GetJsonMember( + hmi_response::speech_capabilities, + hmi_apis::FunctionID::TTS_GetCapabilities, + requests_required_for_capabilities_); + if (!tts_speech_capabilities_node.isNull()) { smart_objects::SmartObject tts_capabilities_so = smart_objects::SmartObject(smart_objects::SmartType_Array); - for (uint32_t i = 0; i < capabilities.size(); ++i) { - tts_capabilities_so[i] = - tts_enum_capabilities.find(capabilities[i].asString())->second; - } + ConvertJsonArrayToSoArray<hmi_apis::Common_SpeechCapabilities::eType>( + tts_speech_capabilities_node, tts_capabilities_so); set_speech_capabilities(tts_capabilities_so); } + + auto tts_prerecorded_speech_capabilities_node = + json_tts_getter.GetJsonMember( + hmi_response::prerecorded_speech_capabilities, + hmi_apis::FunctionID::TTS_GetCapabilities, + requests_required_for_capabilities_); + if (!tts_prerecorded_speech_capabilities_node.isNull()) { + smart_objects::SmartObject tts_capabilities_so = + smart_objects::SmartObject(smart_objects::SmartType_Array); + ConvertJsonArrayToSoArray<hmi_apis::Common_PrerecordedSpeech::eType>( + tts_prerecorded_speech_capabilities_node, tts_capabilities_so); + set_prerecorded_speech(tts_capabilities_so); + } + } else { + AddRequiredRequestsForCapabilities(hmi_interface::tts); } // TTS end // Buttons - if (check_existing_json_member(root_json, "Buttons")) { - Json::Value buttons = root_json.get("Buttons", ""); - if (check_existing_json_member(buttons, "capabilities")) { - Json::Value bt_capabilities = buttons.get("capabilities", ""); + if (json_root_getter.IsInterfaceJsonMemberExists(hmi_interface::buttons)) { + auto json_buttons_getter = + GetInterfaceGetter(hmi_interface::buttons, json_root_getter); + + auto buttons_capabilities_node = json_buttons_getter.GetJsonMember( + hmi_response::capabilities, + hmi_apis::FunctionID::Buttons_GetCapabilities, + requests_required_for_capabilities_); + if (!buttons_capabilities_node.isNull()) { smart_objects::SmartObject buttons_capabilities_so; - formatters::CFormatterJsonBase::jsonValueToObj(bt_capabilities, - buttons_capabilities_so); + formatters::CFormatterJsonBase::jsonValueToObj( + buttons_capabilities_node, buttons_capabilities_so); for (uint32_t i = 0; i < buttons_capabilities_so.length(); ++i) { if ((buttons_capabilities_so[i]).keyExists(strings::name)) { @@ -1319,22 +1603,39 @@ bool HMICapabilitiesImpl::load_capabilities_from_file() { } set_button_capabilities(buttons_capabilities_so); } - if (check_existing_json_member(buttons, "presetBankCapabilities")) { - Json::Value presetBank = buttons.get("presetBankCapabilities", ""); + + auto buttons_preset_bank_capabilities_node = + json_buttons_getter.GetMainJsonMember( + hmi_response::preset_bank_capabilities); + if (!buttons_preset_bank_capabilities_node.isNull()) { smart_objects::SmartObject preset_bank_so; - formatters::CFormatterJsonBase::jsonValueToObj(presetBank, - preset_bank_so); + formatters::CFormatterJsonBase::jsonValueToObj( + buttons_preset_bank_capabilities_node, preset_bank_so); set_preset_bank_capabilities(preset_bank_so); } + } else { + AddRequiredRequestsForCapabilities(hmi_interface::buttons); } // Buttons end // VehicleType - if (check_existing_json_member(root_json, "VehicleInfo")) { - Json::Value vehicle_info = root_json.get("VehicleInfo", ""); - smart_objects::SmartObject vehicle_type_so; - formatters::CFormatterJsonBase::jsonValueToObj(vehicle_info, - vehicle_type_so); - set_vehicle_type(vehicle_type_so); + + if (json_root_getter.IsInterfaceJsonMemberExists( + hmi_interface::vehicle_info)) { + auto json_vehicle_info_getter = + GetInterfaceGetter(hmi_interface::vehicle_info, json_root_getter); + + auto vehicle_type_node = json_vehicle_info_getter.GetJsonMember( + hmi_response::vehicle_type, + hmi_apis::FunctionID::VehicleInfo_GetVehicleType, + requests_required_for_capabilities_); + if (!vehicle_type_node.isNull()) { + smart_objects::SmartObject vehicle_type_so; + formatters::CFormatterJsonBase::jsonValueToObj(vehicle_type_node, + vehicle_type_so); + set_vehicle_type(vehicle_type_so); + } + } else { + AddRequiredRequestsForCapabilities(hmi_interface::vehicle_info); } // VehicleType end } catch (...) { return false; @@ -1342,6 +1643,534 @@ bool HMICapabilitiesImpl::load_capabilities_from_file() { return true; } +hmi_apis::Common_Language::eType +HMICapabilitiesImpl::GetActiveLanguageForInterface( + const std::string& interface_name) const { + LOG4CXX_AUTO_TRACE(logger_); + if (hmi_interface::ui == interface_name) { + return active_ui_language(); + } + if (hmi_interface::vr == interface_name) { + return active_vr_language(); + } + if (hmi_interface::tts == interface_name) { + return active_tts_language(); + } + return hmi_apis::Common_Language::INVALID_ENUM; +} + +void HMICapabilitiesImpl::UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::eType requested_interface) { + LOG4CXX_AUTO_TRACE(logger_); + if (app_mngr_.IsHMICooperating()) { + LOG4CXX_DEBUG(logger_, + "Remove from default initialized capabilities skipped, " + "because hmi_cooperating equal true already"); + return; + } + + RemoveFromRequestsRequiredForCapabilities(requested_interface); + if (requests_required_for_capabilities_.empty()) { + app_mngr_.SetHMICooperating(true); + } +} + +void HMICapabilitiesImpl::OnSoftwareVersionReceived( + const std::string& ccpu_version) { + LOG4CXX_AUTO_TRACE(logger_); + + if (ccpu_version == ccpu_version_) { + LOG4CXX_DEBUG(logger_, "Software version not changed"); + if (requests_required_for_capabilities_.empty()) { + app_mngr_.SetHMICooperating(true); + } + app_mngr_.RequestForInterfacesAvailability(); + return; + } + + LOG4CXX_DEBUG(logger_, "Software version changed"); + set_ccpu_version(ccpu_version); + UpdateCachedCapabilities(); +} + +void HMICapabilitiesImpl::UpdateCachedCapabilities() { + LOG4CXX_AUTO_TRACE(logger_); + + DeleteCachedCapabilitiesFile(); + + if (!LoadCapabilitiesFromFile()) { + LOG4CXX_ERROR(logger_, "file hmi_capabilities.json was not loaded"); + } + + app_mngr_.RequestForInterfacesAvailability(); +} + +bool HMICapabilitiesImpl::AllFieldsSaved( + const Json::Value& root_node, + const std::string& interface_name, + const std::vector<std::string>& sections_to_check) const { + LOG4CXX_AUTO_TRACE(logger_); + if (!JsonIsMemberSafe(root_node, interface_name.c_str())) { + LOG4CXX_DEBUG(logger_, + interface_name + << " interface is not found. All fields should be saved"); + return false; + } + + const auto& interface_node = root_node.get(interface_name, Json::Value::null); + for (auto it = sections_to_check.begin(); it != sections_to_check.end(); + ++it) { + const std::string section = (*it).c_str(); + if (!JsonIsMemberSafe(interface_node, section.c_str())) { + LOG4CXX_DEBUG(logger_, + "Field " << *it << " should be saved into the file"); + return false; + } + + if (hmi_response::language == section) { + const auto active_language = + GetActiveLanguageForInterface(interface_name); + const auto json_language = interface_node[hmi_response::language]; + + if (active_language != + MessageHelper::CommonLanguageFromString(json_language.asString())) { + LOG4CXX_DEBUG(logger_, + "Active " << interface_name + << " language is not the same as the persisted " + "one. Field should be overwritten"); + return false; + } + } + } + + return true; +} + +void HMICapabilitiesImpl::RemoveFromRequestsRequiredForCapabilities( + hmi_apis::FunctionID::eType requested_interface) { + LOG4CXX_AUTO_TRACE(logger_); + + auto it = find(requests_required_for_capabilities_.begin(), + requests_required_for_capabilities_.end(), + requested_interface); + if (it != requests_required_for_capabilities_.end()) { + requests_required_for_capabilities_.erase(it); + LOG4CXX_DEBUG(logger_, + "Wait for " << requests_required_for_capabilities_.size() + << " responses"); + } +} + +void HMICapabilitiesImpl::PrepareUiJsonValueForSaving( + const std::vector<std::string>& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const { + LOG4CXX_AUTO_TRACE(logger_); + + smart_objects::SmartObject capability(smart_objects::SmartType_Map); + auto system_capabilities = std::make_shared<smart_objects::SmartObject>( + capability[strings::system_capabilities]); + + for (const auto& section_to_update : sections_to_update) { + if (section_to_update == hmi_response::hmi_zone_capabilities) { + save_hmi_capability_field_to_json(hmi_response::hmi_zone_capabilities, + schema, + hmi_zone_capabilities(), + out_node); + } + + else if (section_to_update == hmi_response::soft_button_capabilities) { + save_hmi_capability_field_to_json(hmi_response::soft_button_capabilities, + schema, + soft_button_capabilities(), + out_node); + } + + else if (section_to_update == strings::audio_pass_thru_capabilities) { + smart_objects::SmartObjectSPtr audio_pass_thru_capabilities_so = + audio_pass_thru_capabilities(); + + for (size_t i = 0; i < audio_pass_thru_capabilities_so->length(); ++i) { + const smart_objects::SmartObject& element = + (*audio_pass_thru_capabilities_so)[i]; + const auto audio_pass_thru_capabilities = + std::make_shared<smart_objects::SmartObject>(element); + Json::Value out_audio_pass_thru; + save_hmi_capability_field_to_json(strings::audio_pass_thru_capabilities, + schema, + audio_pass_thru_capabilities, + out_audio_pass_thru); + out_node[strings::audio_pass_thru_capabilities][Json::ArrayIndex(i)] = + out_audio_pass_thru[strings::audio_pass_thru_capabilities]; + } + } + + else if (section_to_update == strings::navigation) { + out_node[strings::hmi_capabilities][strings::navigation] = + navigation_supported(); + } + + else if (section_to_update == strings::phone_call) { + out_node[strings::hmi_capabilities][strings::phone_call] = + phone_call_supported(); + } + + else if (section_to_update == strings::video_streaming) { + out_node[strings::hmi_capabilities][strings::video_streaming] = + video_streaming_supported(); + } + + else if (section_to_update == strings::navigation_capability) { + const auto navigation_capability_so = navigation_capability(); + if (navigation_capability_so) { + (*system_capabilities)[strings::navigation_capability] = + *navigation_capability_so; + } + } + + else if (section_to_update == strings::phone_capability) { + const auto phone_capability_so = phone_capability(); + if (phone_capability_so) { + (*system_capabilities)[strings::phone_capability] = + *phone_capability_so; + } + } + + else if (section_to_update == strings::video_streaming_capability) { + const auto video_streaming_capability_so = video_streaming_capability(); + + if (video_streaming_capability_so) { + (*system_capabilities)[strings::video_streaming_capability] = + *video_streaming_capability_so; + } + } + + else if (section_to_update == strings::display_capabilities) { + const auto display_capabilities_so = display_capabilities(); + + if (display_capabilities_so) { + save_hmi_capability_field_to_json(strings::display_capabilities, + schema, + display_capabilities_so, + out_node); + } + } + + else if (section_to_update == strings::pcm_stream_capabilities) { + save_hmi_capability_field_to_json(strings::pcm_stream_capabilities, + schema, + pcm_stream_capabilities(), + out_node); + } + + else if (section_to_update == hmi_response::language) { + out_node[hmi_response::language] = + MessageHelper::CommonLanguageToString(active_ui_language()); + } + + else if (section_to_update == hmi_response::languages) { + save_hmi_capability_field_to_json( + hmi_response::languages, schema, ui_supported_languages(), out_node); + } + } + + if (!system_capabilities->empty()) { + save_hmi_capability_field_to_json( + strings::system_capabilities, schema, system_capabilities, out_node); + } +} + +void HMICapabilitiesImpl::PrepareVrJsonValueForSaving( + const std::vector<std::string>& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const { + LOG4CXX_AUTO_TRACE(logger_); + + for (const auto& section_to_update : sections_to_update) { + if (section_to_update == hmi_response::language) { + out_node[hmi_response::language] = + MessageHelper::CommonLanguageToString(active_vr_language()); + } + + if (section_to_update == hmi_response::languages) { + save_hmi_capability_field_to_json( + hmi_response::languages, schema, vr_supported_languages(), out_node); + } + + if (section_to_update == strings::vr_capabilities) { + save_hmi_capability_field_to_json( + strings::vr_capabilities, schema, vr_capabilities(), out_node); + } + } +} + +void HMICapabilitiesImpl::PrepareTtsJsonValueForSaving( + const std::vector<std::string>& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const { + LOG4CXX_AUTO_TRACE(logger_); + + for (const auto& section_to_update : sections_to_update) { + if (section_to_update == hmi_response::language) { + out_node[hmi_response::language] = + MessageHelper::CommonLanguageToString(active_tts_language()); + } + + if (section_to_update == hmi_response::languages) { + save_hmi_capability_field_to_json( + hmi_response::languages, schema, tts_supported_languages(), out_node); + } + + if (section_to_update == hmi_response::speech_capabilities) { + save_hmi_capability_field_to_json(hmi_response::speech_capabilities, + schema, + speech_capabilities(), + out_node); + } + + if (section_to_update == hmi_response::prerecorded_speech_capabilities) { + save_hmi_capability_field_to_json( + hmi_response::prerecorded_speech_capabilities, + schema, + prerecorded_speech(), + out_node); + } + } +} + +void HMICapabilitiesImpl::PrepareButtonsJsonValueForSaving( + const std::vector<std::string>& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const { + LOG4CXX_AUTO_TRACE(logger_); + + for (const auto& section_to_update : sections_to_update) { + if (section_to_update == hmi_response::button_capabilities) { + save_hmi_capability_field_to_json( + hmi_response::capabilities, schema, button_capabilities(), out_node); + } + + if (section_to_update == hmi_response::preset_bank_capabilities) { + save_hmi_capability_field_to_json(hmi_response::preset_bank_capabilities, + schema, + preset_bank_capabilities(), + out_node); + } + } +} + +void HMICapabilitiesImpl::PrepareVehicleInfoJsonValueForSaving( + const std::vector<std::string>& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const { + LOG4CXX_AUTO_TRACE(logger_); + if (helpers::in_range(sections_to_update, hmi_response::vehicle_type)) { + save_hmi_capability_field_to_json( + hmi_response::vehicle_type, schema, vehicle_type(), out_node); + } +} + +void HMICapabilitiesImpl::PrepareRCJsonValueForSaving( + const std::vector<std::string>& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_node) const { + LOG4CXX_AUTO_TRACE(logger_); + + for (const auto& section_to_update : sections_to_update) { + if (section_to_update == strings::rc_capability) { + save_hmi_capability_field_to_json( + strings::rc_capability, schema, rc_capability(), out_node); + } + + if (section_to_update == strings::seat_location_capability) { + save_hmi_capability_field_to_json(strings::seat_location_capability, + schema, + seat_location_capability(), + out_node); + } + } +} + +void HMICapabilitiesImpl::AddRequiredRequestsForCapabilities( + const std::string& interface_name) { + LOG4CXX_DEBUG(logger_, "Add request IDs for interface: " << interface_name); + + if (interface_name == hmi_interface::ui) { + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::UI_GetLanguage); + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::UI_GetSupportedLanguages); + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::UI_GetCapabilities); + } + + else if (interface_name == hmi_interface::rc) { + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::RC_GetCapabilities); + } + + else if (interface_name == hmi_interface::vr) { + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::VR_GetLanguage); + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::VR_GetSupportedLanguages); + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::VR_GetCapabilities); + } + + else if (interface_name == hmi_interface::tts) { + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::TTS_GetLanguage); + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::TTS_GetSupportedLanguages); + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::TTS_GetCapabilities); + } + + else if (interface_name == hmi_interface::buttons) { + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::Buttons_GetCapabilities); + } + + else if (interface_name == hmi_interface::vehicle_info) { + requests_required_for_capabilities_.insert( + hmi_apis::FunctionID::VehicleInfo_GetVehicleType); + } +} + +void HMICapabilitiesImpl::PrepareJsonValueForSaving( + const char* interface_name, + const std::vector<std::string>& sections_to_update, + const smart_objects::CSmartSchema& schema, + Json::Value& out_root_node) const { + LOG4CXX_DEBUG(logger_, + "Prepare " << interface_name << " sections for saving"); + + if (out_root_node.isNull()) { + out_root_node = Json::Value(Json::objectValue); + } + + if (!out_root_node.isMember(interface_name)) { + out_root_node[interface_name] = Json::Value(Json::objectValue); + } + + Json::Value& interface_node = out_root_node[interface_name]; + if (strcmp(interface_name, hmi_interface::ui) == 0) { + PrepareUiJsonValueForSaving(sections_to_update, schema, interface_node); + } + + else if (strcmp(interface_name, hmi_interface::vr) == 0) { + PrepareVrJsonValueForSaving(sections_to_update, schema, interface_node); + } + + else if (strcmp(interface_name, hmi_interface::tts) == 0) { + PrepareTtsJsonValueForSaving(sections_to_update, schema, interface_node); + } + + else if (strcmp(interface_name, hmi_interface::buttons) == 0) { + PrepareButtonsJsonValueForSaving( + sections_to_update, schema, interface_node); + } + + else if (strcmp(interface_name, hmi_interface::vehicle_info) == 0) { + PrepareVehicleInfoJsonValueForSaving( + sections_to_update, schema, interface_node); + } + + else if (strcmp(interface_name, hmi_interface::rc) == 0) { + PrepareRCJsonValueForSaving(sections_to_update, schema, interface_node); + } +} + +bool HMICapabilitiesImpl::SaveCachedCapabilitiesToFile( + const std::string& interface_name, + const std::vector<std::string>& sections_to_update, + const smart_objects::CSmartSchema& schema) { + LOG4CXX_AUTO_TRACE(logger_); + + if (sections_to_update.empty()) { + LOG4CXX_DEBUG(logger_, + "There is no one section to update in the cache file"); + return true; + } + + const std::string cache_file_name = + app_mngr_.get_settings().hmi_capabilities_cache_file_name(); + if (cache_file_name.empty()) { + LOG4CXX_DEBUG(logger_, + "Cache file name is not specified. No need to save cache"); + return true; + } + + Json::Value root_node; + if (file_system::FileExists(cache_file_name)) { + LOG4CXX_DEBUG(logger_, "Cache file exists. Check for it's content"); + + std::string file_content; + if (!file_system::ReadFile(cache_file_name, file_content)) { + LOG4CXX_ERROR(logger_, "Failed to read file content"); + return false; + } + + Json::CharReaderBuilder builder; + const std::unique_ptr<Json::CharReader> reader(builder.newCharReader()); + if (!reader->parse(file_content.c_str(), + file_content.c_str() + file_content.length(), + &root_node, + NULL)) { + LOG4CXX_ERROR(logger_, "Can't parse the file. Skipping"); + return false; + } + + if (AllFieldsSaved(root_node, interface_name, sections_to_update)) { + LOG4CXX_DEBUG( + logger_, + "All " << interface_name + << " fields are present in the file. No need to update"); + return true; + } + + LOG4CXX_DEBUG(logger_, "Some fields in the cache file should be updated"); + } + + PrepareJsonValueForSaving( + interface_name.c_str(), sections_to_update, schema, root_node); + + LOG4CXX_DEBUG(logger_, "Saving cache to file: " << cache_file_name); + const std::string content_to_save = root_node.toStyledString(); + const std::vector<uint8_t> binary_data_to_save(content_to_save.begin(), + content_to_save.end()); + + return file_system::Write(cache_file_name, binary_data_to_save); +} + +bool HMICapabilitiesImpl::DeleteCachedCapabilitiesFile() const { + LOG4CXX_AUTO_TRACE(logger_); + const std::string cache_file_name = + app_mngr_.get_settings().hmi_capabilities_cache_file_name(); + if (cache_file_name.empty()) { + LOG4CXX_DEBUG(logger_, + "Cache file name is not specified. Nothing to delete"); + return false; + } + + if (!file_system::FileExists(cache_file_name)) { + LOG4CXX_DEBUG(logger_, "Cache file does not exist"); + return false; + } + + if (!file_system::DeleteFile(cache_file_name)) { + LOG4CXX_ERROR(logger_, "Failed to delete cache file"); + return false; + } + return true; +} + +bool HMICapabilitiesImpl::IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::eType function_id) const { + return helpers::in_range(requests_required_for_capabilities_, function_id); +} + void HMICapabilitiesImpl::set_ccpu_version(const std::string& ccpu_version) { ccpu_version_ = ccpu_version; } @@ -1350,11 +2179,6 @@ const std::string& HMICapabilitiesImpl::ccpu_version() const { return ccpu_version_; } -bool HMICapabilitiesImpl::check_existing_json_member( - const Json::Value& json_member, const char* name_of_member) const { - return json_member.isMember(name_of_member); -} - void HMICapabilitiesImpl::convert_json_languages_to_obj( const Json::Value& json_languages, smart_objects::SmartObject& languages) const { @@ -1367,18 +2191,18 @@ void HMICapabilitiesImpl::convert_json_languages_to_obj( void HMICapabilitiesImpl::convert_audio_capability_to_obj( const Json::Value& capability, smart_objects::SmartObject& output_so) const { - if (check_existing_json_member(capability, "samplingRate")) { + if (JsonIsMemberSafe(capability, "samplingRate")) { output_so[strings::sampling_rate] = sampling_rate_enum.find(capability.get("samplingRate", "").asString()) ->second; } - if (check_existing_json_member(capability, "bitsPerSample")) { + if (JsonIsMemberSafe(capability, "bitsPerSample")) { output_so[strings::bits_per_sample] = bit_per_sample_enum .find(capability.get("bitsPerSample", "").asString()) ->second; } - if (check_existing_json_member(capability, "audioType")) { + if (JsonIsMemberSafe(capability, "audioType")) { output_so[strings::audio_type] = audio_type_enum.find(capability.get("audioType", "").asString()) ->second; 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 4a64fdb128..d6fbed115b 100644 --- a/src/components/application_manager/src/message_helper/message_helper.cc +++ b/src/components/application_manager/src/message_helper/message_helper.cc @@ -1316,9 +1316,18 @@ smart_objects::SmartObjectSPtr MessageHelper::CreateAppVrHelp( return NULL; } smart_objects::SmartObject& vr_help = *result; - vr_help[strings::vr_help_title] = app->name(); + const smart_objects::SmartObject* vr_help_title = app->vr_help_title(); + if (vr_help_title) { + vr_help[strings::vr_help_title] = vr_help_title->asString(); + } int32_t index = 0; + + smart_objects::SmartObject so_vr_help(smart_objects::SmartType_Map); + so_vr_help[strings::position] = index + 1; + so_vr_help[strings::text] = app->name(); + vr_help[strings::vr_help][index++] = so_vr_help; + if (app->vr_synonyms()) { smart_objects::SmartObject item(smart_objects::SmartType_Map); item[strings::text] = (*(app->vr_synonyms())).getElement(0); @@ -2517,6 +2526,33 @@ bool MessageHelper::SendUnsubscribedWayPoints(ApplicationManager& app_mngr) { void MessageHelper::SendPolicySnapshotNotification( uint32_t connection_key, + const std::string& snapshot_file_path, + const std::string& url, + ApplicationManager& app_mngr) { + LOG4CXX_AUTO_TRACE(logger_); + smart_objects::SmartObject content(smart_objects::SmartType_Map); + const auto request_type = +#if defined(PROPRIETARY_MODE) || defined(EXTERNAL_PROPRIETARY_MODE) + mobile_apis::RequestType::PROPRIETARY; +#else + mobile_apis::RequestType::HTTP; +#endif // PROPRIETARY || EXTERNAL_PROPRIETARY_MODE + + content[strings::msg_params][strings::request_type] = request_type; + + if (!url.empty()) { + content[strings::msg_params][strings::url] = url; + } else { + LOG4CXX_WARN(logger_, "No service URLs"); + } + + content[strings::msg_params][strings::file_name] = snapshot_file_path; + + SendSystemRequestNotification(connection_key, content, app_mngr); +} + +void MessageHelper::SendPolicySnapshotNotification( + uint32_t connection_key, const std::vector<uint8_t>& policy_data, const std::string& url, ApplicationManager& app_mngr) { diff --git a/src/components/application_manager/src/policies/policy_event_observer.cc b/src/components/application_manager/src/policies/policy_event_observer.cc index afe909fee4..7ca4d7b5b8 100644 --- a/src/components/application_manager/src/policies/policy_event_observer.cc +++ b/src/components/application_manager/src/policies/policy_event_observer.cc @@ -70,11 +70,6 @@ void PolicyEventObserver::on_event(const event_engine::Event& event) { unsubscribe_from_event(hmi_apis::FunctionID::VehicleInfo_GetVehicleData); break; } - case hmi_apis::FunctionID::BasicCommunication_OnReady: { - policy_handler_->OnSystemReady(); - unsubscribe_from_event(hmi_apis::FunctionID::BasicCommunication_OnReady); - break; - } default: { break; } } } diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 4bbb33b504..4992bd96ca 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -141,7 +141,7 @@ struct HMILevelPredicate } // namespace -#define POLICY_LIB_CHECK(return_value) \ +#define POLICY_LIB_CHECK_OR_RETURN(return_value) \ { \ sync_primitives::AutoReadLock lock(policy_manager_lock_); \ if (!policy_manager_) { \ @@ -299,10 +299,14 @@ PolicyHandler::PolicyHandler(const PolicySettings& settings, ApplicationManager& application_manager) : AsyncRunner("PolicyHandler async runner thread") , last_activated_app_id_(0) +#ifndef EXTERNAL_PROPRIETARY_MODE + , last_ptu_app_id_(0) +#endif // EXTERNAL_PROPRIETARY_MODE , statistic_manager_impl_(std::make_shared<StatisticManagerImpl>(this)) , settings_(settings) , application_manager_(application_manager) - , last_registered_policy_app_id_(std::string()) {} + , last_registered_policy_app_id_(std::string()) { +} PolicyHandler::~PolicyHandler() {} @@ -375,11 +379,7 @@ const PolicySettings& PolicyHandler::get_settings() const { bool PolicyHandler::InitPolicyTable() { LOG4CXX_AUTO_TRACE(logger_); - POLICY_LIB_CHECK(false); - // Subscribing to notification for system readiness to be able to get system - // info necessary for policy table - event_observer_->subscribe_on_event( - hmi_apis::FunctionID::BasicCommunication_OnReady); + POLICY_LIB_CHECK_OR_RETURN(false); std::string preloaded_file = get_settings().preloaded_pt_file(); if (file_system::FileExists(preloaded_file)) { const bool pt_inited = @@ -403,13 +403,17 @@ void PolicyHandler::OnPTInited() { void PolicyHandler::StopRetrySequence() { LOG4CXX_AUTO_TRACE(logger_); - + POLICY_LIB_CHECK_VOID(); +#ifndef EXTERNAL_PROPRIETARY_MODE + // Clear cached PTU app + last_ptu_app_id_ = 0; +#endif // EXTERNAL_PROPRIETARY_MODE policy_manager_->StopRetrySequence(); } bool PolicyHandler::ResetPolicyTable() { LOG4CXX_TRACE(logger_, "Reset policy table."); - POLICY_LIB_CHECK(false); + POLICY_LIB_CHECK_OR_RETURN(false); std::string preloaded_file = get_settings().preloaded_pt_file(); if (file_system::FileExists(preloaded_file)) { return policy_manager_->ResetPT(preloaded_file); @@ -420,13 +424,43 @@ bool PolicyHandler::ResetPolicyTable() { bool PolicyHandler::ClearUserConsent() { LOG4CXX_AUTO_TRACE(logger_); - POLICY_LIB_CHECK(false); + POLICY_LIB_CHECK_OR_RETURN(false); return policy_manager_->ResetUserConsent(); } +#ifndef EXTERNAL_PROPRIETARY_MODE +uint32_t PolicyHandler::ChoosePTUApplication( + const PTUIterationType iteration_type) { + LOG4CXX_AUTO_TRACE(logger_); + + // Return the previous app chosen if this is a retry for a PTU in progress + if (iteration_type == PTUIterationType::RetryIteration && + last_ptu_app_id_ != 0) { + ApplicationSharedPtr app = + application_manager_.application(last_ptu_app_id_); + if (app && app->IsRegistered()) { + LOG4CXX_INFO(logger_, "Previously chosen application exists, returning"); + return last_ptu_app_id_; + } + } + + last_ptu_app_id_ = GetAppIdForSending(); + return last_ptu_app_id_; +} + +void PolicyHandler::CacheRetryInfo(const uint32_t app_id, + const std::string url, + const std::string snapshot_path) { + last_ptu_app_id_ = app_id; + retry_update_url_ = url; + policy_snapshot_path_ = snapshot_path; +} +#endif // EXTERNAL_PROPRIETARY_MODE + uint32_t PolicyHandler::GetAppIdForSending() const { LOG4CXX_AUTO_TRACE(logger_); - POLICY_LIB_CHECK(0); + POLICY_LIB_CHECK_OR_RETURN(0); + // fix ApplicationSet access crash const ApplicationSet accessor = application_manager_.applications().GetData(); @@ -441,11 +475,10 @@ uint32_t PolicyHandler::GetAppIdForSending() const { "Number of apps with different from NONE level: " << apps_without_none_level.size()); - uint32_t choosen_app_id = - ChooseRandomAppForPolicyUpdate(apps_without_none_level); + uint32_t app_id = ChooseRandomAppForPolicyUpdate(apps_without_none_level); - if (choosen_app_id) { - return choosen_app_id; + if (app_id) { + return app_id; } Applications apps_with_none_level; @@ -468,6 +501,7 @@ uint32_t PolicyHandler::GetAppIdForSending() const { void PolicyHandler::PushAppIdToPTUQueue(const uint32_t app_id) { LOG4CXX_AUTO_TRACE(logger_); + POLICY_LIB_CHECK_VOID(); sync_primitives::AutoLock lock(app_id_queue_lock_); const auto result = applications_ptu_queue_.insert(app_id); if (result.second) { @@ -477,6 +511,7 @@ void PolicyHandler::PushAppIdToPTUQueue(const uint32_t app_id) { void PolicyHandler::PopAppIdFromPTUQueue() { LOG4CXX_AUTO_TRACE(logger_); + POLICY_LIB_CHECK_VOID(); sync_primitives::AutoLock lock(app_id_queue_lock_); if (applications_ptu_queue_.size() > 0) { applications_ptu_queue_.erase(applications_ptu_queue_.begin()); @@ -604,7 +639,7 @@ StatusNotifier PolicyHandler::AddApplication( const std::string& device_id, const std::string& application_id, const rpc::policy_table_interface_base::AppHmiTypes& hmi_types) { - POLICY_LIB_CHECK(std::make_shared<utils::CallNothing>()); + POLICY_LIB_CHECK_OR_RETURN(std::make_shared<utils::CallNothing>()); return policy_manager_->AddApplication(device_id, application_id, hmi_types); } @@ -719,7 +754,7 @@ void policy::PolicyHandler::SetDaysAfterEpoch() { #ifdef ENABLE_SECURITY std::string PolicyHandler::RetrieveCertificate() const { - POLICY_LIB_CHECK(std::string("")); + POLICY_LIB_CHECK_OR_RETURN(std::string("")); return policy_manager_->RetrieveCertificate(); } #endif // ENABLE_SECURITY @@ -754,6 +789,12 @@ void PolicyHandler::OnSystemRequestReceived() const { policy_manager_->ResetTimeout(); } +void PolicyHandler::TriggerPTUOnStartupIfRequired() { +#ifdef PROPRIETARY_MODE + policy_manager_->TriggerPTUOnStartupIfRequired(); +#endif +} + void PolicyHandler::GetRegisteredLinks( std::map<std::string, std::string>& out_links) const { DataAccessor<ApplicationSet> accessor = application_manager_.applications(); @@ -767,7 +808,7 @@ void PolicyHandler::GetRegisteredLinks( std::vector<policy::FunctionalGroupPermission> PolicyHandler::CollectRegisteredAppsPermissions() { LOG4CXX_AUTO_TRACE(logger_); - POLICY_LIB_CHECK(std::vector<policy::FunctionalGroupPermission>()); + POLICY_LIB_CHECK_OR_RETURN(std::vector<policy::FunctionalGroupPermission>()); // If no specific app was passed, get permissions for all currently registered // applications sync_primitives::AutoLock lock(app_to_device_link_lock_); @@ -788,9 +829,11 @@ PolicyHandler::CollectRegisteredAppsPermissions() { std::vector<FunctionalGroupPermission> PolicyHandler::CollectAppPermissions( const uint32_t connection_key) { + std::vector<FunctionalGroupPermission> group_permissions; + POLICY_LIB_CHECK_OR_RETURN(group_permissions); + // Single app only ApplicationSharedPtr app = application_manager_.application(connection_key); - std::vector<FunctionalGroupPermission> group_permissions; if (NULL == app.get() || app.use_count() == 0) { LOG4CXX_WARN(logger_, @@ -868,6 +911,7 @@ void PolicyHandler::LinkAppsToDevice() { bool PolicyHandler::IsAppSuitableForPolicyUpdate( const Applications::value_type value) const { LOG4CXX_AUTO_TRACE(logger_); + POLICY_LIB_CHECK_OR_RETURN(false); if (!value->IsRegistered()) { LOG4CXX_DEBUG( @@ -974,6 +1018,11 @@ void PolicyHandler::OnSystemInfoChanged(const std::string& language) { policy_manager_->SetSystemLanguage(language); } +void PolicyHandler::SetPreloadedPtFlag(const bool is_preloaded) { + LOG4CXX_AUTO_TRACE(logger_); + policy_manager_->SetPreloadedPtFlag(is_preloaded); +} + void PolicyHandler::OnGetSystemInfo(const std::string& ccpu_version, const std::string& wers_country_code, const std::string& language) { @@ -982,10 +1031,9 @@ void PolicyHandler::OnGetSystemInfo(const std::string& ccpu_version, policy_manager_->SetSystemInfo(ccpu_version, wers_country_code, language); } -void PolicyHandler::OnSystemInfoUpdateRequired() { +std::string PolicyHandler::GetCCPUVersionFromPT() const { LOG4CXX_AUTO_TRACE(logger_); - POLICY_LIB_CHECK_VOID(); - MessageHelper::SendGetSystemInfoRequest(application_manager_); + return policy_manager_->GetCCPUVersionFromPT(); } void PolicyHandler::OnVIIsReady() { @@ -1104,10 +1152,16 @@ void PolicyHandler::OnPendingPermissionChange( bool PolicyHandler::SendMessageToSDK(const BinaryMessage& pt_string, const std::string& url) { + const uint32_t app_id = GetAppIdForSending(); + return SendMessageToSDK(pt_string, url, app_id); +} + +bool PolicyHandler::SendMessageToSDK(const BinaryMessage& pt_string, + const std::string& url, + const uint32_t app_id) { LOG4CXX_AUTO_TRACE(logger_); - POLICY_LIB_CHECK(false); + POLICY_LIB_CHECK_OR_RETURN(false); - const uint32_t app_id = GetAppIdForSending(); ApplicationSharedPtr app = application_manager_.application(app_id); if (!app) { @@ -1142,7 +1196,7 @@ bool PolicyHandler::SendMessageToSDK(const BinaryMessage& pt_string, bool PolicyHandler::ReceiveMessageFromSDK(const std::string& file, const BinaryMessage& pt_string) { - POLICY_LIB_CHECK(false); + POLICY_LIB_CHECK_OR_RETURN(false); const auto load_pt_result = policy_manager_->LoadPT(file, pt_string); @@ -1157,6 +1211,10 @@ bool PolicyHandler::ReceiveMessageFromSDK(const std::string& file, policy_manager_->CleanupUnpairedDevices(); SetDaysAfterEpoch(); policy_manager_->OnPTUFinished(load_pt_result); +#ifndef EXTERNAL_PROPRIETARY_MODE + // Clean up retry information + last_ptu_app_id_ = 0; +#endif // EXTERNAL_PROPRIETARY_MODE uint32_t correlation_id = application_manager_.GetNextHMICorrelationID(); event_observer_->subscribe_on_event( @@ -1262,18 +1320,22 @@ void PolicyHandler::OnAllowSDLFunctionalityNotification( #ifdef EXTERNAL_PROPRIETARY_MODE - DataAccessor<ApplicationSet> accessor = - application_manager_.applications(); + ApplicationSet applications; + { + DataAccessor<ApplicationSet> accessor = + application_manager_.applications(); + applications = accessor.GetData(); + } if (!is_allowed) { std::for_each( - accessor.GetData().begin(), - accessor.GetData().end(), + applications.begin(), + applications.end(), DeactivateApplication(device_handle, application_manager_.state_controller())); } else { std::for_each( - accessor.GetData().begin(), - accessor.GetData().end(), + applications.begin(), + applications.end(), SDLAlowedNotification(device_handle, policy_manager_.get(), application_manager_.state_controller())); @@ -1507,6 +1569,8 @@ void PolicyHandler::OnPermissionsUpdated(const std::string& device_id, const std::string& policy_app_id, const Permissions& permissions) { LOG4CXX_AUTO_TRACE(logger_); + POLICY_LIB_CHECK_VOID(); + ApplicationSharedPtr app = application_manager_.application(device_id, policy_app_id); if (app.use_count() == 0) { @@ -1576,13 +1640,13 @@ void PolicyHandler::OnSnapshotCreated(const BinaryMessage& pt_string, POLICY_LIB_CHECK_VOID(); #ifdef PROPRIETARY_MODE if (PTUIterationType::RetryIteration == iteration_type) { - uint32_t app_id_for_sending = GetAppIdForSending(); - - if (0 != app_id_for_sending) { + uint32_t app_id_for_sending = 0; + const std::string& url = + GetNextUpdateUrl(PTUIterationType::RetryIteration, app_id_for_sending); + if (0 != url.length() && !policy_snapshot_path_.empty()) { MessageHelper::SendPolicySnapshotNotification( - app_id_for_sending, pt_string, std::string(), application_manager_); + app_id_for_sending, policy_snapshot_path_, url, application_manager_); } - } else { std::string policy_snapshot_full_path; if (!SaveSnapshot(pt_string, policy_snapshot_full_path)) { @@ -1597,28 +1661,75 @@ void PolicyHandler::OnSnapshotCreated(const BinaryMessage& pt_string, application_manager_); } #else // PROPRIETARY_MODE - LOG4CXX_ERROR(logger_, "HTTP policy"); - EndpointUrls urls; - policy_manager_->GetUpdateUrls("0x07", urls); + LOG4CXX_INFO(logger_, "HTTP policy"); - if (urls.empty()) { - LOG4CXX_ERROR(logger_, "Service URLs are empty! NOT sending PT to mobile!"); - return; + uint32_t app_id_for_sending = 0; + const std::string& url = GetNextUpdateUrl(iteration_type, app_id_for_sending); + if (0 != url.length()) { + SendMessageToSDK(pt_string, url, app_id_for_sending); } +#endif // PROPRIETARY_MODE +} - AppIdURL app_url = policy_manager_->GetNextUpdateUrl(urls); - while (!IsUrlAppIdValid(app_url.first, urls)) { - app_url = policy_manager_->GetNextUpdateUrl(urls); +std::string PolicyHandler::GetNextUpdateUrl( + const PTUIterationType iteration_type, uint32_t& app_id) { + LOG4CXX_AUTO_TRACE(logger_); + POLICY_LIB_CHECK_OR_RETURN(std::string()); + app_id = ChoosePTUApplication(iteration_type); + + if (0 == app_id) { + return std::string(); } - const std::string& url = urls[app_url.first].url[app_url.second]; - SendMessageToSDK(pt_string, url); -#endif // PROPRIETARY_MODE + + // Use cached URL for retries if it was provided by the HMI + if (PTUIterationType::RetryIteration == iteration_type && + !retry_update_url_.empty()) { + return retry_update_url_; + } + + EndpointUrls endpoint_urls; + policy_manager_->GetUpdateUrls("0x07", endpoint_urls); + + if (endpoint_urls.empty()) { + LOG4CXX_ERROR(logger_, "Service URLs are empty!"); + return std::string(); + } + + auto get_ptu_app = [this](AppIdURL app_url, uint32_t& app_id) { + if (app_url.first == 0 && app_url.second == 0) { + // We've looped past the end of the list, choose new application + app_id = ChoosePTUApplication(PTUIterationType::DefaultIteration); + if (0 == app_id) { + return ApplicationSharedPtr(); + } + } + return application_manager_.application(app_id); + }; + + AppIdURL app_url = policy_manager_->GetNextUpdateUrl(endpoint_urls); + ApplicationSharedPtr app = get_ptu_app(app_url, app_id); + if (!app) { + LOG4CXX_ERROR(logger_, "No available applications for PTU!"); + return std::string(); + } + EndpointData& data = endpoint_urls[app_url.first]; + while (!IsUrlAppIdValid(app->policy_app_id(), data)) { + app_url = policy_manager_->GetNextUpdateUrl(endpoint_urls); + app = get_ptu_app(app_url, app_id); + if (!app) { + LOG4CXX_ERROR(logger_, "No available applications for PTU!"); + return std::string(); + } + data = endpoint_urls[app_url.first]; + } + const std::string& url = data.url[app_url.second]; + return url; } #endif // EXTERNAL_PROPRIETARY_MODE bool PolicyHandler::GetPriority(const std::string& policy_app_id, std::string* priority) const { - POLICY_LIB_CHECK(false); + POLICY_LIB_CHECK_OR_RETURN(false); return policy_manager_->GetPriority(policy_app_id, priority); } @@ -1650,59 +1761,90 @@ void PolicyHandler::CheckPermissions( uint32_t PolicyHandler::GetNotificationsNumber( const std::string& priority) const { - POLICY_LIB_CHECK(0); + POLICY_LIB_CHECK_OR_RETURN(0); return policy_manager_->GetNotificationsNumber(priority); } DeviceConsent PolicyHandler::GetUserConsentForDevice( const std::string& device_id) const { - POLICY_LIB_CHECK(kDeviceDisallowed); + POLICY_LIB_CHECK_OR_RETURN(kDeviceDisallowed); return policy_manager_->GetUserConsentForDevice(device_id); } Json::Value PolicyHandler::GetPolicyTableData() const { + POLICY_LIB_CHECK_OR_RETURN(Json::Value()); return policy_manager_->GetPolicyTableData(); } bool PolicyHandler::GetDefaultHmi(const std::string& device_id, const std::string& policy_app_id, std::string* default_hmi) const { - POLICY_LIB_CHECK(false); + POLICY_LIB_CHECK_OR_RETURN(false); return policy_manager_->GetDefaultHmi(device_id, policy_app_id, default_hmi); } bool PolicyHandler::GetInitialAppData(const std::string& application_id, StringArray* nicknames, StringArray* app_hmi_types) { - POLICY_LIB_CHECK(false); + POLICY_LIB_CHECK_OR_RETURN(false); return policy_manager_->GetInitialAppData( application_id, nicknames, app_hmi_types); } void PolicyHandler::GetUpdateUrls(const std::string& service_type, - EndpointUrls& out_end_points) { + EndpointUrls& out_end_points) const { POLICY_LIB_CHECK_VOID(); policy_manager_->GetUpdateUrls(service_type, out_end_points); } void PolicyHandler::GetUpdateUrls(const uint32_t service_type, - EndpointUrls& out_end_points) { + EndpointUrls& out_end_points) const { POLICY_LIB_CHECK_VOID(); policy_manager_->GetUpdateUrls(service_type, out_end_points); } -std::string PolicyHandler::GetLockScreenIconUrl() const { - POLICY_LIB_CHECK(std::string("")); - return policy_manager_->GetLockScreenIconUrl(); +std::string PolicyHandler::GetLockScreenIconUrl( + const std::string& policy_app_id) const { + const std::string default_url; + POLICY_LIB_CHECK_OR_RETURN(default_url); + + EndpointUrls endpoints; + policy_manager_->GetUpdateUrls("lock_screen_icon_url", endpoints); + + auto it_specific = + std::find_if(endpoints.begin(), + endpoints.end(), + [&policy_app_id](const EndpointData& endpoint) { + return endpoint.app_id == policy_app_id; + }); + + if (endpoints.end() != it_specific && !it_specific->url.empty()) { + LOG4CXX_DEBUG(logger_, + "Specific app URL will be used for " << policy_app_id); + return it_specific->url.front(); + } + + auto it_default = std::find_if( + endpoints.begin(), endpoints.end(), [](const EndpointData& endpoint) { + return endpoint.app_id == kDefaultId; + }); + + if (endpoints.end() != it_default && !it_default->url.empty()) { + LOG4CXX_DEBUG(logger_, "Default URL will be used for " << policy_app_id); + return it_default->url.front(); + } + + LOG4CXX_ERROR(logger_, "Can't find URL for " << policy_app_id); + return std::string(); } std::string PolicyHandler::GetIconUrl(const std::string& policy_app_id) const { - POLICY_LIB_CHECK(std::string("")); + POLICY_LIB_CHECK_OR_RETURN(std::string("")); return policy_manager_->GetIconUrl(policy_app_id); } uint32_t PolicyHandler::NextRetryTimeout() { - POLICY_LIB_CHECK(0); + POLICY_LIB_CHECK_OR_RETURN(0); LOG4CXX_AUTO_TRACE(logger_); return policy_manager_->NextRetryTimeout(); } @@ -1712,7 +1854,7 @@ uint32_t PolicyHandler::TimeoutExchangeSec() const { } uint32_t PolicyHandler::TimeoutExchangeMSec() const { - POLICY_LIB_CHECK(0); + POLICY_LIB_CHECK_OR_RETURN(0); return policy_manager_->TimeoutExchangeMSec(); } @@ -1727,21 +1869,16 @@ void PolicyHandler::OnExceededTimeout() { policy_manager_->OnExceededTimeout(); } -void PolicyHandler::OnSystemReady() { - POLICY_LIB_CHECK_VOID(); - policy_manager_->OnSystemReady(); -} - const boost::optional<bool> PolicyHandler::LockScreenDismissalEnabledState() const { - POLICY_LIB_CHECK(boost::optional<bool>()); + POLICY_LIB_CHECK_OR_RETURN(boost::optional<bool>()); return policy_manager_->LockScreenDismissalEnabledState(); } const boost::optional<std::string> PolicyHandler::LockScreenDismissalWarningMessage( const std::string& language) const { - POLICY_LIB_CHECK(boost::optional<std::string>()); + POLICY_LIB_CHECK_OR_RETURN(boost::optional<std::string>()); return policy_manager_->LockScreenDismissalWarningMessage(language); } @@ -1976,7 +2113,7 @@ void PolicyHandler::RemoveDevice(const std::string& device_id) { bool PolicyHandler::IsApplicationRevoked(const std::string& app_id) { LOG4CXX_AUTO_TRACE(logger_); - POLICY_LIB_CHECK(false); + POLICY_LIB_CHECK_OR_RETURN(false); return policy_manager_->IsApplicationRevoked(app_id); } @@ -1988,12 +2125,12 @@ void PolicyHandler::OnUpdateRequestSentToMobile() { } bool PolicyHandler::CheckKeepContext(const std::string& policy_app_id) const { - POLICY_LIB_CHECK(false); + POLICY_LIB_CHECK_OR_RETURN(false); return policy_manager_->CanAppKeepContext(policy_app_id); } bool PolicyHandler::CheckStealFocus(const std::string& policy_app_id) const { - POLICY_LIB_CHECK(false); + POLICY_LIB_CHECK_OR_RETURN(false); return policy_manager_->CanAppStealFocus(policy_app_id); } @@ -2017,7 +2154,7 @@ bool PolicyHandler::CheckSystemAction( } std::vector<std::string> PolicyHandler::GetApplicationPolicyIDs() const { - POLICY_LIB_CHECK(std::vector<std::string>()); + POLICY_LIB_CHECK_OR_RETURN(std::vector<std::string>()); const auto all_policy_ids = policy_manager_->GetApplicationPolicyIDs(); std::vector<std::string> policy_app_ids; @@ -2041,18 +2178,18 @@ void PolicyHandler::GetEnabledCloudApps( bool PolicyHandler::GetAppProperties(const std::string& policy_app_id, AppProperties& out_app_properties) const { - POLICY_LIB_CHECK(false); + POLICY_LIB_CHECK_OR_RETURN(false); return policy_manager_->GetAppProperties(policy_app_id, out_app_properties); } std::vector<std::string> PolicyHandler::GetEnabledLocalApps() const { - POLICY_LIB_CHECK(std::vector<std::string>()); + POLICY_LIB_CHECK_OR_RETURN(std::vector<std::string>()); return policy_manager_->GetEnabledLocalApps(); } const bool PolicyHandler::CheckCloudAppEnabled( const std::string& policy_app_id) const { - POLICY_LIB_CHECK(false); + POLICY_LIB_CHECK_OR_RETURN(false); AppProperties out_app_properties; policy_manager_->GetAppProperties(policy_app_id, out_app_properties); return out_app_properties.enabled; @@ -2062,6 +2199,7 @@ PolicyHandler::AppPropertiesState PolicyHandler::GetAppPropertiesStatus( const smart_objects::SmartObject& properties, const std::string& app_id) const { LOG4CXX_AUTO_TRACE(logger_); + POLICY_LIB_CHECK_OR_RETURN(AppPropertiesState::NO_CHANGES); AppProperties app_properties; policy_manager_->GetAppProperties(app_id, app_properties); @@ -2118,7 +2256,7 @@ PolicyHandler::AppPropertiesState PolicyHandler::GetAppPropertiesStatus( const smart_objects::SmartArray* nicknames_array = properties[strings::nicknames].asArray(); - if (nicknames_array->empty() && !nicknames.empty()) { + if (nicknames_array->size() != nicknames.size()) { return AppPropertiesState::NICKNAMES_CHANGED; } @@ -2156,6 +2294,7 @@ PolicyHandler::AppPropertiesState PolicyHandler::GetAppPropertiesStatus( } bool PolicyHandler::IsNewApplication(const std::string& policy_app_id) const { + POLICY_LIB_CHECK_OR_RETURN(false); return policy_manager_->IsNewApplication(policy_app_id); } @@ -2214,6 +2353,7 @@ void PolicyHandler::OnSetAppProperties( } void PolicyHandler::OnLocalAppAdded() { + POLICY_LIB_CHECK_VOID(); policy_manager_->OnLocalAppAdded(); } @@ -2365,18 +2505,18 @@ bool PolicyHandler::CheckAppServiceParameters( bool PolicyHandler::UnknownRPCPassthroughAllowed( const std::string& policy_app_id) const { LOG4CXX_AUTO_TRACE(logger_); - POLICY_LIB_CHECK(false); + POLICY_LIB_CHECK_OR_RETURN(false); return policy_manager_->UnknownRPCPassthroughAllowed(policy_app_id); } uint32_t PolicyHandler::HeartBeatTimeout(const std::string& app_id) const { - POLICY_LIB_CHECK(0); + POLICY_LIB_CHECK_OR_RETURN(0); return policy_manager_->HeartBeatTimeout(app_id); } const std::string PolicyHandler::RemoteAppsUrl() const { const std::string default_url; - POLICY_LIB_CHECK(default_url); + POLICY_LIB_CHECK_OR_RETURN(default_url); EndpointUrls endpoints; policy_manager_->GetUpdateUrls("queryAppsUrl", endpoints); if (endpoints.empty() || endpoints[0].url.empty()) { @@ -2387,12 +2527,12 @@ const std::string PolicyHandler::RemoteAppsUrl() const { } void PolicyHandler::OnAppsSearchStarted() { - POLICY_LIB_CHECK(); + POLICY_LIB_CHECK_VOID(); policy_manager_->OnAppsSearchStarted(); } void PolicyHandler::OnAppsSearchCompleted(const bool trigger_ptu) { - POLICY_LIB_CHECK(); + POLICY_LIB_CHECK_VOID(); policy_manager_->OnAppsSearchCompleted(trigger_ptu); } @@ -2414,13 +2554,13 @@ void PolicyHandler::OnAppRegisteredOnMobile(const std::string& device_id, RequestType::State PolicyHandler::GetAppRequestTypeState( const std::string& policy_app_id) const { - POLICY_LIB_CHECK(RequestType::State::UNAVAILABLE); + POLICY_LIB_CHECK_OR_RETURN(RequestType::State::UNAVAILABLE); return policy_manager_->GetAppRequestTypesState(policy_app_id); } RequestSubType::State PolicyHandler::GetAppRequestSubTypeState( const std::string& policy_app_id) const { - POLICY_LIB_CHECK(RequestSubType::State::UNAVAILABLE); + POLICY_LIB_CHECK_OR_RETURN(RequestSubType::State::UNAVAILABLE); return policy_manager_->GetAppRequestSubTypesState(policy_app_id); } @@ -2428,7 +2568,7 @@ bool PolicyHandler::IsRequestTypeAllowed( const transport_manager::DeviceHandle& device_id, const std::string& policy_app_id, mobile_apis::RequestType::eType type) const { - POLICY_LIB_CHECK(false); + POLICY_LIB_CHECK_OR_RETURN(false); using namespace mobile_apis; const std::string stringified_type = RequestTypeToString(type); @@ -2469,7 +2609,7 @@ bool PolicyHandler::IsRequestTypeAllowed( bool PolicyHandler::IsRequestSubTypeAllowed( const std::string& policy_app_id, const std::string& request_subtype) const { - POLICY_LIB_CHECK(false); + POLICY_LIB_CHECK_OR_RETURN(false); using namespace mobile_apis; if (request_subtype.empty()) { @@ -2506,7 +2646,7 @@ bool PolicyHandler::IsRequestSubTypeAllowed( const std::vector<std::string> PolicyHandler::GetAppRequestTypes( const transport_manager::DeviceHandle& device_handle, const std::string& policy_app_id) const { - POLICY_LIB_CHECK(std::vector<std::string>()); + POLICY_LIB_CHECK_OR_RETURN(std::vector<std::string>()); #ifdef EXTERNAL_PROPRIETARY_MODE return policy_manager_->GetAppRequestTypes(device_handle, policy_app_id); #else @@ -2516,75 +2656,72 @@ const std::vector<std::string> PolicyHandler::GetAppRequestTypes( const std::vector<std::string> PolicyHandler::GetAppRequestSubTypes( const std::string& policy_app_id) const { - POLICY_LIB_CHECK(std::vector<std::string>()); + POLICY_LIB_CHECK_OR_RETURN(std::vector<std::string>()); return policy_manager_->GetAppRequestSubTypes(policy_app_id); } const std::vector<policy_table::VehicleDataItem> policy::PolicyHandler::GetVehicleDataItems() const { - POLICY_LIB_CHECK(std::vector<policy_table::VehicleDataItem>()); + POLICY_LIB_CHECK_OR_RETURN(std::vector<policy_table::VehicleDataItem>()); return policy_manager_->GetVehicleDataItems(); } std::vector<rpc::policy_table_interface_base::VehicleDataItem> policy::PolicyHandler::GetRemovedVehicleDataItems() const { + POLICY_LIB_CHECK_OR_RETURN(std::vector<policy_table::VehicleDataItem>()); return policy_manager_->GetRemovedVehicleDataItems(); } #ifdef EXTERNAL_PROPRIETARY_MODE const MetaInfo PolicyHandler::GetMetaInfo() const { - POLICY_LIB_CHECK(MetaInfo()); + POLICY_LIB_CHECK_OR_RETURN(MetaInfo()); return policy_manager_->GetMetaInfo(); } #endif // EXTERNAL_PROPRIETARY_MODE void PolicyHandler::Increment(usage_statistics::GlobalCounterId type) { - POLICY_LIB_CHECK(); + POLICY_LIB_CHECK_VOID(); policy_manager_->Increment(type); } void PolicyHandler::Increment(const std::string& app_id, usage_statistics::AppCounterId type) { - POLICY_LIB_CHECK(); + POLICY_LIB_CHECK_VOID(); policy_manager_->Increment(app_id, type); } void PolicyHandler::Set(const std::string& app_id, usage_statistics::AppInfoId type, const std::string& value) { - POLICY_LIB_CHECK(); + POLICY_LIB_CHECK_VOID(); policy_manager_->Set(app_id, type, value); } void PolicyHandler::Add(const std::string& app_id, usage_statistics::AppStopwatchId type, int32_t timespan_seconds) { - POLICY_LIB_CHECK(); + POLICY_LIB_CHECK_VOID(); policy_manager_->Add(app_id, type, timespan_seconds); } -bool PolicyHandler::IsUrlAppIdValid(const uint32_t app_idx, - const EndpointUrls& urls) const { - const EndpointData& app_data = urls[app_idx]; - const std::vector<std::string> app_urls = app_data.url; - const ApplicationSharedPtr app = - application_manager_.application_by_policy_id(app_data.app_id); - +bool PolicyHandler::IsUrlAppIdValid(const std::string app_id, + const EndpointData& app_data) const { if (policy::kDefaultId == app_data.app_id) { return true; } - if (app_urls.empty()) { + const std::vector<std::string> app_urls = app_data.url; + if (app_urls.empty() || app_id != app_data.app_id) { return false; } - const auto devices_ids = GetDevicesIds(app_data.app_id); - LOG4CXX_TRACE(logger_, - "Count devices: " << devices_ids.size() - << " for app_id: " << app_data.app_id); + const auto devices_ids = GetDevicesIds(app_id); + LOG4CXX_TRACE( + logger_, + "Count devices: " << devices_ids.size() << " for app_id: " << app_id); for (const auto& device_id : devices_ids) { - ApplicationSharedPtr app = - application_manager_.application(device_id, app_data.app_id); + const ApplicationSharedPtr app = + application_manager_.application(device_id, app_id); if (app && (app->IsRegistered())) { return true; } @@ -2625,7 +2762,7 @@ void PolicyHandler::UpdateHMILevel(ApplicationSharedPtr app, bool PolicyHandler::CheckModule(const PTString& app_id, const PTString& module) { - POLICY_LIB_CHECK(false); + POLICY_LIB_CHECK_OR_RETURN(false); return policy_manager_->CheckModule(app_id, module); } @@ -2670,7 +2807,7 @@ void PolicyHandler::OnUpdateHMIStatus(const std::string& device_id, bool PolicyHandler::GetModuleTypes(const std::string& policy_app_id, std::vector<std::string>* modules) const { LOG4CXX_AUTO_TRACE(logger_); - POLICY_LIB_CHECK(false); + POLICY_LIB_CHECK_OR_RETURN(false); return policy_manager_->GetModuleTypes(policy_app_id, modules); } @@ -2695,7 +2832,7 @@ bool PolicyHandler::CheckHMIType(const std::string& application_id, mobile_apis::AppHMIType::eType hmi, const smart_objects::SmartObject* app_types) { LOG4CXX_AUTO_TRACE(logger_); - POLICY_LIB_CHECK(false); + POLICY_LIB_CHECK_OR_RETURN(false); std::vector<int> policy_hmi_types; bool ret = policy_manager_->GetHMITypes(application_id, &policy_hmi_types); diff --git a/src/components/application_manager/src/resumption/resume_ctrl_impl.cc b/src/components/application_manager/src/resumption/resume_ctrl_impl.cc index 486cb76369..2d5f1b6638 100644 --- a/src/components/application_manager/src/resumption/resume_ctrl_impl.cc +++ b/src/components/application_manager/src/resumption/resume_ctrl_impl.cc @@ -468,6 +468,7 @@ void ResumeCtrlImpl::OnSuspend() { void ResumeCtrlImpl::OnIgnitionOff() { LOG4CXX_AUTO_TRACE(logger_); + DCHECK_OR_RETURN_VOID(resumption_storage_); if (!application_manager_.IsLowVoltage()) { resumption_storage_->IncrementIgnOffCount(); resumption_storage_->ResetGlobalIgnOnCount(); @@ -629,15 +630,19 @@ bool ResumeCtrlImpl::StartAppHmiStateResumption( LOG4CXX_DEBUG(logger_, "No applicable HMI level found for resuming"); return false; } - const bool is_resume_allowed_by_low_voltage = CheckLowVoltageRestrictions(saved_app); const bool is_hmi_level_allowed_by_ign_cycle = CheckIgnCycleRestrictions(saved_app); - const bool restore_hmi_level_allowed = - is_resume_allowed_by_low_voltage && is_hmi_level_allowed_by_ign_cycle; + const bool is_app_revoked = + application_manager_.GetPolicyHandler().IsApplicationRevoked( + application->policy_app_id()); + + const bool restore_hmi_level_allowed = is_resume_allowed_by_low_voltage && + is_hmi_level_allowed_by_ign_cycle && + !is_app_revoked; if (restore_hmi_level_allowed) { LOG4CXX_INFO(logger_, @@ -726,6 +731,7 @@ void ResumeCtrlImpl::SaveDataOnTimer() { void ResumeCtrlImpl::FinalPersistData() { LOG4CXX_AUTO_TRACE(logger_); + DCHECK_OR_RETURN_VOID(resumption_storage_); StopSavePersistentDataTimer(); SaveAllApplications(); resumption_storage_->Persist(); diff --git a/src/components/application_manager/src/rpc_handler_impl.cc b/src/components/application_manager/src/rpc_handler_impl.cc index 0a62bc8498..44a5af6f41 100644 --- a/src/components/application_manager/src/rpc_handler_impl.cc +++ b/src/components/application_manager/src/rpc_handler_impl.cc @@ -108,8 +108,12 @@ void RPCHandlerImpl::ProcessMessageFromMobile( allow_unknown_parameters = true; } - if (!ConvertMessageToSO( - *message, *so_from_mobile, allow_unknown_parameters, !rpc_passing)) { + std::string warning_info; + if (!ConvertMessageToSO(*message, + *so_from_mobile, + warning_info, + allow_unknown_parameters, + !rpc_passing)) { LOG4CXX_ERROR(logger_, "Cannot create smart object from message"); return; } @@ -131,7 +135,7 @@ void RPCHandlerImpl::ProcessMessageFromMobile( commands::Command::SOURCE_MOBILE, message_type)) { // Since PassThrough failed, refiltering the message - if (!ConvertMessageToSO(*message, *so_from_mobile)) { + if (!ConvertMessageToSO(*message, *so_from_mobile, warning_info)) { LOG4CXX_ERROR(logger_, "Cannot create smart object from message"); return; } @@ -143,7 +147,7 @@ void RPCHandlerImpl::ProcessMessageFromMobile( #endif // TELEMETRY_MONITOR if (!app_manager_.GetRPCService().ManageMobileCommand( - so_from_mobile, commands::Command::SOURCE_MOBILE)) { + so_from_mobile, commands::Command::SOURCE_MOBILE, warning_info)) { LOG4CXX_ERROR(logger_, "Received command didn't run successfully"); } #ifdef TELEMETRY_MONITOR @@ -176,7 +180,9 @@ void RPCHandlerImpl::ProcessMessageFromHMI( allow_unknown_parameters = true; } - if (!ConvertMessageToSO(*message, *smart_object, allow_unknown_parameters)) { + std::string warning_info; + if (!ConvertMessageToSO( + *message, *smart_object, warning_info, allow_unknown_parameters)) { if (application_manager::MessageType::kResponse == (*smart_object)[strings::params][strings::message_type].asInt()) { (*smart_object).erase(strings::msg_params); @@ -190,8 +196,14 @@ void RPCHandlerImpl::ProcessMessageFromHMI( } } + if (!warning_info.empty()) { + LOG4CXX_WARN(logger_, + "Warning while parsing HMI message: " << warning_info); + } + LOG4CXX_DEBUG(logger_, "Converted message, trying to create hmi command"); - if (!app_manager_.GetRPCService().ManageHMICommand(smart_object)) { + if (!app_manager_.GetRPCService().ManageHMICommand( + smart_object, commands::Command::SOURCE_HMI, warning_info)) { LOG4CXX_ERROR(logger_, "Received command didn't run successfully"); } } @@ -320,6 +332,7 @@ void RPCHandlerImpl::GetMessageVersion( bool RPCHandlerImpl::ConvertMessageToSO( const Message& message, ns_smart_device_link::ns_smart_objects::SmartObject& output, + std::string& out_warning_info, const bool allow_unknown_parameters, const bool validate_params) { LOG4CXX_AUTO_TRACE(logger_); @@ -382,6 +395,9 @@ bool RPCHandlerImpl::ConvertMessageToSO( "Convertion result for sdl object is true function_id " << output[jhs::S_PARAMS][jhs::S_FUNCTION_ID].asInt()); + // Populate any warning info generated during the validation process + out_warning_info = rpc::PrettyFormat(report); + output[strings::params][strings::connection_key] = message.connection_key(); output[strings::params][strings::protocol_version] = @@ -534,7 +550,7 @@ bool RPCHandlerImpl::ValidateRpcSO(smart_objects::SmartObject& message, rpc::ValidationReport& report_out, bool allow_unknown_parameters) { if (!mobile_so_factory().attachSchema( - message, !allow_unknown_parameters, msg_version) || + message, !allow_unknown_parameters, msg_version, &report_out) || message.validate(&report_out, msg_version, allow_unknown_parameters) != smart_objects::errors::OK) { LOG4CXX_WARN(logger_, "Failed to parse string to smart object"); diff --git a/src/components/application_manager/src/rpc_service_impl.cc b/src/components/application_manager/src/rpc_service_impl.cc index 627c7265bc..c7959c2386 100644 --- a/src/components/application_manager/src/rpc_service_impl.cc +++ b/src/components/application_manager/src/rpc_service_impl.cc @@ -112,10 +112,16 @@ EncryptionFlagCheckResult RPCServiceImpl::IsEncryptionRequired( ? EncryptionFlagCheckResult::kSuccess_Protected : EncryptionFlagCheckResult::kSuccess_NotProtected; } - bool RPCServiceImpl::ManageMobileCommand( const commands::MessageSharedPtr message, commands::Command::CommandSource source) { + return ManageMobileCommand(message, source, std::string()); +} + +bool RPCServiceImpl::ManageMobileCommand( + const commands::MessageSharedPtr message, + commands::Command::CommandSource source, + const std::string warning_info) { LOG4CXX_AUTO_TRACE(logger_); if (!message) { @@ -206,7 +212,7 @@ bool RPCServiceImpl::ManageMobileCommand( int32_t message_type = (*message)[strings::params][strings::message_type].asInt(); if (message_type == mobile_apis::messageType::response) { - if (command->Init()) { + if (command->Init() && command->CheckPermissions()) { command->Run(); command->CleanUp(); } @@ -214,7 +220,7 @@ bool RPCServiceImpl::ManageMobileCommand( } if (message_type == mobile_apis::messageType::notification) { request_ctrl_.addNotification(command); - if (command->Init()) { + if (command->Init() && command->CheckPermissions()) { command->Run(); if (command->CleanUp()) { request_ctrl_.removeNotification(command.get()); @@ -226,7 +232,7 @@ bool RPCServiceImpl::ManageMobileCommand( if (message_type == mobile_apis::messageType::request && source == commands::Command::CommandSource::SOURCE_SDL) { - if (command->Init()) { + if (command->Init() && command->CheckPermissions()) { command->Run(); command->CleanUp(); return true; @@ -237,7 +243,6 @@ bool RPCServiceImpl::ManageMobileCommand( if (message_type == mobile_apis::messageType::request && source == commands::Command::CommandSource::SOURCE_MOBILE) { - // commands will be launched from requesr_ctrl mobile_apis::HMILevel::eType app_hmi_level = mobile_apis::HMILevel::INVALID_ENUM; if (app) { @@ -245,8 +250,9 @@ bool RPCServiceImpl::ManageMobileCommand( app->hmi_level(mobile_apis::PredefinedWindows::DEFAULT_WINDOW); } - // commands will be launched from request_ctrl + command->set_warning_info(warning_info); + // commands will be launched from request_ctrl const request_controller::RequestController::TResult result = request_ctrl_.addMobileRequest(command, app_hmi_level); @@ -326,6 +332,12 @@ bool RPCServiceImpl::ManageMobileCommand( bool RPCServiceImpl::ManageHMICommand(const commands::MessageSharedPtr message, commands::Command::CommandSource source) { + return ManageHMICommand(message, source, std::string()); +} + +bool RPCServiceImpl::ManageHMICommand(const commands::MessageSharedPtr message, + commands::Command::CommandSource source, + const std::string warning_info) { LOG4CXX_AUTO_TRACE(logger_); if (!message) { @@ -375,6 +387,7 @@ bool RPCServiceImpl::ManageHMICommand(const commands::MessageSharedPtr message, if (kRequest == message_type) { LOG4CXX_DEBUG(logger_, "ManageHMICommand"); + command->set_warning_info(warning_info); request_ctrl_.addHMIRequest(command); } diff --git a/src/components/application_manager/src/smart_object_keys.cc b/src/components/application_manager/src/smart_object_keys.cc index fe0f878e6c..e0204fd6c7 100644 --- a/src/components/application_manager/src/smart_object_keys.cc +++ b/src/components/application_manager/src/smart_object_keys.cc @@ -438,6 +438,19 @@ const char* const x = "x"; const char* const y = "y"; } // namespace strings +namespace hmi_interface { +const char* basic_communication = "BasicCommunication"; +const char* buttons = "Buttons"; +const char* navigation = "Navigation"; +const char* sdl = "SDL"; +const char* tts = "TTS"; +const char* ui = "UI"; +const char* vr = "VR"; +const char* rc = "RC"; +const char* vehicle_info = "VehicleInfo"; +const char* app_service = "AppService"; +} // namespace hmi_interface + namespace json { const char* appId = "appId"; const char* name = "name"; @@ -547,6 +560,7 @@ const char* capabilities = "capabilities"; const char* speech_capabilities = "speechCapabilities"; const char* prerecorded_speech_capabilities = "prerecordedSpeechCapabilities"; const char* preset_bank_capabilities = "presetBankCapabilities"; +const char* on_screen_presets_available = "onScreenPresetsAvailable"; const char* allowed = "allowed"; const char* vehicle_type = "vehicleType"; const char* did_result = "didResult"; diff --git a/src/components/application_manager/test/CMakeLists.txt b/src/components/application_manager/test/CMakeLists.txt index 230be524c8..c9c9a80391 100755 --- a/src/components/application_manager/test/CMakeLists.txt +++ b/src/components/application_manager/test/CMakeLists.txt @@ -47,6 +47,7 @@ include_directories( ${COMPONENTS_DIR}/application_manager/test/include/ ${COMPONENTS_DIR}/application_manager/rpc_plugins/sdl_rpc_plugin/include/ ${COMPONENTS_DIR}/application_manager/rpc_plugins/vehicle_info_plugin/include/ + ${COMPONENTS_DIR}/application_manager/rpc_plugins/rc_rpc_plugin/include/ ${BSON_INCLUDE_DIRECTORY} ) @@ -69,6 +70,7 @@ set(testSources ${AM_TEST_DIR}/rpc_passing_handler_test.cc ${AM_TEST_DIR}/application_manager_impl_test.cc ${AM_TEST_DIR}/application_helper_test.cc + ${AM_TEST_DIR}/rpc_service_impl_test.cc ${AM_TEST_DIR}/command_holder_test.cc ) @@ -157,7 +159,7 @@ set(ResumptionData_SOURCES ${AM_TEST_DIR}/mock_message_helper.cc ) -file(COPY hmi_capabilities.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +file(COPY ${CMAKE_SOURCE_DIR}/src/appMain/hmi_capabilities.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY hmi_capabilities_sc1.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY hmi_capabilities_sc2.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY hmi_capabilities_old_apt.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) 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 2c16048e97..d19cbbad22 100644 --- a/src/components/application_manager/test/application_manager_impl_test.cc +++ b/src/components/application_manager/test/application_manager_impl_test.cc @@ -269,6 +269,17 @@ class ApplicationManagerImplTest ASSERT_TRUE(mock_app_ptr_.get()); } + void SetExpectationForCreateModuleInfoSO( + const hmi_apis::FunctionID::eType function_id) { + smart_objects::SmartObject sm_object(smart_objects::SmartType_Map); + sm_object[strings::params][strings::function_id] = + static_cast<int>(function_id); + auto sptr = std::make_shared<smart_objects::SmartObject>(sm_object); + + ON_CALL(*mock_message_helper_, CreateModuleInfoSO(function_id, _)) + .WillByDefault(Return(sptr)); + } + application_manager::commands::MessageSharedPtr CreateCloseAppMessage() { using namespace application_manager; @@ -351,6 +362,13 @@ class ApplicationManagerImplTest mock_statistics_manager_; }; +MATCHER_P(HMIFunctionIDIs, result_code, "") { + return result_code == static_cast<hmi_apis::FunctionID::eType>( + (*arg)[application_manager::strings::params] + [application_manager::strings::function_id] + .asInt()); +} + INSTANTIATE_TEST_CASE_P( ProcessServiceStatusUpdate_REQUEST_ACCEPTED, ApplicationManagerImplTest, @@ -1198,14 +1216,19 @@ TEST_F(ApplicationManagerImplTest, StartStopAudioPassThru) { const uint32_t app_id = 65537; const int32_t max_duration = 1000; - // below are not used const int32_t correlation_id = 0; const int32_t sampling_rate = 0; const int32_t bits_per_sample = 0; const int32_t audio_type = 0; - EXPECT_CALL(mock_media_manager, - StartMicrophoneRecording(app_id, _, max_duration)) + EXPECT_CALL( + mock_media_manager, + StartMicrophoneRecording(app_id, + _, + max_duration, + mobile_apis::SamplingRate::SamplingRate_8KHZ, + mobile_apis::BitsPerSample::BitsPerSample_8_BIT, + mobile_apis::AudioType::PCM)) .WillOnce(Return()); EXPECT_CALL(mock_media_manager, StopMicrophoneRecording(app_id)) .WillOnce(Return()); @@ -1282,14 +1305,19 @@ TEST_F(ApplicationManagerImplTest, UnregisterAnotherAppDuringAudioPassThru) { app_manager_impl_->AddMockApplication(mock_app_2); const int32_t max_duration = 1000; - // below are not used const int32_t correlation_id = 0; const int32_t sampling_rate = 0; const int32_t bits_per_sample = 0; const int32_t audio_type = 0; - EXPECT_CALL(mock_media_manager, - StartMicrophoneRecording(app_id_2, _, max_duration)) + EXPECT_CALL( + mock_media_manager, + StartMicrophoneRecording(app_id_2, + _, + max_duration, + mobile_apis::SamplingRate::SamplingRate_8KHZ, + mobile_apis::BitsPerSample::BitsPerSample_8_BIT, + mobile_apis::AudioType::PCM)) .WillOnce(Return()); EXPECT_CALL(mock_media_manager, StopMicrophoneRecording(app_id_2)) .WillOnce(Return()); @@ -2028,6 +2056,26 @@ TEST_F(ApplicationManagerImplTest, AddAndRemoveQueryAppDevice_SUCCESS) { EXPECT_FALSE(app_manager_impl_->IsAppsQueriedFrom(device_handle)); } +TEST_F( + ApplicationManagerImplTest, + RequestForInterfacesAvailability_AllRequestsWillBeSuccessfullyRequested) { + std::vector<hmi_apis::FunctionID::eType> expected_requests{ + hmi_apis::FunctionID::VehicleInfo_IsReady, + hmi_apis::FunctionID::VR_IsReady, + hmi_apis::FunctionID::TTS_IsReady, + hmi_apis::FunctionID::UI_IsReady, + hmi_apis::FunctionID::RC_IsReady}; + + for (auto request : expected_requests) { + SetExpectationForCreateModuleInfoSO(request); + EXPECT_CALL(*mock_rpc_service_, + ManageHMICommand(HMIFunctionIDIs(request), + commands::Command::SOURCE_HMI)); + } + + app_manager_impl_->RequestForInterfacesAvailability(); +} + } // namespace application_manager_test } // namespace components } // namespace test diff --git a/src/components/application_manager/test/commands/command_request_impl_test.cc b/src/components/application_manager/test/commands/command_request_impl_test.cc index 2b3231ba98..9034bf442f 100644 --- a/src/components/application_manager/test/commands/command_request_impl_test.cc +++ b/src/components/application_manager/test/commands/command_request_impl_test.cc @@ -402,6 +402,8 @@ TEST_F(CommandRequestImplTest, MessageSharedPtr message = CreateMessage(); (*message)[strings::msg_params] = smart_objects::SmartObject(smart_objects::SmartType_Map); + (*message)[strings::params][strings::message_type] = + mobile_apis::messageType::request; CommandPtr command = CreateCommand<UCommandRequestImpl>(message); @@ -541,8 +543,8 @@ TEST_F(CommandRequestImplTest, HashUpdateAllowed_UpdateExpected) { EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) .WillOnce(DoAll(SaveArg<0>(&result), Return(true))); - const bool is_succedeed = true; - command->SendResponse(is_succedeed, kMobResultSuccess, NULL, NULL); + const bool is_succeeded = true; + command->SendResponse(is_succeeded, kMobResultSuccess, NULL, NULL); MockAppPtr mock_app = CreateMockApp(); EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app)); @@ -562,8 +564,8 @@ TEST_F(CommandRequestImplTest, HashUpdateDisallowed_HashUpdateNotExpected) { EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) .WillOnce(DoAll(SaveArg<0>(&result), Return(true))); - const bool is_succedeed = true; - command->SendResponse(is_succedeed, kMobResultSuccess, NULL, NULL); + const bool is_succeeded = true; + command->SendResponse(is_succeeded, kMobResultSuccess, NULL, NULL); MockAppPtr mock_app = CreateMockApp(); EXPECT_CALL(*mock_app, UpdateHash()).Times(0); @@ -581,8 +583,8 @@ TEST_F(CommandRequestImplTest, RequestFailed_HashUpdateNotExpected) { EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) .WillOnce(DoAll(SaveArg<0>(&result), Return(true))); - const bool is_succedeed = false; - command->SendResponse(is_succedeed, kMobResultSuccess, NULL, NULL); + const bool is_succeeded = false; + command->SendResponse(is_succeeded, kMobResultSuccess, NULL, NULL); MockAppPtr mock_app = CreateMockApp(); EXPECT_CALL(*mock_app, UpdateHash()).Times(0); @@ -600,8 +602,8 @@ TEST_F(CommandRequestImplTest, AppNotFound_HashUpdateNotExpected) { EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) .WillOnce(DoAll(SaveArg<0>(&result), Return(true))); - const bool is_succedeed = true; - command->SendResponse(is_succedeed, kMobResultSuccess, NULL, NULL); + const bool is_succeeded = true; + command->SendResponse(is_succeeded, kMobResultSuccess, NULL, NULL); MockAppPtr mock_app = CreateMockApp(); EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(MockAppPtr())); diff --git a/src/components/application_manager/test/hmi_capabilities.json b/src/components/application_manager/test/hmi_capabilities.json deleted file mode 100644 index afa5fa6056..0000000000 --- a/src/components/application_manager/test/hmi_capabilities.json +++ /dev/null @@ -1,731 +0,0 @@ -{ - "UI": { - "language":"EN_US", - "languages":[ - "EN_US", - "ES_MX", - "FR_CA", - "DE_DE", - "ES_ES", - "EN_GB", - "RU_RU", - "TR_TR", - "PL_PL", - "FR_FR", - "IT_IT", - "SV_SE", - "PT_PT", - "NL_NL", - "ZH_TW", - "JA_JP", - "AR_SA", - "KO_KR", - "PT_BR", - "CS_CZ", - "DA_DK", - "NO_NO", - "NL_BE", - "EL_GR", - "HU_HU", - "FI_FI", - "SK_SK", - "EN_IN", - "TH_TH", - "EN_SA", - "HE_IL", - "RO_RO", - "UK_UA", - "ID_ID", - "VI_VN", - "MS_MY", - "HI_IN" - ], - "displayCapabilities": { - "displayType": "GEN2_8_DMA", - "displayName": "GENERIC_DISPLAY", - "textFields": [ - { - "name": "mainField1", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "mainField2", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "mainField3", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "mainField4", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "statusBar", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "mediaClock", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "mediaTrack", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "alertText1", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "alertText2", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "alertText3", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "scrollableMessageBody", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "initialInteractionText", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "navigationText1", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "navigationText2", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "ETA", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "totalDistance", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "navigationText", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "audioPassThruDisplayText1", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "audioPassThruDisplayText2", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "sliderHeader", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "sliderFooter", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "notificationText", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "menuName", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "secondaryText", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "tertiaryText", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "timeToDestination", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "turnText", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - }, - { - "name": "menuTitle", - "characterSet": "TYPE2SET", - "width": 500, - "rows": 1 - } - ], - "imageFields": [ - { - "name": "softButtonImage", - "imageTypeSupported": [ - "GRAPHIC_PNG" - ], - "imageResolution": { - "resolutionWidth": 35, - "resolutionHeight": 35 - } - }, - { - "name": "choiceImage", - "imageTypeSupported": [ - "GRAPHIC_PNG" - ], - "imageResolution": { - "resolutionWidth": 35, - "resolutionHeight": 35 - } - }, - { - "name": "choiceSecondaryImage", - "imageTypeSupported": [ - "GRAPHIC_PNG" - ], - "imageResolution": { - "resolutionWidth": 35, - "resolutionHeight": 35 - } - }, - { - "name": "menuIcon", - "imageTypeSupported": [ - "GRAPHIC_PNG" - ], - "imageResolution": { - "resolutionWidth": 35, - "resolutionHeight": 35 - } - }, - { - "name": "cmdIcon", - "imageTypeSupported": [ - "GRAPHIC_PNG" - ], - "imageResolution": { - "resolutionWidth": 35, - "resolutionHeight": 35 - } - }, - { - "name": "appIcon", - "imageTypeSupported": [ - "GRAPHIC_PNG" - ], - "imageResolution": { - "resolutionWidth": 35, - "resolutionHeight": 35 - } - }, - { - "name": "graphic", - "imageTypeSupported": [ - "GRAPHIC_PNG" - ], - "imageResolution": { - "resolutionWidth": 35, - "resolutionHeight": 35 - } - }, - { - "name": "secondaryGraphic", - "imageTypeSupported": [ - "GRAPHIC_PNG" - ], - "imageResolution": { - "resolutionWidth": 35, - "resolutionHeight": 35 - } - }, - { - "name": "locationImage", - "imageTypeSupported": [ - "GRAPHIC_PNG" - ], - "imageResolution": { - "resolutionWidth": 35, - "resolutionHeight": 35 - } - } - - ], - "mediaClockFormats": [ - "CLOCK1", - "CLOCK2", - "CLOCK3", - "CLOCKTEXT1", - "CLOCKTEXT2", - "CLOCKTEXT3", - "CLOCKTEXT4" - ], - "graphicSupported": true, - "templatesAvailable": [ - - "DEFAULT", - "MEDIA", - "NON-MEDIA", - "ONSCREEN_PRESETS", - "NAV_FULLSCREEN_MAP", - "NAV_KEYBOARD", - "GRAPHIC_WITH_TEXT", - "TEXT_WITH_GRAPHIC", - "TILES_ONLY", - "TEXTBUTTONS_ONLY", - "GRAPHIC_WITH_TILES", - "TILES_WITH_GRAPHIC", - "GRAPHIC_WITH_TEXT_AND_SOFTBUTTONS", - "TEXT_AND_SOFTBUTTONS_WITH_GRAPHIC", - "GRAPHIC_WITH_TEXTBUTTONS", - "TEXTBUTTONS_WITH_GRAPHIC", - "LARGE_GRAPHIC_WITH_SOFTBUTTONS", - "DOUBLE_GRAPHIC_WITH_SOFTBUTTONS", - "LARGE_GRAPHIC_ONLY" - ], - "screenParams": { - "resolution": { - "resolutionWidth": 800, - "resolutionHeight": 350 - }, - "touchEventAvailable": { - "pressAvailable": true, - "multiTouchAvailable": false, - "doublePressAvailable": false - } - }, - "numCustomPresetsAvailable": 8, - "imageCapabilities": [ - "DYNAMIC", - "STATIC" - ] - }, - "audioPassThruCapabilities": [{ - "samplingRate": "44KHZ", - "bitsPerSample": "RATE_8_BIT", - "audioType": "PCM" - }], - "pcmStreamCapabilities": { - "samplingRate": "16KHZ", - "bitsPerSample": "RATE_16_BIT", - "audioType": "PCM" - }, - "hmiZoneCapabilities": "FRONT", - "softButtonCapabilities": [ - { - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true, - "imageSupported": true - } - ], - "systemCapabilities": { - "navigationCapability": { - "sendLocationEnabled": true, - "getWayPointsEnabled": true - }, - "phoneCapability": { - "dialNumberEnabled": true - }, - - "remoteControlCapability":{ - "climateControlCapabilities": [ - { - "moduleName": "primary_climate", - "fanSpeedAvailable": true, - "desiredTemperatureAvailable": true, - "acEnableAvailable": true, - "acMaxEnableAvailable": true, - "circulateAirEnableAvailable": true, - "autoModeEnableAvailable": true, - "dualModeEnableAvailable": true, - "defrostZoneAvailable": true, - "ventilationModeAvailable": true, - "defrostZone": [ - "FRONT", - "REAR", - "ALL", - "NONE" - ], - "ventilationMode": [ - "UPPER", - "LOWER", - "BOTH", - "NONE" - ] - } - ], - "radioControlCapabilities": [ - { - "moduleName": "radio", - "radioEnableAvailable": true, - "radioBandAvailable": true, - "radioFrequencyAvailable": true, - "hdChannelAvailable": true, - "rdsDataAvailable": true, - "availableHDsAvailable": true, - "stateAvailable": true, - "signalStrengthAvailable": true, - "signalChangeThresholdAvailable": true - } - ], - "buttonCapabilities": [ - { - "name": "AC_MAX", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "AC", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "RECIRCULATE", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "FAN_UP", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "FAN_DOWN", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "TEMP_UP", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "TEMP_DOWN", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "DEFROST_MAX", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "DEFROST", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "DEFROST_REAR", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "UPPER_VENT", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "LOWER_VENT", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "VOLUME_UP", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "VOLUME_DOWN", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "EJECT", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "SOURCE", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "SHUFFLE", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - }, - { - "name": "REPEAT", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": false - } - ] - }, - "videoStreamingCapability": { - "preferredResolution": { - "resolutionWidth": 800, - "resolutionHeight": 350 - }, - "maxBitrate": 10000, - "supportedFormats": [ - { - "protocol": "RAW", - "codec": "H264" - }, - { - "protocol": "RTP", - "codec": "Theora" - } - ], - "hapticSpatialDataSupported": true - } - } - }, - "VR": { - "capabilities": [ - "TEXT" - ], - "language": "ES_MX", - "languages": [ - "AR_SA", - "EN_US", - "ES_MX", - "FR_CA", - "DE_DE", - "ES_ES", - "EN_GB", - "RU_RU", - "TR_TR", - "PL_PL", - "FR_FR", - "IT_IT", - "SV_SE", - "PT_PT", - "NL_NL", - "ZH_TW", - "JA_JP", - "KO_KR", - "PT_BR", - "CS_CZ", - "DA_DK", - "NO_NO" - ] - }, - "TTS": { - "capabilities": [ - "TEXT" - ], - "language": "DE_DE", - "languages": [ - "DA_DK", - "CS_CZ", - "KO_KR", - "EN_US", - "ES_MX", - "FR_CA", - "DE_DE", - "ES_ES", - "EN_GB", - "RU_RU", - "TR_TR", - "PL_PL", - "FR_FR", - "IT_IT", - "SV_SE", - "PT_PT", - "NL_NL", - "ZH_TW", - "JA_JP", - "AR_SA", - "PT_BR", - "NO_NO" - ] - }, - "Buttons": { - "capabilities": [ - { - "name": "PRESET_0", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PRESET_1", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PRESET_2", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PRESET_3", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PRESET_4", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PRESET_5", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PRESET_6", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PRESET_7", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PRESET_8", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PRESET_9", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "OK", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "PLAY_PAUSE", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "SEEKLEFT", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "SEEKRIGHT", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "TUNEUP", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - }, - { - "name": "TUNEDOWN", - "shortPressAvailable": true, - "longPressAvailable": true, - "upDownAvailable": true - } - ], - "presetBankCapabilities": { - "onScreenPresetsAvailable": true - } - }, - "VehicleInfo": { - "make": "Ford", - "model": "Fiesta", - "modelYear": "2013", - "trim": "SE" - }, - "SyncMessageVersion": { - "majorVersion": 3, - "minorVersion": 0 - } -} diff --git a/src/components/application_manager/test/hmi_capabilities_sc2.json b/src/components/application_manager/test/hmi_capabilities_sc2.json index a8578f04f5..318fcf7a3e 100644 --- a/src/components/application_manager/test/hmi_capabilities_sc2.json +++ b/src/components/application_manager/test/hmi_capabilities_sc2.json @@ -1,5 +1,11 @@ { "UI": { + "language": "EN_US", + "languages": [ + "EN_US", + "ES_MX", + "FR_CA" + ], "systemCapabilities": { "navigationCapability": { "sendLocationEnabled": true, diff --git a/src/components/application_manager/test/hmi_capabilities_test.cc b/src/components/application_manager/test/hmi_capabilities_test.cc index 6234830f50..73e86fc7a7 100644 --- a/src/components/application_manager/test/hmi_capabilities_test.cc +++ b/src/components/application_manager/test/hmi_capabilities_test.cc @@ -33,7 +33,12 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include "application_manager/hmi_capabilities_impl.h" + +#include <algorithm> +#include <memory> #include <string> +#include <vector> #include "application_manager/hmi_capabilities.h" #include "application_manager/mock_message_helper.h" @@ -42,81 +47,57 @@ #include "smart_objects/enum_schema_item.h" #include "smart_objects/smart_object.h" -#include "application_manager/hmi_capabilities_for_testing.h" #include "application_manager/mock_application_manager.h" #include "application_manager/mock_application_manager_settings.h" #include "application_manager/mock_event_dispatcher.h" #include "application_manager/mock_rpc_service.h" #include "application_manager/resumption/resume_ctrl.h" #include "application_manager/state_controller.h" +#include "rc_rpc_plugin/rc_module_constants.h" #include "resumption/last_state_impl.h" #include "resumption/last_state_wrapper_impl.h" #include "utils/file_system.h" +#include "utils/jsoncpp_reader_wrapper.h" namespace test { namespace components { namespace application_manager_test { +namespace { +const std::string kAppInfoDataFile = "./app_info_data"; +const std::string kAppStorageFolder = "app_storage_folder"; +const std::string kAppInfoStorage = "app_info_storage"; +const std::string kHmiCapabilitiesDefaultFile = "hmi_capabilities.json"; +const std::string kHmiCapabilitiesCacheFile = "hmi_capabilities_cache.json"; +const uint32_t kEqualizerMaxChanelId = 10; +} // namespace + using ::testing::_; -using ::testing::AtLeast; -using ::testing::InSequence; using ::testing::Invoke; +using ::testing::NiceMock; using ::testing::Return; using ::testing::ReturnRef; using namespace application_manager; -class HMICapabilitiesTest : public ::testing::Test { - protected: - HMICapabilitiesTest() - : last_state_wrapper_(std::make_shared<resumption::LastStateWrapperImpl>( - std::make_shared<resumption::LastStateImpl>("app_storage_folder", - "app_info_storage"))) - , file_name_("hmi_capabilities.json") {} - virtual void SetUp() OVERRIDE { - EXPECT_CALL(app_mngr_, event_dispatcher()) - .WillOnce(ReturnRef(mock_event_dispatcher)); - EXPECT_CALL(app_mngr_, get_settings()) - .WillRepeatedly(ReturnRef(mock_application_manager_settings_)); - EXPECT_CALL(mock_application_manager_settings_, - hmi_capabilities_file_name()) - .WillOnce(ReturnRef(file_name_)); - EXPECT_CALL(mock_event_dispatcher, add_observer(_, _, _)).Times(1); - EXPECT_CALL(mock_event_dispatcher, remove_observer(_)).Times(1); - EXPECT_CALL(mock_application_manager_settings_, launch_hmi()) - .WillOnce(Return(false)); - hmi_capabilities_test = - std::make_shared<HMICapabilitiesForTesting>(app_mngr_); - hmi_capabilities_test->Init(last_state_wrapper_); - } +typedef std::map<std::string, hmi_apis::Common_Language::eType> + LanguageCStringToEnumMap; - void TearDown() OVERRIDE { - hmi_capabilities_test.reset(); - } - static void TearDownTestCase() { - if (file_system::FileExists("./app_info_data")) { - EXPECT_TRUE(::file_system::DeleteFile("./app_info_data")); - } - } +typedef std::map<std::string, hmi_apis::Common_LightName::eType> + LightNameCStringToEnumMap; - void SetCooperating(); - MockApplicationManager app_mngr_; - event_engine_test::MockEventDispatcher mock_event_dispatcher; - resumption::LastStateWrapperPtr last_state_wrapper_; - MockApplicationManagerSettings mock_application_manager_settings_; - std::shared_ptr<HMICapabilitiesForTesting> hmi_capabilities_test; - const std::string file_name_; - application_manager_test::MockRPCService mock_rpc_service_; -}; +static LanguageCStringToEnumMap languages_map; +static LightNameCStringToEnumMap light_names_map; -const char* const cstring_values_[] = { - "EN_US", "ES_MX", "FR_CA", "DE_DE", "ES_ES", "EN_GB", "RU_RU", "TR_TR", - "PL_PL", "FR_FR", "IT_IT", "SV_SE", "PT_PT", "NL_NL", "EN_AU", "ZH_CN", - "ZH_TW", "JA_JP", "AR_SA", "KO_KR", "PT_BR", "CS_CZ", "DA_DK", "NO_NO", - "NL_BE", "EL_GR", "HU_HU", "FI_FI", "SK_SK", "EN_IN", "TH_TH", "EN_SA", - "HE_IL", "RO_RO", "UK_UA", "ID_ID", "VI_VN", "MS_MY", "HI_IN"}; +const std::vector<std::string> language_string_values{ + {"EN-US"}, {"ES-MX"}, {"FR-CA"}, {"DE-DE"}, {"ES-ES"}, {"EN-GB"}, {"RU-RU"}, + {"TR-TR"}, {"PL-PL"}, {"FR-FR"}, {"IT-IT"}, {"SV-SE"}, {"PT-PT"}, {"NL-NL"}, + {"EN-AU"}, {"ZH-CN"}, {"ZH-TW"}, {"JA-JP"}, {"AR-SA"}, {"KO-KR"}, {"PT-BR"}, + {"CS-CZ"}, {"DA-DK"}, {"NO-NO"}, {"NL-BE"}, {"EL-GR"}, {"HU-HU"}, {"FI-FI"}, + {"SK-SK"}, {"EN-IN"}, {"TH-TH"}, {"EN-SA"}, {"HE-IL"}, {"RO-RO"}, {"UK-UA"}, + {"ID-ID"}, {"VI-VN"}, {"MS-MY"}, {"HI-IN"}}; -const hmi_apis::Common_Language::eType enum_values_[] = { +const std::vector<hmi_apis::Common_Language::eType> language_enum_values{ hmi_apis::Common_Language::EN_US, hmi_apis::Common_Language::ES_MX, hmi_apis::Common_Language::FR_CA, hmi_apis::Common_Language::DE_DE, hmi_apis::Common_Language::ES_ES, hmi_apis::Common_Language::EN_GB, @@ -138,142 +119,338 @@ const hmi_apis::Common_Language::eType enum_values_[] = { hmi_apis::Common_Language::VI_VN, hmi_apis::Common_Language::MS_MY, hmi_apis::Common_Language::HI_IN}; -struct CStringComparator { - bool operator()(const char* a, const char* b) { - return strcmp(a, b) < 0; +const std::vector<hmi_apis::Common_LightName::eType> light_name_enum_values{ + hmi_apis::Common_LightName::eType::FRONT_LEFT_HIGH_BEAM, + hmi_apis::Common_LightName::eType::FRONT_RIGHT_HIGH_BEAM, + hmi_apis::Common_LightName::eType::FRONT_LEFT_LOW_BEAM, + hmi_apis::Common_LightName::eType::FRONT_RIGHT_LOW_BEAM, + hmi_apis::Common_LightName::eType::FRONT_LEFT_PARKING_LIGHT, + hmi_apis::Common_LightName::eType::FRONT_RIGHT_PARKING_LIGHT, + hmi_apis::Common_LightName::eType::FRONT_LEFT_FOG_LIGHT, + hmi_apis::Common_LightName::eType::FRONT_RIGHT_FOG_LIGHT, + hmi_apis::Common_LightName::eType::FRONT_LEFT_DAYTIME_RUNNING_LIGHT, + hmi_apis::Common_LightName::eType::FRONT_RIGHT_DAYTIME_RUNNING_LIGHT, + hmi_apis::Common_LightName::eType::FRONT_LEFT_TURN_LIGHT, + hmi_apis::Common_LightName::eType::FRONT_RIGHT_TURN_LIGHT, + hmi_apis::Common_LightName::eType::REAR_LEFT_FOG_LIGHT, + hmi_apis::Common_LightName::eType::REAR_RIGHT_FOG_LIGHT, + hmi_apis::Common_LightName::eType::REAR_LEFT_TAIL_LIGHT, + hmi_apis::Common_LightName::eType::REAR_RIGHT_TAIL_LIGHT, + hmi_apis::Common_LightName::eType::REAR_LEFT_BRAKE_LIGHT, + hmi_apis::Common_LightName::eType::REAR_RIGHT_BRAKE_LIGHT, + hmi_apis::Common_LightName::eType::REAR_LEFT_TURN_LIGHT, + hmi_apis::Common_LightName::eType::REAR_RIGHT_TURN_LIGHT, + hmi_apis::Common_LightName::eType::REAR_REGISTRATION_PLATE_LIGHT, + hmi_apis::Common_LightName::eType::HIGH_BEAMS, + hmi_apis::Common_LightName::eType::LOW_BEAMS, + hmi_apis::Common_LightName::eType::FOG_LIGHTS, + hmi_apis::Common_LightName::eType::RUNNING_LIGHTS, + hmi_apis::Common_LightName::eType::PARKING_LIGHTS, + hmi_apis::Common_LightName::eType::BRAKE_LIGHTS, + hmi_apis::Common_LightName::eType::REAR_REVERSING_LIGHTS, + hmi_apis::Common_LightName::eType::SIDE_MARKER_LIGHTS, + hmi_apis::Common_LightName::eType::LEFT_TURN_LIGHTS, + hmi_apis::Common_LightName::eType::RIGHT_TURN_LIGHTS, + hmi_apis::Common_LightName::eType::HAZARD_LIGHTS, + hmi_apis::Common_LightName::eType::REAR_CARGO_LIGHTS, + hmi_apis::Common_LightName::eType::REAR_TRUCK_BED_LIGHTS, + hmi_apis::Common_LightName::eType::REAR_TRAILER_LIGHTS, + hmi_apis::Common_LightName::eType::LEFT_SPOT_LIGHTS, + hmi_apis::Common_LightName::eType::RIGHT_SPOT_LIGHTS, + hmi_apis::Common_LightName::eType::LEFT_PUDDLE_LIGHTS, + hmi_apis::Common_LightName::eType::RIGHT_PUDDLE_LIGHTS, + hmi_apis::Common_LightName::eType::AMBIENT_LIGHTS, + hmi_apis::Common_LightName::eType::OVERHEAD_LIGHTS, + hmi_apis::Common_LightName::eType::READING_LIGHTS, + hmi_apis::Common_LightName::eType::TRUNK_LIGHTS, + hmi_apis::Common_LightName::eType::EXTERIOR_FRONT_LIGHTS, + hmi_apis::Common_LightName::eType::EXTERIOR_REAR_LIGHTS, + hmi_apis::Common_LightName::eType::EXTERIOR_LEFT_LIGHTS, + hmi_apis::Common_LightName::eType::EXTERIOR_RIGHT_LIGHTS, + hmi_apis::Common_LightName::eType::EXTERIOR_ALL_LIGHTS}; + +const std::vector<std::string> light_name_string_values{ + {"FRONT_LEFT_HIGH_BEAM"}, + {"FRONT_RIGHT_HIGH_BEAM"}, + {"FRONT_LEFT_LOW_BEAM"}, + {"FRONT_RIGHT_LOW_BEAM"}, + {"FRONT_LEFT_PARKING_LIGHT"}, + {"FRONT_RIGHT_PARKING_LIGHT"}, + {"FRONT_LEFT_FOG_LIGHT"}, + {"FRONT_RIGHT_FOG_LIGHT"}, + {"FRONT_LEFT_DAYTIME_RUNNING_LIGHT"}, + {"FRONT_RIGHT_DAYTIME_RUNNING_LIGHT"}, + {"FRONT_LEFT_TURN_LIGHT"}, + {"FRONT_RIGHT_TURN_LIGHT"}, + {"REAR_LEFT_FOG_LIGHT"}, + {"REAR_RIGHT_FOG_LIGHT"}, + {"REAR_LEFT_TAIL_LIGHT"}, + {"REAR_RIGHT_TAIL_LIGHT"}, + {"REAR_LEFT_BRAKE_LIGHT"}, + {"REAR_RIGHT_BRAKE_LIGHT"}, + {"REAR_LEFT_TURN_LIGHT"}, + {"REAR_RIGHT_TURN_LIGHT"}, + {"REAR_REGISTRATION_PLATE_LIGHT"}, + {"HIGH_BEAMS"}, + {"LOW_BEAMS"}, + {"FOG_LIGHTS"}, + {"RUNNING_LIGHTS"}, + {"PARKING_LIGHTS"}, + {"BRAKE_LIGHTS"}, + {"REAR_REVERSING_LIGHTS"}, + {"SIDE_MARKER_LIGHTS"}, + {"LEFT_TURN_LIGHTS"}, + {"RIGHT_TURN_LIGHTS"}, + {"HAZARD_LIGHTS"}, + {"REAR_CARGO_LIGHTS"}, + {"REAR_TRUCK_BED_LIGHTS"}, + {"REAR_TRAILER_LIGHTS"}, + {"LEFT_SPOT_LIGHTS"}, + {"RIGHT_SPOT_LIGHTS"}, + {"LEFT_PUDDLE_LIGHTS"}, + {"RIGHT_PUDDLE_LIGHTS"}, + {"AMBIENT_LIGHTS"}, + {"OVERHEAD_LIGHTS"}, + {"READING_LIGHTS"}, + {"TRUNK_LIGHTS"}, + {"EXTERIOR_FRONT_LIGHTS"}, + {"EXTERIOR_REAR_LIGHTS"}, + {"EXTERIOR_LEFT_LIGHTS"}, + {"EXTERIOR_RIGHT_LIGHTS"}, + {"EXTERIOR_ALL_LIGHTS"}}; + +void InitLightNameStringToEnumMap( + LightNameCStringToEnumMap& out_light_names_map) { + for (size_t i = 0; i < light_name_string_values.size(); ++i) { + out_light_names_map[light_name_string_values[i]] = + light_name_enum_values[i]; } -}; - -typedef std:: - map<const char*, hmi_apis::Common_Language::eType, CStringComparator> - CStringToEnumMap; +} -CStringToEnumMap InitCStringToEnumMap() { - size_t value = sizeof(cstring_values_) / sizeof(cstring_values_[0]); - CStringToEnumMap result; - for (size_t i = 0; i < value; ++i) { - result[cstring_values_[i]] = enum_values_[i]; +bool LightNameStringToEnum(const std::string& light_name_str, + hmi_apis::Common_LightName::eType& out_value) { + auto it = light_names_map.find(light_name_str); + if (it == light_names_map.end()) { + return false; } - return result; + out_value = it->second; + return true; } -bool StringToEnum(const char* str, hmi_apis::Common_Language::eType& value) { - size_t count_value = sizeof(cstring_values_) / sizeof(cstring_values_[0]); - CStringToEnumMap result; - for (size_t i = 0; i < count_value; ++i) { - result[cstring_values_[i]] = enum_values_[i]; +void InitLanguageStringToEnumMap(LanguageCStringToEnumMap& out_languages_map) { + for (size_t i = 0; i < language_string_values.size(); ++i) { + out_languages_map[language_string_values[i]] = language_enum_values[i]; } +} - CStringToEnumMap::const_iterator it = result.find(str); - if (it == result.end()) { +bool LanguageStringToEnum(const std::string& language_str, + hmi_apis::Common_Language::eType& out_value) { + LanguageCStringToEnumMap::const_iterator it = + languages_map.find(language_str); + if (it == languages_map.end()) { return false; } - value = it->second; + out_value = it->second; return true; } hmi_apis::Common_Language::eType TestCommonLanguageFromString( const std::string& language) { hmi_apis::Common_Language::eType value; - if (StringToEnum(language.c_str(), value)) { + if (LanguageStringToEnum(language, value)) { return value; } return hmi_apis::Common_Language::INVALID_ENUM; } -TEST_F(HMICapabilitiesTest, LoadCapabilitiesFromFile) { - const std::string hmi_capabilities_file = "hmi_capabilities.json"; - EXPECT_CALL(mock_application_manager_settings_, hmi_capabilities_file_name()) - .WillOnce(ReturnRef(hmi_capabilities_file)); - EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), - CommonLanguageFromString(_)) - .WillRepeatedly(Invoke(TestCommonLanguageFromString)); +hmi_apis::Common_LightName::eType TestCommonLightNameFromString( + const std::string& light_name_str) { + hmi_apis::Common_LightName::eType value; + if (LightNameStringToEnum(light_name_str, value)) { + return value; + } + return hmi_apis::Common_LightName::INVALID_ENUM; +} + +bool IsLightNameExists(const hmi_apis::Common_LightName::eType& light_name) { + auto it = std::find( + light_name_enum_values.begin(), light_name_enum_values.end(), light_name); + return !(it == light_name_enum_values.end()); +} + +class HMICapabilitiesTest : public ::testing::Test { + protected: + HMICapabilitiesTest() + : last_state_wrapper_(std::make_shared<resumption::LastStateWrapperImpl>( + std::make_shared<resumption::LastStateImpl>(kAppStorageFolder, + kAppInfoStorage))) { + if (languages_map.empty()) { + InitLanguageStringToEnumMap(languages_map); + } + if (light_names_map.empty()) { + InitLightNameStringToEnumMap(light_names_map); + } + } + + void SetUp() OVERRIDE { + ON_CALL(mock_app_mngr_, event_dispatcher()) + .WillByDefault(ReturnRef(mock_event_dispatcher_)); + ON_CALL(mock_app_mngr_, get_settings()) + .WillByDefault(ReturnRef(mock_application_manager_settings_)); + ON_CALL(mock_application_manager_settings_, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(kHmiCapabilitiesDefaultFile)); + ON_CALL(mock_application_manager_settings_, + hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(kHmiCapabilitiesCacheFile)); + + hmi_capabilities_ = std::make_shared<HMICapabilitiesImpl>(mock_app_mngr_); + } - if (file_system::FileExists("./app_info_data")) { - EXPECT_TRUE(::file_system::DeleteFile("./app_info_data")); + void TearDown() OVERRIDE { + DeleteFileIfExists(kHmiCapabilitiesCacheFile); + DeleteFileIfExists(kAppInfoDataFile); + hmi_capabilities_.reset(); + } + + void CreateFile(const std::string& file_name) { + file_system::CreateFile(file_name); + ASSERT_TRUE(file_system::FileExists(file_name)); + } + + void DeleteFileIfExists(const std::string& file_path) { + if (file_system::FileExists(file_path)) { + EXPECT_TRUE(::file_system::DeleteFile(file_path)); + } } - EXPECT_CALL(app_mngr_, IsSOStructValid(_, _)).WillOnce(Return(true)); - EXPECT_TRUE(hmi_capabilities_test->LoadCapabilitiesFromFile()); + void SetUpLanguageAndLightCapabilitiesExpectation() { + ON_CALL(mock_app_mngr_, IsSOStructValid(_, _)).WillByDefault(Return(true)); + + EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), + CommonLanguageFromString(_)) + .WillRepeatedly(Invoke(TestCommonLanguageFromString)); + EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), + CommonLightNameFromString(_)) + .WillRepeatedly(Invoke(TestCommonLightNameFromString)); + } + + std::shared_ptr<HMICapabilitiesImpl> hmi_capabilities_; + NiceMock<MockApplicationManager> mock_app_mngr_; + NiceMock<event_engine_test::MockEventDispatcher> mock_event_dispatcher_; + NiceMock<MockApplicationManagerSettings> mock_application_manager_settings_; + resumption::LastStateWrapperPtr last_state_wrapper_; + smart_objects::CSmartSchema schema_; +}; + +TEST_F(HMICapabilitiesTest, + Init_CheckActiveLanguages_SuccesSetupDefaultLanguages) { + SetUpLanguageAndLightCapabilitiesExpectation(); + hmi_capabilities_->Init(last_state_wrapper_); - // Check active languages EXPECT_EQ(hmi_apis::Common_Language::EN_US, - hmi_capabilities_test->active_ui_language()); - EXPECT_EQ(hmi_apis::Common_Language::ES_MX, - hmi_capabilities_test->active_vr_language()); - EXPECT_EQ(hmi_apis::Common_Language::DE_DE, - hmi_capabilities_test->active_tts_language()); + hmi_capabilities_->active_ui_language()); + EXPECT_EQ(hmi_apis::Common_Language::EN_US, + hmi_capabilities_->active_vr_language()); + EXPECT_EQ(hmi_apis::Common_Language::EN_US, + hmi_capabilities_->active_tts_language()); +} - // Check UI languages - const smart_objects::SmartObject ui_supported_languages = - *(hmi_capabilities_test->ui_supported_languages()); +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckUILanguages_SuccessLoadAndConvert) { + SetUpLanguageAndLightCapabilitiesExpectation(); + hmi_capabilities_->Init(last_state_wrapper_); + const auto ui_supported_languages_so = + *(hmi_capabilities_->ui_supported_languages()); EXPECT_EQ(hmi_apis::Common_Language::EN_US, static_cast<hmi_apis::Common_Language::eType>( - ui_supported_languages[0].asInt())); + ui_supported_languages_so[0].asInt())); EXPECT_EQ(hmi_apis::Common_Language::ES_MX, static_cast<hmi_apis::Common_Language::eType>( - ui_supported_languages[1].asInt())); + ui_supported_languages_so[1].asInt())); EXPECT_EQ(hmi_apis::Common_Language::FR_CA, static_cast<hmi_apis::Common_Language::eType>( - ui_supported_languages[2].asInt())); + ui_supported_languages_so[2].asInt())); +} - // Check VR languages - const smart_objects::SmartObject vr_supported_languages = - *(hmi_capabilities_test->vr_supported_languages()); +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckVRLanguages_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto vr_supported_languages_so = + *(hmi_capabilities_->vr_supported_languages()); - EXPECT_EQ(hmi_apis::Common_Language::AR_SA, - static_cast<hmi_apis::Common_Language::eType>( - vr_supported_languages[0].asInt())); EXPECT_EQ(hmi_apis::Common_Language::EN_US, static_cast<hmi_apis::Common_Language::eType>( - vr_supported_languages[1].asInt())); + vr_supported_languages_so[0].asInt())); EXPECT_EQ(hmi_apis::Common_Language::ES_MX, static_cast<hmi_apis::Common_Language::eType>( - vr_supported_languages[2].asInt())); + vr_supported_languages_so[1].asInt())); + EXPECT_EQ(hmi_apis::Common_Language::FR_CA, + static_cast<hmi_apis::Common_Language::eType>( + vr_supported_languages_so[2].asInt())); +} - // Check TTS languages - const smart_objects::SmartObject tts_supported_languages = - *(hmi_capabilities_test->tts_supported_languages()); +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckTTSSupportedLanguages_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto tts_supported_languages_so = + *(hmi_capabilities_->tts_supported_languages()); - EXPECT_EQ(hmi_apis::Common_Language::DA_DK, + EXPECT_EQ(hmi_apis::Common_Language::EN_US, static_cast<hmi_apis::Common_Language::eType>( - tts_supported_languages[0].asInt())); - EXPECT_EQ(hmi_apis::Common_Language::CS_CZ, + tts_supported_languages_so[0].asInt())); + EXPECT_EQ(hmi_apis::Common_Language::ES_MX, static_cast<hmi_apis::Common_Language::eType>( - tts_supported_languages[1].asInt())); - EXPECT_EQ(hmi_apis::Common_Language::KO_KR, + tts_supported_languages_so[1].asInt())); + EXPECT_EQ(hmi_apis::Common_Language::FR_CA, static_cast<hmi_apis::Common_Language::eType>( - tts_supported_languages[2].asInt())); + tts_supported_languages_so[2].asInt())); +} + +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckSpeechCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto tts_capabilities_so = *(hmi_capabilities_->speech_capabilities()); - // Check TTS capabilities - const smart_objects::SmartObject tts_capabilities = - *(hmi_capabilities_test->speech_capabilities()); EXPECT_EQ(hmi_apis::Common_SpeechCapabilities::SC_TEXT, static_cast<hmi_apis::Common_SpeechCapabilities::eType>( - tts_capabilities[0].asInt())); + tts_capabilities_so[0].asInt())); +} - // Check button capabilities - const smart_objects::SmartObject buttons_capabilities_so = - *(hmi_capabilities_test->button_capabilities()); +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckUIButtonCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto buttons_capabilities_so = + *(hmi_capabilities_->button_capabilities()); // Count of buttons in json file - const uint32_t btn_length = buttons_capabilities_so.length(); - EXPECT_EQ(16u, btn_length); - for (uint32_t i = 0; i < btn_length; ++i) { - EXPECT_TRUE((buttons_capabilities_so[i]).keyExists(strings::name)); - EXPECT_TRUE((buttons_capabilities_so[i]).keyExists("shortPressAvailable")); - EXPECT_TRUE((buttons_capabilities_so[i]).keyExists("longPressAvailable")); - EXPECT_TRUE((buttons_capabilities_so[i]).keyExists("upDownAvailable")); - EXPECT_TRUE(buttons_capabilities_so[i]["shortPressAvailable"].asBool()); - EXPECT_TRUE(buttons_capabilities_so[i]["longPressAvailable"].asBool()); - EXPECT_TRUE(buttons_capabilities_so[i]["upDownAvailable"].asBool()); + const size_t btn_length = buttons_capabilities_so.length(); + EXPECT_EQ(16ull, btn_length); + for (size_t index = 0; index < btn_length; ++index) { + EXPECT_TRUE(buttons_capabilities_so + [index][rc_rpc_plugin::enums_value::kShortPressAvailable] + .asBool()); + EXPECT_TRUE( + buttons_capabilities_so[index] + [rc_rpc_plugin::enums_value::kLongPressAvailable] + .asBool()); + EXPECT_TRUE( + buttons_capabilities_so[index] + [rc_rpc_plugin::enums_value::kUpDownAvailable] + .asBool()); } - const smart_objects::SmartObject display_capabilities_so = - *(hmi_capabilities_test->display_capabilities()); +} + +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckDisplayType_SuccessLoadAndConvert) { + SetUpLanguageAndLightCapabilitiesExpectation(); + hmi_capabilities_->Init(last_state_wrapper_); + const auto display_capabilities_so = + *(hmi_capabilities_->display_capabilities()); - // Check display type - EXPECT_EQ(hmi_apis::Common_DisplayType::GEN2_8_DMA, + EXPECT_EQ(hmi_apis::Common_DisplayType::SDL_GENERIC, static_cast<hmi_apis::Common_DisplayType::eType>( display_capabilities_so[hmi_response::display_type].asInt())); @@ -281,51 +458,79 @@ TEST_F(HMICapabilitiesTest, LoadCapabilitiesFromFile) { display_capabilities_so[hmi_response::display_name].asString()); EXPECT_TRUE(display_capabilities_so["graphicSupported"].asBool()); +} - // Check text fields - const uint32_t text_len = - display_capabilities_so[hmi_response::text_fields].length(); - EXPECT_NE(0u, text_len); - for (uint32_t i = 0; i < text_len; ++i) { - EXPECT_TRUE((display_capabilities_so[hmi_response::text_fields][i]) - .keyExists(strings::name)); - EXPECT_TRUE((display_capabilities_so[hmi_response::text_fields][i]) - .keyExists(strings::character_set)); - } - - // Check image fields - EXPECT_TRUE((display_capabilities_so).keyExists(hmi_response::image_fields)); - const uint32_t img_len = +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckImageFields_SuccessLoadAndConvert) { + SetUpLanguageAndLightCapabilitiesExpectation(); + hmi_capabilities_->Init(last_state_wrapper_); + const auto display_capabilities_so = + *(hmi_capabilities_->display_capabilities()); + + ASSERT_TRUE((display_capabilities_so).keyExists(hmi_response::image_fields)); + const size_t img_len = display_capabilities_so[hmi_response::image_fields].length(); - EXPECT_NE(0u, img_len); - for (uint32_t i = 0; i < img_len; ++i) { - EXPECT_TRUE((display_capabilities_so[hmi_response::image_fields][i]) + EXPECT_NE(0ull, img_len); + for (size_t index = 0; index < img_len; ++index) { + EXPECT_TRUE((display_capabilities_so[hmi_response::image_fields][index]) .keyExists(strings::name)); - EXPECT_TRUE((display_capabilities_so[hmi_response::image_fields][i]) - .keyExists(strings::image_type_supported)); - if (display_capabilities_so[hmi_response::image_fields][i][strings::name] == - hmi_apis::Common_ImageFieldName::locationImage) { + + const hmi_apis::Common_ImageFieldName::eType field_name = + static_cast<hmi_apis::Common_ImageFieldName::eType>( + display_capabilities_so[hmi_response::image_fields][index] + [strings::name] + .asInt()); + + if ((field_name == hmi_apis::Common_ImageFieldName::locationImage) || + (field_name == hmi_apis::Common_ImageFieldName::alertIcon)) { + EXPECT_TRUE((display_capabilities_so[hmi_response::image_fields][index]) + .keyExists(strings::image_type_supported)); EXPECT_EQ(hmi_apis::Common_FileType::GRAPHIC_PNG, static_cast<hmi_apis::Common_FileType::eType>( - display_capabilities_so[hmi_response::image_fields][i] + display_capabilities_so[hmi_response::image_fields][index] [strings::image_type_supported][0] .asInt())); } } +} + +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckTextFields_SuccessLoadAndConvert) { + SetUpLanguageAndLightCapabilitiesExpectation(); + hmi_capabilities_->Init(last_state_wrapper_); + const auto display_capabilities_so = + *(hmi_capabilities_->display_capabilities()); + + const size_t text_len = + display_capabilities_so[hmi_response::text_fields].length(); + EXPECT_NE(0ull, text_len); + for (size_t index = 0; index < text_len; ++index) { + EXPECT_TRUE((display_capabilities_so[hmi_response::text_fields][index]) + .keyExists(strings::name)); + EXPECT_TRUE((display_capabilities_so[hmi_response::text_fields][index]) + .keyExists(strings::character_set)); + } +} + +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckMediaClockFormats_SuccessLoadAndConvert) { + SetUpLanguageAndLightCapabilitiesExpectation(); + hmi_capabilities_->Init(last_state_wrapper_); + const auto display_capabilities_so = + *(hmi_capabilities_->display_capabilities()); - // Check media clock formats EXPECT_TRUE( (display_capabilities_so).keyExists(hmi_response::media_clock_formats)); - const uint32_t media_length = + const size_t media_length = display_capabilities_so[hmi_response::media_clock_formats].length(); - EXPECT_NE(0u, media_length); - for (uint32_t i = 0; i < media_length; ++i) { + EXPECT_NE(0ull, media_length); + for (size_t i = 0; i < media_length; ++i) { EXPECT_EQ( i, display_capabilities_so[hmi_response::media_clock_formats][i].asUInt()); } - EXPECT_TRUE( + ASSERT_TRUE( (display_capabilities_so).keyExists(hmi_response::image_capabilities)); EXPECT_EQ(hmi_apis::Common_ImageType::DYNAMIC, static_cast<hmi_apis::Common_ImageType::eType>( @@ -336,9 +541,17 @@ TEST_F(HMICapabilitiesTest, LoadCapabilitiesFromFile) { display_capabilities_so[hmi_response::image_capabilities][1] .asInt())); - // Check audio pass thru - const smart_objects::SmartObject audio_pass_thru_capabilities_so = - *(hmi_capabilities_test->audio_pass_thru_capabilities()); + // TemplatesAvailable parameter could be as empty array + ASSERT_TRUE( + display_capabilities_so.keyExists(hmi_response::templates_available)); +} + +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckAudioPassThru_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto audio_pass_thru_capabilities_so = + *(hmi_capabilities_->audio_pass_thru_capabilities()); + EXPECT_EQ(smart_objects::SmartType_Array, audio_pass_thru_capabilities_so.getType()); EXPECT_EQ(1u, audio_pass_thru_capabilities_so.length()); @@ -351,57 +564,118 @@ TEST_F(HMICapabilitiesTest, LoadCapabilitiesFromFile) { EXPECT_EQ(hmi_apis::Common_AudioType::PCM, static_cast<hmi_apis::Common_AudioType::eType>( audio_pass_thru_capabilities_so[0]["audioType"].asInt())); +} + +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckHmiZoneCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto hmi_zone_capabilities_so = + *(hmi_capabilities_->hmi_zone_capabilities()); - // Check hmi zone capabilities - const smart_objects::SmartObject hmi_zone_capabilities_so = - *(hmi_capabilities_test->hmi_zone_capabilities()); EXPECT_EQ(hmi_apis::Common_HmiZoneCapabilities::FRONT, static_cast<hmi_apis::Common_HmiZoneCapabilities::eType>( hmi_zone_capabilities_so.asInt())); +} - const smart_objects::SmartObject soft_button_capabilities_so = - *(hmi_capabilities_test->soft_button_capabilities()); +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckSoftButtonCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto& soft_button_capabilities_so = + *(hmi_capabilities_->soft_button_capabilities()); + + const size_t soft_butons_length = soft_button_capabilities_so.length(); + + ASSERT_TRUE(soft_butons_length > 0); + + for (size_t index = 0; index < soft_butons_length; ++index) { + EXPECT_TRUE(soft_button_capabilities_so[index].keyExists( + rc_rpc_plugin::enums_value::kShortPressAvailable)); + EXPECT_EQ(smart_objects::SmartType::SmartType_Boolean, + soft_button_capabilities_so + [index][rc_rpc_plugin::enums_value::kShortPressAvailable] + .getType()); + + EXPECT_TRUE(soft_button_capabilities_so[index].keyExists( + rc_rpc_plugin::enums_value::kLongPressAvailable)); + EXPECT_EQ(smart_objects::SmartType::SmartType_Boolean, + soft_button_capabilities_so + [index][rc_rpc_plugin::enums_value::kLongPressAvailable] + .getType()); + + EXPECT_TRUE(soft_button_capabilities_so[index].keyExists( + rc_rpc_plugin::enums_value::kUpDownAvailable)); + EXPECT_EQ(smart_objects::SmartType::SmartType_Boolean, + soft_button_capabilities_so + [index][rc_rpc_plugin::enums_value::kUpDownAvailable] + .getType()); + + EXPECT_TRUE(soft_button_capabilities_so[index].keyExists( + hmi_response::image_supported)); + EXPECT_EQ(smart_objects::SmartType::SmartType_Boolean, + soft_button_capabilities_so[index][hmi_response::image_supported] + .getType()); + } +} - EXPECT_TRUE(soft_button_capabilities_so[0]["shortPressAvailable"].asBool()); - EXPECT_TRUE(soft_button_capabilities_so[0]["longPressAvailable"].asBool()); - EXPECT_TRUE(soft_button_capabilities_so[0]["upDownAvailable"].asBool()); - EXPECT_TRUE(soft_button_capabilities_so[0]["imageSupported"].asBool()); +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckPresetBankCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto preset_bank_so = *(hmi_capabilities_->preset_bank_capabilities()); - const smart_objects::SmartObject preset_bank_so = - *(hmi_capabilities_test->preset_bank_capabilities()); - EXPECT_TRUE(preset_bank_so["onScreenPresetsAvailable"].asBool()); + EXPECT_TRUE( + preset_bank_so.keyExists(hmi_response::on_screen_presets_available)); + EXPECT_EQ( + smart_objects::SmartType::SmartType_Boolean, + preset_bank_so[hmi_response::on_screen_presets_available].getType()); +} - // Check vehicle type - const smart_objects::SmartObject vehicle_type_so = - *(hmi_capabilities_test->vehicle_type()); +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckVehicleType_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto vehicle_type_so = *(hmi_capabilities_->vehicle_type()); - EXPECT_EQ("Ford", vehicle_type_so["make"].asString()); - EXPECT_EQ("Fiesta", vehicle_type_so["model"].asString()); - EXPECT_EQ("2013", vehicle_type_so["modelYear"].asString()); + EXPECT_EQ("SDL", vehicle_type_so["make"].asString()); + EXPECT_EQ("Generic", vehicle_type_so["model"].asString()); + EXPECT_EQ("2019", vehicle_type_so["modelYear"].asString()); EXPECT_EQ("SE", vehicle_type_so["trim"].asString()); +} - // Check system capabilities - smart_objects::SmartObject navigation_capability_so = - *(hmi_capabilities_test->navigation_capability()); +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckNavigationCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto navigation_capability_so = + *(hmi_capabilities_->navigation_capability()); EXPECT_TRUE(navigation_capability_so.keyExists("sendLocationEnabled")); EXPECT_TRUE(navigation_capability_so.keyExists("getWayPointsEnabled")); EXPECT_TRUE(navigation_capability_so["sendLocationEnabled"].asBool()); EXPECT_TRUE(navigation_capability_so["getWayPointsEnabled"].asBool()); - // since we have navigation capabilities, the feature should be supported - EXPECT_TRUE(hmi_capabilities_test->navigation_supported()); + // Since we have navigation capabilities, the feature should be supported + EXPECT_TRUE(hmi_capabilities_->navigation_supported()); +} - const smart_objects::SmartObject phone_capability_so = - *(hmi_capabilities_test->phone_capability()); +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckPhoneCapability_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto phone_capability_so = *(hmi_capabilities_->phone_capability()); EXPECT_TRUE(phone_capability_so.keyExists("dialNumberEnabled")); EXPECT_TRUE(phone_capability_so["dialNumberEnabled"].asBool()); - EXPECT_TRUE(hmi_capabilities_test->phone_call_supported()); + EXPECT_TRUE(hmi_capabilities_->phone_call_supported()); +} - const smart_objects::SmartObject vs_capability_so = - *(hmi_capabilities_test->video_streaming_capability()); +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckVideoStreamingCapability_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto vs_capability_so = + *(hmi_capabilities_->video_streaming_capability()); EXPECT_TRUE(vs_capability_so.keyExists(strings::preferred_resolution)); EXPECT_TRUE(vs_capability_so[strings::preferred_resolution].keyExists( @@ -419,156 +693,312 @@ TEST_F(HMICapabilitiesTest, LoadCapabilitiesFromFile) { EXPECT_TRUE(vs_capability_so.keyExists(strings::max_bitrate)); EXPECT_EQ(10000, vs_capability_so[strings::max_bitrate].asInt()); EXPECT_TRUE(vs_capability_so.keyExists(strings::supported_formats)); - const uint32_t supported_formats_len = + const size_t supported_formats_len = vs_capability_so[strings::supported_formats].length(); - EXPECT_EQ(2u, supported_formats_len); + EXPECT_EQ(1ull, supported_formats_len); + EXPECT_TRUE(vs_capability_so[strings::supported_formats][0].keyExists( strings::protocol)); EXPECT_TRUE(vs_capability_so[strings::supported_formats][0].keyExists( strings::codec)); - EXPECT_EQ(0, + EXPECT_EQ(hmi_apis::Common_VideoStreamingProtocol::RAW, vs_capability_so[strings::supported_formats][0][strings::protocol] .asInt()); EXPECT_EQ( - 0, + hmi_apis::Common_VideoStreamingCodec::H264, vs_capability_so[strings::supported_formats][0][strings::codec].asInt()); - EXPECT_TRUE(vs_capability_so[strings::supported_formats][1].keyExists( - strings::protocol)); - EXPECT_TRUE(vs_capability_so[strings::supported_formats][1].keyExists( - strings::codec)); - EXPECT_EQ(1, - vs_capability_so[strings::supported_formats][1][strings::protocol] - .asInt()); - EXPECT_EQ( - 2, - vs_capability_so[strings::supported_formats][1][strings::codec].asInt()); EXPECT_TRUE( vs_capability_so.keyExists(strings::haptic_spatial_data_supported)); - EXPECT_TRUE( + EXPECT_FALSE( vs_capability_so[strings::haptic_spatial_data_supported].asBool()); - EXPECT_TRUE(hmi_capabilities_test->video_streaming_supported()); - - // Check remote control capabilites - const smart_objects::SmartObject rc_capability_so = - *(hmi_capabilities_test->rc_capability()); + EXPECT_TRUE(hmi_capabilities_->video_streaming_supported()); +} - EXPECT_TRUE(rc_capability_so.keyExists("climateControlCapabilities")); - EXPECT_TRUE(rc_capability_so.keyExists("radioControlCapabilities")); - EXPECT_TRUE(rc_capability_so.keyExists("buttonCapabilities")); +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckRemoteControlCapabilites_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto rc_capability_so = *(hmi_capabilities_->rc_capability()); + + ASSERT_TRUE(rc_capability_so.keyExists( + rc_rpc_plugin::strings::kclimateControlCapabilities)); + const auto& climate_control_capabilities_so = + rc_capability_so[rc_rpc_plugin::strings::kclimateControlCapabilities][0]; + + EXPECT_TRUE(climate_control_capabilities_so + [rc_rpc_plugin::strings::kFanSpeedAvailable] + .asBool()); + EXPECT_TRUE(climate_control_capabilities_so + [rc_rpc_plugin::strings::kDesiredTemperatureAvailable] + .asBool()); + EXPECT_TRUE(climate_control_capabilities_so + [rc_rpc_plugin::strings::kAcEnableAvailable] + .asBool()); + EXPECT_TRUE(climate_control_capabilities_so + [rc_rpc_plugin::strings::kAcMaxEnableAvailable] + .asBool()); +} +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckRadioControlCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto rc_capability_so = *(hmi_capabilities_->rc_capability()); + + ASSERT_TRUE(rc_capability_so.keyExists( + rc_rpc_plugin::strings::kradioControlCapabilities)); + const auto& radio_control_capabilities_so = + rc_capability_so[rc_rpc_plugin::strings::kradioControlCapabilities][0]; + + EXPECT_EQ("radio", radio_control_capabilities_so["moduleName"].asString()); + + EXPECT_TRUE(radio_control_capabilities_so + [rc_rpc_plugin::message_params::kAvailableHdChannelsAvailable] + .asBool()); + EXPECT_TRUE(radio_control_capabilities_so + [rc_rpc_plugin::strings::kSignalChangeThresholdAvailable] + .asBool()); + EXPECT_TRUE(radio_control_capabilities_so + [rc_rpc_plugin::strings::kSignalStrengthAvailable] + .asBool()); + EXPECT_TRUE(radio_control_capabilities_so + [rc_rpc_plugin::strings::kHdRadioEnableAvailable] + .asBool()); + EXPECT_TRUE(radio_control_capabilities_so + [rc_rpc_plugin::strings::kSiriusxmRadioAvailable] + .asBool()); EXPECT_TRUE( - rc_capability_so["climateControlCapabilities"][0]["fanSpeedAvailable"] + radio_control_capabilities_so[rc_rpc_plugin::strings::kSisDataAvailable] .asBool()); - EXPECT_TRUE(rc_capability_so["climateControlCapabilities"][0] - ["desiredTemperatureAvailable"] - .asBool()); EXPECT_TRUE( - rc_capability_so["climateControlCapabilities"][0]["acEnableAvailable"] + radio_control_capabilities_so[rc_rpc_plugin::strings::kStateAvailable] .asBool()); EXPECT_TRUE( - rc_capability_so["climateControlCapabilities"][0]["acMaxEnableAvailable"] + radio_control_capabilities_so[rc_rpc_plugin::strings::kRadioBandAvailable] .asBool()); - + EXPECT_TRUE(radio_control_capabilities_so + [rc_rpc_plugin::strings::kRadioFrequencyAvailable] + .asBool()); EXPECT_TRUE( - rc_capability_so["radioControlCapabilities"][0]["radioBandAvailable"] + radio_control_capabilities_so[rc_rpc_plugin::strings::kHdChannelAvailable] .asBool()); EXPECT_TRUE( - rc_capability_so["radioControlCapabilities"][0]["radioFrequencyAvailable"] + radio_control_capabilities_so[rc_rpc_plugin::strings::kRdsDataAvailable] .asBool()); + + ASSERT_TRUE(radio_control_capabilities_so.keyExists( + rc_rpc_plugin::message_params::kModuleInfo)); + ASSERT_TRUE( + radio_control_capabilities_so[rc_rpc_plugin::message_params::kModuleInfo] + .keyExists(rc_rpc_plugin::message_params::kModuleId)); +} + +TEST_F( + HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckRCButtonCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto rc_capability_so = *(hmi_capabilities_->rc_capability()); + + ASSERT_TRUE( + rc_capability_so.keyExists(rc_rpc_plugin::strings::kbuttonCapabilities)); + const auto& button_capabilities_so = + rc_capability_so[rc_rpc_plugin::strings::kbuttonCapabilities]; + + const size_t button_capabilities_length = button_capabilities_so.length(); + + for (size_t index = 0; index < button_capabilities_length; ++index) { + ASSERT_TRUE(button_capabilities_so[index].keyExists("name")); + + ASSERT_TRUE(button_capabilities_so[index].keyExists( + rc_rpc_plugin::enums_value::kLongPressAvailable)); + EXPECT_EQ( + smart_objects::SmartType::SmartType_Boolean, + button_capabilities_so[index] + [rc_rpc_plugin::enums_value::kLongPressAvailable] + .getType()); + ASSERT_TRUE(button_capabilities_so[index].keyExists( + rc_rpc_plugin::enums_value::kShortPressAvailable)); + EXPECT_EQ( + smart_objects::SmartType::SmartType_Boolean, + button_capabilities_so[index] + [rc_rpc_plugin::enums_value::kShortPressAvailable] + .getType()); + + ASSERT_TRUE(button_capabilities_so[index].keyExists( + rc_rpc_plugin::enums_value::kUpDownAvailable)); + EXPECT_EQ( + smart_objects::SmartType::SmartType_Boolean, + button_capabilities_so[index] + [rc_rpc_plugin::enums_value::kUpDownAvailable] + .getType()); + } +} + +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckAudioCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto rc_capability_so = *(hmi_capabilities_->rc_capability()); + + EXPECT_TRUE(rc_capability_so.keyExists( + rc_rpc_plugin::strings::kaudioControlCapabilities)); + + const auto& audio_capabilities_so = + rc_capability_so[rc_rpc_plugin::strings::kaudioControlCapabilities][0]; + + EXPECT_TRUE(audio_capabilities_so.keyExists( + rc_rpc_plugin::message_params::kModuleInfo)); + + const auto& audio_cap_module_info = + audio_capabilities_so[rc_rpc_plugin::message_params::kModuleInfo]; + EXPECT_TRUE(audio_cap_module_info.keyExists( + rc_rpc_plugin::message_params::kModuleId)); + EXPECT_TRUE(audio_cap_module_info.keyExists( + rc_rpc_plugin::strings::kAllowMultipleAccess)); EXPECT_TRUE( - rc_capability_so["radioControlCapabilities"][0]["hdChannelAvailable"] + audio_cap_module_info[rc_rpc_plugin::strings::kAllowMultipleAccess] .asBool()); + + EXPECT_TRUE( + audio_capabilities_so[rc_rpc_plugin::strings::kSourceAvailable].asBool()); + EXPECT_TRUE( + audio_capabilities_so[rc_rpc_plugin::strings::kVolumeAvailable].asBool()); + EXPECT_TRUE(audio_capabilities_so[rc_rpc_plugin::strings::kEqualizerAvailable] + .asBool()); EXPECT_TRUE( - rc_capability_so["radioControlCapabilities"][0]["rdsDataAvailable"] + audio_capabilities_so[rc_rpc_plugin::strings::kKeepContextAvailable] .asBool()); + EXPECT_EQ( + kEqualizerMaxChanelId, + audio_capabilities_so[rc_rpc_plugin::strings::kEqualizerMaxChannelId] + .asInt()); +} - EXPECT_TRUE(rc_capability_so["buttonCapabilities"][0]["shortPressAvailable"] - .asBool()); +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFile_CheckSeatCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto rc_capability_so = *(hmi_capabilities_->rc_capability()); + + EXPECT_TRUE(rc_capability_so.keyExists( + rc_rpc_plugin::strings::kseatControlCapabilities)); + const auto& seat_capabilities_so = + rc_capability_so[rc_rpc_plugin::strings::kseatControlCapabilities][0]; + + EXPECT_TRUE(seat_capabilities_so.keyExists( + rc_rpc_plugin::message_params::kModuleInfo)); + const auto& seat_cap_module_info = + seat_capabilities_so[rc_rpc_plugin::message_params::kModuleInfo]; EXPECT_TRUE( - rc_capability_so["buttonCapabilities"][0]["longPressAvailable"].asBool()); + seat_cap_module_info.keyExists(rc_rpc_plugin::message_params::kModuleId)); + EXPECT_TRUE(seat_cap_module_info.keyExists( + rc_rpc_plugin::strings::kAllowMultipleAccess)); EXPECT_FALSE( - rc_capability_so["buttonCapabilities"][0]["upDownAvailable"].asBool()); + seat_cap_module_info[rc_rpc_plugin::strings::kAllowMultipleAccess] + .asBool()); } TEST_F(HMICapabilitiesTest, - LoadCapabilitiesFromFileAndVerifyUnsupportedSystemCapabilities) { - MockApplicationManager mock_app_mngr; - event_engine_test::MockEventDispatcher mock_dispatcher; - MockApplicationManagerSettings mock_application_manager_settings; + LoadCapabilitiesFromFile_CheckLightCapabilities_SuccessLoadAndConvert) { + hmi_capabilities_->Init(last_state_wrapper_); + const auto rc_capability_so = *(hmi_capabilities_->rc_capability()); + + EXPECT_TRUE(rc_capability_so.keyExists( + rc_rpc_plugin::strings::klightControlCapabilities)); + const auto& light_capabilities_so = + rc_capability_so[rc_rpc_plugin::strings::klightControlCapabilities]; + + EXPECT_TRUE(light_capabilities_so.keyExists( + rc_rpc_plugin::message_params::kModuleInfo)); + const auto& light_cap_module_info = + light_capabilities_so[rc_rpc_plugin::message_params::kModuleInfo]; + EXPECT_TRUE(light_cap_module_info.keyExists( + rc_rpc_plugin::message_params::kModuleId)); + EXPECT_FALSE( + light_cap_module_info[rc_rpc_plugin::strings::kAllowMultipleAccess] + .asBool()); - const std::string hmi_capabilities_file = "hmi_capabilities_sc1.json"; + EXPECT_TRUE(light_capabilities_so.keyExists( + rc_rpc_plugin::strings::kSupportedLights)); + + const auto& supported_lights = + light_capabilities_so[rc_rpc_plugin::strings::kSupportedLights]; + + const size_t supported_lights_length = supported_lights.length(); + for (size_t index = 0; index < supported_lights_length; ++index) { + EXPECT_TRUE( + IsLightNameExists(static_cast<hmi_apis::Common_LightName::eType>( + supported_lights[index]["name"].asInt()))); + EXPECT_TRUE(supported_lights[index].keyExists( + rc_rpc_plugin::strings::kStatusAvailable)); + EXPECT_TRUE(supported_lights[index].keyExists( + rc_rpc_plugin::strings::kDensityAvailable)); + EXPECT_TRUE(supported_lights[index].keyExists( + rc_rpc_plugin::strings::kRGBColorSpaceAvailable)); + } + + EXPECT_TRUE(rc_capability_so.keyExists( + rc_rpc_plugin::strings::klightControlCapabilities)); + const auto& light_ctrl_cap_so = + rc_capability_so[rc_rpc_plugin::strings::klightControlCapabilities]; + + EXPECT_TRUE(light_ctrl_cap_so.keyExists("moduleName")); + EXPECT_TRUE( + light_ctrl_cap_so.keyExists(rc_rpc_plugin::strings::kSupportedLights)); + EXPECT_EQ( + smart_objects::SmartType::SmartType_Array, + light_ctrl_cap_so[rc_rpc_plugin::strings::kSupportedLights].getType()); + + const auto& supported_light_so = + light_ctrl_cap_so[rc_rpc_plugin::strings::kSupportedLights]; - EXPECT_CALL(mock_app_mngr, event_dispatcher()) - .WillOnce(ReturnRef(mock_dispatcher)); - EXPECT_CALL(mock_app_mngr, get_settings()) - .WillRepeatedly(ReturnRef(mock_application_manager_settings)); - EXPECT_CALL(mock_application_manager_settings, hmi_capabilities_file_name()) - .WillOnce(ReturnRef(hmi_capabilities_file)); - EXPECT_CALL(mock_dispatcher, add_observer(_, _, _)).Times(1); - EXPECT_CALL(mock_dispatcher, remove_observer(_)).Times(1); - EXPECT_CALL(mock_application_manager_settings, launch_hmi()) - .WillOnce(Return(false)); - - if (file_system::FileExists("./app_info_data")) { - EXPECT_TRUE(::file_system::DeleteFile("./app_info_data")); + const size_t sup_lights_length = supported_light_so.length(); + + for (size_t index = 0; index < sup_lights_length; ++index) { + EXPECT_TRUE( + supported_light_so[index].keyExists(rc_rpc_plugin::strings::kName)); } +} + +TEST_F(HMICapabilitiesTest, + LoadCapabilitiesFromFileAndVerifyUnsupportedSystemCapabilities) { + const std::string hmi_capabilities_file = "hmi_capabilities_sc1.json"; + ON_CALL(mock_application_manager_settings_, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_file)); - std::shared_ptr<HMICapabilitiesForTesting> hmi_capabilities = - std::make_shared<HMICapabilitiesForTesting>(mock_app_mngr); - hmi_capabilities->Init(last_state_wrapper_); + hmi_capabilities_->Init(last_state_wrapper_); // Check system capabilities; only phone capability is available - EXPECT_FALSE(hmi_capabilities->navigation_supported()); - EXPECT_TRUE(hmi_capabilities->phone_call_supported()); - EXPECT_FALSE(hmi_capabilities->video_streaming_supported()); - EXPECT_FALSE(hmi_capabilities->rc_supported()); + EXPECT_FALSE(hmi_capabilities_->navigation_supported()); + EXPECT_TRUE(hmi_capabilities_->phone_call_supported()); + EXPECT_FALSE(hmi_capabilities_->video_streaming_supported()); + EXPECT_FALSE(hmi_capabilities_->rc_supported()); // verify phone capability const smart_objects::SmartObject phone_capability_so = - *(hmi_capabilities->phone_capability()); + *(hmi_capabilities_->phone_capability()); EXPECT_TRUE(phone_capability_so.keyExists("dialNumberEnabled")); EXPECT_TRUE(phone_capability_so["dialNumberEnabled"].asBool()); } TEST_F(HMICapabilitiesTest, LoadCapabilitiesFromFileAndVerifyEmptySystemCapabilities) { - MockApplicationManager mock_app_mngr; - event_engine_test::MockEventDispatcher mock_dispatcher; - MockApplicationManagerSettings mock_application_manager_settings; - const std::string hmi_capabilities_file = "hmi_capabilities_sc2.json"; + ON_CALL(mock_application_manager_settings_, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_file)); - EXPECT_CALL(mock_app_mngr, event_dispatcher()) - .WillOnce(ReturnRef(mock_dispatcher)); - EXPECT_CALL(mock_app_mngr, get_settings()) - .WillRepeatedly(ReturnRef(mock_application_manager_settings)); - EXPECT_CALL(mock_application_manager_settings, hmi_capabilities_file_name()) - .WillOnce(ReturnRef(hmi_capabilities_file)); - EXPECT_CALL(mock_dispatcher, add_observer(_, _, _)).Times(1); - EXPECT_CALL(mock_dispatcher, remove_observer(_)).Times(1); - EXPECT_CALL(mock_application_manager_settings, launch_hmi()) - .WillOnce(Return(false)); - - if (file_system::FileExists("./app_info_data")) { - EXPECT_TRUE(::file_system::DeleteFile("./app_info_data")); - } - - std::shared_ptr<HMICapabilitiesForTesting> hmi_capabilities = - std::make_shared<HMICapabilitiesForTesting>(mock_app_mngr); - hmi_capabilities->Init(last_state_wrapper_); + hmi_capabilities_->Init(last_state_wrapper_); // Check system capabilities; only navigation capability is valid, the other // two are empty - EXPECT_TRUE(hmi_capabilities->navigation_supported()); - EXPECT_FALSE(hmi_capabilities->phone_call_supported()); - EXPECT_FALSE(hmi_capabilities->video_streaming_supported()); - EXPECT_FALSE(hmi_capabilities->rc_supported()); + EXPECT_TRUE(hmi_capabilities_->navigation_supported()); + EXPECT_FALSE(hmi_capabilities_->phone_call_supported()); + EXPECT_FALSE(hmi_capabilities_->video_streaming_supported()); + EXPECT_FALSE(hmi_capabilities_->rc_supported()); // verify navigation capabilities smart_objects::SmartObject navigation_capability_so = - *(hmi_capabilities->navigation_capability()); + *(hmi_capabilities_->navigation_capability()); EXPECT_TRUE(navigation_capability_so.keyExists("sendLocationEnabled")); EXPECT_TRUE(navigation_capability_so.keyExists("getWayPointsEnabled")); EXPECT_TRUE(navigation_capability_so["sendLocationEnabled"].asBool()); @@ -577,41 +1007,23 @@ TEST_F(HMICapabilitiesTest, TEST_F(HMICapabilitiesTest, LoadCapabilitiesFromFileAndVerifyOldAudioPassThruCapabilities) { - MockApplicationManager mock_app_mngr; - event_engine_test::MockEventDispatcher mock_dispatcher; - MockApplicationManagerSettings mock_application_manager_settings; - const std::string hmi_capabilities_file = "hmi_capabilities_old_apt.json"; + ON_CALL(mock_application_manager_settings_, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_file)); - EXPECT_CALL(mock_app_mngr, event_dispatcher()) - .WillOnce(ReturnRef(mock_dispatcher)); - EXPECT_CALL(mock_app_mngr, get_settings()) - .WillRepeatedly(ReturnRef(mock_application_manager_settings)); - EXPECT_CALL(mock_application_manager_settings, hmi_capabilities_file_name()) - .WillOnce(ReturnRef(hmi_capabilities_file)); - EXPECT_CALL(mock_dispatcher, add_observer(_, _, _)).Times(1); - EXPECT_CALL(mock_dispatcher, remove_observer(_)).Times(1); - EXPECT_CALL(mock_application_manager_settings, launch_hmi()) - .WillOnce(Return(false)); EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), CommonLanguageFromString(_)) .WillRepeatedly(Invoke(TestCommonLanguageFromString)); - if (file_system::FileExists("./app_info_data")) { - EXPECT_TRUE(::file_system::DeleteFile("./app_info_data")); - } - - std::shared_ptr<HMICapabilitiesForTesting> hmi_capabilities = - std::make_shared<HMICapabilitiesForTesting>(mock_app_mngr); - hmi_capabilities->Init(last_state_wrapper_); + hmi_capabilities_->Init(last_state_wrapper_); // with old audio pass thru format, the object is an array containing a single // object smart_objects::SmartObjectSPtr audio_pass_thru_capabilities_so = - hmi_capabilities->audio_pass_thru_capabilities(); + hmi_capabilities_->audio_pass_thru_capabilities(); EXPECT_EQ(smart_objects::SmartType_Array, audio_pass_thru_capabilities_so->getType()); - EXPECT_EQ(1u, audio_pass_thru_capabilities_so->length()); + EXPECT_EQ(1ull, audio_pass_thru_capabilities_so->length()); smart_objects::SmartObject& first_element = (*audio_pass_thru_capabilities_so)[0]; EXPECT_TRUE(first_element.keyExists("samplingRate")); @@ -629,45 +1041,608 @@ TEST_F(HMICapabilitiesTest, } TEST_F(HMICapabilitiesTest, VerifyImageType) { + ON_CALL(mock_app_mngr_, IsSOStructValid(_, _)).WillByDefault(Return(true)); + const int32_t image_type = 1; smart_objects::SmartObject sm_obj; - EXPECT_CALL(app_mngr_, IsSOStructValid(_, _)).WillOnce(Return(true)); sm_obj[hmi_response::image_capabilities][0] = image_type; - hmi_capabilities_test->set_display_capabilities(sm_obj); + hmi_capabilities_->set_display_capabilities(sm_obj); - EXPECT_TRUE(hmi_capabilities_test->VerifyImageType(image_type)); + EXPECT_TRUE(hmi_capabilities_->VerifyImageType(image_type)); const int32_t new_image_type = 2; - EXPECT_FALSE(hmi_capabilities_test->VerifyImageType(new_image_type)); -} - -void HMICapabilitiesTest::SetCooperating() { - smart_objects::SmartObjectSPtr test_so; - EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), - CreateModuleInfoSO(_, _)) - .WillRepeatedly(Return(test_so)); - EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)) - .WillRepeatedly(Return(true)); + EXPECT_FALSE(hmi_capabilities_->VerifyImageType(new_image_type)); } TEST_F(HMICapabilitiesTest, SetVRCooperating) { - hmi_capabilities_test->set_is_vr_cooperating(true); - EXPECT_EQ(true, hmi_capabilities_test->is_vr_cooperating()); + hmi_capabilities_->set_is_vr_cooperating(true); + EXPECT_TRUE(hmi_capabilities_->is_vr_cooperating()); } TEST_F(HMICapabilitiesTest, SetTTSCooperating) { - hmi_capabilities_test->set_is_tts_cooperating(true); - EXPECT_EQ(true, hmi_capabilities_test->is_tts_cooperating()); + hmi_capabilities_->set_is_tts_cooperating(true); + EXPECT_TRUE(hmi_capabilities_->is_tts_cooperating()); } TEST_F(HMICapabilitiesTest, SetUICooperating) { - hmi_capabilities_test->set_is_ui_cooperating(true); - EXPECT_EQ(true, hmi_capabilities_test->is_ui_cooperating()); + hmi_capabilities_->set_is_ui_cooperating(true); + EXPECT_TRUE(hmi_capabilities_->is_ui_cooperating()); } TEST_F(HMICapabilitiesTest, SetIviCooperating) { - hmi_capabilities_test->set_is_ivi_cooperating(true); - EXPECT_EQ(true, hmi_capabilities_test->is_ivi_cooperating()); + hmi_capabilities_->set_is_ivi_cooperating(true); + EXPECT_TRUE(hmi_capabilities_->is_ivi_cooperating()); +} + +TEST_F( + HMICapabilitiesTest, + UpdateCapabilitiesDependingOn_ccpuVersion_FromCacheForOld_RequestForNew) { + const std::string ccpu_version = "4.1.3.B_EB355B"; + const std::string ccpu_version_new = "5.1.3.B_EB355B"; + const std::string hmi_capabilities_invalid_file = + "hmi_capabilities_invalid_file.json"; + + ON_CALL(mock_application_manager_settings_, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_invalid_file)); + + EXPECT_CALL(mock_app_mngr_, SetHMICooperating(true)); + EXPECT_CALL(mock_app_mngr_, RequestForInterfacesAvailability()).Times(2); + + hmi_capabilities_->set_ccpu_version(ccpu_version); + hmi_capabilities_->OnSoftwareVersionReceived(ccpu_version); + + EXPECT_EQ(ccpu_version, hmi_capabilities_->ccpu_version()); + + hmi_capabilities_->OnSoftwareVersionReceived(ccpu_version_new); + EXPECT_EQ(ccpu_version_new, hmi_capabilities_->ccpu_version()); +} + +TEST_F(HMICapabilitiesTest, + UpdateCapabilitiesForNew_ccpuVersion_DeleteCacheFile) { + MockApplicationManagerSettings mock_application_manager_settings; + const std::string ccpu_version = "4.1.3.B_EB355B"; + const std::string ccpu_version_new = "5.1.3.B_EB355B"; + const std::string hmi_capabilities_invalid_file = + "hmi_capabilities_invalid_file.json"; + + CreateFile(kHmiCapabilitiesCacheFile); + + ON_CALL(mock_application_manager_settings_, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_invalid_file)); + + hmi_capabilities_->set_ccpu_version(ccpu_version); + hmi_capabilities_->OnSoftwareVersionReceived(ccpu_version_new); + EXPECT_EQ(ccpu_version_new, hmi_capabilities_->ccpu_version()); + + EXPECT_FALSE(file_system::FileExists(kHmiCapabilitiesCacheFile)); +} + +TEST_F( + HMICapabilitiesTest, + OnSoftwareVersionReceived_CcpuMatchNoPendingRequestsForCapability_SetHMICooperatingToTrue) { + // If local ccpu_version matches with the received ccpu_version from the HMI, + // and cache exists, SDL Core should check if hmi_cooperating is set to true + // if yes - SDL should respond to all pending RAI requests, if they exist. + // hmi_cooperting is set to true when no pending capability requests exist + const std::string ccpu_version = "4.1.3.B_EB355B"; + + hmi_capabilities_->set_ccpu_version(ccpu_version); + + EXPECT_CALL(mock_app_mngr_, SetHMICooperating(true)); + + hmi_capabilities_->OnSoftwareVersionReceived(ccpu_version); +} + +TEST_F( + HMICapabilitiesTest, + OnSoftwareVersionReceived_CcpuMatchHavePendingRequestsForCapability_NoSetHMICooperatingToTrue) { + // If local ccpu_version matches with the received ccpu_version from the HMI, + // and there is no cache, SDL Core should check if hmi_cooperating is set to + // true if no - SDL should suspend all RAI responses (if any) and wait for HMI + // responses with all required capabilities. The RAI responses (if any) could + // be handled only after hmi_cooperating is set to true, it is set when all + // capabilities responses are received from the HMI + const std::string ccpu_version = "4.1.3.B_EB355B"; + + // Init() is required to set pending capabilities requests to the HMI + hmi_capabilities_->Init(last_state_wrapper_); + hmi_capabilities_->set_ccpu_version(ccpu_version); + + EXPECT_CALL(mock_app_mngr_, SetHMICooperating(true)).Times(0); + + hmi_capabilities_->OnSoftwareVersionReceived(ccpu_version); +} + +TEST_F(HMICapabilitiesTest, + CacheFileNameNotSpecified_NoNeedToSave_ReturnSuccess) { + const std::string hmi_capabilities_empty_file_name = ""; + const std::vector<std::string> sections_to_update{hmi_response::language}; + + ON_CALL(mock_application_manager_settings_, + hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_empty_file_name)); + + EXPECT_TRUE(hmi_capabilities_->SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, schema_)); +} + +TEST_F(HMICapabilitiesTest, SaveCachedCapabilitiesToFile_ParseFile_Failed) { + const std::vector<std::string> sections_to_update{hmi_response::language}; + + file_system::CreateFile(kHmiCapabilitiesCacheFile); + EXPECT_TRUE(file_system::FileExists(kHmiCapabilitiesCacheFile)); + + EXPECT_FALSE(hmi_capabilities_->SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, schema_)); +} + +TEST_F(HMICapabilitiesTest, + SaveCachedCapabilitiesToFile_ParsedFieldsSave_Success) { + const std::vector<std::string> sections_to_update{ + hmi_response::display_capabilities}; + const std::string content_to_save = "{\"field\" : \"value\" }"; + + CreateFile(kHmiCapabilitiesCacheFile); + + const std::vector<uint8_t> binary_data_to_save(content_to_save.begin(), + content_to_save.end()); + file_system::Write(kHmiCapabilitiesCacheFile, binary_data_to_save); + + EXPECT_TRUE(hmi_capabilities_->SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, schema_)); + + std::string content_after_update; + EXPECT_TRUE( + file_system::ReadFile(kHmiCapabilitiesCacheFile, content_after_update)); + EXPECT_NE(content_to_save, content_after_update); +} + +TEST_F( + HMICapabilitiesTest, + SaveCachedCapabilitiesToFile_LanguageIsNotTheSameAsPersisted_SaveNewLanguageToCache) { + SetUpLanguageAndLightCapabilitiesExpectation(); + const std::string new_language = "RU_RU"; + ON_CALL(*(MockMessageHelper::message_helper_mock()), + CommonLanguageToString(_)) + .WillByDefault(Return(new_language)); + + hmi_capabilities_->Init(last_state_wrapper_); + hmi_capabilities_->set_active_tts_language(hmi_apis::Common_Language::RU_RU); + const std::vector<std::string> sections_to_update{hmi_response::language}; + const std::string content_to_save = "{\"TTS\": {\"language\":\"EN_US\"}}"; + + CreateFile(kHmiCapabilitiesCacheFile); + const std::vector<uint8_t> binary_data_to_save(content_to_save.begin(), + content_to_save.end()); + file_system::Write(kHmiCapabilitiesCacheFile, binary_data_to_save); + + EXPECT_TRUE(hmi_capabilities_->SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, schema_)); + + std::string content_after_update; + ASSERT_TRUE( + file_system::ReadFile(kHmiCapabilitiesCacheFile, content_after_update)); + EXPECT_TRUE(content_after_update.find(new_language) != std::string::npos); +} + +TEST_F( + HMICapabilitiesTest, + SaveCachedCapabilitiesToFile_SectionToUpdateIsEmpty_SkipSaving_ReturnTrue) { + const std::vector<std::string> sections_to_update; + EXPECT_TRUE(hmi_capabilities_->SaveCachedCapabilitiesToFile( + "", sections_to_update, schema_)); +} + +TEST_F(HMICapabilitiesTest, PrepareJsonValueForSaving_Success) { + const std::vector<std::string> sections_to_update{ + hmi_response::display_capabilities, + hmi_response::hmi_zone_capabilities, + hmi_response::soft_button_capabilities, + strings::audio_pass_thru_capabilities, + strings::hmi_capabilities, + strings::system_capabilities, + hmi_response::languages}; + + const std::vector<std::string> interfaces_name{ + hmi_interface::tts, + hmi_interface::vr, + hmi_interface::ui, + hmi_interface::buttons, + hmi_interface::vehicle_info, + hmi_interface::rc, + hmi_response::speech_capabilities, + hmi_response::prerecorded_speech_capabilities, + hmi_response::button_capabilities, + hmi_response::preset_bank_capabilities}; + + smart_objects::SmartObject audio_capabilities_so( + smart_objects::SmartType_Array); + audio_capabilities_so[0][strings::sampling_rate] = + hmi_apis::Common_SamplingRate::RATE_44KHZ; + audio_capabilities_so[0][strings::bits_per_sample] = + hmi_apis::Common_BitsPerSample::RATE_8_BIT; + audio_capabilities_so[0][strings::audio_type] = + hmi_apis::Common_AudioType::PCM; + + const std::string content_to_save = "{\"field\" : \"value\" }"; + const std::vector<uint8_t> binary_data_to_save(content_to_save.begin(), + content_to_save.end()); + + hmi_capabilities_->set_audio_pass_thru_capabilities(audio_capabilities_so); + + CreateFile(kHmiCapabilitiesCacheFile); + file_system::Write(kHmiCapabilitiesCacheFile, binary_data_to_save); + + for (size_t i = 0; i < interfaces_name.size(); ++i) { + EXPECT_TRUE(hmi_capabilities_->SaveCachedCapabilitiesToFile( + interfaces_name[i], sections_to_update, schema_)); + } + + std::string content_after_update; + EXPECT_TRUE( + file_system::ReadFile(kHmiCapabilitiesCacheFile, content_after_update)); + + Json::Value root_node; + utils::JsonReader reader; + ASSERT_TRUE(reader.parse(content_after_update, &root_node)); + + for (size_t i = 0; i < interfaces_name.size(); ++i) { + EXPECT_TRUE(static_cast<bool>(root_node[interfaces_name[i]])); + } + EXPECT_TRUE( + root_node[hmi_interface::ui][strings::audio_pass_thru_capabilities] + .isArray()); +} + +TEST_F(HMICapabilitiesTest, + OnCapabilityInitialized_RespondToAllPendingRAIRequestsIfTheyHold) { + SetUpLanguageAndLightCapabilitiesExpectation(); + + std::vector<hmi_apis::FunctionID::eType> requests_required{ + hmi_apis::FunctionID::RC_GetCapabilities, + hmi_apis::FunctionID::VR_GetLanguage, + hmi_apis::FunctionID::VR_GetSupportedLanguages, + hmi_apis::FunctionID::VR_GetCapabilities, + hmi_apis::FunctionID::TTS_GetLanguage, + hmi_apis::FunctionID::TTS_GetSupportedLanguages, + hmi_apis::FunctionID::TTS_GetCapabilities, + hmi_apis::FunctionID::Buttons_GetCapabilities, + hmi_apis::FunctionID::VehicleInfo_GetVehicleType, + hmi_apis::FunctionID::UI_GetCapabilities, + hmi_apis::FunctionID::UI_GetLanguage, + hmi_apis::FunctionID::UI_GetSupportedLanguages}; + + // Contains only UI capabilities + const std::string hmi_capabilities_file = "hmi_capabilities_sc2.json"; + ON_CALL(mock_application_manager_settings_, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_file)); + + // Initializes the UI capabilities with the default values + // Other interfaces are absent and appropriate requests should be sent + hmi_capabilities_->Init(last_state_wrapper_); + + ON_CALL(mock_app_mngr_, IsHMICooperating()).WillByDefault(Return(false)); + + // Sets isHMICooperating flag to true after all required capabilities are + // received from HMI + EXPECT_CALL(mock_app_mngr_, SetHMICooperating(true)); + + for (const auto& request_id : requests_required) { + hmi_capabilities_->UpdateRequestsRequiredForCapabilities(request_id); + } +} + +TEST_F(HMICapabilitiesTest, + OnlyUICapabilitiesInCacheFile_RequestRequiredForOtherInterfaces) { + SetUpLanguageAndLightCapabilitiesExpectation(); + + std::vector<hmi_apis::FunctionID::eType> requests_required{ + hmi_apis::FunctionID::RC_GetCapabilities, + hmi_apis::FunctionID::VR_GetLanguage, + hmi_apis::FunctionID::VR_GetSupportedLanguages, + hmi_apis::FunctionID::VR_GetCapabilities, + hmi_apis::FunctionID::TTS_GetLanguage, + hmi_apis::FunctionID::TTS_GetSupportedLanguages, + hmi_apis::FunctionID::TTS_GetCapabilities, + hmi_apis::FunctionID::Buttons_GetCapabilities, + hmi_apis::FunctionID::VehicleInfo_GetVehicleType}; + + const std::string hmi_capabilities_cache_file = + "hmi_capabilities_cache_test.json"; + CreateFile(hmi_capabilities_cache_file); + const std::string predefined_ui_capabilities = + "{\"UI\" : {\"language\" : " + "\"EN-US\",\"languages\":[],\"displayCapabilities\" : " + "{},\"audioPassThruCapabilities\":[],\"pcmStreamCapabilities\" : " + "{},\"hmiZoneCapabilities\": \"\",\"softButtonCapabilities\" : " + "[],\"systemCapabilities\" : {}}}"; + + const std::vector<uint8_t> binary_data_to_save( + predefined_ui_capabilities.begin(), predefined_ui_capabilities.end()); + + file_system::Write(hmi_capabilities_cache_file, binary_data_to_save); + + ON_CALL(mock_application_manager_settings_, + hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_cache_file)); + + hmi_capabilities_->Init(last_state_wrapper_); + + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetLanguage)); + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetSupportedLanguages)); + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetCapabilities)); + + for (const auto& item : requests_required) { + EXPECT_TRUE(hmi_capabilities_->IsRequestsRequiredForCapabilities(item)); + } + + DeleteFileIfExists(hmi_capabilities_cache_file); +} + +TEST_F(HMICapabilitiesTest, + OnlyRCCapabilitiesInCacheFile_RequestRequiredForOtherInterfaces) { + SetUpLanguageAndLightCapabilitiesExpectation(); + + std::vector<hmi_apis::FunctionID::eType> requests_required{ + hmi_apis::FunctionID::UI_GetLanguage, + hmi_apis::FunctionID::UI_GetSupportedLanguages, + hmi_apis::FunctionID::UI_GetCapabilities, + hmi_apis::FunctionID::VR_GetLanguage, + hmi_apis::FunctionID::VR_GetSupportedLanguages, + hmi_apis::FunctionID::VR_GetCapabilities, + hmi_apis::FunctionID::TTS_GetLanguage, + hmi_apis::FunctionID::TTS_GetSupportedLanguages, + hmi_apis::FunctionID::TTS_GetCapabilities, + hmi_apis::FunctionID::Buttons_GetCapabilities, + hmi_apis::FunctionID::VehicleInfo_GetVehicleType}; + + const std::string hmi_capabilities_cache_file = + "hmi_capabilities_cache_test.json"; + CreateFile(hmi_capabilities_cache_file); + const std::string predefined_rc_capabilities = + "{\"RC\" : {\"remoteControlCapability\" : {\"buttonCapabilities\": " + "[],\"climateControlCapabilities\": [],\"radioControlCapabilities\": " + "[],\"audioControlCapabilities\": [],\"seatControlCapabilities\": " + "[],\"lightControlCapabilities\": {},\"hmiSettingsControlCapabilities\": " + "{}},\"seatLocationCapability\": {}}}}"; + + const std::vector<uint8_t> binary_data_to_save( + predefined_rc_capabilities.begin(), predefined_rc_capabilities.end()); + + file_system::Write(hmi_capabilities_cache_file, binary_data_to_save); + + ON_CALL(mock_application_manager_settings_, + hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_cache_file)); + + hmi_capabilities_->Init(last_state_wrapper_); + + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::RC_GetCapabilities)); + + for (const auto& item : requests_required) { + EXPECT_TRUE(hmi_capabilities_->IsRequestsRequiredForCapabilities(item)); + } +} + +TEST_F(HMICapabilitiesTest, + OnlyVRCapabilitiesInCacheFile_RequestRequiredForOtherInterfaces) { + SetUpLanguageAndLightCapabilitiesExpectation(); + + std::vector<hmi_apis::FunctionID::eType> requests_required{ + hmi_apis::FunctionID::UI_GetLanguage, + hmi_apis::FunctionID::UI_GetSupportedLanguages, + hmi_apis::FunctionID::RC_GetCapabilities, + hmi_apis::FunctionID::UI_GetCapabilities, + hmi_apis::FunctionID::TTS_GetLanguage, + hmi_apis::FunctionID::TTS_GetSupportedLanguages, + hmi_apis::FunctionID::TTS_GetCapabilities, + hmi_apis::FunctionID::Buttons_GetCapabilities, + hmi_apis::FunctionID::VehicleInfo_GetVehicleType}; + + const std::string hmi_capabilities_cache_file = + "hmi_capabilities_cache_test.json"; + CreateFile(hmi_capabilities_cache_file); + const std::string predefined_vr_capabilities = + "{\"VR\": {\"vrCapabilities\": [],\"language\": \"\",\"languages\": []}}"; + + const std::vector<uint8_t> binary_data_to_save( + predefined_vr_capabilities.begin(), predefined_vr_capabilities.end()); + + file_system::Write(hmi_capabilities_cache_file, binary_data_to_save); + + ON_CALL(mock_application_manager_settings_, + hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_cache_file)); + + hmi_capabilities_->Init(last_state_wrapper_); + + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetLanguage)); + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetSupportedLanguages)); + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetCapabilities)); + + for (const auto& item : requests_required) { + EXPECT_TRUE(hmi_capabilities_->IsRequestsRequiredForCapabilities(item)); + } +} + +TEST_F(HMICapabilitiesTest, + OnlyTTSCapabilitiesInCacheFile_RequestRequiredForOtherInterfaces) { + SetUpLanguageAndLightCapabilitiesExpectation(); + + std::vector<hmi_apis::FunctionID::eType> requests_required{ + hmi_apis::FunctionID::UI_GetLanguage, + hmi_apis::FunctionID::UI_GetSupportedLanguages, + hmi_apis::FunctionID::UI_GetCapabilities, + hmi_apis::FunctionID::RC_GetCapabilities, + hmi_apis::FunctionID::VR_GetLanguage, + hmi_apis::FunctionID::VR_GetSupportedLanguages, + hmi_apis::FunctionID::VR_GetCapabilities, + hmi_apis::FunctionID::Buttons_GetCapabilities, + hmi_apis::FunctionID::VehicleInfo_GetVehicleType}; + + const std::string hmi_capabilities_cache_file = + "hmi_capabilities_cache_test.json"; + CreateFile(hmi_capabilities_cache_file); + const std::string predefined_tts_capabilities = + "{\"TTS\": {\"speechCapabilities\": [],\"prerecordedSpeechCapabilities\" " + ": [],\"language\": \"\",\"languages\": " + "[]}}"; + + const std::vector<uint8_t> binary_data_to_save( + predefined_tts_capabilities.begin(), predefined_tts_capabilities.end()); + + file_system::Write(hmi_capabilities_cache_file, binary_data_to_save); + + ON_CALL(mock_application_manager_settings_, + hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_cache_file)); + + hmi_capabilities_->Init(last_state_wrapper_); + + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetLanguage)); + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetSupportedLanguages)); + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetCapabilities)); + + for (const auto& item : requests_required) { + EXPECT_TRUE(hmi_capabilities_->IsRequestsRequiredForCapabilities(item)); + } +} + +TEST_F(HMICapabilitiesTest, + OnlyButtonsSCapabilitiesInCacheFile_RequestRequiredForOtherInterfaces) { + SetUpLanguageAndLightCapabilitiesExpectation(); + + std::vector<hmi_apis::FunctionID::eType> requests_required{ + hmi_apis::FunctionID::UI_GetLanguage, + hmi_apis::FunctionID::UI_GetSupportedLanguages, + hmi_apis::FunctionID::UI_GetCapabilities, + hmi_apis::FunctionID::RC_GetCapabilities, + hmi_apis::FunctionID::TTS_GetLanguage, + hmi_apis::FunctionID::TTS_GetSupportedLanguages, + hmi_apis::FunctionID::TTS_GetCapabilities, + hmi_apis::FunctionID::VR_GetLanguage, + hmi_apis::FunctionID::VR_GetSupportedLanguages, + hmi_apis::FunctionID::VR_GetCapabilities, + hmi_apis::FunctionID::VehicleInfo_GetVehicleType}; + + const std::string hmi_capabilities_cache_file = + "hmi_capabilities_cache_test.json"; + CreateFile(hmi_capabilities_cache_file); + const std::string predefined_buttons_capabilities = + "{\"Buttons\": {\"capabilities\": [],\"presetBankCapabilities\": {}}}"; + + const std::vector<uint8_t> binary_data_to_save( + predefined_buttons_capabilities.begin(), + predefined_buttons_capabilities.end()); + + file_system::Write(hmi_capabilities_cache_file, binary_data_to_save); + + ON_CALL(mock_application_manager_settings_, + hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_cache_file)); + + hmi_capabilities_->Init(last_state_wrapper_); + + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::Buttons_GetCapabilities)); + + for (const auto& item : requests_required) { + EXPECT_TRUE(hmi_capabilities_->IsRequestsRequiredForCapabilities(item)); + } +} + +TEST_F(HMICapabilitiesTest, + OnlyVehicleInfoInCacheFile_RequestRequiredForOtherInterfaces) { + SetUpLanguageAndLightCapabilitiesExpectation(); + + std::vector<hmi_apis::FunctionID::eType> requests_required{ + hmi_apis::FunctionID::UI_GetLanguage, + hmi_apis::FunctionID::UI_GetSupportedLanguages, + hmi_apis::FunctionID::UI_GetCapabilities, + hmi_apis::FunctionID::RC_GetCapabilities, + hmi_apis::FunctionID::TTS_GetLanguage, + hmi_apis::FunctionID::TTS_GetSupportedLanguages, + hmi_apis::FunctionID::TTS_GetCapabilities, + hmi_apis::FunctionID::VR_GetLanguage, + hmi_apis::FunctionID::VR_GetSupportedLanguages, + hmi_apis::FunctionID::VR_GetCapabilities, + hmi_apis::FunctionID::Buttons_GetCapabilities}; + + const std::string hmi_capabilities_cache_file = + "hmi_capabilities_cache_test.json"; + CreateFile(hmi_capabilities_cache_file); + const std::string predefined_vi_capabilities = + "{\"VehicleInfo\": { \"vehicleType\" : {} }}"; + + const std::vector<uint8_t> binary_data_to_save( + predefined_vi_capabilities.begin(), predefined_vi_capabilities.end()); + + file_system::Write(hmi_capabilities_cache_file, binary_data_to_save); + + ON_CALL(mock_application_manager_settings_, + hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_cache_file)); + + hmi_capabilities_->Init(last_state_wrapper_); + + EXPECT_FALSE(hmi_capabilities_->IsRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VehicleInfo_GetVehicleType)); + + for (const auto& item : requests_required) { + EXPECT_TRUE(hmi_capabilities_->IsRequestsRequiredForCapabilities(item)); + } +} + +TEST_F( + HMICapabilitiesTest, + ConvertJsonArrayToSoArray_ConvertPrerecordedSpeech_SuccessConvertFromStringToEnum) { + SetUpLanguageAndLightCapabilitiesExpectation(); + + CreateFile(kHmiCapabilitiesCacheFile); + const std::string prerecordedSpeechCapabilities = + "{ \"TTS\" :{" + "\"prerecordedSpeechCapabilities\" :[" + "\"HELP_JINGLE\"," + "\"INITIAL_JINGLE\"," + "\"LISTEN_JINGLE\"," + "\"POSITIVE_JINGLE\"," + "\"NEGATIVE_JINGLE\"]}" + "}"; + + const std::vector<uint8_t> binary_data_to_save( + prerecordedSpeechCapabilities.begin(), + prerecordedSpeechCapabilities.end()); + file_system::Write(kHmiCapabilitiesCacheFile, binary_data_to_save); + + hmi_capabilities_->Init(last_state_wrapper_); + + const auto tts_capabilities_so = *(hmi_capabilities_->prerecorded_speech()); + + EXPECT_EQ(hmi_apis::Common_PrerecordedSpeech::HELP_JINGLE, + static_cast<hmi_apis::Common_PrerecordedSpeech::eType>( + tts_capabilities_so[0].asInt())); + EXPECT_EQ(hmi_apis::Common_PrerecordedSpeech::INITIAL_JINGLE, + static_cast<hmi_apis::Common_PrerecordedSpeech::eType>( + tts_capabilities_so[1].asInt())); + EXPECT_EQ(hmi_apis::Common_PrerecordedSpeech::LISTEN_JINGLE, + static_cast<hmi_apis::Common_PrerecordedSpeech::eType>( + tts_capabilities_so[2].asInt())); + EXPECT_EQ(hmi_apis::Common_PrerecordedSpeech::POSITIVE_JINGLE, + static_cast<hmi_apis::Common_PrerecordedSpeech::eType>( + tts_capabilities_so[3].asInt())); + EXPECT_EQ(hmi_apis::Common_PrerecordedSpeech::NEGATIVE_JINGLE, + static_cast<hmi_apis::Common_PrerecordedSpeech::eType>( + tts_capabilities_so[4].asInt())); } } // namespace application_manager_test 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 0b3753a532..60d2f90297 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 @@ -37,6 +37,7 @@ #include "application_manager/app_service_manager.h" #include "application_manager/commands/command.h" #include "application_manager/commands/command_impl.h" +#include "application_manager/rpc_passing_handler.h" namespace test { namespace components { @@ -86,6 +87,7 @@ class MockAppServiceManager : public application_manager::AppServiceManager { const bool service_published)); MOCK_METHOD1(UpdateNavigationCapabilities, bool(smart_objects::SmartObject& out_params)); + MOCK_METHOD0(GetRPCPassingHandler, application_manager::RPCPassingHandler&()); }; } // namespace application_manager_test diff --git a/src/components/application_manager/test/include/application_manager/hmi_capabilities_for_testing.h b/src/components/application_manager/test/include/application_manager/mock_command_holder.h index 9764a9997f..0391808126 100644 --- a/src/components/application_manager/test/include/application_manager/hmi_capabilities_for_testing.h +++ b/src/components/application_manager/test/include/application_manager/mock_command_holder.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Ford Motor Company + * Copyright (c) 2020, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,28 +29,32 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ - -#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_HMI_CAPABILITIES_FOR_TESTING_H_ -#define SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_HMI_CAPABILITIES_FOR_TESTING_H_ - -#include "application_manager/hmi_capabilities_impl.h" +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_COMMAND_HOLDER_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_COMMAND_HOLDER_H_ +#include "application_manager/command_holder.h" +#include "gmock/gmock.h" namespace test { namespace components { namespace application_manager_test { -class HMICapabilitiesForTesting - : public ::application_manager::HMICapabilitiesImpl { +class MockCommandHolder : public application_manager::CommandHolder { public: - HMICapabilitiesForTesting(::application_manager::ApplicationManager& app_mngr) - : HMICapabilitiesImpl(app_mngr) {} - bool LoadCapabilitiesFromFile() { - return load_capabilities_from_file(); - } + MOCK_METHOD4( + Suspend, + void(application_manager::ApplicationSharedPtr application, + application_manager::CommandHolder::CommandType type, + application_manager::commands::Command::CommandSource source, + smart_objects::SmartObjectSPtr command)); + MOCK_METHOD2(Resume, + void(application_manager::ApplicationSharedPtr application, + application_manager::CommandHolder::CommandType type)); + MOCK_METHOD1(Clear, + void(application_manager::ApplicationSharedPtr application)); }; } // namespace application_manager_test } // namespace components } // namespace test -#endif // SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_HMI_CAPABILITIES_FOR_TESTING_H_ +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_COMMAND_HOLDER_H_ diff --git a/src/components/application_manager/test/include/application_manager/mock_hmi_capabilities.h b/src/components/application_manager/test/include/application_manager/mock_hmi_capabilities.h index 7c163d78ad..6d428eda24 100644 --- a/src/components/application_manager/test/include/application_manager/mock_hmi_capabilities.h +++ b/src/components/application_manager/test/include/application_manager/mock_hmi_capabilities.h @@ -75,7 +75,7 @@ class MockHMICapabilities : public ::application_manager::HMICapabilities { void(const hmi_apis::Common_Language::eType language)); MOCK_CONST_METHOD0(ui_supported_languages, - const smart_objects::SmartObject*()); + const smart_objects::SmartObjectSPtr()); MOCK_METHOD1(set_ui_supported_languages, void(const smart_objects::SmartObject& supported_languages)); @@ -85,7 +85,7 @@ class MockHMICapabilities : public ::application_manager::HMICapabilities { void(const hmi_apis::Common_Language::eType language)); MOCK_CONST_METHOD0(vr_supported_languages, - const smart_objects::SmartObject*()); + const smart_objects::SmartObjectSPtr()); MOCK_METHOD1(set_vr_supported_languages, void(const smart_objects::SmartObject& supported_languages)); @@ -95,7 +95,7 @@ class MockHMICapabilities : public ::application_manager::HMICapabilities { void(const hmi_apis::Common_Language::eType language)); MOCK_CONST_METHOD0(tts_supported_languages, - const smart_objects::SmartObject*()); + const smart_objects::SmartObjectSPtr()); MOCK_METHOD1(set_tts_supported_languages, void(const smart_objects::SmartObject& supported_languages)); @@ -173,25 +173,25 @@ class MockHMICapabilities : public ::application_manager::HMICapabilities { MOCK_METHOD1(set_rc_supported, void(const bool supported)); MOCK_CONST_METHOD0(navigation_capability, - const smart_objects::SmartObject*()); + const smart_objects::SmartObjectSPtr()); MOCK_METHOD1(set_navigation_capability, void(const smart_objects::SmartObject& navigation_capability)); - MOCK_CONST_METHOD0(phone_capability, const smart_objects::SmartObject*()); + MOCK_CONST_METHOD0(phone_capability, const smart_objects::SmartObjectSPtr()); MOCK_METHOD1(set_phone_capability, void(const smart_objects::SmartObject& phone_capability)); MOCK_CONST_METHOD0(video_streaming_capability, - const smart_objects::SmartObject*()); + const smart_objects::SmartObjectSPtr()); MOCK_METHOD1( set_video_streaming_capability, void(const smart_objects::SmartObject& video_streaming_capability)); - MOCK_CONST_METHOD0(rc_capability, const smart_objects::SmartObject*()); + MOCK_CONST_METHOD0(rc_capability, const smart_objects::SmartObjectSPtr()); MOCK_METHOD1(set_rc_capability, void(const smart_objects::SmartObject& rc_capability)); MOCK_CONST_METHOD0(seat_location_capability, - const smart_objects::SmartObject*()); + const smart_objects::SmartObjectSPtr()); MOCK_METHOD1( set_seat_location_capability, void(const smart_objects::SmartObject& seat_location_capability)); @@ -203,22 +203,22 @@ class MockHMICapabilities : public ::application_manager::HMICapabilities { MOCK_CONST_METHOD0(ccpu_version, const std::string&()); MOCK_METHOD1(set_ccpu_version, void(const std::string& ccpu_version)); + MOCK_METHOD1(OnSoftwareVersionReceived, + void(const std::string& ccpu_version)); + MOCK_METHOD0(UpdateCachedCapabilities, void()); MOCK_METHOD0(get_hmi_language_handler, application_manager::HMILanguageHandler&()); MOCK_METHOD1(set_handle_response_for, void(const smart_objects::SmartObject& request)); - - protected: - MOCK_CONST_METHOD2(check_existing_json_member, - bool(const Json::Value& json_member, - const char* name_of_member)); - - MOCK_CONST_METHOD2(convert_json_languages_to_obj, - void(const Json::Value& json_languages, - smart_objects::SmartObject& languages)); - MOCK_CONST_METHOD2(convert_audio_capability_to_obj, - void(const Json::Value& capability, - smart_objects::SmartObject& output_so)); + MOCK_METHOD3(SaveCachedCapabilitiesToFile, + bool(const std::string& interface_name, + const std::vector<std::string>& sections_to_update, + const smart_objects::CSmartSchema& schema)); + MOCK_CONST_METHOD0(DeleteCachedCapabilitiesFile, bool()); + MOCK_CONST_METHOD1(IsRequestsRequiredForCapabilities, + bool(hmi_apis::FunctionID::eType)); + MOCK_METHOD1(UpdateRequestsRequiredForCapabilities, + void(hmi_apis::FunctionID::eType requested_interface)); }; } // namespace application_manager_test 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 eb3c97bfff..5f6e613123 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 @@ -162,6 +162,11 @@ class MockMessageHelper { const bool require_encryption)); MOCK_METHOD4(SendPolicySnapshotNotification, void(uint32_t connection_key, + const std::string& snapshot_file_path, + const std::string& url, + ApplicationManager& app_mngr)); + MOCK_METHOD4(SendPolicySnapshotNotification, + void(uint32_t connection_key, const std::vector<uint8_t>& policy_data, const std::string& url, ApplicationManager& app_mngr)); diff --git a/src/components/application_manager/test/include/application_manager/mock_request.h b/src/components/application_manager/test/include/application_manager/mock_request.h index 77b5bb7c38..c1cc7f601f 100644 --- a/src/components/application_manager/test/include/application_manager/mock_request.h +++ b/src/components/application_manager/test/include/application_manager/mock_request.h @@ -56,6 +56,8 @@ class MockRequest : public application_manager::commands::Command { MOCK_CONST_METHOD0(default_timeout, uint32_t()); MOCK_CONST_METHOD0(function_id, int32_t()); MOCK_CONST_METHOD0(window_id, application_manager::WindowID()); + MOCK_METHOD1(set_warning_info, void(const std::string info)); + MOCK_CONST_METHOD0(warning_info, std::string()); MOCK_METHOD0(onTimeOut, void()); MOCK_METHOD0(AllowedToTerminate, bool()); MOCK_METHOD1(SetAllowedToTerminate, void(bool is_allowed)); diff --git a/src/components/application_manager/test/include/application_manager/resumption_data_test.h b/src/components/application_manager/test/include/application_manager/resumption_data_test.h index e313427547..e38b428877 100644 --- a/src/components/application_manager/test/include/application_manager/resumption_data_test.h +++ b/src/components/application_manager/test/include/application_manager/resumption_data_test.h @@ -63,7 +63,15 @@ using namespace mobile_apis; class ResumptionDataTest : public ::testing::Test { protected: ResumptionDataTest() - : kCountOfCommands_(5u) + : help_prompt_(NULL) + , timeout_prompt_(NULL) + , vr_help_(NULL) + , vr_help_title_(NULL) + , vr_synonyms_(NULL) + , keyboard_props_(NULL) + , menu_title_(NULL) + , menu_icon_(NULL) + , kCountOfCommands_(5u) , kCountOfChoice_(2u) , kCountOfChoiceSets_(4u) , kCountOfSubmenues_(3u) @@ -77,6 +85,7 @@ class ResumptionDataTest : public ::testing::Test { , ivilock_ptr_(std::make_shared<sync_primitives::Lock>()) , window_params_map_lock_ptr_(std::make_shared<sync_primitives::Lock>()) { } + virtual ~ResumptionDataTest(); // Check structure in saved application void CheckSavedApp(sm::SmartObject& saved_data); // Set data for resumption @@ -161,7 +170,8 @@ class ResumptionDataTest : public ::testing::Test { std::shared_ptr<sync_primitives::Lock> window_params_map_lock_ptr_; application_manager_test::MockApplicationManagerSettings mock_application_manager_settings_; - application_manager_test::MockApplicationManager mock_application_manager_; + NiceMock<application_manager_test::MockApplicationManager> + mock_application_manager_; std::shared_ptr<NiceMock<application_manager_test::MockAppExtension> > mock_app_extension_; std::list<application_manager::AppExtensionPtr> extensions_; diff --git a/src/components/application_manager/test/include/application_manager/test_resumption_data_db.h b/src/components/application_manager/test/include/application_manager/test_resumption_data_db.h index 3f5802cb5a..e7a8f25261 100644 --- a/src/components/application_manager/test/include/application_manager/test_resumption_data_db.h +++ b/src/components/application_manager/test/include/application_manager/test_resumption_data_db.h @@ -44,13 +44,16 @@ namespace test { namespace components { namespace resumption_test { +using ::testing::NiceMock; + class TestResumptionDataDB : public ResumptionDataDB { public: utils::dbms::SQLDatabase* get_db_handle() { return db(); } - application_manager_test::MockApplicationManager mock_application_manager_; + NiceMock<application_manager_test::MockApplicationManager> + mock_application_manager_; TestResumptionDataDB(DbStorage db_storage) : ResumptionDataDB(db_storage, mock_application_manager_) {} }; diff --git a/src/components/application_manager/test/mock_message_helper.cc b/src/components/application_manager/test/mock_message_helper.cc index 959bbf5bd0..a001e852b8 100644 --- a/src/components/application_manager/test/mock_message_helper.cc +++ b/src/components/application_manager/test/mock_message_helper.cc @@ -220,6 +220,15 @@ void MessageHelper::SendOnPermissionsChangeNotification( void MessageHelper::SendPolicySnapshotNotification( uint32_t connection_key, + const std::string& snapshot_file_path, + const std::string& url, + ApplicationManager& app_mngr) { + MockMessageHelper::message_helper_mock()->SendPolicySnapshotNotification( + connection_key, snapshot_file_path, url, app_mngr); +} + +void MessageHelper::SendPolicySnapshotNotification( + uint32_t connection_key, const std::vector<uint8_t>& policy_data, const std::string& url, ApplicationManager& app_mngr) { diff --git a/src/components/application_manager/test/policy_event_observer_test.cc b/src/components/application_manager/test/policy_event_observer_test.cc index a74b12071c..22d7a8cfa0 100644 --- a/src/components/application_manager/test/policy_event_observer_test.cc +++ b/src/components/application_manager/test/policy_event_observer_test.cc @@ -89,8 +89,6 @@ class PolicyEventObserverTest : public ::testing::Test { EXPECT_CALL(policy_handler_mock_, PTUpdatedAt(Counters::KILOMETERS, field_value)) .Times(pt_updated_calls_number); - EXPECT_CALL(policy_handler_mock_, OnSystemReady()) - .Times(on_system_ready_calls_number); policy_event_observer_->on_event(*event_); } @@ -125,15 +123,6 @@ TEST_F(PolicyEventObserverTest, CheckResultsOnEvent(1u, 0u); } -TEST_F(PolicyEventObserverTest, - OnEvent_EventBasicCommunication_OnReady_ExpectOnSystemReady) { - // Arrange - CreateEvent(Event::EventID::BasicCommunication_OnReady); - CookSmartObject(hmi_apis::Common_Result::SUCCESS, field_name, field_value); - // Check - CheckResultsOnEvent(0u, 1u); -} - } // namespace policy_test } // namespace components } // namespace test diff --git a/src/components/application_manager/test/policy_handler_test.cc b/src/components/application_manager/test/policy_handler_test.cc index 3f37cec657..ad94c4d1c8 100644 --- a/src/components/application_manager/test/policy_handler_test.cc +++ b/src/components/application_manager/test/policy_handler_test.cc @@ -31,6 +31,7 @@ */ #include <fstream> +#include <memory> #include <string> #include <vector> #include "gmock/gmock.h" @@ -92,9 +93,12 @@ using ::testing::SetArgReferee; typedef NiceMock<application_manager_test::MockRPCService> MockRPCService; +namespace { +const std::string kFakeNickname = "fake_nickname"; const std::string kDummyData = "some_data"; const WindowID kDefaultWindowId = mobile_apis::PredefinedWindows::DEFAULT_WINDOW; +} // namespace class PolicyHandlerTest : public ::testing::Test { public: @@ -811,15 +815,6 @@ TEST_F(PolicyHandlerTest, OnExceededTimeout) { policy_handler_.OnExceededTimeout(); } -TEST_F(PolicyHandlerTest, OnSystemReady) { - // Arrange - EnablePolicyAndPolicyManagerMock(); - // Check expectations - EXPECT_CALL(*mock_policy_manager_, OnSystemReady()); - // Act - policy_handler_.OnSystemReady(); -} - TEST_F(PolicyHandlerTest, PTUpdatedAt_method_UseCounter_KILOMETERS) { // Arrange EnablePolicyAndPolicyManagerMock(); @@ -1366,15 +1361,6 @@ TEST_F(PolicyHandlerTest, IsApplicationRevoked) { policy_handler_.IsApplicationRevoked(kPolicyAppId_); } -TEST_F(PolicyHandlerTest, OnSystemInfoUpdateRequired) { - // Arrange - ChangePolicyManagerToMock(); - // Check expectations - EXPECT_CALL(mock_message_helper_, SendGetSystemInfoRequest(_)); - // Act - policy_handler_.OnSystemInfoUpdateRequired(); -} - TEST_F(PolicyHandlerTest, GetAppRequestTypes) { // Arrange EnablePolicy(); @@ -1873,7 +1859,9 @@ TEST_F(PolicyHandlerTest, DISABLED_OnSnapshotCreated_UrlAdded) { .WillOnce(ReturnRef(mock_session_observer)); EXPECT_CALL(*mock_app_, device()).WillOnce(Return(0)); EXPECT_CALL(app_manager_, applications()).WillOnce(Return(app_set)); - EXPECT_CALL(mock_message_helper_, SendPolicySnapshotNotification(_, _, _, _)); + EXPECT_CALL(mock_message_helper_, + SendPolicySnapshotNotification( + _, testing::A<const std::vector<uint8_t>&>(), _, _)); // Check expectations for get app id GetAppIDForSending(); // Expectations @@ -2212,63 +2200,6 @@ TEST_F(PolicyHandlerTest, GetAppIdForSending_ExpectReturnAnyAppInNone) { EXPECT_EQ(app_in_none_id_1 || app_in_none_id_2, app_id); } -TEST_F(PolicyHandlerTest, - SendMessageToSDK_SuitableAppPresent_ExpectedNotificationSending) { - BinaryMessage msg; - const std::string url = "test_url"; - EnablePolicyAndPolicyManagerMock(); - test_app.insert(mock_app_); - - EXPECT_CALL(app_manager_, application(kAppId1_)) - .WillRepeatedly(Return(mock_app_)); - EXPECT_CALL(*mock_app_, app_id()).WillRepeatedly(Return(kAppId1_)); - EXPECT_CALL(*mock_app_, policy_app_id()) - .WillRepeatedly(Return(kPolicyAppId_)); - EXPECT_CALL(*mock_app_, hmi_level(kDefaultWindowId)) - .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL)); - EXPECT_CALL(*mock_app_, IsRegistered()).WillRepeatedly(Return(true)); - - const connection_handler::DeviceHandle test_device_id = 1u; - EXPECT_CALL(*mock_app_, device()).WillRepeatedly(Return(test_device_id)); - EXPECT_CALL(*mock_policy_manager_, GetUserConsentForDevice(_)) - .WillOnce(Return(kDeviceAllowed)); - - // Act - EXPECT_CALL(mock_message_helper_, - SendPolicySnapshotNotification(kAppId1_, msg, url, _)); - EXPECT_TRUE(policy_handler_.SendMessageToSDK(msg, url)); -} - -TEST_F(PolicyHandlerTest, - SendMessageToSDK_NoSuitableApp_ExpectedNotificationNotSent) { - BinaryMessage msg; - const std::string url = "test_url"; - EnablePolicyAndPolicyManagerMock(); - test_app.insert(mock_app_); - - EXPECT_CALL(app_manager_, application(kAppId1_)) - .WillRepeatedly(Return(mock_app_)); - EXPECT_CALL(*mock_app_, app_id()).WillRepeatedly(Return(kAppId1_)); - EXPECT_CALL(*mock_app_, policy_app_id()) - .WillRepeatedly(Return(kPolicyAppId_)); - EXPECT_CALL(*mock_app_, hmi_level(kDefaultWindowId)) - .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_NONE)); - EXPECT_CALL(*mock_app_, IsRegistered()).WillRepeatedly(Return(true)); - - const connection_handler::DeviceHandle test_device_id = 1u; - EXPECT_CALL(*mock_app_, device()).WillRepeatedly(Return(test_device_id)); - EXPECT_CALL(*mock_policy_manager_, GetUserConsentForDevice(_)) - .WillOnce(Return(kDeviceDisallowed)); - - // Expected to get 0 as application id so SDL does not have valid application - // with such id - EXPECT_CALL(app_manager_, application(0)) - .WillOnce( - Return(std::shared_ptr<application_manager_test::MockApplication>())); - - EXPECT_FALSE(policy_handler_.SendMessageToSDK(msg, url)); -} - TEST_F(PolicyHandlerTest, CanUpdate) { GetAppIDForSending(); EXPECT_TRUE(policy_handler_.CanUpdate()); @@ -2590,11 +2521,24 @@ TEST_F(PolicyHandlerTest, #endif } +ACTION_P(SetEndpoint, endpoint) { + arg1 = endpoint; +} + TEST_F(PolicyHandlerTest, GetLockScreenIconUrl_SUCCESS) { EnablePolicyAndPolicyManagerMock(); - EXPECT_CALL(*mock_policy_manager_, GetLockScreenIconUrl()); - policy_handler_.GetLockScreenIconUrl(); + const std::string url_str = "test_icon_url"; + EndpointData data(url_str); + + EndpointUrls endpoints; + endpoints.push_back(data); + + const std::string service_type = "lock_screen_icon_url"; + EXPECT_CALL(*mock_policy_manager_, GetUpdateUrls(service_type, _)) + .WillOnce(SetEndpoint(endpoints)); + + EXPECT_EQ(url_str, policy_handler_.GetLockScreenIconUrl(kPolicyAppId_)); } TEST_F(PolicyHandlerTest, RemoveListener_SUCCESS) { @@ -2657,10 +2601,6 @@ TEST_F(PolicyHandlerTest, OnSystemError_SUCCESS) { EXPECT_TRUE(waiter1.Wait(auto_lock)); } -ACTION_P(SetEndpoint, endpoint) { - arg1 = endpoint; -} - TEST_F(PolicyHandlerTest, RemoteAppsUrl_EndpointsEmpty_UNSUCCESS) { EnablePolicyAndPolicyManagerMock(); @@ -3017,8 +2957,6 @@ TEST_F(PolicyHandlerTest, GetAppPropertiesStatus_EndPointNotChanged_SUCCESS) { TEST_F(PolicyHandlerTest, GetAppPropertiesStatus_NicknameChanged_SUCCESS) { ChangePolicyManagerToMock(); - const std::string kFakeNickname = "fake_nickname"; - smart_objects::SmartObject properties; properties[strings::app_id] = kPolicyAppId_; properties[strings::nicknames] = @@ -3040,10 +2978,32 @@ TEST_F(PolicyHandlerTest, GetAppPropertiesStatus_NicknameChanged_SUCCESS) { policy_handler_.GetAppPropertiesStatus(properties, kPolicyAppId_)); } -TEST_F(PolicyHandlerTest, GetAppPropertiesStatus_NicknameNotChanged_SUCCESS) { +TEST_F(PolicyHandlerTest, + GetAppPropertiesStatus_RemoveNickname_NicknamesChanged) { ChangePolicyManagerToMock(); - const std::string kFakeNickname = "fake_nickname"; + smart_objects::SmartObject properties; + properties[strings::app_id] = kPolicyAppId_; + properties[strings::nicknames] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + properties[strings::nicknames].asArray()->push_back( + smart_objects::SmartObject(kFakeNickname)); + + auto nicknames = std::make_shared<policy::StringArray>(2, kFakeNickname); + + const auto expected_app_properties_state = + policy::PolicyHandlerInterface::AppPropertiesState::NICKNAMES_CHANGED; + + EXPECT_CALL(*mock_policy_manager_, GetAppProperties(kPolicyAppId_, _)) + .WillOnce(Return(true)); + EXPECT_CALL(*mock_policy_manager_, GetInitialAppData(kPolicyAppId_, _, _)) + .WillOnce(DoAll(SetArgPointee<1>(*nicknames), Return(true))); + EXPECT_EQ(expected_app_properties_state, + policy_handler_.GetAppPropertiesStatus(properties, kPolicyAppId_)); +} + +TEST_F(PolicyHandlerTest, GetAppPropertiesStatus_NicknameNotChanged_SUCCESS) { + ChangePolicyManagerToMock(); smart_objects::SmartObject properties; properties[strings::app_id] = kPolicyAppId_; @@ -3112,6 +3072,23 @@ TEST_F(PolicyHandlerTest, GetAppPropertiesStatus_HybridAppNotChanged_SUCCESS) { policy::PolicyHandlerInterface::AppPropertiesState::NO_CHANGES); } +TEST_F(PolicyHandlerTest, GetAppPropertiesStatus_PolicyDisabled_FAIL) { + ChangePolicyManagerToMock(); + + EXPECT_CALL(policy_settings_, enable_policy()).WillOnce(Return(false)); + policy_handler_.LoadPolicyLibrary(); + + smart_objects::SmartObject properties; + properties[strings::app_id] = kPolicyAppId_; + + EXPECT_CALL(*mock_policy_manager_, GetAppProperties(_, _)).Times(0); + EXPECT_CALL(*mock_policy_manager_, GetInitialAppData(_, _, _)).Times(0); + const auto expected_app_properties_state = + policy::PolicyHandlerInterface::AppPropertiesState::NO_CHANGES; + EXPECT_EQ(expected_app_properties_state, + policy_handler_.GetAppPropertiesStatus(properties, kPolicyAppId_)); +} + TEST_F(PolicyHandlerTest, GetEnabledLocalApps_SUCCESS) { ChangePolicyManagerToMock(); std::vector<std::string> enabled_local_apps; @@ -3126,6 +3103,194 @@ TEST_F(PolicyHandlerTest, GetEnabledLocalApps_SUCCESS) { EXPECT_EQ(enabled_local_apps, policy_handler_.GetEnabledLocalApps()); } +TEST_F(PolicyHandlerTest, PushAppIdToPTUQueue_PolicyEnabled_SUCCESS) { + ChangePolicyManagerToMock(); + const uint32_t expected_apps_count = 1u; + EXPECT_CALL(*mock_policy_manager_, + UpdatePTUReadyAppsCount(expected_apps_count)); + policy_handler_.PushAppIdToPTUQueue(kAppId1_); + EXPECT_EQ(expected_apps_count, + policy_handler_.applications_ptu_queue_.size()); +} + +TEST_F(PolicyHandlerTest, PushAppIdToPTUQueue_PolicyDisabled_FAIL) { + ChangePolicyManagerToMock(); + + const uint32_t expected_apps_count = 0u; + EXPECT_CALL(policy_settings_, enable_policy()).WillOnce(Return(false)); + EXPECT_CALL(*mock_policy_manager_, + UpdatePTUReadyAppsCount(expected_apps_count)) + .Times(0); + + policy_handler_.LoadPolicyLibrary(); + policy_handler_.PushAppIdToPTUQueue(kAppId1_); + EXPECT_EQ(expected_apps_count, + policy_handler_.applications_ptu_queue_.size()); +} + +TEST_F(PolicyHandlerTest, StopRetrySequence_PolicyEnabled_SUCCESS) { + ChangePolicyManagerToMock(); + EXPECT_CALL(*mock_policy_manager_, StopRetrySequence()); + policy_handler_.StopRetrySequence(); +} + +TEST_F(PolicyHandlerTest, StopRetrySequence_PolicyDisabled_FAIL) { + ChangePolicyManagerToMock(); + + EXPECT_CALL(policy_settings_, enable_policy()).WillOnce(Return(false)); + EXPECT_CALL(*mock_policy_manager_, StopRetrySequence()).Times(0); + + policy_handler_.LoadPolicyLibrary(); + policy_handler_.StopRetrySequence(); +} + +TEST_F(PolicyHandlerTest, GetPolicyTableData_PolicyEnabled_SUCCESS) { + ChangePolicyManagerToMock(); + Json::Value expected_table_data(Json::objectValue); + expected_table_data["test_key"] = "test_value"; + EXPECT_CALL(*mock_policy_manager_, GetPolicyTableData()) + .WillOnce(Return(expected_table_data)); + EXPECT_EQ(expected_table_data, policy_handler_.GetPolicyTableData()); +} + +TEST_F(PolicyHandlerTest, GetPolicyTableData_PolicyDisabled_FAIL) { + ChangePolicyManagerToMock(); + + EXPECT_CALL(policy_settings_, enable_policy()).WillOnce(Return(false)); + EXPECT_CALL(*mock_policy_manager_, GetPolicyTableData()).Times(0); + + policy_handler_.LoadPolicyLibrary(); + + Json::Value expected_table_data; + EXPECT_EQ(expected_table_data, policy_handler_.GetPolicyTableData()); +} + +TEST_F(PolicyHandlerTest, GetRemovedVehicleDataItems_PolicyEnabled_SUCCESS) { + using rpc::policy_table_interface_base::VehicleDataItem; + + ChangePolicyManagerToMock(); + + std::vector<VehicleDataItem> expected_removed_items; + expected_removed_items.push_back(VehicleDataItem()); + + EXPECT_CALL(*mock_policy_manager_, GetRemovedVehicleDataItems()) + .WillOnce(Return(expected_removed_items)); + + const auto& actually_removed_items = + policy_handler_.GetRemovedVehicleDataItems(); + ASSERT_EQ(expected_removed_items.size(), actually_removed_items.size()); + EXPECT_TRUE(expected_removed_items[0] == actually_removed_items[0]); +} + +TEST_F(PolicyHandlerTest, GetRemovedVehicleDataItems_PolicyDisabled_FAIL) { + using rpc::policy_table_interface_base::VehicleDataItem; + + ChangePolicyManagerToMock(); + + EXPECT_CALL(policy_settings_, enable_policy()).WillOnce(Return(false)); + EXPECT_CALL(*mock_policy_manager_, GetRemovedVehicleDataItems()).Times(0); + + policy_handler_.LoadPolicyLibrary(); + + EXPECT_TRUE(policy_handler_.GetRemovedVehicleDataItems().empty()); +} + +TEST_F(PolicyHandlerTest, PopAppIdFromPTUQueue_PolicyEnabled_SUCCESS) { + ChangePolicyManagerToMock(); + + policy_handler_.PushAppIdToPTUQueue(kAppId1_); + ASSERT_EQ(1u, policy_handler_.applications_ptu_queue_.size()); + + policy_handler_.PopAppIdFromPTUQueue(); + EXPECT_EQ(0u, policy_handler_.applications_ptu_queue_.size()); +} + +TEST_F(PolicyHandlerTest, PopAppIdFromPTUQueue_PolicyDisabled_FAIL) { + ChangePolicyManagerToMock(); + + const uint32_t expected_apps_count = 0u; + EXPECT_CALL(policy_settings_, enable_policy()).WillOnce(Return(false)); + EXPECT_CALL(*mock_policy_manager_, + UpdatePTUReadyAppsCount(expected_apps_count)) + .Times(0); + + policy_handler_.LoadPolicyLibrary(); + policy_handler_.PopAppIdFromPTUQueue(); + EXPECT_EQ(expected_apps_count, + policy_handler_.applications_ptu_queue_.size()); +} + +TEST_F(PolicyHandlerTest, OnLocalAppAdded_PolicyEnabled_SUCCESS) { + ChangePolicyManagerToMock(); + EXPECT_CALL(*mock_policy_manager_, OnLocalAppAdded()); + policy_handler_.OnLocalAppAdded(); +} + +TEST_F(PolicyHandlerTest, OnLocalAppAdded_PolicyDisabled_FAIL) { + ChangePolicyManagerToMock(); + + EXPECT_CALL(policy_settings_, enable_policy()).WillOnce(Return(false)); + EXPECT_CALL(*mock_policy_manager_, OnLocalAppAdded()).Times(0); + + policy_handler_.LoadPolicyLibrary(); + policy_handler_.OnLocalAppAdded(); +} + +TEST_F(PolicyHandlerTest, OnPermissionsUpdated_PolicyEnabled_SUCCESS) { + ChangePolicyManagerToMock(); + + EXPECT_CALL(app_manager_, application(kDeviceId_, kPolicyAppId_)) + .WillOnce(Return(mock_app_)); + + const rpc::Optional<rpc::Boolean> encryption_requiered; + EXPECT_CALL(*mock_policy_manager_, GetAppEncryptionRequired(kPolicyAppId_)) + .WillOnce(Return(encryption_requiered)); + EXPECT_CALL(*mock_app_, app_id()).WillRepeatedly(Return(kAppId1_)); + + Permissions app_permissions; + EXPECT_CALL(mock_message_helper_, + SendOnPermissionsChangeNotification(kAppId1_, _, _, _)); + policy_handler_.OnPermissionsUpdated( + kDeviceId_, kPolicyAppId_, app_permissions); +} + +TEST_F(PolicyHandlerTest, OnPermissionsUpdated_PolicyDisabled_FAIL) { + ChangePolicyManagerToMock(); + + EXPECT_CALL(policy_settings_, enable_policy()).WillOnce(Return(false)); + policy_handler_.LoadPolicyLibrary(); + + EXPECT_CALL(app_manager_, application(kDeviceId_, kPolicyAppId_)).Times(0); + EXPECT_CALL(*mock_policy_manager_, GetAppEncryptionRequired(kPolicyAppId_)) + .Times(0); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + Permissions app_permissions; + EXPECT_CALL(mock_message_helper_, + SendOnPermissionsChangeNotification(_, _, _, _)) + .Times(0); + policy_handler_.OnPermissionsUpdated( + kDeviceId_, kPolicyAppId_, app_permissions); +} + +TEST_F(PolicyHandlerTest, IsNewApplication_PolicyEnabled_SUCCESS) { + ChangePolicyManagerToMock(); + + EXPECT_CALL(*mock_policy_manager_, IsNewApplication(kPolicyAppId_)) + .WillOnce(Return(true)); + EXPECT_TRUE(policy_handler_.IsNewApplication(kPolicyAppId_)); +} + +TEST_F(PolicyHandlerTest, IsNewApplication_PolicyDisabled_FAIL) { + ChangePolicyManagerToMock(); + + EXPECT_CALL(policy_settings_, enable_policy()).WillOnce(Return(false)); + policy_handler_.LoadPolicyLibrary(); + + EXPECT_CALL(*mock_policy_manager_, IsNewApplication(kPolicyAppId_)).Times(0); + EXPECT_FALSE(policy_handler_.IsNewApplication(kPolicyAppId_)); +} + } // namespace policy_handler_test } // namespace components } // namespace test diff --git a/src/components/application_manager/test/rc_policy_handler_test.cc b/src/components/application_manager/test/rc_policy_handler_test.cc index 818a014a3f..cc9f741d28 100644 --- a/src/components/application_manager/test/rc_policy_handler_test.cc +++ b/src/components/application_manager/test/rc_policy_handler_test.cc @@ -151,58 +151,6 @@ class RCPolicyHandlerTest : public ::testing::Test { } }; -TEST_F(RCPolicyHandlerTest, - SendMessageToSDK_RemoteControlInvalidMobileAppId_UNSUCCESS) { - // Precondition - BinaryMessage msg; - EnablePolicyAndPolicyManagerMock(); - - EXPECT_CALL(app_manager_, applications()).WillOnce(Return(app_set)); - test_app.insert(mock_app_); - - ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId1_)); - ON_CALL(*mock_app_, hmi_level()) - .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); - EXPECT_CALL(*mock_app_, IsRegistered()).WillOnce(Return(true)); - - EXPECT_CALL(app_manager_, application(kAppId1_)) - .WillRepeatedly(Return(mock_app_)); - const std::string empty_mobile_app_id(""); - EXPECT_CALL(*mock_app_, policy_app_id()) - .WillOnce(Return(empty_mobile_app_id)); - - EXPECT_CALL(*mock_policy_manager_, GetUserConsentForDevice(_)) - .WillOnce(Return(kDeviceAllowed)); - - EXPECT_CALL(mock_message_helper_, SendPolicySnapshotNotification(_, _, _, _)) - .Times(0); - EXPECT_FALSE(policy_handler_.SendMessageToSDK(msg, kUrl_)); -} - -TEST_F(RCPolicyHandlerTest, SendMessageToSDK_RemoteControl_SUCCESS) { - BinaryMessage msg; - EnablePolicyAndPolicyManagerMock(); - EXPECT_CALL(app_manager_, applications()).WillOnce(Return(app_set)); - test_app.insert(mock_app_); - - ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId1_)); - ON_CALL(*mock_app_, hmi_level()) - .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); - EXPECT_CALL(*mock_app_, IsRegistered()).WillOnce(Return(true)); - - EXPECT_CALL(app_manager_, application(kAppId1_)) - .WillRepeatedly(Return(mock_app_)); - - EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(kPolicyAppId_)); - - EXPECT_CALL(*mock_policy_manager_, GetUserConsentForDevice(_)) - .WillOnce(Return(kDeviceAllowed)); - - EXPECT_CALL(mock_message_helper_, - SendPolicySnapshotNotification(kAppId1_, _, kUrl_, _)); - EXPECT_TRUE(policy_handler_.SendMessageToSDK(msg, kUrl_)); -} - TEST_F(RCPolicyHandlerTest, OnUpdateHMILevel_InvalidApp_UNSUCCESS) { EnablePolicyAndPolicyManagerMock(); diff --git a/src/components/application_manager/test/resumption/resume_ctrl_test.cc b/src/components/application_manager/test/resumption/resume_ctrl_test.cc index da3cd934e4..b4e5e85376 100644 --- a/src/components/application_manager/test/resumption/resume_ctrl_test.cc +++ b/src/components/application_manager/test/resumption/resume_ctrl_test.cc @@ -53,6 +53,7 @@ #include "application_manager/mock_event_dispatcher.h" #include "application_manager/mock_message_helper.h" #include "application_manager/mock_state_controller.h" +#include "application_manager/policies/mock_policy_handler_interface.h" namespace test { namespace components { @@ -203,17 +204,25 @@ class ResumeCtrlTest : public ::testing::Test { return response; } + void SetupIsAppRevoked(const bool is_app_revoked) { + EXPECT_CALL(mock_app_mngr_, GetPolicyHandler()) + .WillOnce(ReturnRef(mock_policy_handler_)); + EXPECT_CALL(mock_policy_handler_, IsApplicationRevoked(_)) + .WillOnce(Return(is_app_revoked)); + } + NiceMock<event_engine_test::MockEventDispatcher> mock_event_dispatcher_; - application_manager_test::MockApplicationManagerSettings + NiceMock<application_manager_test::MockApplicationManagerSettings> mock_application_manager_settings_; NiceMock<application_manager_test::MockApplicationManager> mock_app_mngr_; std::shared_ptr<NiceMock<application_manager_test::MockAppExtension> > mock_app_extension_; - MockStateController mock_state_controller_; + NiceMock<MockStateController> mock_state_controller_; std::shared_ptr<ResumeCtrl> res_ctrl_; std::shared_ptr<NiceMock<resumption_test::MockResumptionData> > mock_storage_; std::shared_ptr<NiceMock<MockApplication> > mock_app_; std::shared_ptr<MockHelpPromptManager> mock_help_prompt_manager_; + policy_test::MockPolicyHandlerInterface mock_policy_handler_; application_manager::ApplicationConstSharedPtr const_app_; const uint32_t kTestAppId_; const std::string kTestPolicyAppId_; @@ -246,7 +255,6 @@ TEST_F(ResumeCtrlTest, StartResumption_AppWithGrammarId) { // Check RestoreApplicationData GetInfoFromApp(); - ON_CALL(mock_app_mngr_, GetDefaultHmiLevel(const_app_)) .WillByDefault(Return(kDefaultTestLevel_)); ON_CALL(*mock_storage_, @@ -933,6 +941,9 @@ TEST_F(ResumeCtrlTest, StartAppHmiStateResumption_AppInFull) { GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); + const bool is_app_revoked = false; + SetupIsAppRevoked(is_app_revoked); + EXPECT_CALL(*mock_storage_, RemoveApplicationFromSaved(kTestPolicyAppId_, kMacAddress_)) .WillOnce(Return(true)); @@ -980,6 +991,9 @@ TEST_F(ResumeCtrlTest, StartAppHmiStateResumption_AppHasDeferredResumption) { GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); + const bool is_app_revoked = false; + SetupIsAppRevoked(is_app_revoked); + mobile_apis::HMILevel::eType app_deferred_level = deferred_level; EXPECT_CALL(*mock_app_, deferred_resumption_hmi_level()) .WillRepeatedly(ReturnPointee(&app_deferred_level)); @@ -1016,6 +1030,9 @@ TEST_F(ResumeCtrlTest, GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); + const bool is_app_revoked = false; + SetupIsAppRevoked(is_app_revoked); + EXPECT_CALL(mock_app_mngr_, CheckResumptionRequiredTransportAvailable(_)) .WillOnce(Return(false)); @@ -1061,6 +1078,9 @@ TEST_F( GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); + const bool is_app_revoked = false; + SetupIsAppRevoked(is_app_revoked); + EXPECT_CALL(mock_app_mngr_, CheckResumptionRequiredTransportAvailable(_)) .WillOnce(Return(false)); @@ -1210,6 +1230,9 @@ TEST_F(ResumeCtrlTest, ApplicationResumptiOnTimer_AppInFull) { GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); + const bool is_app_revoked = false; + SetupIsAppRevoked(is_app_revoked); + EXPECT_CALL(*mock_storage_, RemoveApplicationFromSaved(kTestPolicyAppId_, kMacAddress_)) .WillOnce(Return(true)); @@ -1554,6 +1577,9 @@ TEST_F( GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); + const bool is_app_revoked = false; + SetupIsAppRevoked(is_app_revoked); + EXPECT_CALL(*mock_storage_, RemoveApplicationFromSaved(kTestPolicyAppId_, kMacAddress_)) .WillOnce(Return(true)); @@ -1596,6 +1622,9 @@ TEST_F( GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); + const bool is_app_revoked = false; + SetupIsAppRevoked(is_app_revoked); + ON_CALL(mock_app_mngr_, GetUserConsentForDevice("12345")) .WillByDefault(Return(policy::kDeviceAllowed)); @@ -1662,6 +1691,9 @@ TEST_F( GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); + const bool is_app_revoked = false; + SetupIsAppRevoked(is_app_revoked); + EXPECT_CALL(*mock_storage_, RemoveApplicationFromSaved(kTestPolicyAppId_, kMacAddress_)) .WillOnce(Return(true)); @@ -1704,6 +1736,9 @@ TEST_F( GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); + const bool is_app_revoked = false; + SetupIsAppRevoked(is_app_revoked); + ON_CALL(mock_app_mngr_, GetUserConsentForDevice("12345")) .WillByDefault(Return(policy::kDeviceAllowed)); diff --git a/src/components/application_manager/test/resumption/resumption_data_test.cc b/src/components/application_manager/test/resumption/resumption_data_test.cc index e362064a78..12a38e1bc4 100644 --- a/src/components/application_manager/test/resumption/resumption_data_test.cc +++ b/src/components/application_manager/test/resumption/resumption_data_test.cc @@ -52,6 +52,33 @@ using ::testing::Return; using ::testing::ReturnPointee; using ::testing::ReturnRef; +ResumptionDataTest::~ResumptionDataTest() { + delete help_prompt_; + delete timeout_prompt_; + delete vr_help_; + delete vr_help_title_; + delete vr_synonyms_; + delete keyboard_props_; + delete menu_title_; + delete menu_icon_; + + for (am::CommandsMap::iterator it = test_commands_map.begin(); + test_commands_map.end() != it; + ++it) { + delete it->second; + } + for (am::SubMenuMap::iterator it = test_submenu_map.begin(); + test_submenu_map.end() != it; + ++it) { + delete it->second; + } + for (am::ChoiceSetMap::iterator it = test_choiceset_map.begin(); + test_choiceset_map.end() != it; + ++it) { + delete it->second; + } +} + void ResumptionDataTest::CheckSavedApp(sm::SmartObject& resume_app_list) { EXPECT_EQ(policy_app_id_, resume_app_list[am::strings::app_id].asString()); EXPECT_EQ(grammar_id_, resume_app_list[am::strings::grammar_id].asUInt()); diff --git a/src/components/application_manager/test/rpc_service_impl_test.cc b/src/components/application_manager/test/rpc_service_impl_test.cc new file mode 100644 index 0000000000..0a7cff031d --- /dev/null +++ b/src/components/application_manager/test/rpc_service_impl_test.cc @@ -0,0 +1,837 @@ +/* + * Copyright (c) 2020, 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 "gtest/gtest.h" + +#include <string> +#include "application_manager/rpc_service_impl.h" + +#include "application_manager/commands/command.h" +#include "application_manager/commands/command_impl.h" +#include "application_manager/mock_app_service_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_command_factory.h" +#include "application_manager/mock_command_holder.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_request.h" +#include "application_manager/mock_request_controller_settings.h" +#include "application_manager/mock_rpc_plugin.h" +#include "application_manager/mock_rpc_plugin_manager.h" +#include "application_manager/mock_rpc_protection_manager.h" +#include "application_manager/plugin_manager/plugin_keys.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "connection_handler/mock_connection_handler.h" +#include "hmi_message_handler/mock_hmi_message_handler.h" +#include "include/test/protocol_handler/mock_protocol_handler.h" + +namespace test { +namespace components { +namespace application_manager_test { + +namespace rpc_service = application_manager::rpc_service; +namespace am = application_manager; +using test::components::hmi_message_handler_test::MockHMIMessageHandler; +using test::components::protocol_handler_test::MockProtocolHandler; +typedef smart_objects::SmartObjectSPtr MessageSharedPtr; +typedef utils::Optional<am::plugin_manager::RPCPlugin> PluginOpt; +using test::components::application_manager_test::MockAppServiceManager; +using ::testing::_; +using ::testing::NiceMock; +using ::testing::Return; +using ::testing::ReturnRef; + +namespace { +const uint32_t kConnectionKey = 1u; +const connection_handler::DeviceHandle kDeviceHandle = 1u; +const std::string kPolicyAppId = "policy_app_id"; +const uint32_t kCorrelationId = 1u; +const uint32_t kFunctionId = 1u; +const uint32_t kAppId = 1u; +const int32_t kMobileProtocolType = 0; +const int32_t kProtocolVersion = 1; +const int32_t kConnectionSessionsCount = 2; +} // namespace + +class RPCServiceImplTest : public ::testing::Test { + public: + RPCServiceImplTest() + : request_controller_(mock_request_controler_) + , mock_rpc_protection_manager_( + std::make_shared< + testing::NiceMock<am::MockRPCProtectionManager> >()) + , mock_message_helper_(*am::MockMessageHelper::message_helper_mock()) + , mock_app_service_nmgr_(mock_app_mngr_, nullptr) { + rpc_service_ = std::make_shared<rpc_service::RPCServiceImpl>( + mock_app_mngr_, + request_controller_, + &mock_protocol_handler_, + &mock_hmi_handler_, + mock_command_holder_, + mock_rpc_protection_manager_, + hmi_so_factory_, + mobile_so_factory_); + } + + MessageSharedPtr CreateMessage( + const smart_objects::SmartType type = smart_objects::SmartType_Null) { + return std::make_shared<smart_objects::SmartObject>(type); + } + void PrepareBasicMessage(MessageSharedPtr& message) { + (*message)[am::strings::params][am::strings::function_id] = + static_cast<mobile_apis::FunctionID::eType>( + mobile_apis::FunctionID::RESERVED); + (*message)[am::strings::params][am::strings::correlation_id] = + kCorrelationId; + (*message)[am::strings::params][am::strings::protocol_type] = + kMobileProtocolType; + (*message)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + } + + // This class is created to allow access to protected method + // InitFunctionSchema from MOBILE_API + class MobileAPIWithPublicSchemaSetting : public mobile_apis::MOBILE_API { + public: + void SetSchema(mobile_apis::FunctionID::eType function_id, + mobile_apis::messageType::eType message_type) { + InitFunctionSchema(function_id, message_type); + } + }; + + // This class is created to allow access to protected method + // InitFunctionSchema from HMI_API + class HMIAPIWithPublicSchemaSetting : public hmi_apis::HMI_API { + public: + void SetSchema(hmi_apis::FunctionID::eType function_id, + hmi_apis::messageType::eType message_type) { + InitFunctionSchema(function_id, message_type); + } + }; + + protected: + hmi_apis::HMI_API hmi_so_factory_; + mobile_apis::MOBILE_API mobile_so_factory_; + testing::NiceMock<MockApplicationManager> mock_app_mngr_; + testing::NiceMock<MockRequestControlerSettings> mock_request_controler_; + testing::NiceMock<MockProtocolHandler> mock_protocol_handler_; + am::request_controller::RequestController request_controller_; + testing::NiceMock<MockHMIMessageHandler> mock_hmi_handler_; + testing::NiceMock<MockCommandHolder> mock_command_holder_; + std::shared_ptr<am::MockRPCProtectionManager> mock_rpc_protection_manager_; + std::shared_ptr<rpc_service::RPCService> rpc_service_; + std::shared_ptr<MockApplication> mock_app_ptr_; + am::MockMessageHelper& mock_message_helper_; + MockAppServiceManager mock_app_service_nmgr_; + testing::NiceMock<am::plugin_manager::MockRPCPluginManager> + mock_rpc_plugin_manager_; + testing::NiceMock<am::plugin_manager::MockRPCPlugin> mock_rpc_plugin_; + testing::NiceMock<MockCommandFactory> mock_command_factory_; +}; + +TEST_F(RPCServiceImplTest, ManageMobileCommand_MessageIsNullPtr_False) { + MessageSharedPtr message; + EXPECT_FALSE(rpc_service_->ManageMobileCommand( + message, am::commands::Command::CommandSource::SOURCE_MOBILE)); +} + +TEST_F(RPCServiceImplTest, ManageMobileCommand_IsLowVoltage_False) { + auto message = CreateMessage(); + ON_CALL(mock_app_mngr_, IsLowVoltage()).WillByDefault(Return(true)); + EXPECT_FALSE(rpc_service_->ManageMobileCommand( + message, am::commands::Command::CommandSource::SOURCE_MOBILE)); +} + +TEST_F(RPCServiceImplTest, ManageMobileCommand_AppInReconnectMode) { + auto message = CreateMessage(smart_objects::SmartType_Map); + auto source = am::commands::Command::CommandSource::SOURCE_MOBILE; + (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey; + + mock_app_ptr_ = std::make_shared<NiceMock<MockApplication> >(); + ON_CALL(mock_app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_ptr_)); + ON_CALL(*mock_app_ptr_, device()).WillByDefault(Return(kDeviceHandle)); + ON_CALL(*mock_app_ptr_, policy_app_id()).WillByDefault(Return(kPolicyAppId)); + ON_CALL(mock_app_mngr_, IsAppInReconnectMode(kDeviceHandle, kPolicyAppId)) + .WillByDefault(Return(true)); + EXPECT_CALL(mock_command_holder_, + Suspend(static_cast<am::ApplicationSharedPtr>(mock_app_ptr_), + am::CommandHolder::CommandType::kMobileCommand, + source, + message)) + .WillOnce(Return()); + + EXPECT_TRUE(rpc_service_->ManageMobileCommand(message, source)); +} + +TEST_F(RPCServiceImplTest, + ManageMobileCommand_SourceIsCheckedForUnsupportedRequest) { + typedef am::plugin_manager::RPCPlugin RPCPlugin; + + auto message = CreateMessage(smart_objects::SmartType_Map); + auto source = am::commands::Command::CommandSource::SOURCE_MOBILE; + (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*message)[am::strings::params][am::strings::function_id] = kFunctionId; + (*message)[am::strings::params][am::strings::protocol_type] = + kMobileProtocolType; + + ON_CALL(mock_app_mngr_, IsLowVoltage()).WillByDefault(Return(false)); + mock_app_ptr_ = std::make_shared<NiceMock<MockApplication> >(); + ON_CALL(mock_app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_ptr_)); + ON_CALL(*mock_app_ptr_, device()).WillByDefault(Return(kDeviceHandle)); + ON_CALL(*mock_app_ptr_, policy_app_id()).WillByDefault(Return(kPolicyAppId)); + ON_CALL(mock_app_mngr_, IsAppInReconnectMode(kDeviceHandle, kPolicyAppId)) + .WillByDefault(Return(false)); + ON_CALL(mock_app_mngr_, GetPluginManager()) + .WillByDefault(ReturnRef(mock_rpc_plugin_manager_)); + auto empty_plugin(utils::Optional<RPCPlugin>::OptionalEmpty::EMPTY); + ON_CALL(mock_rpc_plugin_manager_, FindPluginToProcess(kFunctionId, source)) + .WillByDefault(Return(empty_plugin)); + + EXPECT_FALSE(rpc_service_->ManageMobileCommand(message, source)); +} + +TEST_F(RPCServiceImplTest, ManageHMICommand_MessageIsNullPtr_False) { + MessageSharedPtr message; + EXPECT_FALSE(rpc_service_->ManageHMICommand( + message, am::commands::Command::CommandSource::SOURCE_HMI)); +} + +TEST_F(RPCServiceImplTest, ManageHMICommand_IsLowVoltage_ReturnFalse) { + auto message = CreateMessage(); + ON_CALL(mock_app_mngr_, IsLowVoltage()).WillByDefault(Return(true)); + EXPECT_FALSE(rpc_service_->ManageHMICommand( + message, am::commands::Command::CommandSource::SOURCE_HMI)); +} + +TEST_F(RPCServiceImplTest, ManageHMICommand_PluginIsEmpty_False) { + auto message = CreateMessage(); + auto source = am::commands::Command::CommandSource::SOURCE_HMI; + (*message)[am::strings::params][am::strings::function_id] = kFunctionId; + + ON_CALL(mock_app_mngr_, IsLowVoltage()).WillByDefault(Return(false)); + ON_CALL(mock_app_mngr_, GetPluginManager()) + .WillByDefault(ReturnRef(mock_rpc_plugin_manager_)); + typedef am::plugin_manager::RPCPlugin RPCPlugin; + utils::Optional<RPCPlugin> mock_rpc_plugin_opt( + utils::Optional<RPCPlugin>::OptionalEmpty::EMPTY); + ON_CALL(mock_rpc_plugin_manager_, FindPluginToProcess(kFunctionId, source)) + .WillByDefault(Return(mock_rpc_plugin_opt)); + + EXPECT_FALSE(rpc_service_->ManageHMICommand(message, source)); +} + +TEST_F(RPCServiceImplTest, ManageHMICommand_FailedCreateCommand_False) { + typedef am::plugin_manager::RPCPlugin RPCPlugin; + + auto message = CreateMessage(); + auto source = am::commands::Command::CommandSource::SOURCE_HMI; + (*message)[am::strings::params][am::strings::function_id] = kFunctionId; + + ON_CALL(mock_app_mngr_, IsLowVoltage()).WillByDefault(Return(false)); + ON_CALL(mock_app_mngr_, GetPluginManager()) + .WillByDefault(ReturnRef(mock_rpc_plugin_manager_)); + utils::Optional<RPCPlugin> mock_rpc_plugin_opt = mock_rpc_plugin_; + ON_CALL(mock_rpc_plugin_manager_, FindPluginToProcess(kFunctionId, source)) + .WillByDefault(Return(mock_rpc_plugin_opt)); + ON_CALL(mock_rpc_plugin_, GetCommandFactory()) + .WillByDefault(ReturnRef(mock_command_factory_)); + std::shared_ptr<MockRequest> cmd; + ON_CALL(mock_command_factory_, CreateCommand(message, source)) + .WillByDefault(Return(cmd)); + + EXPECT_FALSE(rpc_service_->ManageHMICommand(message, source)); +} + +TEST_F(RPCServiceImplTest, ManageHMICommand_IsAppInReconnectMode_True) { + typedef am::plugin_manager::RPCPlugin RPCPlugin; + + auto message = CreateMessage(); + auto source = am::commands::Command::CommandSource::SOURCE_HMI; + (*message)[am::strings::params][am::strings::function_id] = kFunctionId; + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId; + + ON_CALL(mock_app_mngr_, IsLowVoltage()).WillByDefault(Return(false)); + ON_CALL(mock_app_mngr_, GetPluginManager()) + .WillByDefault(ReturnRef(mock_rpc_plugin_manager_)); + utils::Optional<RPCPlugin> mock_rpc_plugin_opt = mock_rpc_plugin_; + ON_CALL(mock_rpc_plugin_manager_, FindPluginToProcess(kFunctionId, source)) + .WillByDefault(Return(mock_rpc_plugin_opt)); + ON_CALL(mock_rpc_plugin_, GetCommandFactory()) + .WillByDefault(ReturnRef(mock_command_factory_)); + std::shared_ptr<MockRequest> cmd = + std::make_shared<MockRequest>(kConnectionKey, kCorrelationId); + ON_CALL(mock_command_factory_, CreateCommand(message, source)) + .WillByDefault(Return(cmd)); + + auto mock_app = std::make_shared<NiceMock<MockApplication> >(); + ON_CALL(mock_app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app)); + const connection_handler::DeviceHandle device_id1 = 1u; + ON_CALL(*mock_app, device()).WillByDefault(Return(device_id1)); + ON_CALL(*mock_app, policy_app_id()).WillByDefault(Return(kPolicyAppId)); + ON_CALL(mock_app_mngr_, IsAppInReconnectMode(device_id1, kPolicyAppId)) + .WillByDefault(Return(true)); + + EXPECT_CALL(mock_command_holder_, + Suspend(static_cast<am::ApplicationSharedPtr>(mock_app), + am::CommandHolder::CommandType::kHmiCommand, + source, + message)) + .WillOnce(Return()); + EXPECT_TRUE(rpc_service_->ManageHMICommand(message, source)); +} + +TEST_F(RPCServiceImplTest, + ManageHMICommand_MessageTypeUnknownTypeCommandNotInit_ReturnFalse) { + typedef am::plugin_manager::RPCPlugin RPCPlugin; + + auto message = CreateMessage(); + auto source = am::commands::Command::CommandSource::SOURCE_HMI; + (*message)[am::strings::params][am::strings::function_id] = kFunctionId; + (*message)[am::strings::params][am::strings::message_type] = am::kUnknownType; + + ON_CALL(mock_app_mngr_, IsLowVoltage()).WillByDefault(Return(false)); + ON_CALL(mock_app_mngr_, GetPluginManager()) + .WillByDefault(ReturnRef(mock_rpc_plugin_manager_)); + utils::Optional<RPCPlugin> mock_rpc_plugin_opt = mock_rpc_plugin_; + ON_CALL(mock_rpc_plugin_manager_, FindPluginToProcess(kFunctionId, source)) + .WillByDefault(Return(mock_rpc_plugin_opt)); + ON_CALL(mock_rpc_plugin_, GetCommandFactory()) + .WillByDefault(ReturnRef(mock_command_factory_)); + std::shared_ptr<MockRequest> cmd = + std::make_shared<MockRequest>(kConnectionKey, kCorrelationId); + ON_CALL(mock_command_factory_, CreateCommand(message, source)) + .WillByDefault(Return(cmd)); + + EXPECT_CALL(*cmd, Init()).WillOnce(Return(false)); + EXPECT_FALSE(rpc_service_->ManageHMICommand(message, source)); +} + +TEST_F(RPCServiceImplTest, + IsAppServiceRPC_SourceMobileWithValidFuncId_ReturnTrue) { + auto source_mobile = am::commands::Command::CommandSource::SOURCE_MOBILE; + auto source_sdl = am::commands::Command::CommandSource::SOURCE_SDL; + + EXPECT_TRUE(rpc_service_->IsAppServiceRPC( + mobile_apis::FunctionID::GetSystemCapabilityID, source_mobile)); + EXPECT_TRUE(rpc_service_->IsAppServiceRPC( + mobile_apis::FunctionID::OnSystemCapabilityUpdatedID, source_sdl)); + EXPECT_TRUE(rpc_service_->IsAppServiceRPC( + mobile_apis::FunctionID::GetSystemCapabilityID, source_sdl)); + EXPECT_TRUE(rpc_service_->IsAppServiceRPC( + mobile_apis::FunctionID::OnSystemCapabilityUpdatedID, source_sdl)); +} + +TEST_F(RPCServiceImplTest, + IsAppServiceRPC_SourceHMIWithValidFuncId_ReturnTrue) { + auto source_hmi = am::commands::Command::CommandSource::SOURCE_HMI; + auto source_sdl_to_hmi = + am::commands::Command::CommandSource::SOURCE_SDL_TO_HMI; + int32_t function_id = + hmi_apis::FunctionID::BasicCommunication_OnSystemCapabilityUpdated; + + EXPECT_TRUE(rpc_service_->IsAppServiceRPC(function_id, source_hmi)); + EXPECT_TRUE(rpc_service_->IsAppServiceRPC(function_id, source_sdl_to_hmi)); +} + +TEST_F(RPCServiceImplTest, IsAppServiceRPC_EmptyPlugin_ReturnFalse) { + auto source = am::commands::Command::CommandSource::SOURCE_HMI; + + ON_CALL(mock_app_mngr_, GetPluginManager()) + .WillByDefault(ReturnRef(mock_rpc_plugin_manager_)); + typedef am::plugin_manager::RPCPlugin RPCPlugin; + utils::Optional<RPCPlugin> mock_rpc_plugin_opt( + utils::Optional<RPCPlugin>::OptionalEmpty::EMPTY); + ON_CALL(mock_rpc_plugin_manager_, FindPluginToProcess(kFunctionId, source)) + .WillByDefault(Return(mock_rpc_plugin_opt)); + + EXPECT_FALSE(rpc_service_->IsAppServiceRPC(kFunctionId, source)); +} + +TEST_F(RPCServiceImplTest, IsAppServiceRPC_PluginWithWrongName_ReturnFalse) { + auto source = am::commands::Command::CommandSource::SOURCE_HMI; + + ON_CALL(mock_app_mngr_, GetPluginManager()) + .WillByDefault(ReturnRef(mock_rpc_plugin_manager_)); + PluginOpt mock_rpc_plugin_opt(mock_rpc_plugin_); + ON_CALL(mock_rpc_plugin_manager_, FindPluginToProcess(kFunctionId, source)) + .WillByDefault(Return(mock_rpc_plugin_opt)); + ON_CALL(mock_rpc_plugin_, PluginName()).WillByDefault(Return("")); + + EXPECT_FALSE(rpc_service_->IsAppServiceRPC(kFunctionId, source)); +} + +TEST_F(RPCServiceImplTest, + IsAppServiceRPC_CommandFactoryIsAbleToProcess_ReturnTrue) { + auto source = am::commands::Command::CommandSource::SOURCE_HMI; + using namespace application_manager::plugin_manager::plugin_names; + + ON_CALL(mock_app_mngr_, GetPluginManager()) + .WillByDefault(ReturnRef(mock_rpc_plugin_manager_)); + PluginOpt mock_rpc_plugin_opt(mock_rpc_plugin_); + ON_CALL(mock_rpc_plugin_manager_, FindPluginToProcess(kFunctionId, source)) + .WillByDefault(Return(mock_rpc_plugin_opt)); + ON_CALL(mock_rpc_plugin_, PluginName()) + .WillByDefault(Return(app_service_rpc_plugin)); + ON_CALL(mock_rpc_plugin_, GetCommandFactory()) + .WillByDefault(ReturnRef(mock_command_factory_)); + ON_CALL(mock_command_factory_, IsAbleToProcess(kFunctionId, source)) + .WillByDefault(Return(true)); + + EXPECT_TRUE(rpc_service_->IsAppServiceRPC(kFunctionId, source)); +} + +TEST_F(RPCServiceImplTest, + UpdateMobileRPCParams_FunctionSchemaIsResettedAndAddedCustomMember) { + using namespace ns_smart_device_link::ns_smart_objects; + + // Get initial state of schema + auto function_id = mobile_apis::FunctionID::OnHMIStatusID; + auto message_type = mobile_apis::messageType::notification; + MobileAPIWithPublicSchemaSetting extended_mobile_api; + extended_mobile_api.SetSchema(function_id, message_type); + + auto rpc_service_with_extended_api = + std::make_shared<rpc_service::RPCServiceImpl>( + mock_app_mngr_, + request_controller_, + &mock_protocol_handler_, + &mock_hmi_handler_, + mock_command_holder_, + mock_rpc_protection_manager_, + hmi_so_factory_, + extended_mobile_api); + + CSmartSchema initial_schema; + extended_mobile_api.GetSchema(function_id, message_type, initial_schema); + auto initial_schema_item = initial_schema.getSchemaItem(); + + // Change state of schema and add custom parameter + auto new_function_id = mobile_apis::FunctionID::OnButtonEventID; + std::map<std::string, SMember> members; + members["custom member"] = SMember(); + rpc_service_with_extended_api->UpdateMobileRPCParams( + new_function_id, message_type, members); + CSmartSchema updated_schema; + extended_mobile_api.GetSchema(new_function_id, message_type, updated_schema); + + // Check that schema is changed + EXPECT_NE(initial_schema_item, updated_schema.getSchemaItem()); +} + +TEST_F(RPCServiceImplTest, + UpdateHMIRPCParams_FunctionSchemaIsResettedAndAddedCustomMember) { + using namespace ns_smart_device_link::ns_smart_objects; + + // Get initial state of schema + auto function_id = hmi_apis::FunctionID::Buttons_OnButtonEvent; + auto message_type = hmi_apis::messageType::notification; + HMIAPIWithPublicSchemaSetting extended_hmi_api; + extended_hmi_api.SetSchema(function_id, message_type); + + auto rpc_service_with_extended_api = + std::make_shared<rpc_service::RPCServiceImpl>( + mock_app_mngr_, + request_controller_, + &mock_protocol_handler_, + &mock_hmi_handler_, + mock_command_holder_, + mock_rpc_protection_manager_, + extended_hmi_api, + mobile_so_factory_); + + CSmartSchema initial_schema; + extended_hmi_api.GetSchema(function_id, message_type, initial_schema); + auto initial_schema_item = initial_schema.getSchemaItem(); + + // Change state of schema and add custom parameter + auto new_function_id = hmi_apis::FunctionID::Buttons_OnButtonPress; + std::map<std::string, SMember> members; + members["custom member"] = SMember(); + rpc_service_with_extended_api->UpdateHMIRPCParams( + function_id, message_type, members); + CSmartSchema updated_schema; + extended_hmi_api.GetSchema(new_function_id, message_type, updated_schema); + + // Check that schema is changed + EXPECT_NE(initial_schema_item, updated_schema.getSchemaItem()); +} + +TEST_F(RPCServiceImplTest, SendMessageToHMI_HappyPath) { + using namespace application_manager::plugin_manager::plugin_names; + auto source = am::commands::Command::CommandSource::SOURCE_SDL_TO_HMI; + auto func_id = mobile_apis::FunctionID::RESERVED; + auto message = CreateMessage(smart_objects::SmartType_Map); + PrepareBasicMessage(message); + + ON_CALL(mock_app_mngr_, GetPluginManager()) + .WillByDefault(ReturnRef(mock_rpc_plugin_manager_)); + PluginOpt mock_rpc_plugin_opt(mock_rpc_plugin_); + ON_CALL(mock_rpc_plugin_manager_, FindPluginToProcess(func_id, source)) + .WillByDefault(Return(mock_rpc_plugin_opt)); + ON_CALL(mock_rpc_plugin_, PluginName()) + .WillByDefault(Return(app_service_rpc_plugin)); + ON_CALL(mock_rpc_plugin_, GetCommandFactory()) + .WillByDefault(ReturnRef(mock_command_factory_)); + + EXPECT_CALL(mock_command_factory_, IsAbleToProcess(func_id, source)) + .WillOnce(Return(true)); + rpc_service_->SendMessageToHMI(message); +} + +TEST_F(RPCServiceImplTest, SendMessageToHMI_NoHMIHandler_ExecutionAborted) { + auto message = CreateMessage(smart_objects::SmartType_Map); + PrepareBasicMessage(message); + + rpc_service_->set_hmi_message_handler(nullptr); + EXPECT_CALL(mock_app_mngr_, GetPluginManager()).Times(0); + rpc_service_->SendMessageToHMI(message); +} + +TEST_F(RPCServiceImplTest, Handle_NoHMIHandler_ExecutionAborted) { + auto message_handler = std::make_shared<rpc_service::RPCServiceImpl>( + mock_app_mngr_, + request_controller_, + &mock_protocol_handler_, + &mock_hmi_handler_, + mock_command_holder_, + mock_rpc_protection_manager_, + hmi_so_factory_, + mobile_so_factory_); + message_handler->set_hmi_message_handler(nullptr); + + auto msg = std::shared_ptr<am::Message>(); + auto msg_to_hmi = am::rpc_service::impl::MessageToHmi(msg); + + EXPECT_CALL(mock_hmi_handler_, SendMessageToHMI(msg_to_hmi)).Times(0); + message_handler->Handle(msg_to_hmi); +} + +TEST_F(RPCServiceImplTest, Handle_ValidHMIHandler) { + auto message_handler = std::make_shared<rpc_service::RPCServiceImpl>( + mock_app_mngr_, + request_controller_, + &mock_protocol_handler_, + &mock_hmi_handler_, + mock_command_holder_, + mock_rpc_protection_manager_, + hmi_so_factory_, + mobile_so_factory_); + auto msg = std::shared_ptr<am::Message>(); + auto msg_to_hmi = am::rpc_service::impl::MessageToHmi(msg); + + EXPECT_CALL(mock_hmi_handler_, SendMessageToHMI(msg_to_hmi)); + message_handler->Handle(msg_to_hmi); +} + +TEST_F(RPCServiceImplTest, Handle_NoMobileProtocolHandler_ExecutionAborted) { + auto message_handler = std::make_shared<rpc_service::RPCServiceImpl>( + mock_app_mngr_, + request_controller_, + &mock_protocol_handler_, + &mock_hmi_handler_, + mock_command_holder_, + mock_rpc_protection_manager_, + hmi_so_factory_, + mobile_so_factory_); + + message_handler->set_protocol_handler(nullptr); + auto message_to_send = std::make_shared<am::Message>( + protocol_handler::MessagePriority::kDefault); + + EXPECT_CALL(mock_protocol_handler_, IsRPCServiceSecure(_)).Times(0); + message_handler->Handle( + am::rpc_service::impl::MessageToMobile(message_to_send, false)); +} + +TEST_F(RPCServiceImplTest, Handle_NoRawMessage_ExecutionAborted) { + auto message_handler = std::make_shared<rpc_service::RPCServiceImpl>( + mock_app_mngr_, + request_controller_, + &mock_protocol_handler_, + &mock_hmi_handler_, + mock_command_holder_, + mock_rpc_protection_manager_, + hmi_so_factory_, + mobile_so_factory_); + auto message_to_send = std::make_shared<am::Message>( + protocol_handler::MessagePriority::kDefault); + + EXPECT_CALL(mock_protocol_handler_, IsRPCServiceSecure(_)).Times(0); + message_handler->Handle( + am::rpc_service::impl::MessageToMobile(message_to_send, false)); +} + +TEST_F(RPCServiceImplTest, + Handle_NeedsEncryptionAndServiceNotSecure_ExecutionAborted) { + auto message_handler = std::make_shared<rpc_service::RPCServiceImpl>( + mock_app_mngr_, + request_controller_, + &mock_protocol_handler_, + &mock_hmi_handler_, + mock_command_holder_, + mock_rpc_protection_manager_, + hmi_so_factory_, + mobile_so_factory_); + auto message_to_send = std::make_shared<am::Message>( + protocol_handler::MessagePriority::kDefault); + message_to_send->set_protocol_version( + protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_1); + message_to_send->set_connection_key(kConnectionKey); + message_to_send->set_correlation_id(kCorrelationId); + message_to_send->set_function_id(kFunctionId); + message_to_send->set_message_type(static_cast<am::MessageType>(0)); + message_to_send->set_json_message(std::string("message")); + + EXPECT_CALL(mock_protocol_handler_, IsRPCServiceSecure(kConnectionKey)) + .WillOnce(Return(false)); + EXPECT_CALL(*mock_rpc_protection_manager_, IsInEncryptionNeededCache(_, _)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_protocol_handler_, SendMessageToMobileApp(_, _, _)).Times(0); + message_handler->Handle( + am::rpc_service::impl::MessageToMobile(message_to_send, false)); +} + +TEST_F(RPCServiceImplTest, Handle_HappyPathWithoutClosingSession) { + auto message_handler = std::make_shared<rpc_service::RPCServiceImpl>( + mock_app_mngr_, + request_controller_, + &mock_protocol_handler_, + &mock_hmi_handler_, + mock_command_holder_, + mock_rpc_protection_manager_, + hmi_so_factory_, + mobile_so_factory_); + auto message_to_send = std::make_shared<am::Message>( + protocol_handler::MessagePriority::kDefault); + message_to_send->set_protocol_version( + protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_1); + message_to_send->set_connection_key(kConnectionKey); + message_to_send->set_correlation_id(kCorrelationId); + message_to_send->set_function_id(kFunctionId); + message_to_send->set_message_type(am::MessageType::kNotification); + message_to_send->set_json_message(std::string("message")); + + EXPECT_CALL(mock_protocol_handler_, IsRPCServiceSecure(kConnectionKey)) + .WillOnce(Return(true)); + ON_CALL(mock_app_mngr_, application(_)).WillByDefault(Return(nullptr)); + EXPECT_CALL(*mock_rpc_protection_manager_, CheckPolicyEncryptionFlag(_, _, _)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_protocol_handler_, SendMessageToMobileApp(_, _, _)) + .WillOnce(Return()); + EXPECT_CALL(*mock_rpc_protection_manager_, + RemoveFromEncryptionNeededCache(_, _)) + .WillOnce(Return()); + message_handler->Handle( + am::rpc_service::impl::MessageToMobile(message_to_send, false)); +} + +TEST_F(RPCServiceImplTest, Handle_HappyPathWithClosedSession) { + auto message_handler = std::make_shared<rpc_service::RPCServiceImpl>( + mock_app_mngr_, + request_controller_, + &mock_protocol_handler_, + &mock_hmi_handler_, + mock_command_holder_, + mock_rpc_protection_manager_, + hmi_so_factory_, + mobile_so_factory_); + auto message_to_send = std::make_shared<am::Message>( + protocol_handler::MessagePriority::kDefault); + message_to_send->set_protocol_version( + protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_1); + message_to_send->set_connection_key(kConnectionKey); + message_to_send->set_correlation_id(kCorrelationId); + message_to_send->set_function_id(kFunctionId); + message_to_send->set_message_type(am::MessageType::kNotification); + message_to_send->set_json_message(std::string("message")); + + NiceMock<test::components::connection_handler_test::MockConnectionHandler> + mock_conn_handler; + EXPECT_CALL(mock_app_mngr_, connection_handler()) + .WillRepeatedly(ReturnRef(mock_conn_handler)); + ON_CALL(mock_conn_handler, GetConnectionSessionsCount(_)) + .WillByDefault(Return(kConnectionSessionsCount)); + ON_CALL(mock_protocol_handler_, IsRPCServiceSecure(_)) + .WillByDefault(Return(true)); + ON_CALL(mock_app_mngr_, application(_)).WillByDefault(Return(nullptr)); + EXPECT_CALL(*mock_rpc_protection_manager_, CheckPolicyEncryptionFlag(_, _, _)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_protocol_handler_, SendMessageToMobileApp(_, _, _)) + .WillOnce(Return()); + EXPECT_CALL(*mock_rpc_protection_manager_, + RemoveFromEncryptionNeededCache(_, _)) + .WillOnce(Return()); + EXPECT_CALL(mock_conn_handler, CloseSession(_, _)).WillOnce(Return()); + + message_handler->Handle( + am::rpc_service::impl::MessageToMobile(message_to_send, true)); +} + +TEST_F(RPCServiceImplTest, SendMessageToMobile_HappyPath) { + using namespace application_manager::plugin_manager::plugin_names; + namespace jhs = ns_smart_device_link::ns_json_handler::strings; + auto func_id = mobile_apis::FunctionID::OnSystemRequestID; + auto source = am::commands::Command::CommandSource::SOURCE_SDL; + + auto message = CreateMessage(smart_objects::SmartType_Map); + (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*message)[am::strings::params][am::strings::function_id] = func_id; + (*message)[am::strings::msg_params][am::strings::request_type] = + mobile_apis::RequestType::PROPRIETARY; + (*message)[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::SUCCESS; + + (*message)[jhs::S_PARAMS][jhs::S_FUNCTION_ID] = func_id; + (*message)[jhs::S_PARAMS][jhs::S_MESSAGE_TYPE] = + mobile_apis::messageType::request; + (*message)[jhs::S_PARAMS][jhs::S_PROTOCOL_TYPE] = kMobileProtocolType; + (*message)[jhs::S_PARAMS][jhs::S_PROTOCOL_VERSION] = kProtocolVersion; + + mock_app_ptr_ = std::make_shared<NiceMock<MockApplication> >(); + ON_CALL(mock_app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_ptr_)); + ON_CALL(*mock_app_ptr_, protocol_version()) + .WillByDefault( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_1)); + + EXPECT_CALL(mock_app_mngr_, GetAppServiceManager()) + .WillRepeatedly(ReturnRef(mock_app_service_nmgr_)); + auto rpc_pass_handler = std::make_shared<am::RPCPassingHandler>( + mock_app_service_nmgr_, mock_app_mngr_); + EXPECT_CALL(mock_app_service_nmgr_, GetRPCPassingHandler()) + .WillRepeatedly(ReturnRef(*rpc_pass_handler)); + EXPECT_CALL(mock_app_service_nmgr_, GetActiveServices()) + .WillRepeatedly(Return(std::vector<am::AppService>())); + + ON_CALL(mock_app_mngr_, GetPluginManager()) + .WillByDefault(ReturnRef(mock_rpc_plugin_manager_)); + PluginOpt mock_rpc_plugin_opt(mock_rpc_plugin_); + ON_CALL(mock_rpc_plugin_manager_, FindPluginToProcess(func_id, source)) + .WillByDefault(Return(mock_rpc_plugin_opt)); + ON_CALL(mock_rpc_plugin_, PluginName()) + .WillByDefault(Return(app_service_rpc_plugin)); + ON_CALL(mock_rpc_plugin_, GetCommandFactory()) + .WillByDefault(ReturnRef(mock_command_factory_)); + ON_CALL(mock_command_factory_, IsAbleToProcess(func_id, source)) + .WillByDefault(Return(true)); + + auto window_id = 0; + ON_CALL(mock_message_helper_, ExtractWindowIdFromSmartObject(_)) + .WillByDefault(Return(window_id)); + ON_CALL(mock_message_helper_, StringifiedFunctionID(func_id)) + .WillByDefault(Return("OnSystemRequest")); + EXPECT_CALL(mock_app_mngr_, + CheckPolicyPermissions(_, window_id, "OnSystemRequest", _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + policy_test::MockPolicyHandlerInterface mock_policy_handler; + EXPECT_CALL(mock_app_mngr_, GetPolicyHandler()) + .WillOnce(ReturnRef(mock_policy_handler)); + EXPECT_CALL(mock_policy_handler, OnUpdateRequestSentToMobile()); + + rpc_service_->SendMessageToMobile(message); +} + +TEST_F(RPCServiceImplTest, + SendMessageToMobile_PolicyPermissionsFailed_ExecutionAborted) { + using namespace application_manager::plugin_manager::plugin_names; + + namespace jhs = ns_smart_device_link::ns_json_handler::strings; + auto func_id = mobile_apis::FunctionID::OnSystemRequestID; + auto source = am::commands::Command::CommandSource::SOURCE_SDL; + + auto message = CreateMessage(smart_objects::SmartType_Map); + (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*message)[am::strings::params][am::strings::function_id] = func_id; + (*message)[am::strings::msg_params][am::strings::request_type] = + mobile_apis::RequestType::PROPRIETARY; + (*message)[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::SUCCESS; + + (*message)[jhs::S_PARAMS][jhs::S_FUNCTION_ID] = func_id; + (*message)[jhs::S_PARAMS][jhs::S_MESSAGE_TYPE] = + mobile_apis::messageType::request; + (*message)[jhs::S_PARAMS][jhs::S_PROTOCOL_TYPE] = kMobileProtocolType; + (*message)[jhs::S_PARAMS][jhs::S_PROTOCOL_VERSION] = kProtocolVersion; + + mock_app_ptr_ = std::make_shared<NiceMock<MockApplication> >(); + ON_CALL(mock_app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_ptr_)); + ON_CALL(*mock_app_ptr_, protocol_version()) + .WillByDefault( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_1)); + + EXPECT_CALL(mock_app_mngr_, GetAppServiceManager()) + .WillRepeatedly(ReturnRef(mock_app_service_nmgr_)); + auto rpc_pass_handler = std::make_shared<am::RPCPassingHandler>( + mock_app_service_nmgr_, mock_app_mngr_); + EXPECT_CALL(mock_app_service_nmgr_, GetRPCPassingHandler()) + .WillRepeatedly(ReturnRef(*rpc_pass_handler)); + EXPECT_CALL(mock_app_service_nmgr_, GetActiveServices()) + .WillRepeatedly(Return(std::vector<am::AppService>())); + + ON_CALL(mock_app_mngr_, GetPluginManager()) + .WillByDefault(ReturnRef(mock_rpc_plugin_manager_)); + PluginOpt mock_rpc_plugin_opt(mock_rpc_plugin_); + ON_CALL(mock_rpc_plugin_manager_, FindPluginToProcess(func_id, source)) + .WillByDefault(Return(mock_rpc_plugin_opt)); + ON_CALL(mock_rpc_plugin_, PluginName()) + .WillByDefault(Return(app_service_rpc_plugin)); + ON_CALL(mock_rpc_plugin_, GetCommandFactory()) + .WillByDefault(ReturnRef(mock_command_factory_)); + ON_CALL(mock_command_factory_, IsAbleToProcess(func_id, source)) + .WillByDefault(Return(true)); + + auto window_id = -1; // Assume that this ID is invalid; + ON_CALL(mock_message_helper_, ExtractWindowIdFromSmartObject(_)) + .WillByDefault(Return(window_id)); + ON_CALL(mock_message_helper_, StringifiedFunctionID(func_id)) + .WillByDefault(Return("OnSystemRequest")); + EXPECT_CALL(mock_app_mngr_, + CheckPolicyPermissions(_, window_id, "OnSystemRequest", _, _)) + .WillOnce(Return(mobile_apis::Result::INVALID_ENUM)); + + policy_test::MockPolicyHandlerInterface mock_policy_handler; + EXPECT_CALL(mock_app_mngr_, GetPolicyHandler()).Times(0); + EXPECT_CALL(mock_policy_handler, OnUpdateRequestSentToMobile()).Times(0); + + rpc_service_->SendMessageToMobile(message); +} +} // namespace application_manager_test + +} // namespace components + +} // namespace test |