diff options
Diffstat (limited to 'src/components/application_manager')
192 files changed, 7453 insertions, 2083 deletions
diff --git a/src/components/application_manager/CMakeLists.txt b/src/components/application_manager/CMakeLists.txt index 7a49ce6b81..e9f2f8ec7b 100644 --- a/src/components/application_manager/CMakeLists.txt +++ b/src/components/application_manager/CMakeLists.txt @@ -324,6 +324,7 @@ set (HMI_COMMANDS_SOURCES ${COMMANDS_SOURCE_DIR}/hmi/on_system_error_notification.cc ${COMMANDS_SOURCE_DIR}/hmi/basic_communication_system_request.cc ${COMMANDS_SOURCE_DIR}/hmi/basic_communication_system_response.cc + ${COMMANDS_SOURCE_DIR}/hmi/basic_communication_on_awake_sdl.cc ${COMMANDS_SOURCE_DIR}/hmi/sdl_policy_update.cc ${COMMANDS_SOURCE_DIR}/hmi/sdl_policy_update_response.cc ${COMMANDS_SOURCE_DIR}/hmi/on_received_policy_update.cc @@ -344,9 +345,6 @@ set (HMI_COMMANDS_SOURCES ${COMMANDS_SOURCE_DIR}/hmi/rc_get_capabilities_response.cc ${COMMANDS_SOURCE_DIR}/hmi/ui_send_haptic_data_request.cc ${COMMANDS_SOURCE_DIR}/hmi/ui_send_haptic_data_response.cc -) - -set (HMI_COMMANDS_SOURCES_JSON ${COMMANDS_SOURCE_DIR}/hmi/vi_get_vehicle_data_request.cc ${COMMANDS_SOURCE_DIR}/hmi/vi_get_vehicle_data_response.cc ${COMMANDS_SOURCE_DIR}/hmi/vi_subscribe_vehicle_data_request.cc @@ -356,6 +354,9 @@ set (HMI_COMMANDS_SOURCES_JSON ${COMMANDS_SOURCE_DIR}/hmi/on_vi_vehicle_data_notification.cc ) +set (HMI_COMMANDS_SOURCES_JSON +) + set (HMI_COMMANDS_SOURCES_DBUS ${COMMANDS_SOURCE_DIR}/hmi/on_vi_gps_data_notification.cc ${COMMANDS_SOURCE_DIR}/hmi/on_vi_speed_notification.cc diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index 3a03cb5343..fa6f18e9c2 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -46,8 +46,10 @@ #include "application_manager/message.h" #include "application_manager/hmi_state.h" #include "application_manager/application_state.h" +#include "application_manager/help_prompt_manager.h" #include "protocol_handler/protocol_handler.h" #include "smart_objects/smart_object.h" +#include "utils/macro.h" namespace application_manager { @@ -161,13 +163,18 @@ typedef std::set<uint32_t> SoftButtonID; /** * @brief Defines set of vehicle info types */ -typedef std::set<uint32_t> VehicleInfoSubscriptions; +typedef std::set<mobile_apis::VehicleDataType::eType> VehicleInfoSubscriptions; /** * @brief Defines set of buttons subscription */ typedef std::set<mobile_apis::ButtonName::eType> ButtonSubscriptions; +/** + * @breif Collection for the mobile command smart object. + */ +typedef std::vector<smart_objects::SmartObjectSPtr> MobileMessageQueue; + class DynamicApplicationData { public: virtual ~DynamicApplicationData() {} @@ -409,6 +416,20 @@ class Application : public virtual InitialApplicationData, virtual void UpdateHash() = 0; /** + * @brief checks is hashID was changed during suspended state + * @return Returns TRUE if hashID was changed during suspended state + * otherwise returns FALSE. + */ + virtual bool IsHashChangedDuringSuspend() const = 0; + + /** + * @brief changes state of the flag which tracks is hashID was changed during + * suspended state or not + * @param state new state of the flag + */ + virtual void SetHashChangedDuringSuspend(const bool state) = 0; + + /** * @brief method is called when SDL is saving application data for resumption * @return TRUE if data of application need to save for resumption, otherwise * return FALSE @@ -547,7 +568,8 @@ class Application : public virtual InitialApplicationData, virtual void increment_list_files_in_none_count() = 0; virtual bool set_app_icon_path(const std::string& file_name) = 0; virtual void set_app_allowed(const bool allowed) = 0; - virtual void set_device(connection_handler::DeviceHandle device) = 0; + DEPRECATED virtual void set_device( + connection_handler::DeviceHandle device) = 0; virtual uint32_t get_grammar_id() const = 0; virtual void set_grammar_id(uint32_t value) = 0; @@ -602,6 +624,18 @@ class Application : public virtual InitialApplicationData, * @return object for recording statistics */ virtual UsageStatistics& usage_report() = 0; + /** + * @brief Access to HelpPromptManager interface + * @return object for Handling VR help + */ + virtual HelpPromptManager& help_prompt_manager() = 0; + + /** + * @brief SetInitialState sets initial HMI state for application on + * registration + * @param state Hmi state value + */ + virtual void SetInitialState(HmiStatePtr state) = 0; /** * @brief SetRegularState set permanent state of application @@ -693,6 +727,16 @@ class Application : public virtual InitialApplicationData, virtual bool IsAudioApplication() const = 0; /** + * DEPRECATED + * @brief GetDeviceId allows to obtain device id which posseses + * by this application. + * @return device the device id. + */ + std::string GetDeviceId() const { + return device_id_; + } + + /** * @brief IsRegistered allows to distinguish if this * application has been registered. * @@ -750,16 +794,6 @@ class Application : public virtual InitialApplicationData, } /** - * @brief GetDeviceId allows to obtain device id which posseses - * by this application. - * - * @return device the device id. - */ - std::string GetDeviceId() const { - return device_id_; - } - - /** * @brief Returns is application should be greyed out on HMI */ bool is_greyed_out() const { @@ -786,6 +820,21 @@ class Application : public virtual InitialApplicationData, */ virtual uint32_t GetAvailableDiskSpace() = 0; + /** + * @brief Allows to save mobile's command smart object in order to perform + * this command later. + * @param mobile_message the message smart_object. + */ + virtual void PushMobileMessage( + smart_objects::SmartObjectSPtr mobile_message) = 0; + + /** + * @brief Allows to obtain the whole list of pending commands in order to + * process them. + * @param mobile_message the messages array which is filled by the method. + */ + virtual void SwapMobileMessageQueue(MobileMessageQueue& mobile_messages) = 0; + #ifdef SDL_REMOTE_CONTROL /** * @brief set_system_context Set system context for application @@ -837,7 +886,7 @@ class Application : public virtual InitialApplicationData, * @brief Get list of subscriptions to vehicle info notifications * @return list of subscriptions to vehicle info notifications */ - virtual const std::set<uint32_t>& SubscribesIVI() const = 0; + virtual const VehicleInfoSubscriptions& SubscribesIVI() const = 0; #endif // SDL_REMOTE_CONTROL protected: diff --git a/src/components/application_manager/include/application_manager/application_impl.h b/src/components/application_manager/include/application_manager/application_impl.h index dc2d8ce528..2a7ea112d4 100644 --- a/src/components/application_manager/include/application_manager/application_impl.h +++ b/src/components/application_manager/include/application_manager/application_impl.h @@ -44,6 +44,7 @@ #include "utils/date_time.h" #include "application_manager/application_data_impl.h" #include "application_manager/usage_statistics.h" +#include "application_manager/help_prompt_manager_impl.h" #include "application_manager/hmi_state.h" #include "protocol_handler/protocol_handler.h" @@ -52,6 +53,7 @@ #include "utils/atomic_object.h" #include "utils/custom_string.h" #include "utils/timer.h" +#include "utils/macro.h" namespace usage_statistics { @@ -65,6 +67,19 @@ using namespace timer; namespace mobile_api = mobile_apis; namespace custom_str = custom_string; +/** + * @brief SwitchApplicationParameters updates application internal parameters + * on transport switch. Must be used only for switching flow. + * @param app Pointer to switched application + * @param app_id New application id (connection key) + * @param device_id New device id + * @param mac_address New device MAC address + */ +void SwitchApplicationParameters(ApplicationSharedPtr app, + const uint32_t app_id, + const size_t device_id, + const std::string& mac_address); + class ApplicationImpl : public virtual Application, public virtual InitialApplicationDataImpl, public virtual DynamicApplicationDataImpl { @@ -73,6 +88,15 @@ class ApplicationImpl : public virtual Application, uint32_t application_id, const std::string& policy_app_id, const std::string& mac_address, + const connection_handler::DeviceHandle device_id, + const custom_str::CustomString& app_name, + utils::SharedPtr<usage_statistics::StatisticsManager> statistics_manager, + ApplicationManager& application_manager); + + DEPRECATED ApplicationImpl( + uint32_t application_id, + const std::string& policy_app_id, + const std::string& mac_address, const custom_str::CustomString& app_name, utils::SharedPtr<usage_statistics::StatisticsManager> statistics_manager, ApplicationManager& application_manager); @@ -198,18 +222,34 @@ class ApplicationImpl : public virtual Application, virtual DataAccessor<ButtonSubscriptions> SubscribedButtons() const OVERRIDE; virtual const std::string& curHash() const; -#ifdef CUSTOMER_PASA - virtual bool flag_sending_hash_change_after_awake() const; - virtual void set_flag_sending_hash_change_after_awake(bool flag); -#endif // CUSTOMER_PASA - /** - * @brief Change Hash for current application - * and send notification to mobile - * @return updated_hash - */ + + /** + * @brief Change Hash for current application + * and send notification to mobile + * @return updated_hash + */ virtual void UpdateHash(); + /** + * @brief checks is hashID was changed during suspended state + * @return Returns TRUE if hashID was changed during suspended state + * otherwise returns FALSE. + */ + bool IsHashChangedDuringSuspend() const OVERRIDE; + + /** + * @brief changes state of the flag which tracks is hashID was changed during + * suspended state or not + * @param state new state of the flag + */ + void SetHashChangedDuringSuspend(const bool state) OVERRIDE; + UsageStatistics& usage_report(); + /** + * @brief Access to HelpPromptManager interface + * @return object for Handling VR help + */ + HelpPromptManager& help_prompt_manager() OVERRIDE; bool AreCommandLimitsExceeded(mobile_apis::FunctionID::eType cmd_id, TLimitSource source); @@ -232,6 +272,13 @@ class ApplicationImpl : public virtual Application, virtual bool IsAudioApplication() const; /** + * @brief SetInitialState sets initial HMI state for application on + * registration + * @param state Hmi state value + */ + void SetInitialState(HmiStatePtr state) FINAL; + + /** * @brief SetRegularState set permanent state of application * * @param state state to setup @@ -331,7 +378,7 @@ class ApplicationImpl : public virtual Application, * @brief Get list of subscriptions to vehicle info notifications * @return list of subscriptions to vehicle info notifications */ - const std::set<uint32_t>& SubscribesIVI() const OVERRIDE; + const VehicleInfoSubscriptions& SubscribesIVI() const OVERRIDE; /** * @brief Return pointer to extension by uid @@ -341,6 +388,11 @@ class ApplicationImpl : public virtual Application, AppExtensionPtr QueryInterface(AppExtensionUID uid) OVERRIDE; #endif + void PushMobileMessage( + smart_objects::SmartObjectSPtr mobile_message) OVERRIDE; + + void SwapMobileMessageQueue(MobileMessageQueue& mobile_messages) OVERRIDE; + protected: /** * @brief Clean up application folder. Persistent files will stay @@ -422,16 +474,18 @@ class ApplicationImpl : public virtual Application, uint32_t delete_file_in_none_count_; uint32_t list_files_in_none_count_; std::string app_icon_path_; - connection_handler::DeviceHandle device_; - const std::string mac_address_; + std::string mac_address_; + connection_handler::DeviceHandle device_id_; std::string bundle_id_; AppFilesMap app_files_; std::set<mobile_apis::ButtonName::eType> subscribed_buttons_; VehicleInfoSubscriptions subscribed_vehicle_info_; UsageStatistics usage_report_; + HelpPromptManagerImpl help_prompt_manager_impl_; protocol_handler::MajorProtocolVersion protocol_version_; bool is_voice_communication_application_; sync_primitives::atomic_bool is_resuming_; + bool is_hash_changed_during_suspend_; uint32_t video_stream_retry_number_; uint32_t audio_stream_retry_number_; @@ -467,6 +521,15 @@ class ApplicationImpl : public virtual Application, sync_primitives::Lock button_lock_; std::string folder_name_; ApplicationManager& application_manager_; + + sync_primitives::Lock mobile_message_lock_; + MobileMessageQueue mobile_message_queue_; + + friend void SwitchApplicationParameters(ApplicationSharedPtr app, + const uint32_t app_id, + const size_t device_id, + const std::string& mac_address); + DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); }; 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 7a26501afc..286ad87018 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 @@ -48,12 +48,12 @@ #include "application_manager/message_helper.h" #include "application_manager/request_controller.h" #include "application_manager/resumption/resume_ctrl.h" -#include "application_manager/vehicle_info_data.h" #include "application_manager/state_controller_impl.h" #include "application_manager/app_launch/app_launch_data.h" #include "application_manager/application_manager_settings.h" #include "application_manager/event_engine/event_dispatcher_impl.h" #include "application_manager/hmi_interfaces_impl.h" +#include "application_manager/command_holder.h" #include "protocol_handler/protocol_observer.h" #include "protocol_handler/protocol_handler.h" @@ -311,6 +311,7 @@ class ApplicationManagerImpl bool IsAppTypeExistsInFullOrLimited(ApplicationConstSharedPtr app) const; /** + * DEPRECATED * @brief Checks if Application is subscribed for way points * @param Application AppID * @return true if Application is subscribed for way points @@ -319,18 +320,40 @@ class ApplicationManagerImpl bool IsAppSubscribedForWayPoints(const uint32_t app_id) const OVERRIDE; /** + * DEPRECATED * @brief Subscribe Application for way points * @param Application AppID */ void SubscribeAppForWayPoints(const uint32_t app_id) OVERRIDE; /** + * DEPRECATED * @brief Unsubscribe Application for way points * @param Application AppID */ void UnsubscribeAppFromWayPoints(const uint32_t app_id) 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; + + /** + * @brief Subscribe Application for way points + * @param Application pointer + */ + void SubscribeAppForWayPoints(ApplicationSharedPtr app) OVERRIDE; + + /** + * @brief Unsubscribe Application for way points + * @param Application pointer + */ + void UnsubscribeAppFromWayPoints(ApplicationSharedPtr app) OVERRIDE; + + /** * @brief Is Any Application is subscribed for way points * @return true if some app is subscribed otherwise false */ @@ -349,11 +372,18 @@ class ApplicationManagerImpl * @param vehicle_info Enum value of type of vehicle data * @param new value (for integer values currently) of vehicle data */ - std::vector<ApplicationSharedPtr> IviInfoUpdated(VehicleDataType vehicle_info, - int value) OVERRIDE; + std::vector<ApplicationSharedPtr> IviInfoUpdated( + mobile_apis::VehicleDataType::eType vehicle_info, int value) OVERRIDE; void OnApplicationRegistered(ApplicationSharedPtr app) OVERRIDE; + /** + * @brief OnApplicationSwitched starts processing of commands collected + * during device switching process + * @param app Application + */ + void OnApplicationSwitched(ApplicationSharedPtr app) OVERRIDE; + HMICapabilities& hmi_capabilities() OVERRIDE; const HMICapabilities& hmi_capabilities() const OVERRIDE; @@ -423,8 +453,9 @@ class ApplicationManagerImpl */ void UnregisterAllApplications(); - bool RemoveAppDataFromHMI(ApplicationSharedPtr app); - bool LoadAppDataToHMI(ApplicationSharedPtr app); + DEPRECATED bool RemoveAppDataFromHMI(ApplicationSharedPtr app); + + DEPRECATED bool LoadAppDataToHMI(ApplicationSharedPtr app); bool ActivateApplication(ApplicationSharedPtr app) OVERRIDE; /** @@ -447,33 +478,53 @@ class ApplicationManagerImpl uint32_t GetNextHMICorrelationID() OVERRIDE; /* @brief Starts audio passthru process + * @deprecated Use BeginAudioPassThru(uint32_t app_id) instead * * @return true on success, false if passthru is already in process */ bool BeginAudioPassThrough() OVERRIDE; + /** + * @brief Starts AudioPassThru process by given application + * @param app_id ID of the application which starts the process + * @return true if AudioPassThru can be started, false otherwise + */ + bool BeginAudioPassThru(uint32_t app_id) OVERRIDE; + /* * @brief Finishes already started audio passthru process + * @deprecated Use EndAudioPassThru(uint32_t app_id) instead * * @return true on success, false if passthru is not active */ bool EndAudioPassThrough() OVERRIDE; + /** + * @brief Finishes already started AudioPassThru process by given application + * @param app_id ID of the application which started the process + * @return true if AudioPassThru process has been started with given + * application and thus it can be stopped, false otherwise + */ + bool EndAudioPassThru(uint32_t app_id) OVERRIDE; + /* * @brief Retrieves driver distraction state * * @return Current state of the distraction state */ - inline bool driver_distraction() const; + hmi_apis::Common_DriverDistractionState::eType driver_distraction_state() + const; /* * @brief Sets state for driver distraction * * @param state New state to be set */ - void set_driver_distraction(const bool is_distracting) OVERRIDE; + void set_driver_distraction_state( + const hmi_apis::Common_DriverDistractionState::eType state) OVERRIDE; /* + * DEPRECATED * @brief Retrieves if VR session has started * * @return Current VR session state (started, stopped) @@ -481,6 +532,7 @@ class ApplicationManagerImpl inline bool vr_session_started() const; /* + * DEPRECATED * @brief Sets VR session state * * @param state Current HMI VR session state @@ -503,13 +555,28 @@ class ApplicationManagerImpl /** * @brief CreateRegularState create regular HMI state for application - * @param app_id + * @param app Application * @param hmi_level of returned state * @param audio_state of returned state * @param system_context of returned state * @return new regular HMI state */ HmiStatePtr CreateRegularState( + utils::SharedPtr<Application> app, + mobile_apis::HMILevel::eType hmi_level, + mobile_apis::AudioStreamingState::eType audio_state, + mobile_apis::SystemContext::eType system_context) const OVERRIDE; + + /** + * DEPRECATED + * @brief CreateRegularState create regular HMI state for application + * @param app_id Application id + * @param hmi_level of returned state + * @param audio_state of returned state + * @param system_context of returned state + * @return new regular HMI state + */ + DEPRECATED HmiStatePtr CreateRegularState( uint32_t app_id, mobile_apis::HMILevel::eType hmi_level, mobile_apis::AudioStreamingState::eType audio_state, @@ -838,8 +905,27 @@ class ApplicationManagerImpl void OnFindNewApplicationsRequest() OVERRIDE; void RemoveDevice( const connection_handler::DeviceHandle& device_handle) OVERRIDE; - // DEPRECATED - bool OnServiceStartedCallback( + + /** + * @brief OnDeviceSwitchingStart is invoked on device transport switching + * start (e.g. from Bluetooth to USB) and creates waiting list of applications + * expected to be re-registered after switching is complete + * @param device_from device params being switched to the new transport + * @param device_to device params on the new transport + */ + void OnDeviceSwitchingStart( + const connection_handler::Device& device_from, + const connection_handler::Device& device_to) FINAL; + + /** + * @brief OnDeviceSwitchingFinish is invoked on device trasport switching end + * i.e. timeout for switching is expired, unregisters applications from + * waiting list which haven't been re-registered and clears the waiting list + * @param device_uid UID of device being switched + */ + void OnDeviceSwitchingFinish(const std::string& device_uid) FINAL; + + DEPRECATED bool OnServiceStartedCallback( const connection_handler::DeviceHandle& device_handle, const int32_t& session_key, const protocol_handler::ServiceType& type) OVERRIDE; @@ -853,14 +939,42 @@ class ApplicationManagerImpl const protocol_handler::ServiceType& type, const connection_handler::CloseSessionReason& close_reason) OVERRIDE; + /** + * @brief Check if application with specified app_id has NAVIGATION HMI type + * @param app_id id of application to check + * @return true if application is navi otherwise returns false + */ + bool CheckAppIsNavi(const uint32_t app_id) const OVERRIDE; + #ifdef ENABLE_SECURITY - // Overriden SecurityManagerListener method + /** + * @brief Notification about protection result + * @param connection_key Unique key of session which triggers handshake + * @param result result of connection protection + * @return true on success notification handling or false otherwise + */ bool OnHandshakeDone( uint32_t connection_key, security_manager::SSLContext::HandshakeResult result) OVERRIDE; + /** + * @brief Notification that certificate update is required. + */ void OnCertificateUpdateRequired() OVERRIDE; + /** + * @brief Get certificate data from policy + * @param reference to string where to save certificate data + * @return true if listener saved some data to string otherwise false + */ + bool GetPolicyCertificateData(std::string& data) const OVERRIDE; + + /** + * @brief Get unique handshake context by application id + * @param key id of application + * @return generated handshake context or empty context if application with + * provided id does not exist + */ security_manager::SSLContext::HandshakeContext GetHandshakeContext( uint32_t key) const OVERRIDE; #endif // ENABLE_SECURITY @@ -991,15 +1105,15 @@ class ApplicationManagerImpl uint32_t GenerateNewHMIAppID() OVERRIDE; /** + * DERPECATED * @brief Parse smartObject and replace mobile app Id by HMI app ID - * * @param message Smartobject to be parsed */ void ReplaceMobileByHMIAppId(smart_objects::SmartObject& message); /** + * DEPRECATED * @brief Parse smartObject and replace HMI app ID by mobile app Id - * * @param message Smartobject to be parsed */ void ReplaceHMIByMobileAppId(smart_objects::SmartObject& message); @@ -1056,6 +1170,7 @@ class ApplicationManagerImpl void RemoveAppFromTTSGlobalPropertiesList(const uint32_t app_id) OVERRIDE; /** + * DEPRECATED * @brief method adds application in FULL and LIMITED state * to on_phone_call_app_list_. * Also OnHMIStateNotification with BACKGROUND state sent for these apps @@ -1063,6 +1178,7 @@ class ApplicationManagerImpl void CreatePhoneCallAppList(); /** + * DEPRECATED * @brief method removes application from on_phone_call_app_list_. * * Also OnHMIStateNotification with previous HMI state sent for these apps @@ -1169,15 +1285,6 @@ class ApplicationManagerImpl } }; - struct SubscribedToIVIPredicate { - int32_t vehicle_info_; - SubscribedToIVIPredicate(int32_t vehicle_info) - : vehicle_info_(vehicle_info) {} - bool operator()(const ApplicationSharedPtr app) const { - return app ? app->IsSubscribedToIVI(vehicle_info_) : false; - } - }; - struct GrammarIdPredicate { uint32_t grammar_id_; GrammarIdPredicate(uint32_t grammar_id) : grammar_id_(grammar_id) {} @@ -1214,11 +1321,32 @@ class ApplicationManagerImpl bool IsAppsQueriedFrom( const connection_handler::DeviceHandle handle) const OVERRIDE; + /** + * @brief IsAppInReconnectMode check if application belongs to session + * affected by transport switching at the moment by checking internal + * waiting list prepared on switching start + * @param policy_app_id Application id + * @return True if application is in the waiting list, otherwise - false + */ + bool IsAppInReconnectMode(const std::string& policy_app_id) const FINAL; + bool IsStopping() const OVERRIDE { return is_stopping_; } /** + * @brief ProcessReconnection handles reconnection flow for application on + * transport switch + * @param application Pointer to switched application, must be validated + * before passing + * @param connection_key Connection key from registration request of + * switched + * application + */ + void ProcessReconnection(ApplicationSharedPtr application, + const uint32_t connection_key) FINAL; + + /** * @brief Clears all applications' persistent data */ void ClearAppsPersistentData(); @@ -1354,6 +1482,32 @@ class ApplicationManagerImpl */ bool IsLowVoltage(); + /** + * @brief Allows to process postponed commands for application + * when its HMI level has been changed. + * @param app_id the application id for processing. + * @param from the old HMILevel. + * @param to the new HMILevel for the certain app. + */ + void ProcessPostponedMessages(const uint32_t app_id); + + /** + * @brief Allows to process applications after HMILevel has been changed. + * @param app_id the application id for processing. + * @param from the old HMILevel. + * @param to the new HMILevel for the certain app. + */ + void ProcessApp(const uint32_t app_id, + const mobile_apis::HMILevel::eType from, + const mobile_apis::HMILevel::eType to); + + /** + * @brief Allows to send appropriate message to mobile device. + * @param message The smart object which contains all neccesary info to send + * notification. + */ + void SendMobileMessage(smart_objects::SmartObjectSPtr message); + private: /* * NaviServiceStatusMap shows which navi service (audio/video) is opened @@ -1402,9 +1556,8 @@ class ApplicationManagerImpl * @param service_type Type of service to start * @return True on success, false on fail */ - // DEPRECATED - bool StartNaviService(uint32_t app_id, - protocol_handler::ServiceType service_type); + DEPRECATED bool StartNaviService(uint32_t app_id, + protocol_handler::ServiceType service_type); /** * @brief Starts specified navi service for application @@ -1447,6 +1600,14 @@ class ApplicationManagerImpl protocol_handler::MajorProtocolVersion SupportedSDLVersion() const; /** + * @brief Checks if driver distraction state is valid, creates message + * and puts it to postponed message. + * @param application contains registered application. + */ + void PutDriverDistractionMessageToPostponed( + ApplicationSharedPtr application) const; + + /** * @brief Types of directories used by Application Manager */ enum DirectoryType { TYPE_STORAGE, TYPE_SYSTEM, TYPE_ICONS }; @@ -1488,6 +1649,28 @@ class ApplicationManagerImpl void ClearTTSGlobalPropertiesList(); /** + * @brief EraseAppFromReconnectionList drops application from reconnection + * list on transport switch success + * @param app Pointer to application + */ + void EraseAppFromReconnectionList(const ApplicationSharedPtr& app); + + /** + * @brief SwitchApplication updates parameters of switched application and + * internal applications list + * @param app Pointer to switched application, must be validated before + * passing in + * @param connection_key Connection key of switched application from its + * registration request + * @param device_id Device id of switched application + * @param mac_address New device mac address + */ + void SwitchApplication(ApplicationSharedPtr app, + const uint32_t connection_key, + const size_t device_id, + const std::string& mac_address); + + /** * @brief Converts BSON object containing video parameters to * smart object's map object * @param output the smart object to add video parameters @@ -1536,9 +1719,10 @@ class ApplicationManagerImpl std::map<uint32_t, TimevalStruct> tts_global_properties_app_list_; bool audio_pass_thru_active_; + uint32_t audio_pass_thru_app_id_; sync_primitives::Lock audio_pass_thru_lock_; sync_primitives::Lock tts_global_properties_app_list_lock_; - bool is_distracting_driver_; + hmi_apis::Common_DriverDistractionState::eType driver_distraction_state_; bool is_vr_session_strated_; bool hmi_cooperating_; bool is_all_apps_allowed_; @@ -1620,6 +1804,15 @@ class ApplicationManagerImpl std::auto_ptr<app_launch::AppLaunchData> app_launch_dto_; std::auto_ptr<app_launch::AppLaunchCtrl> app_launch_ctrl_; + /** + * @brief ReregisterWaitList is list of applications expected to be + * re-registered after transport switching is complete + */ + typedef std::vector<ApplicationSharedPtr> ReregisterWaitList; + ReregisterWaitList reregister_wait_list_; + + mutable sync_primitives::Lock reregister_wait_list_lock_; + #ifdef TELEMETRY_MONITOR AMTelemetryObserver* metric_observer_; #endif // TELEMETRY_MONITOR @@ -1634,6 +1827,8 @@ class ApplicationManagerImpl volatile bool is_stopping_; + std::unique_ptr<CommandHolder> commands_holder_; + #ifdef BUILD_TESTS public: /** @@ -1643,20 +1838,23 @@ class ApplicationManagerImpl */ void AddMockApplication(ApplicationSharedPtr mock_app); + /** + * @brief set a mock media manager without running Init(). Only for unit + * testing. + * @param mock_app the mock app to be registered + */ + void SetMockMediaManager(media_manager::MediaManager* mock_media_manager); + private: #endif DISALLOW_COPY_AND_ASSIGN(ApplicationManagerImpl); }; -bool ApplicationManagerImpl::vr_session_started() const { +DEPRECATED bool ApplicationManagerImpl::vr_session_started() const { return is_vr_session_strated_; } -bool ApplicationManagerImpl::driver_distraction() const { - return is_distracting_driver_; -} - inline bool ApplicationManagerImpl::all_apps_allowed() const { return is_all_apps_allowed_; } diff --git a/src/components/application_manager/include/application_manager/command_holder.h b/src/components/application_manager/include/application_manager/command_holder.h new file mode 100644 index 0000000000..d3171aedbb --- /dev/null +++ b/src/components/application_manager/include/application_manager/command_holder.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2017, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMAND_HOLDER_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMAND_HOLDER_H_ + +#include <string> +#include "application_manager/application.h" +#include "smart_objects/smart_object.h" +#include "utils/shared_ptr.h" + +namespace application_manager { +/** + * @brief The CommandHolder class should hold commands for particular + * application until certain event happens + */ +class CommandHolder { + public: + /** + * @brief The CommandType enum defines type of command to suspend or resume + */ + enum class CommandType { kHmiCommand, kMobileCommand }; + + /** + * @brief ~CommandsHolder destructor + */ + virtual ~CommandHolder() {} + + /** + * @brief Suspend collects command for specific application policy id + * internally + * @param application Application pointer + * @param type Command type + * @param command Command + */ + virtual void Suspend(ApplicationSharedPtr application, + CommandType type, + smart_objects::SmartObjectSPtr command) = 0; + + /** + * @brief Resume send all collected commands for further processing and + * removes them afterward + * @param application Application pointer + * @param type Command type + */ + virtual void Resume(ApplicationSharedPtr application, CommandType type) = 0; + + /** + * @brief Clear removes all collected commands w/o processing + * @param application Application pointer + */ + virtual void Clear(ApplicationSharedPtr application) = 0; +}; +} // namespace application_manager + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMAND_HOLDER_H_ diff --git a/src/components/application_manager/include/application_manager/command_holder_impl.h b/src/components/application_manager/include/application_manager/command_holder_impl.h new file mode 100644 index 0000000000..ed5f6baa62 --- /dev/null +++ b/src/components/application_manager/include/application_manager/command_holder_impl.h @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2017, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMAND_HOLDER_IMPL_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMAND_HOLDER_IMPL_H_ + +#include "application_manager/command_holder.h" + +#include <string> +#include <vector> +#include <map> +#include "application_manager/application.h" +#include "smart_objects/smart_object.h" +#include "utils/lock.h" +#include "utils/shared_ptr.h" +#include "utils/macro.h" + +namespace application_manager { +class ApplicationManager; +/** + * @brief The CommandHolderImpl class should hold commands for particular + * application during application transport switching process and sends for + * processing after switching is completed successfully or drops otherwise + */ +class CommandHolderImpl : public CommandHolder { + public: + /** + * @brief CommandHolderImpl constructor + */ + + explicit CommandHolderImpl(ApplicationManager& app_manager); + + /** + * @brief Suspend collects command for specific application id internally + * @param application Application pointer + * @param type Command type + * @param command Command + */ + void Suspend(ApplicationSharedPtr application, + CommandType type, + smart_objects::SmartObjectSPtr command) FINAL; + + /** + * @brief Resume sends all collected HMI commands to ApplicationManager + * for further processing + * @param application Application pointer + * @param type Command type + */ + void Resume(ApplicationSharedPtr application, CommandType type) FINAL; + + /** + * @brief Clear removes all commands collected for specific application id + * @param application Application pointer + */ + void Clear(ApplicationSharedPtr application) FINAL; + + private: + /** + * @brief ResumeHmiCommand sends suspended HMI commands for processing + * @param application Application which commands to process + */ + void ResumeHmiCommand(ApplicationSharedPtr app); + + /** + * @brief ResumeMobileCommand sends suspended mobile commands for processing + * @param application Application which commands to process + */ + void ResumeMobileCommand(ApplicationSharedPtr application); + + using AppCommands = + std::map<ApplicationSharedPtr, + std::vector<utils::SharedPtr<smart_objects::SmartObject> > >; + + ApplicationManager& app_manager_; + sync_primitives::Lock commands_lock_; + AppCommands app_mobile_commands_; + AppCommands app_hmi_commands_; +}; +} // namespace application_manager + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMAND_HOLDER_IMPL_H_ 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 66456dfdb1..5fee7500ce 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 @@ -142,16 +142,30 @@ class CommandImpl : public Command { protected: /** - * @brief Parse smartObject and replace mobile app Id by HMI app ID - * - * @param message Smartobject to be parsed + * @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 + */ + bool ReplaceMobileWithHMIAppId(smart_objects::SmartObject& message); + + /** + * DEPRECATED + * @brief Parses mobile message and replaces mobile app id with HMI app id + * @param message Message to replace its ids */ void ReplaceMobileByHMIAppId(smart_objects::SmartObject& message); /** - * @brief Parse smartObject and replace HMI app ID by mobile app Id - * - * @param message Smartobject to be parsed + * @brief Parses message from HMI and replaces HMI app id with mobile app id + * @param message Message to replace its ids + * @return True if replacement succeeded, otherwise - false + */ + bool ReplaceHMIWithMobileAppId(smart_objects::SmartObject& message); + + /** + * DEPRECATED + * @brief Parses message from HMI and replaces HMI app id with mobile app id + * @param message Message to replace its ids */ void ReplaceHMIByMobileAppId(smart_objects::SmartObject& message); 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 aa3c216d4d..74a884a223 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 @@ -43,27 +43,18 @@ namespace application_manager { namespace commands { struct ResponseInfo { - ResponseInfo() - : result_code(hmi_apis::Common_Result::INVALID_ENUM) - , interface(HmiInterfaces::HMI_INTERFACE_INVALID_ENUM) - , interface_state(HmiInterfaces::STATE_NOT_RESPONSE) - , is_ok(false) - , is_unsupported_resource(false) - , is_invalid_enum(false) {} - ResponseInfo(hmi_apis::Common_Result::eType result, - HmiInterfaces::InterfaceID interface) - : result_code(result) - , interface(interface) - , interface_state(HmiInterfaces::STATE_NOT_RESPONSE) - , is_ok(false) - , is_unsupported_resource(false) - , is_invalid_enum(false) {} + DEPRECATED ResponseInfo(hmi_apis::Common_Result::eType result, + HmiInterfaces::InterfaceID interface); + ResponseInfo(); + ResponseInfo(const hmi_apis::Common_Result::eType result, + const HmiInterfaces::InterfaceID hmi_interface, + ApplicationManager& application_manager); hmi_apis::Common_Result::eType result_code; HmiInterfaces::InterfaceID interface; HmiInterfaces::InterfaceState interface_state; bool is_ok; bool is_unsupported_resource; - bool is_invalid_enum; + bool is_not_used; }; namespace NsSmart = NsSmartDeviceLink::NsSmartObjects; @@ -290,6 +281,19 @@ class CommandRequestImpl : public CommandImpl, mobile_apis::Result::eType PrepareResultCodeForResponse( const ResponseInfo& first, const ResponseInfo& second); + /** + * @brief Resolves if the return code must be + * UNSUPPORTED_RESOURCE + * @param first contains result_code from HMI response and + * interface that returns response + * @param second contains result_code from HMI response and + * interface that returns response. + * @return True, if the communication return code must be + * UNSUPPORTED_RESOURCE, otherwise false. + */ + bool IsResultCodeUnsupported(const ResponseInfo& first, + const ResponseInfo& second) const; + protected: /** * @brief Returns policy parameters permissions @@ -297,6 +301,35 @@ class CommandRequestImpl : public CommandImpl, */ const CommandParametersPermissions& parameters_permissions() const; + /** + * @brief Adds interface to be awaited for by sdl request command + @param interface_id interface which SDL expects to response in given time + */ + void StartAwaitForInterface(const HmiInterfaces::InterfaceID interface_id); + + /** + * @brief Gets interface await state. + * @param interface_id interface which SDL awaits for response in given time + * @return true if SDL awaits for response from given interface in + * interface_id + */ + bool IsInterfaceAwaited(const HmiInterfaces::InterfaceID& interface_id) const; + + /** + * @brief Sets given HMI interface await status to false + * @param interface_id interface which SDL no longer awaits for response in + * given time + */ + void EndAwaitForInterface(const HmiInterfaces::InterfaceID& interface_id); + + /** + * @brief This set stores all the interfaces which are awaited by SDL to + * return a response on some request + */ + std::set<HmiInterfaces::InterfaceID> awaiting_response_interfaces_; + + mutable sync_primitives::Lock awaiting_response_interfaces_lock_; + RequestState current_state_; sync_primitives::Lock state_lock_; CommandParametersPermissions parameters_permissions_; @@ -331,10 +364,10 @@ class CommandRequestImpl : public CommandImpl, const hmi_apis::FunctionID::eType& function_id); /** - * @brief UpdateHash updates hash field for application and sends - * OnHashChanged notification to mobile side in case of approriate hash mode - * is set - */ + * @brief UpdateHash updates hash field for application and sends + * OnHashChanged notification to mobile side in case of approriate hash mode + * is set + */ void UpdateHash(); /** @@ -342,6 +375,13 @@ class CommandRequestImpl : public CommandImpl, * it is value of 'success' field of appropriate response sent to mobile */ bool is_success_result_; + + /** + * @brief Add information for the component of response in case of timeout + * @param response Response message, which info should be extended + */ + void AddTimeOutComponentInfoToMessage( + smart_objects::SmartObject& response) const; }; } // namespace commands diff --git a/src/components/application_manager/include/application_manager/commands/hmi/basic_communication_on_awake_sdl.h b/src/components/application_manager/include/application_manager/commands/hmi/basic_communication_on_awake_sdl.h index f789a14780..daa71e68b5 100644 --- a/src/components/application_manager/include/application_manager/commands/hmi/basic_communication_on_awake_sdl.h +++ b/src/components/application_manager/include/application_manager/commands/hmi/basic_communication_on_awake_sdl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Ford Motor Company + * Copyright (c) 2017, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,3 +29,45 @@ * 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_INCLUDE_APPLICATION_MANAGER_COMMANDS_HMI_BASIC_COMMUNICATION_ON_AWAKE_SDL_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_HMI_BASIC_COMMUNICATION_ON_AWAKE_SDL_H_ + +#include "application_manager/commands/hmi/notification_from_hmi.h" + +namespace application_manager { + +namespace commands { + +/** + * @brief OnAwakeSDLNotification command class + **/ +class OnAwakeSDLNotification : public NotificationFromHMI { + public: + /** + * @brief OnAwakeSDLNotification class constructor + * @param message Incoming SmartObject message + * @param application_manager reference to ApplicationManager instance + **/ + OnAwakeSDLNotification(const MessageSharedPtr& message, + ApplicationManager& application_manager); + + /** + * @brief OnAwakeSDLNotification class destructor + **/ + virtual ~OnAwakeSDLNotification(); + + /** + * @brief Execute command + **/ + void Run() FINAL; + + private: + DISALLOW_COPY_AND_ASSIGN(OnAwakeSDLNotification); +}; + +} // namespace commands + +} // namespace application_manager + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_HMI_BASIC_COMMUNICATION_ON_AWAKE_SDL_H_ diff --git a/src/components/application_manager/include/application_manager/commands/hmi/on_app_unregistered_notification.h b/src/components/application_manager/include/application_manager/commands/hmi/on_app_unregistered_notification.h index 980e558d6f..f49dac071f 100644 --- a/src/components/application_manager/include/application_manager/commands/hmi/on_app_unregistered_notification.h +++ b/src/components/application_manager/include/application_manager/commands/hmi/on_app_unregistered_notification.h @@ -55,12 +55,22 @@ class OnAppUnregisteredNotification : public NotificationToHMI { /** * @brief OnAppUnregisteredNotification class destructor **/ - virtual ~OnAppUnregisteredNotification(); + ~OnAppUnregisteredNotification() FINAL; + + /** + * @brief Init overrides and skips replacement of app id with hmi id since + * 1) at the moment this notification is being sent there is no application + * registered in application manager + * 2) hmi id is already used whenever this message is being constructed, so + * its already there + * @return True in any case + */ + bool Init() FINAL; /** * @brief Execute command **/ - virtual void Run(); + virtual void Run() FINAL; private: DISALLOW_COPY_AND_ASSIGN(OnAppUnregisteredNotification); diff --git a/src/components/application_manager/include/application_manager/commands/hmi/on_exit_all_applications_notification.h b/src/components/application_manager/include/application_manager/commands/hmi/on_exit_all_applications_notification.h index a752e00801..92ef97a4aa 100644 --- a/src/components/application_manager/include/application_manager/commands/hmi/on_exit_all_applications_notification.h +++ b/src/components/application_manager/include/application_manager/commands/hmi/on_exit_all_applications_notification.h @@ -60,7 +60,7 @@ class OnExitAllApplicationsNotification : public NotificationFromHMI { /** * @brief Execute command **/ - virtual void Run(); + void Run() FINAL; private: /** diff --git a/src/components/application_manager/include/application_manager/commands/mobile/alert_request.h b/src/components/application_manager/include/application_manager/commands/mobile/alert_request.h index 77f1813e46..01b9782662 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/alert_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/alert_request.h @@ -72,13 +72,6 @@ class AlertRequest : public CommandRequestImpl { **/ virtual void Run(); - /* - * @brief Will caled by request controller, when default will be expired. - * If Alert request has soft buttons, timeout response should not be sent to - * mobile - */ - virtual void onTimeOut(); - /** * @brief Interface method that is called whenever new event received * diff --git a/src/components/application_manager/include/application_manager/commands/mobile/change_registration_request.h b/src/components/application_manager/include/application_manager/commands/mobile/change_registration_request.h index f783af12b3..2cd8e386e0 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/change_registration_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/change_registration_request.h @@ -167,6 +167,16 @@ class ChangeRegistrationRequest : public CommandRequestImpl { std::string vr_response_info_; std::string tts_response_info_; + void SendVRRequest(ApplicationSharedPtr app, + smart_objects::SmartObject& msg_params); + + void SendTTSRequest(ApplicationSharedPtr app, + smart_objects::SmartObject& msg_params); + + void SendUIRequest(ApplicationSharedPtr app, + smart_objects::SmartObject& msg_params, + const int32_t hmi_language); + DISALLOW_COPY_AND_ASSIGN(ChangeRegistrationRequest); }; diff --git a/src/components/application_manager/include/application_manager/commands/mobile/perform_audio_pass_thru_request.h b/src/components/application_manager/include/application_manager/commands/mobile/perform_audio_pass_thru_request.h index 99f86ea1d5..efe1f107f3 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/perform_audio_pass_thru_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/perform_audio_pass_thru_request.h @@ -87,12 +87,38 @@ class PerformAudioPassThruRequest : public CommandRequestImpl { private: /** * @brief Prepare result code, result and info for sending to mobile + * @brief Response params + * success for sending to mobile application + * result code for sending to mobile application + * info for sending to mobile application + */ + struct ResponseParams { + bool success; + mobile_apis::Result::eType result_code; + std::string info; + ResponseParams() + : success(false), result_code(mobile_apis::Result::INVALID_ENUM) {} + }; + + ResponseParams response_params_; + + /** + * @brief Prepare result code, result and info for sending to mobile * application * @param result_code contains result code for sending to mobile application * @return result for sending to mobile application. + * @deprecated */ - bool PrepareResponseParameters(mobile_apis::Result::eType& result_code, - std::string& info); + DEPRECATED bool PrepareResponseParameters( + mobile_apis::Result::eType& result_code, std::string& info); + /** + * @brief Prepare result code, 'success' result and info for sending + * to mobile application + * @param result_code contains result code for sending to mobile application + * @return result for sending to mobile application. + */ + const ResponseParams& PrepareResponseParameters(); + /** * @brief Sends TTS Speak request */ @@ -133,10 +159,23 @@ class PerformAudioPassThruRequest : public CommandRequestImpl { */ bool IsWaitingHMIResponse(); - /* flag display state of speak and ui perform audio - during perform audio pass thru*/ - bool awaiting_tts_speak_response_; - bool awaiting_ui_response_; + /** + * @brief Pair of result_code and success for mobile app + */ + typedef std::pair<mobile_apis::Result::eType, bool> AudioPassThruResults; + + /** + * @brief Checks result code from HMI for splitted RPC + * and returns parameter for sending to mobile app in + * audioPassThru communication. + * @param ui_response contains result_code from UI + * @param tts_response contains result_code from TTS + * @return pair of result code (UI error code has precedence than TTS's, + * error_code from TTS is turned to WARNINGS) and + * result for mobile app + */ + AudioPassThruResults PrepareAudioPassThruResultCodeForResponse( + const ResponseInfo& ui_response, const ResponseInfo& tts_response); hmi_apis::Common_Result::eType result_tts_speak_; hmi_apis::Common_Result::eType result_ui_; diff --git a/src/components/application_manager/include/application_manager/commands/mobile/register_app_interface_request.h b/src/components/application_manager/include/application_manager/commands/mobile/register_app_interface_request.h index cc3d5b685c..5713e2e814 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/register_app_interface_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/register_app_interface_request.h @@ -78,14 +78,29 @@ class RegisterAppInterfaceRequest : public CommandRequestImpl { virtual void Run(); /** - * @brief Sends RegisterAppInterface response to mobile - * - *@param application_impl application - * + * @brief Prepares and sends RegisterAppInterface response to mobile + * considering application type **/ void SendRegisterAppInterfaceResponseToMobile(); private: + /** + * @brief The AppicationType enum defines whether application is newly + * registered or existing and being switched over another transport + */ + enum class ApplicationType { + kNewApplication, + kSwitchedApplicationHashOk, + kSwitchedApplicationWrongHashId + }; + + /** + * @brief Prepares and sends RegisterAppInterface response to mobile + * considering application type + * @param app_type Type of application + **/ + void SendRegisterAppInterfaceResponseToMobile(ApplicationType app_type); + smart_objects::SmartObjectSPtr GetLockScreenIconUrlNotification( const uint32_t connection_key, ApplicationSharedPtr app); @@ -184,6 +199,15 @@ class RegisterAppInterfaceRequest : public CommandRequestImpl { */ void SendSubscribeCustomButtonNotification(); + /** + * @brief IsApplicationSwitched checks whether application is switched from + * another transport. If application id is found, but not in reconnection + * list, returns 'already registered' code. Otherwise - proceed with + * switching. + * @return True if application is detected as switched, otherwise false. + */ + bool IsApplicationSwitched(); + private: std::string response_info_; mobile_apis::Result::eType result_checking_app_hmi_type_; diff --git a/src/components/application_manager/include/application_manager/commands/mobile/reset_global_properties_request.h b/src/components/application_manager/include/application_manager/commands/mobile/reset_global_properties_request.h index eb955df197..c16a014c9f 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/reset_global_properties_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/reset_global_properties_request.h @@ -131,12 +131,6 @@ class ResetGlobalPropertiesRequest : public CommandRequestImpl { DISALLOW_COPY_AND_ASSIGN(ResetGlobalPropertiesRequest); - bool is_ui_send_; - bool is_tts_send_; - - bool is_ui_received_; - bool is_tts_received_; - hmi_apis::Common_Result::eType ui_result_; hmi_apis::Common_Result::eType tts_result_; std::string ui_response_info_; diff --git a/src/components/application_manager/include/application_manager/commands/mobile/subscribe_vehicle_data_request.h b/src/components/application_manager/include/application_manager/commands/mobile/subscribe_vehicle_data_request.h index eb360b50d8..719c514729 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/subscribe_vehicle_data_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/subscribe_vehicle_data_request.h @@ -3,6 +3,9 @@ Copyright (c) 2013, Ford Motor Company All rights reserved. + Copyright (c) 2017, Livio, Inc. + All rights reserved. + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -117,6 +120,13 @@ class SubscribeVehicleDataRequest : public CommandRequestImpl { ApplicationSharedPtr app, const smart_objects::SmartObject& msg_params) const; + DEPRECATED void CheckVISubscribtions( + ApplicationSharedPtr app, + std::string& out_info, + mobile_apis::Result::eType& out_result_code, + smart_objects::SmartObject& out_response_params, + smart_objects::SmartObject& out_request_params, + bool& out_result); /** * @brief Checks if current application and other applications * were subscribed to VI, prepare data that need to send to mobile app @@ -130,7 +140,7 @@ class SubscribeVehicleDataRequest : public CommandRequestImpl { * HMI * @param result contains result that SDL sends to mobile app. */ - void CheckVISubscribtions(ApplicationSharedPtr app, + void CheckVISubscriptions(ApplicationSharedPtr app, std::string& out_info, mobile_apis::Result::eType& out_result_code, smart_objects::SmartObject& out_response_params, @@ -148,6 +158,11 @@ class SubscribeVehicleDataRequest : public CommandRequestImpl { */ VehicleInfoSubscriptions vi_already_subscribed_by_this_app_; + /** + * @brief VI parameters which wait for subscribe after HMI respond + */ + VehicleInfoSubscriptions vi_waiting_for_subscribe_; + DISALLOW_COPY_AND_ASSIGN(SubscribeVehicleDataRequest); }; diff --git a/src/components/application_manager/include/application_manager/help_prompt_manager.h b/src/components/application_manager/include/application_manager/help_prompt_manager.h new file mode 100644 index 0000000000..e7978949e9 --- /dev/null +++ b/src/components/application_manager/include/application_manager/help_prompt_manager.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2018, 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. +*/ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_HELP_PROMPT_MANAGER_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_HELP_PROMPT_MANAGER_H_ + +#include "smart_objects/smart_object.h" + +namespace application_manager { +/** + * @brief The HelpPromptManager is a mechanism for handling "help" requests + * by the user when the application does not provide any or such information. + */ +class HelpPromptManager { + public: + /** + * @brief Class destructor + */ + virtual ~HelpPromptManager() {} + /** + * @brief Adds command to constructed values, and sends SetGlobalProperties if + * required + */ + virtual void OnVrCommandAdded(const uint32_t cmd_id, + const smart_objects::SmartObject& command) = 0; + /** + * @brief Removes command from constructed values, and send + * SetGlobalProperties if required + */ + virtual void OnVrCommandDeleted(const uint32_t cmd_id) = 0; + /** + * @brief Send SetGlobalProperties with constructed vrHelp and/or helpPrompt + * parameters + */ + virtual void OnTimeoutExpired() = 0; + /** + * @brief Stop constructing vrHelp and/or helpPrompt if they are present in + * message + * @param msg containing GlobalProperties + * @param is_response determines is the request or response for the for + * the SetGlobalPropertiesRequest + */ + virtual void OnSetGlobalPropertiesReceived( + const smart_objects::SmartObject& msg, const bool is_response) = 0; + /** + * @brief Starts mechanism for handling "help" requests + * @param is_restore determines the need to restore commands + * after resuming + */ + virtual void OnAppActivated(const bool is_restore) = 0; + /** + * @brief Stop mechanism for handling "help" requests + */ + virtual void OnAppUnregistered() = 0; +}; + +} // namespace application_manager + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_HELP_PROMPT_MANAGER_H_ diff --git a/src/components/application_manager/include/application_manager/help_prompt_manager_impl.h b/src/components/application_manager/include/application_manager/help_prompt_manager_impl.h new file mode 100644 index 0000000000..9d9f07df19 --- /dev/null +++ b/src/components/application_manager/include/application_manager/help_prompt_manager_impl.h @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2018, 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. +*/ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_HELP_PROMPT_MANAGER_IMPL_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_HELP_PROMPT_MANAGER_IMPL_H_ + +#include "application_manager/help_prompt_manager.h" +#include "utils/timer.h" + +namespace application_manager { + +class Application; +class ApplicationManager; + +/** + * @brief The HelpPromptManagerImpl class implemented interface + * HelpPromptManager + * is a mechanism for handling "help" requests + * by the user when the application does not provide any or such information. + */ +class HelpPromptManagerImpl : public HelpPromptManager { + public: + /** + * @brief Continer for buffering VR help commands + */ + typedef std::map<uint32_t, smart_objects::SmartObjectSPtr> VRCommandsMap; + /** + * @brief Class constructor + * @param app owner for this class + */ + HelpPromptManagerImpl(Application& app, ApplicationManager& app_manager); + /** + * @brief Class destructor + */ + ~HelpPromptManagerImpl(); + /** + * @brief The type sends info to HMI + */ + enum class SendingType { kNoneSend, kSendHelpPromt, kSendVRHelp, kSendBoth }; + + /** + * @brief Adds command to constructed values, and send SetGlobalProperties if + * required + */ + void OnVrCommandAdded(const uint32_t cmd_id, + const smart_objects::SmartObject& command) OVERRIDE; + /** + * @brief Removes command from constructed values, and send + * SetGlobalProperties if required + */ + void OnVrCommandDeleted(const uint32_t cmd_id) OVERRIDE; + /** + * @brief Send SetGlobalProperties with constructed vrHelp and/or helpPrompt + * parameters + */ + void OnTimeoutExpired() OVERRIDE; + /** + * @brief Stop constructing vrHelp and/or helpPrompt if they are present in + * message + * @param msg containing GlobalProperties + * @param is_response determines is the request or response for the for + * the SetGlobalPropertiesRequest + */ + void OnSetGlobalPropertiesReceived(const smart_objects::SmartObject& msg, + const bool is_response) OVERRIDE; + /** + * @brief Starts mechanism for handling "help" requests + * @param is_restore determines the need to restore commands + * after resuming + */ + void OnAppActivated(const bool is_restore) OVERRIDE; + /** + * @brief Stop mechanism for handling "help" requests + */ + void OnAppUnregistered() OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(HelpPromptManagerImpl); + /** + * @brief Run timer to helps buffer the requests. + * @param is_restore determines the need to restore commands + * after resuming + */ + void StartTimer(const bool is_restore); + /** + * @brief Stops the buffering timer. + */ + void StopTimer(); + /** + * @brief Callback for timer to helps buffer the requests. + */ + void OnTimerExpired(); + /** + * @brief Send TTS request to HMI + */ + void SendTTSRequest(); + /** + * @brief Send UI request to HMI + */ + void SendUIRequest(); + /** + * @brief Send TTS and UI requests to HMI + */ + void SendBothRequests(); + /** + * @brief Send TTS or UI or both Requests + */ + void SendRequests(); + /** + * @brief Construct the helpPrompt parameter + */ + void CreatePromtMsg(smart_objects::SmartObject& out_msg_params); + /** + * @brief Construct the vrHelp parameter + */ + void CreateVRMsg(smart_objects::SmartObject& out_msg_params); + /** + * @brief Getting request type to send HMI + * @param msg containing request or response for the + * SetGlobalPropertiesRequest + * @param is_response determines is the request or response for the for + * the SetGlobalPropertiesRequest + * @return SendingType + */ + SendingType GetSendingType(const smart_objects::SmartObject& msg, + const bool is_response); + + Application& app_; + ApplicationManager& app_manager_; + timer::Timer internal_timer_; + VRCommandsMap vr_commands_; + SendingType sending_type_; + std::size_t count_requests_commands_; + bool is_tts_send_; + bool is_ui_send_; +}; + +} // namespace application_manager + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_HELP_PROMPT_MANAGER_IMPL_H_ diff --git a/src/components/application_manager/include/application_manager/helpers/application_helper.h b/src/components/application_manager/include/application_manager/helpers/application_helper.h new file mode 100644 index 0000000000..cecda0cd6f --- /dev/null +++ b/src/components/application_manager/include/application_manager/helpers/application_helper.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2017, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_HELPERS_APPLICATION_HELPER_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_HELPERS_APPLICATION_HELPER_H_ + +#include "application_manager/application.h" +#include "application_manager/application_manager.h" + +/* + * This file is for code w/o direct usage of ApplicationManagerImpl internals + */ +namespace application_manager { + +/** + * Helper function for lookup through applications list and returning first + * application satisfying predicate logic + */ +template <class UnaryPredicate> +ApplicationSharedPtr FindApp(DataAccessor<ApplicationSet> accessor, + UnaryPredicate finder) { + ApplicationSet::iterator it = std::find_if( + accessor.GetData().begin(), accessor.GetData().end(), finder); + if (accessor.GetData().end() == it) { + return ApplicationSharedPtr(); + } + ApplicationSharedPtr app = *it; + return app; +} + +/** + * Helper function for lookup through applications list and returning all + * applications satisfying predicate logic + */ +template <class UnaryPredicate> +std::vector<ApplicationSharedPtr> FindAllApps( + DataAccessor<ApplicationSet> accessor, UnaryPredicate finder) { + std::vector<ApplicationSharedPtr> result; + ApplicationSetConstIt it = std::find_if( + accessor.GetData().begin(), accessor.GetData().end(), finder); + while (it != accessor.GetData().end()) { + result.push_back(*it); + it = std::find_if(++it, accessor.GetData().end(), finder); + } + return result; +} + +/** + * @brief The SubscribedToIVIPredicate is predicate for lookup within + * applications list for apps subscribed for specific vehicle data + */ +struct SubscribedToIVIPredicate { + uint32_t vehicle_info_; + explicit SubscribedToIVIPredicate(uint32_t vehicle_info); + bool operator()(const ApplicationSharedPtr app) const; +}; + +/** + * @brief RecallApplicationData cleans up data within application instance to + * its initial state and notifies HMI to delete same data on its side + * @param app Application to clean its data + * @param app_manager Application manager + */ +void DeleteApplicationData(ApplicationSharedPtr app, + ApplicationManager& app_manager); +} // namespace application_manager + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_HELPERS_APPLICATION_HELPER_H_ diff --git a/src/components/application_manager/include/application_manager/hmi_state.h b/src/components/application_manager/include/application_manager/hmi_state.h index 939b8b86d0..f2d665d998 100644 --- a/src/components/application_manager/include/application_manager/hmi_state.h +++ b/src/components/application_manager/include/application_manager/hmi_state.h @@ -36,11 +36,13 @@ #include <list> #include "interfaces/MOBILE_API.h" #include "utils/shared_ptr.h" +#include "utils/macro.h" namespace application_manager { class HmiState; class ApplicationManager; +class Application; typedef utils::SharedPtr<HmiState> HmiStatePtr; @@ -70,7 +72,39 @@ class HmiState { STATE_ID_EMBEDDED_NAVI }; + /** + * @brief HmiState constructor + * @param app Application pointer + * @param app_mngr Application manager + */ + HmiState(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr); + + /** + * @brief HmiState constructor + * @param app Application pointer + * @param app_mngr Application manager + * @param state_id HMI state to assign + */ + HmiState(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr, + StateID state_id); + + /** + * DEPRECATED + * @brief HmiState constructor + * @param app_id Application id + * @param app_mngr Application manager + */ HmiState(uint32_t app_id, const ApplicationManager& app_mngr); + + /** + * DEPRECATED + * @brief HmiState constructor + * @param app_id Application id + * @param app_mngr Application manager + * @param state_id HMI state to assign + */ HmiState(uint32_t app_id, const ApplicationManager& app_mngr, StateID state_id); @@ -166,7 +200,7 @@ class HmiState { } protected: - uint32_t app_id_; + utils::SharedPtr<Application> app_; StateID state_id_; const ApplicationManager& app_mngr_; HmiStatePtr parent_; @@ -177,26 +211,28 @@ class HmiState { protected: /** * @brief is_navi_app check if app is navi - * @param app_id application id * @return true if app is navi, otherwise return false */ - bool is_navi_app(const uint32_t app_id) const; + bool is_navi_app() const; /** * @brief is_media_app check if app is media - * @param app_id application id * @return true if media_app, otherwise return false */ - bool is_media_app(const uint32_t app_id) const; + bool is_media_app() const; /** * @brief is_voice_communicationn_app check if app is voice comunication - * @param app_id application id * @return true if voice_communicationn_app, otherwise return false */ - bool is_voice_communication_app(const uint32_t app_id) const; + bool is_voice_communication_app() const; - bool is_mobile_projection_app(const uint32_t app_id) const; + /** + * @brief is_mobile_projection_app checks if application of 'projection' + * HMI type + * @return True if application is of 'projection' HMI type, otherwise - false + */ + bool is_mobile_projection_app() const; private: void operator=(const HmiState&); @@ -209,7 +245,10 @@ class VRHmiState : public HmiState { public: virtual mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE; - VRHmiState(uint32_t app_id, const ApplicationManager& app_mngr); + VRHmiState(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr); + + DEPRECATED VRHmiState(uint32_t app_id, const ApplicationManager& app_mngr); }; /** @@ -217,7 +256,11 @@ class VRHmiState : public HmiState { */ class TTSHmiState : public HmiState { public: - TTSHmiState(uint32_t app_id, const ApplicationManager& app_mngr); + TTSHmiState(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr); + + DEPRECATED TTSHmiState(uint32_t app_id, const ApplicationManager& app_mngr); + virtual mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE; }; @@ -228,7 +271,12 @@ class TTSHmiState : public HmiState { */ class NaviStreamingHmiState : public HmiState { public: - NaviStreamingHmiState(uint32_t app_id, const ApplicationManager& app_mngr); + NaviStreamingHmiState(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr); + + DEPRECATED NaviStreamingHmiState(uint32_t app_id, + const ApplicationManager& app_mngr); + mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE; }; @@ -239,7 +287,12 @@ class NaviStreamingHmiState : public HmiState { */ class PhoneCallHmiState : public HmiState { public: - PhoneCallHmiState(uint32_t app_id, const ApplicationManager& app_mngr); + PhoneCallHmiState(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr); + + DEPRECATED PhoneCallHmiState(uint32_t app_id, + const ApplicationManager& app_mngr); + mobile_apis::HMILevel::eType hmi_level() const OVERRIDE; mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE { @@ -253,7 +306,12 @@ class PhoneCallHmiState : public HmiState { */ class SafetyModeHmiState : public HmiState { public: - SafetyModeHmiState(uint32_t app_id, const ApplicationManager& app_mngr); + SafetyModeHmiState(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr); + + DEPRECATED SafetyModeHmiState(uint32_t app_id, + const ApplicationManager& app_mngr); + mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE { return mobile_apis::AudioStreamingState::NOT_AUDIBLE; @@ -266,7 +324,11 @@ class SafetyModeHmiState : public HmiState { */ class DeactivateHMI : public HmiState { public: - DeactivateHMI(uint32_t app_id, const ApplicationManager& app_mngr); + DeactivateHMI(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr); + + DEPRECATED DeactivateHMI(uint32_t app_id, const ApplicationManager& app_mngr); + mobile_apis::HMILevel::eType hmi_level() const OVERRIDE; mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE { @@ -280,7 +342,11 @@ class DeactivateHMI : public HmiState { */ class AudioSource : public HmiState { public: - AudioSource(uint32_t app_id, const ApplicationManager& app_mngr); + AudioSource(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr); + + DEPRECATED AudioSource(uint32_t app_id, const ApplicationManager& app_mngr); + mobile_apis::HMILevel::eType hmi_level() const OVERRIDE; mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE { @@ -295,7 +361,11 @@ class AudioSource : public HmiState { */ class EmbeddedNavi : public HmiState { public: - EmbeddedNavi(uint32_t app_id, const ApplicationManager& app_mngr); + EmbeddedNavi(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr); + + DEPRECATED EmbeddedNavi(uint32_t app_id, const ApplicationManager& app_mngr); + mobile_apis::HMILevel::eType hmi_level() const OVERRIDE; mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE { diff --git a/src/components/application_manager/include/application_manager/message.h b/src/components/application_manager/include/application_manager/message.h index 77ef5479ee..f399da6870 100644 --- a/src/components/application_manager/include/application_manager/message.h +++ b/src/components/application_manager/include/application_manager/message.h @@ -93,7 +93,8 @@ class Message { void set_correlation_id(int32_t id); void set_connection_key(int32_t key); void set_message_type(MessageType type); - void set_binary_data(BinaryData* data); + DEPRECATED void set_binary_data(BinaryData* data); + void set_binary_data(const BinaryData* data); void set_json_message(const std::string& json_message); void set_protocol_version(protocol_handler::MajorProtocolVersion version); void set_smart_object(const smart_objects::SmartObject& object); 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 c0a3f37c34..b94609c01b 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -2,6 +2,9 @@ Copyright (c) 2015, Ford Motor Company All rights reserved. + Copyright (c) 2017, Livio, Inc. + All rights reserved. + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -42,11 +45,11 @@ #include "utils/macro.h" #include "connection_handler/device.h" #include "application_manager/application.h" -#include "application_manager/vehicle_info_data.h" #include "policy/policy_types.h" #include "protocol_handler/session_observer.h" #include "application_manager/policies/policy_handler_interface.h" #include "smart_objects/smart_object.h" +#include "transport_manager/common.h" namespace policy { class PolicyHandlerInterface; @@ -61,7 +64,7 @@ namespace mobile_api = mobile_apis; * @param const char* Name of the parameter in mobile request * @param VehicleDataType Enum for vehicle data */ -typedef std::map<std::string, VehicleDataType> VehicleData; +typedef std::map<std::string, mobile_apis::VehicleDataType::eType> VehicleData; /** * @brief MessageHelper class @@ -138,7 +141,8 @@ class MessageHelper { mobile_apis::Result::eType mobile_result); static std::string GetDeviceMacAddressForHandle( - const uint32_t device_handle, const ApplicationManager& app_mngr); + const transport_manager::DeviceHandle device_handle, + const ApplicationManager& app_mngr); /** * @brief Converts string to mobile Result enum value * @param mobile_result stringified value @@ -213,10 +217,12 @@ class MessageHelper { static smart_objects::SmartObjectSPtr CreateSetAppIcon( const std::string& path_to_icon, uint32_t app_id); + DEPRECATED static bool SendIVISubscribtions(const uint32_t app_id, + ApplicationManager& app_mngr); /** * @brief Sends IVI subscription requests */ - static bool SendIVISubscribtions(const uint32_t app_id, + static bool SendIVISubscriptions(const uint32_t app_id, ApplicationManager& app_mngr); /** @@ -702,6 +708,71 @@ class MessageHelper { int32_t connection_key, mobile_api::AppInterfaceUnregisteredReason::eType reason); + /** + * @brief SendDeleteCommandRequest sends requests to HMI to remove UI/VR + * command data depending on command parameters + * @param cmd Command data + * @param application Application owning the command data + * @param app_mngr Application manager + */ + static void SendDeleteCommandRequest(smart_objects::SmartObject* cmd, + ApplicationSharedPtr application, + ApplicationManager& app_mngr); + + /** + * @brief SendDeleteSubmenuRequest sends UI/VR requests to HMI to remove + * submenues-related data depending on command parameters + * @param cmd Command data + * @param application Application owning the commmand data + * @param app_mngr Application manager + */ + static void SendDeleteSubmenuRequest(smart_objects::SmartObject* cmd, + ApplicationSharedPtr application, + ApplicationManager& app_mngr); + + /** + * @brief SendDeleteChoiceSetRequest sends requests to HMI to remove + * choice sets - related data depending on command parameters + * @param cmd Command data + * @param application Application owning command data + * @param app_mngr Application manager + */ + static void SendDeleteChoiceSetRequest(smart_objects::SmartObject* cmd, + ApplicationSharedPtr application, + ApplicationManager& app_mngr); + + /** + * @brief SendResetPropertiesRequest sends requests to HMI to remove/reset + * global properties for application + * @param application Application to remove/reset global properties for + * @param app_mngr Application manager + */ + static void SendResetPropertiesRequest(ApplicationSharedPtr application, + ApplicationManager& app_mngr); + + /** + * @brief SendUnsubscribeButtonNotification sends notification to HMI to + * remove button subscription for application + * @param button Button type + * @param application Application to unsubscribe + * @param app_mngr Application manager + */ + static void SendUnsubscribeButtonNotification( + mobile_apis::ButtonName::eType button, + ApplicationSharedPtr application, + ApplicationManager& app_mngr); + + /** + * @brief SendUnsubscribeIVIRequest sends request to HMI to remove vehicle + * data subscription for application + * @param ivi_id Vehicle data item id + * @param application Application to unsubscribe + * @param app_mngr Application manager + */ + static void SendUnsubscribeIVIRequest(int32_t ivi_id, + ApplicationSharedPtr application, + ApplicationManager& app_mngr); + #ifdef SDL_REMOTE_CONTROL /** * @brief Sends HMI status notification to mobile @@ -729,11 +800,14 @@ class MessageHelper { private: /** - * @brief Creates new request object and fill its header - * @return New request object + * @brief CreateMessageForHMI Creates HMI message with prepared header + * acccoring to message type + * @param message_type Message type + * @param correlation_id Correlation id + * @return HMI message object with filled header */ - static smart_objects::SmartObjectSPtr CreateRequestObject( - const uint32_t correlation_id); + static smart_objects::SmartObjectSPtr CreateMessageForHMI( + hmi_apis::messageType::eType message_type, const uint32_t correlation_id); /** * @brief Allows to fill SO according to the current permissions. 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 9de2d6af68..b4653c6cb2 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 @@ -67,7 +67,7 @@ class ApplicationManager; namespace policy { typedef std::vector<uint32_t> AppIds; -typedef std::vector<uint32_t> DeviceHandles; +typedef std::vector<transport_manager::DeviceHandle> DeviceHandles; namespace custom_str = utils::custom_string; class PolicyHandler : public PolicyHandlerInterface, @@ -533,6 +533,15 @@ class PolicyHandler : public PolicyHandlerInterface, virtual void OnPTUFinished(const bool ptu_result) OVERRIDE; + /** + * @brief OnDeviceSwitching Notifies policy manager on device switch event so + * policy permissions should be processed accordingly + * @param device_id_from Id of device being switched + * @param device_id_to Id of device on the new transport + */ + void OnDeviceSwitching(const std::string& device_id_from, + const std::string& device_id_to) FINAL; + protected: /** * Starts next retry exchange policy table diff --git a/src/components/application_manager/include/application_manager/request_controller.h b/src/components/application_manager/include/application_manager/request_controller.h index d3a5a0b821..c0bae1aac8 100644 --- a/src/components/application_manager/include/application_manager/request_controller.h +++ b/src/components/application_manager/include/application_manager/request_controller.h @@ -289,6 +289,13 @@ class RequestController { */ std::list<RequestPtr> notification_list_; + /** + * @brief Map keeping track of how many duplicate messages were sent for a + * given correlation id, to prevent early termination of a request + */ + std::map<uint32_t, uint32_t> duplicate_message_count_; + sync_primitives::Lock duplicate_message_count_lock_; + /* * timer for checking requests timeout */ diff --git a/src/components/application_manager/include/application_manager/resumption/resume_ctrl.h b/src/components/application_manager/include/application_manager/resumption/resume_ctrl.h index 26b1739a38..0ec58f2419 100644 --- a/src/components/application_manager/include/application_manager/resumption/resume_ctrl.h +++ b/src/components/application_manager/include/application_manager/resumption/resume_ctrl.h @@ -115,11 +115,25 @@ class ResumeCtrl { virtual void OnSuspend() = 0; /** + * @brief Processes resumption data after receiving signal "Ignition Off" + */ + virtual void OnIgnitionOff() = 0; + + /** * @brief Processes resumption data after receiving signal "Awake" */ virtual void OnAwake() = 0; /** + * @brief Checks if SDL has already received OnExitAllApplication notification + * with "SUSPEND" reason + * + * @return Returns TRUE if SDL has received OnExitAllApplication notification + * with reason "SUSPEND" otherwise returns FALSE + */ + virtual bool is_suspended() const = 0; + + /** * @brief Method stops timer "RsmCtrlPercist" when SDL * receives OnExitAllApplication notification * with reason "SUSPEND" diff --git a/src/components/application_manager/include/application_manager/resumption/resume_ctrl_impl.h b/src/components/application_manager/include/application_manager/resumption/resume_ctrl_impl.h index bb886cd5f6..d7ff621c95 100644 --- a/src/components/application_manager/include/application_manager/resumption/resume_ctrl_impl.h +++ b/src/components/application_manager/include/application_manager/resumption/resume_ctrl_impl.h @@ -129,11 +129,25 @@ class ResumeCtrlImpl : public ResumeCtrl, void OnSuspend() OVERRIDE; /** + * @brief Processes resumption data after receiving signal "Ignition Off" + */ + void OnIgnitionOff() OVERRIDE; + + /** * @brief Processes resumption data after receiving signal "Awake" */ void OnAwake() OVERRIDE; /** + * @brief Checks if SDL has already received OnExitAllApplication notification + * with "SUSPEND" reason + * + * @return Returns TRUE if SDL has received OnExitAllApplication notification + * with reason "SUSPEND" otherwise returns FALSE + */ + bool is_suspended() const OVERRIDE; + + /** * @brief Method stops timer "RsmCtrlPercist" when SDL * receives OnExitAllApplication notification * with reason "SUSPEND" @@ -301,6 +315,12 @@ class ResumeCtrlImpl : public ResumeCtrl, void SaveDataOnTimer(); /** + * @brief FinalPersistData persists ResumptionData last time and stops + * persistent data timer to avoid further persisting + */ + void FinalPersistData(); + + /** * @brief AddFiles allows to add files for the application * which should be resumed * @param application application which will be resumed @@ -491,6 +511,7 @@ class ResumeCtrlImpl : public ResumeCtrl, WaitingForTimerList waiting_for_timer_; bool is_resumption_active_; bool is_data_saved_; + bool is_suspended_; time_t launch_time_; utils::SharedPtr<ResumptionData> resumption_storage_; application_manager::ApplicationManager& application_manager_; diff --git a/src/components/application_manager/include/application_manager/resumption/resumption_data.h b/src/components/application_manager/include/application_manager/resumption/resumption_data.h index aeb65b32b9..bee2bce570 100644 --- a/src/components/application_manager/include/application_manager/resumption/resumption_data.h +++ b/src/components/application_manager/include/application_manager/resumption/resumption_data.h @@ -36,6 +36,7 @@ #include "smart_objects/smart_object.h" #include "application_manager/application.h" #include "application_manager/application_manager.h" +#include "utils/macro.h" namespace application_manager { class ApplicationManagerSettings; @@ -91,7 +92,23 @@ class ResumptionData { * @brief Increments ignition counter for all registered applications * and remember ign_off time stamp */ - virtual void OnSuspend() = 0; + virtual void IncrementIgnOffCount() = 0; + + /** + * @brief Increments ignition counter for all registered applications + * and remember ign_off time stamp + */ + DEPRECATED virtual void OnSuspend() = 0; + + /** + * @brief Decrements ignition counter for all registered applications + */ + virtual void DecrementIgnOffCount() = 0; + + /** + * @brief Decrements ignition counter for all registered applications + */ + DEPRECATED virtual void OnAwake() = 0; /** * @brief Retrieves hash ID for the given mobile app ID @@ -108,12 +125,6 @@ class ResumptionData { std::string& hash_id) const = 0; /** - * @brief Increments ignition counter for all registered applications - * and remember ign_off time stamp - */ - virtual void OnAwake() = 0; - - /** * @brief Retrieves data of saved application for the given mobile app ID * and device ID * @param policy_app_id - mobile application id diff --git a/src/components/application_manager/include/application_manager/resumption/resumption_data_db.h b/src/components/application_manager/include/application_manager/resumption/resumption_data_db.h index 862816bf87..780aac82c1 100644 --- a/src/components/application_manager/include/application_manager/resumption/resumption_data_db.h +++ b/src/components/application_manager/include/application_manager/resumption/resumption_data_db.h @@ -55,6 +55,7 @@ struct ApplicationParams { mobile_apis::HMILevel::eType m_hmi_level; bool m_is_media_application; bool m_is_valid; + app_mngr::ApplicationSharedPtr app_ptr; }; /** @@ -113,7 +114,23 @@ class ResumptionDataDB : public ResumptionData { * @brief Increments ignition counter for all registered applications * and remember ign_off time stamp */ - virtual void OnSuspend(); + DEPRECATED void OnSuspend() FINAL; + + /** + * @brief Decrements ignition counter for all registered applications + */ + DEPRECATED void OnAwake() FINAL; + + /** + * @brief Increments ignition counter for all registered applications + * and remember ign_off time stamp + */ + void IncrementIgnOffCount() FINAL; + + /** + * @brief Decrements ignition counter for all registered applications + */ + void DecrementIgnOffCount() FINAL; /** * @brief Retrieves hash ID for the given mobile app ID @@ -130,12 +147,6 @@ class ResumptionDataDB : public ResumptionData { std::string& hash_id) const; /** - * @brief Decrements ignition counter for all registered applications - * and remember ign_off time stamp - */ - virtual void OnAwake(); - - /** * @brief Retrieves data of saved application for the given mobile app ID * and device ID * @param policy_app_id - mobile application id @@ -672,7 +683,7 @@ class ResumptionDataDB : public ResumptionData { smart_objects::SmartObject& saved_app) const; /** - * @brief Selects data from applicationSubscribtionsArray table + * @brief Selects data from applicationSubscriptionsArray table * @param policy_app_id contains mobile application id of application * @param device_id contains id of device on which is running application * @param saved_app will contain subscriptions diff --git a/src/components/application_manager/include/application_manager/resumption/resumption_data_json.h b/src/components/application_manager/include/application_manager/resumption/resumption_data_json.h index 0be6d64db2..82ec1d9e5c 100644 --- a/src/components/application_manager/include/application_manager/resumption/resumption_data_json.h +++ b/src/components/application_manager/include/application_manager/resumption/resumption_data_json.h @@ -85,13 +85,23 @@ class ResumptionDataJson : public ResumptionData { * @brief Increments ignition counter for all registered applications * and remember ign_off time stamp */ - virtual void OnSuspend(); + DEPRECATED void OnSuspend() FINAL; + + /** + * @brief Decrements ignition counter for all registered applications + */ + DEPRECATED void OnAwake() FINAL; /** * @brief Increments ignition counter for all registered applications * and remember ign_off time stamp */ - virtual void OnAwake(); + void IncrementIgnOffCount() FINAL; + + /** + * @brief Decrements ignition counter for all registered applications + */ + void DecrementIgnOffCount() FINAL; /** * @brief Retrieves hash ID for the given mobile app ID diff --git a/src/components/application_manager/include/application_manager/resumption/resumption_sql_queries.h b/src/components/application_manager/include/application_manager/resumption/resumption_sql_queries.h index d61baff7d2..33d62740f7 100644 --- a/src/components/application_manager/include/application_manager/resumption/resumption_sql_queries.h +++ b/src/components/application_manager/include/application_manager/resumption/resumption_sql_queries.h @@ -62,7 +62,7 @@ extern const std::string kDeleteFile; extern const std::string kDeleteApplicationFilesArray; extern const std::string kDeleteSubMenu; extern const std::string kDeleteApplicationSubMenuArray; -extern const std::string kDeleteApplicationSubscribtionsArray; +extern const std::string kDeleteApplicationSubscriptionsArray; extern const std::string kDeleteImageFromCommands; extern const std::string kDeleteVrCommands; extern const std::string kDeleteCommands; 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 0d4eeea0c4..32a2315f23 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 @@ -282,7 +282,7 @@ extern const char* application_choice_sets; extern const char* application_global_properties; extern const char* application_vehicle_info; extern const char* application_buttons; -extern const char* application_subscribtions; +extern const char* application_subscriptions; extern const char* application_files; extern const char* application_show; extern const char* resumption; diff --git a/src/components/application_manager/include/application_manager/state_controller_impl.h b/src/components/application_manager/include/application_manager/state_controller_impl.h index f2f9fb39a4..1b2033f5a8 100644 --- a/src/components/application_manager/include/application_manager/state_controller_impl.h +++ b/src/components/application_manager/include/application_manager/state_controller_impl.h @@ -289,7 +289,7 @@ class StateControllerImpl : public event_engine::EventObserver, void HMIStateStarted(ApplicationSharedPtr app) { DCHECK_OR_RETURN_VOID(app); HmiStatePtr old_hmi_state = app->CurrentHmiState(); - HmiStatePtr new_hmi_state = CreateHmiState(app->app_id(), ID); + HmiStatePtr new_hmi_state = CreateHmiState(app, ID); DCHECK_OR_RETURN_VOID(new_hmi_state); DCHECK_OR_RETURN_VOID(new_hmi_state->state_id() != HmiState::STATE_ID_REGULAR); @@ -326,7 +326,7 @@ class StateControllerImpl : public event_engine::EventObserver, DCHECK_OR_RETURN_VOID(app); HmiStatePtr cur = app->CurrentHmiState(); HmiStatePtr old_hmi_state = - CreateHmiState(app->app_id(), HmiState::StateID::STATE_ID_REGULAR); + CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN_VOID(old_hmi_state); old_hmi_state->set_hmi_level(cur->hmi_level()); old_hmi_state->set_audio_streaming_state(cur->audio_streaming_state()); @@ -431,7 +431,8 @@ class StateControllerImpl : public event_engine::EventObserver, * @param state_id state id * @return */ - HmiStatePtr CreateHmiState(uint32_t app_id, HmiState::StateID state_id) const; + HmiStatePtr CreateHmiState(utils::SharedPtr<Application> app, + HmiState::StateID state_id) const; mobile_apis::AudioStreamingState::eType CalcAudioState( ApplicationSharedPtr app, diff --git a/src/components/application_manager/src/app_launch/app_launch_sql_queries.cc b/src/components/application_manager/src/app_launch/app_launch_sql_queries.cc index 950bcd44fa..cc4765e6c9 100644 --- a/src/components/application_manager/src/app_launch/app_launch_sql_queries.cc +++ b/src/components/application_manager/src/app_launch/app_launch_sql_queries.cc @@ -36,7 +36,7 @@ namespace app_launch { const std::string kCreateSchema = "CREATE TABLE IF NOT EXISTS `app_launch`( " " `deviceMac` TEXT, " - " `appID` TEXT," + " `appID` TEXT collate nocase," " `bundleID` TEXT," " `last_session` DATETIME, " " PRIMARY KEY(`deviceMac`, `appID`, `bundleID`)" diff --git a/src/components/application_manager/src/application_data_impl.cc b/src/components/application_manager/src/application_data_impl.cc index a81540708c..6cf4e34c4a 100644 --- a/src/components/application_manager/src/application_data_impl.cc +++ b/src/components/application_manager/src/application_data_impl.cc @@ -427,6 +427,8 @@ void DynamicApplicationDataImpl::AddCommand( if (commands_.end() == it) { commands_[cmd_id] = new smart_objects::SmartObject(command); } + auto& help_prompt_mngr = help_prompt_manager(); + help_prompt_mngr.OnVrCommandAdded(cmd_id, command); } void DynamicApplicationDataImpl::RemoveCommand(uint32_t cmd_id) { @@ -436,6 +438,8 @@ void DynamicApplicationDataImpl::RemoveCommand(uint32_t cmd_id) { delete it->second; commands_.erase(it); } + auto& help_prompt_mngr = help_prompt_manager(); + help_prompt_mngr.OnVrCommandDeleted(cmd_id); } smart_objects::SmartObject* DynamicApplicationDataImpl::FindCommand( diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index 4a752febf8..3559480d10 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -41,9 +41,12 @@ #include "utils/file_system.h" #include "utils/logger.h" #include "utils/gen_hash.h" +#include "utils/shared_ptr.h" #include "utils/make_shared.h" #include "utils/timer_task_impl.h" #include "application_manager/policies/policy_handler_interface.h" +#include "application_manager/resumption/resume_ctrl.h" +#include "transport_manager/common.h" namespace { @@ -75,10 +78,24 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "ApplicationManager") namespace application_manager { +void SwitchApplicationParameters(ApplicationSharedPtr app, + const uint32_t app_id, + const size_t device_id, + const std::string& mac_address) { + LOG4CXX_AUTO_TRACE(logger_); + utils::SharedPtr<ApplicationImpl> application = + ApplicationSharedPtr::dynamic_pointer_cast<ApplicationImpl>(app); + DCHECK_OR_RETURN_VOID(application); + application->app_id_ = app_id; + application->device_id_ = device_id; + application->mac_address_ = mac_address; +} + ApplicationImpl::ApplicationImpl( uint32_t application_id, const std::string& mobile_app_id, const std::string& mac_address, + const connection_handler::DeviceHandle device_id, const custom_str::CustomString& app_name, utils::SharedPtr<usage_statistics::StatisticsManager> statistics_manager, ApplicationManager& application_manager) @@ -104,13 +121,15 @@ ApplicationImpl::ApplicationImpl( , put_file_in_none_count_(0) , delete_file_in_none_count_(0) , list_files_in_none_count_(0) - , device_(0) , mac_address_(mac_address) + , device_id_(device_id) , usage_report_(mobile_app_id, statistics_manager) + , help_prompt_manager_impl_(*this, application_manager) , protocol_version_( protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_3) , is_voice_communication_application_(false) , is_resuming_(false) + , is_hash_changed_during_suspend_(false) , video_stream_retry_number_(0) , audio_stream_retry_number_(0) , video_stream_suspend_timer_( @@ -135,12 +154,6 @@ ApplicationImpl::ApplicationImpl( SubscribeToButton(mobile_apis::ButtonName::CUSTOM_BUTTON); // load persistent files LoadPersistentFiles(); - HmiStatePtr initial_state = application_manager_.CreateRegularState( - app_id(), - mobile_apis::HMILevel::INVALID_ENUM, - mobile_apis::AudioStreamingState::INVALID_ENUM, - mobile_api::SystemContext::SYSCTXT_MAIN); - state_.InitState(initial_state); video_stream_suspend_timeout_ = application_manager_.get_settings().video_data_stopped_timeout(); @@ -345,7 +358,7 @@ const std::string& ApplicationImpl::bundle_id() const { } connection_handler::DeviceHandle ApplicationImpl::device() const { - return device_; + return device_id_; } const std::string& ApplicationImpl::mac_address() const { @@ -605,7 +618,7 @@ void ApplicationImpl::set_app_allowed(const bool allowed) { } void ApplicationImpl::set_device(connection_handler::DeviceHandle device) { - device_ = device; + device_id_ = device; } uint32_t ApplicationImpl::get_grammar_id() const { @@ -720,25 +733,33 @@ bool ApplicationImpl::UnsubscribeFromButton( bool ApplicationImpl::SubscribeToIVI(uint32_t vehicle_info_type) { sync_primitives::AutoLock lock(vi_lock_); - return subscribed_vehicle_info_.insert(vehicle_info_type).second; + return subscribed_vehicle_info_ + .insert( + static_cast<mobile_apis::VehicleDataType::eType>(vehicle_info_type)) + .second; } bool ApplicationImpl::IsSubscribedToIVI(uint32_t vehicle_info_type) const { sync_primitives::AutoLock lock(vi_lock_); - VehicleInfoSubscriptions::const_iterator it = - subscribed_vehicle_info_.find(vehicle_info_type); + VehicleInfoSubscriptions::const_iterator it = subscribed_vehicle_info_.find( + static_cast<mobile_apis::VehicleDataType::eType>(vehicle_info_type)); return (subscribed_vehicle_info_.end() != it); } bool ApplicationImpl::UnsubscribeFromIVI(uint32_t vehicle_info_type) { sync_primitives::AutoLock lock(vi_lock_); - return subscribed_vehicle_info_.erase(vehicle_info_type); + return subscribed_vehicle_info_.erase( + static_cast<mobile_apis::VehicleDataType::eType>(vehicle_info_type)); } UsageStatistics& ApplicationImpl::usage_report() { return usage_report_; } +HelpPromptManager& ApplicationImpl::help_prompt_manager() { + return help_prompt_manager_impl_; +} + bool ApplicationImpl::AreCommandLimitsExceeded( mobile_apis::FunctionID::eType cmd_id, TLimitSource source) { TimevalStruct current = date_time::DateTime::getCurrentTime(); @@ -857,6 +878,10 @@ bool ApplicationImpl::is_application_data_changed() const { return is_application_data_changed_; } +void ApplicationImpl::SetInitialState(HmiStatePtr state) { + state_.InitState(state); +} + void ApplicationImpl::set_is_application_data_changed( bool state_application_data) { is_application_data_changed_ = state_application_data; @@ -868,7 +893,19 @@ void ApplicationImpl::UpdateHash() { utils::gen_hash(application_manager_.get_settings().hash_string_size()); set_is_application_data_changed(true); - MessageHelper::SendHashUpdateNotification(app_id(), application_manager_); + if (!application_manager_.resume_controller().is_suspended()) { + MessageHelper::SendHashUpdateNotification(app_id(), application_manager_); + } else { + is_hash_changed_during_suspend_ = true; + } +} + +bool ApplicationImpl::IsHashChangedDuringSuspend() const { + return is_hash_changed_during_suspend_; +} + +void ApplicationImpl::SetHashChangedDuringSuspend(const bool state) { + is_hash_changed_during_suspend_ = state; } void ApplicationImpl::CleanupFiles() { @@ -1045,7 +1082,7 @@ void ApplicationImpl::set_hmi_level( usage_report_.RecordHmiStateChanged(new_hmi_level); } -const std::set<uint32_t>& ApplicationImpl::SubscribesIVI() const { +const VehicleInfoSubscriptions& ApplicationImpl::SubscribesIVI() const { return subscribed_vehicle_info_; } @@ -1085,4 +1122,16 @@ void ApplicationImpl::RemoveExtensions() { } #endif // SDL_REMOTE_CONTROL +void ApplicationImpl::PushMobileMessage( + smart_objects::SmartObjectSPtr mobile_message) { + sync_primitives::AutoLock lock(mobile_message_lock_); + mobile_message_queue_.push_back(mobile_message); +} + +void ApplicationImpl::SwapMobileMessageQueue( + MobileMessageQueue& mobile_messages) { + sync_primitives::AutoLock lock(mobile_message_lock_); + mobile_messages.swap(mobile_message_queue_); +} + } // namespace application_manager diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 9814b4cff8..f0b02f30ff 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -50,8 +50,10 @@ #include "application_manager/app_launch/app_launch_ctrl_impl.h" #include "application_manager/app_launch/app_launch_data_db.h" #include "application_manager/app_launch/app_launch_data_json.h" +#include "application_manager/helpers/application_helper.h" #include "protocol_handler/protocol_handler.h" #include "hmi_message_handler/hmi_message_handler.h" +#include "application_manager/command_holder_impl.h" #include "connection_handler/connection_handler_impl.h" #include "formatters/formatter_json_rpc.h" #include "formatters/CFormatterJsonSDLRPCv2.h" @@ -93,9 +95,40 @@ DeviceTypes devicesType = { hmi_apis::Common_TransportType::USB_IOS), std::make_pair(std::string("BLUETOOTH"), hmi_apis::Common_TransportType::BLUETOOTH), + std::make_pair(std::string("BLUETOOTH_IOS"), + hmi_apis::Common_TransportType::BLUETOOTH), std::make_pair(std::string("WIFI"), hmi_apis::Common_TransportType::WIFI)}; } +/** + * @brief device_id_comparator is predicate to compare application device id + * @param device_id Device id to compare with + * @param app Application pointer + * @return True if device id of application matches to device id passed + */ +bool device_id_comparator(const std::string& device_id, + ApplicationSharedPtr app) { + DCHECK_OR_RETURN(app, false); + LOG4CXX_DEBUG(logger_, + "Data to compare: device_id : " << device_id << " app mac: " + << app->mac_address()); + + return device_id == app->mac_address(); +} + +/** + * @brief policy_app_id_comparator is predicate to compare policy application + * ids + * @param policy_app_id Policy id of application + * @param app Application pointer + * @return True if policy id of application matches to policy id passed + */ +bool policy_app_id_comparator(const std::string& policy_app_id, + ApplicationSharedPtr app) { + DCHECK_OR_RETURN(app, false); + return app->policy_app_id() == policy_app_id; +} + uint32_t ApplicationManagerImpl::corelation_id_ = 0; const uint32_t ApplicationManagerImpl::max_corelation_id_ = UINT_MAX; @@ -110,7 +143,9 @@ ApplicationManagerImpl::ApplicationManagerImpl( : settings_(am_settings) , applications_list_lock_(true) , audio_pass_thru_active_(false) - , is_distracting_driver_(false) + , audio_pass_thru_app_id_(0) + , driver_distraction_state_( + hmi_apis::Common_DriverDistractionState::INVALID_ENUM) , is_vr_session_strated_(false) , hmi_cooperating_(false) , is_all_apps_allowed_(true) @@ -164,6 +199,7 @@ ApplicationManagerImpl::ApplicationManagerImpl( const uint32_t timeout_ms = 10000u; clearing_timer->Start(timeout_ms, timer::kSingleShot); timer_pool_.push_back(clearing_timer); + commands_holder_.reset(new CommandHolderImpl(*this)); } ApplicationManagerImpl::~ApplicationManagerImpl() { @@ -193,33 +229,6 @@ ApplicationManagerImpl::~ApplicationManagerImpl() { navi_app_to_end_stream_.clear(); } -template <class UnaryPredicate> -ApplicationSharedPtr FindApp(DataAccessor<ApplicationSet> accessor, - UnaryPredicate finder) { - ApplicationSet::iterator it = std::find_if( - accessor.GetData().begin(), accessor.GetData().end(), finder); - if (accessor.GetData().end() == it) { - LOG4CXX_DEBUG(logger_, "Unable to find application"); - return ApplicationSharedPtr(); - } - ApplicationSharedPtr app = *it; - LOG4CXX_DEBUG(logger_, " Found Application app_id = " << app->app_id()); - return app; -} - -template <class UnaryPredicate> -std::vector<ApplicationSharedPtr> FindAllApps( - DataAccessor<ApplicationSet> accessor, UnaryPredicate finder) { - std::vector<ApplicationSharedPtr> result; - ApplicationSetConstIt it = std::find_if( - accessor.GetData().begin(), accessor.GetData().end(), finder); - while (it != accessor.GetData().end()) { - result.push_back(*it); - it = std::find_if(++it, accessor.GetData().end(), finder); - } - return result; -} - DataAccessor<ApplicationSet> ApplicationManagerImpl::applications() const { DataAccessor<ApplicationSet> accessor(applications_, applications_list_lock_); return accessor; @@ -330,15 +339,6 @@ ApplicationManagerImpl::applications_by_button(uint32_t button) { return FindAllApps(accessor, finder); } -struct SubscribedToIVIPredicate { - int32_t vehicle_info_; - SubscribedToIVIPredicate(int32_t vehicle_info) - : vehicle_info_(vehicle_info) {} - bool operator()(const ApplicationSharedPtr app) const { - return app ? app->IsSubscribedToIVI(vehicle_info_) : false; - } -}; - struct IsApplication { IsApplication(connection_handler::DeviceHandle device_handle, const std::string& policy_app_id) @@ -354,18 +354,18 @@ struct IsApplication { }; std::vector<ApplicationSharedPtr> ApplicationManagerImpl::IviInfoUpdated( - VehicleDataType vehicle_info, int value) { + mobile_apis::VehicleDataType::eType vehicle_info, int value) { // Notify Policy Manager if available about info it's interested in, // i.e. odometer etc switch (vehicle_info) { - case ODOMETER: + case mobile_apis::VehicleDataType::VEHICLEDATA_ODOMETER: GetPolicyHandler().KmsChanged(value); break; default: break; } - SubscribedToIVIPredicate finder(static_cast<int32_t>(vehicle_info)); + SubscribedToIVIPredicate finder(vehicle_info); DataAccessor<ApplicationSet> accessor = applications(); return FindAllApps(accessor, finder); } @@ -393,6 +393,12 @@ void ApplicationManagerImpl::OnApplicationRegistered(ApplicationSharedPtr app) { event.raise(event_dispatcher()); } +void ApplicationManagerImpl::OnApplicationSwitched(ApplicationSharedPtr app) { + LOG4CXX_AUTO_TRACE(logger_); + commands_holder_->Resume(app, CommandHolder::CommandType::kMobileCommand); + commands_holder_->Resume(app, CommandHolder::CommandType::kHmiCommand); +} + bool ApplicationManagerImpl::IsAppTypeExistsInFullOrLimited( ApplicationConstSharedPtr app) const { bool voice_state = app->is_voice_communication_supported(); @@ -472,10 +478,10 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( // original app_id can be received via ApplicationImpl::mobile_app_id() uint32_t app_id = 0; std::list<int32_t> sessions_list; - uint32_t device_id = 0; + connection_handler::DeviceHandle device_id = 0; DCHECK_OR_RETURN(connection_handler_, ApplicationSharedPtr()); - if (connection_handler().GetDataOnSessionKey( + if (connection_handler().get_session_observer().GetDataOnSessionKey( connection_key, &app_id, &sessions_list, &device_id) == -1) { LOG4CXX_ERROR(logger_, "Failed to create application: no connection info."); utils::SharedPtr<smart_objects::SmartObject> response( @@ -488,6 +494,20 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( return ApplicationSharedPtr(); } + smart_objects::SmartObject& params = message[strings::msg_params]; + const std::string& policy_app_id = params[strings::app_id].asString(); + const custom_str::CustomString& app_name = + message[strings::msg_params][strings::app_name].asCustomString(); + std::string device_mac; + std::string connection_type; + if (connection_handler().get_session_observer().GetDataOnDeviceID( + device_id, NULL, NULL, &device_mac, &connection_type) == -1) { + LOG4CXX_DEBUG(logger_, "Failed to extract device mac for id " << device_id); + } else { + LOG4CXX_DEBUG(logger_, + "Device mac for id" << device_id << " is " << device_mac); + } + LOG4CXX_DEBUG(logger_, "Restarting application list update timer"); GetPolicyHandler().OnAppsSearchStarted(); uint32_t timeout = get_settings().application_list_update_timeout(); @@ -506,22 +526,11 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( return ApplicationSharedPtr(); } - smart_objects::SmartObject& params = message[strings::msg_params]; - const std::string& policy_app_id = params[strings::app_id].asString(); - const custom_str::CustomString& app_name = - message[strings::msg_params][strings::app_name].asCustomString(); - std::string device_mac = ""; - if (connection_handler().get_session_observer().GetDataOnDeviceID( - device_id, NULL, NULL, &device_mac, NULL) == -1) { - LOG4CXX_ERROR(logger_, "Failed to extract device mac for id " << device_id); - } else { - LOG4CXX_DEBUG(logger_, - "Device mac for id" << device_id << " is " << device_mac); - } ApplicationSharedPtr application( new ApplicationImpl(app_id, policy_app_id, device_mac, + device_id, app_name, GetPolicyHandler().GetStatisticManager(), *this)); @@ -536,12 +545,19 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( return ApplicationSharedPtr(); } + HmiStatePtr initial_state = + CreateRegularState(utils::SharedPtr<Application>(application), + mobile_apis::HMILevel::INVALID_ENUM, + mobile_apis::AudioStreamingState::INVALID_ENUM, + mobile_api::SystemContext::SYSCTXT_MAIN); + + application->SetInitialState(initial_state); + application->set_folder_name(policy_app_id + "_" + application->mac_address()); // To load persistent files, app folder name must be known first, which is now // depends on device_id and mobile_app_id application->LoadPersistentFiles(); - application->set_device(device_id); application->set_grammar_id(GenerateGrammarID()); mobile_api::Language::eType launguage_desired = @@ -607,6 +623,8 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( const std::string& bundle_id = app_info[strings::bundle_id].asString(); application->set_bundle_id(bundle_id); } + PutDriverDistractionMessageToPostponed(application); + // Stops timer of saving data to resumption in order to // doesn't erase data from resumption storage. // Timer will be started after hmi level resumption. @@ -624,11 +642,13 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( return application; } -bool ApplicationManagerImpl::RemoveAppDataFromHMI(ApplicationSharedPtr app) { +DEPRECATED bool ApplicationManagerImpl::RemoveAppDataFromHMI( + ApplicationSharedPtr app) { return true; } -bool ApplicationManagerImpl::LoadAppDataToHMI(ApplicationSharedPtr app) { +DEPRECATED bool ApplicationManagerImpl::LoadAppDataToHMI( + ApplicationSharedPtr app) { return true; } @@ -637,6 +657,10 @@ bool ApplicationManagerImpl::ActivateApplication(ApplicationSharedPtr app) { LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN(app, false); + auto& help_prompt_manager = app->help_prompt_manager(); + const bool is_restore = false; + help_prompt_manager.OnAppActivated(is_restore); + // remove from resumption if app was activated by user resume_controller().OnAppActivated(app); HMILevel::eType hmi_level = HMILevel::HMI_FULL; @@ -765,6 +789,17 @@ bool ApplicationManagerImpl::BeginAudioPassThrough() { } } +bool ApplicationManagerImpl::BeginAudioPassThru(uint32_t app_id) { + sync_primitives::AutoLock lock(audio_pass_thru_lock_); + if (audio_pass_thru_active_) { + return false; + } else { + audio_pass_thru_active_ = true; + audio_pass_thru_app_id_ = app_id; + return true; + } +} + bool ApplicationManagerImpl::EndAudioPassThrough() { sync_primitives::AutoLock lock(audio_pass_thru_lock_); if (audio_pass_thru_active_) { @@ -775,11 +810,29 @@ bool ApplicationManagerImpl::EndAudioPassThrough() { } } -void ApplicationManagerImpl::set_driver_distraction(const bool is_distracting) { - is_distracting_driver_ = is_distracting; +bool ApplicationManagerImpl::EndAudioPassThru(uint32_t app_id) { + sync_primitives::AutoLock lock(audio_pass_thru_lock_); + if (audio_pass_thru_active_ && audio_pass_thru_app_id_ == app_id) { + audio_pass_thru_active_ = false; + audio_pass_thru_app_id_ = 0; + return true; + } else { + return false; + } } -void ApplicationManagerImpl::set_vr_session_started(const bool state) { +hmi_apis::Common_DriverDistractionState::eType +ApplicationManagerImpl::driver_distraction_state() const { + return driver_distraction_state_; +} + +void ApplicationManagerImpl::set_driver_distraction_state( + const hmi_apis::Common_DriverDistractionState::eType state) { + driver_distraction_state_ = state; +} + +DEPRECATED void ApplicationManagerImpl::set_vr_session_started( + const bool state) { is_vr_session_strated_ = state; } @@ -788,6 +841,18 @@ void ApplicationManagerImpl::SetAllAppsAllowed(const bool allowed) { } HmiStatePtr ApplicationManagerImpl::CreateRegularState( + utils::SharedPtr<Application> app, + mobile_apis::HMILevel::eType hmi_level, + mobile_apis::AudioStreamingState::eType audio_state, + mobile_apis::SystemContext::eType system_context) const { + HmiStatePtr state(new HmiState(app, *this)); + state->set_hmi_level(hmi_level); + state->set_audio_streaming_state(audio_state); + state->set_system_context(system_context); + return state; +} + +HmiStatePtr ApplicationManagerImpl::CreateRegularState( uint32_t app_id, mobile_apis::HMILevel::eType hmi_level, mobile_apis::AudioStreamingState::eType audio_state, @@ -1044,6 +1109,105 @@ void ApplicationManagerImpl::RemoveDevice( LOG4CXX_DEBUG(logger_, "device_handle " << device_handle); } +void ApplicationManagerImpl::OnDeviceSwitchingStart( + const connection_handler::Device& device_from, + const connection_handler::Device& device_to) { + LOG4CXX_AUTO_TRACE(logger_); + { + auto apps_data_accessor = applications(); + + std::copy_if(apps_data_accessor.GetData().begin(), + apps_data_accessor.GetData().end(), + std::back_inserter(reregister_wait_list_), + std::bind1st(std::ptr_fun(&device_id_comparator), + device_from.mac_address())); + } + + { + // During sending of UpdateDeviceList this lock is acquired also so making + // it scoped + sync_primitives::AutoLock lock(reregister_wait_list_lock_); + for (auto i = reregister_wait_list_.begin(); + reregister_wait_list_.end() != i; + ++i) { + auto app = *i; + request_ctrl_.terminateAppRequests(app->app_id()); + resume_ctrl_->SaveApplication(app); + } + } + + policy_handler_->OnDeviceSwitching(device_from.mac_address(), + device_to.mac_address()); + + connection_handler::DeviceMap device_list; + device_list.insert(std::make_pair(device_to.device_handle(), device_to)); + + smart_objects::SmartObjectSPtr msg_params = + MessageHelper::CreateDeviceListSO(device_list, GetPolicyHandler(), *this); + if (!msg_params) { + LOG4CXX_ERROR(logger_, "Can't create UpdateDeviceList notification"); + return; + } + + auto update_list = utils::MakeShared<smart_objects::SmartObject>(); + smart_objects::SmartObject& so_to_send = *update_list; + so_to_send[jhs::S_PARAMS][jhs::S_FUNCTION_ID] = + hmi_apis::FunctionID::BasicCommunication_UpdateDeviceList; + so_to_send[jhs::S_PARAMS][jhs::S_MESSAGE_TYPE] = + hmi_apis::messageType::request; + so_to_send[jhs::S_PARAMS][jhs::S_PROTOCOL_VERSION] = 2; + so_to_send[jhs::S_PARAMS][jhs::S_PROTOCOL_TYPE] = 1; + so_to_send[jhs::S_PARAMS][jhs::S_CORRELATION_ID] = GetNextHMICorrelationID(); + so_to_send[jhs::S_MSG_PARAMS] = *msg_params; + ManageHMICommand(update_list); +} + +void ApplicationManagerImpl::OnDeviceSwitchingFinish( + const std::string& device_uid) { + LOG4CXX_AUTO_TRACE(logger_); + UNUSED(device_uid); + sync_primitives::AutoLock lock(reregister_wait_list_lock_); + + const bool unexpected_disonnect = true; + const bool is_resuming = true; + for (auto app_it = reregister_wait_list_.begin(); + app_it != reregister_wait_list_.end(); + ++app_it) { + auto app = *app_it; + UnregisterApplication(app->app_id(), + mobile_apis::Result::INVALID_ENUM, + is_resuming, + unexpected_disonnect); + } + reregister_wait_list_.clear(); +} + +void ApplicationManagerImpl::SwitchApplication(ApplicationSharedPtr app, + const uint32_t connection_key, + const size_t device_id, + const std::string& mac_address) { + LOG4CXX_AUTO_TRACE(logger_); + DCHECK_OR_RETURN_VOID(app); + sync_primitives::AutoLock lock(applications_list_lock_); + DCHECK_OR_RETURN_VOID(1 == applications_.erase(app)); + + LOG4CXX_DEBUG(logger_, + "Changing app id to " << connection_key + << ". Changing device id to " + << device_id); + + SwitchApplicationParameters(app, connection_key, device_id, mac_address); + + // Normally this is done during registration, however since switched apps are + // not being registered again need to set protocol version on session. + connection_handler().BindProtocolVersionWithSession( + connection_key, static_cast<uint8_t>(app->protocol_version())); + + // Application need to be re-inserted in order to keep sorting in applications + // container. Otherwise data loss on erasing is possible. + applications_.insert(app); +} + mobile_apis::HMILevel::eType ApplicationManagerImpl::GetDefaultHmiLevel( ApplicationConstSharedPtr application) const { using namespace mobile_apis; @@ -1166,7 +1330,6 @@ void ApplicationManagerImpl::ReplaceHMIByMobileAppId( } } -// DEPRECATED bool ApplicationManagerImpl::StartNaviService( uint32_t app_id, protocol_handler::ServiceType service_type) { using namespace protocol_handler; @@ -1338,7 +1501,9 @@ void ApplicationManagerImpl::StopNaviService( app->StopStreaming(service_type); } -// DEPRECATED +// Suppress warning for deprecated method used within another deprecated method +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" bool ApplicationManagerImpl::OnServiceStartedCallback( const connection_handler::DeviceHandle& device_handle, const int32_t& session_key, @@ -1374,6 +1539,7 @@ bool ApplicationManagerImpl::OnServiceStartedCallback( } return false; } +#pragma GCC diagnostic pop void ApplicationManagerImpl::OnServiceStartedCallback( const connection_handler::DeviceHandle& device_handle, @@ -1432,6 +1598,17 @@ void ApplicationManagerImpl::OnServiceEndedCallback( << type << " with reason " << close_reason << " in session 0x" << std::hex << session_key); + auto app = application(static_cast<uint32_t>(session_key)); + if (!app) { + return; + } + + if (IsAppInReconnectMode(app->policy_app_id())) { + LOG4CXX_DEBUG(logger_, + "Application is in reconnection list and won't be closed."); + return; + } + if (type == kRpc) { LOG4CXX_INFO(logger_, "Remove application."); /* In case it was unexpected disconnect or some special case @@ -1486,6 +1663,15 @@ void ApplicationManagerImpl::OnServiceEndedCallback( } } +bool ApplicationManagerImpl::CheckAppIsNavi(const uint32_t app_id) const { + LOG4CXX_AUTO_TRACE(logger_); + ApplicationSharedPtr app = application(app_id); + if (app) { + return app->is_navi(); + } + return false; +} + #ifdef ENABLE_SECURITY bool ApplicationManagerImpl::OnHandshakeDone( uint32_t connection_key, @@ -1514,6 +1700,12 @@ void ApplicationManagerImpl::OnCertificateUpdateRequired() { GetPolicyHandler().OnPTExchangeNeeded(); } +bool ApplicationManagerImpl::GetPolicyCertificateData(std::string& data) const { + LOG4CXX_AUTO_TRACE(logger_); + data = GetPolicyHandler().RetrieveCertificate(); + return true; +} + security_manager::SSLContext::HandshakeContext ApplicationManagerImpl::GetHandshakeContext(uint32_t key) const { LOG4CXX_AUTO_TRACE(logger_); @@ -1694,7 +1886,6 @@ bool ApplicationManagerImpl::ManageMobileCommand( const commands::MessageSharedPtr message, commands::Command::CommandOrigin origin) { LOG4CXX_AUTO_TRACE(logger_); - if (!message) { LOG4CXX_WARN(logger_, "Null-pointer message received."); return false; @@ -1718,6 +1909,16 @@ bool ApplicationManagerImpl::ManageMobileCommand( return false; } + const uint32_t connection_key = static_cast<uint32_t>( + (*message)[strings::params][strings::connection_key].asUInt()); + + auto app_ptr = application(connection_key); + if (app_ptr && IsAppInReconnectMode(app_ptr->policy_app_id())) { + commands_holder_->Suspend( + app_ptr, CommandHolder::CommandType::kMobileCommand, message); + return true; + } + mobile_apis::FunctionID::eType function_id = static_cast<mobile_apis::FunctionID::eType>( (*message)[strings::params][strings::function_id].asInt()); @@ -1728,9 +1929,6 @@ bool ApplicationManagerImpl::ManageMobileCommand( ? (*message)[strings::params][strings::correlation_id].asUInt() : 0; - uint32_t connection_key = - (*message)[strings::params][strings::connection_key].asUInt(); - int32_t protocol_type = (*message)[strings::params][strings::protocol_type].asUInt(); @@ -1947,8 +2145,21 @@ bool ApplicationManagerImpl::ManageHMICommand( return false; } + if ((*message).keyExists(strings::msg_params) && + (*message)[strings::msg_params].keyExists(strings::app_id)) { + const auto connection_key = + (*message)[strings::msg_params][strings::app_id].asUInt(); + + auto app = application(static_cast<uint32_t>(connection_key)); + if (app && IsAppInReconnectMode(app->policy_app_id())) { + commands_holder_->Suspend( + app, CommandHolder::CommandType::kHmiCommand, message); + return true; + } + } + int32_t message_type = - (*(message.get()))[strings::params][strings::message_type].asInt(); + (*message)[strings::params][strings::message_type].asInt(); if (kRequest == message_type) { LOG4CXX_DEBUG(logger_, "ManageHMICommand"); @@ -1959,9 +2170,9 @@ bool ApplicationManagerImpl::ManageHMICommand( command->Run(); if (kResponse == message_type) { const uint32_t correlation_id = - (*(message.get()))[strings::params][strings::correlation_id].asUInt(); + (*message)[strings::params][strings::correlation_id].asUInt(); const int32_t function_id = - (*(message.get()))[strings::params][strings::function_id].asInt(); + (*message)[strings::params][strings::function_id].asInt(); request_ctrl_.OnHMIResponse(correlation_id, function_id); } return true; @@ -2083,9 +2294,12 @@ bool ApplicationManagerImpl::ConvertMessageToSO( message.function_id(), message.type(), message.correlation_id()); + + rpc::ValidationReport report("RPC"); + if (!conversion_result || !mobile_so_factory().attachSchema(output, true) || - ((output.validate() != smart_objects::Errors::OK))) { + ((output.validate(&report) != smart_objects::Errors::OK))) { LOG4CXX_WARN(logger_, "Failed to parse string to smart object :" << message.json_message()); @@ -2095,6 +2309,9 @@ bool ApplicationManagerImpl::ConvertMessageToSO( message.function_id(), message.correlation_id(), mobile_apis::Result::INVALID_DATA)); + + (*response)[strings::msg_params][strings::info] = + rpc::PrettyFormat(report); ManageMobileCommand(response, commands::Command::ORIGIN_SDL); return false; } @@ -2142,8 +2359,18 @@ bool ApplicationManagerImpl::ConvertMessageToSO( LOG4CXX_WARN(logger_, "Failed to attach schema to object."); return false; } - if (output.validate() != smart_objects::Errors::OK) { - LOG4CXX_ERROR(logger_, "Incorrect parameter from HMI"); + + rpc::ValidationReport report("RPC"); + + if (output.validate(&report) != smart_objects::Errors::OK) { + LOG4CXX_ERROR(logger_, + "Incorrect parameter from HMI" + << rpc::PrettyFormat(report)); + + output.erase(strings::msg_params); + output[strings::params][hmi_response::code] = + hmi_apis::Common_Result::INVALID_DATA; + output[strings::msg_params][strings::info] = rpc::PrettyFormat(report); return false; } break; @@ -2283,7 +2510,7 @@ bool ApplicationManagerImpl::ConvertSOtoMessage( } if (message.getElement(jhs::S_PARAMS).keyExists(strings::binary_data)) { - application_manager::BinaryData binaryData( + const application_manager::BinaryData binaryData( message.getElement(jhs::S_PARAMS) .getElement(strings::binary_data) .asBinary()); @@ -2319,8 +2546,11 @@ MessageValidationResult ApplicationManagerImpl::ValidateMessageBySchema( if (!mobile_so_factory().attachSchema(so, true)) { return INVALID_METADATA; } - - if (so.validate() != smart_objects::Errors::OK) { + rpc::ValidationReport report("RPC"); + if (so.validate(&report) != smart_objects::Errors::OK) { + LOG4CXX_WARN(logger_, + "validate() failed for Mobile message - " + << rpc::PrettyFormat(report)); return SCHEMA_MISMATCH; } break; @@ -2339,7 +2569,11 @@ MessageValidationResult ApplicationManagerImpl::ValidateMessageBySchema( return INVALID_METADATA; } - if (so.validate() != smart_objects::Errors::OK) { + rpc::ValidationReport report("RPC"); + if (so.validate(&report) != smart_objects::Errors::OK) { + LOG4CXX_WARN(logger_, + "validate() failed for HMI message - " + << rpc::PrettyFormat(report)); return SCHEMA_MISMATCH; } break; @@ -2587,10 +2821,10 @@ void ApplicationManagerImpl::CreateApplications(SmartArray& obj_array, const std::string app_icon_dir(settings_.app_icons_folder()); const std::string full_icon_path(app_icon_dir + "/" + policy_app_id); - uint32_t device_id = 0; + connection_handler::DeviceHandle device_id = 0; if (-1 == - connection_handler().GetDataOnSessionKey( + connection_handler().get_session_observer().GetDataOnSessionKey( connection_key, NULL, NULL, &device_id)) { LOG4CXX_ERROR(logger_, "Failed to create application: no connection info."); @@ -2612,6 +2846,7 @@ void ApplicationManagerImpl::CreateApplications(SmartArray& obj_array, new ApplicationImpl(0, policy_app_id, device_mac, + device_id, appName, GetPolicyHandler().GetStatisticManager(), *this)); @@ -2620,7 +2855,6 @@ void ApplicationManagerImpl::CreateApplications(SmartArray& obj_array, app->SetPackageName(package_name); app->set_app_icon_path(full_icon_path); app->set_hmi_application_id(hmi_app_id); - app->set_device(device_id); app->set_vr_synonyms(vrSynonym); app->set_tts_name(ttsName); @@ -2883,7 +3117,7 @@ void ApplicationManagerImpl::UnregisterAllApplications() { } } if (is_ignition_off) { - resume_controller().OnSuspend(); + resume_controller().OnIgnitionOff(); } request_ctrl_.terminateAllHMIRequests(); } @@ -2975,13 +3209,14 @@ void ApplicationManagerImpl::UnregisterApplication( ApplicationSharedPtr app_to_remove; connection_handler::DeviceHandle handle = 0; { - DataAccessor<ApplicationSet> accessor(applications()); - ApplicationSetConstIt it = accessor.GetData().begin(); - for (; it != accessor.GetData().end(); ++it) { - if ((*it)->app_id() == app_id) { - app_to_remove = *it; - handle = app_to_remove->device(); - break; + sync_primitives::AutoLock lock(applications_list_lock_); + auto it_app = applications_.begin(); + while (applications_.end() != it_app) { + if (app_id == (*it_app)->app_id()) { + app_to_remove = *it_app; + applications_.erase(it_app++); + } else { + ++it_app; } } if (!app_to_remove) { @@ -2999,11 +3234,10 @@ void ApplicationManagerImpl::UnregisterApplication( } else { resume_controller().RemoveApplicationFromSaved(app_to_remove); } - applications_.erase(app_to_remove); (hmi_capabilities_->get_hmi_language_handler()) .OnUnregisterApplication(app_id); AppV4DevicePredicate finder(handle); - ApplicationSharedPtr app = FindApp(accessor, finder); + ApplicationSharedPtr app = FindApp(applications(), finder); if (!app) { LOG4CXX_DEBUG( logger_, "There is no more SDL4 apps with device handle: " << handle); @@ -3012,9 +3246,14 @@ void ApplicationManagerImpl::UnregisterApplication( SendUpdateAppList(); } } - if (audio_pass_thru_active_) { + + auto& help_prompt_manager = app_to_remove->help_prompt_manager(); + help_prompt_manager.OnAppUnregistered(); + + commands_holder_->Clear(app_to_remove); + + if (EndAudioPassThru(app_id)) { // May be better to put this code in MessageHelper? - EndAudioPassThrough(); StopAudioPassThru(app_id); MessageHelper::SendStopAudioPathThru(*this); } @@ -3234,8 +3473,9 @@ bool ApplicationManagerImpl::IsLowVoltage() { std::string ApplicationManagerImpl::GetHashedAppID( uint32_t connection_key, const std::string& mobile_app_id) const { - uint32_t device_id = 0; - connection_handler().GetDataOnSessionKey(connection_key, 0, NULL, &device_id); + connection_handler::DeviceHandle device_id = 0; + connection_handler().get_session_observer().GetDataOnSessionKey( + connection_key, 0, NULL, &device_id); std::string device_name; connection_handler().get_session_observer().GetDataOnDeviceID( device_id, &device_name, NULL, NULL, NULL); @@ -3405,6 +3645,41 @@ void ApplicationManagerImpl::OnHMILevelChanged( mobile_apis::HMILevel::eType from, mobile_apis::HMILevel::eType to) { LOG4CXX_AUTO_TRACE(logger_); + ProcessPostponedMessages(app_id); + ProcessApp(app_id, from, to); +} + +void ApplicationManagerImpl::ProcessPostponedMessages(const uint32_t app_id) { + LOG4CXX_AUTO_TRACE(logger_); + + ApplicationSharedPtr app = application(app_id); + if (!app) { + LOG4CXX_WARN(logger_, "The app with id: " << app_id << " does not exist"); + return; + } + MobileMessageQueue messages; + app->SwapMobileMessageQueue(messages); + auto push_allowed_messages = + [this, &app](smart_objects::SmartObjectSPtr message) { + const std::string function_id = MessageHelper::StringifiedFunctionID( + static_cast<mobile_apis::FunctionID::eType>( + (*message)[strings::params][strings::function_id].asUInt())); + const RPCParams params; + const mobile_apis::Result::eType check_result = + CheckPolicyPermissions(app, function_id, params); + if (mobile_api::Result::SUCCESS == check_result) { + ManageMobileCommand(message, + commands::Command::CommandOrigin::ORIGIN_SDL); + } else { + app->PushMobileMessage(message); + } + }; + std::for_each(messages.begin(), messages.end(), push_allowed_messages); +} + +void ApplicationManagerImpl::ProcessApp(const uint32_t app_id, + const mobile_apis::HMILevel::eType from, + const mobile_apis::HMILevel::eType to) { using namespace mobile_apis::HMILevel; using namespace helpers; @@ -3596,6 +3871,17 @@ bool ApplicationManagerImpl::IsApplicationForbidden( return forbidden_applications.find(name) != forbidden_applications.end(); } +bool ApplicationManagerImpl::IsAppInReconnectMode( + const std::string& policy_app_id) const { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(reregister_wait_list_lock_); + return reregister_wait_list_.end() != + std::find_if(reregister_wait_list_.begin(), + reregister_wait_list_.end(), + std::bind1st(std::ptr_fun(&policy_app_id_comparator), + policy_app_id)); +} + policy::DeviceConsent ApplicationManagerImpl::GetUserConsentForDevice( const std::string& device_id) const { return GetPolicyHandler().GetUserConsentForDevice(device_id); @@ -3879,6 +4165,48 @@ void ApplicationManagerImpl::OnUpdateHMIAppType( } } +void ApplicationManagerImpl::EraseAppFromReconnectionList( + const ApplicationSharedPtr& app) { + LOG4CXX_AUTO_TRACE(logger_); + if (!app) { + LOG4CXX_WARN(logger_, "Application is not valid."); + return; + } + + const auto policy_app_id = app->policy_app_id(); + sync_primitives::AutoLock lock(reregister_wait_list_lock_); + auto app_it = std::find_if( + reregister_wait_list_.begin(), + reregister_wait_list_.end(), + std::bind1st(std::ptr_fun(&policy_app_id_comparator), policy_app_id)); + if (reregister_wait_list_.end() != app_it) { + reregister_wait_list_.erase(app_it); + } +} + +void ApplicationManagerImpl::ProcessReconnection( + ApplicationSharedPtr application, const uint32_t connection_key) { + LOG4CXX_AUTO_TRACE(logger_); + DCHECK_OR_RETURN_VOID(application); + + connection_handler::DeviceHandle new_device_id = 0; + connection_handler().get_session_observer().GetDataOnSessionKey( + connection_key, NULL, NULL, &new_device_id); + DCHECK_OR_RETURN_VOID(new_device_id); + + std::string device_mac; + std::string connection_type; + connection_handler().get_session_observer().GetDataOnDeviceID( + new_device_id, NULL, NULL, &device_mac, &connection_type); + + EraseAppFromReconnectionList(application); + + SwitchApplication(application, connection_key, new_device_id, device_mac); + + // Update connection type for existed device. + GetPolicyHandler().AddDevice(device_mac, connection_type); +} + void ApplicationManagerImpl::OnPTUFinished(const bool ptu_result) { #ifdef SDL_REMOTE_CONTROL if (!ptu_result) { @@ -3889,6 +4217,28 @@ void ApplicationManagerImpl::OnPTUFinished(const bool ptu_result) { #endif // SDL_REMOTE_CONTROL } +void ApplicationManagerImpl::PutDriverDistractionMessageToPostponed( + ApplicationSharedPtr application) const { + LOG4CXX_AUTO_TRACE(logger_); + if (hmi_apis::Common_DriverDistractionState::INVALID_ENUM == + driver_distraction_state()) { + LOG4CXX_WARN(logger_, "DriverDistractionState is INVALID_ENUM"); + return; + } + smart_objects::SmartObjectSPtr on_driver_distraction = + utils::MakeShared<smart_objects::SmartObject>(); + + (*on_driver_distraction)[strings::params][strings::message_type] = + static_cast<int32_t>(application_manager::MessageType::kNotification); + (*on_driver_distraction)[strings::params][strings::function_id] = + mobile_api::FunctionID::OnDriverDistractionID; + (*on_driver_distraction)[strings::msg_params][mobile_notification::state] = + driver_distraction_state(); + (*on_driver_distraction)[strings::params][strings::connection_key] = + application->app_id(); + application->PushMobileMessage(on_driver_distraction); +} + protocol_handler::MajorProtocolVersion ApplicationManagerImpl::SupportedSDLVersion() const { LOG4CXX_AUTO_TRACE(logger_); @@ -3979,9 +4329,46 @@ void ApplicationManagerImpl::UnsubscribeAppFromWayPoints( subscribed_way_points_apps_list_.erase(app_id); } +bool ApplicationManagerImpl::IsAppSubscribedForWayPoints( + ApplicationSharedPtr app) 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) == + subscribed_way_points_apps_list_.end()) { + return false; + } + return true; +} + +void ApplicationManagerImpl::SubscribeAppForWayPoints( + ApplicationSharedPtr app) { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); + subscribed_way_points_apps_list_.insert(app); + LOG4CXX_DEBUG(logger_, + "There are applications subscribed: " + << subscribed_way_points_apps_list_.size()); +} + +void ApplicationManagerImpl::UnsubscribeAppFromWayPoints( + ApplicationSharedPtr app) { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); + subscribed_way_points_apps_list_.erase(app); + LOG4CXX_DEBUG(logger_, + "There are applications subscribed: " + << subscribed_way_points_apps_list_.size()); +} + bool ApplicationManagerImpl::IsAnyAppSubscribedForWayPoints() 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()); return !subscribed_way_points_apps_list_.empty(); } @@ -4083,6 +4470,11 @@ void ApplicationManagerImpl::AddMockApplication(ApplicationSharedPtr mock_app) { apps_size_ = applications_.size(); applications_list_lock_.Release(); } + +void ApplicationManagerImpl::SetMockMediaManager( + media_manager::MediaManager* mock_media_manager) { + media_manager_ = mock_media_manager; +} #endif // BUILD_TESTS #ifdef SDL_REMOTE_CONTROL struct MobileAppIdPredicate { diff --git a/src/components/application_manager/src/command_holder_impl.cc b/src/components/application_manager/src/command_holder_impl.cc new file mode 100644 index 0000000000..afdaa2f1f4 --- /dev/null +++ b/src/components/application_manager/src/command_holder_impl.cc @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2017, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "application_manager/command_holder_impl.h" +#include "application_manager/application_manager.h" +#include "application_manager/commands/command.h" + +namespace application_manager { +CREATE_LOGGERPTR_GLOBAL(logger_, "ApplicationManager") + +CommandHolderImpl::CommandHolderImpl(ApplicationManager& app_manager) + : app_manager_(app_manager) {} + +void CommandHolderImpl::Suspend( + ApplicationSharedPtr application, + CommandType type, + utils::SharedPtr<smart_objects::SmartObject> command) { + LOG4CXX_AUTO_TRACE(logger_); + DCHECK_OR_RETURN_VOID(application); + LOG4CXX_DEBUG(logger_, + "Suspending command(s) for application: " + << application->policy_app_id()); + sync_primitives::AutoLock lock(commands_lock_); + + if (CommandType::kHmiCommand == type) { + app_hmi_commands_[application].push_back(command); + LOG4CXX_DEBUG(logger_, + "Suspended HMI command(s): " << app_hmi_commands_.size()); + } else { + app_mobile_commands_[application].push_back(command); + LOG4CXX_DEBUG( + logger_, + "Suspended mobile command(s): " << app_mobile_commands_.size()); + } +} + +void CommandHolderImpl::Resume(ApplicationSharedPtr application, + CommandType type) { + LOG4CXX_AUTO_TRACE(logger_); + DCHECK_OR_RETURN_VOID(application); + LOG4CXX_DEBUG( + logger_, + "Resuming command(s) for application: " << application->policy_app_id()); + if (CommandType::kHmiCommand == type) { + ResumeHmiCommand(application); + } else { + ResumeMobileCommand(application); + } +} + +void CommandHolderImpl::Clear(ApplicationSharedPtr application) { + LOG4CXX_AUTO_TRACE(logger_); + DCHECK_OR_RETURN_VOID(application); + LOG4CXX_DEBUG( + logger_, + "Clearing command(s) for application: " << application->policy_app_id()); + sync_primitives::AutoLock lock(commands_lock_); + auto app_hmi_commands = app_hmi_commands_.find(application); + if (app_hmi_commands_.end() != app_hmi_commands) { + LOG4CXX_DEBUG( + logger_, + "Clearing HMI command(s): " << app_hmi_commands->second.size()); + app_hmi_commands_.erase(app_hmi_commands); + } + + auto app_mobile_commands = app_mobile_commands_.find(application); + if (app_mobile_commands_.end() != app_mobile_commands) { + LOG4CXX_DEBUG( + logger_, + "Clearing mobile command(s): " << app_mobile_commands->second.size()); + app_mobile_commands_.erase(app_mobile_commands); + } +} + +void CommandHolderImpl::ResumeHmiCommand(ApplicationSharedPtr application) { + DCHECK_OR_RETURN_VOID(application); + sync_primitives::AutoLock lock(commands_lock_); + auto app_commands = app_hmi_commands_.find(application); + if (app_hmi_commands_.end() == app_commands) { + return; + } + + LOG4CXX_DEBUG(logger_, + "Resuming HMI command(s): " << app_hmi_commands_.size()); + + for (auto cmd : app_commands->second) { + (*cmd)[strings::msg_params][strings::app_id] = application->hmi_app_id(); + app_manager_.ManageHMICommand(cmd); + } + + app_hmi_commands_.erase(app_commands); +} + +void CommandHolderImpl::ResumeMobileCommand(ApplicationSharedPtr application) { + DCHECK_OR_RETURN_VOID(application); + sync_primitives::AutoLock lock(commands_lock_); + auto app_commands = app_mobile_commands_.find(application); + if (app_mobile_commands_.end() == app_commands) { + return; + } + + LOG4CXX_DEBUG(logger_, + "Resuming mobile command(s): " << app_mobile_commands_.size()); + + for (auto cmd : app_commands->second) { + (*cmd)[strings::params][strings::connection_key] = application->app_id(); + app_manager_.ManageMobileCommand( + cmd, commands::Command::CommandOrigin::ORIGIN_MOBILE); + } + + app_mobile_commands_.erase(app_commands); +} +} // application_manager diff --git a/src/components/application_manager/src/commands/command_impl.cc b/src/components/application_manager/src/commands/command_impl.cc index 0a3e65a790..b928184148 100644 --- a/src/components/application_manager/src/commands/command_impl.cc +++ b/src/components/application_manager/src/commands/command_impl.cc @@ -94,25 +94,30 @@ void CommandImpl::SetAllowedToTerminate(const bool allowed) { allowed_to_terminate_ = allowed; } -void CommandImpl::ReplaceMobileByHMIAppId( +bool CommandImpl::ReplaceMobileWithHMIAppId( NsSmartDeviceLink::NsSmartObjects::SmartObject& message) { + LOG4CXX_AUTO_TRACE(logger_); if (message.keyExists(strings::app_id)) { ApplicationSharedPtr application = application_manager_.application(message[strings::app_id].asUInt()); - if (application.valid()) { - LOG4CXX_DEBUG(logger_, - "ReplaceMobileByHMIAppId from " - << message[strings::app_id].asInt() << " to " - << application->hmi_app_id()); - message[strings::app_id] = application->hmi_app_id(); + if (!application) { + LOG4CXX_ERROR(logger_, "Substitution mobile --> HMI id is failed."); + return false; } + LOG4CXX_DEBUG(logger_, + "ReplaceMobileWithHMIAppId from " + << message[strings::app_id].asInt() << " to " + << application->hmi_app_id()); + message[strings::app_id] = application->hmi_app_id(); } else { switch (message.getType()) { case smart_objects::SmartType::SmartType_Array: { smart_objects::SmartArray* message_array = message.asArray(); smart_objects::SmartArray::iterator it = message_array->begin(); for (; it != message_array->end(); ++it) { - ReplaceMobileByHMIAppId(*it); + if (!ReplaceMobileWithHMIAppId(*it)) { + break; + } } break; } @@ -121,36 +126,51 @@ void CommandImpl::ReplaceMobileByHMIAppId( std::set<std::string>::const_iterator key = keys.begin(); for (; key != keys.end(); ++key) { std::string k = *key; - ReplaceMobileByHMIAppId(message[*key]); + if (!ReplaceMobileWithHMIAppId(message[*key])) { + break; + } } break; } default: { break; } } } + + return true; +} + +DEPRECATED void CommandImpl::ReplaceMobileByHMIAppId( + NsSmartDeviceLink::NsSmartObjects::SmartObject& message) { + if (!ReplaceMobileWithHMIAppId(message)) { + LOG4CXX_ERROR(logger_, "Substitution mobile --> HMI id is failed."); + } } -void CommandImpl::ReplaceHMIByMobileAppId( +bool CommandImpl::ReplaceHMIWithMobileAppId( NsSmartDeviceLink::NsSmartObjects::SmartObject& message) { if (message.keyExists(strings::app_id)) { ApplicationSharedPtr application = application_manager_.application_by_hmi_app( message[strings::app_id].asUInt()); - if (application.valid()) { - LOG4CXX_DEBUG(logger_, - "ReplaceHMIByMobileAppId from " - << message[strings::app_id].asInt() << " to " - << application->app_id()); - message[strings::app_id] = application->app_id(); + if (!application) { + LOG4CXX_ERROR(logger_, "Substitution HMI --> mobile id is failed."); + return false; } + LOG4CXX_DEBUG(logger_, + "ReplaceHMIWithMobileAppId from " + << message[strings::app_id].asInt() << " to " + << application->app_id()); + message[strings::app_id] = application->app_id(); } else { switch (message.getType()) { case smart_objects::SmartType::SmartType_Array: { smart_objects::SmartArray* message_array = message.asArray(); smart_objects::SmartArray::iterator it = message_array->begin(); for (; it != message_array->end(); ++it) { - ReplaceHMIByMobileAppId(*it); + if (!ReplaceHMIWithMobileAppId(*it)) { + break; + } } break; } @@ -158,13 +178,24 @@ void CommandImpl::ReplaceHMIByMobileAppId( std::set<std::string> keys = message.enumerate(); std::set<std::string>::const_iterator key = keys.begin(); for (; key != keys.end(); ++key) { - ReplaceHMIByMobileAppId(message[*key]); + if (!ReplaceHMIWithMobileAppId(message[*key])) { + break; + } } break; } default: { break; } } } + + return true; +} + +DEPRECATED void CommandImpl::ReplaceHMIByMobileAppId( + NsSmartDeviceLink::NsSmartObjects::SmartObject& message) { + if (!ReplaceHMIWithMobileAppId(message)) { + LOG4CXX_ERROR(logger_, "Substitution HMI --> mobile id is failed."); + } } } // namespace commands 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 3f9a1d13b3..515d8a998c 100644 --- a/src/components/application_manager/src/commands/command_request_impl.cc +++ b/src/components/application_manager/src/commands/command_request_impl.cc @@ -31,8 +31,10 @@ */ #include <algorithm> +#include <numeric> #include <string> #include "utils/macro.h" +#include "utils/make_shared.h" #include "application_manager/commands/command_request_impl.h" #include "application_manager/application_manager.h" #include "application_manager/message_helper.h" @@ -105,20 +107,29 @@ const std::string CreateInfoForUnsupportedResult( } bool CheckResultCode(const ResponseInfo& first, const ResponseInfo& second) { - if (first.is_ok && second.is_unsupported_resource && - second.interface_state == HmiInterfaces::STATE_NOT_AVAILABLE) { + if (first.is_ok && second.is_unsupported_resource) { + return true; + } + if (first.is_ok && second.is_not_used) { + return true; + } + if (first.is_ok && second.is_ok) { return true; } return false; } -bool IsResultCodeUnsupported(const ResponseInfo& first, - const ResponseInfo& second) { - return ((first.is_ok || first.is_invalid_enum) && - second.is_unsupported_resource) || - ((second.is_ok || second.is_invalid_enum) && - first.is_unsupported_resource) || - (first.is_unsupported_resource && second.is_unsupported_resource); +bool IsResultCodeWarning(const ResponseInfo& first, + const ResponseInfo& second) { + const bool first_is_ok_second_is_warn = + (first.is_ok || first.is_not_used) && + hmi_apis::Common_Result::WARNINGS == second.result_code; + + const bool both_warnings = + hmi_apis::Common_Result::WARNINGS == first.result_code && + hmi_apis::Common_Result::WARNINGS == second.result_code; + + return first_is_ok_second_is_warn || both_warnings; } struct DisallowedParamsInserter { @@ -146,6 +157,42 @@ struct DisallowedParamsInserter { mobile_apis::VehicleDataResultCode::eType code_; }; +ResponseInfo::ResponseInfo() + : result_code(hmi_apis::Common_Result::INVALID_ENUM) + , interface(HmiInterfaces::HMI_INTERFACE_INVALID_ENUM) + , interface_state(HmiInterfaces::STATE_NOT_RESPONSE) + , is_ok(false) + , is_unsupported_resource(false) + , is_not_used(false) {} + +ResponseInfo::ResponseInfo(const hmi_apis::Common_Result::eType result, + const HmiInterfaces::InterfaceID hmi_interface, + ApplicationManager& application_manager) + : result_code(result) + , interface(hmi_interface) + , interface_state(HmiInterfaces::STATE_NOT_RESPONSE) + , is_ok(false) + , is_unsupported_resource(false) + , is_not_used(false) { + using namespace helpers; + + interface_state = + application_manager.hmi_interfaces().GetInterfaceState(hmi_interface); + + is_ok = Compare<hmi_apis::Common_Result::eType, EQ, ONE>( + result_code, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::WARNINGS, + hmi_apis::Common_Result::WRONG_LANGUAGE, + hmi_apis::Common_Result::RETRY, + hmi_apis::Common_Result::SAVED); + + is_not_used = hmi_apis::Common_Result::INVALID_ENUM == result_code; + + is_unsupported_resource = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == result_code; +} + CommandRequestImpl::CommandRequestImpl(const MessageSharedPtr& message, ApplicationManager& application_manager) : CommandImpl(message, application_manager) @@ -193,7 +240,7 @@ void CommandRequestImpl::onTimeOut() { function_id(), correlation_id(), mobile_api::Result::GENERIC_ERROR); - + AddTimeOutComponentInfoToMessage(*response); application_manager_.ManageMobileCommand(response, ORIGIN_SDL); } @@ -204,6 +251,7 @@ void CommandRequestImpl::SendResponse( const mobile_apis::Result::eType& result_code, const char* info, const smart_objects::SmartObject* response_params) { + LOG4CXX_AUTO_TRACE(logger_); { sync_primitives::AutoLock auto_lock(state_lock_); if (kTimedOut == current_state_) { @@ -214,11 +262,9 @@ void CommandRequestImpl::SendResponse( current_state_ = kCompleted; } - smart_objects::SmartObjectSPtr result = new smart_objects::SmartObject; - if (!result) { - LOG4CXX_ERROR(logger_, "Memory allocation failed."); - return; - } + smart_objects::SmartObjectSPtr result = + utils::MakeShared<smart_objects::SmartObject>(); + smart_objects::SmartObject& response = *result; response[strings::params][strings::message_type] = MessageType::kResponse; @@ -755,6 +801,7 @@ bool CommandRequestImpl::HasDisallowedParams() const { bool CommandRequestImpl::PrepareResultForMobileResponse( hmi_apis::Common_Result::eType result_code, HmiInterfaces::InterfaceID interface) const { + LOG4CXX_AUTO_TRACE(logger_); using namespace helpers; if (Compare<hmi_apis::Common_Result::eType, EQ, ONE>( result_code, @@ -777,48 +824,9 @@ bool CommandRequestImpl::PrepareResultForMobileResponse( bool CommandRequestImpl::PrepareResultForMobileResponse( ResponseInfo& out_first, ResponseInfo& out_second) const { - using namespace helpers; - - out_first.is_ok = Compare<hmi_apis::Common_Result::eType, EQ, ONE>( - out_first.result_code, - hmi_apis::Common_Result::SUCCESS, - hmi_apis::Common_Result::WARNINGS, - hmi_apis::Common_Result::WRONG_LANGUAGE, - hmi_apis::Common_Result::RETRY, - hmi_apis::Common_Result::SAVED); - - out_second.is_ok = Compare<hmi_apis::Common_Result::eType, EQ, ONE>( - out_second.result_code, - hmi_apis::Common_Result::SUCCESS, - hmi_apis::Common_Result::WARNINGS, - hmi_apis::Common_Result::WRONG_LANGUAGE, - hmi_apis::Common_Result::RETRY, - hmi_apis::Common_Result::SAVED); - - out_first.is_invalid_enum = - hmi_apis::Common_Result::INVALID_ENUM == out_first.result_code; - - out_second.is_invalid_enum = - hmi_apis::Common_Result::INVALID_ENUM == out_second.result_code; - - out_first.is_unsupported_resource = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == out_first.result_code; - - out_second.is_unsupported_resource = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE == out_second.result_code; - - out_first.interface_state = - application_manager_.hmi_interfaces().GetInterfaceState( - out_first.interface); - out_second.interface_state = - application_manager_.hmi_interfaces().GetInterfaceState( - out_second.interface); - - bool result = (out_first.is_ok && out_second.is_ok) || - (out_second.is_invalid_enum && out_first.is_ok) || - (out_first.is_invalid_enum && out_second.is_ok); - result = result || CheckResultCode(out_first, out_second); - result = result || CheckResultCode(out_second, out_first); + LOG4CXX_AUTO_TRACE(logger_); + bool result = CheckResultCode(out_first, out_second) || + CheckResultCode(out_second, out_first); return result; } @@ -835,25 +843,30 @@ void CommandRequestImpl::GetInfo( mobile_apis::Result::eType CommandRequestImpl::PrepareResultCodeForResponse( const ResponseInfo& first, const ResponseInfo& second) { + LOG4CXX_AUTO_TRACE(logger_); mobile_apis::Result::eType result_code = mobile_apis::Result::INVALID_ENUM; - if (IsResultCodeUnsupported(first, second)) { - result_code = mobile_apis::Result::UNSUPPORTED_RESOURCE; - } else { - // If response contains erroneous result code SDL need return erroneus - // result code. - hmi_apis::Common_Result::eType first_result = - hmi_apis::Common_Result::INVALID_ENUM; - hmi_apis::Common_Result::eType second_result = - hmi_apis::Common_Result::INVALID_ENUM; - if (!first.is_unsupported_resource) { - first_result = first.result_code; - } - if (!second.is_unsupported_resource) { - second_result = second.result_code; - } - result_code = - MessageHelper::HMIToMobileResult(std::max(first_result, second_result)); - } + if (IsResultCodeUnsupported(first, second) || + IsResultCodeUnsupported(second, first)) { + return mobile_apis::Result::UNSUPPORTED_RESOURCE; + } + if (IsResultCodeWarning(first, second) || + IsResultCodeWarning(second, first)) { + return mobile_apis::Result::WARNINGS; + } + // If response contains erroneous result code SDL need return erroneus + // result code. + hmi_apis::Common_Result::eType first_result = + hmi_apis::Common_Result::INVALID_ENUM; + hmi_apis::Common_Result::eType second_result = + hmi_apis::Common_Result::INVALID_ENUM; + if (!first.is_unsupported_resource) { + first_result = first.result_code; + } + if (!second.is_unsupported_resource) { + second_result = second.result_code; + } + result_code = + MessageHelper::HMIToMobileResult(std::max(first_result, second_result)); return result_code; } @@ -862,6 +875,100 @@ const CommandParametersPermissions& CommandRequestImpl::parameters_permissions() return parameters_permissions_; } +void CommandRequestImpl::StartAwaitForInterface( + const HmiInterfaces::InterfaceID interface_id) { + sync_primitives::AutoLock lock(awaiting_response_interfaces_lock_); + awaiting_response_interfaces_.insert(interface_id); +} + +bool CommandRequestImpl::IsInterfaceAwaited( + const HmiInterfaces::InterfaceID& interface_id) const { + sync_primitives::AutoLock lock(awaiting_response_interfaces_lock_); + std::set<HmiInterfaces::InterfaceID>::const_iterator it = + awaiting_response_interfaces_.find(interface_id); + return (it != awaiting_response_interfaces_.end()); +} + +void CommandRequestImpl::EndAwaitForInterface( + const HmiInterfaces::InterfaceID& interface_id) { + sync_primitives::AutoLock lock(awaiting_response_interfaces_lock_); + std::set<HmiInterfaces::InterfaceID>::const_iterator it = + awaiting_response_interfaces_.find(interface_id); + if (it != awaiting_response_interfaces_.end()) { + awaiting_response_interfaces_.erase(it); + } else { + LOG4CXX_WARN(logger_, + "EndAwaitForInterface called on interface \ + which was not put into await state: " + << interface_id); + } +} + +bool CommandRequestImpl::IsResultCodeUnsupported( + const ResponseInfo& first, const ResponseInfo& second) const { + const bool first_ok_second_unsupported = + (first.is_ok || first.is_not_used) && second.is_unsupported_resource; + const bool both_unsupported = + first.is_unsupported_resource && second.is_unsupported_resource; + return first_ok_second_unsupported || both_unsupported; +} + +std::string GetComponentNameFromInterface( + const HmiInterfaces::InterfaceID& interface) { + switch (interface) { + case HmiInterfaces::HMI_INTERFACE_Buttons: + return "Buttons"; + case HmiInterfaces::HMI_INTERFACE_BasicCommunication: + return "BasicCommunication"; + case HmiInterfaces::HMI_INTERFACE_VR: + return "VR"; + case HmiInterfaces::HMI_INTERFACE_TTS: + return "TTS"; + case HmiInterfaces::HMI_INTERFACE_UI: + return "UI"; + case HmiInterfaces::HMI_INTERFACE_Navigation: + return "Navigation"; + case HmiInterfaces::HMI_INTERFACE_VehicleInfo: + return "VehicleInfo"; + case HmiInterfaces::HMI_INTERFACE_SDL: + return "SDL"; + default: + return "Unknown type"; + } +} + +const std::string InfoInterfaceSeparator( + const std::string& sum, const HmiInterfaces::InterfaceID container_value) { + return sum.empty() + ? GetComponentNameFromInterface(container_value) + : sum + ", " + GetComponentNameFromInterface(container_value); +} + +void CommandRequestImpl::AddTimeOutComponentInfoToMessage( + smart_objects::SmartObject& response) const { + using NsSmartDeviceLink::NsSmartObjects::SmartObject; + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(awaiting_response_interfaces_lock_); + if (awaiting_response_interfaces_.empty()) { + LOG4CXX_ERROR(logger_, "No interfaces awaiting, info param is empty"); + return; + } + + const std::string not_responding_interfaces_string = + std::accumulate(awaiting_response_interfaces_.begin(), + awaiting_response_interfaces_.end(), + std::string(""), + InfoInterfaceSeparator); + LOG4CXX_DEBUG( + logger_, + "Not responding interfaces string: " << not_responding_interfaces_string); + if (!not_responding_interfaces_string.empty()) { + const std::string component_info = + not_responding_interfaces_string + " component does not respond"; + response[strings::msg_params][strings::info] = component_info; + } +} + } // namespace commands } // namespace application_manager diff --git a/src/components/application_manager/src/commands/hmi/basic_communication_on_awake_sdl.cc b/src/components/application_manager/src/commands/hmi/basic_communication_on_awake_sdl.cc index 80b1edb5bb..c6c550a474 100644 --- a/src/components/application_manager/src/commands/hmi/basic_communication_on_awake_sdl.cc +++ b/src/components/application_manager/src/commands/hmi/basic_communication_on_awake_sdl.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Ford Motor Company + * Copyright (c) 2017, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,3 +29,45 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ + +#include "application_manager/commands/hmi/basic_communication_on_awake_sdl.h" +#include "application_manager/message_helper.h" +#include "application_manager/resumption/resume_ctrl.h" + +namespace application_manager { + +namespace commands { + +OnAwakeSDLNotification::OnAwakeSDLNotification( + const MessageSharedPtr& message, ApplicationManager& application_manager) + : NotificationFromHMI(message, application_manager) {} + +OnAwakeSDLNotification::~OnAwakeSDLNotification() {} + +void OnAwakeSDLNotification::Run() { + LOG4CXX_AUTO_TRACE(logger_); + + if (!application_manager_.resume_controller().is_suspended()) { + return; + } + + { + DataAccessor<ApplicationSet> accessor = application_manager_.applications(); + ApplicationSetIt itBegin = accessor.GetData().begin(); + ApplicationSetIt itEnd = accessor.GetData().end(); + for (; itBegin != itEnd; ++itBegin) { + const ApplicationSharedPtr app = *itBegin; + if (app && app->IsHashChangedDuringSuspend()) { + MessageHelper::SendHashUpdateNotification(app->app_id(), + application_manager_); + app->SetHashChangedDuringSuspend(false); + } + } + } + + application_manager_.resume_controller().OnAwake(); +} + +} // namespace commands + +} // namespace application_manager diff --git a/src/components/application_manager/src/commands/hmi/navi_audio_start_stream_request.cc b/src/components/application_manager/src/commands/hmi/navi_audio_start_stream_request.cc index 0bcb26df8a..42b8c64fc0 100644 --- a/src/components/application_manager/src/commands/hmi/navi_audio_start_stream_request.cc +++ b/src/components/application_manager/src/commands/hmi/navi_audio_start_stream_request.cc @@ -109,6 +109,8 @@ void AudioStartStreamRequest::on_event(const event_engine::Event& event) { logger_, "StartAudioStreamRequest aborted. Application can not stream"); } + application_manager_.TerminateRequest( + connection_key(), correlation_id(), function_id()); break; } if (hmi_apis::Common_Result::REJECTED == code) { @@ -125,15 +127,16 @@ void AudioStartStreamRequest::on_event(const event_engine::Event& event) { } void AudioStartStreamRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); RetryStartSession(); - - application_manager_.TerminateRequest( - connection_key(), correlation_id(), function_id()); } void AudioStartStreamRequest::RetryStartSession() { LOG4CXX_AUTO_TRACE(logger_); + application_manager_.TerminateRequest( + connection_key(), correlation_id(), function_id()); + ApplicationSharedPtr app = application_manager_.application_by_hmi_app(application_id()); if (!app) { @@ -156,10 +159,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. retry_number = " << curr_retry_number); + LOG4CXX_DEBUG(logger_, "Send AudioStartStream retry"); MessageHelper::SendAudioStartStream(app->app_id(), application_manager_); app->set_audio_stream_retry_number(++curr_retry_number); } else { diff --git a/src/components/application_manager/src/commands/hmi/navi_start_stream_request.cc b/src/components/application_manager/src/commands/hmi/navi_start_stream_request.cc index b06c69e703..ffc325b5e4 100644 --- a/src/components/application_manager/src/commands/hmi/navi_start_stream_request.cc +++ b/src/components/application_manager/src/commands/hmi/navi_start_stream_request.cc @@ -109,6 +109,8 @@ void NaviStartStreamRequest::on_event(const event_engine::Event& event) { logger_, "NaviStartStreamRequest aborted. Application can not stream"); } + application_manager_.TerminateRequest( + connection_key(), correlation_id(), function_id()); break; } if (hmi_apis::Common_Result::REJECTED == code) { @@ -125,15 +127,16 @@ void NaviStartStreamRequest::on_event(const event_engine::Event& event) { } void NaviStartStreamRequest::onTimeOut() { + LOG4CXX_AUTO_TRACE(logger_); RetryStartSession(); - - application_manager_.TerminateRequest( - connection_key(), correlation_id(), function_id()); } void NaviStartStreamRequest::RetryStartSession() { LOG4CXX_AUTO_TRACE(logger_); + application_manager_.TerminateRequest( + connection_key(), correlation_id(), function_id()); + ApplicationSharedPtr app = application_manager_.application_by_hmi_app(application_id()); if (!app) { @@ -156,10 +159,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. retry_number = " << curr_retry_number); + LOG4CXX_DEBUG(logger_, "Send NaviStartStream retry"); MessageHelper::SendNaviStartStream(app->app_id(), application_manager_); app->set_video_stream_retry_number(++curr_retry_number); } else { diff --git a/src/components/application_manager/src/commands/hmi/notification_from_hmi.cc b/src/components/application_manager/src/commands/hmi/notification_from_hmi.cc index 64eb63fde8..3c2d73b10c 100644 --- a/src/components/application_manager/src/commands/hmi/notification_from_hmi.cc +++ b/src/components/application_manager/src/commands/hmi/notification_from_hmi.cc @@ -42,7 +42,7 @@ NotificationFromHMI::NotificationFromHMI( const MessageSharedPtr& message, ApplicationManager& application_manager) : CommandImpl(message, application_manager) { // Replace HMI app id with Mobile connection id - ReplaceHMIByMobileAppId(*message); + ReplaceHMIWithMobileAppId(*message); } NotificationFromHMI::~NotificationFromHMI() {} diff --git a/src/components/application_manager/src/commands/hmi/notification_to_hmi.cc b/src/components/application_manager/src/commands/hmi/notification_to_hmi.cc index f1e933b7ef..d52df950c3 100644 --- a/src/components/application_manager/src/commands/hmi/notification_to_hmi.cc +++ b/src/components/application_manager/src/commands/hmi/notification_to_hmi.cc @@ -39,15 +39,13 @@ namespace commands { NotificationToHMI::NotificationToHMI(const MessageSharedPtr& message, ApplicationManager& application_manager) - : CommandImpl(message, application_manager) { - // Replace Mobile connection id with HMI app id - ReplaceMobileByHMIAppId(*(message.get())); -} + : CommandImpl(message, application_manager) {} NotificationToHMI::~NotificationToHMI() {} bool NotificationToHMI::Init() { - return true; + // Replace Mobile connection id with HMI app id + return ReplaceMobileWithHMIAppId(*message_); } bool NotificationToHMI::CleanUp() { diff --git a/src/components/application_manager/src/commands/hmi/on_app_unregistered_notification.cc b/src/components/application_manager/src/commands/hmi/on_app_unregistered_notification.cc index 10ea1ea303..f64e3e111b 100644 --- a/src/components/application_manager/src/commands/hmi/on_app_unregistered_notification.cc +++ b/src/components/application_manager/src/commands/hmi/on_app_unregistered_notification.cc @@ -44,6 +44,12 @@ OnAppUnregisteredNotification::OnAppUnregisteredNotification( OnAppUnregisteredNotification::~OnAppUnregisteredNotification() {} +bool OnAppUnregisteredNotification::Init() { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, "Replacement of hmi id is skipped."); + return true; +} + void OnAppUnregisteredNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); diff --git a/src/components/application_manager/src/commands/hmi/on_driver_distraction_notification.cc b/src/components/application_manager/src/commands/hmi/on_driver_distraction_notification.cc index 4c322c456f..a895d353ce 100644 --- a/src/components/application_manager/src/commands/hmi/on_driver_distraction_notification.cc +++ b/src/components/application_manager/src/commands/hmi/on_driver_distraction_notification.cc @@ -34,8 +34,10 @@ #include "application_manager/commands/hmi/on_driver_distraction_notification.h" #include "application_manager/application_impl.h" +#include "application_manager/message_helper.h" #include "interfaces/MOBILE_API.h" #include "interfaces/HMI_API.h" +#include "utils/make_shared.h" namespace application_manager { @@ -43,6 +45,53 @@ namespace commands { namespace hmi { +namespace { +struct OnDriverDistractionProcessor { + OnDriverDistractionProcessor( + OnDriverDistractionNotification& command, + smart_objects::SmartObjectSPtr on_driver_distraction_so, + ApplicationManager& application_manager) + : command_(command) + , on_driver_distraction_so_(on_driver_distraction_so) + , application_manager_(application_manager) + , stringified_function_id_(MessageHelper::StringifiedFunctionID( + mobile_api::FunctionID::OnDriverDistractionID)) {} + + void operator()(ApplicationSharedPtr application) { + if (application) { + (*on_driver_distraction_so_)[strings::params][strings::connection_key] = + application->app_id(); + const RPCParams params; + policy::CheckPermissionResult result; + application_manager_.GetPolicyHandler().CheckPermissions( + application, stringified_function_id_, params, result); + if (result.hmi_level_permitted != policy::kRpcAllowed) { + MobileMessageQueue messages; + application->SwapMobileMessageQueue(messages); + messages.erase( + std::remove_if( + messages.begin(), + messages.end(), + [this](smart_objects::SmartObjectSPtr message) { + return (*message)[strings::params][strings::function_id] + .asString() == stringified_function_id_; + }), + messages.end()); + application->PushMobileMessage(on_driver_distraction_so_); + return; + } + command_.SendNotificationToMobile(on_driver_distraction_so_); + } + } + + private: + OnDriverDistractionNotification& command_; + smart_objects::SmartObjectSPtr on_driver_distraction_so_; + ApplicationManager& application_manager_; + std::string stringified_function_id_; +}; +} + OnDriverDistractionNotification::OnDriverDistractionNotification( const MessageSharedPtr& message, ApplicationManager& application_manager) : NotificationFromHMI(message, application_manager) {} @@ -51,38 +100,31 @@ OnDriverDistractionNotification::~OnDriverDistractionNotification() {} void OnDriverDistractionNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); - const hmi_apis::Common_DriverDistractionState::eType state = static_cast<hmi_apis::Common_DriverDistractionState::eType>( (*message_)[strings::msg_params][hmi_notification::state].asInt()); - application_manager_.set_driver_distraction(state); + application_manager_.set_driver_distraction_state(state); smart_objects::SmartObjectSPtr on_driver_distraction = - new smart_objects::SmartObject(); + utils::MakeShared<smart_objects::SmartObject>(); if (!on_driver_distraction) { LOG4CXX_ERROR(logger_, "NULL pointer"); return; } - (*on_driver_distraction)[strings::params][strings::function_id] = mobile_api::FunctionID::OnDriverDistractionID; - + (*on_driver_distraction)[strings::params][strings::message_type] = + static_cast<int32_t>(application_manager::MessageType::kNotification); (*on_driver_distraction)[strings::msg_params][mobile_notification::state] = state; const ApplicationSet applications = application_manager_.applications().GetData(); - ApplicationSetConstIt it = applications.begin(); - for (; applications.end() != it; ++it) { - const ApplicationSharedPtr app = *it; - if (app) { - (*on_driver_distraction)[strings::params][strings::connection_key] = - app->app_id(); - SendNotificationToMobile(on_driver_distraction); - } - } + OnDriverDistractionProcessor processor( + *this, on_driver_distraction, application_manager_); + std::for_each(applications.begin(), applications.end(), processor); } } // namespace hmi diff --git a/src/components/application_manager/src/commands/hmi/on_exit_all_applications_notification.cc b/src/components/application_manager/src/commands/hmi/on_exit_all_applications_notification.cc index 07a95adcea..cb68b21263 100644 --- a/src/components/application_manager/src/commands/hmi/on_exit_all_applications_notification.cc +++ b/src/components/application_manager/src/commands/hmi/on_exit_all_applications_notification.cc @@ -75,6 +75,7 @@ void OnExitAllApplicationsNotification::Run() { break; } case hmi_apis::Common_ApplicationsCloseReason::SUSPEND: { + application_manager_.resume_controller().OnSuspend(); SendOnSDLPersistenceComplete(); return; } diff --git a/src/components/application_manager/src/commands/hmi/on_vi_vehicle_data_notification.cc b/src/components/application_manager/src/commands/hmi/on_vi_vehicle_data_notification.cc index 5383876714..bba7e2f3ff 100644 --- a/src/components/application_manager/src/commands/hmi/on_vi_vehicle_data_notification.cc +++ b/src/components/application_manager/src/commands/hmi/on_vi_vehicle_data_notification.cc @@ -53,8 +53,9 @@ void OnVIVehicleDataNotification::Run() { const smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params]; if (msg_params.keyExists(strings::odometer)) { - application_manager_.IviInfoUpdated(ODOMETER, - msg_params[strings::odometer].asInt()); + application_manager_.IviInfoUpdated( + mobile_apis::VehicleDataType::VEHICLEDATA_ODOMETER, + msg_params[strings::odometer].asInt()); } SendNotificationToMobile(message_); diff --git a/src/components/application_manager/src/commands/hmi/request_from_hmi.cc b/src/components/application_manager/src/commands/hmi/request_from_hmi.cc index 1119e7c4fd..5a4e7b149e 100644 --- a/src/components/application_manager/src/commands/hmi/request_from_hmi.cc +++ b/src/components/application_manager/src/commands/hmi/request_from_hmi.cc @@ -43,7 +43,7 @@ RequestFromHMI::RequestFromHMI(const MessageSharedPtr& message, : CommandImpl(message, application_manager) , EventObserver(application_manager.event_dispatcher()) { // Replace HMI app id with Mobile connection id - ReplaceHMIByMobileAppId(*(message.get())); + ReplaceHMIWithMobileAppId(*message); } RequestFromHMI::~RequestFromHMI() {} diff --git a/src/components/application_manager/src/commands/hmi/request_to_hmi.cc b/src/components/application_manager/src/commands/hmi/request_to_hmi.cc index 39d549ac72..6905e7cdef 100644 --- a/src/components/application_manager/src/commands/hmi/request_to_hmi.cc +++ b/src/components/application_manager/src/commands/hmi/request_to_hmi.cc @@ -61,15 +61,13 @@ bool ChangeInterfaceState(ApplicationManager& application_manager, RequestToHMI::RequestToHMI(const MessageSharedPtr& message, ApplicationManager& application_manager) - : CommandImpl(message, application_manager) { - // Replace Mobile connection id with HMI app id - ReplaceMobileByHMIAppId(*(message.get())); -} + : CommandImpl(message, application_manager) {} RequestToHMI::~RequestToHMI() {} bool RequestToHMI::Init() { - return true; + // Replace Mobile connection id with HMI app id + return ReplaceMobileWithHMIAppId(*message_); } bool RequestToHMI::CleanUp() { diff --git a/src/components/application_manager/src/commands/hmi/response_from_hmi.cc b/src/components/application_manager/src/commands/hmi/response_from_hmi.cc index 23d8e6e229..d6d5d95d07 100644 --- a/src/components/application_manager/src/commands/hmi/response_from_hmi.cc +++ b/src/components/application_manager/src/commands/hmi/response_from_hmi.cc @@ -48,7 +48,7 @@ ResponseFromHMI::ResponseFromHMI(const MessageSharedPtr& message, } // Replace HMI app id with Mobile connection id - ReplaceHMIByMobileAppId(*(message.get())); + ReplaceHMIWithMobileAppId(*message); } ResponseFromHMI::~ResponseFromHMI() {} diff --git a/src/components/application_manager/src/commands/hmi/response_to_hmi.cc b/src/components/application_manager/src/commands/hmi/response_to_hmi.cc index e6f64047ba..de1e1e0fde 100644 --- a/src/components/application_manager/src/commands/hmi/response_to_hmi.cc +++ b/src/components/application_manager/src/commands/hmi/response_to_hmi.cc @@ -39,15 +39,13 @@ namespace commands { ResponseToHMI::ResponseToHMI(const MessageSharedPtr& message, ApplicationManager& application_manager) - : CommandImpl(message, application_manager) { - // Replace Mobile connection id with HMI app id - ReplaceMobileByHMIAppId(*(message.get())); -} + : CommandImpl(message, application_manager) {} ResponseToHMI::~ResponseToHMI() {} bool ResponseToHMI::Init() { - return true; + // Replace Mobile connection id with HMI app id + return ReplaceMobileWithHMIAppId(*message_); } bool ResponseToHMI::CleanUp() { diff --git a/src/components/application_manager/src/commands/mobile/add_command_request.cc b/src/components/application_manager/src/commands/mobile/add_command_request.cc index c748ddcbb6..69948b8122 100644 --- a/src/components/application_manager/src/commands/mobile/add_command_request.cc +++ b/src/components/application_manager/src/commands/mobile/add_command_request.cc @@ -192,10 +192,12 @@ void AddCommandRequest::Run() { } if (send_ui_) { + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest(hmi_apis::FunctionID::UI_AddCommand, &ui_msg_params, true); } if (send_vr_) { + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VR); SendHMIRequest(hmi_apis::FunctionID::VR_AddCommand, &vr_msg_params, true); } } @@ -317,6 +319,7 @@ void AddCommandRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::UI_AddCommand: { LOG4CXX_INFO(logger_, "Received UI_AddCommand event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); is_ui_received_ = true; ui_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); @@ -328,6 +331,7 @@ void AddCommandRequest::on_event(const event_engine::Event& event) { } case hmi_apis::FunctionID::VR_AddCommand: { LOG4CXX_INFO(logger_, "Received VR_AddCommand event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VR); is_vr_received_ = true; vr_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); diff --git a/src/components/application_manager/src/commands/mobile/add_sub_menu_request.cc b/src/components/application_manager/src/commands/mobile/add_sub_menu_request.cc index a5491481dc..fe44e5a41f 100644 --- a/src/components/application_manager/src/commands/mobile/add_sub_menu_request.cc +++ b/src/components/application_manager/src/commands/mobile/add_sub_menu_request.cc @@ -94,6 +94,7 @@ void AddSubMenuRequest::Run() { (*message_)[strings::msg_params][strings::menu_name]; msg_params[strings::app_id] = app->app_id(); + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest(hmi_apis::FunctionID::UI_AddSubMenu, &msg_params, true); } @@ -103,6 +104,7 @@ void AddSubMenuRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::UI_AddSubMenu: { + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); hmi_apis::Common_Result::eType result_code = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); diff --git a/src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc b/src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc index b151990289..d5767690d7 100644 --- a/src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc +++ b/src/components/application_manager/src/commands/mobile/alert_maneuver_request.cc @@ -111,6 +111,7 @@ void AlertManeuverRequest::Run() { } pending_requests_.Add(hmi_apis::FunctionID::Navigation_AlertManeuver); + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Navigation); SendHMIRequest( hmi_apis::FunctionID::Navigation_AlertManeuver, &msg_params, true); @@ -123,6 +124,7 @@ void AlertManeuverRequest::Run() { msg_params[hmi_request::speak_type] = hmi_apis::Common_MethodName::ALERT_MANEUVER; + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_TTS); SendHMIRequest(hmi_apis::FunctionID::TTS_Speak, &msg_params, true); } } @@ -134,6 +136,7 @@ void AlertManeuverRequest::on_event(const event_engine::Event& event) { switch (event_id) { case hmi_apis::FunctionID::Navigation_AlertManeuver: { LOG4CXX_INFO(logger_, "Received Navigation_AlertManeuver event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Navigation); pending_requests_.Remove(event_id); navi_alert_maneuver_result_code_ = static_cast<hmi_apis::Common_Result::eType>( @@ -143,6 +146,7 @@ void AlertManeuverRequest::on_event(const event_engine::Event& event) { } case hmi_apis::FunctionID::TTS_Speak: { LOG4CXX_INFO(logger_, "Received TTS_Speak event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_TTS); pending_requests_.Remove(event_id); tts_speak_result_code_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); @@ -191,10 +195,13 @@ bool AlertManeuverRequest::PrepareResponseParameters( application_manager::commands::ResponseInfo navigation_alert_info( navi_alert_maneuver_result_code_, - HmiInterfaces::HMI_INTERFACE_Navigation); + HmiInterfaces::HMI_INTERFACE_Navigation, + application_manager_); application_manager::commands::ResponseInfo tts_alert_info( - tts_speak_result_code_, HmiInterfaces::HMI_INTERFACE_TTS); + tts_speak_result_code_, + HmiInterfaces::HMI_INTERFACE_TTS, + application_manager_); const bool result = PrepareResultForMobileResponse(navigation_alert_info, tts_alert_info); @@ -216,23 +223,42 @@ bool AlertManeuverRequest::PrepareResponseParameters( bool AlertManeuverRequest::IsWhiteSpaceExist() { LOG4CXX_AUTO_TRACE(logger_); - const char* str = NULL; + using smart_objects::SmartArray; if ((*message_)[strings::msg_params].keyExists(strings::tts_chunks)) { - const smart_objects::SmartArray* tc_array = + const SmartArray* tts_chunks_arr = (*message_)[strings::msg_params][strings::tts_chunks].asArray(); - smart_objects::SmartArray::const_iterator it_tc = tc_array->begin(); - smart_objects::SmartArray::const_iterator it_tc_end = tc_array->end(); + SmartArray::const_iterator it_tts_chunk = tts_chunks_arr->begin(); - for (; it_tc != it_tc_end; ++it_tc) { - str = (*it_tc)[strings::text].asCharArray(); - if (strlen(str) && !CheckSyntax(str)) { + for (; it_tts_chunk != tts_chunks_arr->end(); ++it_tts_chunk) { + const char* tts_chunk_text = (*it_tts_chunk)[strings::text].asCharArray(); + if (strlen(tts_chunk_text) && !CheckSyntax(tts_chunk_text)) { LOG4CXX_ERROR(logger_, "Invalid tts_chunks syntax check failed"); return true; } } } + if ((*message_)[strings::msg_params].keyExists(strings::soft_buttons)) { + DCHECK_OR_RETURN( + (*message_)[strings::msg_params][strings::soft_buttons].getType() == + smart_objects::SmartType_Array, + true); + const smart_objects::SmartArray* soft_button_array = + (*message_)[strings::msg_params][strings::soft_buttons].asArray(); + + SmartArray::const_iterator it_soft_button = soft_button_array->begin(); + + for (; it_soft_button != soft_button_array->end(); ++it_soft_button) { + const char* soft_button_text = + (*it_soft_button)[strings::text].asCharArray(); + if (!CheckSyntax(soft_button_text)) { + LOG4CXX_ERROR(logger_, "Invalid soft_buttons syntax check failed"); + return true; + } + } + } + return false; } diff --git a/src/components/application_manager/src/commands/mobile/alert_request.cc b/src/components/application_manager/src/commands/mobile/alert_request.cc index 3288870b92..3c42e43767 100644 --- a/src/components/application_manager/src/commands/mobile/alert_request.cc +++ b/src/components/application_manager/src/commands/mobile/alert_request.cc @@ -116,18 +116,6 @@ void AlertRequest::Run() { } } -void AlertRequest::onTimeOut() { - LOG4CXX_AUTO_TRACE(logger_); - if (false == - (*message_)[strings::msg_params].keyExists(strings::soft_buttons)) { - CommandRequestImpl::onTimeOut(); - return; - } - LOG4CXX_INFO(logger_, - "Default timeout ignored. " - "AlertRequest with soft buttons wait timeout on HMI side"); -} - void AlertRequest::on_event(const event_engine::Event& event) { LOG4CXX_AUTO_TRACE(logger_); const smart_objects::SmartObject& message = event.smart_object(); @@ -148,6 +136,7 @@ void AlertRequest::on_event(const event_engine::Event& event) { case hmi_apis::FunctionID::UI_Alert: { LOG4CXX_INFO(logger_, "Received UI_Alert event"); // Unsubscribe from event to avoid unwanted messages + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); unsubscribe_from_event(hmi_apis::FunctionID::UI_Alert); awaiting_ui_alert_response_ = false; HmiInterfaces::InterfaceState ui_interface_state = @@ -157,6 +146,7 @@ void AlertRequest::on_event(const event_engine::Event& event) { if (awaiting_tts_speak_response_ && HmiInterfaces::STATE_NOT_AVAILABLE != ui_interface_state) { awaiting_tts_stop_speaking_response_ = true; + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_TTS); SendHMIRequest(hmi_apis::FunctionID::TTS_StopSpeaking, NULL, true); } alert_result_ = static_cast<hmi_apis::Common_Result::eType>( @@ -170,6 +160,7 @@ void AlertRequest::on_event(const event_engine::Event& event) { case hmi_apis::FunctionID::TTS_Speak: { LOG4CXX_INFO(logger_, "Received TTS_Speak event"); // Unsubscribe from event to avoid unwanted messages + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_TTS); unsubscribe_from_event(hmi_apis::FunctionID::TTS_Speak); awaiting_tts_speak_response_ = false; tts_speak_result_ = static_cast<hmi_apis::Common_Result::eType>( @@ -179,6 +170,7 @@ void AlertRequest::on_event(const event_engine::Event& event) { } case hmi_apis::FunctionID::TTS_StopSpeaking: { LOG4CXX_INFO(logger_, "Received TTS_StopSpeaking event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_TTS); // Unsubscribe from event to avoid unwanted messages unsubscribe_from_event(hmi_apis::FunctionID::TTS_StopSpeaking); awaiting_tts_stop_speaking_response_ = false; @@ -204,9 +196,11 @@ void AlertRequest::on_event(const event_engine::Event& event) { bool AlertRequest::PrepareResponseParameters( mobile_apis::Result::eType& result_code, std::string& info) { - ResponseInfo ui_alert_info(alert_result_, HmiInterfaces::HMI_INTERFACE_UI); + ResponseInfo ui_alert_info( + alert_result_, HmiInterfaces::HMI_INTERFACE_UI, application_manager_); ResponseInfo tts_alert_info(tts_speak_result_, - HmiInterfaces::HMI_INTERFACE_TTS); + HmiInterfaces::HMI_INTERFACE_TTS, + application_manager_); bool result = PrepareResultForMobileResponse(ui_alert_info, tts_alert_info); @@ -219,7 +213,7 @@ bool AlertRequest::PrepareResponseParameters( result = false; } result_code = mobile_apis::Result::WARNINGS; - if ((ui_alert_info.is_ok || ui_alert_info.is_invalid_enum) && + if ((ui_alert_info.is_ok || ui_alert_info.is_not_used) && tts_alert_info.is_unsupported_resource && HmiInterfaces::STATE_AVAILABLE == tts_alert_info.interface_state) { tts_response_info_ = "Unsupported phoneme type sent in a prompt"; @@ -230,6 +224,10 @@ bool AlertRequest::PrepareResponseParameters( result_code = PrepareResultCodeForResponse(ui_alert_info, tts_alert_info); info = MergeInfos( ui_alert_info, ui_response_info_, tts_alert_info, tts_response_info_); + // Mobile Alert request is successful when UI_Alert is successful + if (is_ui_alert_sent_ && !ui_alert_info.is_ok) { + return false; + } return result; } @@ -346,6 +344,7 @@ void AlertRequest::SendAlertRequest(int32_t app_id) { msg_params.keyExists(hmi_request::soft_buttons)) { awaiting_ui_alert_response_ = true; is_ui_alert_sent_ = true; + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest(hmi_apis::FunctionID::UI_Alert, &msg_params, true); } } @@ -370,6 +369,7 @@ void AlertRequest::SendSpeakRequest(int32_t app_id, } msg_params[strings::app_id] = app_id; msg_params[hmi_request::speak_type] = Common_MethodName::ALERT; + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_TTS); SendHMIRequest(FunctionID::TTS_Speak, &msg_params, true); } diff --git a/src/components/application_manager/src/commands/mobile/change_registration_request.cc b/src/components/application_manager/src/commands/mobile/change_registration_request.cc index f1f3b93e24..f55767c723 100644 --- a/src/components/application_manager/src/commands/mobile/change_registration_request.cc +++ b/src/components/application_manager/src/commands/mobile/change_registration_request.cc @@ -66,6 +66,73 @@ ChangeRegistrationRequest::ChangeRegistrationRequest( ChangeRegistrationRequest::~ChangeRegistrationRequest() {} +void ChangeRegistrationRequest::SendVRRequest( + ApplicationSharedPtr app, smart_objects::SmartObject& msg_params) { + const HmiInterfaces& hmi_interfaces = application_manager_.hmi_interfaces(); + auto function = hmi_apis::FunctionID::VR_ChangeRegistration; + pending_requests_.Add(function); + smart_objects::SmartObject vr_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + vr_params[strings::language] = msg_params[strings::language]; + + vr_params[strings::app_id] = app->app_id(); + if (msg_params.keyExists(strings::vr_synonyms)) { + vr_params[strings::vr_synonyms] = msg_params[strings::vr_synonyms]; + app->set_vr_synonyms(msg_params[strings::vr_synonyms]); + } + StartAwaitForInterface(hmi_interfaces.GetInterfaceFromFunction(function)); + SendHMIRequest(function, &vr_params, true); +} + +void ChangeRegistrationRequest::SendTTSRequest( + ApplicationSharedPtr app, smart_objects::SmartObject& msg_params) { + const HmiInterfaces& hmi_interfaces = application_manager_.hmi_interfaces(); + auto function = hmi_apis::FunctionID::TTS_ChangeRegistration; + pending_requests_.Add(function); + + smart_objects::SmartObject tts_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + tts_params[strings::language] = msg_params[strings::language]; + + tts_params[strings::app_id] = app->app_id(); + if (msg_params.keyExists(strings::tts_name)) { + tts_params[strings::tts_name] = msg_params[strings::tts_name]; + app->set_tts_name(msg_params[strings::tts_name]); + } + StartAwaitForInterface(hmi_interfaces.GetInterfaceFromFunction(function)); + SendHMIRequest(function, &tts_params, true); +} + +void ChangeRegistrationRequest::SendUIRequest( + ApplicationSharedPtr app, + smart_objects::SmartObject& msg_params, + const int32_t hmi_language) { + const HmiInterfaces& hmi_interfaces = application_manager_.hmi_interfaces(); + auto function = hmi_apis::FunctionID::UI_ChangeRegistration; + pending_requests_.Add(function); + // UI processing + smart_objects::SmartObject ui_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + ui_params[strings::language] = hmi_language; + ui_params[strings::app_id] = app->app_id(); + if (msg_params.keyExists(strings::app_name)) { + ui_params[strings::app_name] = msg_params[strings::app_name]; + app->set_name(msg_params[strings::app_name].asCustomString()); + } + if (msg_params.keyExists(strings::ngn_media_screen_app_name)) { + ui_params[strings::ngn_media_screen_app_name] = + msg_params[strings::ngn_media_screen_app_name]; + app->set_ngn_media_screen_name( + msg_params[strings::ngn_media_screen_app_name]); + } + + StartAwaitForInterface(hmi_interfaces.GetInterfaceFromFunction(function)); + SendHMIRequest(function, &ui_params, true); +} + void ChangeRegistrationRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); using namespace smart_objects; @@ -111,53 +178,42 @@ void ChangeRegistrationRequest::Run() { return; } - pending_requests_.Add(hmi_apis::FunctionID::UI_ChangeRegistration); - pending_requests_.Add(hmi_apis::FunctionID::VR_ChangeRegistration); - pending_requests_.Add(hmi_apis::FunctionID::TTS_ChangeRegistration); + const HmiInterfaces& hmi_interfaces = application_manager_.hmi_interfaces(); - // UI processing - SmartObject ui_params = SmartObject(SmartType_Map); + const HmiInterfaces::InterfaceState vr_state = + hmi_interfaces.GetInterfaceState( + HmiInterfaces::InterfaceID::HMI_INTERFACE_VR); + const HmiInterfaces::InterfaceState ui_state = + hmi_interfaces.GetInterfaceState( + HmiInterfaces::InterfaceID::HMI_INTERFACE_UI); + const HmiInterfaces::InterfaceState tts_state = + hmi_interfaces.GetInterfaceState( + HmiInterfaces::InterfaceID::HMI_INTERFACE_TTS); - ui_params[strings::language] = hmi_language; - ui_params[strings::app_id] = app->app_id(); - if (msg_params.keyExists(strings::app_name)) { - ui_params[strings::app_name] = msg_params[strings::app_name]; - app->set_name(msg_params[strings::app_name].asCustomString()); + using helpers::Compare; + using helpers::EQ; + using helpers::ALL; + + if (Compare<HmiInterfaces::InterfaceState, EQ, ALL>( + HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE, + vr_state, + tts_state, + ui_state)) { + SendResponse(false, mobile_apis::Result::UNSUPPORTED_RESOURCE); + return; } - if (msg_params.keyExists(strings::ngn_media_screen_app_name)) { - ui_params[strings::ngn_media_screen_app_name] = - msg_params[strings::ngn_media_screen_app_name]; - app->set_ngn_media_screen_name( - msg_params[strings::ngn_media_screen_app_name]); + if (HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE != vr_state) { + // VR processing + SendVRRequest(app, msg_params); } - - SendHMIRequest(hmi_apis::FunctionID::UI_ChangeRegistration, &ui_params, true); - - // VR processing - SmartObject vr_params = SmartObject(SmartType_Map); - - vr_params[strings::language] = msg_params[strings::language]; - - vr_params[strings::app_id] = app->app_id(); - if (msg_params.keyExists(strings::vr_synonyms)) { - vr_params[strings::vr_synonyms] = msg_params[strings::vr_synonyms]; - app->set_vr_synonyms(msg_params[strings::vr_synonyms]); + if (HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE != tts_state) { + // TTS processing + SendTTSRequest(app, msg_params); } - SendHMIRequest(hmi_apis::FunctionID::VR_ChangeRegistration, &vr_params, true); - - // TTS processing - SmartObject tts_params = SmartObject(SmartType_Map); - tts_params[strings::language] = msg_params[strings::language]; - - tts_params[strings::app_id] = app->app_id(); - if (msg_params.keyExists(strings::tts_name)) { - tts_params[strings::tts_name] = msg_params[strings::tts_name]; - app->set_tts_name(msg_params[strings::tts_name]); + if (HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE != ui_state) { + SendUIRequest(app, msg_params, hmi_language); } - - SendHMIRequest( - hmi_apis::FunctionID::TTS_ChangeRegistration, &tts_params, true); } void ChangeRegistrationRequest::on_event(const event_engine::Event& event) { @@ -169,6 +225,7 @@ void ChangeRegistrationRequest::on_event(const event_engine::Event& event) { switch (event_id) { case hmi_apis::FunctionID::UI_ChangeRegistration: { LOG4CXX_INFO(logger_, "Received UI_ChangeRegistration event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); pending_requests_.Remove(event_id); ui_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); @@ -177,6 +234,7 @@ void ChangeRegistrationRequest::on_event(const event_engine::Event& event) { } case hmi_apis::FunctionID::VR_ChangeRegistration: { LOG4CXX_INFO(logger_, "Received VR_ChangeRegistration event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VR); pending_requests_.Remove(event_id); vr_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); @@ -185,6 +243,7 @@ void ChangeRegistrationRequest::on_event(const event_engine::Event& event) { } case hmi_apis::FunctionID::TTS_ChangeRegistration: { LOG4CXX_INFO(logger_, "Received TTS_ChangeRegistration event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_TTS); pending_requests_.Remove(event_id); tts_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); @@ -295,12 +354,14 @@ bool ChangeRegistrationRequest::PrepareResponseParameters( hmi_interfaces.GetInterfaceState( HmiInterfaces::InterfaceID::HMI_INTERFACE_UI); - ResponseInfo ui_properties_info(ui_result_, HmiInterfaces::HMI_INTERFACE_UI); + ResponseInfo ui_properties_info( + ui_result_, HmiInterfaces::HMI_INTERFACE_UI, application_manager_); - ResponseInfo tts_properties_info(tts_result_, - HmiInterfaces::HMI_INTERFACE_TTS); + ResponseInfo tts_properties_info( + tts_result_, HmiInterfaces::HMI_INTERFACE_TTS, application_manager_); - ResponseInfo vr_properties_info(ui_result_, HmiInterfaces::HMI_INTERFACE_VR); + ResponseInfo vr_properties_info( + ui_result_, HmiInterfaces::HMI_INTERFACE_VR, application_manager_); bool result = ((!is_tts_ui_vr_unsupported) && is_tts_succeeded_unsupported && is_ui_succeeded_unsupported && is_vr_succeeded_unsupported); @@ -338,6 +399,9 @@ bool ChangeRegistrationRequest::PrepareResponseParameters( } result_code = MessageHelper::HMIToMobileResult( std::max(std::max(ui_result, vr_result), tts_result)); + if (mobile_api::Result::INVALID_ENUM == result_code) { + result_code = mobile_api::Result::UNSUPPORTED_RESOURCE; + } } const bool is_tts_state_available = diff --git a/src/components/application_manager/src/commands/mobile/create_interaction_choice_set_request.cc b/src/components/application_manager/src/commands/mobile/create_interaction_choice_set_request.cc index e1148bd126..20387ef230 100644 --- a/src/components/application_manager/src/commands/mobile/create_interaction_choice_set_request.cc +++ b/src/components/application_manager/src/commands/mobile/create_interaction_choice_set_request.cc @@ -287,6 +287,7 @@ void CreateInteractionChoiceSetRequest::SendVRAddCommandRequests( sync_primitives::AutoLock commands_lock(vr_commands_lock_); const uint32_t vr_cmd_id = msg_params[strings::cmd_id].asUInt(); + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VR); const uint32_t vr_corr_id = SendHMIRequest(hmi_apis::FunctionID::VR_AddCommand, &msg_params, true); @@ -356,6 +357,7 @@ void CreateInteractionChoiceSetRequest::on_event( uint32_t corr_id = static_cast<uint32_t>( message[strings::params][strings::correlation_id].asUInt()); if (event.id() == hmi_apis::FunctionID::VR_AddCommand) { + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VR); { sync_primitives::AutoLock commands_lock(vr_commands_lock_); if (is_no_error) { @@ -376,6 +378,7 @@ void CreateInteractionChoiceSetRequest::onTimeOut() { if (!error_from_hmi_) { SendResponse(false, mobile_apis::Result::GENERIC_ERROR); } + CommandRequestImpl::onTimeOut(); DeleteChoices(); // We have to keep request alive until receive all responses from HMI diff --git a/src/components/application_manager/src/commands/mobile/delete_command_request.cc b/src/components/application_manager/src/commands/mobile/delete_command_request.cc index cfc8e12144..f894ed452c 100644 --- a/src/components/application_manager/src/commands/mobile/delete_command_request.cc +++ b/src/components/application_manager/src/commands/mobile/delete_command_request.cc @@ -104,12 +104,14 @@ void DeleteCommandRequest::Run() { is_vr_send_ = true; } if (is_ui_send_) { + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest(hmi_apis::FunctionID::UI_DeleteCommand, &msg_params, true); } if (is_vr_send_) { // VR params msg_params[strings::grammar_id] = application->get_grammar_id(); msg_params[strings::type] = hmi_apis::Common_VRCommandType::Command; + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VR); SendHMIRequest(hmi_apis::FunctionID::VR_DeleteCommand, &msg_params, true); } } @@ -117,8 +119,10 @@ void DeleteCommandRequest::Run() { bool DeleteCommandRequest::PrepareResponseParameters( mobile_apis::Result::eType& result_code, std::string& info) { using namespace helpers; - ResponseInfo ui_delete_info(ui_result_, HmiInterfaces::HMI_INTERFACE_UI); - ResponseInfo vr_delete_info(vr_result_, HmiInterfaces::HMI_INTERFACE_VR); + ResponseInfo ui_delete_info( + ui_result_, HmiInterfaces::HMI_INTERFACE_UI, application_manager_); + ResponseInfo vr_delete_info( + vr_result_, HmiInterfaces::HMI_INTERFACE_VR, application_manager_); const bool result = PrepareResultForMobileResponse(ui_delete_info, vr_delete_info); @@ -143,6 +147,7 @@ void DeleteCommandRequest::on_event(const event_engine::Event& event) { const smart_objects::SmartObject& message = event.smart_object(); switch (event.id()) { case hmi_apis::FunctionID::UI_DeleteCommand: { + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); is_ui_received_ = true; ui_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); @@ -153,6 +158,7 @@ void DeleteCommandRequest::on_event(const event_engine::Event& event) { break; } case hmi_apis::FunctionID::VR_DeleteCommand: { + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VR); is_vr_received_ = true; vr_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); diff --git a/src/components/application_manager/src/commands/mobile/delete_sub_menu_request.cc b/src/components/application_manager/src/commands/mobile/delete_sub_menu_request.cc index 21c7ecce90..09f3139245 100644 --- a/src/components/application_manager/src/commands/mobile/delete_sub_menu_request.cc +++ b/src/components/application_manager/src/commands/mobile/delete_sub_menu_request.cc @@ -74,6 +74,7 @@ void DeleteSubMenuRequest::Run() { msg_params[strings::menu_id] = (*message_)[strings::msg_params][strings::menu_id]; msg_params[strings::app_id] = app->app_id(); + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest(hmi_apis::FunctionID::UI_DeleteSubMenu, &msg_params, true); } @@ -143,6 +144,7 @@ void DeleteSubMenuRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::UI_DeleteSubMenu: { + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); hmi_apis::Common_Result::eType result_code = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); diff --git a/src/components/application_manager/src/commands/mobile/diagnostic_message_request.cc b/src/components/application_manager/src/commands/mobile/diagnostic_message_request.cc index 5c5d250026..7704d700f9 100644 --- a/src/components/application_manager/src/commands/mobile/diagnostic_message_request.cc +++ b/src/components/application_manager/src/commands/mobile/diagnostic_message_request.cc @@ -83,6 +83,7 @@ void DiagnosticMessageRequest::Run() { // Add app_id for HMI request (*message_)[strings::msg_params][strings::app_id] = app->app_id(); + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VehicleInfo); SendHMIRequest(hmi_apis::FunctionID::VehicleInfo_DiagnosticMessage, &(*message_)[strings::msg_params], true); @@ -94,6 +95,7 @@ void DiagnosticMessageRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::VehicleInfo_DiagnosticMessage: { + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VehicleInfo); hmi_apis::Common_Result::eType result_code = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); diff --git a/src/components/application_manager/src/commands/mobile/dial_number_request.cc b/src/components/application_manager/src/commands/mobile/dial_number_request.cc index 64685afe2e..d0ab42e266 100644 --- a/src/components/application_manager/src/commands/mobile/dial_number_request.cc +++ b/src/components/application_manager/src/commands/mobile/dial_number_request.cc @@ -87,6 +87,7 @@ void DialNumberRequest::Run() { (*message_)[strings::msg_params][strings::number].asString(); msg_params[strings::app_id] = application->hmi_app_id(); + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_BasicCommunication); SendHMIRequest( hmi_apis::FunctionID::BasicCommunication_DialNumber, &msg_params, true); } @@ -106,6 +107,7 @@ void DialNumberRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::BasicCommunication_DialNumber: { LOG4CXX_INFO(logger_, "Received DialNumber event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_BasicCommunication); result_code = CommandRequestImpl::GetMobileResultCode( static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt())); diff --git a/src/components/application_manager/src/commands/mobile/end_audio_pass_thru_request.cc b/src/components/application_manager/src/commands/mobile/end_audio_pass_thru_request.cc index f67d1f2434..fb168e4256 100644 --- a/src/components/application_manager/src/commands/mobile/end_audio_pass_thru_request.cc +++ b/src/components/application_manager/src/commands/mobile/end_audio_pass_thru_request.cc @@ -47,6 +47,7 @@ EndAudioPassThruRequest::~EndAudioPassThruRequest() {} void EndAudioPassThruRequest::Run() { LOG4CXX_AUTO_TRACE(logger_); + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest(hmi_apis::FunctionID::UI_EndAudioPassThru, NULL, true); } @@ -56,6 +57,7 @@ void EndAudioPassThruRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::UI_EndAudioPassThru: { + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); hmi_apis::Common_Result::eType result_code = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asUInt()); @@ -64,9 +66,10 @@ void EndAudioPassThruRequest::on_event(const event_engine::Event& event) { const bool result = PrepareResultForMobileResponse( result_code, HmiInterfaces::HMI_INTERFACE_UI); if (result) { - bool ended_successfully = application_manager_.EndAudioPassThrough(); + uint32_t app_id = connection_key(); + bool ended_successfully = application_manager_.EndAudioPassThru(app_id); if (ended_successfully) { - application_manager_.StopAudioPassThru(connection_key()); + application_manager_.StopAudioPassThru(app_id); } } diff --git a/src/components/application_manager/src/commands/mobile/get_dtcs_request.cc b/src/components/application_manager/src/commands/mobile/get_dtcs_request.cc index d98207c772..88fd07234a 100644 --- a/src/components/application_manager/src/commands/mobile/get_dtcs_request.cc +++ b/src/components/application_manager/src/commands/mobile/get_dtcs_request.cc @@ -72,6 +72,7 @@ void GetDTCsRequest::Run() { msg_params[strings::app_id] = app->app_id(); + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VehicleInfo); SendHMIRequest(hmi_apis::FunctionID::VehicleInfo_GetDTCs, &msg_params, true); } @@ -81,6 +82,7 @@ void GetDTCsRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::VehicleInfo_GetDTCs: { + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VehicleInfo); hmi_apis::Common_Result::eType result_code = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); diff --git a/src/components/application_manager/src/commands/mobile/get_vehicle_data_request.cc b/src/components/application_manager/src/commands/mobile/get_vehicle_data_request.cc index 25e2da3eb6..f81d0a8c2a 100644 --- a/src/components/application_manager/src/commands/mobile/get_vehicle_data_request.cc +++ b/src/components/application_manager/src/commands/mobile/get_vehicle_data_request.cc @@ -57,7 +57,7 @@ void GetVehicleDataRequest::Run() { int32_t app_id = (*message_)[strings::params][strings::connection_key].asUInt(); - ApplicationSharedPtr app = appplication_manager.application(app_id); + ApplicationSharedPtr app = application_manager_.application(app_id); if (!app) { LOG4CXX_ERROR(logger_, "NULL pointer"); @@ -250,6 +250,7 @@ void GetVehicleDataRequest::Run() { } } if (msg_params.length() > min_length_msg_params) { + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VehicleInfo); SendHMIRequest( hmi_apis::FunctionID::VehicleInfo_GetVehicleData, &msg_params, true); return; @@ -266,6 +267,7 @@ void GetVehicleDataRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::VehicleInfo_GetVehicleData: { + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VehicleInfo); hmi_apis::Common_Result::eType result_code = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); diff --git a/src/components/application_manager/src/commands/mobile/get_way_points_request.cc b/src/components/application_manager/src/commands/mobile/get_way_points_request.cc index c313d74d4b..da4ce38646 100644 --- a/src/components/application_manager/src/commands/mobile/get_way_points_request.cc +++ b/src/components/application_manager/src/commands/mobile/get_way_points_request.cc @@ -31,6 +31,7 @@ void GetWayPointsRequest::Run() { msg_params = (*message_)[strings::msg_params]; msg_params[strings::app_id] = app->app_id(); + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Navigation); SendHMIRequest(hmi_apis::FunctionID::Navigation_GetWayPoints, msg_params.empty() ? NULL : &msg_params, true); @@ -48,6 +49,7 @@ void GetWayPointsRequest::on_event(const event_engine::Event& event) { } case hmi_apis::FunctionID::Navigation_GetWayPoints: { LOG4CXX_INFO(logger_, "Received Navigation_GetWayPoints event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Navigation); const hmi_apis::Common_Result::eType result_code = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); diff --git a/src/components/application_manager/src/commands/mobile/on_hmi_status_notification.cc b/src/components/application_manager/src/commands/mobile/on_hmi_status_notification.cc index 5225002652..f408d04955 100644 --- a/src/components/application_manager/src/commands/mobile/on_hmi_status_notification.cc +++ b/src/components/application_manager/src/commands/mobile/on_hmi_status_notification.cc @@ -60,17 +60,8 @@ void OnHMIStatusNotification::Run() { mobile_apis::HMILevel::eType hmi_level = static_cast<mobile_apis::HMILevel::eType>( (*message_)[strings::msg_params][strings::hmi_level].asInt()); - if ((mobile_apis::HMILevel::HMI_BACKGROUND == hmi_level) || - (mobile_apis::HMILevel::HMI_NONE == hmi_level)) { - if (!(app->tts_properties_in_none())) { - app->set_tts_properties_in_none(true); - LOG4CXX_INFO(logger_, - "OnHMIStatusNotification::Send TTS GlobalProperties" - " with empty array to HMI"); - MessageHelper::SendTTSGlobalProperties(app, false, application_manager_); - } - } else if ((mobile_apis::HMILevel::HMI_FULL == hmi_level) || - (mobile_apis::HMILevel::HMI_LIMITED == hmi_level)) { + if ((mobile_apis::HMILevel::HMI_FULL == hmi_level) || + (mobile_apis::HMILevel::HMI_LIMITED == hmi_level)) { if (!(app->tts_properties_in_full())) { app->set_tts_properties_in_full(true); LOG4CXX_INFO(logger_, diff --git a/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc b/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc index 9f5fd937f9..20076ac50c 100644 --- a/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc +++ b/src/components/application_manager/src/commands/mobile/perform_audio_pass_thru_request.cc @@ -47,8 +47,6 @@ namespace str = strings; PerformAudioPassThruRequest::PerformAudioPassThruRequest( const MessageSharedPtr& message, ApplicationManager& application_manager) : CommandRequestImpl(message, application_manager) - , awaiting_tts_speak_response_(false) - , awaiting_ui_response_(false) , result_tts_speak_(hmi_apis::Common_Result::INVALID_ENUM) , result_ui_(hmi_apis::Common_Result::INVALID_ENUM) { subscribe_on_event(hmi_apis::FunctionID::TTS_OnResetTimeout); @@ -97,7 +95,7 @@ void PerformAudioPassThruRequest::Run() { // According with new implementation processing of UNSUPPORTE_RESOURCE // need set flag before sending to hmi - awaiting_ui_response_ = true; + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); if ((*message_)[str::msg_params].keyExists(str::initial_prompt) && (0 < (*message_)[str::msg_params][str::initial_prompt].length())) { // In case TTS Speak, subscribe on notification @@ -119,7 +117,7 @@ void PerformAudioPassThruRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::UI_PerformAudioPassThru: { LOG4CXX_TRACE(logger_, "Received UI_PerformAudioPassThru"); - awaiting_ui_response_ = false; + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); result_ui_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asUInt()); @@ -142,7 +140,7 @@ void PerformAudioPassThruRequest::on_event(const event_engine::Event& event) { result_tts_speak_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asUInt()); GetInfo(message, tts_info_); - awaiting_tts_speak_response_ = false; + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_TTS); const bool is_tts_speak_success_unsuported = Compare<hmi_apis::Common_Result::eType, EQ, ONE>( result_tts_speak_, @@ -179,36 +177,58 @@ void PerformAudioPassThruRequest::on_event(const event_engine::Event& event) { return; } - std::string return_info; - mobile_apis::Result::eType result_code = mobile_apis::Result::INVALID_ENUM; - const bool result = PrepareResponseParameters(result_code, return_info); + const ResponseParams response_params = PrepareResponseParameters(); - SendResponse(result, - result_code, - return_info.empty() ? NULL : return_info.c_str(), - &(message[strings::msg_params])); + SendResponse( + response_params.success, + response_params.result_code, + response_params.info.empty() ? NULL : response_params.info.c_str(), + &(message[strings::msg_params])); } -bool PerformAudioPassThruRequest::PrepareResponseParameters( - mobile_apis::Result::eType& result_code, std::string& info) { +const PerformAudioPassThruRequest::ResponseParams& +PerformAudioPassThruRequest::PrepareResponseParameters() { LOG4CXX_AUTO_TRACE(logger_); - ResponseInfo ui_perform_info(result_ui_, HmiInterfaces::HMI_INTERFACE_UI); + ResponseInfo ui_perform_info( + result_ui_, HmiInterfaces::HMI_INTERFACE_UI, application_manager_); ResponseInfo tts_perform_info(result_tts_speak_, - HmiInterfaces::HMI_INTERFACE_TTS); - const bool result = - PrepareResultForMobileResponse(ui_perform_info, tts_perform_info); + HmiInterfaces::HMI_INTERFACE_TTS, + application_manager_); + // Note(dtrunov): According to requirment "WARNINGS, success:true on getting + // UNSUPPORTED_RESOURCE for "ttsChunks" if (ui_perform_info.is_ok && tts_perform_info.is_unsupported_resource && HmiInterfaces::STATE_AVAILABLE == tts_perform_info.interface_state) { - result_code = mobile_apis::Result::WARNINGS; + response_params_.result_code = mobile_apis::Result::WARNINGS; tts_info_ = "Unsupported phoneme type sent in a prompt"; - info = MergeInfos(ui_perform_info, ui_info_, tts_perform_info, tts_info_); - return result; + response_params_.info = + MergeInfos(ui_perform_info, ui_info_, tts_perform_info, tts_info_); + response_params_.success = true; + return response_params_; } - result_code = PrepareResultCodeForResponse(ui_perform_info, tts_perform_info); - info = MergeInfos(ui_perform_info, ui_info_, tts_perform_info, tts_info_); - return result; + + response_params_.success = + PrepareResultForMobileResponse(ui_perform_info, tts_perform_info); + if (IsResultCodeUnsupported(ui_perform_info, tts_perform_info)) { + response_params_.result_code = mobile_apis::Result::UNSUPPORTED_RESOURCE; + } else { + AudioPassThruResults results = PrepareAudioPassThruResultCodeForResponse( + ui_perform_info, tts_perform_info); + response_params_.success = results.second; + response_params_.result_code = results.first; + } + response_params_.info = + MergeInfos(ui_perform_info, ui_info_, tts_perform_info, tts_info_); + + return response_params_; +} + +bool PerformAudioPassThruRequest::PrepareResponseParameters( + mobile_apis::Result::eType& result_code, std::string& info) { + LOG4CXX_AUTO_TRACE(logger_); + NOTREACHED(); + return false; } void PerformAudioPassThruRequest::SendSpeakRequest() { @@ -229,7 +249,7 @@ void PerformAudioPassThruRequest::SendSpeakRequest() { // app_id msg_params[strings::app_id] = connection_key(); msg_params[hmi_request::speak_type] = Common_MethodName::AUDIO_PASS_THRU; - awaiting_tts_speak_response_ = true; + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_TTS); SendHMIRequest(FunctionID::TTS_Speak, &msg_params, true); } @@ -273,6 +293,7 @@ void PerformAudioPassThruRequest::SendPerformAudioPassThruRequest() { msg_params[str::mute_audio] = true; } + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest( hmi_apis::FunctionID::UI_PerformAudioPassThru, &msg_params, true); } @@ -290,7 +311,8 @@ void PerformAudioPassThruRequest::SendRecordStartNotification() { void PerformAudioPassThruRequest::StartMicrophoneRecording() { LOG4CXX_AUTO_TRACE(logger_); - application_manager_.BeginAudioPassThrough(); + uint32_t app_id = connection_key(); + application_manager_.BeginAudioPassThru(app_id); application_manager_.StartAudioPassThruThread( connection_key(), @@ -349,20 +371,61 @@ bool PerformAudioPassThruRequest::IsWhiteSpaceExist() { void PerformAudioPassThruRequest::FinishTTSSpeak() { LOG4CXX_AUTO_TRACE(logger_); - if (application_manager_.EndAudioPassThrough()) { + uint32_t app_id = connection_key(); + if (application_manager_.EndAudioPassThru(app_id)) { LOG4CXX_DEBUG(logger_, "Stop AudioPassThru."); - application_manager_.StopAudioPassThru(connection_key()); + application_manager_.StopAudioPassThru(app_id); } - if (!awaiting_tts_speak_response_) { + if (!IsInterfaceAwaited(HmiInterfaces::HMI_INTERFACE_TTS)) { LOG4CXX_WARN(logger_, "TTS Speak is inactive."); return; } SendHMIRequest(hmi_apis::FunctionID::TTS_StopSpeaking, NULL); } +PerformAudioPassThruRequest::AudioPassThruResults +PerformAudioPassThruRequest::PrepareAudioPassThruResultCodeForResponse( + const ResponseInfo& ui_response, const ResponseInfo& tts_response) { + mobile_apis::Result::eType result_code = mobile_apis::Result::INVALID_ENUM; + + hmi_apis::Common_Result::eType common_result = + hmi_apis::Common_Result::INVALID_ENUM; + const hmi_apis::Common_Result::eType ui_result = ui_response.result_code; + const hmi_apis::Common_Result::eType tts_result = tts_response.result_code; + bool result = false; + + if ((ui_result == hmi_apis::Common_Result::SUCCESS) && + (tts_result == hmi_apis::Common_Result::SUCCESS)) { + result = true; + } + + if ((ui_result == hmi_apis::Common_Result::SUCCESS) && + (tts_result == hmi_apis::Common_Result::INVALID_ENUM)) { + result = true; + } + + if ((ui_result == hmi_apis::Common_Result::SUCCESS) && + (tts_result != hmi_apis::Common_Result::SUCCESS) && + (tts_result != hmi_apis::Common_Result::INVALID_ENUM)) { + common_result = hmi_apis::Common_Result::WARNINGS; + result = true; + } else if (ui_response.is_ok && + tts_result == hmi_apis::Common_Result::WARNINGS) { + common_result = hmi_apis::Common_Result::WARNINGS; + result = true; + } else if (ui_result == hmi_apis::Common_Result::INVALID_ENUM) { + common_result = tts_result; + } else { + common_result = ui_result; + } + result_code = MessageHelper::HMIToMobileResult(common_result); + return std::make_pair(result_code, result); +} + bool PerformAudioPassThruRequest::IsWaitingHMIResponse() { LOG4CXX_AUTO_TRACE(logger_); - return awaiting_tts_speak_response_ || awaiting_ui_response_; + return IsInterfaceAwaited(HmiInterfaces::HMI_INTERFACE_TTS) || + IsInterfaceAwaited(HmiInterfaces::HMI_INTERFACE_UI); } } // namespace commands diff --git a/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc b/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc index 007440e8e6..68940158b9 100644 --- a/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc +++ b/src/components/application_manager/src/commands/mobile/perform_interaction_request.cc @@ -143,11 +143,10 @@ void PerformInteractionRequest::Run() { } } - if (choice_set_id_list_length && - (!CheckChoiceIDFromRequest( - app, - choice_set_id_list_length, - msg_params[strings::interaction_choice_set_id_list]))) { + if (!CheckChoiceIDFromRequest( + app, + choice_set_id_list_length, + msg_params[strings::interaction_choice_set_id_list])) { LOG4CXX_ERROR(logger_, "PerformInteraction has choice sets with " "duplicated IDs or application does not have choice sets"); @@ -227,6 +226,7 @@ void PerformInteractionRequest::on_event(const event_engine::Event& event) { } case hmi_apis::FunctionID::UI_PerformInteraction: { LOG4CXX_DEBUG(logger_, "Received UI_PerformInteraction event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); ui_response_received_ = true; unsubscribe_from_event(hmi_apis::FunctionID::UI_PerformInteraction); ui_result_code_ = static_cast<hmi_apis::Common_Result::eType>( @@ -237,6 +237,7 @@ void PerformInteractionRequest::on_event(const event_engine::Event& event) { } case hmi_apis::FunctionID::VR_PerformInteraction: { LOG4CXX_DEBUG(logger_, "Received VR_PerformInteraction"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VR); vr_response_received_ = true; unsubscribe_from_event(hmi_apis::FunctionID::VR_PerformInteraction); vr_result_code_ = static_cast<hmi_apis::Common_Result::eType>( @@ -392,14 +393,14 @@ void PerformInteractionRequest::ProcessUIResponse( if (result) { if (is_pi_warning) { ui_result_code_ = hmi_apis::Common_Result::WARNINGS; - ui_info_ = "Unsupported phoneme type was sent in an item"; + ui_info_ = message[strings::msg_params][strings::info].asString(); if (message.keyExists(strings::params) && message[strings::params].keyExists(strings::data)) { msg_params = message[strings::params][strings::data]; } } else if (is_pi_unsupported) { ui_result_code_ = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - ui_info_ = "Unsupported phoneme type was sent in an item"; + ui_info_ = message[strings::msg_params][strings::info].asString(); } else if (message.keyExists(strings::msg_params)) { msg_params = message[strings::msg_params]; } @@ -503,6 +504,7 @@ void PerformInteractionRequest::SendUIPerformInteractionRequest( (*message_)[strings::msg_params][hmi_request::interaction_layout] .asInt(); } + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest( hmi_apis::FunctionID::UI_PerformInteraction, &msg_params, true); } @@ -595,6 +597,7 @@ void PerformInteractionRequest::SendVRPerformInteractionRequest( msg_params[strings::timeout] = default_timeout_; } msg_params[strings::app_id] = app->app_id(); + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VR); SendHMIRequest( hmi_apis::FunctionID::VR_PerformInteraction, &msg_params, true); } @@ -926,10 +929,10 @@ void PerformInteractionRequest::SendBothModeResponse( LOG4CXX_AUTO_TRACE(logger_); mobile_apis::Result::eType perform_interaction_result_code = mobile_apis::Result::INVALID_ENUM; - ResponseInfo ui_perform_info(ui_result_code_, - HmiInterfaces::HMI_INTERFACE_UI); - ResponseInfo vr_perform_info(vr_result_code_, - HmiInterfaces::HMI_INTERFACE_VR); + ResponseInfo ui_perform_info( + ui_result_code_, HmiInterfaces::HMI_INTERFACE_UI, application_manager_); + ResponseInfo vr_perform_info( + vr_result_code_, HmiInterfaces::HMI_INTERFACE_VR, application_manager_); const bool result = PrepareResultForMobileResponse(ui_perform_info, vr_perform_info); perform_interaction_result_code = diff --git a/src/components/application_manager/src/commands/mobile/read_did_request.cc b/src/components/application_manager/src/commands/mobile/read_did_request.cc index 0bf747bde3..c51f545e7e 100644 --- a/src/components/application_manager/src/commands/mobile/read_did_request.cc +++ b/src/components/application_manager/src/commands/mobile/read_did_request.cc @@ -87,6 +87,7 @@ void ReadDIDRequest::Run() { (*message_)[strings::msg_params][strings::ecu_name]; msg_params[strings::did_location] = (*message_)[strings::msg_params][strings::did_location]; + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VehicleInfo); SendHMIRequest(hmi_apis::FunctionID::VehicleInfo_ReadDID, &msg_params, true); } @@ -97,6 +98,7 @@ void ReadDIDRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::VehicleInfo_ReadDID: { + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VehicleInfo); hmi_apis::Common_Result::eType result_code = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); diff --git a/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc b/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc index 5185d9e5a6..a3a30ddb20 100644 --- a/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc +++ b/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc @@ -46,6 +46,7 @@ #include "application_manager/message_helper.h" #include "application_manager/resumption/resume_ctrl.h" #include "application_manager/policies/policy_handler.h" +#include "application_manager/helpers/application_helper.h" #include "config_profile/profile.h" #include "interfaces/MOBILE_API.h" #include "interfaces/generated_msg_version.h" @@ -217,6 +218,10 @@ void RegisterAppInterfaceRequest::Run() { return; } + if (IsApplicationSwitched()) { + return; + } + const std::string mobile_app_id = (*message_)[strings::msg_params][strings::app_id].asString(); @@ -231,7 +236,13 @@ void RegisterAppInterfaceRequest::Run() { const smart_objects::SmartObject& msg_params = (*message_)[strings::msg_params]; - const std::string& policy_app_id = msg_params[strings::app_id].asString(); + const std::string policy_app_id = msg_params[strings::app_id].asString(); + std::string new_policy_app_id = policy_app_id; + std::transform(policy_app_id.begin(), + policy_app_id.end(), + new_policy_app_id.begin(), + ::tolower); + (*message_)[strings::msg_params][strings::app_id] = new_policy_app_id; if (application_manager_.IsApplicationForbidden(connection_key(), policy_app_id)) { @@ -359,7 +370,7 @@ void RegisterAppInterfaceRequest::Run() { GetPolicyHandler().SetDeviceInfo(device_mac, device_info); - SendRegisterAppInterfaceResponseToMobile(); + SendRegisterAppInterfaceResponseToMobile(ApplicationType::kNewApplication); smart_objects::SmartObjectSPtr so = GetLockScreenIconUrlNotification(connection_key(), application); application_manager_.ManageMobileCommand(so, commands::Command::ORIGIN_SDL); @@ -498,7 +509,8 @@ void FillUIRelatedFields(smart_objects::SmartObject& response_params, hmi_capabilities.rc_supported(); } -void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile() { +void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( + ApplicationType app_type) { LOG4CXX_AUTO_TRACE(logger_); smart_objects::SmartObject response_params(smart_objects::SmartType_Map); @@ -569,18 +581,27 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile() { FillUIRelatedFields(response_params, hmi_capabilities); } + if (HmiInterfaces::STATE_NOT_AVAILABLE != + application_manager_.hmi_interfaces().GetInterfaceState( + HmiInterfaces::HMI_INTERFACE_VehicleInfo)) { + FillVIRelatedFields(response_params, hmi_capabilities); + } + if (hmi_capabilities.button_capabilities()) { response_params[hmi_response::button_capabilities] = *hmi_capabilities.button_capabilities(); } + if (hmi_capabilities.soft_button_capabilities()) { response_params[hmi_response::soft_button_capabilities] = *hmi_capabilities.soft_button_capabilities(); } + if (hmi_capabilities.preset_bank_capabilities()) { response_params[hmi_response::preset_bank_capabilities] = *hmi_capabilities.preset_bank_capabilities(); } + if (hmi_capabilities.hmi_zone_capabilities()) { if (smart_objects::SmartType_Array == hmi_capabilities.hmi_zone_capabilities()->getType()) { @@ -593,23 +614,11 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile() { } } - if (HmiInterfaces::STATE_NOT_AVAILABLE != - application_manager_.hmi_interfaces().GetInterfaceState( - HmiInterfaces::HMI_INTERFACE_TTS)) { - FillTTSRelatedFields(response_params, hmi_capabilities); - } - if (hmi_capabilities.pcm_stream_capabilities()) { response_params[strings::pcm_stream_capabilities] = *hmi_capabilities.pcm_stream_capabilities(); } - if (HmiInterfaces::STATE_NOT_AVAILABLE != - application_manager_.hmi_interfaces().GetInterfaceState( - HmiInterfaces::HMI_INTERFACE_VehicleInfo)) { - FillVIRelatedFields(response_params, hmi_capabilities); - } - const std::vector<uint32_t>& diag_modes = application_manager_.get_settings().supported_diag_modes(); if (!diag_modes.empty()) { @@ -620,6 +629,7 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile() { ++index; } } + response_params[strings::sdl_version] = application_manager_.get_settings().sdl_version(); const std::string ccpu_version = @@ -628,6 +638,27 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile() { response_params[strings::system_software_version] = ccpu_version; } + if (ApplicationType::kSwitchedApplicationWrongHashId == app_type) { + LOG4CXX_DEBUG(logger_, + "Application has been switched from another transport, " + "but doesn't have correct hashID."); + + application_manager::DeleteApplicationData(application, + application_manager_); + + SendResponse( + true, mobile_apis::Result::RESUME_FAILED, NULL, &response_params); + return; + } + + if (ApplicationType::kSwitchedApplicationHashOk == app_type) { + LOG4CXX_DEBUG(logger_, + "Application has been switched from another transport " + "and has correct hashID."); + SendResponse(true, mobile_apis::Result::SUCCESS, NULL, &response_params); + return; + } + bool resumption = (*message_)[strings::msg_params].keyExists(strings::hash_id); @@ -710,6 +741,11 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile() { SendChangeRegistrationOnHMI(application); } +DEPRECATED void +RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile() { + SendRegisterAppInterfaceResponseToMobile(ApplicationType::kNewApplication); +} + void RegisterAppInterfaceRequest::SendChangeRegistration( const hmi_apis::FunctionID::eType function_id, const int32_t language, @@ -1191,6 +1227,56 @@ void RegisterAppInterfaceRequest::SendSubscribeCustomButtonNotification() { CreateHMINotification(FunctionID::Buttons_OnButtonSubscription, msg_params); } +bool RegisterAppInterfaceRequest::IsApplicationSwitched() { + const smart_objects::SmartObject& msg_params = + (*message_)[strings::msg_params]; + + const std::string& policy_app_id = msg_params[strings::app_id].asString(); + + LOG4CXX_DEBUG(logger_, "Looking for application id " << policy_app_id); + + auto app = application_manager_.application_by_policy_id(policy_app_id); + + if (!app) { + LOG4CXX_DEBUG(logger_, + "Application with policy id " << policy_app_id + << " is not found."); + return false; + } + + LOG4CXX_DEBUG(logger_, + "Application with policy id " << policy_app_id << " is found."); + if (!application_manager_.IsAppInReconnectMode(policy_app_id)) { + LOG4CXX_DEBUG(logger_, + "Policy id " << policy_app_id + << " is not found in reconnection list."); + SendResponse(false, mobile_apis::Result::APPLICATION_REGISTERED_ALREADY); + return false; + } + + LOG4CXX_DEBUG(logger_, "Application is found in reconnection list."); + + auto app_type = ApplicationType::kSwitchedApplicationWrongHashId; + if ((*message_)[strings::msg_params].keyExists(strings::hash_id)) { + const auto hash_id = + (*message_)[strings::msg_params][strings::hash_id].asString(); + + auto& resume_ctrl = application_manager_.resume_controller(); + if (resume_ctrl.CheckApplicationHash(app, hash_id)) { + app_type = ApplicationType::kSwitchedApplicationHashOk; + } + } + + application_manager_.ProcessReconnection(app, connection_key()); + SendRegisterAppInterfaceResponseToMobile(app_type); + + application_manager_.SendHMIStatusNotification(app); + + application_manager_.OnApplicationSwitched(app); + + return true; +} + policy::PolicyHandlerInterface& RegisterAppInterfaceRequest::GetPolicyHandler() { return application_manager_.GetPolicyHandler(); diff --git a/src/components/application_manager/src/commands/mobile/reset_global_properties_request.cc b/src/components/application_manager/src/commands/mobile/reset_global_properties_request.cc index 713d50e190..a7c2db0e65 100644 --- a/src/components/application_manager/src/commands/mobile/reset_global_properties_request.cc +++ b/src/components/application_manager/src/commands/mobile/reset_global_properties_request.cc @@ -46,10 +46,6 @@ namespace commands { ResetGlobalPropertiesRequest::ResetGlobalPropertiesRequest( const MessageSharedPtr& message, ApplicationManager& application_manager) : CommandRequestImpl(message, application_manager) - , is_ui_send_(false) - , is_tts_send_(false) - , is_ui_received_(false) - , is_tts_received_(false) , ui_result_(hmi_apis::Common_Result::INVALID_ENUM) , tts_result_(hmi_apis::Common_Result::INVALID_ENUM) {} @@ -111,11 +107,11 @@ void ResetGlobalPropertiesRequest::Run() { if (vr_help_title_items || menu_name || menu_icon || is_key_board_properties) { - is_ui_send_ = true; + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); } if (timeout_prompt || helpt_promt) { - is_tts_send_ = true; + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_TTS); } app->set_reset_global_properties_active(true); @@ -245,7 +241,7 @@ void ResetGlobalPropertiesRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::UI_SetGlobalProperties: { LOG4CXX_INFO(logger_, "Received UI_SetGlobalProperties event"); - is_ui_received_ = true; + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); ui_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); GetInfo(message, ui_response_info_); @@ -253,7 +249,7 @@ void ResetGlobalPropertiesRequest::on_event(const event_engine::Event& event) { } case hmi_apis::FunctionID::TTS_SetGlobalProperties: { LOG4CXX_INFO(logger_, "Received TTS_SetGlobalProperties event"); - is_tts_received_ = true; + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_TTS); tts_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); GetInfo(message, tts_response_info_); @@ -292,9 +288,10 @@ bool ResetGlobalPropertiesRequest::PrepareResponseParameters( using namespace helpers; bool result = false; - ResponseInfo ui_properties_info(ui_result_, HmiInterfaces::HMI_INTERFACE_UI); - ResponseInfo tts_properties_info(tts_result_, - HmiInterfaces::HMI_INTERFACE_TTS); + ResponseInfo ui_properties_info( + ui_result_, HmiInterfaces::HMI_INTERFACE_UI, application_manager_); + ResponseInfo tts_properties_info( + tts_result_, HmiInterfaces::HMI_INTERFACE_TTS, application_manager_); HmiInterfaces::InterfaceState tts_interface_state = application_manager_.hmi_interfaces().GetInterfaceState( @@ -321,7 +318,8 @@ bool ResetGlobalPropertiesRequest::PrepareResponseParameters( } bool ResetGlobalPropertiesRequest::IsPendingResponseExist() { - return is_ui_send_ != is_ui_received_ || is_tts_send_ != is_tts_received_; + return IsInterfaceAwaited(HmiInterfaces::HMI_INTERFACE_TTS) || + IsInterfaceAwaited(HmiInterfaces::HMI_INTERFACE_UI); } } // namespace commands diff --git a/src/components/application_manager/src/commands/mobile/scrollable_message_request.cc b/src/components/application_manager/src/commands/mobile/scrollable_message_request.cc index 0c770953fe..b0b2d5f464 100644 --- a/src/components/application_manager/src/commands/mobile/scrollable_message_request.cc +++ b/src/components/application_manager/src/commands/mobile/scrollable_message_request.cc @@ -109,7 +109,7 @@ void ScrollableMessageRequest::Run() { MessageHelper::SubscribeApplicationToSoftButton( (*message_)[strings::msg_params], app, function_id()); } - + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest(hmi_apis::FunctionID::UI_ScrollableMessage, &msg_params, true); } @@ -126,6 +126,7 @@ void ScrollableMessageRequest::on_event(const event_engine::Event& event) { } case hmi_apis::FunctionID::UI_ScrollableMessage: { LOG4CXX_INFO(logger_, "Received UI_ScrollableMessage event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); hmi_apis::Common_Result::eType result_code = static_cast<hmi_apis::Common_Result::eType>( diff --git a/src/components/application_manager/src/commands/mobile/send_location_request.cc b/src/components/application_manager/src/commands/mobile/send_location_request.cc index 9ec4ca3fcc..54664a8771 100644 --- a/src/components/application_manager/src/commands/mobile/send_location_request.cc +++ b/src/components/application_manager/src/commands/mobile/send_location_request.cc @@ -125,6 +125,7 @@ void SendLocationRequest::Run() { SmartObject request_msg_params = SmartObject(smart_objects::SmartType_Map); request_msg_params = msg_params; request_msg_params[strings::app_id] = app->hmi_app_id(); + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Navigation); SendHMIRequest( hmi_apis::FunctionID::Navigation_SendLocation, &request_msg_params, true); } @@ -135,6 +136,7 @@ void SendLocationRequest::on_event(const event_engine::Event& event) { const smart_objects::SmartObject& message = event.smart_object(); if (hmi_apis::FunctionID::Navigation_SendLocation == event.id()) { LOG4CXX_INFO(logger_, "Received Navigation_SendLocation event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Navigation); const Common_Result::eType result_code = static_cast<Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); std::string response_info; diff --git a/src/components/application_manager/src/commands/mobile/set_app_icon_request.cc b/src/components/application_manager/src/commands/mobile/set_app_icon_request.cc index 5afddfb4d0..ee544e956a 100644 --- a/src/components/application_manager/src/commands/mobile/set_app_icon_request.cc +++ b/src/components/application_manager/src/commands/mobile/set_app_icon_request.cc @@ -114,7 +114,7 @@ void SetAppIconRequest::Run() { // for further use in on_event function (*message_)[strings::msg_params][strings::sync_file_name] = msg_params[strings::sync_file_name]; - + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest(hmi_apis::FunctionID::UI_SetAppIcon, &msg_params, true); } @@ -242,6 +242,7 @@ void SetAppIconRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::UI_SetAppIcon: { + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); hmi_apis::Common_Result::eType result_code = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); diff --git a/src/components/application_manager/src/commands/mobile/set_display_layout_request.cc b/src/components/application_manager/src/commands/mobile/set_display_layout_request.cc index 984690384a..38b62ce731 100644 --- a/src/components/application_manager/src/commands/mobile/set_display_layout_request.cc +++ b/src/components/application_manager/src/commands/mobile/set_display_layout_request.cc @@ -58,6 +58,7 @@ void SetDisplayLayoutRequest::Run() { } (*message_)[strings::msg_params][strings::app_id] = app->app_id(); + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest(hmi_apis::FunctionID::UI_SetDisplayLayout, &((*message_)[strings::msg_params]), true); @@ -70,6 +71,7 @@ void SetDisplayLayoutRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::UI_SetDisplayLayout: { LOG4CXX_INFO(logger_, "Received UI_SetDisplayLayout event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); hmi_apis::Common_Result::eType result_code = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); diff --git a/src/components/application_manager/src/commands/mobile/set_global_properties_request.cc b/src/components/application_manager/src/commands/mobile/set_global_properties_request.cc index 096c4ed783..75d08f9f26 100644 --- a/src/components/application_manager/src/commands/mobile/set_global_properties_request.cc +++ b/src/components/application_manager/src/commands/mobile/set_global_properties_request.cc @@ -152,6 +152,9 @@ void SetGlobalPropertiesRequest::Run() { params[strings::app_id] = app->app_id(); SendUIRequest(params, true); + + auto& help_prompt_manager = app->help_prompt_manager(); + help_prompt_manager.OnSetGlobalPropertiesReceived(params, false); } else { LOG4CXX_DEBUG(logger_, "VRHelp params does not present"); DCHECK_OR_RETURN_VOID(!is_vr_help_title_present && !is_vr_help_present); @@ -159,15 +162,6 @@ void SetGlobalPropertiesRequest::Run() { smart_objects::SmartObject params = smart_objects::SmartObject(smart_objects::SmartType_Map); - if (ValidateVRHelpTitle(app->vr_help_title())) { - LOG4CXX_DEBUG(logger_, "App already contains VRHelp data"); - } else { - if (!PrepareUIRequestDefaultVRHelpData(app, params)) { - LOG4CXX_ERROR(logger_, "default VRHElp data could not be generated"); - SendResponse(false, mobile_apis::Result::INVALID_DATA); - return; - } - } PrepareUIRequestMenuAndKeyboardData(app, msg_params, params); // Preparing data @@ -197,6 +191,9 @@ void SetGlobalPropertiesRequest::Run() { params[strings::app_id] = app->app_id(); SendTTSRequest(params, true); + + auto& help_prompt_manager = app->help_prompt_manager(); + help_prompt_manager.OnSetGlobalPropertiesReceived(params, false); } } @@ -226,21 +223,34 @@ void SetGlobalPropertiesRequest::on_event(const event_engine::Event& event) { using namespace helpers; const smart_objects::SmartObject& message = event.smart_object(); + ApplicationSharedPtr application = + application_manager_.application(connection_key()); + switch (event.id()) { case hmi_apis::FunctionID::UI_SetGlobalProperties: { LOG4CXX_INFO(logger_, "Received UI_SetGlobalProperties event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); is_ui_received_ = true; ui_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); GetInfo(message, ui_response_info_); + if (application.valid()) { + auto& help_prompt_manager = application->help_prompt_manager(); + help_prompt_manager.OnSetGlobalPropertiesReceived(message, true); + } break; } case hmi_apis::FunctionID::TTS_SetGlobalProperties: { LOG4CXX_INFO(logger_, "Received TTS_SetGlobalProperties event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_TTS); is_tts_received_ = true; tts_result_ = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); GetInfo(message, tts_response_info_); + if (application.valid()) { + auto& help_prompt_manager = application->help_prompt_manager(); + help_prompt_manager.OnSetGlobalPropertiesReceived(message, true); + } break; } default: { @@ -257,10 +267,6 @@ void SetGlobalPropertiesRequest::on_event(const event_engine::Event& event) { std::string response_info; const bool result = PrepareResponseParameters(result_code, response_info); - // TODO{ALeshin} APPLINK-15858. connection_key removed during SendResponse - ApplicationSharedPtr application = - application_manager_.application(connection_key()); - SendResponse(result, result_code, response_info.empty() ? NULL : response_info.c_str(), @@ -277,10 +283,11 @@ bool SetGlobalPropertiesRequest::PrepareResponseParameters( LOG4CXX_AUTO_TRACE(logger_); using namespace helpers; - ResponseInfo ui_properties_info(ui_result_, HmiInterfaces::HMI_INTERFACE_UI); + ResponseInfo ui_properties_info( + ui_result_, HmiInterfaces::HMI_INTERFACE_UI, application_manager_); - ResponseInfo tts_properties_info(tts_result_, - HmiInterfaces::HMI_INTERFACE_TTS); + ResponseInfo tts_properties_info( + tts_result_, HmiInterfaces::HMI_INTERFACE_TTS, application_manager_); const bool result = PrepareResultForMobileResponse(ui_properties_info, tts_properties_info); if (result && @@ -397,6 +404,7 @@ void SetGlobalPropertiesRequest::SendTTSRequest( const smart_objects::SmartObject& params, bool use_events) { LOG4CXX_AUTO_TRACE(logger_); is_tts_send_ = true; + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_TTS); SendHMIRequest( hmi_apis::FunctionID::TTS_SetGlobalProperties, ¶ms, use_events); } @@ -405,6 +413,7 @@ void SetGlobalPropertiesRequest::SendUIRequest( const smart_objects::SmartObject& params, bool use_events) { LOG4CXX_AUTO_TRACE(logger_); is_ui_send_ = true; + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest( hmi_apis::FunctionID::UI_SetGlobalProperties, ¶ms, use_events); } diff --git a/src/components/application_manager/src/commands/mobile/set_icon_request.cc b/src/components/application_manager/src/commands/mobile/set_icon_request.cc index 85f34aead9..037de54456 100644 --- a/src/components/application_manager/src/commands/mobile/set_icon_request.cc +++ b/src/components/application_manager/src/commands/mobile/set_icon_request.cc @@ -95,7 +95,7 @@ void SetIconRequest::Run() { // for further use in on_event function (*message_)[strings::msg_params][strings::sync_file_name] = msg_params[strings::sync_file_name]; - + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest(hmi_apis::FunctionID::UI_SetAppIcon, &msg_params, true); } @@ -105,6 +105,7 @@ void SetIconRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::UI_SetAppIcon: { + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); mobile_apis::Result::eType result_code = static_cast<mobile_apis::Result::eType>( message[strings::params][hmi_response::code].asInt()); diff --git a/src/components/application_manager/src/commands/mobile/set_media_clock_timer_request.cc b/src/components/application_manager/src/commands/mobile/set_media_clock_timer_request.cc index 1e0a00318d..54727abe01 100644 --- a/src/components/application_manager/src/commands/mobile/set_media_clock_timer_request.cc +++ b/src/components/application_manager/src/commands/mobile/set_media_clock_timer_request.cc @@ -71,6 +71,7 @@ void SetMediaClockRequest::Run() { // copy entirely msg msg_params = (*message_)[strings::msg_params]; msg_params[strings::app_id] = app->app_id(); + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest( hmi_apis::FunctionID::UI_SetMediaClockTimer, &msg_params, true); @@ -85,6 +86,7 @@ void SetMediaClockRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::UI_SetMediaClockTimer: { + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); hmi_apis::Common_Result::eType result_code = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); diff --git a/src/components/application_manager/src/commands/mobile/show_constant_tbt_request.cc b/src/components/application_manager/src/commands/mobile/show_constant_tbt_request.cc index b1cc40009d..42bfea4864 100644 --- a/src/components/application_manager/src/commands/mobile/show_constant_tbt_request.cc +++ b/src/components/application_manager/src/commands/mobile/show_constant_tbt_request.cc @@ -172,6 +172,7 @@ void ShowConstantTBTRequest::Run() { } app->set_tbt_show_command(msg_params); + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Navigation); SendHMIRequest( hmi_apis::FunctionID::Navigation_ShowConstantTBT, &msg_params, true); } @@ -184,6 +185,7 @@ void ShowConstantTBTRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::Navigation_ShowConstantTBT: { LOG4CXX_INFO(logger_, "Received Navigation_ShowConstantTBT event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Navigation); const Common_Result::eType result_code = static_cast<Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); diff --git a/src/components/application_manager/src/commands/mobile/show_request.cc b/src/components/application_manager/src/commands/mobile/show_request.cc index 5b8e98d7ea..ad598efc1d 100644 --- a/src/components/application_manager/src/commands/mobile/show_request.cc +++ b/src/components/application_manager/src/commands/mobile/show_request.cc @@ -263,6 +263,7 @@ void ShowRequest::Run() { (*message_)[strings::msg_params][strings::custom_presets]; } + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest(hmi_apis::FunctionID::UI_Show, &msg_params, true); MessageSharedPtr persistentData = new smart_objects::SmartObject(msg_params); @@ -278,6 +279,7 @@ void ShowRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::UI_Show: { LOG4CXX_DEBUG(logger_, "Received UI_Show event."); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); std::string response_info; hmi_apis::Common_Result::eType result_code = static_cast<hmi_apis::Common_Result::eType>( diff --git a/src/components/application_manager/src/commands/mobile/slider_request.cc b/src/components/application_manager/src/commands/mobile/slider_request.cc index 054d0ec16d..f98869b08f 100644 --- a/src/components/application_manager/src/commands/mobile/slider_request.cc +++ b/src/components/application_manager/src/commands/mobile/slider_request.cc @@ -107,6 +107,7 @@ void SliderRequest::Run() { msg_params[strings::timeout] = default_timeout_; } + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); SendHMIRequest(hmi_apis::FunctionID::UI_Slider, &msg_params, true); } @@ -132,7 +133,7 @@ void SliderRequest::on_event(const event_engine::Event& event) { } LOG4CXX_DEBUG(logger_, "Received UI_Slider event"); - + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_UI); const Common_Result::eType response_code = static_cast<Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); diff --git a/src/components/application_manager/src/commands/mobile/speak_request.cc b/src/components/application_manager/src/commands/mobile/speak_request.cc index 6cbb762102..1954cde181 100644 --- a/src/components/application_manager/src/commands/mobile/speak_request.cc +++ b/src/components/application_manager/src/commands/mobile/speak_request.cc @@ -72,6 +72,7 @@ void SpeakRequest::Run() { (*message_)[strings::msg_params][strings::app_id] = app->app_id(); (*message_)[strings::msg_params][hmi_request::speak_type] = hmi_apis::Common_MethodName::SPEAK; + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_TTS); SendHMIRequest(hmi_apis::FunctionID::TTS_Speak, &message_->getElement(strings::msg_params), true); @@ -82,7 +83,7 @@ void SpeakRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::TTS_Speak: { LOG4CXX_INFO(logger_, "Received TTS_Speak event"); - + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_TTS); ProcessTTSSpeakResponse(event.smart_object()); break; } diff --git a/src/components/application_manager/src/commands/mobile/subscribe_vehicle_data_request.cc b/src/components/application_manager/src/commands/mobile/subscribe_vehicle_data_request.cc index fc839a43f4..15ba7999bd 100644 --- a/src/components/application_manager/src/commands/mobile/subscribe_vehicle_data_request.cc +++ b/src/components/application_manager/src/commands/mobile/subscribe_vehicle_data_request.cc @@ -3,6 +3,9 @@ Copyright (c) 2013, Ford Motor Company All rights reserved. + Copyright (c) 2017, Livio, Inc. + All rights reserved. + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -116,7 +119,7 @@ void SubscribeVehicleDataRequest::Run() { smart_objects::SmartObject response_params = smart_objects::SmartObject(smart_objects::SmartType_Map); bool result = false; - CheckVISubscribtions( + CheckVISubscriptions( app, info, result_code, response_params, msg_params, result); if (mobile_apis::Result::INVALID_ENUM != result_code) { @@ -149,6 +152,7 @@ void SubscribeVehicleDataRequest::Run() { ++it) SendHMIRequest(it->func_id, &msg_params, true); #else + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VehicleInfo); SendHMIRequest(hmi_apis::FunctionID::VehicleInfo_SubscribeVehicleData, &msg_params, true); @@ -165,7 +169,7 @@ void SubscribeVehicleDataRequest::on_event(const event_engine::Event& event) { LOG4CXX_ERROR(logger_, "Received unknown event."); return; } - + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VehicleInfo); ApplicationSharedPtr app = application_manager_.application(CommandRequestImpl::connection_key()); @@ -250,6 +254,15 @@ void SubscribeVehicleDataRequest::on_event(const event_engine::Event& event) { result_code = mobile_apis::Result::IGNORED; response_info = "Already subscribed on some provided VehicleData."; } + + if (!vi_waiting_for_subscribe_.empty()) { + LOG4CXX_DEBUG(logger_, "Subscribing to all pending VehicleData"); + VehicleInfoSubscriptions::const_iterator key = + vi_waiting_for_subscribe_.begin(); + for (; key != vi_waiting_for_subscribe_.end(); ++key) { + app->SubscribeToIVI(*key); + } + } } UnsubscribeFailedSubscriptions(app, message[strings::msg_params]); @@ -276,20 +289,33 @@ void SubscribeVehicleDataRequest::AddAlreadySubscribedVI( smart_objects::SmartObject& msg_params) const { LOG4CXX_AUTO_TRACE(logger_); using namespace mobile_apis; + auto vi_to_string = + [](const mobile_apis::VehicleDataType::eType vehicle_data) { + for (auto& vi_str_to_int_pair : MessageHelper::vehicle_data()) { + if (vehicle_data == vi_str_to_int_pair.second) { + return vi_str_to_int_pair.first; + } + } + return std::string(); + }; + VehicleInfoSubscriptions::const_iterator it_same_app = vi_already_subscribed_by_this_app_.begin(); for (; vi_already_subscribed_by_this_app_.end() != it_same_app; ++it_same_app) { - msg_params[*it_same_app][strings::result_code] = + msg_params[vi_to_string(*it_same_app)][strings::result_code] = VehicleDataResultCode::VDRC_DATA_ALREADY_SUBSCRIBED; + msg_params[vi_to_string(*it_same_app)][strings::data_type] = *it_same_app; } VehicleInfoSubscriptions::const_iterator it_another_app = vi_already_subscribed_by_another_apps_.begin(); for (; vi_already_subscribed_by_another_apps_.end() != it_another_app; ++it_another_app) { - msg_params[*it_another_app][strings::result_code] = + msg_params[vi_to_string(*it_another_app)][strings::result_code] = VehicleDataResultCode::VDRC_SUCCESS; + msg_params[vi_to_string(*it_another_app)][strings::data_type] = + *it_another_app; } } @@ -342,6 +368,21 @@ void SubscribeVehicleDataRequest::CheckVISubscribtions( smart_objects::SmartObject& out_response_params, smart_objects::SmartObject& out_request_params, bool& out_result) { + CheckVISubscriptions(app, + out_info, + out_result_code, + out_response_params, + out_request_params, + out_result); +} + +void SubscribeVehicleDataRequest::CheckVISubscriptions( + ApplicationSharedPtr app, + std::string& out_info, + mobile_apis::Result::eType& out_result_code, + smart_objects::SmartObject& out_response_params, + smart_objects::SmartObject& out_request_params, + bool& out_result) { // counter for items to subscribe VehicleInfoSubscriptions::size_type items_to_subscribe = 0; // counter for subscribed items by application @@ -366,7 +407,7 @@ void SubscribeVehicleDataRequest::CheckVISubscribtions( ++items_to_subscribe; } if (!is_interface_not_available && is_key_enabled) { - VehicleDataType key_type = it->second; + mobile_apis::VehicleDataType::eType key_type = it->second; if (app->IsSubscribedToIVI(key_type)) { LOG4CXX_DEBUG(logger_, "App with connection key " @@ -407,12 +448,13 @@ void SubscribeVehicleDataRequest::CheckVISubscribtions( out_request_params[key_name] = is_key_enabled; - if (app->SubscribeToIVI(static_cast<uint32_t>(key_type))) { + if (is_key_enabled) { + vi_waiting_for_subscribe_.insert(key_type); LOG4CXX_DEBUG( logger_, "App with connection key " << connection_key() - << " have been subscribed for VehicleDataType: " << key_type); + << " will be subscribed for VehicleDataType: " << key_type); ++subscribed_items; } } diff --git a/src/components/application_manager/src/commands/mobile/subscribe_way_points_request.cc b/src/components/application_manager/src/commands/mobile/subscribe_way_points_request.cc index 0e0d760228..8195697dfc 100644 --- a/src/components/application_manager/src/commands/mobile/subscribe_way_points_request.cc +++ b/src/components/application_manager/src/commands/mobile/subscribe_way_points_request.cc @@ -25,17 +25,18 @@ void SubscribeWayPointsRequest::Run() { return; } - if (application_manager_.IsAppSubscribedForWayPoints(app->app_id())) { + if (application_manager_.IsAppSubscribedForWayPoints(app)) { SendResponse(false, mobile_apis::Result::IGNORED); return; } if (application_manager_.IsAnyAppSubscribedForWayPoints()) { - application_manager_.SubscribeAppForWayPoints(app->app_id()); + application_manager_.SubscribeAppForWayPoints(app); SendResponse(true, mobile_apis::Result::SUCCESS); return; } + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Navigation); SendHMIRequest( hmi_apis::FunctionID::Navigation_SubscribeWayPoints, NULL, true); } @@ -47,6 +48,7 @@ void SubscribeWayPointsRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::Navigation_SubscribeWayPoints: { LOG4CXX_INFO(logger_, "Received Navigation_SubscribeWayPoints event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Navigation); const hmi_apis::Common_Result::eType result_code = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); @@ -55,7 +57,7 @@ void SubscribeWayPointsRequest::on_event(const event_engine::Event& event) { const bool result = PrepareResultForMobileResponse( result_code, HmiInterfaces::HMI_INTERFACE_Navigation); if (result) { - application_manager_.SubscribeAppForWayPoints(app->app_id()); + application_manager_.SubscribeAppForWayPoints(app); } SendResponse(result, MessageHelper::HMIToMobileResult(result_code), diff --git a/src/components/application_manager/src/commands/mobile/system_request.cc b/src/components/application_manager/src/commands/mobile/system_request.cc index e4706441ef..fe38b93732 100644 --- a/src/components/application_manager/src/commands/mobile/system_request.cc +++ b/src/components/application_manager/src/commands/mobile/system_request.cc @@ -535,19 +535,8 @@ void SystemRequest::Run() { if (!file || !file->is_download_complete || !file_system::MoveFile(app_full_file_path, file_dst_path)) { LOG4CXX_DEBUG(logger_, "Binary data not found."); - - std::string origin_file_name; - if ((*message_)[strings::msg_params].keyExists(strings::file_name)) { - origin_file_name = - (*message_)[strings::msg_params][strings::file_name].asString(); - } - if (!(mobile_apis::RequestType::HTTP == request_type && - 0 == origin_file_name.compare(kIVSU))) { - LOG4CXX_DEBUG(logger_, "Binary data required. Invalid data"); - SendResponse(false, mobile_apis::Result::INVALID_DATA); - return; - } - LOG4CXX_DEBUG(logger_, "IVSU does not require binary data. Continue"); + SendResponse(false, mobile_apis::Result::REJECTED); + return; } processing_file_ = file_dst_path; } @@ -598,6 +587,7 @@ void SystemRequest::Run() { msg_params[strings::request_type] = (*message_)[strings::msg_params][strings::request_type]; + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_BasicCommunication); SendHMIRequest(hmi_apis::FunctionID::BasicCommunication_SystemRequest, &msg_params, true); @@ -611,6 +601,7 @@ void SystemRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::BasicCommunication_SystemRequest: { + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_BasicCommunication); mobile_apis::Result::eType result_code = GetMobileResultCode(static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asUInt())); diff --git a/src/components/application_manager/src/commands/mobile/unsubscribe_vehicle_data_request.cc b/src/components/application_manager/src/commands/mobile/unsubscribe_vehicle_data_request.cc index fa3a9ad400..d6ad928bf7 100644 --- a/src/components/application_manager/src/commands/mobile/unsubscribe_vehicle_data_request.cc +++ b/src/components/application_manager/src/commands/mobile/unsubscribe_vehicle_data_request.cc @@ -134,7 +134,7 @@ void UnsubscribeVehicleDataRequest::Run() { if (is_key_enabled) { ++items_to_unsubscribe; - VehicleDataType key_type = it->second; + mobile_apis::VehicleDataType::eType key_type = it->second; if (!app->IsSubscribedToIVI(key_type)) { ++unsubscribed_items; vi_already_unsubscribed_by_this_app_.insert(key_type); @@ -234,6 +234,7 @@ void UnsubscribeVehicleDataRequest::Run() { ++it) SendHMIRequest(it->func_id, &msg_params, true); #else + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VehicleInfo); SendHMIRequest(hmi_apis::FunctionID::VehicleInfo_UnsubscribeVehicleData, &msg_params, true); @@ -250,6 +251,15 @@ void UnsubscribeVehicleDataRequest::on_event(const event_engine::Event& event) { LOG4CXX_ERROR(logger_, "Received unknown event."); return; } + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_VehicleInfo); + + ApplicationSharedPtr app = + application_manager_.application(CommandRequestImpl::connection_key()); + + if (!app) { + LOG4CXX_ERROR(logger_, "NULL pointer."); + return; + } #ifdef HMI_DBUS_API for (HmiRequests::iterator it = hmi_requests_.begin(); @@ -306,7 +316,7 @@ void UnsubscribeVehicleDataRequest::on_event(const event_engine::Event& event) { } SendResponse(any_arg_success, status, NULL, &response_params); if (true == any_arg_success) { - UpdateHash(); + app->UpdateHash(); } } #else diff --git a/src/components/application_manager/src/commands/mobile/unsubscribe_way_points_request.cc b/src/components/application_manager/src/commands/mobile/unsubscribe_way_points_request.cc index 953bbc7a12..dc3404c022 100644 --- a/src/components/application_manager/src/commands/mobile/unsubscribe_way_points_request.cc +++ b/src/components/application_manager/src/commands/mobile/unsubscribe_way_points_request.cc @@ -25,11 +25,12 @@ void UnSubscribeWayPointsRequest::Run() { return; } - if (!application_manager_.IsAppSubscribedForWayPoints(app->app_id())) { + if (!application_manager_.IsAppSubscribedForWayPoints(app)) { SendResponse(false, mobile_apis::Result::IGNORED); return; } + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Navigation); SendHMIRequest( hmi_apis::FunctionID::Navigation_UnsubscribeWayPoints, NULL, true); } @@ -41,6 +42,7 @@ void UnSubscribeWayPointsRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::Navigation_UnsubscribeWayPoints: { LOG4CXX_INFO(logger_, "Received Navigation_UnSubscribeWayPoints event"); + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Navigation); const hmi_apis::Common_Result::eType result_code = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); @@ -49,7 +51,7 @@ void UnSubscribeWayPointsRequest::on_event(const event_engine::Event& event) { const bool result = PrepareResultForMobileResponse( result_code, HmiInterfaces::HMI_INTERFACE_Navigation); if (result) { - application_manager_.UnsubscribeAppFromWayPoints(app->app_id()); + application_manager_.UnsubscribeAppFromWayPoints(app); } SendResponse(result, MessageHelper::HMIToMobileResult(result_code), diff --git a/src/components/application_manager/src/commands/mobile/update_turn_list_request.cc b/src/components/application_manager/src/commands/mobile/update_turn_list_request.cc index becab175e9..44fe9d0d07 100644 --- a/src/components/application_manager/src/commands/mobile/update_turn_list_request.cc +++ b/src/components/application_manager/src/commands/mobile/update_turn_list_request.cc @@ -138,6 +138,7 @@ void UpdateTurnListRequest::Run() { if ((*message_)[strings::msg_params].keyExists(strings::turn_list) || (*message_)[strings::msg_params].keyExists(strings::soft_buttons)) { + StartAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Navigation); SendHMIRequest( hmi_apis::FunctionID::Navigation_UpdateTurnList, &msg_params, true); } else { @@ -154,7 +155,7 @@ void UpdateTurnListRequest::on_event(const event_engine::Event& event) { switch (event.id()) { case hmi_apis::FunctionID::Navigation_UpdateTurnList: { LOG4CXX_INFO(logger_, "Received Navigation_UpdateTurnList event"); - + EndAwaitForInterface(HmiInterfaces::HMI_INTERFACE_Navigation); const hmi_apis::Common_Result::eType result_code = static_cast<hmi_apis::Common_Result::eType>( message[strings::params][hmi_response::code].asInt()); diff --git a/src/components/application_manager/src/event_engine/event_dispatcher_impl.cc b/src/components/application_manager/src/event_engine/event_dispatcher_impl.cc index d0bc0c41ef..b19a6f9194 100644 --- a/src/components/application_manager/src/event_engine/event_dispatcher_impl.cc +++ b/src/components/application_manager/src/event_engine/event_dispatcher_impl.cc @@ -45,8 +45,10 @@ EventDispatcherImpl::EventDispatcherImpl() EventDispatcherImpl::~EventDispatcherImpl() {} void EventDispatcherImpl::raise_event(const Event& event) { + AutoLock observer_lock(observer_lock_); { - AutoLock auto_lock(state_lock_); + AutoLock state_lock(state_lock_); + // check if event is notification if (hmi_apis::messageType::notification == event.smart_object_type()) { const uint32_t notification_correlation_id = 0; @@ -61,12 +63,10 @@ void EventDispatcherImpl::raise_event(const Event& event) { } // Call observers - EventObserver* temp; while (!observers_.empty()) { - observer_lock_.Acquire(); - temp = *observers_.begin(); + EventObserver* temp = *observers_.begin(); observers_.erase(observers_.begin()); - observer_lock_.Release(); + AutoUnlock unlock_observer(observer_lock); temp->on_event(event); } } diff --git a/src/components/application_manager/src/help_prompt_manager_impl.cc b/src/components/application_manager/src/help_prompt_manager_impl.cc new file mode 100644 index 0000000000..dbd3b49a5d --- /dev/null +++ b/src/components/application_manager/src/help_prompt_manager_impl.cc @@ -0,0 +1,436 @@ +/* + * Copyright (c) 2018, 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 "application_manager/help_prompt_manager_impl.h" +#include "application_manager/application.h" +#include "application_manager/message_helper.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" +#include "application_manager/application_manager.h" +#include "application_manager/commands/command_impl.h" +#include "utils/logger.h" +#include "utils/timer_task_impl.h" +#include "utils/make_shared.h" + +CREATE_LOGGERPTR_GLOBAL(logger_, "HelpPromptManagerImpl") + +namespace { +const std::size_t kLimitCommand = 30; +const uint32_t kBufferingTimeout = 10000; +} + +namespace application_manager { + +HelpPromptManagerImpl::HelpPromptManagerImpl(Application& app, + ApplicationManager& app_manager) + : app_(app) + , app_manager_(app_manager) + , internal_timer_("HelpPromtManagerTimer", + new ::timer::TimerTaskImpl<HelpPromptManagerImpl>( + this, &HelpPromptManagerImpl::OnTimerExpired)) + , sending_type_(SendingType::kNoneSend) + , count_requests_commands_(0) + , is_tts_send_(false) + , is_ui_send_(false) {} + +HelpPromptManagerImpl::~HelpPromptManagerImpl() { + LOG4CXX_AUTO_TRACE(logger_); + StopTimer(); +} + +void HelpPromptManagerImpl::OnVrCommandAdded( + const uint32_t cmd_id, const smart_objects::SmartObject& command) { + LOG4CXX_AUTO_TRACE(logger_); + if (SendingType::kNoneSend == sending_type_) { + LOG4CXX_DEBUG(logger_, + "SendingType::kNoneSend" + << " commands with id:" << cmd_id + << " will not be added"); + return; + } + auto it = vr_commands_.find(cmd_id); + if (vr_commands_.end() != it) { + LOG4CXX_DEBUG(logger_, "Commands with id:" << cmd_id << " alreday exists"); + return; + } + + if (false == command.keyExists(strings::vr_commands)) { + LOG4CXX_DEBUG(logger_, "vr_commands does`t present"); + return; + } + const smart_objects::SmartObject& commands = command[strings::vr_commands]; + /** + * The remaining number of commands for adding + * without taking into account the commands + * added during the timer operation + */ + std::size_t limit = kLimitCommand - count_requests_commands_; + LOG4CXX_DEBUG(logger_, "Remaining number of commands" << limit); + if (0 == limit || limit > kLimitCommand) { + LOG4CXX_DEBUG(logger_, "Commands limit is exceeded"); + return; + } + + if (internal_timer_.is_running() || commands.length() < limit) { + limit = commands.length(); + } + + LOG4CXX_DEBUG(logger_, + "Internal timer is running: " << internal_timer_.is_running() + << " Will be added " << limit + << " commands"); + + vr_commands_[cmd_id] = utils::MakeShared<smart_objects::SmartObject>( + smart_objects::SmartType_Array); + smart_objects::SmartArray& ar_vr_cmd = *(vr_commands_[cmd_id]->asArray()); + smart_objects::SmartArray& ar_cmd = *(commands.asArray()); + ar_vr_cmd.reserve(limit); + ar_vr_cmd.insert(ar_vr_cmd.end(), ar_cmd.begin(), ar_cmd.begin() + limit); + LOG4CXX_DEBUG(logger_, + "VR commands with id: " << cmd_id << " added for appID: " + << app_.app_id()); + if (false == internal_timer_.is_running()) { + count_requests_commands_ += limit; + SendRequests(); + } +} + +void HelpPromptManagerImpl::OnVrCommandDeleted(const uint32_t cmd_id) { + LOG4CXX_AUTO_TRACE(logger_); + if (SendingType::kNoneSend == sending_type_) { + LOG4CXX_DEBUG(logger_, + "SendingType::kNoneSend" + << " commands with id:" << cmd_id + << " will not be deleted"); + return; + } + auto it = vr_commands_.find(cmd_id); + if (vr_commands_.end() != it) { + count_requests_commands_ -= + kLimitCommand == count_requests_commands_ ? 0 : it->second->length(); + + vr_commands_.erase(it); + LOG4CXX_DEBUG(logger_, + "VR command with id: " << cmd_id << " deleted for appID: " + << app_.app_id()); + if (false == internal_timer_.is_running()) { + SendRequests(); + } + } +} + +void HelpPromptManagerImpl::OnTimeoutExpired() { + LOG4CXX_AUTO_TRACE(logger_); + SendRequests(); +} + +void HelpPromptManagerImpl::OnSetGlobalPropertiesReceived( + const smart_objects::SmartObject& msg, const bool is_response) { + LOG4CXX_AUTO_TRACE(logger_); + if (SendingType::kNoneSend == sending_type_) { + LOG4CXX_DEBUG(logger_, + "SendingType::kNoneSend" + " do not track SetGlobalProperties"); + return; + } + sending_type_ = GetSendingType(msg, is_response); + if (SendingType::kNoneSend == sending_type_) { + StopTimer(); + } + LOG4CXX_DEBUG(logger_, "Set sending type to:" << unsigned(sending_type_)); +} + +void HelpPromptManagerImpl::OnAppActivated(const bool is_restore) { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, "Activated for appID:" << app_.app_id()); + if (is_restore) { + LOG4CXX_DEBUG(logger_, "restoring"); + is_tts_send_ = (app_.help_prompt() && app_.help_prompt()->length()); + is_ui_send_ = (app_.vr_help() && app_.vr_help()->length()); + LOG4CXX_DEBUG(logger_, "is_tts_send_:" << is_tts_send_); + LOG4CXX_DEBUG(logger_, "is_ui_send_:" << is_ui_send_); + if (is_tts_send_ && is_ui_send_) { + LOG4CXX_DEBUG(logger_, + "SetGlobalProperties RPC" + " with the vrHelp and helpPrompt" + " has been sent"); + return; + } + } + StartTimer(is_restore); +} + +void HelpPromptManagerImpl::OnAppUnregistered() { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, "Unregisted for appID:" << app_.app_id()); + StopTimer(); +} + +void HelpPromptManagerImpl::StartTimer(const bool is_restore) { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, "Timer for appID:" << app_.app_id()); + StopTimer(); + sending_type_ = SendingType::kSendBoth; + internal_timer_.Start(kBufferingTimeout, timer::kSingleShot); + if (is_restore) { + sending_type_ = is_tts_send_ ? SendingType::kSendVRHelp : sending_type_; + sending_type_ = is_ui_send_ ? SendingType::kSendHelpPromt : sending_type_; + is_tts_send_ = false; + is_ui_send_ = false; + const DataAccessor<CommandsMap> accessor = app_.commands_map(); + const CommandsMap& commands = accessor.GetData(); + for (auto& command : commands) { + OnVrCommandAdded(command.first, *command.second); + } + } +} + +void HelpPromptManagerImpl::StopTimer() { + LOG4CXX_AUTO_TRACE(logger_); + sending_type_ = SendingType::kNoneSend; + if (internal_timer_.is_running()) { + internal_timer_.Stop(); + } + vr_commands_.clear(); +} + +void HelpPromptManagerImpl::OnTimerExpired() { + LOG4CXX_AUTO_TRACE(logger_); + OnTimeoutExpired(); +} + +void HelpPromptManagerImpl::SendTTSRequest() { + LOG4CXX_AUTO_TRACE(logger_); + if (vr_commands_.empty()) { + LOG4CXX_DEBUG(logger_, "vr_commands_ is empty"); + return; + } + LOG4CXX_DEBUG(logger_, "TTS request for appID:" << app_.app_id()); + smart_objects::SmartObjectSPtr tts_global_properties = + utils::MakeShared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); + if (tts_global_properties) { + smart_objects::SmartObject& ref = *tts_global_properties; + + ref[strings::params][strings::message_type] = + hmi_apis::messageType::request; + ref[strings::params][strings::protocol_version] = + commands::CommandImpl::protocol_version_; + ref[strings::params][strings::protocol_type] = + commands::CommandImpl::hmi_protocol_type_; + ref[strings::params][strings::correlation_id] = + app_manager_.GetNextHMICorrelationID(); + + smart_objects::SmartObject& so_to_send = *tts_global_properties; + so_to_send[strings::params][strings::function_id] = + hmi_apis::FunctionID::TTS_SetGlobalProperties; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + CreatePromtMsg(msg_params); + + msg_params[strings::app_id] = app_.app_id(); + so_to_send[strings::msg_params] = msg_params; + app_manager_.ManageHMICommand(tts_global_properties); + } +} + +void HelpPromptManagerImpl::SendUIRequest() { + LOG4CXX_AUTO_TRACE(logger_); + if (vr_commands_.empty()) { + LOG4CXX_DEBUG(logger_, "vr_commands_ is empty"); + return; + } + LOG4CXX_DEBUG(logger_, "UI request for appID:" << app_.app_id()); + smart_objects::SmartObjectSPtr ui_global_properties = + utils::MakeShared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); + if (ui_global_properties) { + smart_objects::SmartObject& ref = *ui_global_properties; + + ref[strings::params][strings::message_type] = + hmi_apis::messageType::request; + ref[strings::params][strings::protocol_version] = + commands::CommandImpl::protocol_version_; + ref[strings::params][strings::protocol_type] = + commands::CommandImpl::hmi_protocol_type_; + ref[strings::params][strings::correlation_id] = + app_manager_.GetNextHMICorrelationID(); + + smart_objects::SmartObject& so_to_send = *ui_global_properties; + so_to_send[strings::params][strings::function_id] = + hmi_apis::FunctionID::UI_SetGlobalProperties; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + CreateVRMsg(msg_params); + + msg_params[strings::app_id] = app_.app_id(); + so_to_send[strings::msg_params] = msg_params; + app_manager_.ManageHMICommand(ui_global_properties); + } +} + +void HelpPromptManagerImpl::SendBothRequests() { + LOG4CXX_AUTO_TRACE(logger_); + SendTTSRequest(); + SendUIRequest(); +} + +void HelpPromptManagerImpl::SendRequests() { + LOG4CXX_AUTO_TRACE(logger_); + if (vr_commands_.empty()) { + LOG4CXX_DEBUG(logger_, "vr_commands_ is empty"); + return; + } + + switch (sending_type_) { + case SendingType::kSendHelpPromt: + SendTTSRequest(); + return; + case SendingType::kSendVRHelp: + SendUIRequest(); + return; + case SendingType::kSendBoth: + SendBothRequests(); + return; + case SendingType::kNoneSend: + break; + } + LOG4CXX_DEBUG(logger_, + "SendingType:" << (unsigned)sending_type_ + << " request not sending"); +} + +void HelpPromptManagerImpl::CreatePromtMsg( + smart_objects::SmartObject& out_msg_params) { + LOG4CXX_AUTO_TRACE(logger_); + if (vr_commands_.empty()) { + LOG4CXX_DEBUG(logger_, "vr_commands_ is empty"); + return; + } + out_msg_params[strings::help_prompt] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + uint32_t index = 0; + for (const auto& it : vr_commands_) { + for (std::size_t i = 0; i < it.second->length(); ++i) { + smart_objects::SmartObject item(smart_objects::SmartType_Map); + + item[strings::text] = it.second->getElement(i).asString(); + item[strings::type] = mobile_apis::SpeechCapabilities::SC_TEXT; + + out_msg_params[strings::help_prompt][index++] = item; + } + } + app_.set_help_prompt(out_msg_params[strings::help_prompt]); +} + +void HelpPromptManagerImpl::CreateVRMsg( + smart_objects::SmartObject& out_msg_params) { + LOG4CXX_AUTO_TRACE(logger_); + if (vr_commands_.empty()) { + LOG4CXX_DEBUG(logger_, "vr_commands_ is empty"); + return; + } + if (false == out_msg_params.keyExists(strings::vr_help_title)) { + if (app_.vr_help_title()) { + out_msg_params[strings::vr_help_title] = (*app_.vr_help_title()); + } else { + out_msg_params[strings::vr_help_title] = app_.name(); + } + } + out_msg_params[strings::vr_help] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + uint32_t index = 0; + for (const auto& it : vr_commands_) { + for (std::size_t i = 0; i < it.second->length(); ++i) { + smart_objects::SmartObject item(smart_objects::SmartType_Map); + + item[strings::text] = it.second->getElement(i).asString(); + item[strings::position] = index + 1; + + out_msg_params[strings::vr_help][index++] = item; + } + } + app_.set_vr_help(out_msg_params[strings::vr_help]); +} + +HelpPromptManagerImpl::SendingType HelpPromptManagerImpl::GetSendingType( + const smart_objects::SmartObject& msg, const bool is_response) { + LOG4CXX_AUTO_TRACE(logger_); + if (false == is_response) { + if (msg.keyExists(strings::help_prompt)) { + is_tts_send_ = true; + } + if (msg.keyExists(strings::vr_help)) { + is_ui_send_ = true; + } + LOG4CXX_DEBUG(logger_, "is_tts_send_:" << is_tts_send_); + LOG4CXX_DEBUG(logger_, "is_ui_send_:" << is_ui_send_); + return sending_type_; + } + hmi_apis::Common_Result::eType result = + static_cast<hmi_apis::Common_Result::eType>( + msg[strings::params][hmi_response::code].asInt()); + LOG4CXX_DEBUG(logger_, "HMI response result:" << result); + if (hmi_apis::Common_Result::eType::SUCCESS == result) { + hmi_apis::FunctionID::eType function_id = + static_cast<hmi_apis::FunctionID::eType>( + msg[strings::params][strings::function_id].asUInt()); + LOG4CXX_DEBUG(logger_, "Function id:" << function_id); + switch (function_id) { + case hmi_apis::FunctionID::TTS_SetGlobalProperties: + if (is_tts_send_) { + is_tts_send_ = false; + return (SendingType::kSendHelpPromt == sending_type_) + ? SendingType::kNoneSend + : SendingType::kSendVRHelp; + } + break; + case hmi_apis::FunctionID::UI_SetGlobalProperties: + if (is_ui_send_) { + is_ui_send_ = false; + return (SendingType::kSendVRHelp == sending_type_) + ? SendingType::kNoneSend + : SendingType::kSendHelpPromt; + } + break; + default: + return sending_type_; + } + } + return sending_type_; +} + +} // namespace application_manager diff --git a/src/components/application_manager/src/helpers/application_helper.cc b/src/components/application_manager/src/helpers/application_helper.cc new file mode 100644 index 0000000000..16b49faa2a --- /dev/null +++ b/src/components/application_manager/src/helpers/application_helper.cc @@ -0,0 +1,146 @@ +#include <vector> +#include <string> +#include "application_manager/helpers/application_helper.h" +#include "application_manager/message_helper.h" +#include "utils/logger.h" +#include "utils/file_system.h" + +namespace { +using namespace application_manager; +void DeleteWayPoints(ApplicationSharedPtr app, + ApplicationManager& app_manager) { + app_manager.UnsubscribeAppFromWayPoints(app); + if (!app_manager.IsAnyAppSubscribedForWayPoints()) { + MessageHelper::SendUnsubscribedWayPoints(app_manager); + } +} + +void DeleteCommands(ApplicationSharedPtr app, ApplicationManager& app_manager) { + CommandsMap cmap = app->commands_map().GetData(); + + for (auto cmd : cmap) { + MessageHelper::SendDeleteCommandRequest(cmd.second, app, app_manager); + app->RemoveCommand(cmd.first); + } +} + +void DeleteSubmenus(ApplicationSharedPtr app, ApplicationManager& app_manager) { + SubMenuMap smap = app->sub_menu_map().GetData(); + + for (auto smenu : smap) { + MessageHelper::SendDeleteSubmenuRequest(smenu.second, app, app_manager); + app->RemoveSubMenu(smenu.first); + } +} + +void DeleteChoiceSets(ApplicationSharedPtr app, + ApplicationManager& app_manager) { + ChoiceSetMap csmap = app->choice_set_map().GetData(); + + for (auto choice : csmap) { + MessageHelper::SendDeleteChoiceSetRequest(choice.second, app, app_manager); + app->RemoveChoiceSet(choice.first); + } +} + +void DeleteGlobalProperties(ApplicationSharedPtr app, + ApplicationManager& app_manager) { + using namespace smart_objects; + + const std::vector<std::string>& timeout_prompt = + app_manager.get_settings().time_out_promt(); + + SmartObject so_default_timeout_prompt = SmartObject(SmartType_Array); + + int32_t index = 0; + for (auto prompt : timeout_prompt) { + SmartObject timeoutPrompt = SmartObject(SmartType_Map); + timeoutPrompt[strings::text] = timeout_prompt[static_cast<size_t>(index)]; + timeoutPrompt[strings::type] = hmi_apis::Common_SpeechCapabilities::SC_TEXT; + so_default_timeout_prompt[index] = timeoutPrompt; + ++index; + } + + app->set_timeout_prompt(so_default_timeout_prompt); + + SmartObject empty_so = SmartObject(SmartType_Array); + app->set_help_prompt(empty_so); + app->reset_vr_help_title(); + app->reset_vr_help(); + app->set_keyboard_props(empty_so); + app->set_menu_icon(empty_so); + app->set_menu_title(empty_so); + + MessageHelper::SendResetPropertiesRequest(app, app_manager); +} + +void DeleteButtonSubscriptions(ApplicationSharedPtr app, + ApplicationManager& app_manager) { + ButtonSubscriptions buttons = app->SubscribedButtons().GetData(); + + for (auto button : buttons) { + if (mobile_apis::ButtonName::CUSTOM_BUTTON == button) { + continue; + } + MessageHelper::SendUnsubscribeButtonNotification(button, app, app_manager); + app->UnsubscribeFromButton(button); + } +} + +void DeleteVISubscriptions(ApplicationSharedPtr app, + ApplicationManager& app_manager) { + VehicleInfoSubscriptions ivi = app->SubscribedIVI().GetData(); + + for (auto i : ivi) { + app->UnsubscribeFromIVI(i); + SubscribedToIVIPredicate p(i); + auto app = FindApp(app_manager.applications(), p); + if (!app) { + MessageHelper::SendUnsubscribeIVIRequest(i, app, app_manager); + } + } +} + +void CleanupAppFiles(ApplicationSharedPtr app) { + const auto icon_file = app->app_icon_path(); + + auto files = app->getAppFiles(); + for (auto file : files) { + auto file_name = file.first; + if (icon_file == file_name) { + continue; + } + app->DeleteFile(file_name); + file_system::DeleteFile(file_name); + } +} +} // namespace + +namespace application_manager { + +CREATE_LOGGERPTR_GLOBAL(logger, "ApplicationManager") + +SubscribedToIVIPredicate::SubscribedToIVIPredicate(uint32_t vehicle_info) + : vehicle_info_(vehicle_info) {} + +bool SubscribedToIVIPredicate::operator()( + const ApplicationSharedPtr app) const { + return app ? app->IsSubscribedToIVI(vehicle_info_) : false; +} + +void DeleteApplicationData(ApplicationSharedPtr app, + ApplicationManager& app_manager) { + LOG4CXX_AUTO_TRACE(logger); + DCHECK_OR_RETURN_VOID(app); + + DeleteWayPoints(app, app_manager); + DeleteCommands(app, app_manager); + DeleteSubmenus(app, app_manager); + DeleteChoiceSets(app, app_manager); + DeleteGlobalProperties(app, app_manager); + DeleteButtonSubscriptions(app, app_manager); + DeleteVISubscriptions(app, app_manager); + CleanupAppFiles(app); +} + +} // namespace application_manager diff --git a/src/components/application_manager/src/hmi_command_factory.cc b/src/components/application_manager/src/hmi_command_factory.cc index ffaa8d9b5f..a7f3ce7e6b 100644 --- a/src/components/application_manager/src/hmi_command_factory.cc +++ b/src/components/application_manager/src/hmi_command_factory.cc @@ -269,6 +269,7 @@ #include "application_manager/commands/hmi/on_system_error_notification.h" #include "application_manager/commands/hmi/basic_communication_system_request.h" #include "application_manager/commands/hmi/basic_communication_system_response.h" +#include "application_manager/commands/hmi/basic_communication_on_awake_sdl.h" #include "application_manager/commands/hmi/sdl_policy_update.h" #include "application_manager/commands/hmi/sdl_policy_update_response.h" #include "application_manager/commands/hmi/on_received_policy_update.h" @@ -781,6 +782,11 @@ CommandSharedPtr HMICommandFactory::CreateCommand( message, application_manager)); break; } + case hmi_apis::FunctionID::BasicCommunication_OnAwakeSDL: { + command.reset( + new commands::OnAwakeSDLNotification(message, application_manager)); + break; + } case hmi_apis::FunctionID::BasicCommunication_OnExitApplication: { command.reset(new commands::OnExitApplicationNotification( message, application_manager)); diff --git a/src/components/application_manager/src/hmi_state.cc b/src/components/application_manager/src/hmi_state.cc index 393a9d7784..bc1ccd8f42 100644 --- a/src/components/application_manager/src/hmi_state.cc +++ b/src/components/application_manager/src/hmi_state.cc @@ -37,47 +37,65 @@ namespace application_manager { -HmiState::HmiState(uint32_t app_id, +HmiState::HmiState(utils::SharedPtr<Application> app, const ApplicationManager& app_mngr, StateID state_id) - : app_id_(app_id) + : app_(app) , state_id_(state_id) , app_mngr_(app_mngr) , hmi_level_(mobile_apis::HMILevel::INVALID_ENUM) , audio_streaming_state_(mobile_apis::AudioStreamingState::INVALID_ENUM) , system_context_(mobile_apis::SystemContext::INVALID_ENUM) {} -HmiState::HmiState(uint32_t app_id, const ApplicationManager& app_mngr) - : app_id_(app_id) +HmiState::HmiState(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr) + : app_(app) , state_id_(STATE_ID_REGULAR) , app_mngr_(app_mngr) , hmi_level_(mobile_apis::HMILevel::INVALID_ENUM) , audio_streaming_state_(mobile_apis::AudioStreamingState::INVALID_ENUM) , system_context_(mobile_apis::SystemContext::INVALID_ENUM) {} +DEPRECATED HmiState::HmiState(uint32_t app_id, + const ApplicationManager& app_mngr, + StateID state_id) + : state_id_(state_id) + , app_mngr_(app_mngr) + , hmi_level_(mobile_apis::HMILevel::INVALID_ENUM) + , audio_streaming_state_(mobile_apis::AudioStreamingState::INVALID_ENUM) + , system_context_(mobile_apis::SystemContext::INVALID_ENUM) { + app_ = app_mngr_.application(app_id); +} + +DEPRECATED HmiState::HmiState(uint32_t app_id, + const ApplicationManager& app_mngr) + : state_id_(STATE_ID_REGULAR) + , app_mngr_(app_mngr) + , hmi_level_(mobile_apis::HMILevel::INVALID_ENUM) + , audio_streaming_state_(mobile_apis::AudioStreamingState::INVALID_ENUM) + , system_context_(mobile_apis::SystemContext::INVALID_ENUM) { + app_ = app_mngr_.application(app_id); +} + void HmiState::set_parent(HmiStatePtr parent) { DCHECK_OR_RETURN_VOID(parent); parent_ = parent; } -bool HmiState::is_navi_app(const uint32_t app_id) const { - const ApplicationSharedPtr app = app_mngr_.application(app_id); - return app ? app->is_navi() : false; +bool HmiState::is_navi_app() const { + return app_->is_navi(); } -bool HmiState::is_media_app(const uint32_t app_id) const { - const ApplicationSharedPtr app = app_mngr_.application(app_id); - return app ? app->is_media_application() : false; +bool HmiState::is_media_app() const { + return app_->is_media_application(); } -bool HmiState::is_voice_communication_app(const uint32_t app_id) const { - const ApplicationSharedPtr app = app_mngr_.application(app_id); - return app ? app->is_voice_communication_supported() : false; +bool HmiState::is_voice_communication_app() const { + return app_->is_voice_communication_supported(); } -bool HmiState::is_mobile_projection_app(const uint32_t app_id) const { - const ApplicationSharedPtr app = app_mngr_.application(app_id); - return app ? app->mobile_projection_enabled() : false; +bool HmiState::is_mobile_projection_app() const { + return app_->mobile_projection_enabled(); } mobile_apis::AudioStreamingState::eType VRHmiState::audio_streaming_state() @@ -86,10 +104,20 @@ mobile_apis::AudioStreamingState::eType VRHmiState::audio_streaming_state() return AudioStreamingState::NOT_AUDIBLE; } -VRHmiState::VRHmiState(uint32_t app_id, const ApplicationManager& app_mngr) +VRHmiState::VRHmiState(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr) + : HmiState(app, app_mngr, STATE_ID_VR_SESSION) {} + +DEPRECATED VRHmiState::VRHmiState(uint32_t app_id, + const ApplicationManager& app_mngr) : HmiState(app_id, app_mngr, STATE_ID_VR_SESSION) {} -TTSHmiState::TTSHmiState(uint32_t app_id, const ApplicationManager& app_mngr) +TTSHmiState::TTSHmiState(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr) + : HmiState(app, app_mngr, STATE_ID_TTS_SESSION) {} + +DEPRECATED TTSHmiState::TTSHmiState(uint32_t app_id, + const ApplicationManager& app_mngr) : HmiState(app_id, app_mngr, STATE_ID_TTS_SESSION) {} mobile_apis::AudioStreamingState::eType TTSHmiState::audio_streaming_state() @@ -107,8 +135,12 @@ mobile_apis::AudioStreamingState::eType TTSHmiState::audio_streaming_state() return expected_state; } -NaviStreamingHmiState::NaviStreamingHmiState(uint32_t app_id, +NaviStreamingHmiState::NaviStreamingHmiState(utils::SharedPtr<Application> app, const ApplicationManager& app_mngr) + : HmiState(app, app_mngr, STATE_ID_NAVI_STREAMING) {} + +DEPRECATED NaviStreamingHmiState::NaviStreamingHmiState( + uint32_t app_id, const ApplicationManager& app_mngr) : HmiState(app_id, app_mngr, STATE_ID_NAVI_STREAMING) {} mobile_apis::AudioStreamingState::eType @@ -117,7 +149,7 @@ NaviStreamingHmiState::audio_streaming_state() const { using namespace mobile_apis; AudioStreamingState::eType expected_state = parent()->audio_streaming_state(); - if (!is_navi_app(app_id_) && AudioStreamingState::AUDIBLE == expected_state) { + if (!is_navi_app() && AudioStreamingState::AUDIBLE == expected_state) { if (app_mngr_.is_attenuated_supported()) { expected_state = AudioStreamingState::ATTENUATED; } else { @@ -127,8 +159,12 @@ NaviStreamingHmiState::audio_streaming_state() const { return expected_state; } -PhoneCallHmiState::PhoneCallHmiState(uint32_t app_id, +PhoneCallHmiState::PhoneCallHmiState(utils::SharedPtr<Application> app, const ApplicationManager& app_mngr) + : HmiState(app, app_mngr, STATE_ID_PHONE_CALL) {} + +DEPRECATED PhoneCallHmiState::PhoneCallHmiState( + uint32_t app_id, const ApplicationManager& app_mngr) : HmiState(app_id, app_mngr, STATE_ID_PHONE_CALL) {} mobile_apis::HMILevel::eType PhoneCallHmiState::hmi_level() const { @@ -139,21 +175,29 @@ mobile_apis::HMILevel::eType PhoneCallHmiState::hmi_level() const { HMILevel::HMI_NONE)) { return parent()->hmi_level(); } - if (is_navi_app(app_id_) || is_mobile_projection_app(app_id_)) { + if (is_navi_app() || is_mobile_projection_app()) { return HMILevel::HMI_LIMITED; } - if (!is_media_app(app_id_)) { + if (!is_media_app()) { return parent()->hmi_level(); } return HMILevel::HMI_BACKGROUND; } -SafetyModeHmiState::SafetyModeHmiState(uint32_t app_id, +SafetyModeHmiState::SafetyModeHmiState(utils::SharedPtr<Application> app, const ApplicationManager& app_mngr) + : HmiState(app, app_mngr, STATE_ID_SAFETY_MODE) {} + +DEPRECATED SafetyModeHmiState::SafetyModeHmiState( + uint32_t app_id, const ApplicationManager& app_mngr) : HmiState(app_id, app_mngr, STATE_ID_SAFETY_MODE) {} -DeactivateHMI::DeactivateHMI(uint32_t app_id, +DeactivateHMI::DeactivateHMI(utils::SharedPtr<Application> app, const ApplicationManager& app_mngr) + : HmiState(app, app_mngr, STATE_ID_DEACTIVATE_HMI) {} + +DEPRECATED DeactivateHMI::DeactivateHMI(uint32_t app_id, + const ApplicationManager& app_mngr) : HmiState(app_id, app_mngr, STATE_ID_DEACTIVATE_HMI) {} mobile_apis::HMILevel::eType DeactivateHMI::hmi_level() const { @@ -167,7 +211,12 @@ mobile_apis::HMILevel::eType DeactivateHMI::hmi_level() const { return HMILevel::HMI_BACKGROUND; } -AudioSource::AudioSource(uint32_t app_id, const ApplicationManager& app_mngr) +AudioSource::AudioSource(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr) + : HmiState(app, app_mngr, STATE_ID_AUDIO_SOURCE) {} + +DEPRECATED AudioSource::AudioSource(uint32_t app_id, + const ApplicationManager& app_mngr) : HmiState(app_id, app_mngr, STATE_ID_AUDIO_SOURCE) {} mobile_apis::HMILevel::eType AudioSource::hmi_level() const { @@ -181,13 +230,18 @@ mobile_apis::HMILevel::eType AudioSource::hmi_level() const { HMILevel::HMI_NONE)) { return parent()->hmi_level(); } - if (is_navi_app(app_id_) || is_voice_communication_app(app_id_)) { + if (is_navi_app() || is_voice_communication_app()) { return HMILevel::HMI_LIMITED; } return HMILevel::HMI_BACKGROUND; } -EmbeddedNavi::EmbeddedNavi(uint32_t app_id, const ApplicationManager& app_mngr) +EmbeddedNavi::EmbeddedNavi(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr) + : HmiState(app, app_mngr, STATE_ID_EMBEDDED_NAVI) {} + +DEPRECATED EmbeddedNavi::EmbeddedNavi(uint32_t app_id, + const ApplicationManager& app_mngr) : HmiState(app_id, app_mngr, STATE_ID_EMBEDDED_NAVI) {} mobile_apis::HMILevel::eType EmbeddedNavi::hmi_level() const { @@ -198,7 +252,7 @@ mobile_apis::HMILevel::eType EmbeddedNavi::hmi_level() const { HMILevel::HMI_NONE)) { return parent()->hmi_level(); } - if (is_media_app(app_id_)) { + if (is_media_app()) { return HMILevel::HMI_LIMITED; } return HMILevel::HMI_BACKGROUND; diff --git a/src/components/application_manager/src/message.cc b/src/components/application_manager/src/message.cc index b211b270b8..7bc686aef1 100644 --- a/src/components/application_manager/src/message.cc +++ b/src/components/application_manager/src/message.cc @@ -89,7 +89,7 @@ Message& Message::operator=(const Message& message) { set_data_size(message.data_size_); set_payload_size(message.payload_size_); if (message.binary_data_) { - set_binary_data(message.binary_data_); + set_binary_data(static_cast<const BinaryData*>(message.binary_data_)); } set_json_message(message.json_message_); set_protocol_version(message.protocol_version()); @@ -207,6 +207,19 @@ void Message::set_binary_data(BinaryData* data) { binary_data_ = new BinaryData(*data); } +void Message::set_binary_data(const BinaryData* data) { + if (NULL == data) { + NOTREACHED(); + return; + } + + if (binary_data_) { + delete binary_data_; + } + + binary_data_ = new BinaryData(*data); +} + void Message::set_json_message(const std::string& json_message) { json_message_ = json_message; } 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 65f4c79fa6..6a908c4ebc 100644 --- a/src/components/application_manager/src/message_helper/message_helper.cc +++ b/src/components/application_manager/src/message_helper/message_helper.cc @@ -2,6 +2,9 @@ Copyright (c) 2013, Ford Motor Company All rights reserved. + Copyright (c) 2017, Livio, Inc. + All rights reserved. + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -42,6 +45,7 @@ #include <algorithm> #include <utility> #include <map> +#include <functional> #include "application_manager/application.h" #include "application_manager/application_manager.h" @@ -50,6 +54,7 @@ #include "application_manager/policies/policy_handler_interface.h" #include "application_manager/resumption/resume_ctrl.h" #include "connection_handler/connection_handler_impl.h" +#include "transport_manager/common.h" #include "interfaces/MOBILE_API.h" #include "smart_objects/enum_schema_item.h" #include "utils/file_system.h" @@ -158,37 +163,60 @@ struct ExternalConsentStatusAppender } // namespace -std::pair<std::string, VehicleDataType> kVehicleDataInitializer[] = { - std::make_pair(strings::gps, GPS), - std::make_pair(strings::speed, SPEED), - std::make_pair(strings::rpm, RPM), - std::make_pair(strings::fuel_level, FUELLEVEL), - std::make_pair(strings::fuel_level_state, FUELLEVEL_STATE), - std::make_pair(strings::instant_fuel_consumption, FUELCONSUMPTION), - std::make_pair(strings::external_temp, EXTERNTEMP), - std::make_pair(strings::vin, VIN), - std::make_pair(strings::prndl, PRNDL), - std::make_pair(strings::tire_pressure, TIREPRESSURE), - std::make_pair(strings::odometer, ODOMETER), - std::make_pair(strings::belt_status, BELTSTATUS), - std::make_pair(strings::body_information, BODYINFO), - std::make_pair(strings::device_status, DEVICESTATUS), - std::make_pair(strings::driver_braking, BRAKING), - std::make_pair(strings::wiper_status, WIPERSTATUS), - std::make_pair(strings::head_lamp_status, HEADLAMPSTATUS), - std::make_pair(strings::e_call_info, ECALLINFO), - std::make_pair(strings::airbag_status, AIRBAGSTATUS), - std::make_pair(strings::emergency_event, EMERGENCYEVENT), - std::make_pair(strings::cluster_mode_status, CLUSTERMODESTATUS), - std::make_pair(strings::my_key, MYKEY), +std::pair<std::string, + mobile_apis::VehicleDataType::eType> kVehicleDataInitializer[] = { + std::make_pair(strings::gps, mobile_apis::VehicleDataType::VEHICLEDATA_GPS), + std::make_pair(strings::speed, + mobile_apis::VehicleDataType::VEHICLEDATA_SPEED), + std::make_pair(strings::rpm, mobile_apis::VehicleDataType::VEHICLEDATA_RPM), + std::make_pair(strings::fuel_level, + mobile_apis::VehicleDataType::VEHICLEDATA_FUELLEVEL), + std::make_pair(strings::fuel_level_state, + mobile_apis::VehicleDataType::VEHICLEDATA_FUELLEVEL_STATE), + std::make_pair(strings::instant_fuel_consumption, + mobile_apis::VehicleDataType::VEHICLEDATA_FUELCONSUMPTION), + std::make_pair(strings::external_temp, + mobile_apis::VehicleDataType::VEHICLEDATA_EXTERNTEMP), + std::make_pair(strings::vin, mobile_apis::VehicleDataType::VEHICLEDATA_VIN), + std::make_pair(strings::prndl, + mobile_apis::VehicleDataType::VEHICLEDATA_PRNDL), + std::make_pair(strings::tire_pressure, + mobile_apis::VehicleDataType::VEHICLEDATA_TIREPRESSURE), + std::make_pair(strings::odometer, + mobile_apis::VehicleDataType::VEHICLEDATA_ODOMETER), + std::make_pair(strings::belt_status, + mobile_apis::VehicleDataType::VEHICLEDATA_BELTSTATUS), + std::make_pair(strings::body_information, + mobile_apis::VehicleDataType::VEHICLEDATA_BODYINFO), + std::make_pair(strings::device_status, + mobile_apis::VehicleDataType::VEHICLEDATA_DEVICESTATUS), + std::make_pair(strings::driver_braking, + mobile_apis::VehicleDataType::VEHICLEDATA_BRAKING), + std::make_pair(strings::wiper_status, + mobile_apis::VehicleDataType::VEHICLEDATA_WIPERSTATUS), + std::make_pair(strings::head_lamp_status, + mobile_apis::VehicleDataType::VEHICLEDATA_HEADLAMPSTATUS), + std::make_pair(strings::e_call_info, + mobile_apis::VehicleDataType::VEHICLEDATA_ECALLINFO), + std::make_pair(strings::airbag_status, + mobile_apis::VehicleDataType::VEHICLEDATA_AIRBAGSTATUS), + std::make_pair(strings::emergency_event, + mobile_apis::VehicleDataType::VEHICLEDATA_EMERGENCYEVENT), + std::make_pair(strings::cluster_mode_status, + mobile_apis::VehicleDataType::VEHICLEDATA_CLUSTERMODESTATUS), + std::make_pair(strings::my_key, + mobile_apis::VehicleDataType::VEHICLEDATA_MYKEY), /* NOT DEFINED in mobile API std::make_pair(strings::gps, BATTVOLTAGE), */ - std::make_pair(strings::engine_torque, ENGINETORQUE), - std::make_pair(strings::acc_pedal_pos, ACCPEDAL), - std::make_pair(strings::steering_wheel_angle, STEERINGWHEEL), + std::make_pair(strings::engine_torque, + mobile_apis::VehicleDataType::VEHICLEDATA_ENGINETORQUE), + std::make_pair(strings::acc_pedal_pos, + mobile_apis::VehicleDataType::VEHICLEDATA_ACCPEDAL), + std::make_pair(strings::steering_wheel_angle, + mobile_apis::VehicleDataType::VEHICLEDATA_STEERINGWHEEL), }; const VehicleData MessageHelper::vehicle_data_( @@ -268,7 +296,8 @@ hmi_apis::Common_Language::eType MessageHelper::CommonLanguageFromString( } std::string MessageHelper::GetDeviceMacAddressForHandle( - const uint32_t device_handle, const ApplicationManager& app_mngr) { + const transport_manager::DeviceHandle device_handle, + const ApplicationManager& app_mngr) { std::string device_mac_address = ""; app_mngr.connection_handler().get_session_observer().GetDataOnDeviceID( device_handle, NULL, NULL, &device_mac_address); @@ -287,21 +316,20 @@ std::string MessageHelper::CommonLanguageToString( return std::string(); } -smart_objects::SmartObjectSPtr MessageHelper::CreateRequestObject( - const uint32_t correlation_id) { +smart_objects::SmartObjectSPtr MessageHelper::CreateMessageForHMI( + hmi_apis::messageType::eType message_type, const uint32_t correlation_id) { using namespace smart_objects; - SmartObjectSPtr request = utils::MakeShared<SmartObject>(SmartType_Map); - SmartObject& ref = *request; + SmartObjectSPtr message = utils::MakeShared<SmartObject>(SmartType_Map); + SmartObject& ref = *message; - ref[strings::params][strings::message_type] = - static_cast<int>(hmi_apis::messageType::request); + ref[strings::params][strings::message_type] = static_cast<int>(message_type); ref[strings::params][strings::protocol_version] = commands::CommandImpl::protocol_version_; ref[strings::params][strings::protocol_type] = commands::CommandImpl::hmi_protocol_type_; ref[strings::params][strings::correlation_id] = correlation_id; - return request; + return message; } smart_objects::SmartObjectSPtr MessageHelper::CreateHashUpdateNotification( @@ -321,8 +349,8 @@ smart_objects::SmartObjectSPtr MessageHelper::CreateHashUpdateNotification( void MessageHelper::SendDecryptCertificateToHMI(const std::string& file_name, ApplicationManager& app_mngr) { using namespace smart_objects; - SmartObjectSPtr message = - CreateRequestObject(app_mngr.GetNextHMICorrelationID()); + SmartObjectSPtr message = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); DCHECK(message); SmartObject& object = *message; @@ -377,6 +405,253 @@ MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( return notification; } +void MessageHelper::SendDeleteCommandRequest(smart_objects::SmartObject* cmd, + ApplicationSharedPtr application, + ApplicationManager& app_mngr) { + LOG4CXX_AUTO_TRACE(logger_); + DCHECK_OR_RETURN_VOID(cmd); + using namespace smart_objects; + SmartObject msg_params = SmartObject(smart_objects::SmartType_Map); + + msg_params[strings::cmd_id] = (*cmd)[strings::cmd_id]; + msg_params[strings::app_id] = application->app_id(); + + if ((*cmd).keyExists(strings::menu_params)) { + SmartObjectSPtr message = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); + DCHECK(message); + + SmartObject& object = *message; + object[strings::params][strings::function_id] = + hmi_apis::FunctionID::UI_DeleteCommand; + + object[strings::msg_params] = msg_params; + + app_mngr.ManageHMICommand(message); + } + + if ((*cmd).keyExists(strings::vr_commands)) { + msg_params[strings::grammar_id] = application->get_grammar_id(); + msg_params[strings::type] = hmi_apis::Common_VRCommandType::Command; + + SmartObjectSPtr message = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); + DCHECK(message); + + SmartObject& object = *message; + object[strings::params][strings::function_id] = + hmi_apis::FunctionID::VR_DeleteCommand; + + object[strings::msg_params] = msg_params; + + app_mngr.ManageHMICommand(message); + } +} + +void MessageHelper::SendDeleteSubmenuRequest(smart_objects::SmartObject* cmd, + ApplicationSharedPtr application, + ApplicationManager& app_mngr) { + LOG4CXX_AUTO_TRACE(logger_); + DCHECK_OR_RETURN_VOID(cmd); + using namespace smart_objects; + + SmartObject msg_params = SmartObject(smart_objects::SmartType_Map); + + msg_params[strings::menu_id] = (*cmd)[strings::menu_id]; + msg_params[strings::app_id] = application->app_id(); + + SmartObjectSPtr message = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); + DCHECK(message); + + SmartObject& object = *message; + object[strings::params][strings::function_id] = + hmi_apis::FunctionID::UI_DeleteSubMenu; + + object[strings::msg_params] = msg_params; + + app_mngr.ManageHMICommand(message); + + const DataAccessor<CommandsMap> accessor = application->commands_map(); + const CommandsMap& commands = accessor.GetData(); + CommandsMap::const_iterator it = commands.begin(); + + for (; commands.end() != it; ++it) { + if (!(*it->second).keyExists(strings::vr_commands)) { + continue; + } + + if ((*cmd)[strings::menu_id].asInt() == + (*it->second)[strings::menu_params][hmi_request::parent_id].asInt()) { + SmartObject msg_params = SmartObject(smart_objects::SmartType_Map); + msg_params[strings::cmd_id] = (*it->second)[strings::cmd_id].asInt(); + msg_params[strings::app_id] = application->app_id(); + msg_params[strings::grammar_id] = application->get_grammar_id(); + msg_params[strings::type] = hmi_apis::Common_VRCommandType::Command; + + SmartObjectSPtr message = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); + DCHECK(message); + + SmartObject& object = *message; + object[strings::params][strings::function_id] = + hmi_apis::FunctionID::VR_DeleteCommand; + + object[strings::msg_params] = msg_params; + + app_mngr.ManageHMICommand(message); + } + } +} + +void MessageHelper::SendDeleteChoiceSetRequest(smart_objects::SmartObject* cmd, + ApplicationSharedPtr application, + ApplicationManager& app_mngr) { + LOG4CXX_AUTO_TRACE(logger_); + DCHECK_OR_RETURN_VOID(cmd); + using namespace smart_objects; + + // Same is deleted with SendDeleteCommandRequest? + + SmartObject msg_params = SmartObject(smart_objects::SmartType_Map); + + msg_params[strings::app_id] = application->app_id(); + msg_params[strings::type] = hmi_apis::Common_VRCommandType::Choice; + msg_params[strings::grammar_id] = (*cmd)[strings::grammar_id]; + cmd = &((*cmd)[strings::choice_set]); + for (uint32_t i = 0; i < (*cmd).length(); ++i) { + msg_params[strings::cmd_id] = (*cmd)[i][strings::choice_id]; + + SmartObjectSPtr message = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); + DCHECK(message); + + SmartObject& object = *message; + object[strings::params][strings::function_id] = + hmi_apis::FunctionID::VR_DeleteCommand; + + object[strings::msg_params] = msg_params; + + app_mngr.ManageHMICommand(message); + } +} + +void MessageHelper::SendResetPropertiesRequest(ApplicationSharedPtr application, + ApplicationManager& app_mngr) { + LOG4CXX_AUTO_TRACE(logger_); + using namespace smart_objects; + + { + SmartObject msg_params = SmartObject(smart_objects::SmartType_Map); + + msg_params = *MessageHelper::CreateAppVrHelp(application); + msg_params[hmi_request::menu_title] = ""; + + smart_objects::SmartObject key_board_properties = + smart_objects::SmartObject(smart_objects::SmartType_Map); + key_board_properties[strings::language] = + static_cast<int32_t>(hmi_apis::Common_Language::EN_US); + key_board_properties[hmi_request::keyboard_layout] = + static_cast<int32_t>(hmi_apis::Common_KeyboardLayout::QWERTY); + + key_board_properties[hmi_request::auto_complete_text] = ""; + msg_params[hmi_request::keyboard_properties] = key_board_properties; + + msg_params[strings::app_id] = application->app_id(); + + SmartObjectSPtr message = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); + DCHECK(message); + + SmartObject& object = *message; + object[strings::params][strings::function_id] = + hmi_apis::FunctionID::UI_SetGlobalProperties; + + object[strings::msg_params] = msg_params; + + app_mngr.ManageHMICommand(message); + } + + { + SmartObject msg_params = SmartObject(smart_objects::SmartType_Map); + + msg_params[strings::help_prompt] = application->help_prompt(); + msg_params[strings::timeout_prompt] = application->timeout_prompt(); + msg_params[strings::app_id] = application->app_id(); + + SmartObjectSPtr message = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); + DCHECK(message); + + SmartObject& object = *message; + object[strings::params][strings::function_id] = + hmi_apis::FunctionID::TTS_SetGlobalProperties; + + object[strings::msg_params] = msg_params; + + app_mngr.ManageHMICommand(message); + } +} + +void MessageHelper::SendUnsubscribeButtonNotification( + mobile_apis::ButtonName::eType button, + ApplicationSharedPtr application, + ApplicationManager& app_mngr) { + using namespace smart_objects; + using namespace hmi_apis; + + SmartObject msg_params = SmartObject(SmartType_Map); + msg_params[strings::app_id] = application->app_id(); + msg_params[strings::name] = button; + msg_params[strings::is_suscribed] = false; + + SmartObjectSPtr message = CreateMessageForHMI( + hmi_apis::messageType::notification, app_mngr.GetNextHMICorrelationID()); + DCHECK(message); + + SmartObject& object = *message; + object[strings::params][strings::function_id] = + hmi_apis::FunctionID::Buttons_OnButtonSubscription; + + object[strings::msg_params] = msg_params; + + app_mngr.ManageHMICommand(message); +} + +void MessageHelper::SendUnsubscribeIVIRequest(int32_t ivi_id, + ApplicationSharedPtr application, + ApplicationManager& app_mngr) { + using namespace smart_objects; + + std::string key_name; + for (auto item : vehicle_data_) { + if (ivi_id == item.second) { + key_name = item.first; + break; + } + } + + if (key_name.empty()) { + return; + } + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[key_name] = true; + + SmartObjectSPtr message = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); + DCHECK(message); + + SmartObject& object = *message; + object[strings::params][strings::function_id] = + hmi_apis::FunctionID::VehicleInfo_UnsubscribeVehicleData; + + object[strings::msg_params] = msg_params; + + app_mngr.ManageHMICommand(message); +} + const VehicleData& MessageHelper::vehicle_data() { return vehicle_data_; } @@ -788,6 +1063,11 @@ smart_objects::SmartObjectSPtr MessageHelper::CreateSetAppIcon( bool MessageHelper::SendIVISubscribtions(const uint32_t app_id, ApplicationManager& app_mngr) { + return SendIVISubscriptions(app_id, app_mngr); +} + +bool MessageHelper::SendIVISubscriptions(const uint32_t app_id, + ApplicationManager& app_mngr) { LOG4CXX_AUTO_TRACE(logger_); bool result = true; @@ -829,7 +1109,7 @@ smart_objects::SmartObjectList MessageHelper::GetIVISubscriptionRequests( const VehicleInfoSubscriptions& subscriptions = vi_accessor.GetData(); for (; vehicle_data.end() != ivi_it; ++ivi_it) { - uint32_t type_id = static_cast<int>(ivi_it->second); + mobile_apis::VehicleDataType::eType type_id = ivi_it->second; if (subscriptions.end() != subscriptions.find(type_id)) { std::string key_name = ivi_it->first; msg_params[key_name] = true; @@ -850,7 +1130,7 @@ smart_objects::SmartObjectList MessageHelper::GetIVISubscriptionRequests( if (true == msg_params.keyExists(sr.str) && true == msg_params[sr.str].asBool()) { smart_objects::SmartObjectSPtr request = - MessageHelper::CreateModuleInfoSO(sr.func_id); + MessageHelper::CreateModuleInfoSO(sr.func_id, app_mngr); (*request)[strings::msg_params] = msg_params; hmi_requests.push_back(request); } @@ -927,7 +1207,9 @@ void MessageHelper::SendSetAppIcon( using namespace smart_objects; SmartObjectSPtr set_app_icon = - CreateRequestObject(application_manager.GetNextHMICorrelationID()); + CreateMessageForHMI(hmi_apis::messageType::request, + application_manager.GetNextHMICorrelationID()); + if (set_app_icon) { SmartObject& so_to_send = *set_app_icon; so_to_send[strings::params][strings::function_id] = @@ -949,7 +1231,7 @@ void MessageHelper::SendAppDataToHMI(ApplicationConstSharedPtr app, ApplicationManager& app_man) { LOG4CXX_AUTO_TRACE(logger_); if (app) { - SendSetAppIcon(app, app->app_icon_path(), app_man); + SendSetAppIcon(app->app_id(), app->app_icon_path(), app_man); SendGlobalPropertiesToHMI(app, app_man); SendShowRequestToHMI(app, app_man); } @@ -986,7 +1268,7 @@ MessageHelper::CreateGlobalPropertiesRequestsToHMI( if (app->vr_help_title() || app->vr_help()) { smart_objects::SmartObjectSPtr ui_global_properties = - CreateRequestObject(correlation_id); + CreateMessageForHMI(hmi_apis::messageType::request, correlation_id); if (!ui_global_properties) { return requests; } @@ -1021,7 +1303,7 @@ MessageHelper::CreateGlobalPropertiesRequestsToHMI( // TTS global properties if (app->help_prompt() || app->timeout_prompt()) { smart_objects::SmartObjectSPtr tts_global_properties = - CreateRequestObject(correlation_id); + CreateMessageForHMI(hmi_apis::messageType::request, correlation_id); if (!tts_global_properties) { return requests; } @@ -1053,8 +1335,9 @@ void MessageHelper::SendTTSGlobalProperties(ApplicationSharedPtr app, if (!app) { return; } - smart_objects::SmartObjectSPtr tts_global_properties = - CreateRequestObject(app_man.GetNextHMICorrelationID()); + smart_objects::SmartObjectSPtr tts_global_properties = CreateMessageForHMI( + hmi_apis::messageType::request, app_man.GetNextHMICorrelationID()); + if (tts_global_properties) { smart_objects::SmartObject& so_to_send = *tts_global_properties; so_to_send[strings::params][strings::function_id] = @@ -1132,7 +1415,7 @@ smart_objects::SmartObjectList MessageHelper::CreateShowRequestToHMI( if (app->show_command()) { smart_objects::SmartObjectSPtr ui_show = - CreateRequestObject(correlation_id); + CreateMessageForHMI(hmi_apis::messageType::request, correlation_id); (*ui_show)[strings::params][strings::function_id] = static_cast<int>(hmi_apis::FunctionID::UI_Show); @@ -1164,8 +1447,8 @@ void MessageHelper::SendShowConstantTBTRequestToHMI( } if (app->tbt_show_command()) { - smart_objects::SmartObjectSPtr navi_show_tbt = - CreateRequestObject(app_man.GetNextHMICorrelationID()); + smart_objects::SmartObjectSPtr navi_show_tbt = CreateMessageForHMI( + hmi_apis::messageType::request, app_man.GetNextHMICorrelationID()); if (!navi_show_tbt) { return; } @@ -1205,8 +1488,8 @@ smart_objects::SmartObjectList MessageHelper::CreateAddCommandRequestToHMI( for (; commands.end() != i; ++i) { // UI Interface if ((*i->second).keyExists(strings::menu_params)) { - smart_objects::SmartObjectSPtr ui_command = - CreateRequestObject(app_mngr.GetNextHMICorrelationID()); + smart_objects::SmartObjectSPtr ui_command = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); if (!ui_command) { return requests; } @@ -1258,8 +1541,8 @@ MessageHelper::CreateAddVRCommandRequestFromChoiceToHMI( (*(it->second))[strings::grammar_id].asUInt(); const size_t size = (*(it->second))[strings::choice_set].length(); for (size_t j = 0; j < size; ++j) { - smart_objects::SmartObjectSPtr vr_command = - CreateRequestObject(app_mngr.GetNextHMICorrelationID()); + smart_objects::SmartObjectSPtr vr_command = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); if (!vr_command) { return requests; } @@ -1292,8 +1575,8 @@ smart_objects::SmartObjectSPtr MessageHelper::CreateChangeRegistration( const uint32_t app_id, const smart_objects::SmartObject* app_types, ApplicationManager& app_mngr) { - smart_objects::SmartObjectSPtr command = - CreateRequestObject(app_mngr.GetNextHMICorrelationID()); + smart_objects::SmartObjectSPtr command = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); if (!command) { return NULL; } @@ -1349,8 +1632,8 @@ smart_objects::SmartObjectSPtr MessageHelper::CreateAddVRCommandToHMI( const smart_objects::SmartObject& vr_commands, uint32_t app_id, ApplicationManager& app_mngr) { - smart_objects::SmartObjectSPtr vr_command = - CreateRequestObject(app_mngr.GetNextHMICorrelationID()); + smart_objects::SmartObjectSPtr vr_command = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); if (!vr_command) { return NULL; } @@ -1469,7 +1752,7 @@ smart_objects::SmartObjectList MessageHelper::CreateAddSubMenuRequestToHMI( SubMenuMap::const_iterator i = sub_menu.begin(); for (; sub_menu.end() != i; ++i) { smart_objects::SmartObjectSPtr ui_sub_menu = - CreateRequestObject(correlation_id); + CreateMessageForHMI(hmi_apis::messageType::request, correlation_id); if (!ui_sub_menu) { return requsets; } @@ -1508,7 +1791,7 @@ void MessageHelper::SendOnAppUnregNotificationToHMI( message[strings::params][strings::message_type] = MessageType::kNotification; // we put hmi_app_id because applicaton list does not contain application on // this momment - // and ReplaceHMIByMobileAppId function will be unable to replace app_id to + // and ReplaceHMIWithMobileAppId function will be unable to replace app_id to // hmi_app_id message[strings::msg_params][strings::app_id] = app->hmi_app_id(); message[strings::msg_params][strings::unexpected_disconnect] = @@ -1658,8 +1941,8 @@ void MessageHelper::SendPolicyUpdate(const std::string& file_path, const uint32_t timeout, const std::vector<int>& retries, ApplicationManager& app_mngr) { - smart_objects::SmartObjectSPtr message = - CreateRequestObject(app_mngr.GetNextHMICorrelationID()); + smart_objects::SmartObjectSPtr message = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); smart_objects::SmartObject& object = *message; object[strings::params][strings::function_id] = hmi_apis::FunctionID::BasicCommunication_PolicyUpdate; @@ -1840,8 +2123,8 @@ void MessageHelper::SendNaviSetVideoConfig( ApplicationManager& app_mngr, const smart_objects::SmartObject& video_params) { LOG4CXX_AUTO_TRACE(logger_); - smart_objects::SmartObjectSPtr request = - CreateRequestObject(app_mngr.GetNextHMICorrelationID()); + smart_objects::SmartObjectSPtr request = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); if (!request) { return; } @@ -1858,8 +2141,8 @@ void MessageHelper::SendNaviSetVideoConfig( void MessageHelper::SendNaviStartStream(const int32_t app_id, ApplicationManager& app_mngr) { LOG4CXX_AUTO_TRACE(logger_); - smart_objects::SmartObjectSPtr start_stream = - CreateRequestObject(app_mngr.GetNextHMICorrelationID()); + smart_objects::SmartObjectSPtr start_stream = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); if (!start_stream) { return; } @@ -1897,8 +2180,8 @@ void MessageHelper::SendNaviStartStream(const int32_t app_id, void MessageHelper::SendNaviStopStream(const int32_t app_id, ApplicationManager& app_mngr) { LOG4CXX_AUTO_TRACE(logger_); - smart_objects::SmartObjectSPtr stop_stream = - CreateRequestObject(app_mngr.GetNextHMICorrelationID()); + smart_objects::SmartObjectSPtr stop_stream = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); if (!stop_stream) { return; } @@ -1914,8 +2197,8 @@ void MessageHelper::SendNaviStopStream(const int32_t app_id, void MessageHelper::SendAudioStartStream(const int32_t app_id, ApplicationManager& app_mngr) { LOG4CXX_AUTO_TRACE(logger_); - smart_objects::SmartObjectSPtr start_stream = - CreateRequestObject(app_mngr.GetNextHMICorrelationID()); + smart_objects::SmartObjectSPtr start_stream = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); if (!start_stream) { return; @@ -1954,8 +2237,8 @@ void MessageHelper::SendAudioStartStream(const int32_t app_id, void MessageHelper::SendAudioStopStream(const int32_t app_id, ApplicationManager& app_mngr) { LOG4CXX_AUTO_TRACE(logger_); - smart_objects::SmartObjectSPtr stop_stream = - CreateRequestObject(app_mngr.GetNextHMICorrelationID()); + smart_objects::SmartObjectSPtr stop_stream = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); if (!stop_stream) { return; @@ -2004,8 +2287,8 @@ void MessageHelper::SendOnDataStreaming( bool MessageHelper::SendStopAudioPathThru(ApplicationManager& app_mngr) { LOG4CXX_INFO(logger_, "MessageHelper::SendAudioStopAudioPathThru"); - smart_objects::SmartObjectSPtr result = - CreateRequestObject(app_mngr.GetNextHMICorrelationID()); + smart_objects::SmartObjectSPtr result = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); (*result)[strings::params][strings::function_id] = hmi_apis::FunctionID::UI_EndAudioPassThru; @@ -2016,8 +2299,8 @@ bool MessageHelper::SendStopAudioPathThru(ApplicationManager& app_mngr) { bool MessageHelper::SendUnsubscribedWayPoints(ApplicationManager& app_mngr) { LOG4CXX_INFO(logger_, "MessageHelper::SendUnsubscribedWayPoints"); - smart_objects::SmartObjectSPtr result = - CreateRequestObject(app_mngr.GetNextHMICorrelationID()); + smart_objects::SmartObjectSPtr result = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); (*result)[strings::params][strings::function_id] = hmi_apis::FunctionID::Navigation_UnsubscribeWayPoints; @@ -2134,6 +2417,7 @@ void MessageHelper::SendOnPermissionsChangeNotification( uint32_t connection_key, const policy::Permissions& permissions, ApplicationManager& app_mngr) { + LOG4CXX_AUTO_TRACE(logger_); smart_objects::SmartObject content(smart_objects::SmartType_Map); content[strings::params][strings::function_id] = @@ -2376,8 +2660,8 @@ void MessageHelper::SendOnStatusUpdate(const std::string& status, } void MessageHelper::SendGetSystemInfoRequest(ApplicationManager& app_mngr) { - smart_objects::SmartObjectSPtr message = - CreateRequestObject(app_mngr.GetNextHMICorrelationID()); + smart_objects::SmartObjectSPtr message = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); if (!message) { return; } diff --git a/src/components/application_manager/src/mobile_message_handler.cc b/src/components/application_manager/src/mobile_message_handler.cc index a3b5aa7dbd..2f06c5f3b5 100644 --- a/src/components/application_manager/src/mobile_message_handler.cc +++ b/src/components/application_manager/src/mobile_message_handler.cc @@ -196,7 +196,7 @@ MobileMessageHandler::HandleIncomingMessageProtocolV2( outgoing_message->set_payload_size(message->payload_size()); if (!payload.data.empty()) { - BinaryData binary_payload_data(payload.data); + const BinaryData binary_payload_data(payload.data); outgoing_message->set_binary_data(&binary_payload_data); } return outgoing_message.release(); diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index e6ebaf3b83..559b9c0035 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -103,7 +103,7 @@ const std::string RequestTypeToString(mobile_apis::RequestType::eType type) { const policy::DeviceParams GetDeviceParams( connection_handler::DeviceHandle device_handle, const protocol_handler::SessionObserver& session_observer) { - CREATE_LOGGERPTR_LOCAL(logger_, "PolicyHandler") + CREATE_LOGGERPTR_LOCAL(logger_, "PolicyHandler"); policy::DeviceParams device_params; if (-1 == session_observer.GetDataOnDeviceID( @@ -852,6 +852,13 @@ uint32_t PolicyHandler::ChooseRandomAppForPolicyUpdate( return 0; } +void PolicyHandler::OnDeviceSwitching(const std::string& device_id_from, + const std::string& device_id_to) { + LOG4CXX_AUTO_TRACE(logger_); + POLICY_LIB_CHECK_VOID(); + policy_manager_->OnDeviceSwitching(device_id_from, device_id_to); +} + void PolicyHandler::OnGetStatusUpdate(const uint32_t correlation_id) { LOG4CXX_AUTO_TRACE(logger_); POLICY_LIB_CHECK_VOID(); @@ -1084,8 +1091,7 @@ bool PolicyHandler::ReceiveMessageFromSDK(const std::string& file, MessageHelper::CreateGetVehicleDataRequest( correlation_id, vehicle_data_args, application_manager_); } else { - LOG4CXX_WARN(logger_, "Exchange wasn't successful, trying another one."); - policy_manager_->ForcePTExchange(); + LOG4CXX_WARN(logger_, "Exchange wasn't successful"); } OnPTUFinished(ret); return ret; @@ -1170,7 +1176,7 @@ void PolicyHandler::OnAllowSDLFunctionalityNotification( continue; } policy_manager_->SetUserConsentForDevice(device_id, is_allowed); - uint32_t device_handle = 0; + connection_handler::DeviceHandle device_handle = 0; if (!connection_handler.GetDeviceID(device_id, &device_handle)) { LOG4CXX_WARN(logger_, "Device handle with mac " << device_id @@ -1204,7 +1210,7 @@ void PolicyHandler::OnAllowSDLFunctionalityNotification( } // Case, when specific device was changed - uint32_t device_handle = 0u; + connection_handler::DeviceHandle device_handle = 0u; if (device_specific) { policy_manager_->SetUserConsentForDevice(device_mac, is_allowed); if (!connection_handler.GetDeviceID(device_mac, &device_handle)) { @@ -1216,6 +1222,7 @@ void PolicyHandler::OnAllowSDLFunctionalityNotification( device_handle); // If consent done from HMI menu if (it == pending_device_handles_.end()) { + LOG4CXX_WARN(logger_, "No pendining application activation"); return; } @@ -1768,7 +1775,7 @@ void PolicyHandler::OnCertificateUpdated(const std::string& certificate_data) { void PolicyHandler::OnPTUFinished(const bool ptu_result) { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(listeners_lock_); - HandlersCollection::const_iterator it = listeners_.begin(); + std::for_each( listeners_.begin(), listeners_.end(), diff --git a/src/components/application_manager/src/request_controller.cc b/src/components/application_manager/src/request_controller.cc index 1b9bd7ffb9..f341967842 100644 --- a/src/components/application_manager/src/request_controller.cc +++ b/src/components/application_manager/src/request_controller.cc @@ -50,6 +50,7 @@ RequestController::RequestController(const RequestControlerSettings& settings) : pool_state_(UNDEFINED) , pool_size_(settings.thread_pool_size()) , request_tracker_(settings) + , duplicate_message_count_() , timer_("AM RequestCtrlTimer", new timer::TimerTaskImpl<RequestController>( this, &RequestController::TimeoutThread)) @@ -230,6 +231,21 @@ void RequestController::TerminateRequest(const uint32_t correlation_id, << correlation_id << " connection_key = " << connection_key << " function_id = " << function_id << " force_terminate = " << force_terminate); + { + AutoLock auto_lock(duplicate_message_count_lock_); + auto dup_it = duplicate_message_count_.find(correlation_id); + if (duplicate_message_count_.end() != dup_it) { + duplicate_message_count_[correlation_id]--; + if (0 == duplicate_message_count_[correlation_id]) { + duplicate_message_count_.erase(dup_it); + } + LOG4CXX_DEBUG(logger_, + "Ignoring termination request due to duplicate correlation " + "ID being sent"); + return; + } + } + RequestInfoPtr request = waiting_for_response_.Find(connection_key, correlation_id); if (!request) { @@ -474,7 +490,24 @@ void RequestController::Worker::threadMain() { RequestInfoPtr request_info_ptr = utils::MakeShared<MobileRequestInfo>(request_ptr, timeout_in_mseconds); - request_controller_->waiting_for_response_.Add(request_info_ptr); + if (!request_controller_->waiting_for_response_.Add(request_info_ptr)) { + commands::CommandRequestImpl* cmd_request = + dynamic_cast<commands::CommandRequestImpl*>(request_ptr.get()); + if (cmd_request != NULL) { + uint32_t corr_id = cmd_request->correlation_id(); + request_controller_->duplicate_message_count_lock_.Acquire(); + auto dup_it = + request_controller_->duplicate_message_count_.find(corr_id); + if (request_controller_->duplicate_message_count_.end() == dup_it) { + request_controller_->duplicate_message_count_[corr_id] = 0; + } + request_controller_->duplicate_message_count_[corr_id]++; + request_controller_->duplicate_message_count_lock_.Release(); + cmd_request->SendResponse( + false, mobile_apis::Result::INVALID_ID, "Duplicate correlation_id"); + } + continue; + } LOG4CXX_DEBUG(logger_, "timeout_in_mseconds " << timeout_in_mseconds); if (0 != timeout_in_mseconds) { 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 e7788bf9ff..bfb82a8eeb 100644 --- a/src/components/application_manager/src/resumption/resume_ctrl_impl.cc +++ b/src/components/application_manager/src/resumption/resume_ctrl_impl.cc @@ -67,6 +67,7 @@ ResumeCtrlImpl::ResumeCtrlImpl(ApplicationManager& application_manager) this, &ResumeCtrlImpl::SaveDataOnTimer)) , is_resumption_active_(false) , is_data_saved_(false) + , is_suspended_(false) , launch_time_(time(NULL)) , application_manager_(application_manager) {} #ifdef BUILD_TESTS @@ -160,7 +161,17 @@ bool ResumeCtrlImpl::RestoreAppHMIState(ApplicationSharedPtr application) { static_cast<mobile_apis::HMILevel::eType>( saved_app[strings::hmi_level].asInt()); LOG4CXX_DEBUG(logger_, "Saved HMI Level is : " << saved_hmi_level); - return SetAppHMIState(application, saved_hmi_level, true); + result = SetAppHMIState(application, saved_hmi_level, true); + if (result) { + const HMILevel::eType def_hmi_level = + application_manager_.GetDefaultHmiLevel(application); + if (def_hmi_level != saved_hmi_level) { + auto& help_prompt_manager = application->help_prompt_manager(); + const bool is_restore = true; + help_prompt_manager.OnAppActivated(is_restore); + } + } + return result; } else { result = false; LOG4CXX_ERROR(logger_, "saved app data corrupted"); @@ -263,16 +274,25 @@ bool ResumeCtrlImpl::RemoveApplicationFromSaved( void ResumeCtrlImpl::OnSuspend() { LOG4CXX_AUTO_TRACE(logger_); - StopSavePersistentDataTimer(); - SaveAllApplications(); - resumption_storage_->OnSuspend(); - resumption_storage_->Persist(); + is_suspended_ = true; + FinalPersistData(); +} + +void ResumeCtrlImpl::OnIgnitionOff() { + LOG4CXX_AUTO_TRACE(logger_); + resumption_storage_->IncrementIgnOffCount(); + FinalPersistData(); } void ResumeCtrlImpl::OnAwake() { + LOG4CXX_AUTO_TRACE(logger_); + is_suspended_ = false; ResetLaunchTime(); StartSavePersistentDataTimer(); - return resumption_storage_->OnAwake(); +} + +bool ResumeCtrlImpl::is_suspended() const { + return is_suspended_; } void ResumeCtrlImpl::StartSavePersistentDataTimer() { @@ -433,6 +453,13 @@ void ResumeCtrlImpl::SaveDataOnTimer() { } } +void ResumeCtrlImpl::FinalPersistData() { + LOG4CXX_AUTO_TRACE(logger_); + StopSavePersistentDataTimer(); + SaveAllApplications(); + resumption_storage_->Persist(); +} + bool ResumeCtrlImpl::IsDeviceMacAddressEqual( ApplicationSharedPtr application, const std::string& saved_device_mac) { LOG4CXX_AUTO_TRACE(logger_); @@ -580,7 +607,7 @@ void ResumeCtrlImpl::AddWayPointsSubscription( const smart_objects::SmartObject& subscribed_for_way_points_so = saved_app[strings::subscribed_for_way_points]; if (true == subscribed_for_way_points_so.asBool()) { - application_manager_.SubscribeAppForWayPoints(application->app_id()); + application_manager_.SubscribeAppForWayPoints(application); } } } @@ -589,29 +616,30 @@ void ResumeCtrlImpl::AddSubscriptions( ApplicationSharedPtr application, const smart_objects::SmartObject& saved_app) { LOG4CXX_AUTO_TRACE(logger_); - if (saved_app.keyExists(strings::application_subscribtions)) { - const smart_objects::SmartObject& subscribtions = - saved_app[strings::application_subscribtions]; + if (saved_app.keyExists(strings::application_subscriptions)) { + const smart_objects::SmartObject& subscriptions = + saved_app[strings::application_subscriptions]; - if (subscribtions.keyExists(strings::application_buttons)) { - const smart_objects::SmartObject& subscribtions_buttons = - subscribtions[strings::application_buttons]; + if (subscriptions.keyExists(strings::application_buttons)) { + const smart_objects::SmartObject& subscriptions_buttons = + subscriptions[strings::application_buttons]; mobile_apis::ButtonName::eType btn; - for (size_t i = 0; i < subscribtions_buttons.length(); ++i) { + for (size_t i = 0; i < subscriptions_buttons.length(); ++i) { btn = static_cast<mobile_apis::ButtonName::eType>( - (subscribtions_buttons[i]).asInt()); + (subscriptions_buttons[i]).asInt()); application->SubscribeToButton(btn); } } MessageHelper::SendAllOnButtonSubscriptionNotificationsForApp( application, application_manager_); - if (subscribtions.keyExists(strings::application_vehicle_info)) { - const smart_objects::SmartObject& subscribtions_ivi = - subscribtions[strings::application_vehicle_info]; - VehicleDataType ivi; - for (size_t i = 0; i < subscribtions_ivi.length(); ++i) { - ivi = static_cast<VehicleDataType>((subscribtions_ivi[i]).asInt()); + if (subscriptions.keyExists(strings::application_vehicle_info)) { + const smart_objects::SmartObject& subscriptions_ivi = + subscriptions[strings::application_vehicle_info]; + mobile_apis::VehicleDataType::eType ivi; + for (size_t i = 0; i < subscriptions_ivi.length(); ++i) { + ivi = static_cast<mobile_apis::VehicleDataType::eType>( + (subscriptions_ivi[i]).asInt()); application->SubscribeToIVI(ivi); } ProcessHMIRequests(MessageHelper::GetIVISubscriptionRequests( @@ -773,7 +801,7 @@ void ResumeCtrlImpl::LoadResumeData() { "Resumption data for application " << app_id << " and device id " << device_id << " will be dropped."); - resumption_storage_->DropAppDataResumption(device_id, app_id); + resumption_storage_->RemoveApplicationFromSaved(app_id, device_id); continue; } } diff --git a/src/components/application_manager/src/resumption/resumption_data.cc b/src/components/application_manager/src/resumption/resumption_data.cc index 273cd5413e..bd5bdbddab 100644 --- a/src/components/application_manager/src/resumption/resumption_data.cc +++ b/src/components/application_manager/src/resumption/resumption_data.cc @@ -33,7 +33,6 @@ #include "application_manager/resumption/resumption_data.h" #include "utils/logger.h" #include "application_manager/smart_object_keys.h" -#include "application_manager/vehicle_info_data.h" #include "application_manager/application_manager_settings.h" namespace resumption { diff --git a/src/components/application_manager/src/resumption/resumption_data_db.cc b/src/components/application_manager/src/resumption/resumption_data_db.cc index 08de6d8190..2fe7330a9c 100644 --- a/src/components/application_manager/src/resumption/resumption_data_db.cc +++ b/src/components/application_manager/src/resumption/resumption_data_db.cc @@ -212,7 +212,9 @@ uint32_t ResumptionDataDB::GetHMIApplicationID( return hmi_app_id; } -void ResumptionDataDB::OnSuspend() { +DEPRECATED void ResumptionDataDB::OnSuspend() {} + +void ResumptionDataDB::IncrementIgnOffCount() { LOG4CXX_AUTO_TRACE(logger_); utils::dbms::SQLQuery query_update_suspend_data(db()); @@ -291,7 +293,9 @@ bool ResumptionDataDB::GetHashId(const std::string& policy_app_id, return SelectHashId(policy_app_id, device_id, hash_id); } -void ResumptionDataDB::OnAwake() { +DEPRECATED void ResumptionDataDB::OnAwake() {} + +void ResumptionDataDB::DecrementIgnOffCount() { LOG4CXX_AUTO_TRACE(logger_); UpdateDataOnAwake(); @@ -949,7 +953,7 @@ bool ResumptionDataDB::SelectSubscriptionsData( return false; } - saved_app[strings::application_subscribtions] = SmartObject(SmartType_Map); + saved_app[strings::application_subscriptions] = SmartObject(SmartType_Map); if (0 == count_item) { LOG4CXX_INFO(logger_, "Application does not contain subscriptions data"); @@ -968,8 +972,8 @@ bool ResumptionDataDB::SelectSubscriptionsData( size_t buttons_idx = 0; size_t vi_idx = 0; /* Position of data in "select_subscriptions" : - field "vehicleValue" from table "applicationSubscribtionsArray" = 0 - field "ButtonNameValue" from table "applicationSubscribtionsArray" = 1*/ + field "vehicleValue" from table "applicationSubscriptionsArray" = 0 + field "ButtonNameValue" from table "applicationSubscriptionsArray" = 1*/ while (select_subscriptions.Next()) { if (!select_subscriptions.IsNull(0)) { application_vehicle_info[vi_idx++] = select_subscriptions.GetInteger(0); @@ -979,12 +983,12 @@ bool ResumptionDataDB::SelectSubscriptionsData( } } if (!application_buttons.empty()) { - saved_app[strings::application_subscribtions] + saved_app[strings::application_subscriptions] [strings::application_buttons] = application_buttons; } if (!application_vehicle_info.empty()) { - saved_app[strings::application_subscribtions] + saved_app[strings::application_subscriptions] [strings::application_vehicle_info] = application_vehicle_info; } LOG4CXX_INFO(logger_, "Subscriptions were restored from DB successfully"); @@ -1500,9 +1504,9 @@ bool ResumptionDataDB::DeleteSavedSubscriptions( LOG4CXX_AUTO_TRACE(logger_); if (!ExecQueryToDeleteData( - policy_app_id, device_id, kDeleteApplicationSubscribtionsArray)) { + policy_app_id, device_id, kDeleteApplicationSubscriptionsArray)) { LOG4CXX_WARN(logger_, - "Incorrect delete from applicationSubscribtionsArray."); + "Incorrect delete from applicationSubscriptionsArray."); return false; } return true; @@ -1895,7 +1899,7 @@ bool ResumptionDataDB::SaveApplicationToDB( } if (!InsertSubscriptionsData(GetApplicationSubscriptions(application), application_primary_key)) { - LOG4CXX_WARN(logger_, "Incorrect insert subscribtions data to DB."); + LOG4CXX_WARN(logger_, "Incorrect insert subscriptions data to DB."); db_->RollbackTransaction(); return false; } @@ -1952,9 +1956,9 @@ bool ResumptionDataDB::SaveApplicationToDB( db_->RollbackTransaction(); return false; } - if (!InsertSubscriptionsData(application["subscribtions"], + if (!InsertSubscriptionsData(application["subscriptions"], application_primary_key)) { - LOG4CXX_WARN(logger_, "Incorrect insert subscribtions data to DB."); + LOG4CXX_WARN(logger_, "Incorrect insert subscriptions data to DB."); db_->RollbackTransaction(); return false; } @@ -2160,9 +2164,9 @@ bool ResumptionDataDB::InsertSubscriptionsData( return false; } /* Positions of binding data for "insert_subscriptions": - field "idApplication" from table "applicationSubscribtionsArray" = 0 - field "vehicleValue" from table "applicationSubscribtionsArray" = 1 - field "ButtonNameValue" from table "applicationSubscribtionsArray" = 2*/ + field "idApplication" from table "applicationSubscriptionsArray" = 0 + field "vehicleValue" from table "applicationSubscriptionsArray" = 1 + field "ButtonNameValue" from table "applicationSubscriptionsArray" = 2*/ for (size_t i = 0; i < max_length; ++i) { insert_subscriptions.Bind(0, application_primary_key); if (i < vi_sub_length) { @@ -2578,7 +2582,7 @@ bool ResumptionDataDB::InsertApplicationData( const mobile_apis::HMILevel::eType hmi_level = application.m_hmi_level; bool is_media_application = application.m_is_media_application; bool is_subscribed_for_way_points = - application_manager_.IsAppSubscribedForWayPoints(connection_key); + application_manager_.IsAppSubscribedForWayPoints(application.app_ptr); if (!query.Prepare(kInsertApplication)) { LOG4CXX_WARN(logger_, @@ -2804,6 +2808,7 @@ ApplicationParams::ApplicationParams(app_mngr::ApplicationSharedPtr application) m_hmi_app_id = application->hmi_app_id(); m_hmi_level = application->hmi_level(); m_is_media_application = application->IsAudioApplication(); + app_ptr = application; } } diff --git a/src/components/application_manager/src/resumption/resumption_data_json.cc b/src/components/application_manager/src/resumption/resumption_data_json.cc index 7866fc4de1..b6a50fd5de 100644 --- a/src/components/application_manager/src/resumption/resumption_data_json.cc +++ b/src/components/application_manager/src/resumption/resumption_data_json.cc @@ -66,7 +66,7 @@ void ResumptionDataJson::SaveApplication( const std::string device_mac = application->mac_address(); const mobile_apis::HMILevel::eType hmi_level = application->hmi_level(); const bool is_subscribed_for_way_points = - application_manager_.IsAppSubscribedForWayPoints(application->app_id()); + application_manager_.IsAppSubscribedForWayPoints(application); sync_primitives::AutoLock autolock(resumption_lock_); Json::Value tmp; @@ -95,7 +95,7 @@ void ResumptionDataJson::SaveApplication( json_app[strings::application_global_properties] = tmp; Formatters::CFormatterJsonBase::objToJsonValue( GetApplicationSubscriptions(application), tmp); - json_app[strings::application_subscribtions] = tmp; + json_app[strings::application_subscriptions] = tmp; Formatters::CFormatterJsonBase::objToJsonValue( GetApplicationFiles(application), tmp); json_app[strings::application_files] = tmp; @@ -143,11 +143,13 @@ uint32_t ResumptionDataJson::GetHMIApplicationID( return hmi_app_id; } -void ResumptionDataJson::OnSuspend() { +DEPRECATED void ResumptionDataJson::OnSuspend() {} + +void ResumptionDataJson::IncrementIgnOffCount() { using namespace app_mngr; LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock autolock(resumption_lock_); - Json::Value to_save; + Json::Value to_save = Json::arrayValue; for (Json::Value::iterator it = GetSavedApplications().begin(); it != GetSavedApplications().end(); ++it) { @@ -167,7 +169,9 @@ void ResumptionDataJson::OnSuspend() { LOG4CXX_DEBUG(logger_, GetResumptionData().toStyledString()); } -void ResumptionDataJson::OnAwake() { +DEPRECATED void ResumptionDataJson::OnAwake() {} + +void ResumptionDataJson::DecrementIgnOffCount() { using namespace app_mngr; LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock autolock(resumption_lock_); @@ -469,7 +473,7 @@ bool ResumptionDataJson::DropAppDataResumption(const std::string& device_id, application[strings::application_submenus].clear(); application[strings::application_choice_sets].clear(); application[strings::application_global_properties].clear(); - application[strings::application_subscribtions].clear(); + application[strings::application_subscriptions].clear(); application[strings::application_files].clear(); application.removeMember(strings::grammar_id); LOG4CXX_DEBUG(logger_, @@ -480,6 +484,9 @@ bool ResumptionDataJson::DropAppDataResumption(const std::string& device_id, } void ResumptionDataJson::Persist() { + // We lock the resumption data because SaveStateToFileSystem accesses + // the same dictionary that we use here in ResumptionDataJson + sync_primitives::AutoLock autolock(resumption_lock_); last_state().SaveStateToFileSystem(); } diff --git a/src/components/application_manager/src/resumption/resumption_sql_queries.cc b/src/components/application_manager/src/resumption/resumption_sql_queries.cc index 5f318e6955..9ca91e859a 100644 --- a/src/components/application_manager/src/resumption/resumption_sql_queries.cc +++ b/src/components/application_manager/src/resumption/resumption_sql_queries.cc @@ -212,7 +212,7 @@ const std::string kCreateSchema = "`vrHelpItemArray`(`idglobalProperties`); " "CREATE TABLE IF NOT EXISTS `application`( " " `idApplication` INTEGER PRIMARY KEY NOT NULL, " - " `appID` TEXT, " + " `appID` TEXT COLLATE NOCASE, " " `connection_key` INTEGER, " " `grammarID` INTEGER, " " `hashID` TEXT, " @@ -298,8 +298,8 @@ const std::string kCreateSchema = "CREATE INDEX IF NOT EXISTS " "`applicationSubMenuArray.fk_Application_idx` " " ON `applicationSubMenuArray`(`idApplication`); " - "CREATE TABLE IF NOT EXISTS `applicationSubscribtionsArray`( " - " `idapplicationSubscribtionsArray` INTEGER PRIMARY KEY NOT NULL, " + "CREATE TABLE IF NOT EXISTS `applicationSubscriptionsArray`( " + " `idapplicationSubscriptionsArray` INTEGER PRIMARY KEY NOT NULL, " " `vehicleValue` INTEGER, " " `ButtonNameValue` INTEGER, " " `idApplication` INTEGER, " @@ -308,8 +308,8 @@ const std::string kCreateSchema = " REFERENCES `application`(`idApplication`) " " ); " "CREATE INDEX IF NOT EXISTS " - "`applicationSubscribtionsArray.fk_Application_idx` " - " ON `applicationSubscribtionsArray`(`idApplication`); " + "`applicationSubscriptionsArray.fk_Application_idx` " + " ON `applicationSubscriptionsArray`(`idApplication`); " "CREATE TABLE IF NOT EXISTS `_internal_data`( " " `db_version_hash` INTEGER " " ); " @@ -365,8 +365,8 @@ const std::string kDropSchema = "DROP TABLE IF EXISTS `applicationSubMenuArray`; " "DROP INDEX IF EXISTS `applicationSubMenuArray.fk_subMenu_idx`; " "DROP INDEX IF EXISTS `applicationSubMenuArray.fk_Application_idx`; " - "DROP TABLE IF EXISTS `applicationSubscribtionsArray`; " - "DROP INDEX IF EXISTS `applicationSubscribtionsArray.fk_Application_idx`; " + "DROP TABLE IF EXISTS `applicationSubscriptionsArray`; " + "DROP INDEX IF EXISTS `applicationSubscriptionsArray.fk_Application_idx`; " "DROP TABLE IF EXISTS `_internal_data`; " "COMMIT; " "VACUUM;"; @@ -477,8 +477,8 @@ const std::string kDeleteApplicationSubMenuArray = "FROM `application` " "WHERE `appID` = ? AND `deviceID` = ?)"; -const std::string kDeleteApplicationSubscribtionsArray = - "DELETE FROM `applicationSubscribtionsArray` " +const std::string kDeleteApplicationSubscriptionsArray = + "DELETE FROM `applicationSubscriptionsArray` " "WHERE `idApplication` = (SELECT `idApplication` " "FROM `application` " "WHERE `appID` = ? AND `deviceID` = ?)"; @@ -713,7 +713,7 @@ const std::string kInsertVrCommand = "(?, ?, ?);"; const std::string kInsertSubscriptions = - "INSERT INTO `applicationSubscribtionsArray` " + "INSERT INTO `applicationSubscriptionsArray` " "(`idApplication`, `vehicleValue`, `ButtonNameValue`) " "VALUES " "(?, ?, ?);"; @@ -851,14 +851,14 @@ const std::string kSelectCommands = const std::string kSelectCountSubscriptions = "SELECT COUNT (`idApplication`) " - "FROM `applicationSubscribtionsArray` " + "FROM `applicationSubscriptionsArray` " "WHERE `idApplication` = (SELECT `idApplication` " "FROM `application` " "WHERE `appID` = ? AND `deviceID` = ?);"; const std::string kSelectSubscriptions = "SELECT `vehicleValue`, `ButtonNameValue` " - "FROM `applicationSubscribtionsArray` " + "FROM `applicationSubscriptionsArray` " "WHERE `idApplication` = (SELECT `idApplication` " "FROM `application` " "WHERE `appID` = ? AND `deviceID` = ?);"; diff --git a/src/components/application_manager/src/smart_object_keys.cc b/src/components/application_manager/src/smart_object_keys.cc index 0bf3287e42..c3aba90dd5 100644 --- a/src/components/application_manager/src/smart_object_keys.cc +++ b/src/components/application_manager/src/smart_object_keys.cc @@ -246,7 +246,7 @@ const char* application_choice_sets = "applicationChoiceSets"; const char* application_global_properties = "globalProperties"; const char* application_vehicle_info = "vehicleInfo"; const char* application_buttons = "buttons"; -const char* application_subscribtions = "subscribtions"; +const char* application_subscriptions = "subscriptions"; const char* application_files = "applicationFiles"; const char* application_show = "applicationShow"; const char* resumption = "resumption"; diff --git a/src/components/application_manager/src/state_controller_impl.cc b/src/components/application_manager/src/state_controller_impl.cc index b456ff6abb..84081a3830 100644 --- a/src/components/application_manager/src/state_controller_impl.cc +++ b/src/components/application_manager/src/state_controller_impl.cc @@ -123,7 +123,7 @@ void StateControllerImpl::SetRegularState( HmiStatePtr prev_regular = app->RegularHmiState(); DCHECK_OR_RETURN_VOID(prev_regular); HmiStatePtr hmi_state = - CreateHmiState(app->app_id(), HmiState::StateID::STATE_ID_REGULAR); + CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN_VOID(hmi_state); hmi_state->set_hmi_level(hmi_level); hmi_state->set_audio_streaming_state(audio_state); @@ -144,7 +144,7 @@ void StateControllerImpl::SetRegularState( return; } const HmiStatePtr hmi_state = - CreateHmiState(app->app_id(), HmiState::StateID::STATE_ID_REGULAR); + CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN_VOID(hmi_state); hmi_state->set_hmi_level(hmi_level); @@ -166,7 +166,7 @@ void StateControllerImpl::SetRegularState( return; } HmiStatePtr hmi_state = - CreateHmiState(app->app_id(), HmiState::StateID::STATE_ID_REGULAR); + CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN_VOID(hmi_state); hmi_state->set_hmi_level(hmi_level); hmi_state->set_audio_streaming_state(audio_state); @@ -184,7 +184,7 @@ void StateControllerImpl::SetRegularState( } HmiStatePtr prev_state = app->RegularHmiState(); HmiStatePtr hmi_state = - CreateHmiState(app->app_id(), HmiState::StateID::STATE_ID_REGULAR); + CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN_VOID(hmi_state); hmi_state->set_hmi_level(hmi_level); hmi_state->set_audio_streaming_state(CalcAudioState(app, hmi_level)); @@ -206,7 +206,7 @@ void StateControllerImpl::SetRegularState( HmiStatePtr prev_regular = app->RegularHmiState(); DCHECK_OR_RETURN_VOID(prev_regular); HmiStatePtr hmi_state = - CreateHmiState(app->app_id(), HmiState::StateID::STATE_ID_REGULAR); + CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN_VOID(hmi_state); hmi_state->set_hmi_level(prev_regular->hmi_level()); hmi_state->set_audio_streaming_state( @@ -227,7 +227,7 @@ void StateControllerImpl::SetRegularState( HmiStatePtr prev_state = app->RegularHmiState(); DCHECK_OR_RETURN_VOID(prev_state); HmiStatePtr hmi_state = - CreateHmiState(app->app_id(), HmiState::StateID::STATE_ID_REGULAR); + CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN_VOID(hmi_state); hmi_state->set_hmi_level(prev_state->hmi_level()); hmi_state->set_audio_streaming_state(audio_state); @@ -325,7 +325,7 @@ HmiStatePtr StateControllerImpl::ResolveHmiState(ApplicationSharedPtr app, << state->system_context()); HmiStatePtr available_state = - CreateHmiState(app->app_id(), HmiState::StateID::STATE_ID_REGULAR); + CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN(available_state, HmiStatePtr()); available_state->set_hmi_level(state->hmi_level()); available_state->set_audio_streaming_state(state->audio_streaming_state()); @@ -502,7 +502,7 @@ void StateControllerImpl::SetupRegularHmiState(ApplicationSharedPtr app, << ", system_context " << state->system_context()); HmiStatePtr curr_state = app->CurrentHmiState(); HmiStatePtr old_state = - CreateHmiState(app->app_id(), HmiState::StateID::STATE_ID_REGULAR); + CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN_VOID(old_state); old_state->set_hmi_level(curr_state->hmi_level()); old_state->set_audio_streaming_state(curr_state->audio_streaming_state()); @@ -533,7 +533,7 @@ void StateControllerImpl::SetupRegularHmiState( HmiStatePtr prev_state = app->RegularHmiState(); DCHECK_OR_RETURN_VOID(prev_state); HmiStatePtr new_state = - CreateHmiState(app->app_id(), HmiState::StateID::STATE_ID_REGULAR); + CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN_VOID(new_state); new_state->set_hmi_level(hmi_level); new_state->set_audio_streaming_state(audio_state); @@ -716,7 +716,7 @@ void StateControllerImpl::OnApplicationRegistered( active_states_lock_.Acquire(); StateIDList::iterator it = active_states_.begin(); for (; it != active_states_.end(); ++it) { - HmiStatePtr new_state = CreateHmiState(app->app_id(), *it); + HmiStatePtr new_state = CreateHmiState(app, *it); DCHECK_OR_RETURN_VOID(new_state); DCHECK_OR_RETURN_VOID(new_state->state_id() != HmiState::STATE_ID_REGULAR); HmiStatePtr old_hmi_state = app->CurrentHmiState(); @@ -726,7 +726,7 @@ void StateControllerImpl::OnApplicationRegistered( active_states_lock_.Release(); HmiStatePtr default_state = - CreateHmiState(app->app_id(), HmiState::StateID::STATE_ID_REGULAR); + CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN_VOID(default_state); default_state->set_hmi_level(default_level); default_state->set_audio_streaming_state(CalcAudioState(app, default_level)); @@ -896,49 +896,49 @@ bool StateControllerImpl::IsStateActive(HmiState::StateID state_id) const { } HmiStatePtr StateControllerImpl::CreateHmiState( - uint32_t app_id, HmiState::StateID state_id) const { + utils::SharedPtr<Application> app, HmiState::StateID state_id) const { using namespace utils; LOG4CXX_AUTO_TRACE(logger_); HmiStatePtr new_state; switch (state_id) { case HmiState::STATE_ID_PHONE_CALL: { - new_state = MakeShared<PhoneCallHmiState>(app_id, app_mngr_); + new_state = MakeShared<PhoneCallHmiState>(app, app_mngr_); break; } case HmiState::STATE_ID_SAFETY_MODE: { - new_state = MakeShared<SafetyModeHmiState>(app_id, app_mngr_); + new_state = MakeShared<SafetyModeHmiState>(app, app_mngr_); break; } case HmiState::STATE_ID_VR_SESSION: { - new_state = MakeShared<VRHmiState>(app_id, app_mngr_); + new_state = MakeShared<VRHmiState>(app, app_mngr_); break; } case HmiState::STATE_ID_TTS_SESSION: { - new_state = MakeShared<TTSHmiState>(app_id, app_mngr_); + new_state = MakeShared<TTSHmiState>(app, app_mngr_); break; } case HmiState::STATE_ID_NAVI_STREAMING: { - new_state = MakeShared<NaviStreamingHmiState>(app_id, app_mngr_); + new_state = MakeShared<NaviStreamingHmiState>(app, app_mngr_); break; } case HmiState::STATE_ID_REGULAR: { - new_state = MakeShared<HmiState>(app_id, app_mngr_); + new_state = MakeShared<HmiState>(app, app_mngr_); break; } case HmiState::STATE_ID_POSTPONED: { - new_state = MakeShared<HmiState>(app_id, app_mngr_, state_id); + new_state = MakeShared<HmiState>(app, app_mngr_, state_id); break; } case HmiState::STATE_ID_DEACTIVATE_HMI: { - new_state = MakeShared<DeactivateHMI>(app_id, app_mngr_); + new_state = MakeShared<DeactivateHMI>(app, app_mngr_); break; } case HmiState::STATE_ID_AUDIO_SOURCE: { - new_state = MakeShared<AudioSource>(app_id, app_mngr_); + new_state = MakeShared<AudioSource>(app, app_mngr_); break; } case HmiState::STATE_ID_EMBEDDED_NAVI: { - new_state = MakeShared<EmbeddedNavi>(app_id, app_mngr_); + new_state = MakeShared<EmbeddedNavi>(app, app_mngr_); break; } default: diff --git a/src/components/application_manager/test/CMakeLists.txt b/src/components/application_manager/test/CMakeLists.txt index 0580998e84..a6a42aee66 100644..100755 --- a/src/components/application_manager/test/CMakeLists.txt +++ b/src/components/application_manager/test/CMakeLists.txt @@ -31,12 +31,6 @@ include(${CMAKE_SOURCE_DIR}/tools/cmake/helpers/platform.cmake) include(${CMAKE_SOURCE_DIR}/tools/cmake/helpers/sources.cmake) -# TODO{ALeshin}: APPLINK-10792. Do not write tests which use -# application manager(AM) singleton while refactoring of AM is finished. - -# TODO{ILytvynenko}: SDLOPEN-797 Uncomment application_manager_impl_test and -# cover with UT missed files. - include_directories( ${GMOCK_INCLUDE_DIRECTORY} ${CMAKE_BINARY_DIR}/src/components/ @@ -68,9 +62,20 @@ set(testSources ${AM_TEST_DIR}/application_state_test.cc ${AM_TEST_DIR}/usage_statistics_test.cc ${AM_TEST_DIR}/policy_handler_test.cc - ${AM_TEST_DIR}/mock_message_helper.cc ${AM_TEST_DIR}/application_manager_impl_test.cc + ${AM_TEST_DIR}/application_helper_test.cc + ${AM_TEST_DIR}/command_holder_test.cc +) + +set(testSourcesMockHmi + ${AM_SOURCE_DIR}/src/message_helper/message_helper.cc + ${AM_TEST_DIR}/application_manager_impl_mock_hmi_test.cc + ${AM_TEST_DIR}/mock_hmi_command_factory.cc +) +set(testSourcesHelpPromptManager +${AM_TEST_DIR}/help_prompt_manager_test.cc +${AM_TEST_DIR}/mock_message_helper.cc ) if(REMOTE_CONTROL) @@ -101,11 +106,14 @@ set(LIBRARIES MediaManager Resumption ProtocolHandler - SecurityManager bson -L${BSON_LIBS_DIRECTORY} emhashmap -L${EMHASHMAP_LIBS_DIRECTORY} ) +if (ENABLE_SECURITY) + list(APPEND LIBRARIES SecurityManager) +endif() + if (${CMAKE_SYSTEM_NAME} MATCHES "QNX") list(REMOVE_ITEM LIBRARIES dl) endif() @@ -130,10 +138,13 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath=${CMAKE_CURRENT_BINARY_DIR}" ) create_test("application_manager_test" "${testSources}" "${LIBRARIES}") +create_test("application_manager_mock_hmi_test" "${testSourcesMockHmi}" "${LIBRARIES}") add_dependencies("application_manager_test" libbson) -create_test("request_controller_test" "${RequestController_SOURCES}" "${LIBRARIES}") -# TODO [AKozoriz] : Fix not buildable tests +create_test("help_prompt_manager_test" "${testSourcesHelpPromptManager}" "${LIBRARIES}") + +create_test("request_controller_test" "${testSourcesHelpPromptManager}" "${LIBRARIES}") + set(ResumptionData_SOURCES ${AM_TEST_DIR}/resumption/resumption_data_test.cc ${AM_TEST_DIR}/resumption/resumption_data_db_test.cc diff --git a/src/components/application_manager/test/application_helper_test.cc b/src/components/application_manager/test/application_helper_test.cc new file mode 100644 index 0000000000..a0b6fd6aa2 --- /dev/null +++ b/src/components/application_manager/test/application_helper_test.cc @@ -0,0 +1,258 @@ +/* + * Copyright (c) 2017, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <gmock/gmock.h> +#include <string> +#include <vector> + +#include "application_manager/mock_application_manager_settings.h" +#include "application_manager/mock_message_helper.h" +#include "policy/usage_statistics/mock_statistics_manager.h" +#include "policy/mock_policy_settings.h" + +#include "application_manager/application.h" +#include "application_manager/application_impl.h" +#include "application_manager/application_manager_impl.h" +#include "application_manager/usage_statistics.h" +#include "application_manager/helpers/application_helper.h" +#include "application_manager/smart_object_keys.h" +#include "interfaces/MOBILE_API.h" +#include "connection_handler/device.h" +#include "smart_objects/smart_object.h" +#include "utils/custom_string.h" +#include "utils/macro.h" +#include "utils/shared_ptr.h" +#include "utils/make_shared.h" + +namespace { +const uint8_t expected_tread_pool_size = 2u; +const uint8_t stop_streaming_timeout = 1u; +const std::string kDirectoryName = "./test_storage"; +const std::vector<std::string> kTimeoutPrompt{"timeoutPrompt"}; +} + +namespace test { +namespace components { +namespace application_manager_test { + +using testing::_; +using ::testing::Mock; +using ::testing::NiceMock; +using ::testing::Return; +using ::testing::ReturnRef; + +using namespace application_manager; +using namespace policy_handler_test; + +class ApplicationHelperTest : public testing::Test { + public: + ApplicationHelperTest() + : mock_message_helper_( + application_manager::MockMessageHelper::message_helper_mock()) + , app_manager_impl_(mock_application_manager_settings_, + mock_policy_settings_) {} + + void SetUp() OVERRIDE { + ON_CALL(mock_application_manager_settings_, thread_pool_size()) + .WillByDefault(Return(expected_tread_pool_size)); + ON_CALL(mock_application_manager_settings_, app_icons_folder()) + .WillByDefault(ReturnRef(kDirectoryName)); + ON_CALL(mock_application_manager_settings_, app_storage_folder()) + .WillByDefault(ReturnRef(kDirectoryName)); + ON_CALL(mock_application_manager_settings_, launch_hmi()) + .WillByDefault(Return(true)); + ON_CALL(mock_application_manager_settings_, stop_streaming_timeout()) + .WillByDefault(Return(stop_streaming_timeout)); + ON_CALL(mock_application_manager_settings_, time_out_promt()) + .WillByDefault(ReturnRef(kTimeoutPrompt)); + + CreateApplication(); + app_manager_impl_.AddMockApplication(app_impl_); + + Mock::VerifyAndClearExpectations(&mock_message_helper_); + } + + void TearDown() OVERRIDE { + Mock::VerifyAndClearExpectations(&mock_message_helper_); + } + + void CreateApplication() { + const uint32_t application_id = 1; + const std::string policy_app_id = "p_app_id"; + const std::string mac_address = "MA:CA:DD:RE:SS"; + const connection_handler::DeviceHandle device_id = 1; + const custom_str::CustomString app_name(""); + + app_impl_ = new ApplicationImpl( + application_id, + policy_app_id, + mac_address, + device_id, + app_name, + utils::MakeShared<usage_statistics_test::MockStatisticsManager>(), + app_manager_impl_); + } + + MockMessageHelper* mock_message_helper_; + NiceMock<MockApplicationManagerSettings> mock_application_manager_settings_; + NiceMock<MockPolicySettings> mock_policy_settings_; + + ApplicationManagerImpl app_manager_impl_; + ApplicationSharedPtr app_impl_; +}; + +TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectAppDataReset) { + const uint32_t cmd_id = 1; + const uint32_t menu_id = 2; + const uint32_t choice_set_id = 3; + const mobile_apis::VehicleDataType::eType vi = + mobile_apis::VehicleDataType::VEHICLEDATA_ACCPEDAL; + const mobile_apis::ButtonName::eType button = mobile_apis::ButtonName::AC; + + smart_objects::SmartObject cmd; + cmd[strings::msg_params][strings::cmd_id] = cmd_id; + cmd[strings::msg_params][strings::vr_commands][0] = "vrCmd"; + cmd[strings::msg_params][strings::menu_id] = menu_id; + cmd[strings::msg_params][strings::interaction_choice_set_id] = choice_set_id; + + app_impl_->AddCommand(cmd_id, cmd[strings::msg_params]); + app_impl_->AddSubMenu(menu_id, cmd[strings::menu_params]); + app_impl_->AddChoiceSet(choice_set_id, cmd[strings::msg_params]); + EXPECT_TRUE(app_impl_->SubscribeToIVI(static_cast<uint32_t>(vi))); + EXPECT_TRUE(app_impl_->SubscribeToButton(button)); + + const std::string some_string = "some_string"; + smart_objects::SmartObject dummy_data = + smart_objects::SmartObject(smart_objects::SmartType_String); + dummy_data = some_string; + app_impl_->set_help_prompt(dummy_data); + app_impl_->set_timeout_prompt(dummy_data); + app_impl_->set_vr_help(dummy_data); + app_impl_->set_vr_help_title(dummy_data); + app_impl_->set_keyboard_props(dummy_data); + app_impl_->set_menu_title(dummy_data); + app_impl_->set_menu_icon(dummy_data); + + const bool persistent = false; + const bool downloaded = true; + const std::string filename = "filename"; + AppFile file(filename, persistent, downloaded, mobile_apis::FileType::BINARY); + + app_impl_->AddFile(file); + + EXPECT_TRUE(NULL != app_impl_->FindCommand(cmd_id)); + EXPECT_TRUE(NULL != app_impl_->FindSubMenu(menu_id)); + EXPECT_TRUE(NULL != app_impl_->FindChoiceSet(choice_set_id)); + EXPECT_TRUE(app_impl_->IsSubscribedToButton(button)); + EXPECT_TRUE(app_impl_->IsSubscribedToIVI(static_cast<uint32_t>(vi))); + auto help_prompt = app_impl_->help_prompt(); + EXPECT_TRUE(help_prompt->asString() == some_string); + auto timeout_prompt = app_impl_->timeout_prompt(); + EXPECT_TRUE(timeout_prompt->asString() == some_string); + auto vr_help = app_impl_->vr_help(); + EXPECT_TRUE(vr_help->asString() == some_string); + auto vr_help_title = app_impl_->vr_help_title(); + EXPECT_TRUE(vr_help_title->asString() == some_string); + auto kb_properties = app_impl_->keyboard_props(); + EXPECT_TRUE(kb_properties->asString() == some_string); + auto menu_title = app_impl_->menu_title(); + EXPECT_TRUE(menu_title->asString() == some_string); + auto menu_icon = app_impl_->menu_icon(); + EXPECT_TRUE(menu_icon->asString() == some_string); + auto file_ptr = app_impl_->GetFile(filename); + EXPECT_TRUE(NULL != file_ptr); + EXPECT_TRUE(file_ptr->file_name == filename); + + // Act + application_manager::DeleteApplicationData(app_impl_, app_manager_impl_); + EXPECT_FALSE(NULL != app_impl_->FindCommand(cmd_id)); + EXPECT_FALSE(NULL != app_impl_->FindSubMenu(menu_id)); + EXPECT_FALSE(NULL != app_impl_->FindChoiceSet(choice_set_id)); + EXPECT_FALSE(app_impl_->IsSubscribedToButton(button)); + EXPECT_FALSE(app_impl_->IsSubscribedToIVI(static_cast<uint32_t>(vi))); + help_prompt = app_impl_->help_prompt(); + EXPECT_FALSE(help_prompt->asString() == some_string); + timeout_prompt = app_impl_->timeout_prompt(); + EXPECT_FALSE(timeout_prompt->asString() == some_string); + vr_help = app_impl_->vr_help(); + EXPECT_TRUE(vr_help == NULL); + vr_help_title = app_impl_->vr_help_title(); + EXPECT_TRUE(vr_help_title == NULL); + kb_properties = app_impl_->keyboard_props(); + EXPECT_FALSE(kb_properties->asString() == some_string); + menu_title = app_impl_->menu_title(); + EXPECT_FALSE(menu_title->asString() == some_string); + menu_icon = app_impl_->menu_icon(); + EXPECT_FALSE(menu_icon->asString() == some_string); + file_ptr = app_impl_->GetFile(filename); + EXPECT_TRUE(NULL == file_ptr); +} + +TEST_F(ApplicationHelperTest, RecallApplicationData_ExpectHMICleanupRequests) { + const uint32_t cmd_id = 1; + const uint32_t menu_id = 2; + const uint32_t choice_set_id = 3; + smart_objects::SmartObject cmd; + cmd[strings::msg_params][strings::cmd_id] = cmd_id; + cmd[strings::msg_params][strings::vr_commands][0] = "vrCmd"; + cmd[strings::msg_params][strings::menu_id] = menu_id; + cmd[strings::msg_params][strings::interaction_choice_set_id] = choice_set_id; + + app_impl_->AddCommand(cmd_id, cmd[strings::msg_params]); + app_impl_->AddSubMenu(menu_id, cmd[strings::menu_params]); + app_impl_->AddChoiceSet(choice_set_id, cmd[strings::msg_params]); + app_impl_->SubscribeToIVI(static_cast<uint32_t>( + mobile_apis::VehicleDataType::VEHICLEDATA_ACCPEDAL)); + app_impl_->SubscribeToButton(mobile_apis::ButtonName::AC); + + EXPECT_CALL(*mock_message_helper_, SendUnsubscribedWayPoints(_)); + + EXPECT_CALL(*mock_message_helper_, SendDeleteCommandRequest(_, _, _)); + + EXPECT_CALL(*mock_message_helper_, SendDeleteSubmenuRequest(_, _, _)); + + EXPECT_CALL(*mock_message_helper_, SendDeleteChoiceSetRequest(_, _, _)); + + EXPECT_CALL(*mock_message_helper_, SendResetPropertiesRequest(_, _)); + + EXPECT_CALL(*mock_message_helper_, + SendUnsubscribeButtonNotification(_, _, _)); + + EXPECT_CALL(*mock_message_helper_, SendUnsubscribeIVIRequest(_, _, _)); + + // Act + application_manager::DeleteApplicationData(app_impl_, app_manager_impl_); +} + +} // application_manager_test +} // components +} // test diff --git a/src/components/application_manager/test/application_impl_test.cc b/src/components/application_manager/test/application_impl_test.cc index a1e284b40d..6b7f78b8f7 100644 --- a/src/components/application_manager/test/application_impl_test.cc +++ b/src/components/application_manager/test/application_impl_test.cc @@ -50,6 +50,7 @@ #include "resumption/last_state.h" #include "application_manager/resumption/resume_ctrl.h" #include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/mock_resume_ctrl.h" #include "policy/usage_statistics/mock_statistics_manager.h" #include "smart_objects/smart_object.h" @@ -77,14 +78,12 @@ class ApplicationImplTest : public ::testing::Test { policy_app_id = "policy_app_id"; app_name = "app_name"; mac_address = "mac_address"; + device_handle = 0; test_lvl = HMILevel::INVALID_ENUM; state_id = HmiState::STATE_ID_REGULAR; audiostate = AudioStreamingState::NOT_AUDIBLE; syst_context = SystemContext::SYSCTXT_MAIN; - testHmiState = CreateTestHmiState(); - EXPECT_CALL(mock_application_manager_, CreateRegularState(app_id, _, _, _)) - .WillOnce(Return(testHmiState)); EXPECT_CALL(mock_application_manager_, get_settings()) .WillRepeatedly(ReturnRef(mock_application_manager_settings_)); EXPECT_CALL(mock_application_manager_settings_, app_icons_folder()) @@ -95,15 +94,17 @@ class ApplicationImplTest : public ::testing::Test { audio_data_stopped_timeout()).WillOnce(Return(0)); EXPECT_CALL(mock_application_manager_settings_, video_data_stopped_timeout()).WillOnce(Return(0)); - app_impl = new ApplicationImpl(app_id, - policy_app_id, - mac_address, - app_name, - utils::MakeShared<MockStatisticsManager>(), - mock_application_manager_); - } - void TearDown() OVERRIDE { - delete app_impl; + app_impl.reset( + new ApplicationImpl(app_id, + policy_app_id, + mac_address, + device_handle, + app_name, + utils::MakeShared<MockStatisticsManager>(), + mock_application_manager_)); + + HmiStatePtr initial_state = CreateTestHmiState(); + app_impl->SetInitialState(initial_state); } HmiStatePtr CreateTestHmiState(); @@ -114,10 +115,11 @@ class ApplicationImplTest : public ::testing::Test { void CheckCurrentHMIState(); MockApplicationManagerSettings mock_application_manager_settings_; MockApplicationManager mock_application_manager_; - ApplicationImpl* app_impl; + utils::SharedPtr<ApplicationImpl> app_impl; uint32_t app_id; std::string policy_app_id; std::string mac_address; + connection_handler::DeviceHandle device_handle; custom_str::CustomString app_name; const std::string directory_name = "./test_storage"; HmiState::StateID state_id; @@ -128,8 +130,10 @@ class ApplicationImplTest : public ::testing::Test { }; HmiStatePtr ApplicationImplTest::CreateTestHmiState() { - HmiStatePtr testState = - utils::MakeShared<HmiState>(app_id, mock_application_manager_, state_id); + HmiStatePtr testState = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(app_impl), + mock_application_manager_, + state_id); testState->set_hmi_level(test_lvl); testState->set_audio_streaming_state(audiostate); testState->set_system_context(syst_context); @@ -142,7 +146,7 @@ HmiStatePtr ApplicationImplTest::TestAddHmiState(HMILevel::eType hmi_lvl, test_lvl = hmi_lvl; state_id = id_state; HmiStatePtr state = CreateTestHmiState(); - (app_impl->*hmi_action)(state); + ((app_impl.get())->*hmi_action)(state); return state; } @@ -565,7 +569,7 @@ TEST_F(ApplicationImplTest, SubscribeToSoftButton_UnsubscribeFromSoftButton) { TEST_F(ApplicationImplTest, ChangeSupportingAppHMIType_TypeNotNaviNotVoice) { smart_objects::SmartObject type_media; - type_media[0] = AppHMIType::MEDIA; + type_media[0] = mobile_apis::AppHMIType::MEDIA; EXPECT_FALSE(app_impl->is_navi()); EXPECT_FALSE(app_impl->is_voice_communication_supported()); @@ -581,7 +585,7 @@ TEST_F(ApplicationImplTest, ChangeSupportingAppHMIType_TypeNotNaviNotVoice) { TEST_F(ApplicationImplTest, ChangeSupportingAppHMIType_TypeIsVoice) { smart_objects::SmartObject type_comm; - type_comm[0] = AppHMIType::COMMUNICATION; + type_comm[0] = mobile_apis::AppHMIType::COMMUNICATION; EXPECT_FALSE(app_impl->is_navi()); EXPECT_FALSE(app_impl->is_voice_communication_supported()); @@ -597,7 +601,7 @@ TEST_F(ApplicationImplTest, ChangeSupportingAppHMIType_TypeIsVoice) { TEST_F(ApplicationImplTest, ChangeSupportingAppHMIType_TypeIsNavi) { smart_objects::SmartObject type_navi; - type_navi[0] = AppHMIType::NAVIGATION; + type_navi[0] = mobile_apis::AppHMIType::NAVIGATION; EXPECT_FALSE(app_impl->is_navi()); EXPECT_FALSE(app_impl->is_voice_communication_supported()); @@ -613,9 +617,9 @@ TEST_F(ApplicationImplTest, ChangeSupportingAppHMIType_TypeIsNavi) { TEST_F(ApplicationImplTest, ChangeSupportingAppHMIType_TypeIsNaviAndVoice) { smart_objects::SmartObject app_types; - app_types[0] = AppHMIType::NAVIGATION; - app_types[1] = AppHMIType::COMMUNICATION; - app_types[2] = AppHMIType::MEDIA; + app_types[0] = mobile_apis::AppHMIType::NAVIGATION; + app_types[1] = mobile_apis::AppHMIType::COMMUNICATION; + app_types[2] = mobile_apis::AppHMIType::MEDIA; EXPECT_FALSE(app_impl->is_navi()); EXPECT_FALSE(app_impl->is_voice_communication_supported()); @@ -632,10 +636,10 @@ TEST_F(ApplicationImplTest, ChangeSupportingAppHMIType_TypeIsNaviAndVoice) { TEST_F(ApplicationImplTest, ChangeSupportingAppHMIType_TypeIsNaviAndVoiceAndProjection) { smart_objects::SmartObject app_types; - app_types[0] = AppHMIType::NAVIGATION; - app_types[1] = AppHMIType::COMMUNICATION; - app_types[2] = AppHMIType::MEDIA; - app_types[3] = AppHMIType::PROJECTION; + app_types[0] = mobile_apis::AppHMIType::NAVIGATION; + app_types[1] = mobile_apis::AppHMIType::COMMUNICATION; + app_types[2] = mobile_apis::AppHMIType::MEDIA; + app_types[3] = mobile_apis::AppHMIType::PROJECTION; EXPECT_FALSE(app_impl->is_navi()); EXPECT_FALSE(app_impl->is_voice_communication_supported()); @@ -652,6 +656,22 @@ TEST_F(ApplicationImplTest, TEST_F(ApplicationImplTest, UpdateHash_AppMngrNotSuspended) { EXPECT_CALL(*MockMessageHelper::message_helper_mock(), SendHashUpdateNotification(app_id, _)).Times(1); + resumprion_test::MockResumeCtrl mock_resume_ctrl; + EXPECT_CALL(mock_application_manager_, resume_controller()) + .WillOnce(ReturnRef(mock_resume_ctrl)); + EXPECT_CALL(mock_resume_ctrl, is_suspended()).WillOnce(Return(false)); + app_impl->UpdateHash(); + + EXPECT_TRUE(app_impl->is_application_data_changed()); +} + +TEST_F(ApplicationImplTest, UpdateHash_AppMngrSuspended) { + EXPECT_CALL(*MockMessageHelper::message_helper_mock(), + SendHashUpdateNotification(app_id, _)).Times(0); + resumprion_test::MockResumeCtrl mock_resume_ctrl; + EXPECT_CALL(mock_application_manager_, resume_controller()) + .WillOnce(ReturnRef(mock_resume_ctrl)); + EXPECT_CALL(mock_resume_ctrl, is_suspended()).WillOnce(Return(true)); app_impl->UpdateHash(); EXPECT_TRUE(app_impl->is_application_data_changed()); @@ -784,6 +804,29 @@ TEST_F(ApplicationImplTest, StopStreaming_StreamingApproved) { EXPECT_FALSE(app_impl->audio_streaming_approved()); } +TEST_F(ApplicationImplTest, PushPopMobileMessage) { + smart_objects::SmartObjectSPtr on_driver_distraction = + utils::MakeShared<smart_objects::SmartObject>(); + const hmi_apis::Common_DriverDistractionState::eType state = + hmi_apis::Common_DriverDistractionState::DD_ON; + (*on_driver_distraction)[strings::params][strings::function_id] = + mobile_api::FunctionID::OnDriverDistractionID; + + (*on_driver_distraction)[strings::msg_params][mobile_notification::state] = + state; + + app_impl->PushMobileMessage(on_driver_distraction); + app_impl->PushMobileMessage(on_driver_distraction); + + MobileMessageQueue messages; + app_impl->SwapMobileMessageQueue(messages); + + EXPECT_EQ(2u, messages.size()); + + app_impl->SwapMobileMessageQueue(messages); + EXPECT_TRUE(messages.empty()); +} + } // namespace application_manager_test } // namespace components } // namespace test diff --git a/src/components/application_manager/test/application_manager_impl_mock_hmi_test.cc b/src/components/application_manager/test/application_manager_impl_mock_hmi_test.cc new file mode 100644 index 0000000000..b9437d55e0 --- /dev/null +++ b/src/components/application_manager/test/application_manager_impl_mock_hmi_test.cc @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2017, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include <stdint.h> +#include <memory> +#include <string> + +#include "gtest/gtest.h" +#include "application_manager/application.h" +#include "application_manager/application_impl.h" +#include "application_manager/application_manager_impl.h" +#include "utils/custom_string.h" +#include "utils/make_shared.h" +#include "encryption/hashing.h" + +#include "application_manager/mock_application_manager_settings.h" +#include "application_manager/mock_resumption_data.h" +#include "application_manager/mock_hmi_command_factory.h" +#include "application_manager/mock_request.h" +#include "connection_handler/mock_connection_handler.h" +#include "policy/mock_policy_settings.h" +#include "policy/usage_statistics/mock_statistics_manager.h" +#include "protocol_handler/mock_session_observer.h" + +namespace test { +namespace components { +namespace application_manager_test { + +namespace am = application_manager; + +using testing::_; +using ::testing::DoAll; +using ::testing::Mock; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::NiceMock; +using ::testing::SetArgPointee; + +using namespace application_manager; + +namespace { +const uint32_t kApplicationId = 0u; +const std::string kDirectoryName = "./test_storage"; +const uint32_t kTimeout = 10000u; +} // namespace + +/** + * @brief The ApplicationManagerImplMockHmiTest class uses mocked HMI factory + * which calls its static method and real (non-mocked) MessageHelper. + * Class is separated from ApplicationManagerImplTest since it requires real + * HMI factory and mocked MessageHelper. So it is not possible to combine + * this code together. + */ +class ApplicationManagerImplMockHmiTest : public ::testing::Test { + public: + ApplicationManagerImplMockHmiTest() + : mock_storage_( + ::utils::MakeShared<NiceMock<resumption_test::MockResumptionData> >( + mock_app_mngr_)) {} + + protected: + void SetUp() OVERRIDE { + const uint8_t expected_tread_pool_size = 2u; + const uint8_t stop_streaming_timeout = 1u; + + ON_CALL(mock_application_manager_settings_, thread_pool_size()) + .WillByDefault(Return(expected_tread_pool_size)); + ON_CALL(mock_application_manager_settings_, app_icons_folder()) + .WillByDefault(ReturnRef(kDirectoryName)); + ON_CALL(mock_application_manager_settings_, app_storage_folder()) + .WillByDefault(ReturnRef(kDirectoryName)); + ON_CALL(mock_application_manager_settings_, launch_hmi()) + .WillByDefault(Return(true)); + ON_CALL(mock_application_manager_settings_, stop_streaming_timeout()) + .WillByDefault(Return(stop_streaming_timeout)); + ON_CALL(mock_application_manager_settings_, default_timeout()) + .WillByDefault(ReturnRef(kTimeout)); + + ON_CALL(mock_connection_handler_, get_session_observer()) + .WillByDefault(ReturnRef(mock_session_observer_)); + + app_manager_impl_.reset(new am::ApplicationManagerImpl( + mock_application_manager_settings_, mock_policy_settings_)); + + app_manager_impl_->set_connection_handler(&mock_connection_handler_); + app_manager_impl_->resume_controller().set_resumption_storage( + mock_storage_); + } + + void SetCommonExpectationOnAppReconnection( + const connection_handler::DeviceHandle new_device_id, + const uint32_t new_application_id, + const std::string& mac_address) { + EXPECT_CALL( + mock_session_observer_, + GetDataOnSessionKey(new_application_id, + _, + _, + testing::An<connection_handler::DeviceHandle*>())) + .WillOnce(DoAll(SetArgPointee<3u>(new_device_id), Return(0))); + + const std::string connection_type = "MyConnectionType"; + EXPECT_CALL( + mock_session_observer_, + GetDataOnDeviceID( + ::testing::Matcher<connection_handler::DeviceHandle>(new_device_id), + _, + _, + _, + _)) + .WillOnce(DoAll(SetArgPointee<3u>(mac_address), + SetArgPointee<4u>(connection_type), + Return(0))); + } + + utils::SharedPtr<NiceMock<resumption_test::MockResumptionData> > + mock_storage_; + application_manager_test::MockApplicationManager mock_app_mngr_; + NiceMock<policy_handler_test::MockPolicySettings> mock_policy_settings_; + NiceMock<connection_handler_test::MockConnectionHandler> + mock_connection_handler_; + NiceMock<protocol_handler_test::MockSessionObserver> mock_session_observer_; + NiceMock<MockApplicationManagerSettings> mock_application_manager_settings_; + std::unique_ptr<am::ApplicationManagerImpl> app_manager_impl_; +}; + +TEST_F(ApplicationManagerImplMockHmiTest, + PostponeCommandsDuringSwitching_ExpectSendingOnSwitchingEnd) { + const uint32_t application_id = 1u; + const std::string policy_app_id = "p_app_id"; + const std::string mac_address = "MA:CA:DD:RE:SS"; + const connection_handler::DeviceHandle device_id = 1u; + const custom_str::CustomString app_name(""); + + utils::SharedPtr<ApplicationImpl> app_impl = new ApplicationImpl( + application_id, + policy_app_id, + encryption::MakeHash(mac_address), + device_id, + app_name, + utils::SharedPtr<usage_statistics::StatisticsManager>( + new usage_statistics_test::MockStatisticsManager()), + *app_manager_impl_); + + app_manager_impl_->AddMockApplication(app_impl); + + const connection_handler::Device bt( + device_id, "BT_device", mac_address, "BLUETOOTH"); + + const connection_handler::Device usb( + device_id + 1, "USB_device", "USB_serial", "USB_IOS"); + + MockHMICommandFactory* mock_hmi_factory = + MockHMICommandFactory::mock_hmi_command_factory(); + + // Skip sending notification on device switching as it is not the goal here + EXPECT_CALL(*mock_hmi_factory, CreateCommand(_, _)) + .WillOnce(Return(utils::SharedPtr<commands::Command>())); + + app_manager_impl_->OnDeviceSwitchingStart(bt, usb); + + const uint32_t connection_key = 1u; + const uint32_t correlation_id_1 = 1u; + const uint32_t correlation_id_2 = 2u; + const uint32_t correlation_id_3 = 3u; + utils::SharedPtr<NiceMock<MockRequest> > cmd_1 = + utils::MakeShared<NiceMock<MockRequest> >(connection_key, + correlation_id_1); + utils::SharedPtr<NiceMock<MockRequest> > cmd_2 = + utils::MakeShared<NiceMock<MockRequest> >(connection_key, + correlation_id_2); + utils::SharedPtr<NiceMock<MockRequest> > cmd_3 = + utils::MakeShared<NiceMock<MockRequest> >(connection_key, + correlation_id_3); + + EXPECT_CALL(*mock_hmi_factory, CreateCommand(_, _)) + .WillOnce(Return(cmd_1)) + .WillOnce(Return(cmd_2)) + .WillOnce(Return(cmd_3)); + + commands::MessageSharedPtr hmi_msg_1 = + utils::MakeShared<smart_objects::SmartObject>(); + commands::MessageSharedPtr hmi_msg_2 = + utils::MakeShared<smart_objects::SmartObject>(); + commands::MessageSharedPtr hmi_msg_3 = + utils::MakeShared<smart_objects::SmartObject>(); + + (*hmi_msg_1)[strings::msg_params][strings::app_id] = + (*hmi_msg_2)[strings::msg_params][strings::app_id] = + (*hmi_msg_3)[strings::msg_params][strings::app_id] = application_id; + + EXPECT_CALL(*cmd_1, Init()).Times(0); + EXPECT_CALL(*cmd_2, Init()).Times(0); + EXPECT_CALL(*cmd_3, Init()).Times(0); + + // Act + app_manager_impl_->ManageHMICommand(hmi_msg_1); + app_manager_impl_->ManageHMICommand(hmi_msg_2); + app_manager_impl_->ManageHMICommand(hmi_msg_3); + + EXPECT_CALL(*mock_hmi_factory, CreateCommand(_, _)) + .WillOnce(Return(cmd_1)) + .WillOnce(Return(cmd_2)) + .WillOnce(Return(cmd_3)); + + EXPECT_CALL(*cmd_1, Init()).WillOnce(Return(true)); + EXPECT_CALL(*cmd_1, Run()); + EXPECT_CALL(*cmd_2, Init()).WillOnce(Return(true)); + EXPECT_CALL(*cmd_2, Run()); + EXPECT_CALL(*cmd_3, Init()).WillOnce(Return(true)); + EXPECT_CALL(*cmd_3, Run()); + + const connection_handler::DeviceHandle new_device_id = 2; + const uint32_t new_application_id = 2; + SetCommonExpectationOnAppReconnection( + new_device_id, new_application_id, mac_address); + + app_manager_impl_->ProcessReconnection(app_impl, new_application_id); + app_manager_impl_->OnApplicationSwitched(app_impl); + + Mock::VerifyAndClearExpectations(&mock_hmi_factory); +} + +} // application_manager_test +} // namespace components +} // namespace test 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 d19d3cd8ed..128d8e87a7 100644 --- a/src/components/application_manager/test/application_manager_impl_test.cc +++ b/src/components/application_manager/test/application_manager_impl_test.cc @@ -32,6 +32,8 @@ #include <stdint.h> #include <memory> #include <set> +#include <string> +#include <vector> #include <bson_object.h> #include "gtest/gtest.h" @@ -39,12 +41,14 @@ #include "application_manager/application_impl.h" #include "application_manager/application_manager_impl.h" #include "application_manager/mock_application.h" +#include "application_manager/mock_help_prompt_manager.h" #include "application_manager/mock_application_manager_settings.h" #include "application_manager/mock_resumption_data.h" #include "application_manager/resumption/resume_ctrl_impl.h" #include "application_manager/test/include/application_manager/mock_message_helper.h" #include "connection_handler/mock_connection_handler.h" #include "hmi_message_handler/mock_hmi_message_handler.h" +#include "media_manager/mock_media_manager.h" #include "policy/mock_policy_settings.h" #include "policy/usage_statistics/mock_statistics_manager.h" #include "protocol/bson_object_keys.h" @@ -54,6 +58,7 @@ #include "utils/lock.h" #include "utils/make_shared.h" #include "utils/push_log.h" +#include "encryption/hashing.h" namespace test { namespace components { @@ -64,6 +69,7 @@ namespace policy_test = test::components::policy_handler_test; namespace con_test = connection_handler_test; using testing::_; +using ::testing::Matcher; using ::testing::ByRef; using ::testing::DoAll; using ::testing::Mock; @@ -83,8 +89,7 @@ ACTION_P6(InvokeMemberFuncWithArg4, ptr, memberFunc, a, b, c, d) { namespace { const std::string kDirectoryName = "./test_storage"; const uint32_t kTimeout = 10000u; -sync_primitives::Lock state_lock_; -sync_primitives::ConditionalVariable state_condition_; +connection_handler::DeviceHandle kDeviceId = 12345u; } // namespace class ApplicationManagerImplTest : public ::testing::Test { @@ -92,7 +97,7 @@ class ApplicationManagerImplTest : public ::testing::Test { ApplicationManagerImplTest() : mock_storage_( ::utils::MakeShared<NiceMock<resumption_test::MockResumptionData> >( - app_mngr_)) + mock_app_mngr_)) , mock_message_helper_( application_manager::MockMessageHelper::message_helper_mock()) , app_id_(0u) { @@ -106,8 +111,7 @@ class ApplicationManagerImplTest : public ::testing::Test { protected: void SetUp() OVERRIDE { CreateAppManager(); - - ON_CALL(mock_connection_handler_, GetDataOnSessionKey(_, _, _, _)) + ON_CALL(mock_connection_handler_, GetDataOnSessionKey(_, _, _, &kDeviceId)) .WillByDefault(DoAll(SetArgPointee<3u>(app_id_), Return(0))); ON_CALL(mock_connection_handler_, get_session_observer()) .WillByDefault(ReturnRef(mock_session_observer_)); @@ -128,14 +132,17 @@ class ApplicationManagerImplTest : public ::testing::Test { ON_CALL(mock_application_manager_settings_, app_storage_folder()) .WillByDefault(ReturnRef(kDirectoryName)); ON_CALL(mock_application_manager_settings_, launch_hmi()) - .WillByDefault(Return(true)); + .WillByDefault(Return(false)); ON_CALL(mock_application_manager_settings_, stop_streaming_timeout()) .WillByDefault(Return(stop_streaming_timeout)); ON_CALL(mock_application_manager_settings_, default_timeout()) .WillByDefault(ReturnRef(kTimeout)); + app_manager_impl_.reset(new am::ApplicationManagerImpl( mock_application_manager_settings_, mock_policy_settings_)); mock_app_ptr_ = utils::SharedPtr<MockApplication>(new MockApplication()); + mock_help_prompt_manager_ = + utils::SharedPtr<MockHelpPromptManager>(new MockHelpPromptManager()); ASSERT_TRUE(app_manager_impl_.get()); ASSERT_TRUE(mock_app_ptr_.get()); @@ -145,18 +152,44 @@ class ApplicationManagerImplTest : public ::testing::Test { app_manager_impl_->AddMockApplication(mock_app_ptr_); } + void SetCommonExpectationOnAppReconnection( + const connection_handler::DeviceHandle new_device_id, + const uint32_t new_application_id, + const std::string& mac_address) { + EXPECT_CALL( + mock_session_observer_, + GetDataOnSessionKey(new_application_id, + _, + _, + testing::An<connection_handler::DeviceHandle*>())) + .WillOnce(DoAll(SetArgPointee<3u>(new_device_id), Return(0))); + + const std::string connection_type = "MyConnectionType"; + EXPECT_CALL( + mock_session_observer_, + GetDataOnDeviceID( + ::testing::Matcher<connection_handler::DeviceHandle>(new_device_id), + _, + _, + _, + _)) + .WillOnce(DoAll(SetArgPointee<3u>(mac_address), + SetArgPointee<4u>(connection_type), + Return(0))); + } + NiceMock<policy_test::MockPolicySettings> mock_policy_settings_; utils::SharedPtr<NiceMock<resumption_test::MockResumptionData> > mock_storage_; NiceMock<con_test::MockConnectionHandler> mock_connection_handler_; NiceMock<protocol_handler_test::MockSessionObserver> mock_session_observer_; NiceMock<MockApplicationManagerSettings> mock_application_manager_settings_; - application_manager_test::MockApplicationManager app_mngr_; + application_manager_test::MockApplicationManager mock_app_mngr_; std::auto_ptr<am::ApplicationManagerImpl> app_manager_impl_; application_manager::MockMessageHelper* mock_message_helper_; uint32_t app_id_; - application_manager::MessageHelper* message_helper_; utils::SharedPtr<MockApplication> mock_app_ptr_; + utils::SharedPtr<MockHelpPromptManager> mock_help_prompt_manager_; }; TEST_F(ApplicationManagerImplTest, ProcessQueryApp_ExpectSuccess) { @@ -181,16 +214,20 @@ TEST_F(ApplicationManagerImplTest, ProcessQueryApp_ExpectSuccess) { TEST_F(ApplicationManagerImplTest, SubscribeAppForWayPoints_ExpectSubscriptionApp) { - app_manager_impl_->SubscribeAppForWayPoints(app_id_); - EXPECT_TRUE(app_manager_impl_->IsAppSubscribedForWayPoints(app_id_)); + auto app_ptr = + ApplicationSharedPtr::static_pointer_cast<am::Application>(mock_app_ptr_); + app_manager_impl_->SubscribeAppForWayPoints(app_ptr); + EXPECT_TRUE(app_manager_impl_->IsAppSubscribedForWayPoints(app_ptr)); } TEST_F(ApplicationManagerImplTest, UnsubscribeAppForWayPoints_ExpectUnsubscriptionApp) { - app_manager_impl_->SubscribeAppForWayPoints(app_id_); - EXPECT_TRUE(app_manager_impl_->IsAppSubscribedForWayPoints(app_id_)); - app_manager_impl_->UnsubscribeAppFromWayPoints(app_id_); - EXPECT_FALSE(app_manager_impl_->IsAppSubscribedForWayPoints(app_id_)); + auto app_ptr = + ApplicationSharedPtr::static_pointer_cast<am::Application>(mock_app_ptr_); + app_manager_impl_->SubscribeAppForWayPoints(app_ptr); + EXPECT_TRUE(app_manager_impl_->IsAppSubscribedForWayPoints(app_ptr)); + app_manager_impl_->UnsubscribeAppFromWayPoints(app_ptr); + EXPECT_FALSE(app_manager_impl_->IsAppSubscribedForWayPoints(app_ptr)); const std::set<int32_t> result = app_manager_impl_->GetAppsSubscribedForWayPoints(); EXPECT_TRUE(result.empty()); @@ -207,10 +244,12 @@ TEST_F( TEST_F( ApplicationManagerImplTest, GetAppsSubscribedForWayPoints_SubcribeAppForWayPoints_ExpectCorrectResult) { - app_manager_impl_->SubscribeAppForWayPoints(app_id_); + auto app_ptr = + ApplicationSharedPtr::static_pointer_cast<am::Application>(mock_app_ptr_); + app_manager_impl_->SubscribeAppForWayPoints(app_ptr); std::set<int32_t> result = app_manager_impl_->GetAppsSubscribedForWayPoints(); EXPECT_EQ(1u, result.size()); - EXPECT_TRUE(result.find(app_id_) != result.end()); + EXPECT_TRUE(result.find(app_ptr) != result.end()); } TEST_F(ApplicationManagerImplTest, OnServiceStartedCallback_RpcService) { @@ -639,6 +678,279 @@ TEST_F(ApplicationManagerImplTest, EXPECT_TRUE(rejected_params.empty()); } +TEST_F(ApplicationManagerImplTest, + OnDeviceSwitchingStart_ExpectPutAppsInWaitList) { + utils::SharedPtr<MockApplication> switching_app_ptr = + utils::MakeShared<MockApplication>(); + + const std::string switching_device_id = "switching"; + const std::string switching_device_id_hash = + encryption::MakeHash(switching_device_id); + app_manager_impl_->AddMockApplication(switching_app_ptr); + EXPECT_CALL(*switching_app_ptr, mac_address()) + .WillRepeatedly(ReturnRef(switching_device_id_hash)); + + const std::string policy_app_id_switch = "abc"; + EXPECT_CALL(*switching_app_ptr, policy_app_id()) + .WillRepeatedly(Return(policy_app_id_switch)); + + const auto hmi_level_switching_app = mobile_apis::HMILevel::HMI_FULL; + EXPECT_CALL(*switching_app_ptr, hmi_level()) + .WillRepeatedly(Return(hmi_level_switching_app)); + + utils::SharedPtr<MockApplication> nonswitching_app_ptr = + utils::MakeShared<MockApplication>(); + + const std::string nonswitching_device_id = "nonswitching"; + const std::string nonswitching_device_id_hash = + encryption::MakeHash(nonswitching_device_id); + app_manager_impl_->AddMockApplication(nonswitching_app_ptr); + EXPECT_CALL(*nonswitching_app_ptr, mac_address()) + .WillRepeatedly(ReturnRef(nonswitching_device_id_hash)); + + const std::string policy_app_id_nonswitch = "efg"; + EXPECT_CALL(*nonswitching_app_ptr, policy_app_id()) + .WillRepeatedly(Return(policy_app_id_nonswitch)); + + const auto hmi_level_nonswitching_app = mobile_apis::HMILevel::HMI_LIMITED; + EXPECT_CALL(*nonswitching_app_ptr, hmi_level()) + .WillRepeatedly(Return(hmi_level_nonswitching_app)); + + // Act + const connection_handler::DeviceHandle switching_handle = 1; + const connection_handler::Device switching_device( + switching_handle, "switching_device", switching_device_id, "BLUETOOTH"); + + const connection_handler::DeviceHandle non_switching_handle = 2; + const connection_handler::Device non_switching_device(non_switching_handle, + "non_switching_device", + nonswitching_device_id, + "USB"); + + EXPECT_CALL(*mock_message_helper_, CreateDeviceListSO(_, _, _)) + .WillOnce(Return(smart_objects::SmartObjectSPtr())); + app_manager_impl_->OnDeviceSwitchingStart(switching_device, + non_switching_device); + EXPECT_TRUE(app_manager_impl_->IsAppInReconnectMode(policy_app_id_switch)); + EXPECT_FALSE( + app_manager_impl_->IsAppInReconnectMode(policy_app_id_nonswitch)); +} + +TEST_F(ApplicationManagerImplTest, + OnDeviceSwitchingFinish_ExpectUnregisterAppsInWaitList) { + utils::SharedPtr<MockApplication> switching_app_ptr = + utils::MakeShared<MockApplication>(); + + const std::string switching_device_id = "switching"; + const std::string switching_device_id_hash = + encryption::MakeHash(switching_device_id); + app_manager_impl_->AddMockApplication(switching_app_ptr); + EXPECT_CALL(*switching_app_ptr, mac_address()) + .WillRepeatedly(ReturnRef(switching_device_id_hash)); + + const std::string policy_app_id_switch = "abc"; + EXPECT_CALL(*switching_app_ptr, policy_app_id()) + .WillRepeatedly(Return(policy_app_id_switch)); + + const auto hmi_level_switching_app = mobile_apis::HMILevel::HMI_FULL; + EXPECT_CALL(*switching_app_ptr, hmi_level()) + .WillRepeatedly(Return(hmi_level_switching_app)); + + utils::SharedPtr<MockApplication> nonswitching_app_ptr = + utils::MakeShared<MockApplication>(); + + const std::string nonswitching_device_id = "nonswitching"; + const std::string nonswitching_device_id_hash = + encryption::MakeHash(nonswitching_device_id); + app_manager_impl_->AddMockApplication(nonswitching_app_ptr); + EXPECT_CALL(*nonswitching_app_ptr, mac_address()) + .WillRepeatedly(ReturnRef(nonswitching_device_id_hash)); + + const std::string policy_app_id_nonswitch = "efg"; + EXPECT_CALL(*nonswitching_app_ptr, policy_app_id()) + .WillRepeatedly(Return(policy_app_id_nonswitch)); + + const auto hmi_level_nonswitching_app = mobile_apis::HMILevel::HMI_LIMITED; + EXPECT_CALL(*nonswitching_app_ptr, hmi_level()) + .WillRepeatedly(Return(hmi_level_nonswitching_app)); + + // Act + const connection_handler::DeviceHandle switching_handle = 1; + const connection_handler::Device switching_device( + switching_handle, "switching_device", switching_device_id, "BLUETOOTH"); + + const connection_handler::DeviceHandle non_switching_handle = 2; + const connection_handler::Device non_switching_device(non_switching_handle, + "non_switching_device", + nonswitching_device_id, + "USB"); + + EXPECT_CALL(*mock_message_helper_, CreateDeviceListSO(_, _, _)) + .WillOnce(Return(smart_objects::SmartObjectSPtr())); + + app_manager_impl_->OnDeviceSwitchingStart(switching_device, + non_switching_device); + + EXPECT_TRUE(app_manager_impl_->IsAppInReconnectMode(policy_app_id_switch)); + + EXPECT_CALL(*switching_app_ptr, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); + + app_manager_impl_->OnDeviceSwitchingFinish(switching_device_id); + EXPECT_FALSE( + app_manager_impl_->application_by_policy_id(policy_app_id_switch)); +} + +TEST_F(ApplicationManagerImplTest, + ProcessReconnection_ExpectChangeAppIdDeviceId) { + const uint32_t application_id = 1; + const std::string policy_app_id = "p_app_id"; + const std::string mac_address = "MA:CA:DD:RE:SS"; + const connection_handler::DeviceHandle device_id = 1; + const custom_str::CustomString app_name(""); + + utils::SharedPtr<ApplicationImpl> app_impl = new ApplicationImpl( + application_id, + policy_app_id, + mac_address, + device_id, + app_name, + utils::SharedPtr<usage_statistics::StatisticsManager>( + new usage_statistics_test::MockStatisticsManager()), + *app_manager_impl_); + + app_manager_impl_->AddMockApplication(app_impl); + + const connection_handler::DeviceHandle new_device_id = 2; + const uint32_t new_application_id = 2; + SetCommonExpectationOnAppReconnection( + new_device_id, new_application_id, mac_address); + + // Act + app_manager_impl_->ProcessReconnection(app_impl, new_application_id); + EXPECT_EQ(new_device_id, app_impl->device()); + EXPECT_EQ(new_application_id, app_impl->app_id()); +} + +TEST_F(ApplicationManagerImplTest, StartStopAudioPassThru) { + std::string dummy_file_name; + ON_CALL(mock_application_manager_settings_, recording_file_name()) + .WillByDefault(ReturnRef(dummy_file_name)); + + NiceMock<test::components::media_manager_test::MockMediaManager> + mock_media_manager; + app_manager_impl_->SetMockMediaManager(&mock_media_manager); + + 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)) + .WillOnce(Return()); + EXPECT_CALL(mock_media_manager, StopMicrophoneRecording(app_id)) + .WillOnce(Return()); + + bool result = app_manager_impl_->BeginAudioPassThru(app_id); + EXPECT_TRUE(result); + if (result) { + app_manager_impl_->StartAudioPassThruThread(app_id, + correlation_id, + max_duration, + sampling_rate, + bits_per_sample, + audio_type); + } + + result = app_manager_impl_->EndAudioPassThru(app_id); + EXPECT_TRUE(result); + if (result) { + app_manager_impl_->StopAudioPassThru(app_id); + } +} + +TEST_F(ApplicationManagerImplTest, UnregisterAnotherAppDuringAudioPassThru) { + std::string dummy_file_name; + ON_CALL(mock_application_manager_settings_, recording_file_name()) + .WillByDefault(ReturnRef(dummy_file_name)); + + const uint32_t app_id_1 = 65537; + const uint32_t app_id_2 = 65538; + + std::string dummy_mac_address; + utils::SharedPtr<MockApplication> mock_app_1 = + utils::SharedPtr<MockApplication>(new MockApplication()); + EXPECT_CALL(*mock_app_1, app_id()).WillRepeatedly(Return(app_id_1)); + EXPECT_CALL(*mock_app_1, device()).WillRepeatedly(Return(0)); + EXPECT_CALL(*mock_app_1, mac_address()) + .WillRepeatedly(ReturnRef(dummy_mac_address)); + EXPECT_CALL(*mock_app_1, policy_app_id()).WillRepeatedly(Return("")); + EXPECT_CALL(*mock_app_1, protocol_version()) + .WillRepeatedly( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_4)); + + utils::SharedPtr<MockApplication> mock_app_2 = + utils::SharedPtr<MockApplication>(new MockApplication()); + EXPECT_CALL(*mock_app_2, app_id()).WillRepeatedly(Return(app_id_2)); + EXPECT_CALL(*mock_app_2, device()).WillRepeatedly(Return(0)); + EXPECT_CALL(*mock_app_2, mac_address()) + .WillRepeatedly(ReturnRef(dummy_mac_address)); + EXPECT_CALL(*mock_app_2, policy_app_id()).WillRepeatedly(Return("")); + EXPECT_CALL(*mock_app_2, protocol_version()) + .WillRepeatedly( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_4)); + + NiceMock<test::components::media_manager_test::MockMediaManager> + mock_media_manager; + app_manager_impl_->SetMockMediaManager(&mock_media_manager); + + app_manager_impl_->AddMockApplication(mock_app_1); + 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)) + .WillOnce(Return()); + EXPECT_CALL(mock_media_manager, StopMicrophoneRecording(app_id_2)) + .WillOnce(Return()); + + // app 2 starts Audio Pass Thru + bool result = app_manager_impl_->BeginAudioPassThru(app_id_2); + EXPECT_TRUE(result); + if (result) { + app_manager_impl_->StartAudioPassThruThread(app_id_2, + correlation_id, + max_duration, + sampling_rate, + bits_per_sample, + audio_type); + } + + EXPECT_CALL(*mock_app_1, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); + + // while running APT, app 1 is unregistered + app_manager_impl_->UnregisterApplication( + app_id_1, mobile_apis::Result::SUCCESS, false, true); + + // confirm that APT is still running + result = app_manager_impl_->EndAudioPassThru(app_id_2); + EXPECT_TRUE(result); + if (result) { + app_manager_impl_->StopAudioPassThru(app_id_2); + } +} + } // application_manager_test } // namespace components } // namespace test diff --git a/src/components/application_manager/test/application_state_test.cc b/src/components/application_manager/test/application_state_test.cc index 7bc34966b4..33f23022f0 100644 --- a/src/components/application_manager/test/application_state_test.cc +++ b/src/components/application_manager/test/application_state_test.cc @@ -34,6 +34,7 @@ #include "gtest/gtest.h" #include "application_manager/hmi_state.h" #include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" #include "application_manager/event_engine/event_dispatcher.h" #include "resumption/last_state.h" #include "application_manager/policies/policy_handler.h" @@ -64,12 +65,17 @@ std::vector<StateID> GenerateCurrentStates() { } class ApplicationStateTest : public ::testing::Test { + public: + void SetUp() OVERRIDE { + mock_app_.reset(new MockApplication); + } + protected: static std::vector<StateID> added_states_; ApplicationState app_state; const StateID current_id = StateID::STATE_ID_CURRENT; const StateID postponed_id = StateID::STATE_ID_POSTPONED; - const uint32_t app_id = 10; + utils::SharedPtr<MockApplication> mock_app_; MockApplicationManager app_mngr_; }; @@ -79,8 +85,10 @@ std::vector<StateID> ApplicationStateTest::added_states_ = TEST_F(ApplicationStateTest, AddStates_GetCurrentStates) { std::vector<StateID>::iterator new_state = added_states_.begin(); for (; new_state != added_states_.end(); ++new_state) { - HmiStatePtr state = - utils::MakeShared<HmiState>(app_id, app_mngr_, *new_state); + HmiStatePtr state = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(mock_app_), + app_mngr_, + *new_state); app_state.AddState(state); EXPECT_EQ(state, app_state.GetState(current_id)); } @@ -89,8 +97,10 @@ TEST_F(ApplicationStateTest, AddStates_GetCurrentStates) { TEST_F(ApplicationStateTest, AddStates_RemoveStates_GetCurrentState) { std::vector<StateID>::iterator new_state = added_states_.begin(); for (; new_state != added_states_.end(); ++new_state) { - HmiStatePtr state = - utils::MakeShared<HmiState>(app_id, app_mngr_, *new_state); + HmiStatePtr state = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(mock_app_), + app_mngr_, + *new_state); app_state.AddState(state); HmiStatePtr curr_state = app_state.GetState(current_id); @@ -110,16 +120,20 @@ TEST_F(ApplicationStateTest, AddStatesAddPostponedState_GetPostponedState) { // Added some states std::vector<StateID>::iterator new_state = added_states_.begin(); for (; new_state != added_states_.end(); ++new_state) { - HmiStatePtr state = - utils::MakeShared<HmiState>(app_id, app_mngr_, *new_state); + HmiStatePtr state = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(mock_app_), + app_mngr_, + *new_state); app_state.AddState(state); } // Postponed state wasn't added HmiStatePtr get_postponed_id = app_state.GetState(postponed_id); EXPECT_EQ(NULL, get_postponed_id); // Add posponed state - HmiStatePtr state = - utils::MakeShared<HmiState>(app_id, app_mngr_, postponed_id); + HmiStatePtr state = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(mock_app_), + app_mngr_, + postponed_id); app_state.AddState(state); // Postponed state exists get_postponed_id = app_state.GetState(postponed_id); @@ -129,14 +143,19 @@ TEST_F(ApplicationStateTest, AddStatesAddPostponedState_GetPostponedState) { TEST_F(ApplicationStateTest, AddStates_GetRegularState) { // Add state std::vector<StateID>::iterator new_state = added_states_.begin(); - HmiStatePtr state = - utils::MakeShared<HmiState>(app_id, app_mngr_, *new_state); + HmiStatePtr state = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(mock_app_), + app_mngr_, + *new_state); state->set_hmi_level(HMILevel::HMI_FULL); app_state.AddState(state); ++new_state; // Add some other for (; new_state != added_states_.end(); ++new_state) { - state = utils::MakeShared<HmiState>(app_id, app_mngr_, *new_state); + state = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(mock_app_), + app_mngr_, + *new_state); app_state.AddState(state); state->set_hmi_level(HMILevel::HMI_LIMITED); } @@ -150,13 +169,18 @@ TEST_F(ApplicationStateTest, AddStates_GetRegularState) { TEST_F(ApplicationStateTest, AddRegularState_RemoveFirstState_GetRegularState) { std::vector<StateID>::iterator new_state = added_states_.begin(); - HmiStatePtr state = - utils::MakeShared<HmiState>(app_id, app_mngr_, *new_state); + HmiStatePtr state = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(mock_app_), + app_mngr_, + *new_state); app_state.AddState(state); ++new_state; // Add postponed state - state = utils::MakeShared<HmiState>(app_id, app_mngr_, postponed_id); + state = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(mock_app_), + app_mngr_, + postponed_id); app_state.AddState(state); // Make sure that the state was added @@ -164,7 +188,10 @@ TEST_F(ApplicationStateTest, AddRegularState_RemoveFirstState_GetRegularState) { ASSERT_EQ(state, post_state); for (; new_state != added_states_.end(); ++new_state) { - state = utils::MakeShared<HmiState>(app_id, app_mngr_, *new_state); + state = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(mock_app_), + app_mngr_, + *new_state); app_state.AddState(state); } @@ -184,22 +211,32 @@ TEST_F(ApplicationStateTest, AddRegularState_RemoveFirstState_GetRegularState) { TEST_F(ApplicationStateTest, AddRegularState_PreviousStatePostponed) { // Add some state StateID first_state = StateID::STATE_ID_PHONE_CALL; - HmiStatePtr state = - utils::MakeShared<HmiState>(app_id, app_mngr_, first_state); + HmiStatePtr state = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(mock_app_), + app_mngr_, + first_state); app_state.AddState(state); // Add postponed state - state = utils::MakeShared<HmiState>(app_id, app_mngr_, postponed_id); + state = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(mock_app_), + app_mngr_, + postponed_id); app_state.AddState(state); // Add new postponed state - const uint32_t app_id2 = 10; - state = utils::MakeShared<HmiState>(app_id2, app_mngr_, postponed_id); + utils::SharedPtr<MockApplication> mock_app_2(new MockApplication); + state = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(mock_app_), + app_mngr_, + postponed_id); app_state.AddState(state); // Add regular state - state = - utils::MakeShared<HmiState>(app_id, app_mngr_, StateID::STATE_ID_REGULAR); + state = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(mock_app_), + app_mngr_, + StateID::STATE_ID_REGULAR); app_state.AddState(state); // Postponed state is the first @@ -213,8 +250,10 @@ TEST_F(ApplicationStateTest, AddRegularState_PreviousStatePostponed) { TEST_F(ApplicationStateTest, InitState_GetRegularState) { StateID init_state = StateID::STATE_ID_REGULAR; - HmiStatePtr state = - utils::MakeShared<HmiState>(app_id, app_mngr_, init_state); + HmiStatePtr state = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(mock_app_), + app_mngr_, + init_state); app_state.InitState(state); @@ -228,14 +267,19 @@ TEST_F(ApplicationStateTest, InitState_GetRegularState) { TEST_F(ApplicationStateTest, AddPosponedState_DeletePosponedState) { // Precondition StateID init_state = StateID::STATE_ID_REGULAR; - HmiStatePtr state = - utils::MakeShared<HmiState>(app_id, app_mngr_, init_state); + HmiStatePtr state = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(mock_app_), + app_mngr_, + init_state); state->set_hmi_level(mobile_apis::HMILevel::HMI_FULL); app_state.InitState(state); // Add postponed state - state = utils::MakeShared<HmiState>(app_id, app_mngr_, postponed_id); + state = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(mock_app_), + app_mngr_, + postponed_id); app_state.AddState(state); // Make sure that state was added @@ -252,7 +296,10 @@ TEST_F(ApplicationStateTest, AddPosponedState_DeletePosponedState) { TEST_F(ApplicationStateTest, AddRegularState_RemoveRegularState_RegularStateNotDeleted) { StateID reg_state = StateID::STATE_ID_REGULAR; - HmiStatePtr state = utils::MakeShared<HmiState>(app_id, app_mngr_, reg_state); + HmiStatePtr state = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(mock_app_), + app_mngr_, + reg_state); app_state.InitState(state); // Try deleting regular state diff --git a/src/components/application_manager/test/command_holder_test.cc b/src/components/application_manager/test/command_holder_test.cc new file mode 100644 index 0000000000..e10cd5d008 --- /dev/null +++ b/src/components/application_manager/test/command_holder_test.cc @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2017, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <gmock/gmock.h> + +#include "application_manager/command_holder_impl.h" +#include "application_manager/commands/command.h" +#include "smart_objects/smart_object.h" +#include "utils/shared_ptr.h" +#include "utils/make_shared.h" + +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" + +namespace test { +namespace components { +namespace application_manager_test { + +using testing::_; +using testing::Return; + +namespace am = application_manager; + +class CommandHolderImplTest : public testing::Test { + public: + CommandHolderImplTest() + : kPolicyAppId_("p_app_id") + , kHmiApplicationId_(123) + , kConnectionKey_(56789) + , cmd_ptr_(new smart_objects::SmartObject) + , mock_app_ptr_(new MockApplication) {} + + void SetUp() OVERRIDE { + ON_CALL(*mock_app_ptr_, app_id()).WillByDefault(Return(kConnectionKey_)); + ON_CALL(*mock_app_ptr_, hmi_app_id()) + .WillByDefault(Return(kHmiApplicationId_)); + ON_CALL(*mock_app_ptr_, policy_app_id()) + .WillByDefault(Return(kPolicyAppId_)); + } + + MockApplicationManager mock_app_manager_; + const std::string kPolicyAppId_; + const uint32_t kHmiApplicationId_; + const uint32_t kConnectionKey_; + utils::SharedPtr<smart_objects::SmartObject> cmd_ptr_; + utils::SharedPtr<MockApplication> mock_app_ptr_; +}; + +TEST_F(CommandHolderImplTest, HoldOne_ExpectReleaseOne) { + am::CommandHolderImpl cmd_holder(mock_app_manager_); + cmd_holder.Suspend( + mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand, cmd_ptr_); + + // Act + EXPECT_CALL(mock_app_manager_, ManageHMICommand(cmd_ptr_)); + cmd_holder.Resume(mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand); +} + +TEST_F(CommandHolderImplTest, HoldMany_ExpectReleaseSame) { + am::CommandHolderImpl cmd_holder(mock_app_manager_); + + int32_t iterations = 0; + do { + cmd_holder.Suspend( + mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand, cmd_ptr_); + ++iterations; + } while (iterations < 5); + + // Act + EXPECT_CALL(mock_app_manager_, ManageHMICommand(cmd_ptr_)).Times(iterations); + cmd_holder.Resume(mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand); +} + +TEST_F(CommandHolderImplTest, Hold_Drop_ExpectNoReleased) { + am::CommandHolderImpl cmd_holder(mock_app_manager_); + cmd_holder.Suspend( + mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand, cmd_ptr_); + cmd_holder.Suspend( + mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand, cmd_ptr_); + + // Act + cmd_holder.Clear(mock_app_ptr_); + EXPECT_CALL(mock_app_manager_, ManageHMICommand(cmd_ptr_)).Times(0); + cmd_holder.Resume(mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand); +} + +TEST_F(CommandHolderImplTest, Hold_ReleaseAnotherId_ExpectNoReleased) { + am::CommandHolderImpl cmd_holder(mock_app_manager_); + cmd_holder.Suspend( + mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand, cmd_ptr_); + cmd_holder.Suspend( + mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand, cmd_ptr_); + + // Act + utils::SharedPtr<MockApplication> another_app = + utils::MakeShared<MockApplication>(); + + EXPECT_CALL(mock_app_manager_, ManageHMICommand(cmd_ptr_)).Times(0); + cmd_holder.Resume(another_app, am::CommandHolder::CommandType::kHmiCommand); +} + +TEST_F(CommandHolderImplTest, Hold_DropAnotherId_ExpectReleased) { + am::CommandHolderImpl cmd_holder(mock_app_manager_); + + int32_t iterations = 0; + do { + cmd_holder.Suspend( + mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand, cmd_ptr_); + ++iterations; + } while (iterations < 3); + + // Act + utils::SharedPtr<MockApplication> another_app = + utils::MakeShared<MockApplication>(); + cmd_holder.Clear(another_app); + + EXPECT_CALL(mock_app_manager_, ManageHMICommand(cmd_ptr_)).Times(iterations); + cmd_holder.Resume(mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand); +} + +TEST_F(CommandHolderImplTest, Hold_Mobile_and_HMI_commands_ExpectReleased) { + am::CommandHolderImpl cmd_holder(mock_app_manager_); + + cmd_holder.Suspend( + mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand, cmd_ptr_); + + cmd_holder.Suspend( + mock_app_ptr_, am::CommandHolder::CommandType::kMobileCommand, cmd_ptr_); + + // Act + EXPECT_CALL(mock_app_manager_, ManageHMICommand(cmd_ptr_)); + cmd_holder.Resume(mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand); + + EXPECT_CALL( + mock_app_manager_, + ManageMobileCommand(cmd_ptr_, + am::commands::Command::CommandOrigin::ORIGIN_MOBILE)); + cmd_holder.Resume(mock_app_ptr_, + am::CommandHolder::CommandType::kMobileCommand); +} + +} // application_manager_test +} // components +} // test diff --git a/src/components/application_manager/test/commands/CMakeLists.txt b/src/components/application_manager/test/commands/CMakeLists.txt index cc16e4d87b..8dafc16471 100644 --- a/src/components/application_manager/test/commands/CMakeLists.txt +++ b/src/components/application_manager/test/commands/CMakeLists.txt @@ -46,6 +46,7 @@ set(COMMANDS_TEST_DIR ${AM_TEST_DIR}/commands) file(GLOB SOURCES ${COMMANDS_TEST_DIR}/* ${COMPONENTS_DIR}/application_manager/test/mock_message_helper.cc + ${COMPONENTS_DIR}/application_manager/test/mock_application_helper.cc ${COMPONENTS_DIR}/application_manager/src/smart_object_keys.cc ${COMPONENTS_DIR}/application_manager/src/message.cc ${COMMANDS_TEST_DIR}/hmi/* @@ -57,13 +58,13 @@ set(LIBRARIES gmock Utils SmartObjects - jsoncpp HMI_API MOBILE_API ApplicationManager AMHMICommandsLibrary AMMobileCommandsLibrary connectionHandler + jsoncpp ) create_cotired_test("commands_test" "${SOURCES}" "${LIBRARIES}" ) diff --git a/src/components/application_manager/test/commands/command_impl_test.cc b/src/components/application_manager/test/commands/command_impl_test.cc index fd660af210..ff9634cbb1 100644 --- a/src/components/application_manager/test/commands/command_impl_test.cc +++ b/src/components/application_manager/test/commands/command_impl_test.cc @@ -83,8 +83,8 @@ class CommandImplTest : public CommandsTest<CommandsTestMocks::kIsNice> { public: class UnwrappedCommandImpl : CommandImpl { public: - using CommandImpl::ReplaceMobileByHMIAppId; - using CommandImpl::ReplaceHMIByMobileAppId; + using CommandImpl::ReplaceMobileWithHMIAppId; + using CommandImpl::ReplaceHMIWithMobileAppId; UnwrappedCommandImpl(const MessageSharedPtr& message, ApplicationManager& application_manager) @@ -151,16 +151,16 @@ TEST_F(CommandImplTest, GetMethods_SUCCESS) { EXPECT_NO_THROW(command->onTimeOut()); } -TEST_F(CommandImplTest, ReplaceMobileByHMIAppId_NoAppIdInMessage_UNSUCCESS) { +TEST_F(CommandImplTest, ReplaceMobileWithHMIAppId_NoAppIdInMessage_UNSUCCESS) { MessageSharedPtr msg; UCommandImplPtr command = CreateCommand<UCommandImpl>(msg); EXPECT_CALL(app_mngr_, application(_)).Times(0); - command->ReplaceMobileByHMIAppId(*msg); + command->ReplaceMobileWithHMIAppId(*msg); } -TEST_F(CommandImplTest, ReplaceMobileByHMIAppId_SUCCESS) { +TEST_F(CommandImplTest, ReplaceMobileWithHMIAppId_SUCCESS) { MessageSharedPtr msg = CreateMessage(); (*msg)[strings::app_id] = kAppId1; @@ -171,12 +171,12 @@ TEST_F(CommandImplTest, ReplaceMobileByHMIAppId_SUCCESS) { EXPECT_CALL(app_mngr_, application(kAppId1)).WillOnce(Return(app)); ON_CALL(*app, hmi_app_id()).WillByDefault(Return(kAppId2)); - command->ReplaceMobileByHMIAppId(*msg); + command->ReplaceMobileWithHMIAppId(*msg); EXPECT_EQ(kAppId2, (*msg)[strings::app_id].asUInt()); } -TEST_F(CommandImplTest, ReplaceMobileByHMIAppId_Array_SUCCESS) { +TEST_F(CommandImplTest, ReplaceMobileWithHMIAppId_Array_SUCCESS) { MessageSharedPtr msg = CreateArrayMessage(kDefaultMsgCount); UCommandImplPtr command = CreateCommand<UCommandImpl>(msg); @@ -187,14 +187,14 @@ TEST_F(CommandImplTest, ReplaceMobileByHMIAppId_Array_SUCCESS) { .WillRepeatedly(Return(app)); ON_CALL(*app, hmi_app_id()).WillByDefault(Return(kAppId2)); - command->ReplaceMobileByHMIAppId(*msg); + command->ReplaceMobileWithHMIAppId(*msg); EXPECT_TRUE(msg->asArray()); std::for_each( msg->asArray()->begin(), msg->asArray()->end(), ExpectEqualAppId); } -TEST_F(CommandImplTest, ReplaceMobileByHMIAppId_Map_SUCCESS) { +TEST_F(CommandImplTest, ReplaceMobileWithHMIAppId_Map_SUCCESS) { MessageSharedPtr msg = CreateMapMessage(kDefaultMsgCount); UCommandImplPtr command = CreateCommand<UCommandImpl>(msg); @@ -205,7 +205,7 @@ TEST_F(CommandImplTest, ReplaceMobileByHMIAppId_Map_SUCCESS) { .WillRepeatedly(Return(app)); ON_CALL(*app, hmi_app_id()).WillByDefault(Return(kAppId2)); - command->ReplaceMobileByHMIAppId(*msg); + command->ReplaceMobileWithHMIAppId(*msg); std::set<std::string> keys(msg->enumerate()); std::for_each(keys.begin(), @@ -213,16 +213,17 @@ TEST_F(CommandImplTest, ReplaceMobileByHMIAppId_Map_SUCCESS) { std::bind2nd(std::ptr_fun(&ExpectEqualKeyAppId), msg)); } -TEST_F(CommandImplTest, ReplaceHMIByMobileAppId_NoHMIAppIdInMessage_UNSUCCESS) { +TEST_F(CommandImplTest, + ReplaceHMIWithMobileAppId_NoHMIAppIdInMessage_UNSUCCESS) { MessageSharedPtr msg; UCommandImplPtr command = CreateCommand<UCommandImpl>(msg); EXPECT_CALL(app_mngr_, application_by_hmi_app(_)).Times(0); - command->ReplaceHMIByMobileAppId(*msg); + command->ReplaceHMIWithMobileAppId(*msg); } -TEST_F(CommandImplTest, ReplaceHMIByMobileAppId_SUCCESS) { +TEST_F(CommandImplTest, ReplaceHMIWithMobileAppId_SUCCESS) { MessageSharedPtr msg = CreateMessage(); (*msg)[strings::app_id] = kAppId1; @@ -233,12 +234,12 @@ TEST_F(CommandImplTest, ReplaceHMIByMobileAppId_SUCCESS) { EXPECT_CALL(app_mngr_, application_by_hmi_app(kAppId1)).WillOnce(Return(app)); ON_CALL(*app, app_id()).WillByDefault(Return(kAppId2)); - command->ReplaceHMIByMobileAppId(*msg); + command->ReplaceHMIWithMobileAppId(*msg); EXPECT_EQ(kAppId2, (*msg)[strings::app_id].asUInt()); } -TEST_F(CommandImplTest, ReplaceHMIByMobileAppId_Array_SUCCESS) { +TEST_F(CommandImplTest, ReplaceHMIWithMobileAppId_Array_SUCCESS) { MessageSharedPtr msg = CreateArrayMessage(kDefaultMsgCount); UCommandImplPtr command = CreateCommand<UCommandImpl>(msg); @@ -249,14 +250,14 @@ TEST_F(CommandImplTest, ReplaceHMIByMobileAppId_Array_SUCCESS) { .WillRepeatedly(Return(app)); ON_CALL(*app, app_id()).WillByDefault(Return(kAppId2)); - command->ReplaceHMIByMobileAppId(*msg); + command->ReplaceHMIWithMobileAppId(*msg); EXPECT_TRUE(msg->asArray()); std::for_each( msg->asArray()->begin(), msg->asArray()->end(), ExpectEqualAppId); } -TEST_F(CommandImplTest, ReplaceHMIByMobileAppId_Map_SUCCESS) { +TEST_F(CommandImplTest, ReplaceHMIWithMobileAppId_Map_SUCCESS) { MessageSharedPtr msg = CreateMapMessage(kDefaultMsgCount); UCommandImplPtr command = CreateCommand<UCommandImpl>(msg); @@ -267,7 +268,7 @@ TEST_F(CommandImplTest, ReplaceHMIByMobileAppId_Map_SUCCESS) { .WillRepeatedly(Return(app)); ON_CALL(*app, app_id()).WillByDefault(Return(kAppId2)); - command->ReplaceHMIByMobileAppId(*msg); + command->ReplaceHMIWithMobileAppId(*msg); std::set<std::string> keys = msg->enumerate(); std::for_each(keys.begin(), 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 1948608b9f..4493c54d3c 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 @@ -64,7 +64,6 @@ using ::testing::_; using ::testing::Return; using ::testing::SaveArg; using ::testing::DoAll; -using ::testing::Mock; using ::utils::SharedPtr; using am::commands::MessageSharedPtr; @@ -128,14 +127,6 @@ class CommandRequestImplTest } }; - CommandRequestImplTest() - : mock_message_helper_(*am::MockMessageHelper::message_helper_mock()) { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - ~CommandRequestImplTest() { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - MockAppPtr InitAppSetDataAccessor(SharedPtr<ApplicationSet>& app_set) { app_set = (!app_set ? ::utils::MakeShared<ApplicationSet>() : app_set); MockAppPtr app(CreateMockApp()); @@ -147,7 +138,6 @@ class CommandRequestImplTest } sync_primitives::Lock app_set_lock_; - am::MockMessageHelper& mock_message_helper_; }; typedef CommandRequestImplTest::UnwrappedCommandRequestImpl UCommandRequestImpl; @@ -308,8 +298,8 @@ TEST_F(CommandRequestImplTest, SendHMIRequest_UseEvent_SUCCESS) { TEST_F(CommandRequestImplTest, RemoveDisallowedParameters_SUCCESS) { am::VehicleData vehicle_data; - vehicle_data.insert( - am::VehicleData::value_type(kMissedParam, am::VehicleDataType::MYKEY)); + vehicle_data.insert(am::VehicleData::value_type( + kMissedParam, mobile_apis::VehicleDataType::VEHICLEDATA_MYKEY)); EXPECT_CALL(mock_message_helper_, vehicle_data()) .WillOnce(ReturnRef(vehicle_data)); @@ -425,8 +415,8 @@ TEST_F(CommandRequestImplTest, CheckAllowedParameters_MsgParamsMap_SUCCESS) { TEST_F(CommandRequestImplTest, AddDisallowedParameters_SUCCESS) { am::VehicleData vehicle_data; - vehicle_data.insert(am::VehicleData::value_type(kDisallowedParam1, - am::VehicleDataType::MYKEY)); + vehicle_data.insert(am::VehicleData::value_type( + kDisallowedParam1, mobile_apis::VehicleDataType::VEHICLEDATA_MYKEY)); EXPECT_CALL(mock_message_helper_, vehicle_data()) .WillOnce(ReturnRef(vehicle_data)); @@ -477,8 +467,8 @@ TEST_F(CommandRequestImplTest, SendResponse_SUCCESS) { TEST_F(CommandRequestImplTest, SendResponse_AddDisallowedParametersToInfo_SUCCESS) { am::VehicleData vehicle_data; - vehicle_data.insert(am::VehicleData::value_type(kDisallowedParam1, - am::VehicleDataType::MYKEY)); + vehicle_data.insert(am::VehicleData::value_type( + kDisallowedParam1, mobile_apis::VehicleDataType::VEHICLEDATA_MYKEY)); EXPECT_CALL(mock_message_helper_, vehicle_data()) .WillOnce(ReturnRef(vehicle_data)); diff --git a/src/components/application_manager/test/commands/hmi/activate_app_request_test.cc b/src/components/application_manager/test/commands/hmi/activate_app_request_test.cc index 771d13924c..7f7911a01d 100644 --- a/src/components/application_manager/test/commands/hmi/activate_app_request_test.cc +++ b/src/components/application_manager/test/commands/hmi/activate_app_request_test.cc @@ -34,9 +34,9 @@ #include "application_manager/commands/hmi/activate_app_request.h" #include "utils/shared_ptr.h" #include "smart_objects/smart_object.h" -#include "application_manager/mock_application.h" #include "application_manager/commands/command_impl.h" #include "commands/commands_test.h" +#include "application_manager/mock_application.h" namespace test { namespace components { @@ -45,12 +45,16 @@ namespace hmi_commands_test { namespace activate_app_request { using ::testing::_; +using ::utils::SharedPtr; namespace am = ::application_manager; namespace strings = ::application_manager::strings; using am::commands::MessageSharedPtr; using am::commands::ActivateAppRequest; using am::commands::CommandImpl; +using ::test::components::application_manager_test::MockApplication; + +typedef SharedPtr<MockApplication> MockAppPtr; typedef ::utils::SharedPtr<ActivateAppRequest> ActivateAppRequestPtr; MATCHER_P(CheckMessage, level, "") { @@ -83,10 +87,13 @@ class ActivateAppRequestTest : public CommandsTest<CommandsTestMocks::kIsNice> { TEST_F(ActivateAppRequestTest, Run_SUCCESS) { MessageSharedPtr msg = CreateMsgParams(); + MockAppPtr app = CreateMockApp(); + + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app)); + + ON_CALL(*app, hmi_app_id()).WillByDefault(Return(kAppId)); - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); -// TODO(OKozlov) Invastigate and fix issue with using log +// TODO(OKozlov) Investigate and fix issue with using log #ifdef ENABLE_LOG (*msg)[strings::msg_params][strings::activate_app_hmi_level] = mobile_apis::HMILevel::HMI_FULL; diff --git a/src/components/application_manager/test/commands/hmi/get_system_info_response_test.cc b/src/components/application_manager/test/commands/hmi/get_system_info_response_test.cc index 0fe76ae16d..980b6e0e9d 100644 --- a/src/components/application_manager/test/commands/hmi/get_system_info_response_test.cc +++ b/src/components/application_manager/test/commands/hmi/get_system_info_response_test.cc @@ -90,12 +90,6 @@ class GetSystemInfoResponseTest return command_msg; } - void SetUp() OVERRIDE { - message_helper_mock_ = - application_manager::MockMessageHelper::message_helper_mock(); - } - - am::MockMessageHelper* message_helper_mock_; MockHMICapabilities mock_hmi_capabilities_; SmartObject capabilities_; }; @@ -114,7 +108,7 @@ TEST_F(GetSystemInfoResponseTest, GetSystemInfo_SUCCESS) { .WillOnce(ReturnRef(mock_hmi_capabilities_)); std::string language; - EXPECT_CALL(*message_helper_mock_, + EXPECT_CALL(mock_message_helper_, CommonLanguageToString( static_cast<hmi_apis::Common_Language::eType>(lang_code))) .WillOnce(Return(language)); @@ -140,7 +134,7 @@ TEST_F(GetSystemInfoResponseTest, GetSystemInfo_UNSUCCESS) { EXPECT_CALL(app_mngr_, hmi_capabilities()).Times(0); - EXPECT_CALL(*message_helper_mock_, + EXPECT_CALL(mock_message_helper_, CommonLanguageToString( static_cast<hmi_apis::Common_Language::eType>(lang_code))) .Times(0); diff --git a/src/components/application_manager/test/commands/hmi/hmi_notifications/hmi_notifications_test.cc b/src/components/application_manager/test/commands/hmi/hmi_notifications/hmi_notifications_test.cc index 9af72a7925..ffedf1b4f6 100644 --- a/src/components/application_manager/test/commands/hmi/hmi_notifications/hmi_notifications_test.cc +++ b/src/components/application_manager/test/commands/hmi/hmi_notifications/hmi_notifications_test.cc @@ -130,14 +130,14 @@ #include "application_manager/policies/mock_policy_handler_interface.h" #include "application_manager/mock_message_helper.h" #include "protocol_handler/mock_session_observer.h" +#include "application_manager/mock_resume_ctrl.h" + #ifdef SDL_REMOTE_CONTROL #include "functional_module/plugin_manager.h" #endif // SDL_REMOTE_CONTROL namespace am = application_manager; -static am::MockMessageHelper* message_helper_mock_; - namespace test { namespace components { namespace commands_test { @@ -150,7 +150,6 @@ using ::testing::Types; using ::testing::Return; using ::testing::ReturnRef; using ::testing::NiceMock; -using ::testing::Mock; using ::testing::InSequence; using ::utils::SharedPtr; using ::smart_objects::SmartObject; @@ -183,6 +182,11 @@ ACTION_P(GetEventId, event_id) { ACTION_P(GetArg, arg) { *arg = arg0; } + +ACTION_P(GetArg3, result) { + arg3 = *result; +} + ACTION_P2(GetConnectIdPermissionConsent, connect_id, consent) { *connect_id = arg0; std::vector<policy::FunctionalGroupPermission>::const_iterator it = @@ -223,16 +227,11 @@ class HMICommandsNotificationsTest CommandsTestMocks::kIsNice> { public: HMICommandsNotificationsTest() - : applications_(application_set_, applications_lock_), app_ptr_(NULL) { - message_helper_mock_ = - application_manager::MockMessageHelper::message_helper_mock(); - Mock::VerifyAndClearExpectations(message_helper_mock_); - } + : applications_(application_set_, applications_lock_), app_ptr_(NULL) {} ~HMICommandsNotificationsTest() { // Fix DataAccessor release and WinQt crash Mock::VerifyAndClearExpectations(&app_mngr_); - Mock::VerifyAndClearExpectations(message_helper_mock_); } typedef Command CommandType; @@ -842,7 +841,7 @@ TEST_F(HMICommandsNotificationsTest, utils::SharedPtr<Command> command = CreateCommand<OnSystemInfoChangedNotification>(message); - EXPECT_CALL(*message_helper_mock_, CommonLanguageToString(_)); + EXPECT_CALL(mock_message_helper_, CommonLanguageToString(_)); EXPECT_CALL(app_mngr_, GetPolicyHandler()); EXPECT_CALL(policy_interface_, OnSystemInfoChanged(_)); command->Run(); @@ -1037,10 +1036,16 @@ TEST_F(HMICommandsNotificationsTest, kCorrelationId_; MessageSharedPtr temp_message = CreateMessage(); + resumprion_test::MockResumeCtrl mock_resume_ctrl; + EXPECT_CALL(app_mngr_, resume_controller()) + .WillOnce(ReturnRef(mock_resume_ctrl)); + EXPECT_CALL(mock_resume_ctrl, OnSuspend()); + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) .WillOnce(Return(kCorrelationId_)); EXPECT_CALL(app_mngr_, ManageHMICommand(_)) .WillOnce(GetMessage(temp_message)); + command->Run(); EXPECT_EQ( static_cast<uint32_t>( @@ -1116,7 +1121,7 @@ TEST_F(HMICommandsNotificationsTest, #endif // SDL_REMOTE_CONTROL EXPECT_CALL(app_mngr_, application(kAppId_)).WillRepeatedly(Return(app_)); - EXPECT_CALL(*message_helper_mock_, + EXPECT_CALL(mock_message_helper_, GetOnAppInterfaceUnregisteredNotificationToMobile( kAppId_, *it_mobile_reason)).WillOnce(Return(notification)); EXPECT_CALL(app_mngr_, @@ -1441,7 +1446,7 @@ TEST_F(HMICommandsNotificationsTest, .WillOnce(ReturnRef(mock_state_controller_)); EXPECT_CALL(mock_state_controller_, SetRegularState(app_, mobile_apis::HMILevel::HMI_NONE, false)); - EXPECT_CALL(*message_helper_mock_, + EXPECT_CALL(mock_message_helper_, GetOnAppInterfaceUnregisteredNotificationToMobile( kAppId_, mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE)) @@ -1595,7 +1600,10 @@ TEST_F(HMICommandsNotificationsTest, ON_CALL(mock_connection_handler_, get_session_observer()) .WillByDefault(ReturnRef(mock_session_observer_)); const int32_t device_id = 1; - ON_CALL(mock_session_observer_, GetDataOnDeviceID(_, NULL, NULL, _, NULL)) + ON_CALL( + mock_session_observer_, + GetDataOnDeviceID( + testing::An<transport_manager::DeviceHandle>(), NULL, NULL, _, NULL)) .WillByDefault(Return(device_id)); EXPECT_CALL(policy_interface_, GetUserConsentForDevice(_)) @@ -1645,7 +1653,10 @@ TEST_F(HMICommandsNotificationsTest, ON_CALL(mock_connection_handler_, get_session_observer()) .WillByDefault(ReturnRef(mock_session_observer_)); const int32_t device_id = 1; - ON_CALL(mock_session_observer_, GetDataOnDeviceID(_, NULL, NULL, _, NULL)) + ON_CALL( + mock_session_observer_, + GetDataOnDeviceID( + testing::An<transport_manager::DeviceHandle>(), NULL, NULL, _, NULL)) .WillByDefault(Return(device_id)); EXPECT_CALL(policy_interface_, GetUserConsentForDevice(_)) @@ -1764,7 +1775,7 @@ TEST_F(HMICommandsNotificationsTest, ManageMobileCommand(_, Command::CommandOrigin::ORIGIN_SDL)); EXPECT_CALL(*app_ptr_, app_id()).WillRepeatedly(Return(kAppId_)); EXPECT_CALL(*app_ptr_, language()).WillRepeatedly(ReturnRef(kLang)); - EXPECT_CALL(*message_helper_mock_, + EXPECT_CALL(mock_message_helper_, GetOnAppInterfaceUnregisteredNotificationToMobile( kAppId_, mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE)) @@ -1872,7 +1883,7 @@ TEST_F(HMICommandsNotificationsTest, ManageMobileCommand(_, Command::CommandOrigin::ORIGIN_SDL)); EXPECT_CALL(*app_ptr_, app_id()).WillRepeatedly(Return(kAppId_)); EXPECT_CALL(*app_ptr_, ui_language()).WillRepeatedly(ReturnRef(kLang)); - EXPECT_CALL(*message_helper_mock_, + EXPECT_CALL(mock_message_helper_, GetOnAppInterfaceUnregisteredNotificationToMobile( kAppId_, mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE)) @@ -1904,7 +1915,7 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationEmptyData) { utils::SharedPtr<Command> command = CreateCommand<hmi::OnDriverDistractionNotification>(message); - EXPECT_CALL(app_mngr_, set_driver_distraction(state)); + EXPECT_CALL(app_mngr_, set_driver_distraction_state(state)); EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); EXPECT_CALL(app_mngr_, ManageMobileCommand(_, _)).Times(0); @@ -1939,12 +1950,18 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationValidApp) { CreateCommand<hmi::OnDriverDistractionNotification>(message); application_set_.insert(app_); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + policy::CheckPermissionResult result; + result.hmi_level_permitted = policy::kRpcAllowed; + EXPECT_CALL(app_mngr_, GetPolicyHandler()) + .WillOnce(ReturnRef(policy_interface_)); + EXPECT_CALL(policy_interface_, CheckPermissions(_, _, _, _)) + .WillOnce(GetArg3(&result)); EXPECT_CALL(app_mngr_, ManageMobileCommand(_, Command::CommandOrigin::ORIGIN_SDL)) .WillOnce(GetMessage(message)); EXPECT_CALL(*app_ptr_, app_id()).WillRepeatedly(Return(kAppId_)); + command->Run(); EXPECT_EQ( static_cast<int32_t>(am::mobile_api::FunctionID::OnDriverDistractionID), diff --git a/src/components/application_manager/test/commands/hmi/on_driver_distraction_notification_test.cc b/src/components/application_manager/test/commands/hmi/on_driver_distraction_notification_test.cc index 94dd1c6599..b8a8c68ece 100644 --- a/src/components/application_manager/test/commands/hmi/on_driver_distraction_notification_test.cc +++ b/src/components/application_manager/test/commands/hmi/on_driver_distraction_notification_test.cc @@ -43,6 +43,7 @@ #include "commands/commands_test.h" #include "application_manager/mock_application.h" #include "application_manager/mock_application_manager.h" +#include "application_manager/policies/mock_policy_handler_interface.h" #include "hmi/on_driver_distraction_notification.h" #include "interfaces/MOBILE_API.h" @@ -68,6 +69,7 @@ class HMIOnDriverDistractionNotificationTest : public CommandsTest<CommandsTestMocks::kIsNice> { public: ::sync_primitives::Lock app_set_lock_; + policy_test::MockPolicyHandlerInterface mock_policy_handler_interface_; }; MATCHER_P2(CheckNotificationParams, function_id, state, "") { @@ -83,16 +85,52 @@ MATCHER_P2(CheckNotificationParams, function_id, state, "") { return is_function_id_matched && is_state_matched; } +ACTION_P(GetArg3, result) { + arg3 = *result; +} + +TEST_F(HMIOnDriverDistractionNotificationTest, Run_PushMobileMessage_SUCCESS) { + const hmi_apis::Common_DriverDistractionState::eType state = + hmi_apis::Common_DriverDistractionState::DD_ON; + MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map)); + (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state; + + NotificationPtr command( + CreateCommand<OnDriverDistractionNotification>(commands_msg)); + + EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state))); + + MockAppPtr mock_app = CreateMockApp(); + am::ApplicationSet app_set; + app_set.insert(mock_app); + + DataAccessor<am::ApplicationSet> accessor(app_set, app_set_lock_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + policy::CheckPermissionResult result; + result.hmi_level_permitted = policy::kRpcDisallowed; + EXPECT_CALL(app_mngr_, GetPolicyHandler()) + .WillOnce(ReturnRef(mock_policy_handler_interface_)); + EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) + .WillOnce(GetArg3(&result)); + + EXPECT_CALL(*mock_app, + PushMobileMessage(CheckNotificationParams( + am::mobile_api::FunctionID::OnDriverDistractionID, state))); + + command->Run(); +} + TEST_F(HMIOnDriverDistractionNotificationTest, Run_SendNotificationToMobile_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); const hmi_apis::Common_DriverDistractionState::eType state = hmi_apis::Common_DriverDistractionState::DD_ON; - (*msg)[am::strings::msg_params][am::hmi_notification::state] = state; + MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map)); + (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state; - NotificationPtr command(CreateCommand<OnDriverDistractionNotification>(msg)); + NotificationPtr command( + CreateCommand<OnDriverDistractionNotification>(commands_msg)); - EXPECT_CALL(app_mngr_, set_driver_distraction(state)); + EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state))); MockAppPtr mock_app = CreateMockApp(); am::ApplicationSet app_set; @@ -101,9 +139,12 @@ TEST_F(HMIOnDriverDistractionNotificationTest, DataAccessor<am::ApplicationSet> accessor(app_set, app_set_lock_); EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); - const uint32_t app_id = 1u; - EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(app_id)); - + policy::CheckPermissionResult result; + result.hmi_level_permitted = policy::kRpcAllowed; + EXPECT_CALL(app_mngr_, GetPolicyHandler()) + .WillOnce(ReturnRef(mock_policy_handler_interface_)); + EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) + .WillOnce(GetArg3(&result)); EXPECT_CALL(app_mngr_, ManageMobileCommand( CheckNotificationParams( diff --git a/src/components/application_manager/test/commands/hmi/rc_is_ready_request_test.cc b/src/components/application_manager/test/commands/hmi/rc_is_ready_request_test.cc index 27a77ba990..73a43342f1 100644 --- a/src/components/application_manager/test/commands/hmi/rc_is_ready_request_test.cc +++ b/src/components/application_manager/test/commands/hmi/rc_is_ready_request_test.cc @@ -55,7 +55,6 @@ using ::testing::ReturnRef; namespace am = ::application_manager; using am::commands::MessageSharedPtr; using am::commands::RCIsReadyRequest; -using am::MockMessageHelper; using am::event_engine::Event; typedef SharedPtr<RCIsReadyRequest> RCIsReadyRequestPtr; @@ -102,7 +101,7 @@ class RCIsReadyRequestTest void ExpectSendMessagesToHMI() { smart_objects::SmartObjectSPtr capabilities( new smart_objects::SmartObject(smart_objects::SmartType_Map)); - EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), + EXPECT_CALL(mock_message_helper_, CreateModuleInfoSO(hmi_apis::FunctionID::RC_GetCapabilities, _)) .WillOnce(Return(capabilities)); EXPECT_CALL(app_mngr_, ManageHMICommand(capabilities)); diff --git a/src/components/application_manager/test/commands/hmi/sdl_activate_app_request_test.cc b/src/components/application_manager/test/commands/hmi/sdl_activate_app_request_test.cc index 3805df5834..d36b55ee25 100644 --- a/src/components/application_manager/test/commands/hmi/sdl_activate_app_request_test.cc +++ b/src/components/application_manager/test/commands/hmi/sdl_activate_app_request_test.cc @@ -62,7 +62,6 @@ using testing::Return; using testing::ReturnRef; using testing::Mock; using ::testing::NiceMock; -using am::MockMessageHelper; using policy_test::MockPolicyHandlerInterface; using am::event_engine::Event; @@ -102,15 +101,9 @@ MATCHER_P2(CheckMsgParams, result, corr_id, "") { class SDLActivateAppRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { protected: - SDLActivateAppRequestTest() - : message_helper_mock_(am::MockMessageHelper::message_helper_mock()) { - Mock::VerifyAndClearExpectations(message_helper_mock_); - } - ~SDLActivateAppRequestTest() { // Fix DataAccessor release and WinQt crash Mock::VerifyAndClearExpectations(&app_mngr_); - Mock::VerifyAndClearExpectations(message_helper_mock_); } void InitCommand(const uint32_t& timeout) OVERRIDE { @@ -127,7 +120,6 @@ class SDLActivateAppRequestTest ApplicationSet app_list_; ::sync_primitives::Lock lock_; - am::MockMessageHelper* message_helper_mock_; policy_test::MockPolicyHandlerInterface policy_handler_; application_manager_test::MockStateController mock_state_controller_; NiceMock<event_engine_test::MockEventDispatcher> mock_event_dispatcher_; @@ -220,7 +212,7 @@ TEST_F(SDLActivateAppRequestTest, FindAppToRegister_SUCCESS) { const std::string package = "package"; ON_CALL(*mock_app_first, PackageName()).WillByDefault(Return(package)); - EXPECT_CALL(*message_helper_mock_, SendLaunchApp(_, _, _, _)); + EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, _, _, _)); command->Run(); } @@ -299,7 +291,7 @@ TEST_F(SDLActivateAppRequestTest, FirstAppActive_SUCCESS) { ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); EXPECT_CALL(*mock_app_first, is_foreground()).WillRepeatedly(Return(true)); - EXPECT_CALL(*message_helper_mock_, SendLaunchApp(_, _, _, _)); + EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, _, _, _)); command->Run(); } @@ -328,7 +320,6 @@ TEST_F(SDLActivateAppRequestTest, FirstAppNotActive_SUCCESS) { } TEST_F(SDLActivateAppRequestTest, FirstAppIsForeground_SUCCESS) { - Mock::VerifyAndClearExpectations(&message_helper_mock_); MessageSharedPtr msg = CreateMessage(); SetCorrelationAndAppID(msg); @@ -363,10 +354,9 @@ TEST_F(SDLActivateAppRequestTest, FirstAppIsForeground_SUCCESS) { ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); EXPECT_CALL(*mock_app_first, is_foreground()).WillOnce(Return(true)); - EXPECT_CALL(*message_helper_mock_, SendLaunchApp(_, schema, package_name, _)); + EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, schema, package_name, _)); command->Run(); - Mock::VerifyAndClearExpectations(&message_helper_mock_); } TEST_F(SDLActivateAppRequestTest, FirstAppNotRegisteredAndEmpty_SUCCESS) { @@ -397,7 +387,7 @@ TEST_F(SDLActivateAppRequestTest, FirstAppNotRegisteredAndEmpty_SUCCESS) { Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); EXPECT_CALL(*mock_app_first, is_foreground()).WillOnce(Return(false)); - EXPECT_CALL(*message_helper_mock_, SendLaunchApp(_, _, _, _)); + EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, _, _, _)); command->Run(); } @@ -432,7 +422,7 @@ TEST_F(SDLActivateAppRequestTest, FirstAppNotRegistered_SUCCESS) { Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); EXPECT_CALL(*mock_app_first, is_foreground()).WillRepeatedly(Return(true)); - EXPECT_CALL(*message_helper_mock_, SendLaunchApp(_, _, _, _)); + EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, _, _, _)); command->Run(); } diff --git a/src/components/application_manager/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc b/src/components/application_manager/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc index 5ef54f7be5..66fedda3ca 100644 --- a/src/components/application_manager/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc +++ b/src/components/application_manager/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc @@ -73,10 +73,6 @@ namespace strings = ::application_manager::strings; class SDLGetUserFriendlyMessageRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { - public: - SDLGetUserFriendlyMessageRequestTest() - : mock_message_helper_(*MockMessageHelper::message_helper_mock()) {} - protected: void SetUp() OVERRIDE { mock_app_ = CreateMockApp(); @@ -90,7 +86,6 @@ class SDLGetUserFriendlyMessageRequestTest } MockAppPtr mock_app_; MockPolicyHandlerInterface mock_policy_handler_; - MockMessageHelper& mock_message_helper_; }; TEST_F(SDLGetUserFriendlyMessageRequestTest, Run_LanguageSet_SUCCESS) { diff --git a/src/components/application_manager/test/commands/hmi/ui_is_ready_request_test.cc b/src/components/application_manager/test/commands/hmi/ui_is_ready_request_test.cc index 23146eec9a..66b1317870 100644 --- a/src/components/application_manager/test/commands/hmi/ui_is_ready_request_test.cc +++ b/src/components/application_manager/test/commands/hmi/ui_is_ready_request_test.cc @@ -54,12 +54,10 @@ namespace ui_is_ready_request { namespace am = ::application_manager; using ::testing::_; -using ::testing::Mock; using ::testing::Return; using ::testing::ReturnRef; using am::commands::MessageSharedPtr; using am::commands::UIIsReadyRequest; -using am::MockMessageHelper; using am::event_engine::Event; typedef SharedPtr<UIIsReadyRequest> UIIsReadyRequestPtr; @@ -67,14 +65,11 @@ typedef SharedPtr<UIIsReadyRequest> UIIsReadyRequestPtr; class UIIsReadyRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: - UIIsReadyRequestTest() - : command_(CreateCommand<UIIsReadyRequest>()) - , mock_message_helper_(*MockMessageHelper::message_helper_mock()) {} + UIIsReadyRequestTest() : command_(CreateCommand<UIIsReadyRequest>()) {} void SetUp() OVERRIDE { ON_CALL(app_mngr_, hmi_capabilities()) .WillByDefault(ReturnRef(mock_hmi_capabilities_)); - Mock::VerifyAndClearExpectations(&mock_message_helper_); } void SetUpExpectations(bool is_ui_cooperating_available, bool is_send_message_to_hmi, @@ -151,7 +146,6 @@ class UIIsReadyRequestTest } UIIsReadyRequestPtr command_; - MockMessageHelper& mock_message_helper_; application_manager_test::MockHMICapabilities mock_hmi_capabilities_; policy_test::MockPolicyHandlerInterface mock_policy_handler_interface_; }; diff --git a/src/components/application_manager/test/commands/hmi/vi_is_ready_request_test.cc b/src/components/application_manager/test/commands/hmi/vi_is_ready_request_test.cc index 1e15d4ab60..557afa98d0 100644 --- a/src/components/application_manager/test/commands/hmi/vi_is_ready_request_test.cc +++ b/src/components/application_manager/test/commands/hmi/vi_is_ready_request_test.cc @@ -57,7 +57,6 @@ using ::testing::Return; namespace am = ::application_manager; using am::commands::MessageSharedPtr; using am::commands::VIIsReadyRequest; -using am::MockMessageHelper; using am::event_engine::Event; typedef SharedPtr<VIIsReadyRequest> VIIsReadyRequestPtr; @@ -103,7 +102,7 @@ class VIIsReadyRequestTest void ExpectSendMessagesToHMI() { smart_objects::SmartObjectSPtr ivi_type; EXPECT_CALL( - *(MockMessageHelper::message_helper_mock()), + mock_message_helper_, CreateModuleInfoSO(hmi_apis::FunctionID::VehicleInfo_GetVehicleType, _)) .WillOnce(Return(ivi_type)); EXPECT_CALL(app_mngr_, ManageHMICommand(ivi_type)); diff --git a/src/components/application_manager/test/commands/hmi/vr_is_ready_request_test.cc b/src/components/application_manager/test/commands/hmi/vr_is_ready_request_test.cc index 64735a77e2..c9403b2f0e 100644 --- a/src/components/application_manager/test/commands/hmi/vr_is_ready_request_test.cc +++ b/src/components/application_manager/test/commands/hmi/vr_is_ready_request_test.cc @@ -55,7 +55,6 @@ using ::testing::ReturnRef; namespace am = ::application_manager; using am::commands::MessageSharedPtr; using am::commands::VRIsReadyRequest; -using am::MockMessageHelper; using am::event_engine::Event; typedef SharedPtr<VRIsReadyRequest> VRIsReadyRequestPtr; @@ -105,7 +104,7 @@ class VRIsReadyRequestTest smart_objects::SmartObjectSPtr language( new smart_objects::SmartObject(smart_objects::SmartType_Map)); - EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), + EXPECT_CALL(mock_message_helper_, CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetLanguage, _)) .WillOnce(Return(language)); EXPECT_CALL(mock_hmi_capabilities_, set_handle_response_for(*language)); @@ -114,14 +113,14 @@ class VRIsReadyRequestTest smart_objects::SmartObjectSPtr support_language( new smart_objects::SmartObject(smart_objects::SmartType_Map)); EXPECT_CALL( - *(MockMessageHelper::message_helper_mock()), + mock_message_helper_, CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetSupportedLanguages, _)) .WillOnce(Return(support_language)); EXPECT_CALL(app_mngr_, ManageHMICommand(support_language)); smart_objects::SmartObjectSPtr capabilities( new smart_objects::SmartObject(smart_objects::SmartType_Map)); - EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), + EXPECT_CALL(mock_message_helper_, CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetCapabilities, _)) .WillOnce(Return(capabilities)); EXPECT_CALL(app_mngr_, ManageHMICommand(capabilities)); diff --git a/src/components/application_manager/test/commands/mobile/add_command_request_test.cc b/src/components/application_manager/test/commands/mobile/add_command_request_test.cc index dec0ffe7ad..471f0763de 100644 --- a/src/components/application_manager/test/commands/mobile/add_command_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/add_command_request_test.cc @@ -61,11 +61,9 @@ using am::commands::CommandImpl; using am::ApplicationManager; using am::commands::MessageSharedPtr; using am::ApplicationSharedPtr; -using am::MockMessageHelper; using ::testing::_; using ::utils::SharedPtr; using ::testing::Return; -using ::testing::Mock; using ::testing::InSequence; using am::commands::AddCommandRequest; using NsSmartDeviceLink::NsSmartObjects::SmartObjectSPtr; @@ -105,19 +103,13 @@ class AddCommandRequestTest AddCommandRequestTest() : msg_(CreateMessage()) , default_app_name_("test_default_app_name_") - , mock_message_helper_(*MockMessageHelper::message_helper_mock()) , mock_app_(CreateMockApp()) { - Mock::VerifyAndClearExpectations(&mock_message_helper_); EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillRepeatedly(Return(mock_app_)); InitGetters(); InitBasicMessage(); } - ~AddCommandRequestTest() { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - protected: void InitBasicMessage() { (*msg_)[params][connection_key] = kConnectionKey; @@ -209,7 +201,8 @@ class AddCommandRequestTest EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); EXPECT_CALL(app_mngr_, ManageHMICommand(HMIResultCodeIs(cmd_to_delete))) .WillOnce(Return(true)); - SmartObjectSPtr response; + SmartObjectSPtr response = utils::MakeShared<SmartObject>(SmartType_Map); + (*response)[strings::msg_params][strings::info] = "info"; EXPECT_CALL( mock_message_helper_, CreateNegativeResponse(_, _, _, mobile_apis::Result::GENERIC_ERROR)) @@ -226,7 +219,6 @@ class AddCommandRequestTest MessageSharedPtr msg_; SmartObjectSPtr so_ptr_; const utils::custom_string::CustomString default_app_name_; - am::MockMessageHelper& mock_message_helper_; sync_primitives::Lock lock_; MockAppPtr mock_app_; }; @@ -516,9 +508,6 @@ TEST_F(AddCommandRequestTest, OnEvent_UI_SUCCESS) { utils::SharedPtr<AddCommandRequest> request_ptr = CreateCommand<AddCommandRequest>(msg_); request_ptr->Run(); - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::SUCCESS)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); request_ptr->on_event(event); } @@ -530,9 +519,6 @@ TEST_F(AddCommandRequestTest, OnEvent_VR_SUCCESS) { Event event(hmi_apis::FunctionID::VR_AddCommand); event.set_smart_object(*msg); - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::SUCCESS)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); EXPECT_CALL(*mock_app_, AddCommand(kCmdId, (*msg_)[msg_params])); am::CommandsMap commands_map; @@ -619,9 +605,6 @@ TEST_F(AddCommandRequestTest, utils::SharedPtr<AddCommandRequest> request_ptr = CreateCommand<AddCommandRequest>(msg_); request_ptr->Run(); - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::REJECTED)) - .WillOnce(Return(mobile_apis::Result::REJECTED)); EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); EXPECT_CALL(app_mngr_, ManageMobileCommand( @@ -695,9 +678,6 @@ TEST_F( .WillOnce(Return(true)); } - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::GENERIC_ERROR)) - .WillRepeatedly(Return(mobile_apis::Result::GENERIC_ERROR)); EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); utils::SharedPtr<AddCommandRequest> request_ptr = CreateCommand<AddCommandRequest>(msg_); @@ -742,9 +722,6 @@ TEST_F( .WillOnce(Return(true)); } - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::GENERIC_ERROR)) - .WillRepeatedly(Return(mobile_apis::Result::GENERIC_ERROR)); EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); utils::SharedPtr<AddCommandRequest> request_ptr = CreateCommand<AddCommandRequest>(msg_); @@ -973,9 +950,6 @@ TEST_F(AddCommandRequestTest, event_ui.set_smart_object(*msg_ui); Event event_vr(hmi_apis::FunctionID::VR_AddCommand); event_vr.set_smart_object(*msg_); - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::ABORTED)) - .WillOnce(Return(mobile_apis::Result::ABORTED)); EXPECT_CALL( app_mngr_, ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_DeleteCommand))) @@ -1015,9 +989,6 @@ TEST_F(AddCommandRequestTest, utils::SharedPtr<AddCommandRequest> request_ptr = CreateCommand<AddCommandRequest>(msg_); request_ptr->Run(); - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::ABORTED)) - .WillOnce(Return(mobile_apis::Result::ABORTED)); Event event_ui(hmi_apis::FunctionID::UI_AddCommand); event_ui.set_smart_object(*msg_); @@ -1042,7 +1013,8 @@ TEST_F(AddCommandRequestTest, EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(ApplicationSharedPtr())); EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)).Times(0); - SmartObjectSPtr response; + SmartObjectSPtr response = utils::MakeShared<SmartObject>(SmartType_Map); + (*response)[strings::msg_params][strings::info] = "info"; EXPECT_CALL( mock_message_helper_, CreateNegativeResponse(_, _, _, mobile_apis::Result::GENERIC_ERROR)) @@ -1091,7 +1063,8 @@ TEST_F(AddCommandRequestTest, OnTimeOut_AppRemoveCommandCalled) { CreateCommand<AddCommandRequest>(msg_); request_ptr->Run(); EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); - SmartObjectSPtr response; + SmartObjectSPtr response = utils::MakeShared<SmartObject>(SmartType_Map); + (*response)[strings::msg_params][strings::info] = "info"; EXPECT_CALL( mock_message_helper_, CreateNegativeResponse(_, _, _, mobile_apis::Result::GENERIC_ERROR)) diff --git a/src/components/application_manager/test/commands/mobile/add_sub_menu_request_test.cc b/src/components/application_manager/test/commands/mobile/add_sub_menu_request_test.cc index 9617f91016..f5bb7888d8 100644 --- a/src/components/application_manager/test/commands/mobile/add_sub_menu_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/add_sub_menu_request_test.cc @@ -54,9 +54,7 @@ namespace am = ::application_manager; using am::commands::AddSubMenuRequest; using am::commands::MessageSharedPtr; using am::event_engine::Event; -using am::MockMessageHelper; using ::testing::_; -using ::testing::Mock; using ::testing::Return; typedef SharedPtr<AddSubMenuRequest> AddSubMenuPtr; @@ -66,12 +64,7 @@ const uint32_t kConnectionKey = 2u; } // namespace class AddSubMenuRequestTest - : public CommandRequestTest<CommandsTestMocks::kIsNice> { - public: - AddSubMenuRequestTest() - : mock_message_helper_(*MockMessageHelper::message_helper_mock()) {} - MockMessageHelper& mock_message_helper_; -}; + : public CommandRequestTest<CommandsTestMocks::kIsNice> {}; TEST_F(AddSubMenuRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { const uint32_t menu_id = 10u; @@ -97,10 +90,6 @@ TEST_F(AddSubMenuRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { Event event(hmi_apis::FunctionID::UI_AddSubMenu); event.set_smart_object(*ev_msg); - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)) - .WillOnce(Return(mobile_apis::Result::UNSUPPORTED_RESOURCE)); - MessageSharedPtr ui_command_result; EXPECT_CALL( app_mngr_, @@ -123,7 +112,6 @@ TEST_F(AddSubMenuRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { .asString() .empty()); } - Mock::VerifyAndClearExpectations(&mock_message_helper_); } } // namespace add_sub_menu_request diff --git a/src/components/application_manager/test/commands/mobile/alert_maneuver_request_test.cc b/src/components/application_manager/test/commands/mobile/alert_maneuver_request_test.cc index ee0662e5c6..90c6409fa8 100644 --- a/src/components/application_manager/test/commands/mobile/alert_maneuver_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/alert_maneuver_request_test.cc @@ -63,7 +63,6 @@ namespace am = ::application_manager; using am::commands::AlertManeuverRequest; using am::commands::MessageSharedPtr; using am::event_engine::Event; -using am::MockMessageHelper; typedef SharedPtr<AlertManeuverRequest> CommandPtr; @@ -87,11 +86,6 @@ class AlertManeuverRequestTest MockAppPtr mock_app(CreateMockApp()); ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); - MockMessageHelper* mock_message_helper = - MockMessageHelper::message_helper_mock(); - EXPECT_CALL(*mock_message_helper, HMIToMobileResult(_)) - .WillOnce(Return(mobile_apis::Result::UNSUPPORTED_RESOURCE)); - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillRepeatedly(Return(state)); @@ -145,7 +139,8 @@ TEST_F(AlertManeuverRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { TEST_F(AlertManeuverRequestTest, Run_ProcessingResult_UNSUCCESS) { MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::msg_params][am::strings::soft_buttons] = 0; + (*msg)[am::strings::msg_params][am::strings::soft_buttons][0] + [am::strings::text] = "text"; CommandPtr command(CreateCommand<AlertManeuverRequest>(msg)); @@ -158,8 +153,7 @@ TEST_F(AlertManeuverRequestTest, Run_ProcessingResult_UNSUCCESS) { const mobile_apis::Result::eType kProcessingResult = mobile_apis::Result::ABORTED; - EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()), - ProcessSoftButtons(_, _, _, _)) + EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)) .WillOnce(Return(kProcessingResult)); MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); @@ -195,7 +189,8 @@ TEST_F(AlertManeuverRequestTest, Run_IsWhiteSpaceExist_UNSUCCESS) { TEST_F(AlertManeuverRequestTest, Run_ProcessingResult_SUCCESS) { MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::msg_params][am::strings::soft_buttons] = 0; + (*msg)[am::strings::msg_params][am::strings::soft_buttons][0] + [am::strings::text] = "text"; CommandPtr command(CreateCommand<AlertManeuverRequest>(msg)); @@ -205,8 +200,7 @@ TEST_F(AlertManeuverRequestTest, Run_ProcessingResult_SUCCESS) { ON_CALL(app_mngr_, GetPolicyHandler()) .WillByDefault(ReturnRef(policy_interface_)); - EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()), - ProcessSoftButtons(_, _, _, _)) + EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)) .WillOnce(Return(mobile_apis::Result::SUCCESS)); EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceFromFunction(_)) @@ -215,8 +209,7 @@ TEST_F(AlertManeuverRequestTest, Run_ProcessingResult_SUCCESS) { EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); - EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()), - SubscribeApplicationToSoftButton(_, _, _)); + EXPECT_CALL(mock_message_helper_, SubscribeApplicationToSoftButton(_, _, _)); MessageSharedPtr result_msg(CatchHMICommandResult(CallRun(*command))); EXPECT_EQ(hmi_apis::FunctionID::Navigation_AlertManeuver, @@ -237,30 +230,30 @@ TEST_F(AlertManeuverRequestTest, OnEvent_ReceivedUnknownEvent_UNSUCCESS) { .asInt())); } -TEST_F(AlertManeuverRequestTest, OnEvent_UNSUPPORTED_RESOURCE_Case1) { +TEST_F(AlertManeuverRequestTest, OnEvent_SUCCESS) { CheckExpectations(hmi_apis::Common_Result::SUCCESS, - mobile_apis::Result::UNSUPPORTED_RESOURCE, + mobile_apis::Result::SUCCESS, am::HmiInterfaces::STATE_AVAILABLE, true); } -TEST_F(AlertManeuverRequestTest, OnEvent_UNSUPPORTED_RESOURCE_Case2) { - CheckExpectations(hmi_apis::Common_Result::SUCCESS, +TEST_F(AlertManeuverRequestTest, OnEvent_UNSUPPORTED_RESOURCE) { + CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, mobile_apis::Result::UNSUPPORTED_RESOURCE, - am::HmiInterfaces::STATE_NOT_AVAILABLE, - true); + am::HmiInterfaces::STATE_AVAILABLE, + false); } -TEST_F(AlertManeuverRequestTest, OnEvent_UNSUPPORTED_RESOURCE_Case3) { - CheckExpectations(hmi_apis::Common_Result::SUCCESS, - mobile_apis::Result::UNSUPPORTED_RESOURCE, +TEST_F(AlertManeuverRequestTest, OnEvent_WARNINGS) { + CheckExpectations(hmi_apis::Common_Result::WARNINGS, + mobile_apis::Result::WARNINGS, am::HmiInterfaces::STATE_NOT_RESPONSE, true); } -TEST_F(AlertManeuverRequestTest, OnEvent_UNSUPPORTED_RESOURCE_Case4) { +TEST_F(AlertManeuverRequestTest, OnEvent_GENERIC_ERROR) { CheckExpectations(hmi_apis::Common_Result::GENERIC_ERROR, - mobile_apis::Result::UNSUPPORTED_RESOURCE, + mobile_apis::Result::GENERIC_ERROR, am::HmiInterfaces::STATE_NOT_RESPONSE, false); } diff --git a/src/components/application_manager/test/commands/mobile/alert_request_test.cc b/src/components/application_manager/test/commands/mobile/alert_request_test.cc index f83a40843c..5d9e507511 100644 --- a/src/components/application_manager/test/commands/mobile/alert_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/alert_request_test.cc @@ -60,7 +60,6 @@ using ::utils::SharedPtr; using am::event_engine::Event; using policy_test::MockPolicyHandlerInterface; using ::testing::_; -using ::testing::Mock; using ::testing::Return; using ::testing::ReturnRef; @@ -79,10 +78,7 @@ const mobile_apis::FunctionID::eType kFunctionId = class AlertRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: - AlertRequestTest() - : mock_message_helper_(*MockMessageHelper::message_helper_mock()) - , mock_app_(CreateMockApp()) - , msg_(CreateMessage()) {} + AlertRequestTest() : mock_app_(CreateMockApp()), msg_(CreateMessage()) {} protected: MessageSharedPtr CreateFullParamsUISO() { @@ -116,10 +112,6 @@ class AlertRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { info); } - void SetUp() OVERRIDE { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - void PreConditions() { ON_CALL(app_mngr_, application(kConnectionKey)) .WillByDefault(Return(mock_app_)); @@ -128,12 +120,12 @@ class AlertRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { ON_CALL(mock_hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) .WillByDefault( - Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); + Return(am::HmiInterfaces::InterfaceState::STATE_AVAILABLE)); ON_CALL(mock_hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) .WillByDefault( - Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); + Return(am::HmiInterfaces::InterfaceState::STATE_AVAILABLE)); } void Expectations() { @@ -155,9 +147,6 @@ class AlertRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { .WillByDefault(Return(mobile_apis::HMILevel::HMI_BACKGROUND)); } - void TearDown() OVERRIDE { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } void AddAlertTextsToMsg() { (*msg_)[am::strings::msg_params][am::strings::alert_text1] = "alert_text1"; (*msg_)[am::strings::msg_params][am::strings::alert_text2] = "alert_text2"; @@ -192,7 +181,6 @@ class AlertRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { } sync_primitives::Lock lock_; - MockMessageHelper& mock_message_helper_; MockAppPtr mock_app_; MessageSharedPtr msg_; MockPolicyHandlerInterface mock_policy_handler_; @@ -248,9 +236,6 @@ TEST_F(AlertRequestTest, OnEvent_UI_HmiSendSuccess_UNSUPPORTED_RESOURCE) { (*msg)[am::strings::msg_params][am::strings::info] = "UI is not supported by system"; - ON_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillByDefault(Return(mobile_apis::Result::SUCCESS)); - MessageSharedPtr msg_tts = CreateMessage(); (*msg_tts)[am::strings::params][am::hmi_response::code] = hmi_apis::Common_Result::SUCCESS; @@ -263,9 +248,6 @@ TEST_F(AlertRequestTest, OnEvent_UI_HmiSendSuccess_UNSUPPORTED_RESOURCE) { event.set_smart_object(*msg); MessageSharedPtr ui_command_result; - ON_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)) - .WillByDefault(Return(am::mobile_api::Result::UNSUPPORTED_RESOURCE)); EXPECT_CALL( app_mngr_, ManageMobileCommand(_, am::commands::Command::CommandOrigin::ORIGIN_SDL)) @@ -302,14 +284,6 @@ TEST_F(AlertRequestTest, Init_DurationNotExists_SUCCESS) { EXPECT_TRUE(command->Init()); } -TEST_F(AlertRequestTest, OnTimeOut_UNSUCCESS) { - Expectations(); - (*msg_)[am::strings::msg_params][am::strings::soft_buttons] = 0; - CommandPtr command(CreateCommand<AlertRequest>(msg_)); - command->onTimeOut(); - EXPECT_CALL(app_mngr_, ManageMobileCommand(_, _)).Times(0); -} - TEST_F(AlertRequestTest, OnTimeOut_SUCCESS) { Expectations(); MessageSharedPtr result_msg(CreateMessage(smart_objects::SmartType_Null)); @@ -442,8 +416,6 @@ TEST_F(AlertRequestTest, DISABLED_OnEvent_UI_OnResetTimeout_SUCCESS) { Event event(hmi_apis::FunctionID::UI_OnResetTimeout); event.set_smart_object(*msg_); - ON_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillByDefault(Return(mobile_apis::Result::SUCCESS)); command->on_event(event); } @@ -504,8 +476,6 @@ TEST_F(AlertRequestTest, DISABLED_OnEvent_TTSWarnings_SUCCESS) { Event event(hmi_apis::FunctionID::TTS_Speak); event.set_smart_object(*msg_); - ON_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillByDefault(Return(mobile_apis::Result::SUCCESS)); command->on_event(event); } @@ -574,16 +544,12 @@ TEST_F(AlertRequestTest, Event tts_stop_event(hmi_apis::FunctionID::TTS_StopSpeaking); tts_stop_event.set_smart_object(*msg_); - ON_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillByDefault(Return(mobile_apis::Result::SUCCESS)); command->on_event(tts_stop_event); ExpectManageMobileCommandWithResultCode(mobile_apis::Result::WARNINGS); Event event(hmi_apis::FunctionID::TTS_Speak); event.set_smart_object(*msg_); - ON_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillByDefault(Return(mobile_apis::Result::SUCCESS)); command->on_event(event); } @@ -711,8 +677,6 @@ TEST_F(AlertRequestTest, DISABLED_OnEvent_TTSAbortedUiAlertNotSent_SUCCESS) { Event tts_stop_event(hmi_apis::FunctionID::TTS_StopSpeaking); tts_stop_event.set_smart_object(*msg_); - ON_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillByDefault(Return(mobile_apis::Result::SUCCESS)); command->on_event(tts_stop_event); (*msg_)[am::strings::params][am::hmi_response::code] = @@ -722,8 +686,6 @@ TEST_F(AlertRequestTest, DISABLED_OnEvent_TTSAbortedUiAlertNotSent_SUCCESS) { Event event(hmi_apis::FunctionID::TTS_Speak); event.set_smart_object(*msg_); - ON_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillByDefault(Return(mobile_apis::Result::SUCCESS)); command->on_event(event); } @@ -750,8 +712,6 @@ TEST_F(AlertRequestTest, DISABLED_OnEvent_TTSWarningUiAlertWarning_SUCCESS) { Event ui_event(hmi_apis::FunctionID::UI_Alert); ui_event.set_smart_object(*msg_); - ON_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillByDefault(Return(mobile_apis::Result::SUCCESS)); command->on_event(ui_event); Event tts_stop_event(hmi_apis::FunctionID::TTS_StopSpeaking); @@ -762,8 +722,6 @@ TEST_F(AlertRequestTest, DISABLED_OnEvent_TTSWarningUiAlertWarning_SUCCESS) { Event event(hmi_apis::FunctionID::TTS_Speak); event.set_smart_object(*msg_); - ON_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillByDefault(Return(mobile_apis::Result::SUCCESS)); command->on_event(event); } diff --git a/src/components/application_manager/test/commands/mobile/change_registration_test.cc b/src/components/application_manager/test/commands/mobile/change_registration_test.cc index 2fd43a6353..3d7671015c 100644 --- a/src/components/application_manager/test/commands/mobile/change_registration_test.cc +++ b/src/components/application_manager/test/commands/mobile/change_registration_test.cc @@ -66,7 +66,6 @@ using am::commands::MessageSharedPtr; using am::ApplicationSharedPtr; using am::MockMessageHelper; using ::testing::_; -using ::testing::Mock; using ::utils::SharedPtr; using ::testing::Return; using ::testing::ReturnRef; @@ -80,7 +79,6 @@ namespace strings = ::application_manager::strings; namespace hmi_response = ::application_manager::hmi_response; namespace { -const int32_t kCommandId = 1; const uint32_t kAppId = 1u; const uint32_t kCmdId = 1u; const uint32_t kConnectionKey = 2u; @@ -90,8 +88,7 @@ class ChangeRegistrationRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: ChangeRegistrationRequestTest() - : mock_message_helper_(*MockMessageHelper::message_helper_mock()) - , mock_app_(CreateMockApp()) + : mock_app_(CreateMockApp()) , supported_languages_(CreateMessage(smart_objects::SmartType_Array)) {} MessageSharedPtr CreateMsgFromMobile() { @@ -121,26 +118,26 @@ class ChangeRegistrationRequestTest EXPECT_CALL( mock_hmi_interfaces_, GetInterfaceFromFunction(hmi_apis::FunctionID::UI_ChangeRegistration)) - .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + .WillRepeatedly(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); EXPECT_CALL( mock_hmi_interfaces_, GetInterfaceFromFunction(hmi_apis::FunctionID::VR_ChangeRegistration)) - .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); + .WillRepeatedly(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) - .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); EXPECT_CALL( mock_hmi_interfaces_, GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_ChangeRegistration)) - .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + .WillRepeatedly(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) - .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); } void CheckExpectations(const hmi_apis::Common_Result::eType hmi_response, @@ -148,14 +145,11 @@ class ChangeRegistrationRequestTest const am::HmiInterfaces::InterfaceState state, const bool success, const hmi_apis::Common_Result::eType ui_hmi_response = - hmi_apis::Common_Result::WARNINGS, + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, const hmi_apis::Common_Result::eType vr_hmi_response = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE) { MessageSharedPtr msg_from_mobile = CreateMsgFromMobile(); - ON_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillByDefault(Return(mobile_response)); - utils::SharedPtr<ChangeRegistrationRequest> command = CreateCommand<ChangeRegistrationRequest>(msg_from_mobile); MockAppPtr mock_app = CreateMockApp(); @@ -173,6 +167,8 @@ class ChangeRegistrationRequestTest EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); EXPECT_CALL(*app, name()).WillOnce(ReturnRef(name)); PrepareExpectationBeforeRun(); + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(state)); command->Run(); MessageSharedPtr ui_response = CreateMessage(smart_objects::SmartType_Map); @@ -184,9 +180,6 @@ class ChangeRegistrationRequestTest (*tts_response)[strings::params][hmi_response::code] = hmi_response; (*tts_response)[strings::msg_params] = 0; - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillRepeatedly(Return(state)); - am::event_engine::Event event_ui( hmi_apis::FunctionID::UI_ChangeRegistration); event_ui.set_smart_object(*ui_response); @@ -251,10 +244,6 @@ class ChangeRegistrationRequestTest .WillByDefault(ReturnRef(hmi_capabilities_)); } - void TearDown() OVERRIDE { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - void ExpectationsHmiCapabilities( smart_objects::SmartObjectSPtr supported_languages) { EXPECT_CALL(hmi_capabilities_, ui_supported_languages()) @@ -282,7 +271,6 @@ class ChangeRegistrationRequestTest MockHMICapabilities; sync_primitives::Lock app_set_lock_; MockHMICapabilities hmi_capabilities_; - MockMessageHelper& mock_message_helper_; MockAppPtr mock_app_; MessageSharedPtr supported_languages_; MockPolicyHandlerInterface mock_policy_handler_; @@ -379,11 +367,52 @@ TEST_F(ChangeRegistrationRequestTest, } TEST_F(ChangeRegistrationRequestTest, - OnEvent_TTS_UNSUPPORTED_RESOURCE_STATE_NOT_AVAILABLE_Expect_true) { - CheckExpectations(hmi_apis::Common_Result::SUCCESS, - mobile_apis::Result::UNSUPPORTED_RESOURCE, - am::HmiInterfaces::STATE_NOT_AVAILABLE, - true); + OnEvent_TTS_UNSUPPORTED_RESOURCE_STATE_NOT_AVAILABLE_Expect_false) { + MessageSharedPtr msg_from_mobile = CreateMsgFromMobile(); + utils::SharedPtr<ChangeRegistrationRequest> command = + CreateCommand<ChangeRegistrationRequest>(msg_from_mobile); + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + ON_CALL(*mock_app, app_id()).WillByDefault(Return(1)); + am::ApplicationSet application_set; + const utils::custom_string::CustomString name("name"); + MockAppPtr app = CreateMockApp(); + app->set_name(name); + DataAccessor<am::ApplicationSet> accessor(application_set, app_set_lock_); + application_set.insert(app); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + EXPECT_CALL(*app, name()).WillOnce(ReturnRef(name)); + + ON_CALL(app_mngr_, hmi_capabilities()) + .WillByDefault(ReturnRef(hmi_capabilities_)); + (*supported_languages_)[0] = + static_cast<int32_t>(mobile_apis::Language::EN_US); + EXPECT_CALL(hmi_capabilities_, ui_supported_languages()) + .WillOnce(Return(supported_languages_.get())); + EXPECT_CALL(hmi_capabilities_, vr_supported_languages()) + .WillOnce(Return(supported_languages_.get())); + EXPECT_CALL(hmi_capabilities_, tts_supported_languages()) + .WillOnce(Return(supported_languages_.get())); + + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + MessageSharedPtr response_to_mobile; + EXPECT_CALL( + app_mngr_, + ManageMobileCommand(_, am::commands::Command::CommandOrigin::ORIGIN_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + command->Run(); + + EXPECT_EQ( + (*response_to_mobile)[strings::msg_params][strings::success].asBool(), + false); + EXPECT_EQ( + (*response_to_mobile)[strings::msg_params][strings::result_code].asInt(), + static_cast<int32_t>(mobile_apis::Result::UNSUPPORTED_RESOURCE)); } TEST_F(ChangeRegistrationRequestTest, @@ -403,17 +432,17 @@ TEST_F(ChangeRegistrationRequestTest, } TEST_F(ChangeRegistrationRequestTest, - OnEvent_TTS_UNSUPPORTED_RESOURCE_SUCCESS_STATE_AVAILABLE_Expect_false) { + OnEvent_TTS_UNSUPPORTED_RESOURCE_SUCCESS_STATE_AVAILABLE_Expect_true) { CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, mobile_apis::Result::UNSUPPORTED_RESOURCE, am::HmiInterfaces::STATE_AVAILABLE, - false, + true, hmi_apis::Common_Result::SUCCESS, hmi_apis::Common_Result::SUCCESS); } TEST_F(ChangeRegistrationRequestTest, - OnEvent_TTS_SUCCESS_STATE_AVAILABLE_Expect_false) { + OnEvent_TTS_SUCCESS_STATE_AVAILABLE_Expect_true) { CheckExpectations(hmi_apis::Common_Result::SUCCESS, mobile_apis::Result::SUCCESS, am::HmiInterfaces::STATE_AVAILABLE, @@ -425,7 +454,7 @@ TEST_F(ChangeRegistrationRequestTest, TEST_F(ChangeRegistrationRequestTest, OnEvent_TTS_WRONG_LANGUAGE_STATE_AVAILABLE_Expect_true) { CheckExpectations(hmi_apis::Common_Result::WRONG_LANGUAGE, - mobile_apis::Result::SUCCESS, + mobile_apis::Result::WRONG_LANGUAGE, am::HmiInterfaces::STATE_AVAILABLE, true, hmi_apis::Common_Result::SUCCESS, @@ -435,7 +464,7 @@ TEST_F(ChangeRegistrationRequestTest, TEST_F(ChangeRegistrationRequestTest, OnEvent_TTS_INVALID_DATA_STATE_AVAILABLE_Expect_false) { CheckExpectations(hmi_apis::Common_Result::INVALID_DATA, - mobile_apis::Result::SUCCESS, + mobile_apis::Result::INVALID_DATA, am::HmiInterfaces::STATE_AVAILABLE, false, hmi_apis::Common_Result::SUCCESS, @@ -473,14 +502,14 @@ TEST_F(ChangeRegistrationRequestTest, .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); ON_CALL(mock_hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); ON_CALL(mock_hmi_interfaces_, GetInterfaceFromFunction(hmi_apis::FunctionID::VR_ChangeRegistration)) .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); ON_CALL(mock_hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); ON_CALL( mock_hmi_interfaces_, @@ -488,7 +517,7 @@ TEST_F(ChangeRegistrationRequestTest, .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); ON_CALL(mock_hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); command->Run(); diff --git a/src/components/application_manager/test/commands/mobile/create_interaction_choice_set_test.cc b/src/components/application_manager/test/commands/mobile/create_interaction_choice_set_test.cc index a627740588..c3513d2acb 100644 --- a/src/components/application_manager/test/commands/mobile/create_interaction_choice_set_test.cc +++ b/src/components/application_manager/test/commands/mobile/create_interaction_choice_set_test.cc @@ -65,7 +65,6 @@ using am::commands::MessageSharedPtr; using am::ApplicationSharedPtr; using am::MockMessageHelper; using ::testing::_; -using ::testing::Mock; using ::utils::SharedPtr; using ::testing::Return; using ::testing::ReturnRef; @@ -112,15 +111,9 @@ class CreateInteractionChoiceSetRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: CreateInteractionChoiceSetRequestTest() - : message_helper_mock_(*am::MockMessageHelper::message_helper_mock()) - , message_(CreateMessage()) + : message_(CreateMessage()) , command_(CreateCommand<CreateInteractionChoiceSetRequest>(message_)) - , mock_app_(CreateMockApp()) { - Mock::VerifyAndClearExpectations(&message_helper_mock_); - } - ~CreateInteractionChoiceSetRequestTest() { - Mock::VerifyAndClearExpectations(&message_helper_mock_); - } + , mock_app_(CreateMockApp()) {} MessageSharedPtr CreateFullParamsVRSO() { MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); @@ -162,7 +155,6 @@ class CreateInteractionChoiceSetRequestTest [am::strings::interaction_choice_set_id] = kChoiceSetId; } - MockMessageHelper& message_helper_mock_; MessageSharedPtr message_; CreateInteractionChoiceSetRequestPtr command_; MockAppPtr mock_app_; @@ -230,9 +222,6 @@ TEST_F(CreateInteractionChoiceSetRequestTest, OnEvent_VR_UNSUPPORTED_RESOURCE) { ON_CALL(*mock_app_, FindCommand(kCmdId)).WillByDefault(Return(ptr)); EXPECT_EQ(NULL, ptr); - ON_CALL(message_helper_mock_, HMIToMobileResult(_)) - .WillByDefault(Return(mobile_apis::Result::SUCCESS)); - am::CommandsMap commands_map; ON_CALL(*mock_app_, commands_map()) .WillByDefault( @@ -282,7 +271,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, Run_VerifyImageFail_UNSUCCESS) { [am::strings::secondary_image] = kSecondImage; EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); - EXPECT_CALL(message_helper_mock_, VerifyImage(_, _, _)) + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) .WillRepeatedly(Return(mobile_apis::Result::INVALID_DATA)); EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); @@ -298,7 +287,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, Run_FindChoiceSetFail_UNSUCCESS) { kChoiceSetId; EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); - EXPECT_CALL(message_helper_mock_, VerifyImage(_, _, _)) + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); smart_objects::SmartObject* invalid_choice_set_id = @@ -333,7 +322,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); - EXPECT_CALL(message_helper_mock_, VerifyImage(_, _, _)) + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); smart_objects::SmartObject* choice_set_id = NULL; @@ -370,7 +359,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, .WillRepeatedly(Return(choice_set_id)); EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app_)); - EXPECT_CALL(message_helper_mock_, VerifyImage(_, _, _)) + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] @@ -439,7 +428,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, FillMessageFieldsItem2(message_); EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); - EXPECT_CALL(message_helper_mock_, VerifyImage(_, _, _)) + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); smart_objects::SmartObject* choice_set_id = NULL; @@ -478,7 +467,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); - EXPECT_CALL(message_helper_mock_, VerifyImage(_, _, _)) + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); smart_objects::SmartObject* choice_set_id = NULL; @@ -524,7 +513,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, OnEvent_ValidVrNoError_SUCCESS) { EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); - EXPECT_CALL(message_helper_mock_, VerifyImage(_, _, _)) + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); smart_objects::SmartObject* choice_set_id = NULL; @@ -557,7 +546,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, FillMessageFieldsItem2(message_); EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); - EXPECT_CALL(message_helper_mock_, VerifyImage(_, _, _)) + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); smart_objects::SmartObject* choice_set_id = NULL; @@ -591,7 +580,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, kChoiceSetId; ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); - EXPECT_CALL(message_helper_mock_, VerifyImage(_, _, _)) + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); smart_objects::SmartObject* choice_set_id = NULL; @@ -638,7 +627,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); - EXPECT_CALL(message_helper_mock_, VerifyImage(_, _, _)) + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); smart_objects::SmartObject* choice_set_id = NULL; @@ -678,7 +667,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, OnTimeOut_InvalidApp_UNSUCCESS) { EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app_)); - EXPECT_CALL(message_helper_mock_, VerifyImage(_, _, _)) + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); smart_objects::SmartObject* choice_set_id = NULL; @@ -718,7 +707,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = kChoiceSetId; - EXPECT_CALL(message_helper_mock_, VerifyImage(_, _, _)) + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); smart_objects::SmartObject* choice_set_id = NULL; @@ -791,7 +780,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, Run_ErrorFromHmiFalse_UNSUCCESS) { kChoiceSetId; ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); - EXPECT_CALL(message_helper_mock_, VerifyImage(_, _, _)) + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) .WillRepeatedly(Return(mobile_apis::Result::GENERIC_ERROR)); smart_objects::SmartObject* choice_set_id = NULL; diff --git a/src/components/application_manager/test/commands/mobile/delete_command_request_test.cc b/src/components/application_manager/test/commands/mobile/delete_command_request_test.cc index efa889a2c1..c92ec81a1f 100644 --- a/src/components/application_manager/test/commands/mobile/delete_command_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/delete_command_request_test.cc @@ -53,7 +53,6 @@ namespace mobile_commands_test { namespace delete_command_request { using ::testing::_; -using ::testing::Mock; using ::testing::Return; using ::testing::ReturnRef; namespace am = ::application_manager; @@ -61,6 +60,7 @@ using am::commands::DeleteCommandRequest; using am::commands::MessageSharedPtr; using am::event_engine::Event; using am::MockMessageHelper; +using am::MockHmiInterfaces; typedef SharedPtr<DeleteCommandRequest> DeleteCommandPtr; @@ -74,9 +74,7 @@ const uint32_t kConnectionKey = 2u; class DeleteCommandRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: - DeleteCommandRequestTest() - : mock_message_helper_(*MockMessageHelper::message_helper_mock()) - , mock_app_(CreateMockApp()) {} + DeleteCommandRequestTest() : mock_app_(CreateMockApp()) {} MessageSharedPtr CreateFullParamsUISO() { MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; @@ -129,13 +127,11 @@ class DeleteCommandRequestTest ON_CALL(app_mngr_, application(kConnectionKey)) .WillByDefault(Return(mock_app_)); ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(app_mngr_, hmi_interfaces()) + .WillByDefault(ReturnRef(hmi_interfaces_)); } - void TearDown() OVERRIDE { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - - MockMessageHelper& mock_message_helper_; + NiceMock<MockHmiInterfaces> hmi_interfaces_; MockAppPtr mock_app_; }; @@ -154,14 +150,14 @@ TEST_F(DeleteCommandRequestTest, (*test_msg)[am::strings::vr_commands] = 0; (*test_msg)[am::strings::menu_params] = 0; - ON_CALL(mock_hmi_interfaces_, GetInterfaceFromFunction(_)) + ON_CALL(hmi_interfaces_, GetInterfaceFromFunction(_)) .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); - ON_CALL(mock_hmi_interfaces_, + ON_CALL(hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - ON_CALL(mock_hmi_interfaces_, + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + ON_CALL(hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); ON_CALL(*mock_app_, FindCommand(kCommandId)) .WillByDefault(Return(test_msg.get())); ON_CALL(*mock_app_, get_grammar_id()).WillByDefault(Return(kConnectionKey)); @@ -171,7 +167,7 @@ TEST_F(DeleteCommandRequestTest, hmi_apis::Common_Result::SUCCESS; Event event_ui(hmi_apis::FunctionID::UI_DeleteCommand); event_ui.set_smart_object(*msg); - + command->Init(); command->Run(); command->on_event(event_ui); @@ -185,6 +181,8 @@ TEST_F(DeleteCommandRequestTest, EXPECT_CALL(*mock_app_, RemoveCommand(kCommandId)); + EXPECT_CALL(*mock_app_, UpdateHash()); + MessageSharedPtr vr_command_result; EXPECT_CALL( app_mngr_, @@ -212,14 +210,14 @@ TEST_F(DeleteCommandRequestTest, (*test_msg)[am::strings::vr_commands] = 0; (*test_msg)[am::strings::menu_params] = 0; - ON_CALL(mock_hmi_interfaces_, GetInterfaceFromFunction(_)) + ON_CALL(hmi_interfaces_, GetInterfaceFromFunction(_)) .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(mock_hmi_interfaces_, + ON_CALL(hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - ON_CALL(mock_hmi_interfaces_, + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + ON_CALL(hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); ON_CALL(*app, FindCommand(kCommandId)).WillByDefault(Return(test_msg.get())); ON_CALL(*app, get_grammar_id()).WillByDefault(Return(kConnectionKey)); @@ -229,6 +227,7 @@ TEST_F(DeleteCommandRequestTest, Event event_vr(hmi_apis::FunctionID::VR_DeleteCommand); event_vr.set_smart_object(*msg); + command->Init(); command->Run(); command->on_event(event_vr); @@ -242,6 +241,8 @@ TEST_F(DeleteCommandRequestTest, EXPECT_CALL(*app, RemoveCommand(kCommandId)); + EXPECT_CALL(*app, UpdateHash()); + MessageSharedPtr result_msg( CatchMobileCommandResult(CallOnEvent(*command, event_ui))); diff --git a/src/components/application_manager/test/commands/mobile/delete_interaction_choice_set_test.cc b/src/components/application_manager/test/commands/mobile/delete_interaction_choice_set_test.cc index a6d9d8f50a..192cad12b0 100644 --- a/src/components/application_manager/test/commands/mobile/delete_interaction_choice_set_test.cc +++ b/src/components/application_manager/test/commands/mobile/delete_interaction_choice_set_test.cc @@ -53,7 +53,6 @@ namespace mobile_commands_test { namespace delete_interaction_choice_set { using ::testing::_; -using ::testing::Mock; using ::testing::Return; using ::testing::InSequence; diff --git a/src/components/application_manager/test/commands/mobile/delete_sub_menu_test.cc b/src/components/application_manager/test/commands/mobile/delete_sub_menu_test.cc index beff4c3584..cc21e5366e 100644 --- a/src/components/application_manager/test/commands/mobile/delete_sub_menu_test.cc +++ b/src/components/application_manager/test/commands/mobile/delete_sub_menu_test.cc @@ -51,7 +51,6 @@ namespace mobile_commands_test { namespace delete_sub_menu_request { using ::testing::_; -using ::testing::Mock; using ::testing::Return; using ::testing::ReturnRef; using ::testing::InSequence; @@ -97,22 +96,14 @@ class DeleteSubMenuRequestTest public: DeleteSubMenuRequestTest() : accessor_(commands_map_, commands_lock_) - , mock_message_helper_(*MockMessageHelper::message_helper_mock()) , message_(CreateMessage()) , command_(CreateCommand<DeleteSubMenuRequest>(message_)) - , app_(CreateMockApp()) { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - - ~DeleteSubMenuRequestTest() { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } + , app_(CreateMockApp()) {} am::CommandsMap commands_map_; mutable sync_primitives::Lock commands_lock_; DataAccessor<am::CommandsMap> accessor_; - MockMessageHelper& mock_message_helper_; MessageSharedPtr message_; DeleteSubMenuRequestPtr command_; MockAppPtr app_; @@ -149,10 +140,6 @@ TEST_F(DeleteSubMenuRequestTest, DISABLED_OnEvent_UI_UNSUPPORTED_RESOURCE) { GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)) - .WillOnce(Return(mobile_apis::Result::UNSUPPORTED_RESOURCE)); - am::CommandsMap commands_map; smart_objects::SmartObject commands_msg(smart_objects::SmartType_Map); commands_map.insert(std::pair<uint32_t, SmartObject*>(1u, &commands_msg)); @@ -243,9 +230,6 @@ TEST_F(DeleteSubMenuRequestTest, OnEvent_InvalidApp_UNSUCCESS) { (*message_)[am::strings::params][am::hmi_response::code] = hmi_apis::Common_Result::eType::SUCCESS; event.set_smart_object(*message_); - ON_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::eType::SUCCESS)) - .WillByDefault(Return(am::mobile_api::Result::SUCCESS)); MockAppPtr invalid_app; EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); EXPECT_CALL(*app_, RemoveSubMenu(_)).Times(0); @@ -265,8 +249,6 @@ TEST_F(DeleteSubMenuRequestTest, OnEvent_DeleteSubmenu_SUCCESS) { const hmi_apis::Common_Result::eType result_code = hmi_apis::Common_Result::SUCCESS; (*message_)[am::strings::params][am::hmi_response::code] = result_code; - ON_CALL(mock_message_helper_, HMIToMobileResult(result_code)) - .WillByDefault(Return(am::mobile_api::Result::SUCCESS)); event.set_smart_object(*message_); commands_map_.insert( @@ -318,10 +300,6 @@ TEST_F(DeleteSubMenuRequestTest, commands_map_.insert( std::make_pair(0, &((*message_)[am::strings::msg_params]))); - ON_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::SUCCESS)) - .WillByDefault(Return(am::mobile_api::Result::SUCCESS)); - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app_)); EXPECT_CALL(app_mngr_, ManageHMICommand(_)).Times(0); EXPECT_CALL(*app_, commands_map()).Times(2).WillRepeatedly(Return(accessor_)); @@ -345,9 +323,6 @@ TEST_F(DeleteSubMenuRequestTest, commands_map_.insert( std::make_pair(0, &((*message_)[am::strings::msg_params]))); - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillRepeatedly(Return(am::mobile_api::Result::SUCCESS)); - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app_)); EXPECT_CALL(app_mngr_, ManageHMICommand(_)).Times(0); EXPECT_CALL(*app_, commands_map()).Times(2).WillRepeatedly(Return(accessor_)); diff --git a/src/components/application_manager/test/commands/mobile/diagnostic_message_request_test.cc b/src/components/application_manager/test/commands/mobile/diagnostic_message_request_test.cc index 60697446f2..4f46a6f715 100644 --- a/src/components/application_manager/test/commands/mobile/diagnostic_message_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/diagnostic_message_request_test.cc @@ -71,17 +71,7 @@ const uint32_t kDiagnosticMode = 5u; } // namespace class DiagnosticMessageRequestTest - : public CommandRequestTest<CommandsTestMocks::kIsNice> { - public: - DiagnosticMessageRequestTest() - : mock_message_helper_(*am::MockMessageHelper::message_helper_mock()) { - testing::Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - ~DiagnosticMessageRequestTest() { - testing::Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - am::MockMessageHelper& mock_message_helper_; -}; + : public CommandRequestTest<CommandsTestMocks::kIsNice> {}; TEST_F(DiagnosticMessageRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); @@ -181,10 +171,6 @@ TEST_F(DiagnosticMessageRequestTest, OnEvent_SUCCESS) { DiagnosticMessageRequestPtr command( CreateCommand<DiagnosticMessageRequest>()); - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::SUCCESS)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL( app_mngr_, ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); diff --git a/src/components/application_manager/test/commands/mobile/end_audio_pass_thru_request_test.cc b/src/components/application_manager/test/commands/mobile/end_audio_pass_thru_request_test.cc index b8c0ed23f3..6b1d909121 100644 --- a/src/components/application_manager/test/commands/mobile/end_audio_pass_thru_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/end_audio_pass_thru_request_test.cc @@ -53,7 +53,6 @@ namespace end_audio_pass_thru_request { namespace am = ::application_manager; using ::testing::_; -using ::testing::Mock; using ::testing::Return; using ::testing::ReturnRef; using am::commands::MessageSharedPtr; @@ -64,15 +63,11 @@ using am::MockMessageHelper; typedef SharedPtr<EndAudioPassThruRequest> EndAudioPassThruRequestPtr; class EndAudioPassThruRequestTest - : public CommandRequestTest<CommandsTestMocks::kIsNice> { - public: - EndAudioPassThruRequestTest() - : mock_message_helper_(*MockMessageHelper::message_helper_mock()) {} - MockMessageHelper& mock_message_helper_; -}; + : public CommandRequestTest<CommandsTestMocks::kIsNice> {}; TEST_F(EndAudioPassThruRequestTest, OnEvent_UI_UNSUPPORTED_RESOUCRE) { const uint32_t kConnectionKey = 2u; + const uint32_t app_id = kConnectionKey; MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); (*command_msg)[am::strings::params][am::strings::connection_key] = @@ -89,11 +84,7 @@ TEST_F(EndAudioPassThruRequestTest, OnEvent_UI_UNSUPPORTED_RESOUCRE) { Event event(hmi_apis::FunctionID::UI_EndAudioPassThru); event.set_smart_object(*event_msg); - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)) - .WillOnce(Return(mobile_apis::Result::UNSUPPORTED_RESOURCE)); - - EXPECT_CALL(app_mngr_, EndAudioPassThrough()).WillOnce(Return(false)); + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(false)); MessageSharedPtr ui_command_result; EXPECT_CALL( @@ -120,7 +111,6 @@ TEST_F(EndAudioPassThruRequestTest, OnEvent_UI_UNSUPPORTED_RESOUCRE) { .asString() .empty()); } - Mock::VerifyAndClearExpectations(&mock_message_helper_); } } // namespace end_audio_pass_thru_request diff --git a/src/components/application_manager/test/commands/mobile/get_dtcs_request_test.cc b/src/components/application_manager/test/commands/mobile/get_dtcs_request_test.cc index dfa38a758b..106a59803b 100644 --- a/src/components/application_manager/test/commands/mobile/get_dtcs_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/get_dtcs_request_test.cc @@ -69,9 +69,7 @@ typedef SharedPtr<GetDTCsRequest> GetDTCsRequestPtr; class GetDTCsRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: - GetDTCsRequestTest() : CommandRequestTest<CommandsTestMocks::kIsNice>() { - Mock::VerifyAndClearExpectations(message_helper_mock_); - } + GetDTCsRequestTest() : CommandRequestTest<CommandsTestMocks::kIsNice>() {} }; TEST_F(GetDTCsRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { @@ -125,11 +123,7 @@ TEST_F(GetDTCsRequestTest, OnEvent_SUCCESS) { Event event(hmi_apis::FunctionID::VehicleInfo_GetDTCs); event.set_smart_object(*event_msg); - MockMessageHelper& mock_message_helper = - *MockMessageHelper::message_helper_mock(); - ON_CALL(mock_message_helper, HMIToMobileResult(_)) - .WillByDefault(Return(mobile_apis::Result::SUCCESS)); EXPECT_CALL( app_mngr_, ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)); diff --git a/src/components/application_manager/test/commands/mobile/get_vehicle_data_request_test.cc b/src/components/application_manager/test/commands/mobile/get_vehicle_data_request_test.cc index a851a72f8e..52aed6feb8 100644 --- a/src/components/application_manager/test/commands/mobile/get_vehicle_data_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/get_vehicle_data_request_test.cc @@ -70,19 +70,7 @@ const uint32_t kConnectionKey = 2u; } // namespace class GetVehicleDataRequestTest - : public CommandRequestTest<CommandsTestMocks::kIsNice> { - public: - GetVehicleDataRequestTest() - : mock_message_helper_(*am::MockMessageHelper::message_helper_mock()) { - testing::Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - - ~GetVehicleDataRequestTest() { - testing::Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - - am::MockMessageHelper& mock_message_helper_; -}; + : public CommandRequestTest<CommandsTestMocks::kIsNice> {}; class UnwrappedGetVehicleDataRequest : public GetVehicleDataRequest { public: @@ -201,8 +189,8 @@ TEST_F(GetVehicleDataRequestTest, Run_SUCCESS) { CreateCommand<GetVehicleDataRequest>(command_msg)); am::VehicleData vehicle_data; - vehicle_data.insert( - am::VehicleData::value_type(kMsgParamKey, am::VehicleDataType::SPEED)); + vehicle_data.insert(am::VehicleData::value_type( + kMsgParamKey, mobile_apis::VehicleDataType::VEHICLEDATA_SPEED)); EXPECT_CALL(mock_message_helper_, vehicle_data()) .WillOnce(ReturnRef(vehicle_data)); @@ -235,7 +223,7 @@ TEST_F(GetVehicleDataRequestTest, OnEvent_DataNotAvailable_SUCCESS) { const hmi_apis::Common_Result::eType hmi_response_code = hmi_apis::Common_Result::DATA_NOT_AVAILABLE; const mobile_result::eType mobile_response_code = - mobile_result::VEHICLE_DATA_NOT_AVAILABLE; + mobile_result::DATA_NOT_AVAILABLE; MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); (*command_msg)[am::strings::params][am::strings::connection_key] = @@ -251,10 +239,6 @@ TEST_F(GetVehicleDataRequestTest, OnEvent_DataNotAvailable_SUCCESS) { Event event(hmi_apis::FunctionID::VehicleInfo_GetVehicleData); event.set_smart_object(*event_msg); - - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(hmi_response_code)) - .WillOnce(Return(mobile_response_code)); - EXPECT_CALL(app_mngr_, ManageMobileCommand(MobileResultCodeIs(mobile_response_code), _)); diff --git a/src/components/application_manager/test/commands/mobile/get_way_points_request_test.cc b/src/components/application_manager/test/commands/mobile/get_way_points_request_test.cc index d886a2b1bd..979fb0cc83 100644 --- a/src/components/application_manager/test/commands/mobile/get_way_points_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/get_way_points_request_test.cc @@ -53,7 +53,6 @@ namespace get_way_points_request { using namespace mobile_apis::Result; using ::testing::Return; -using ::testing::Mock; using ::testing::_; using application_manager::commands::GetWayPointsRequest; using application_manager::MockMessageHelper; @@ -61,6 +60,7 @@ using application_manager::MockHmiInterfaces; typedef SharedPtr<GetWayPointsRequest> CommandPtr; typedef mobile_apis::Result::eType MobileResult; +typedef hmi_apis::Common_Result::eType HmiResult; namespace { const uint32_t kCorrelationId = 2u; @@ -72,14 +72,7 @@ const std::string kMethodName = "Navigation.GetWayPoints"; class GetWayPointsRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: - GetWayPointsRequestTest() - : message_helper_mock_(*am::MockMessageHelper::message_helper_mock()) { - Mock::VerifyAndClearExpectations(&message_helper_mock_); - } - - ~GetWayPointsRequestTest() { - Mock::VerifyAndClearExpectations(&message_helper_mock_); - } + GetWayPointsRequestTest() : mock_app_(CreateMockApp()) {} void SetUp() OVERRIDE { message_ = utils::MakeShared<SmartObject>(::smart_objects::SmartType_Map); @@ -89,14 +82,9 @@ class GetWayPointsRequestTest command_sptr_ = CreateCommand<application_manager::commands::GetWayPointsRequest>( message_); - mock_app_ = CreateMockApp(); ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); - - ON_CALL(message_helper_mock_, HMIToMobileResult(_)) - .WillByDefault(Return(mobile_apis::Result::SUCCESS)); } - MockMessageHelper& message_helper_mock_; MockAppPtr mock_app_; MessageSharedPtr message_; utils::SharedPtr<application_manager::commands::GetWayPointsRequest> @@ -106,17 +94,10 @@ class GetWayPointsRequestTest class GetWayPointsRequestOnEventTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: - GetWayPointsRequestOnEventTest() - : message_helper_mock_(*am::MockMessageHelper::message_helper_mock()) - , app_(CreateMockApp()) { - Mock::VerifyAndClearExpectations(&message_helper_mock_); - } - ~GetWayPointsRequestOnEventTest() { - Mock::VerifyAndClearExpectations(&message_helper_mock_); - } + GetWayPointsRequestOnEventTest() : app_(CreateMockApp()) {} void CheckOnEventResponse(const std::string& wayPointsParam, - const MobileResult ResultCode, + const HmiResult ResultCode, const bool success) { Event event(Event::EventID::Navigation_GetWayPoints); CommandPtr command(CreateCommand<GetWayPointsRequest>()); @@ -131,17 +112,13 @@ class GetWayPointsRequestOnEventTest event.set_smart_object(*event_msg); - EXPECT_CALL(message_helper_mock_, HMIToMobileResult(_)) - .WillOnce(Return(ResultCode)); - - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app)); + const MobileResult mobile_result = static_cast<MobileResult>(ResultCode); MessageSharedPtr result_msg( CatchMobileCommandResult(CallOnEvent(*command, event))); EXPECT_EQ( - ResultCode, - static_cast<mobile_apis::Result::eType>( + mobile_result, + static_cast<MobileResult>( (*result_msg)[am::strings::msg_params][am::strings::result_code] .asInt())); EXPECT_EQ( @@ -150,7 +127,6 @@ class GetWayPointsRequestOnEventTest } protected: - MockMessageHelper& message_helper_mock_; MockAppPtr app_; MockHmiInterfaces hmi_interfaces_; }; @@ -246,15 +222,15 @@ TEST_F(GetWayPointsRequestOnEventTest, OnEvent_WrongEventId_UNSUCCESS) { } TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_SUCCESS_Case1) { - CheckOnEventResponse("0", SUCCESS, true); + CheckOnEventResponse("0", HmiResult::SUCCESS, true); } TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_SUCCESS_Case2) { - CheckOnEventResponse("", SUCCESS, true); + CheckOnEventResponse("", HmiResult::SUCCESS, true); } TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_SUCCESS_Case3) { - CheckOnEventResponse("test", SUCCESS, true); + CheckOnEventResponse("test", HmiResult::SUCCESS, true); } TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case1) { @@ -265,7 +241,7 @@ TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case1) { GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation)) .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - CheckOnEventResponse(" ", GENERIC_ERROR, false); + CheckOnEventResponse(" ", HmiResult::GENERIC_ERROR, false); } TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case2) { @@ -276,7 +252,7 @@ TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case2) { GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation)) .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - CheckOnEventResponse("test\t", GENERIC_ERROR, false); + CheckOnEventResponse("test\t", HmiResult::GENERIC_ERROR, false); } TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case3) { @@ -287,7 +263,7 @@ TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case3) { GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation)) .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - CheckOnEventResponse("test\n", GENERIC_ERROR, false); + CheckOnEventResponse("test\n", HmiResult::GENERIC_ERROR, false); } TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case4) { @@ -298,7 +274,7 @@ TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case4) { GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation)) .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - CheckOnEventResponse("test\t\n", GENERIC_ERROR, false); + CheckOnEventResponse("test\t\n", HmiResult::GENERIC_ERROR, false); } } // namespace get_way_points_request diff --git a/src/components/application_manager/test/commands/mobile/on_hash_change_notification_test.cc b/src/components/application_manager/test/commands/mobile/on_hash_change_notification_test.cc index 9ef978d756..6d7ccb1fa0 100644 --- a/src/components/application_manager/test/commands/mobile/on_hash_change_notification_test.cc +++ b/src/components/application_manager/test/commands/mobile/on_hash_change_notification_test.cc @@ -56,19 +56,7 @@ using testing::ReturnRef; using testing::_; class OnHashChangeNotificationTest - : public CommandsTest<CommandsTestMocks::kIsNice> { - public: - OnHashChangeNotificationTest() - : message_helper_(*MockMessageHelper::message_helper_mock()) {} - void SetUp() OVERRIDE { - Mock::VerifyAndClearExpectations(&message_helper_); - } - - void TearDown() OVERRIDE { - Mock::VerifyAndClearExpectations(&message_helper_); - } - MockMessageHelper& message_helper_; -}; + : public CommandsTest<CommandsTestMocks::kIsNice> {}; TEST_F(OnHashChangeNotificationTest, Run_ValidApp_SUCCESS) { const uint32_t kConnectionKey = 1u; @@ -83,7 +71,8 @@ TEST_F(OnHashChangeNotificationTest, Run_ValidApp_SUCCESS) { EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app)); EXPECT_CALL(*mock_app, curHash()).WillOnce(ReturnRef(return_string)); - EXPECT_CALL(message_helper_, PrintSmartObject(_)).WillOnce(Return(false)); + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) + .WillOnce(Return(false)); EXPECT_CALL(app_mngr_, SendMessageToMobile(msg, _)); command->Run(); @@ -112,7 +101,7 @@ TEST_F(OnHashChangeNotificationTest, Run_InvalidApp_NoNotification) { EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(MockAppPtr())); EXPECT_CALL(*mock_app, curHash()).Times(0); - EXPECT_CALL(message_helper_, PrintSmartObject(_)).Times(0); + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); EXPECT_CALL(app_mngr_, SendMessageToMobile(msg, _)).Times(0); command->Run(); diff --git a/src/components/application_manager/test/commands/mobile/on_hmi_status_notification_from_mobile_test.cc b/src/components/application_manager/test/commands/mobile/on_hmi_status_notification_from_mobile_test.cc index 34f8a010d8..78875ad164 100644 --- a/src/components/application_manager/test/commands/mobile/on_hmi_status_notification_from_mobile_test.cc +++ b/src/components/application_manager/test/commands/mobile/on_hmi_status_notification_from_mobile_test.cc @@ -235,16 +235,12 @@ TEST_F(OnHMIStatusNotificationFromMobileTest, EXPECT_CALL(*mock_app, is_foreground()).WillOnce(Return(true)); - application_manager::MockMessageHelper& mock_message_helper = - *application_manager::MockMessageHelper::message_helper_mock(); - Mock::VerifyAndClearExpectations(&mock_message_helper); - EXPECT_CALL(mock_message_helper, SendQueryApps(kConnectionKey, _)); + EXPECT_CALL(mock_message_helper_, SendQueryApps(kConnectionKey, _)); command->Run(); ASSERT_EQ(application_manager::MessageType::kNotification, (*msg)[strings::params][strings::message_type].asInt()); - Mock::VerifyAndClearExpectations(&mock_message_helper); } TEST_F(OnHMIStatusNotificationFromMobileTest, diff --git a/src/components/application_manager/test/commands/mobile/on_hmi_status_notification_test.cc b/src/components/application_manager/test/commands/mobile/on_hmi_status_notification_test.cc index 2da0e60df1..acc7395cf3 100644 --- a/src/components/application_manager/test/commands/mobile/on_hmi_status_notification_test.cc +++ b/src/components/application_manager/test/commands/mobile/on_hmi_status_notification_test.cc @@ -59,9 +59,6 @@ using testing::_; class OnHMIStatusNotificationTest : public CommandsTest<CommandsTestMocks::kIsNice> { public: - OnHMIStatusNotificationTest() - : message_helper_(*MockMessageHelper::message_helper_mock()) {} - MessageSharedPtr CreateMsgParams( const mobile_apis::HMILevel::eType kHMIState) { MessageSharedPtr msg = CreateMessage(); @@ -70,13 +67,9 @@ class OnHMIStatusNotificationTest return msg; } - void TearDown() OVERRIDE { - Mock::VerifyAndClearExpectations(&message_helper_); - } - void SetSendNotificationExpectations(MessageSharedPtr& msg) { - Mock::VerifyAndClearExpectations(&message_helper_); - EXPECT_CALL(message_helper_, PrintSmartObject(_)).WillOnce(Return(false)); + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) + .WillOnce(Return(false)); EXPECT_CALL(app_mngr_, SendMessageToMobile(msg, _)); } @@ -88,8 +81,6 @@ class OnHMIStatusNotificationTest ASSERT_EQ(CommandImpl::protocol_version_, (*msg)[strings::params][strings::protocol_version].asInt()); } - - MockMessageHelper& message_helper_; }; TEST_F(OnHMIStatusNotificationTest, Run_InvalidApp_NoNotification) { @@ -128,45 +119,6 @@ TEST_F(OnHMIStatusNotificationTest, Run_InvalidEnum_SUCCESS) { VerifySendNotificationData(msg); } -TEST_F(OnHMIStatusNotificationTest, Run_BackgroundAndFalseProperties_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_BACKGROUND); - SetSendNotificationExpectations(msg); - - SharedPtr<OnHMIStatusNotification> command = - CreateCommand<OnHMIStatusNotification>(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - - EXPECT_CALL(*mock_app, tts_properties_in_none()).WillOnce(Return(false)); - EXPECT_CALL(*mock_app, set_tts_properties_in_none(true)); - EXPECT_CALL(message_helper_, SendTTSGlobalProperties(_, false, _)); - - command->Run(); - - VerifySendNotificationData(msg); -} - -TEST_F(OnHMIStatusNotificationTest, Run_BackgroundAndTrueProperties_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_BACKGROUND); - - SharedPtr<OnHMIStatusNotification> command = - CreateCommand<OnHMIStatusNotification>(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - - EXPECT_CALL(*mock_app, tts_properties_in_none()).WillOnce(Return(true)); - - SetSendNotificationExpectations(msg); - - command->Run(); - - VerifySendNotificationData(msg); -} - TEST_F(OnHMIStatusNotificationTest, Run_FullAndFalseProperties_SUCCESS) { MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); diff --git a/src/components/application_manager/test/commands/mobile/on_keyboard_input_notification_test.cc b/src/components/application_manager/test/commands/mobile/on_keyboard_input_notification_test.cc index d56cd98904..7313f32dca 100644 --- a/src/components/application_manager/test/commands/mobile/on_keyboard_input_notification_test.cc +++ b/src/components/application_manager/test/commands/mobile/on_keyboard_input_notification_test.cc @@ -61,11 +61,9 @@ using testing::_; class OnKeyBoardInputNotificationTest : public CommandsTest<CommandsTestMocks::kIsNice> { public: - OnKeyBoardInputNotificationTest() - : message_helper_(*MockMessageHelper::message_helper_mock()) {} - void SetSendNotificationExpectations(MessageSharedPtr msg) { - EXPECT_CALL(message_helper_, PrintSmartObject(_)).WillOnce(Return(false)); + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) + .WillOnce(Return(false)); EXPECT_CALL(app_mngr_, SendMessageToMobile(msg, _)); } @@ -78,14 +76,6 @@ class OnKeyBoardInputNotificationTest (*msg)[strings::params][strings::protocol_version].asInt()); } - void SetUp() OVERRIDE { - Mock::VerifyAndClearExpectations(&message_helper_); - } - - void TearDown() OVERRIDE { - Mock::VerifyAndClearExpectations(&message_helper_); - } - MockAppPtr InitAppSetDataAccessor(SharedPtr<ApplicationSet>& app_set) { app_set = (!app_set ? ::utils::MakeShared<ApplicationSet>() : app_set); MockAppPtr app(CreateMockApp()); @@ -95,7 +85,6 @@ class OnKeyBoardInputNotificationTest return app; } - MockMessageHelper& message_helper_; SharedPtr<ApplicationSet> app_set_; sync_primitives::Lock lock_; }; @@ -162,7 +151,7 @@ TEST_F(OnKeyBoardInputNotificationTest, Run_InvalidApp_NoNotification) { EXPECT_CALL(*mock_app, hmi_level()) .WillOnce(Return(mobile_apis::HMILevel::eType::HMI_BACKGROUND)); - EXPECT_CALL(message_helper_, PrintSmartObject(_)).Times(0); + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); EXPECT_CALL(app_mngr_, SendMessageToMobile(msg, _)).Times(0); command->Run(); diff --git a/src/components/application_manager/test/commands/mobile/on_system_request_notification_test.cc b/src/components/application_manager/test/commands/mobile/on_system_request_notification_test.cc index 43f725012d..7840e35cec 100644 --- a/src/components/application_manager/test/commands/mobile/on_system_request_notification_test.cc +++ b/src/components/application_manager/test/commands/mobile/on_system_request_notification_test.cc @@ -64,20 +64,7 @@ const uint32_t kConnectionKey = 1u; } // namespace class OnSystemRequestNotificationTest - : public CommandsTest<CommandsTestMocks::kIsNice> { - public: - OnSystemRequestNotificationTest() - : message_helper_(*MockMessageHelper::message_helper_mock()) {} - - void SetUp() OVERRIDE { - Mock::VerifyAndClearExpectations(&message_helper_); - } - - void TearDown() OVERRIDE { - Mock::VerifyAndClearExpectations(&message_helper_); - } - MockMessageHelper& message_helper_; -}; + : public CommandsTest<CommandsTestMocks::kIsNice> {}; TEST_F(OnSystemRequestNotificationTest, Run_ProprietaryType_SUCCESS) { const RequestType::eType kRequestType = RequestType::PROPRIETARY; @@ -107,7 +94,8 @@ TEST_F(OnSystemRequestNotificationTest, Run_ProprietaryType_SUCCESS) { EXPECT_CALL(mock_policy_handler, TimeoutExchangeSec()).WillOnce(Return(5u)); #endif // PROPRIETARY_MODE - EXPECT_CALL(message_helper_, PrintSmartObject(_)).WillOnce(Return(false)); + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) + .WillOnce(Return(false)); EXPECT_CALL(app_mngr_, SendMessageToMobile(msg, _)); command->Run(); @@ -143,7 +131,8 @@ TEST_F(OnSystemRequestNotificationTest, Run_HTTPType_SUCCESS) { EXPECT_CALL(mock_policy_handler, IsRequestTypeAllowed(_, _)) .WillOnce(Return(true)); - EXPECT_CALL(message_helper_, PrintSmartObject(_)).WillOnce(Return(false)); + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) + .WillOnce(Return(false)); EXPECT_CALL(app_mngr_, SendMessageToMobile(msg, _)); command->Run(); @@ -176,7 +165,7 @@ TEST_F(OnSystemRequestNotificationTest, Run_InvalidApp_NoNotification) { MockPolicyHandlerInterface mock_policy_handler; EXPECT_CALL(mock_policy_handler, IsRequestTypeAllowed(_, _)).Times(0); - EXPECT_CALL(message_helper_, PrintSmartObject(_)).Times(0); + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); EXPECT_CALL(app_mngr_, SendMessageToMobile(msg, _)).Times(0); command->Run(); @@ -203,7 +192,7 @@ TEST_F(OnSystemRequestNotificationTest, Run_RequestNotAllowed_NoNotification) { EXPECT_CALL(mock_policy_handler, IsRequestTypeAllowed(_, _)) .WillOnce(Return(false)); - EXPECT_CALL(message_helper_, PrintSmartObject(_)).Times(0); + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); EXPECT_CALL(app_mngr_, SendMessageToMobile(msg, _)).Times(0); ; diff --git a/src/components/application_manager/test/commands/mobile/on_vehicle_data_notification_test.cc b/src/components/application_manager/test/commands/mobile/on_vehicle_data_notification_test.cc index d00e62bcfb..05d97856e4 100644 --- a/src/components/application_manager/test/commands/mobile/on_vehicle_data_notification_test.cc +++ b/src/components/application_manager/test/commands/mobile/on_vehicle_data_notification_test.cc @@ -71,11 +71,9 @@ class OnVehicleDataNotificationTest : public CommandsTest<CommandsTestMocks::kIsNice> { public: OnVehicleDataNotificationTest() - : mock_message_helper_(*am::MockMessageHelper::message_helper_mock()) - , command_msg_(CreateMessage(smart_objects::SmartType_Map)) + : command_msg_(CreateMessage(smart_objects::SmartType_Map)) , command_(CreateCommand<OnVehicleDataNotification>(command_msg_)) {} - am::MockMessageHelper& mock_message_helper_; MessageSharedPtr command_msg_; NotificationPtr command_; }; @@ -113,7 +111,8 @@ TEST_F(OnVehicleDataNotificationTest, Run_NotEmptyListOfAppsSubscribedForEvent_SUCCESS) { am::VehicleData test_vehicle_data; test_vehicle_data.insert(am::VehicleData::value_type( - am::strings::fuel_level, am::VehicleDataType::FUELLEVEL)); + am::strings::fuel_level, + mobile_apis::VehicleDataType::VEHICLEDATA_FUELLEVEL)); EXPECT_CALL(mock_message_helper_, vehicle_data()) .WillOnce(ReturnRef(test_vehicle_data)); @@ -126,9 +125,10 @@ TEST_F(OnVehicleDataNotificationTest, std::vector<ApplicationSharedPtr> applications; applications.push_back(mock_app); - EXPECT_CALL(app_mngr_, - IviInfoUpdated(am::VehicleDataType::FUELLEVEL, kFuelLevel)) - .WillOnce(Return(applications)); + EXPECT_CALL( + app_mngr_, + IviInfoUpdated(mobile_apis::VehicleDataType::VEHICLEDATA_FUELLEVEL, + kFuelLevel)).WillOnce(Return(applications)); EXPECT_CALL(*mock_app, app_id()).WillRepeatedly(Return(kAppId)); ::utils::custom_string::CustomString dummy_name("test_app"); diff --git a/src/components/application_manager/test/commands/mobile/perform_audio_pass_thru_test.cc b/src/components/application_manager/test/commands/mobile/perform_audio_pass_thru_test.cc index e2adc38f50..a27bac970c 100644 --- a/src/components/application_manager/test/commands/mobile/perform_audio_pass_thru_test.cc +++ b/src/components/application_manager/test/commands/mobile/perform_audio_pass_thru_test.cc @@ -57,7 +57,6 @@ using am::commands::MessageSharedPtr; using am::MockMessageHelper; using ::utils::SharedPtr; using ::testing::_; -using ::testing::Mock; using ::testing::Return; using ::testing::ReturnRef; using ::testing::InSequence; @@ -80,8 +79,7 @@ class PerformAudioPassThruRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: PerformAudioPassThruRequestTest() - : mock_message_helper_(*MockMessageHelper::message_helper_mock()) - , mock_app_(CreateMockApp()) + : mock_app_(CreateMockApp()) , message_(utils::MakeShared<SmartObject>(::smart_objects::SmartType_Map)) , msg_params_((*message_)[am::strings::msg_params]) {} @@ -130,6 +128,8 @@ class PerformAudioPassThruRequestTest ON_CALL(app_mngr_, application(kConnectionKey)) .WillByDefault(Return(mock_app_)); ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; command_sptr_ = CreateCommand<am::commands::PerformAudioPassThruRequest>(message_); @@ -137,10 +137,6 @@ class PerformAudioPassThruRequestTest ON_CALL(app_mngr_, application(_)).WillByDefault(Return(application_sptr_)); } - void TearDown() OVERRIDE { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - void ResultCommandExpectations(MessageSharedPtr msg, const std::string& info) { EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), @@ -153,7 +149,6 @@ class PerformAudioPassThruRequestTest } sync_primitives::Lock lock_; - MockMessageHelper& mock_message_helper_; MockAppPtr mock_app_; MessageSharedPtr message_; ::smart_objects::SmartObject& msg_params_; @@ -167,10 +162,15 @@ TEST_F(PerformAudioPassThruRequestTest, OnTimeout_GENERIC_ERROR) { am::mobile_api::Result::GENERIC_ERROR; (*msg_ui)[am::strings::msg_params][am::strings::success] = false; + MessageSharedPtr message = + utils::MakeShared<SmartObject>(::smart_objects::SmartType_Map); + (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey; + utils::SharedPtr<PerformAudioPassThruRequest> command = - CreateCommand<PerformAudioPassThruRequest>(); + CreateCommand<PerformAudioPassThruRequest>(message); - EXPECT_CALL(app_mngr_, EndAudioPassThrough()).WillOnce(Return(true)); + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(true)); EXPECT_CALL(app_mngr_, StopAudioPassThru(_)); EXPECT_CALL( @@ -192,33 +192,33 @@ TEST_F(PerformAudioPassThruRequestTest, OnTimeout_GENERIC_ERROR) { (*vr_command_result)[am::strings::msg_params][am::strings::result_code] .asInt(), static_cast<int32_t>(am::mobile_api::Result::GENERIC_ERROR)); - Mock::VerifyAndClearExpectations(&mock_message_helper_); } TEST_F(PerformAudioPassThruRequestTest, OnEvent_UIHmiSendUnsupportedResource_UNSUPPORTED_RESOURCE) { - MessageSharedPtr msg_ui = CreateFullParamsUISO(); - (*msg_ui)[am::strings::params][am::strings::connection_key] = kConnectionKey; + MessageSharedPtr mobile_request = CreateFullParamsUISO(); + (*mobile_request)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + smart_objects::SmartObject initial_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Array); + initial_prompt[0] = smart_objects::SmartObject(smart_objects::SmartType_Map); + initial_prompt[0][am::strings::text] = "tts chunk text"; + initial_prompt[0][am::strings::type] = 0; + (*mobile_request)[am::strings::msg_params][am::strings::initial_prompt] = + initial_prompt; + EXPECT_CALL(*application_sptr_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); utils::SharedPtr<PerformAudioPassThruRequest> command = - CreateCommand<PerformAudioPassThruRequest>(msg_ui); - - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; - (*msg)[am::strings::msg_params][am::strings::info] = - "UI is not supported by system"; - - am::event_engine::Event event(hmi_apis::FunctionID::UI_PerformAudioPassThru); - event.set_smart_object(*msg); + CreateCommand<PerformAudioPassThruRequest>(mobile_request); ON_CALL(mock_hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); ON_CALL(mock_hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); MessageSharedPtr response_msg_tts = CreateMessage(smart_objects::SmartType_Map); @@ -227,21 +227,40 @@ TEST_F(PerformAudioPassThruRequestTest, (*response_msg_tts)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; am::event_engine::Event event_tts(hmi_apis::FunctionID::TTS_Speak); event_tts.set_smart_object(*response_msg_tts); - ON_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::SUCCESS)) - .WillByDefault(Return(am::mobile_api::Result::SUCCESS)); - command->on_event(event_tts); - MessageSharedPtr ui_command_result; - EXPECT_CALL(app_mngr_, EndAudioPassThrough()).WillOnce(Return(false)); + MessageSharedPtr response_ui = CreateMessage(smart_objects::SmartType_Map); + (*response_ui)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*response_ui)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; + (*response_ui)[am::strings::msg_params][am::strings::info] = + "UI is not supported by system"; + am::event_engine::Event event_ui( + hmi_apis::FunctionID::UI_PerformAudioPassThru); + event_ui.set_smart_object(*response_ui); + + MessageSharedPtr response_to_mobile; + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(false)); + EXPECT_CALL(app_mngr_, ManageHMICommand(_)).WillRepeatedly(Return(true)); EXPECT_CALL( app_mngr_, ManageMobileCommand(_, am::commands::Command::CommandOrigin::ORIGIN_SDL)) - .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); - command->on_event(event); + command->Run(); + command->on_event(event_tts); + command->on_event(event_ui); - ResultCommandExpectations(ui_command_result, "UI is not supported by system"); + EXPECT_EQ((*response_to_mobile)[am::strings::msg_params][am::strings::success] + .asBool(), + false); + EXPECT_EQ( + (*response_to_mobile)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*response_to_mobile)[am::strings::msg_params][am::strings::info] + .asString(), + "UI is not supported by system"); } TEST_F(PerformAudioPassThruRequestTest, @@ -351,7 +370,8 @@ TEST_F(PerformAudioPassThruRequestTest, hmi_apis::Common_Result::GENERIC_ERROR; event.set_smart_object(*message_); - EXPECT_CALL(app_mngr_, EndAudioPassThrough()).WillOnce(Return(false)); + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(false)); ON_CALL(app_mngr_, GetNextHMICorrelationID()) .WillByDefault(Return(kCorrelationId)); @@ -525,7 +545,8 @@ TEST_F( } // Start microphone recording cals - EXPECT_CALL(app_mngr_, BeginAudioPassThrough()); + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, BeginAudioPassThru(app_id)); EXPECT_CALL(app_mngr_, StartAudioPassThruThread(_, _, _, _, _, _)); CallRun caller(*command_sptr_); @@ -546,10 +567,6 @@ TEST_F(PerformAudioPassThruRequestTest, OnEvent_UIPAPT_Rejected) { hmi_apis::Common_Result::REJECTED; event.set_smart_object(*message_); - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::REJECTED)) - .WillOnce(Return(am::mobile_api::Result::REJECTED)); - CallOnEvent caller(*command_sptr_, event); MessageSharedPtr result_message = CatchMobileCommandResult(caller); @@ -574,7 +591,8 @@ TEST_F(PerformAudioPassThruRequestTest, EXPECT_CALL(app_mngr_, ManageHMICommand(_)).WillOnce(Return(true)); // Start microphone recording cals - EXPECT_CALL(app_mngr_, BeginAudioPassThrough()); + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, BeginAudioPassThru(app_id)); EXPECT_CALL(app_mngr_, StartAudioPassThruThread(_, _, _, _, _, _)); EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); @@ -582,15 +600,12 @@ TEST_F(PerformAudioPassThruRequestTest, ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillOnce(Return(am::mobile_api::Result::SUCCESS)); - CallOnEvent caller(*command_sptr_, event); caller(); } TEST_F(PerformAudioPassThruRequestTest, - OnEvent_PAPTunsupportedResource_CorrectInfo) { + DISABLED_OnEvent_PAPTunsupportedResource_CorrectInfo) { const std::string return_info = "Unsupported phoneme type sent in a prompt"; am::event_engine::Event event_speak(hmi_apis::FunctionID::TTS_Speak); @@ -613,7 +628,8 @@ TEST_F(PerformAudioPassThruRequestTest, caller_speak(); // Second call for test correct behavior of UI_PerformAudioPassThru event - EXPECT_CALL(app_mngr_, EndAudioPassThrough()).WillOnce(Return(false)); + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(false)); EXPECT_CALL(app_mngr_, StopAudioPassThru(_)).Times(0); ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); @@ -637,7 +653,8 @@ TEST_F(PerformAudioPassThruRequestTest, EXPECT_CALL(app_mngr_, ManageHMICommand(_)).WillOnce(Return(true)); - EXPECT_CALL(app_mngr_, BeginAudioPassThrough()).WillOnce(Return(true)); + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, BeginAudioPassThru(app_id)).WillOnce(Return(true)); EXPECT_CALL( app_mngr_, @@ -646,8 +663,6 @@ TEST_F(PerformAudioPassThruRequestTest, EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillByDefault(Return(am::mobile_api::Result::SUCCESS)); CallOnEvent caller(*command_sptr_, event); caller(); @@ -662,8 +677,9 @@ TEST_F(PerformAudioPassThruRequestTest, msg_params_[am::strings::connection_key] = kConnectionKey; msg_params_[am::strings::function_id] = kFunctionId; + uint32_t app_id = kConnectionKey; EXPECT_CALL(app_mngr_, ManageHMICommand(_)).WillOnce(Return(true)); - EXPECT_CALL(app_mngr_, BeginAudioPassThrough()).WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, BeginAudioPassThru(app_id)).WillOnce(Return(true)); EXPECT_CALL( app_mngr_, @@ -681,8 +697,9 @@ TEST_F(PerformAudioPassThruRequestTest, TEST_F(PerformAudioPassThruRequestTest, OnEvent_DefaultCase) { am::event_engine::Event event(hmi_apis::FunctionID::INVALID_ENUM); + uint32_t app_id = kConnectionKey; EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); - EXPECT_CALL(app_mngr_, EndAudioPassThrough()).Times(0); + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).Times(0); CallOnEvent caller(*command_sptr_, event); caller(); @@ -701,7 +718,8 @@ TEST_F(PerformAudioPassThruRequestTest, Init_CorrectTimeout) { TEST_F(PerformAudioPassThruRequestTest, onTimeOut_ttsSpeakNotActive_DontSendHMIReqeust) { - EXPECT_CALL(app_mngr_, EndAudioPassThrough()).WillOnce(Return(true)); + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(true)); EXPECT_CALL(app_mngr_, StopAudioPassThru(_)); // For setting current_state_ -> kCompleted @@ -715,7 +733,8 @@ TEST_F(PerformAudioPassThruRequestTest, TEST_F(PerformAudioPassThruRequestTest, DISABLED_onTimeOut_ttsSpeakActive_SendHMIReqeust) { - EXPECT_CALL(app_mngr_, EndAudioPassThrough()).WillOnce(Return(true)); + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(true)); EXPECT_CALL(app_mngr_, StopAudioPassThru(_)); EXPECT_CALL(*application_sptr_, hmi_level()) @@ -771,8 +790,6 @@ TEST_F(PerformAudioPassThruRequestTest, app_mngr_, ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) .WillOnce(Return(false)); - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillOnce(Return(am::mobile_api::Result::SUCCESS)); command_sptr_->onTimeOut(); } diff --git a/src/components/application_manager/test/commands/mobile/perform_interaction_test.cc b/src/components/application_manager/test/commands/mobile/perform_interaction_test.cc index 84a0e0b354..a272234e82 100644 --- a/src/components/application_manager/test/commands/mobile/perform_interaction_test.cc +++ b/src/components/application_manager/test/commands/mobile/perform_interaction_test.cc @@ -63,7 +63,6 @@ using am::commands::MessageSharedPtr; using am::ApplicationSharedPtr; using am::MockMessageHelper; using ::testing::_; -using ::testing::Mock; using ::utils::SharedPtr; using ::testing::Return; using ::testing::ReturnRef; @@ -82,9 +81,7 @@ const uint32_t kConnectionKey = 2u; class PerformInteractionRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: - PerformInteractionRequestTest() - : mock_message_helper_(*MockMessageHelper::message_helper_mock()) - , mock_app_(CreateMockApp()) {} + PerformInteractionRequestTest() : mock_app_(CreateMockApp()) {} void SetUp() OVERRIDE { ON_CALL(app_mngr_, application(kConnectionKey)) @@ -92,10 +89,6 @@ class PerformInteractionRequestTest ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); } - void TearDown() OVERRIDE { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - void ResultCommandExpectations(MessageSharedPtr msg, const std::string& info) { EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), @@ -108,7 +101,6 @@ class PerformInteractionRequestTest } sync_primitives::Lock lock_; - MockMessageHelper& mock_message_helper_; MockAppPtr mock_app_; }; @@ -191,10 +183,10 @@ TEST_F(PerformInteractionRequestTest, EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); MessageSharedPtr response_to_mobile; @@ -222,10 +214,10 @@ TEST_F(PerformInteractionRequestTest, ON_CALL(mock_hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); ON_CALL(mock_hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); MessageSharedPtr response_msg_vr = CreateMessage(smart_objects::SmartType_Map); diff --git a/src/components/application_manager/test/commands/mobile/read_did_request_test.cc b/src/components/application_manager/test/commands/mobile/read_did_request_test.cc index 7e46f6942f..c88f4626f0 100644 --- a/src/components/application_manager/test/commands/mobile/read_did_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/read_did_request_test.cc @@ -90,11 +90,6 @@ TEST_F(ReadDIDRequestTest, OnEvent_SUCCESS) { event.set_smart_object(*event_msg); - am::MockMessageHelper& mock_message_helper( - *am::MockMessageHelper::message_helper_mock()); - EXPECT_CALL(mock_message_helper, HMIToMobileResult(hmi_response_code)) - .WillOnce(Return(mobile_response_code)); - EXPECT_CALL(app_mngr_, ManageMobileCommand(MobileResultCodeIs(mobile_response_code), _)); @@ -102,8 +97,6 @@ TEST_F(ReadDIDRequestTest, OnEvent_SUCCESS) { EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app)); command->on_event(event); - - testing::Mock::VerifyAndClearExpectations(&mock_message_helper); } TEST_F(ReadDIDRequestTest, Run_AppNotRegistered_UNSUCCESS) { diff --git a/src/components/application_manager/test/commands/mobile/register_app_interface_request_test.cc b/src/components/application_manager/test/commands/mobile/register_app_interface_request_test.cc index 844f87d57e..b7a004f199 100644 --- a/src/components/application_manager/test/commands/mobile/register_app_interface_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/register_app_interface_request_test.cc @@ -43,17 +43,19 @@ #include "application_manager/application.h" #include "application_manager/mock_application_manager.h" #include "application_manager/mock_application.h" +#include "application_manager/mock_application_helper.h" #include "interfaces/MOBILE_API.h" #include "application_manager/smart_object_keys.h" #include "application_manager/policies/mock_policy_handler_interface.h" -#include "utils/data_accessor.h" #include "protocol_handler/mock_session_observer.h" #include "connection_handler/mock_connection_handler.h" #include "application_manager/mock_hmi_capabilities.h" #include "application_manager/mock_resume_ctrl.h" #include "application_manager/mock_hmi_interface.h" +#include "utils/data_accessor.h" #include "utils/custom_string.h" #include "utils/lock.h" +#include "utils/macro.h" namespace test { namespace components { @@ -90,11 +92,22 @@ class RegisterAppInterfaceRequestTest RegisterAppInterfaceRequestTest() : msg_(CreateMessage()) , command_(CreateCommand<RegisterAppInterfaceRequest>(msg_)) - , app_name_("test_app_name_") { + , app_name_("test_app_name_") + , mock_application_helper_( + application_manager_test::MockApplicationHelper:: + application_helper_mock()) { InitGetters(); InitLanguage(); } + void SetUp() OVERRIDE { + testing::Mock::VerifyAndClearExpectations(&mock_application_helper_); + } + + void TearDown() OVERRIDE { + testing::Mock::VerifyAndClearExpectations(&mock_application_helper_); + } + void InitBasicMessage() { (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; (*msg_)[am::strings::msg_params][am::strings::app_id] = kAppId; @@ -112,6 +125,7 @@ class RegisterAppInterfaceRequestTest ON_CALL(*mock_app, app_icon_path()).WillByDefault(ReturnRef(kDummyString)); ON_CALL(*mock_app, language()).WillByDefault(ReturnRef(kMobileLanguage)); ON_CALL(*mock_app, ui_language()).WillByDefault(ReturnRef(kMobileLanguage)); + ON_CALL(*mock_app, policy_app_id()).WillByDefault(Return(kAppId)); return mock_app; } @@ -151,6 +165,9 @@ class RegisterAppInterfaceRequestTest .WillByDefault(Return(policy::DeviceConsent::kDeviceAllowed)); ON_CALL(app_mngr_, GetDeviceTransportType(_)) .WillByDefault(Return(hmi_apis::Common_TransportType::WIFI)); + ON_CALL(app_mngr_, IsAppInReconnectMode(_)).WillByDefault(Return(false)); + ON_CALL(app_mngr_, application_by_policy_id(_)) + .WillByDefault(Return(ApplicationSharedPtr())); ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); ON_CALL( @@ -167,6 +184,43 @@ class RegisterAppInterfaceRequestTest .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); } + void SetCommonExpectionsOnSwitchedApplication( + MockAppPtr mock_app, mobile_apis::Result::eType response_result_code) { + EXPECT_CALL(mock_policy_handler_, AddApplication(_, _)).Times(0); + + EXPECT_CALL( + app_mngr_, + ManageMobileCommand(MobileResultCodeIs(response_result_code), _)); + + EXPECT_CALL(app_mngr_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_OnAppRegistered))) + .Times(0); + + EXPECT_CALL(app_mngr_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::Buttons_OnButtonSubscription))) + .Times(0); + + EXPECT_CALL(app_mngr_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_ChangeRegistration))).Times(0); + + EXPECT_CALL(app_mngr_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_ChangeRegistration))).Times(0); + + EXPECT_CALL(app_mngr_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::VR_ChangeRegistration))).Times(0); + + EXPECT_CALL( + app_mngr_, + OnApplicationSwitched( + MockAppPtr::static_pointer_cast<application_manager::Application>( + mock_app))); + } + MessageSharedPtr msg_; SharedPtr<RegisterAppInterfaceRequest> command_; @@ -194,6 +248,7 @@ class RegisterAppInterfaceRequestTest MockConnectionHandler mock_connection_handler_; MockSessionObserver mock_session_observer_; MockHMICapabilities mock_hmi_capabilities_; + application_manager_test::MockApplicationHelper& mock_application_helper_; }; TEST_F(RegisterAppInterfaceRequestTest, Init_SUCCESS) { @@ -353,6 +408,113 @@ TEST_F(RegisterAppInterfaceRequestTest, command_->Run(); } +TEST_F(RegisterAppInterfaceRequestTest, + SwitchApplication_CorrectHash_ExpectNoCleanupSuccess) { + InitBasicMessage(); + + const std::string request_hash_id = "abc123"; + (*msg_)[am::strings::msg_params][am::strings::hash_id] = request_hash_id; + + MockAppPtr mock_app = CreateBasicMockedApp(); + EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId)) + .WillRepeatedly(Return(mock_app)); + + EXPECT_CALL(app_mngr_, IsAppInReconnectMode(kAppId)).WillOnce(Return(true)); + + EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); + + EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).Times(0); + + EXPECT_CALL( + mock_resume_crt_, + CheckApplicationHash( + MockAppPtr::static_pointer_cast<application_manager::Application>( + mock_app), + request_hash_id)).WillOnce(Return(true)); + + EXPECT_CALL(mock_resume_crt_, RemoveApplicationFromSaved(_)).Times(0); + + EXPECT_CALL(mock_application_helper_, RecallApplicationData(_, _)).Times(0); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + + SetCommonExpectionsOnSwitchedApplication(mock_app, + mobile_apis::Result::SUCCESS); + + command_->Run(); +} + +TEST_F(RegisterAppInterfaceRequestTest, + SwitchApplication_WrongHash_ExpectCleanupResumeFailed) { + InitBasicMessage(); + + const std::string request_hash_id = "abc123"; + (*msg_)[am::strings::msg_params][am::strings::hash_id] = request_hash_id; + + MockAppPtr mock_app = CreateBasicMockedApp(); + EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId)) + .WillRepeatedly(Return(mock_app)); + + EXPECT_CALL(app_mngr_, IsAppInReconnectMode(kAppId)).WillOnce(Return(true)); + + EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); + + EXPECT_CALL( + mock_resume_crt_, + CheckApplicationHash( + MockAppPtr::static_pointer_cast<application_manager::Application>( + mock_app), + request_hash_id)).WillOnce(Return(false)); + + EXPECT_CALL( + mock_application_helper_, + RecallApplicationData( + MockAppPtr::static_pointer_cast<application_manager::Application>( + mock_app), + _)); + + EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).Times(0); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + + SetCommonExpectionsOnSwitchedApplication(mock_app, + mobile_apis::Result::RESUME_FAILED); + + command_->Run(); +} + +TEST_F(RegisterAppInterfaceRequestTest, + SwitchApplication_NoHash_ExpectCleanupResumeFailed) { + InitBasicMessage(); + + MockAppPtr mock_app = CreateBasicMockedApp(); + EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId)) + .WillRepeatedly(Return(mock_app)); + + EXPECT_CALL(app_mngr_, IsAppInReconnectMode(kAppId)).WillOnce(Return(true)); + + EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); + + EXPECT_CALL( + mock_application_helper_, + RecallApplicationData( + MockAppPtr::static_pointer_cast<application_manager::Application>( + mock_app), + _)); + + EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).Times(0); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + + SetCommonExpectionsOnSwitchedApplication(mock_app, + mobile_apis::Result::RESUME_FAILED); + + command_->Run(); +} + } // namespace register_app_interface_request } // namespace mobile_commands_test } // namespace commands_test diff --git a/src/components/application_manager/test/commands/mobile/reset_global_properties_test.cc b/src/components/application_manager/test/commands/mobile/reset_global_properties_test.cc index e133ec9119..69fee02262 100644 --- a/src/components/application_manager/test/commands/mobile/reset_global_properties_test.cc +++ b/src/components/application_manager/test/commands/mobile/reset_global_properties_test.cc @@ -58,7 +58,6 @@ namespace mobile_commands_test { namespace reset_global_properties { using ::testing::_; -using ::testing::Mock; using ::testing::Return; using ::testing::ReturnRef; @@ -83,11 +82,7 @@ class ResetGlobalPropertiesRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { protected: ResetGlobalPropertiesRequestTest() - : mock_message_helper_(am::MockMessageHelper::message_helper_mock()) - , msg_(CreateMessage()) - , mock_app_(CreateMockApp()) { - Mock::VerifyAndClearExpectations(mock_message_helper_); - } + : msg_(CreateMessage()), mock_app_(CreateMockApp()) {} void SetUp() OVERRIDE { (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; @@ -102,10 +97,6 @@ class ResetGlobalPropertiesRequestTest .WillByDefault(Return(kCorrelationId)); } - void TearDown() OVERRIDE { - Mock::VerifyAndClearExpectations(mock_message_helper_); - } - am::MockMessageHelper* mock_message_helper_; MessageSharedPtr msg_; MockAppPtr mock_app_; ResetGlobalPropertiesRequestPtr command_; @@ -177,7 +168,7 @@ TEST_F(ResetGlobalPropertiesRequestTest, Run_InvalidVrHelp_UNSUCCESS) { EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); smart_objects::SmartObjectSPtr vr_help; // = NULL; - EXPECT_CALL(*mock_message_helper_, CreateAppVrHelp(_)) + EXPECT_CALL(mock_message_helper_, CreateAppVrHelp(_)) .WillOnce(Return(vr_help)); EXPECT_CALL(app_mngr_, ManageHMICommand(_)).Times(0); @@ -230,7 +221,7 @@ TEST_F(ResetGlobalPropertiesRequestTest, Run_SUCCESS) { smart_objects::SmartObjectSPtr vr_help = ::utils::MakeShared<smart_objects::SmartObject>( smart_objects::SmartType_Map); - EXPECT_CALL(*mock_message_helper_, CreateAppVrHelp(_)) + EXPECT_CALL(mock_message_helper_, CreateAppVrHelp(_)) .WillOnce(Return(vr_help)); smart_objects::SmartObject msg_params = @@ -272,8 +263,6 @@ TEST_F(ResetGlobalPropertiesRequestTest, const hmi_apis::Common_Result::eType result_code = hmi_apis::Common_Result::SUCCESS; (*msg_)[am::strings::params][am::hmi_response::code] = result_code; - ON_CALL(*mock_message_helper_, HMIToMobileResult(result_code)) - .WillByDefault(Return(am::mobile_api::Result::SUCCESS)); (*msg_)[am::strings::msg_params][am::strings::properties][0] = mobile_apis::GlobalProperty::VRHELPTITLE; @@ -285,7 +274,7 @@ TEST_F(ResetGlobalPropertiesRequestTest, smart_objects::SmartObjectSPtr vr_help = ::utils::MakeShared<smart_objects::SmartObject>( smart_objects::SmartType_Map); - EXPECT_CALL(*mock_message_helper_, CreateAppVrHelp(_)) + EXPECT_CALL(mock_message_helper_, CreateAppVrHelp(_)) .WillOnce(Return(vr_help)); command_->Run(); @@ -346,16 +335,6 @@ TEST_F(ResetGlobalPropertiesRequestTest, command_->on_event(event); } -TEST_F(ResetGlobalPropertiesRequestTest, OnEvent_PendingRequest_UNSUCCESS) { - Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); - event.set_smart_object(*msg_); - - EXPECT_CALL(app_mngr_, ManageMobileCommand(_, _)).Times(0); - EXPECT_CALL(*mock_app_, UpdateHash()).Times(0); - - command_->on_event(event); -} - TEST_F(ResetGlobalPropertiesResponseTest, Run_Sendmsg_SUCCESS) { MessageSharedPtr message(CreateMessage()); ResetGlobalPropertiesResponsePtr command( @@ -380,7 +359,7 @@ TEST_F(ResetGlobalPropertiesRequestTest, OnEvent_InvalidApp_NoHashUpdate) { smart_objects::SmartObjectSPtr vr_help = ::utils::MakeShared<smart_objects::SmartObject>( smart_objects::SmartType_Map); - EXPECT_CALL(*mock_message_helper_, CreateAppVrHelp(_)) + EXPECT_CALL(mock_message_helper_, CreateAppVrHelp(_)) .WillOnce(Return(vr_help)); EXPECT_CALL(*mock_app_, UpdateHash()).Times(0); @@ -389,9 +368,6 @@ TEST_F(ResetGlobalPropertiesRequestTest, OnEvent_InvalidApp_NoHashUpdate) { CreateCommand<ResetGlobalPropertiesRequest>(msg_); command->Run(); - EXPECT_CALL(*mock_message_helper_, HMIToMobileResult(_)) - .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(app_mngr_, ManageMobileCommand( MobileResultCodeIs(mobile_apis::Result::eType::SUCCESS), @@ -402,6 +378,186 @@ TEST_F(ResetGlobalPropertiesRequestTest, OnEvent_InvalidApp_NoHashUpdate) { command->on_event(event); } +TEST_F(ResetGlobalPropertiesRequestTest, + Run_WaitTTS_Timeout_GENERIC_ERROR_TTSNotRespond) { + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::UNSUPPORTED_RESOURCE; + + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::TIMEOUTPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][1] = + mobile_apis::GlobalProperty::MENUICON; + + std::vector<std::string> time_out_prompt; + time_out_prompt.push_back("time_out"); + EXPECT_CALL(app_mngr_settings_, time_out_promt()) + .WillOnce(ReturnRef(time_out_prompt)); + + EXPECT_CALL(*mock_app_, set_timeout_prompt(_)); + + smart_objects::SmartObjectSPtr prompt = + utils::MakeShared<smart_objects::SmartObject>(); + *prompt = "prompt"; + + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(prompt.get())); + + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + + EXPECT_CALL(app_mngr_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_SetGlobalProperties))) + .WillOnce(Return(true)); + + ResetGlobalPropertiesRequestPtr command = + CreateCommand<ResetGlobalPropertiesRequest>(msg_); + command->Run(); + + // Received response only from UI + MessageSharedPtr ui_msg = CreateMessage(); + (*ui_msg)[am::strings::params][am::strings::correlation_id] = kCorrelationId; + (*ui_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + (*ui_msg)[am::strings::msg_params] = + SmartObject(smart_objects::SmartType_Map); + Event ui_event(hmi_apis::FunctionID::UI_SetGlobalProperties); + ui_event.set_smart_object(*ui_msg); + command->on_event(ui_event); + + // TTS doesn't respond, so timeout should send generic error + smart_objects::SmartObjectSPtr response = + utils::MakeShared<smart_objects::SmartObject>(); + (*response)[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::GENERIC_ERROR; + EXPECT_CALL(mock_message_helper_, CreateNegativeResponse(_, _, _, _)) + .WillOnce(Return(response)); + const std::string info = "TTS component does not respond"; + EXPECT_CALL( + app_mngr_, + ManageMobileCommand( + MobileResponseIs(mobile_apis::Result::GENERIC_ERROR, info, false), + am::commands::Command::ORIGIN_SDL)); + command->onTimeOut(); +} + +TEST_F(ResetGlobalPropertiesRequestTest, + Run_WaitUI_Timeout_GENERIC_ERROR_UINotRespond) { + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::UNSUPPORTED_RESOURCE; + + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::TIMEOUTPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][1] = + mobile_apis::GlobalProperty::MENUICON; + + std::vector<std::string> time_out_prompt; + time_out_prompt.push_back("time_out"); + EXPECT_CALL(app_mngr_settings_, time_out_promt()) + .WillOnce(ReturnRef(time_out_prompt)); + + EXPECT_CALL(*mock_app_, set_timeout_prompt(_)); + + smart_objects::SmartObjectSPtr prompt = + utils::MakeShared<smart_objects::SmartObject>(); + *prompt = "prompt"; + + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(prompt.get())); + + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + + EXPECT_CALL(app_mngr_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_SetGlobalProperties))) + .WillOnce(Return(true)); + + command_->Run(); + + // Received response only from TTS + MessageSharedPtr tts_msg = CreateMessage(); + (*tts_msg)[am::strings::params][am::strings::correlation_id] = kCorrelationId; + (*tts_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + + Event tts_event(hmi_apis::FunctionID::TTS_SetGlobalProperties); + tts_event.set_smart_object(*tts_msg); + command_->on_event(tts_event); + + // UI doesn't respond, so timeout should send generic error + smart_objects::SmartObjectSPtr response = + utils::MakeShared<smart_objects::SmartObject>(); + (*response)[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::GENERIC_ERROR; + EXPECT_CALL(mock_message_helper_, CreateNegativeResponse(_, _, _, _)) + .WillOnce(Return(response)); + + const std::string info = "UI component does not respond"; + EXPECT_CALL( + app_mngr_, + ManageMobileCommand( + MobileResponseIs(mobile_apis::Result::GENERIC_ERROR, info, false), + am::commands::Command::ORIGIN_SDL)); + command_->onTimeOut(); +} + +TEST_F(ResetGlobalPropertiesRequestTest, + Run_WaitUIAndTTS_Timeout_GENERIC_ERROR_TTSAndUINotRespond) { + Event event(hmi_apis::FunctionID::TTS_SetGlobalProperties); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::UNSUPPORTED_RESOURCE; + + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::TIMEOUTPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][1] = + mobile_apis::GlobalProperty::MENUICON; + + std::vector<std::string> time_out_prompt; + time_out_prompt.push_back("time_out"); + EXPECT_CALL(app_mngr_settings_, time_out_promt()) + .WillOnce(ReturnRef(time_out_prompt)); + + EXPECT_CALL(*mock_app_, set_timeout_prompt(_)); + + smart_objects::SmartObjectSPtr prompt = + utils::MakeShared<smart_objects::SmartObject>(); + *prompt = "prompt"; + + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(prompt.get())); + + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + + EXPECT_CALL(app_mngr_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_SetGlobalProperties))) + .WillOnce(Return(true)); + + command_->Run(); + // TTS and UI don't respond, so timeout should send generic error + std::string info = "TTS, UI component does not respond"; + smart_objects::SmartObjectSPtr response = + utils::MakeShared<smart_objects::SmartObject>(); + (*response)[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::GENERIC_ERROR; + EXPECT_CALL(mock_message_helper_, CreateNegativeResponse(_, _, _, _)) + .WillOnce(Return(response)); + EXPECT_CALL( + app_mngr_, + ManageMobileCommand( + MobileResponseIs(mobile_apis::Result::GENERIC_ERROR, info, false), + am::commands::Command::ORIGIN_SDL)); + command_->onTimeOut(); +} + } // namespace reset_global_properties } // namespace mobile_commands_test } // namespace commands_test diff --git a/src/components/application_manager/test/commands/mobile/scrollable_message_test.cc b/src/components/application_manager/test/commands/mobile/scrollable_message_test.cc index d9fac769e5..4520e1b120 100644 --- a/src/components/application_manager/test/commands/mobile/scrollable_message_test.cc +++ b/src/components/application_manager/test/commands/mobile/scrollable_message_test.cc @@ -65,7 +65,6 @@ using ::utils::SharedPtr; using ::testing::_; using ::testing::Eq; using ::testing::Ref; -using ::testing::Mock; using ::testing::Return; using ::testing::ReturnRef; @@ -84,9 +83,6 @@ const uint32_t kFunctionID = 3u; class ScrollableMessageRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: - ScrollableMessageRequestTest() - : mock_message_helper_(*MockMessageHelper::message_helper_mock()) {} - MockMessageHelper& mock_message_helper_; typedef TypeIf<kMocksAreNice, NiceMock<application_manager_test::MockHMICapabilities>, application_manager_test::MockHMICapabilities>::Result @@ -118,11 +114,6 @@ class ScrollableMessageRequestTest ON_CALL(app_mngr_, GetPolicyHandler()) .WillByDefault(ReturnRef(mock_policy_handler_)); command_ = CreateCommand<ScrollableMessageRequest>(msg_); - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - - void TearDown() OVERRIDE { - Mock::VerifyAndClearExpectations(&mock_message_helper_); } MockPolicyHandlerInterface mock_policy_handler_; @@ -159,10 +150,6 @@ TEST_F(ScrollableMessageRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { Event event(hmi_apis::FunctionID::UI_ScrollableMessage); event.set_smart_object(*msg); - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)) - .WillOnce(Return(mobile_apis::Result::UNSUPPORTED_RESOURCE)); - MessageSharedPtr ui_command_result; EXPECT_CALL( app_mngr_, @@ -185,7 +172,6 @@ TEST_F(ScrollableMessageRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { .asString() .empty()); } - Mock::VerifyAndClearExpectations(&mock_message_helper_); } TEST_F(ScrollableMessageRequestTest, Init_CorrectTimeout_SUCCESS) { @@ -274,8 +260,6 @@ TEST_F(ScrollableMessageRequestTest, DISABLED_OnEvent_ReceivedUIScrollableMessage_SUCCESS) { (*msg_)[params][hmi_response::code] = hmi_apis::Common_Result::SUCCESS; - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); EXPECT_CALL( app_mngr_, ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)); @@ -289,9 +273,6 @@ TEST_F(ScrollableMessageRequestTest, (*msg_)[params][hmi_response::code] = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillOnce(Return(mobile_apis::Result::UNSUPPORTED_RESOURCE)); - EXPECT_CALL( app_mngr_, ManageMobileCommand( diff --git a/src/components/application_manager/test/commands/mobile/send_location_request_test.cc b/src/components/application_manager/test/commands/mobile/send_location_request_test.cc index 03cc715188..c5786675d6 100644 --- a/src/components/application_manager/test/commands/mobile/send_location_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/send_location_request_test.cc @@ -54,7 +54,6 @@ using utils::SharedPtr; using testing::_; using testing::Return; using testing::ReturnRef; -using ::testing::Mock; namespace strings = application_manager::strings; namespace hmi_response = application_manager::hmi_response; @@ -92,18 +91,13 @@ class SendLocationRequestTest typedef SharedPtr<UnwrappedSendLocationRequest> CommandSPrt; - SendLocationRequestTest() - : mock_message_helper_(*MockMessageHelper::message_helper_mock()) { + SendLocationRequestTest() { mock_app_ = CreateMockApp(); disp_cap_ = utils::MakeShared<SmartObject>(smart_objects::SmartType_Map); message_ = CreateMessage(); command_ = CreateCommand<UnwrappedSendLocationRequest>(message_); } - void TearDown() OVERRIDE { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - void InitialSetup(MessageSharedPtr message_) { (*message_)[strings::params][strings::connection_key] = kConnectionKey; (*message_)[strings::params][strings::function_id] = kFunctionID; @@ -158,7 +152,6 @@ class SendLocationRequestTest MockAppPtr mock_app_; MockHMICapabilities mock_hmi_capabilities_; - MockMessageHelper& mock_message_helper_; SharedPtr<SmartObject> disp_cap_; MessageSharedPtr message_; CommandSPrt command_; @@ -356,10 +349,6 @@ TEST_F(SendLocationRequestTest, OnEvent_Success) { Event event(hmi_apis::FunctionID::Navigation_SendLocation); event.set_smart_object(*message_); - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::SUCCESS)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - MockAppPtr app(CreateMockApp()); EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillRepeatedly(Return(app)); diff --git a/src/components/application_manager/test/commands/mobile/set_app_icon_test.cc b/src/components/application_manager/test/commands/mobile/set_app_icon_test.cc index 60b01f2cfa..b278479df8 100644 --- a/src/components/application_manager/test/commands/mobile/set_app_icon_test.cc +++ b/src/components/application_manager/test/commands/mobile/set_app_icon_test.cc @@ -57,7 +57,6 @@ using am::commands::MessageSharedPtr; using am::MockMessageHelper; using ::utils::SharedPtr; using ::testing::_; -using ::testing::Mock; using ::testing::Return; using ::testing::ReturnRef; @@ -70,19 +69,6 @@ const uint32_t kConnectionKey = 2u; class SetAppIconRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: - SetAppIconRequestTest() - : mock_message_helper_(*MockMessageHelper::message_helper_mock()) {} - - void SetUp() OVERRIDE { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - - void TearDown() OVERRIDE { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - - MockMessageHelper& mock_message_helper_; - MessageSharedPtr CreateFullParamsUISO() { MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; @@ -134,10 +120,6 @@ TEST_F(SetAppIconRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { Event event(hmi_apis::FunctionID::UI_SetAppIcon); event.set_smart_object(*msg); - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)) - .WillOnce(Return(mobile_apis::Result::UNSUPPORTED_RESOURCE)); - MessageSharedPtr ui_command_result; EXPECT_CALL( app_mngr_, diff --git a/src/components/application_manager/test/commands/mobile/set_display_layout_test.cc b/src/components/application_manager/test/commands/mobile/set_display_layout_test.cc index 68aa76010f..8444b88d63 100644 --- a/src/components/application_manager/test/commands/mobile/set_display_layout_test.cc +++ b/src/components/application_manager/test/commands/mobile/set_display_layout_test.cc @@ -59,7 +59,6 @@ using am::commands::MessageSharedPtr; using am::MockMessageHelper; using ::utils::SharedPtr; using ::testing::_; -using ::testing::Mock; using ::testing::Return; using ::testing::ReturnRef; @@ -80,20 +79,12 @@ MATCHER_P(CheckMshCorrId, corr_id, "") { class SetDisplayLayoutRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: - SetDisplayLayoutRequestTest() - : mock_message_helper_(*MockMessageHelper::message_helper_mock()) - , mock_app_(CreateMockApp()) { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - + SetDisplayLayoutRequestTest() : mock_app_(CreateMockApp()) { ON_CALL(app_mngr_, application(kConnectionKey)) .WillByDefault(Return(mock_app_)); ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); } - ~SetDisplayLayoutRequestTest() { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - MessageSharedPtr CreateFullParamsUISO() { MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; @@ -130,7 +121,6 @@ class SetDisplayLayoutRequestTest } sync_primitives::Lock lock_; - MockMessageHelper& mock_message_helper_; MockAppPtr mock_app_; }; @@ -164,9 +154,6 @@ TEST_F(SetDisplayLayoutRequestTest, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - ON_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)) - .WillByDefault(Return(mobile_apis::Result::UNSUPPORTED_RESOURCE)); MessageSharedPtr ui_command_result; EXPECT_CALL( app_mngr_, @@ -245,17 +232,12 @@ TEST_F(SetDisplayLayoutRequestTest, OnEvent_SUCCESS) { (*dispaly_capabilities_msg)[am::hmi_response::templates_available] = "templates_available"; - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(app_mngr_, hmi_capabilities()) .WillOnce(ReturnRef(hmi_capabilities)); EXPECT_CALL(hmi_capabilities, display_capabilities()) .WillOnce(Return(dispaly_capabilities_msg.get())); - ON_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::eType::SUCCESS)) - .WillByDefault(Return(am::mobile_api::Result::SUCCESS)); + EXPECT_CALL( app_mngr_, ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), diff --git a/src/components/application_manager/test/commands/mobile/set_global_properties_test.cc b/src/components/application_manager/test/commands/mobile/set_global_properties_test.cc index 7143bdf71a..a406e65bd2 100644 --- a/src/components/application_manager/test/commands/mobile/set_global_properties_test.cc +++ b/src/components/application_manager/test/commands/mobile/set_global_properties_test.cc @@ -39,6 +39,7 @@ #include "gtest/gtest.h" #include "application_manager/commands/command_request_test.h" #include "application_manager/mock_application.h" +#include "application_manager/mock_help_prompt_manager.h" #include "application_manager/mock_application_manager.h" #include "application_manager/mock_message_helper.h" #include "application_manager/event_engine/event.h" @@ -59,7 +60,6 @@ using am::CommandsMap; using utils::custom_string::CustomString; using ::utils::SharedPtr; using ::testing::_; -using ::testing::Mock; using ::testing::Return; using ::testing::ReturnRef; @@ -75,9 +75,11 @@ const uint32_t kPosition = 1u; class SetGlobalPropertiesRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: - SetGlobalPropertiesRequestTest() - : mock_message_helper_(*MockMessageHelper::message_helper_mock()) - , mock_app_(CreateMockApp()) {} + SetGlobalPropertiesRequestTest() : mock_app_(CreateMockApp()) { + mock_help_prompt_manager_ = + utils::SharedPtr<application_manager_test::MockHelpPromptManager>( + new application_manager_test::MockHelpPromptManager()); + } MessageSharedPtr CreateFullParamsUISO() { MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); @@ -118,6 +120,8 @@ class SetGlobalPropertiesRequestTest vr_help_array[0][am::strings::text] = kText; vr_help_array[0][am::strings::position] = kPosition; (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help_array; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); } void OnEventUISetupHelper(MessageSharedPtr msg, @@ -139,6 +143,9 @@ class SetGlobalPropertiesRequestTest EXPECT_CALL(*mock_app_, set_keyboard_props(_)).Times(0); EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillRepeatedly(ReturnRef(*mock_help_prompt_manager_.get())); + command->Run(); } @@ -152,17 +159,20 @@ class SetGlobalPropertiesRequestTest (*msg)[am::strings::msg_params][am::strings::timeout_prompt] = timeout_prompt; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - SmartObject vr_help_title("title"); - EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); EXPECT_CALL(*mock_app_, set_help_prompt(help_prompt)); EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(&help_prompt)); EXPECT_CALL(*mock_app_, set_timeout_prompt(timeout_prompt)); EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(&timeout_prompt)); EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillRepeatedly(ReturnRef(*mock_help_prompt_manager_.get())); + command->Run(); } @@ -216,10 +226,6 @@ class SetGlobalPropertiesRequestTest .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); } - void TearDown() OVERRIDE { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - void ResultCommandExpectations(MessageSharedPtr msg, const std::string& info) { EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), @@ -242,14 +248,15 @@ class SetGlobalPropertiesRequestTest .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); ON_CALL(mock_hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); ON_CALL(mock_hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); } sync_primitives::Lock lock_; - MockMessageHelper& mock_message_helper_; MockAppPtr mock_app_; + utils::SharedPtr<application_manager_test::MockHelpPromptManager> + mock_help_prompt_manager_; }; TEST_F(SetGlobalPropertiesRequestTest, @@ -292,6 +299,9 @@ TEST_F(SetGlobalPropertiesRequestTest, ON_CALL(mock_message_helper_, VerifyImage(_, _, _)) .WillByDefault(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillRepeatedly(ReturnRef(*mock_help_prompt_manager_.get())); + (*msg_vr)[am::strings::params][am::hmi_response::code] = hmi_apis::Common_Result::SUCCESS; Event event_vr(hmi_apis::FunctionID::TTS_SetGlobalProperties); @@ -323,6 +333,12 @@ TEST_F(SetGlobalPropertiesRequestTest, OnEvent_SUCCESS_Expect_MessageNotSend) { utils::SharedPtr<SetGlobalPropertiesRequest> command = CreateCommand<SetGlobalPropertiesRequest>(response); + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + + EXPECT_CALL(*mock_app, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); + EXPECT_CALL( app_mngr_, ManageMobileCommand(_, am::commands::Command::CommandOrigin::ORIGIN_SDL)) @@ -348,12 +364,12 @@ TEST_F(SetGlobalPropertiesRequestTest, utils::SharedPtr<SetGlobalPropertiesRequest> command = CreateCommand<SetGlobalPropertiesRequest>(response); - ON_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillByDefault(Return(mobile_apis::Result::UNSUPPORTED_RESOURCE)); - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillRepeatedly(ReturnRef(*mock_help_prompt_manager_.get())); + MessageSharedPtr response_to_mobile; EXPECT_CALL( app_mngr_, @@ -428,6 +444,9 @@ TEST_F(SetGlobalPropertiesRequestTest, Run_VRWithMenuAndKeyboard_SUCCESS) { GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); + SharedPtr<SetGlobalPropertiesRequest> command( CreateCommand<SetGlobalPropertiesRequest>(msg)); @@ -573,8 +592,6 @@ TEST_F(SetGlobalPropertiesRequestTest, Run_NoVR_SUCCESS) { .WillOnce(Return(mock_app_)); EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - SmartObject vr_help_title("Menu_Title"); - EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); EXPECT_CALL(*mock_app_, set_menu_title(menu_title)); EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); EXPECT_CALL(*mock_app_, set_keyboard_props(keyboard_properties)); @@ -594,38 +611,6 @@ TEST_F(SetGlobalPropertiesRequestTest, Run_NoVR_SUCCESS) { command->Run(); } -TEST_F(SetGlobalPropertiesRequestTest, Run_VRCouldNotGenerate_INVALID_DATA) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject keyboard_properties(smart_objects::SmartType_Map); - (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = - keyboard_properties; - SmartObject menu_title("Menu_Title"); - (*msg)[am::strings::msg_params][am::hmi_request::menu_title] = menu_title; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - SmartObject* vr_help_title = NULL; - CommandsMap commands_map; - SmartObject empty_msg(smart_objects::SmartType_Map); - commands_map.insert(std::pair<uint32_t, SmartObject*>(1u, &empty_msg)); - DataAccessor<CommandsMap> accessor(commands_map, lock_); - EXPECT_CALL(*mock_app_, commands_map()).WillOnce(Return(accessor)); - EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(vr_help_title)); - EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); - - SharedPtr<SetGlobalPropertiesRequest> command( - CreateCommand<SetGlobalPropertiesRequest>(msg)); - - EXPECT_CALL( - app_mngr_, - ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), - am::commands::Command::ORIGIN_SDL)); - - command->Run(); -} - TEST_F(SetGlobalPropertiesRequestTest, Run_NoVRNoDataNoDefault_Canceled) { MessageSharedPtr msg = CreateMsgParams(); SmartObject keyboard_properties(smart_objects::SmartType_Map); @@ -636,17 +621,6 @@ TEST_F(SetGlobalPropertiesRequestTest, Run_NoVRNoDataNoDefault_Canceled) { .WillOnce(Return(mock_app_)); EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - SmartObject vr_help_title(smart_objects::SmartType_Null); - EXPECT_CALL(*mock_app_, vr_help_title()) - .WillOnce(Return(&vr_help_title)) - .WillOnce(Return(&vr_help_title)); - - CommandsMap commands_map; - DataAccessor<CommandsMap> accessor(commands_map, lock_); - EXPECT_CALL(*mock_app_, commands_map()).WillOnce(Return(accessor)); - const CustomString name("name"); - EXPECT_CALL(*mock_app_, name()).WillOnce(ReturnRef(name)); - EXPECT_CALL(*mock_app_, set_vr_help_title(SmartObject(name))); EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); EXPECT_CALL(*mock_app_, set_keyboard_props(_)); @@ -676,23 +650,6 @@ TEST_F(SetGlobalPropertiesRequestTest, Run_NoVRNoDataDefaultCreated_SUCCESS) { .WillOnce(Return(mock_app_)); EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - SmartObject vr_help_title(smart_objects::SmartType_Null); - EXPECT_CALL(*mock_app_, vr_help_title()) - .Times(2) - .WillRepeatedly(Return(&vr_help_title)); - - CommandsMap commands_map; - SmartObject command_text(smart_objects::SmartType_Map); - commands_map[0] = &command_text; - (*commands_map[0])[am::strings::vr_commands] = SmartObject("one"); - DataAccessor<CommandsMap> accessor(commands_map, lock_); - EXPECT_CALL(*mock_app_, commands_map()).WillOnce(Return(accessor)); - EXPECT_CALL(*mock_app_, set_vr_help(_)); - const CustomString name("name"); - EXPECT_CALL(*mock_app_, name()).WillOnce(ReturnRef(name)); - EXPECT_CALL(*mock_app_, set_vr_help_title(SmartObject(name))); - SmartObject vr_help_array(smart_objects::SmartType_Array); - EXPECT_CALL(*mock_app_, vr_help()).WillOnce(Return(&vr_help_array)); EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); EXPECT_CALL(*mock_app_, set_keyboard_props(keyboard_properties)); @@ -711,50 +668,6 @@ TEST_F(SetGlobalPropertiesRequestTest, Run_NoVRNoDataDefaultCreated_SUCCESS) { command->Run(); } -TEST_F(SetGlobalPropertiesRequestTest, Run_NoVRNoDataFromSynonyms_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject keyboard_properties(smart_objects::SmartType_Map); - (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = - keyboard_properties; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - SmartObject vr_help_title(smart_objects::SmartType_Null); - EXPECT_CALL(*mock_app_, vr_help_title()) - .Times(2) - .WillRepeatedly(Return(&vr_help_title)); - - CommandsMap commands_map; - DataAccessor<CommandsMap> accessor(commands_map, lock_); - EXPECT_CALL(*mock_app_, commands_map()).WillOnce(Return(accessor)); - SmartObject vr_help_array(smart_objects::SmartType_Array); - vr_help_array[0] = SmartObject(smart_objects::SmartType_Map); - vr_help_array[0][am::strings::text] = kText; - vr_help_array[0][am::strings::position] = kPosition; - SmartObject vr_synonyms(smart_objects::SmartType_Array); - vr_synonyms[0] = vr_help_array; - const CustomString name("name"); - EXPECT_CALL(*mock_app_, name()).WillOnce(ReturnRef(name)); - EXPECT_CALL(*mock_app_, set_vr_help_title(SmartObject(name))); - EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); - EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); - EXPECT_CALL(*mock_app_, set_keyboard_props(keyboard_properties)); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - EXPECT_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) - .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - SharedPtr<SetGlobalPropertiesRequest> command( - CreateCommand<SetGlobalPropertiesRequest>(msg)); - - command->Run(); -} - TEST_F(SetGlobalPropertiesRequestTest, Run_TTSHelpAndTimeout_SUCCESS) { MessageSharedPtr msg = CreateMsgParams(); SmartObject help_prompt(smart_objects::SmartType_Array); @@ -768,8 +681,6 @@ TEST_F(SetGlobalPropertiesRequestTest, Run_TTSHelpAndTimeout_SUCCESS) { .WillOnce(Return(mock_app_)); EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - SmartObject vr_help_title("title"); - EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); EXPECT_CALL(*mock_app_, set_help_prompt(help_prompt)); EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(&help_prompt)); EXPECT_CALL(*mock_app_, set_timeout_prompt(timeout_prompt)); @@ -784,6 +695,9 @@ TEST_F(SetGlobalPropertiesRequestTest, Run_TTSHelpAndTimeout_SUCCESS) { GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); + SharedPtr<SetGlobalPropertiesRequest> command( CreateCommand<SetGlobalPropertiesRequest>(msg)); @@ -800,8 +714,6 @@ TEST_F(SetGlobalPropertiesRequestTest, Run_TTSOnlyHelp_SUCCESS) { .WillOnce(Return(mock_app_)); EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - SmartObject vr_help_title("title"); - EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); EXPECT_CALL(*mock_app_, set_help_prompt(help_prompt)); EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(&help_prompt)); EXPECT_CALL(*mock_app_, set_timeout_prompt(_)).Times(0); @@ -814,6 +726,8 @@ TEST_F(SetGlobalPropertiesRequestTest, Run_TTSOnlyHelp_SUCCESS) { ON_CALL(mock_hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); SharedPtr<SetGlobalPropertiesRequest> command( CreateCommand<SetGlobalPropertiesRequest>(msg)); @@ -830,8 +744,6 @@ TEST_F(SetGlobalPropertiesRequestTest, Run_TTSOnlyTimeout_SUCCESS) { .WillOnce(Return(mock_app_)); EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - SmartObject vr_help_title("title"); - EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); EXPECT_CALL(*mock_app_, set_help_prompt(_)).Times(0); EXPECT_CALL(*mock_app_, help_prompt()).Times(0); EXPECT_CALL(*mock_app_, set_timeout_prompt(timeout_prompt)); @@ -844,6 +756,8 @@ TEST_F(SetGlobalPropertiesRequestTest, Run_TTSOnlyTimeout_SUCCESS) { ON_CALL(mock_hmi_interfaces_, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); SharedPtr<SetGlobalPropertiesRequest> command( CreateCommand<SetGlobalPropertiesRequest>(msg)); @@ -1032,11 +946,12 @@ TEST_F(SetGlobalPropertiesRequestTest, OnEvent_PendingRequest_UNSUCCESS) { SharedPtr<SetGlobalPropertiesRequest> command( CreateCommand<SetGlobalPropertiesRequest>(msg)); - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(_)).Times(0); - Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); event.set_smart_object(*msg); + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); + command->on_event(event); } @@ -1061,8 +976,8 @@ TEST_F(SetGlobalPropertiesRequestTest, OnEvent_UIAndSuccessResultCode_SUCCESS) { Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); event.set_smart_object(*msg); - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); @@ -1091,15 +1006,14 @@ TEST_F(SetGlobalPropertiesRequestTest, OnEvent_UIAndWarningResultCode_SUCCESS) { .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); OnEventUISetupHelper(msg, command); - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(_)).Times(0); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); event.set_smart_object(*msg); EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); EXPECT_CALL(app_mngr_, ManageMobileCommand(_, am::commands::Command::ORIGIN_SDL)) .WillOnce(Return(true)); @@ -1126,9 +1040,6 @@ TEST_F(SetGlobalPropertiesRequestTest, OnEvent_InvalidApp_Canceled) { EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillRepeatedly(Return(MockAppPtr())); @@ -1146,8 +1057,7 @@ TEST_F(SetGlobalPropertiesRequestTest, OnEvent_InvalidEventID_Canceled) { SharedPtr<SetGlobalPropertiesRequest> command( CreateCommand<SetGlobalPropertiesRequest>(msg)); - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(_)).Times(0); - EXPECT_CALL(app_mngr_, application(kConnectionKey)).Times(0); + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); EXPECT_CALL(*mock_app_, UpdateHash()).Times(0); Event event(hmi_apis::FunctionID::TTS_Stopped); @@ -1180,8 +1090,8 @@ TEST_F(SetGlobalPropertiesRequestTest, ManageMobileCommand(_, am::commands::Command::ORIGIN_SDL)) .WillOnce(Return(true)); - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(response_code)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); Event event(hmi_apis::FunctionID::TTS_SetGlobalProperties); event.set_smart_object(*msg); @@ -1192,7 +1102,7 @@ TEST_F(SetGlobalPropertiesRequestTest, TEST_F(SetGlobalPropertiesRequestTest, OnEvent_TTSAndWarningsResultCode_SUCCESS) { MessageSharedPtr msg = CreateMsgParams(); - hmi_apis::Common_Result::eType response_code = + const hmi_apis::Common_Result::eType response_code = hmi_apis::Common_Result::WARNINGS; (*msg)[am::strings::params][am::hmi_response::code] = response_code; ON_CALL( @@ -1210,17 +1120,30 @@ TEST_F(SetGlobalPropertiesRequestTest, EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - EXPECT_CALL(app_mngr_, - ManageMobileCommand(_, am::commands::Command::ORIGIN_SDL)) - .WillOnce(Return(true)); + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(_)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); + MessageSharedPtr ui_command_result; + EXPECT_CALL( + app_mngr_, + ManageMobileCommand(_, am::commands::Command::CommandOrigin::ORIGIN_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); Event event(hmi_apis::FunctionID::TTS_SetGlobalProperties); event.set_smart_object(*msg); command->on_event(event); + + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::WARNINGS)); } } // namespace set_global_properties_request diff --git a/src/components/application_manager/test/commands/mobile/set_media_clock_timer_test.cc b/src/components/application_manager/test/commands/mobile/set_media_clock_timer_test.cc index 3056d0e9fc..cf668c8b36 100644 --- a/src/components/application_manager/test/commands/mobile/set_media_clock_timer_test.cc +++ b/src/components/application_manager/test/commands/mobile/set_media_clock_timer_test.cc @@ -55,7 +55,6 @@ using am::commands::MessageSharedPtr; using am::event_engine::Event; using am::MockMessageHelper; using ::testing::_; -using ::testing::Mock; using ::testing::Return; using ::testing::ReturnRef; @@ -75,9 +74,7 @@ const uint32_t kSeconds = 1u; class SetMediaClockRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: - SetMediaClockRequestTest() - : mock_message_helper_(*MockMessageHelper::message_helper_mock()) - , mock_app_(CreateMockApp()) {} + SetMediaClockRequestTest() : mock_app_(CreateMockApp()) {} void SetUp() OVERRIDE { ON_CALL(app_mngr_, application(kConnectionKey)) @@ -85,10 +82,6 @@ class SetMediaClockRequestTest ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); } - void TearDown() OVERRIDE { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - void ResultCommandExpectations(MessageSharedPtr msg, const std::string& info) { EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), @@ -114,7 +107,6 @@ class SetMediaClockRequestTest EXPECT_CALL(app_mngr_, ManageMobileCommand(_, _)); } - MockMessageHelper& mock_message_helper_; MockAppPtr mock_app_; }; @@ -140,10 +132,6 @@ TEST_F(SetMediaClockRequestTest, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_RESPONSE)); - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)) - .WillOnce(Return(mobile_apis::Result::UNSUPPORTED_RESOURCE)); - MessageSharedPtr ui_command_result; EXPECT_CALL( app_mngr_, @@ -328,12 +316,9 @@ TEST_F(SetMediaClockRequestTest, Run_InvalidApp_Canceled) { TEST_F(SetMediaClockRequestTest, OnEvent_Success) { MessageSharedPtr msg = CreateMessage(); (*msg)[am::strings::params][am::hmi_response::code] = - mobile_apis::Result::SUCCESS; + hmi_apis::Common_Result::SUCCESS; (*msg)[am::strings::msg_params] = SmartObject(smart_objects::SmartType_Null); - SharedPtr<SetMediaClockRequest> command( - CreateCommand<SetMediaClockRequest>(msg)); - EXPECT_CALL(app_mngr_, ManageMobileCommand(_, _)); MockAppPtr app(CreateMockApp()); @@ -341,7 +326,8 @@ TEST_F(SetMediaClockRequestTest, OnEvent_Success) { Event event(hmi_apis::FunctionID::UI_SetMediaClockTimer); event.set_smart_object(*msg); - + SharedPtr<SetMediaClockRequest> command( + CreateCommand<SetMediaClockRequest>(msg)); command->on_event(event); } diff --git a/src/components/application_manager/test/commands/mobile/show_test.cc b/src/components/application_manager/test/commands/mobile/show_test.cc index d1e3c14181..4752bac0fd 100644 --- a/src/components/application_manager/test/commands/mobile/show_test.cc +++ b/src/components/application_manager/test/commands/mobile/show_test.cc @@ -59,7 +59,6 @@ using am::MockMessageHelper; using test::components::policy_test::MockPolicyHandlerInterface; using ::utils::SharedPtr; using ::testing::_; -using ::testing::Mock; using ::testing::Return; using ::testing::ReturnRef; @@ -73,8 +72,7 @@ const uint32_t kFunctionID = 3u; class ShowRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: - ShowRequestTest() - : mock_message_helper_(*MockMessageHelper::message_helper_mock()) { + ShowRequestTest() { mock_app_ = CreateMockApp(); } sync_primitives::Lock lock_; @@ -203,16 +201,7 @@ class ShowRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { EXPECT_CALL(*mock_app_, set_show_command(msg_params)); } - void SetUp() OVERRIDE { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - - void TearDown() OVERRIDE { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - MockAppPtr mock_app_; - MockMessageHelper& mock_message_helper_; std::string text_field_; }; @@ -238,10 +227,6 @@ TEST_F(ShowRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { Event event(hmi_apis::FunctionID::UI_Show); event.set_smart_object(*msg); - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)) - .WillOnce(Return(mobile_apis::Result::UNSUPPORTED_RESOURCE)); - MessageSharedPtr vr_command_result; EXPECT_CALL( app_mngr_, @@ -264,12 +249,9 @@ TEST_F(ShowRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { .asString() .empty()); } - Mock::VerifyAndClearExpectations(&mock_message_helper_); } TEST_F(ShowRequestTest, Run_SoftButtonExists_SUCCESS) { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - MessageSharedPtr msg = CreateMsgParams(); SmartObject msg_params(smart_objects::SmartType_Map); @@ -298,13 +280,9 @@ TEST_F(ShowRequestTest, Run_SoftButtonExists_SUCCESS) { EXPECT_CALL(*mock_app_, set_show_command(msg_params)); command->Run(); - - Mock::VerifyAndClearExpectations(&mock_message_helper_); } TEST_F(ShowRequestTest, Run_SoftButtonNotExists_SUCCESS) { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - MessageSharedPtr msg = CreateMsgParams(); SmartObject msg_params(smart_objects::SmartType_Map); @@ -328,13 +306,9 @@ TEST_F(ShowRequestTest, Run_SoftButtonNotExists_SUCCESS) { EXPECT_CALL(*mock_app_, set_show_command(msg_params)); command->Run(); - - Mock::VerifyAndClearExpectations(&mock_message_helper_); } TEST_F(ShowRequestTest, Run_SoftButtonExists_Canceled) { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - MessageSharedPtr msg = CreateMsgParams(); SmartObject msg_params(smart_objects::SmartType_Map); @@ -361,13 +335,9 @@ TEST_F(ShowRequestTest, Run_SoftButtonExists_Canceled) { EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); command->Run(); - - Mock::VerifyAndClearExpectations(&mock_message_helper_); } TEST_F(ShowRequestTest, Run_Graphic_SUCCESS) { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - MessageSharedPtr msg = CreateMsgParams(); SmartObject msg_params(smart_objects::SmartType_Map); @@ -392,13 +362,9 @@ TEST_F(ShowRequestTest, Run_Graphic_SUCCESS) { EXPECT_CALL(*mock_app_, set_show_command(msg_params)); command->Run(); - - Mock::VerifyAndClearExpectations(&mock_message_helper_); } TEST_F(ShowRequestTest, Run_Graphic_Canceled) { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - MessageSharedPtr msg = CreateMsgParams(); SmartObject msg_params(smart_objects::SmartType_Map); @@ -420,13 +386,9 @@ TEST_F(ShowRequestTest, Run_Graphic_Canceled) { EXPECT_CALL(*mock_app_, set_show_command(msg_params)).Times(0); command->Run(); - - Mock::VerifyAndClearExpectations(&mock_message_helper_); } TEST_F(ShowRequestTest, Run_Graphic_WrongSyntax) { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - MessageSharedPtr msg = CreateMsgParams(); SmartObject msg_params(smart_objects::SmartType_Map); @@ -447,13 +409,9 @@ TEST_F(ShowRequestTest, Run_Graphic_WrongSyntax) { EXPECT_CALL(*mock_app_, set_show_command(msg_params)).Times(0); command->Run(); - - Mock::VerifyAndClearExpectations(&mock_message_helper_); } TEST_F(ShowRequestTest, Run_SecondaryGraphic_SUCCESS) { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - MessageSharedPtr msg = CreateMsgParams(); SmartObject msg_params(smart_objects::SmartType_Map); @@ -478,13 +436,9 @@ TEST_F(ShowRequestTest, Run_SecondaryGraphic_SUCCESS) { EXPECT_CALL(*mock_app_, set_show_command(msg_params)); command->Run(); - - Mock::VerifyAndClearExpectations(&mock_message_helper_); } TEST_F(ShowRequestTest, Run_SecondaryGraphic_Canceled) { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - MessageSharedPtr msg = CreateMsgParams(); SmartObject msg_params(smart_objects::SmartType_Map); @@ -506,13 +460,9 @@ TEST_F(ShowRequestTest, Run_SecondaryGraphic_Canceled) { EXPECT_CALL(*mock_app_, set_show_command(msg_params)).Times(0); command->Run(); - - Mock::VerifyAndClearExpectations(&mock_message_helper_); } TEST_F(ShowRequestTest, Run_SecondaryGraphic_WrongSyntax) { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - MessageSharedPtr msg = CreateMsgParams(); SmartObject msg_params(smart_objects::SmartType_Map); @@ -533,8 +483,6 @@ TEST_F(ShowRequestTest, Run_SecondaryGraphic_WrongSyntax) { EXPECT_CALL(*mock_app_, set_show_command(msg_params)).Times(0); command->Run(); - - Mock::VerifyAndClearExpectations(&mock_message_helper_); } TEST_F(ShowRequestTest, Run_MainField1_SUCCESS) { @@ -720,7 +668,6 @@ TEST_F(ShowRequestTest, Run_MainField4_MetadataTag) { } TEST_F(ShowRequestTest, Run_MainField1_MetadataTagWithNoFieldData) { - Mock::VerifyAndClearExpectations(&mock_message_helper_); MessageSharedPtr msg = CreateMsgParams(); SharedPtr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); @@ -745,10 +692,6 @@ TEST_F(ShowRequestTest, Run_MainField1_MetadataTagWithNoFieldData) { Event event(hmi_apis::FunctionID::UI_Show); event.set_smart_object(*ev_msg); - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::SUCCESS)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - MessageSharedPtr ui_command_result; EXPECT_CALL( app_mngr_, @@ -764,8 +707,6 @@ TEST_F(ShowRequestTest, Run_MainField1_MetadataTagWithNoFieldData) { (*ui_command_result)[am::strings::msg_params][am::strings::result_code] .asInt(), static_cast<int32_t>(mobile_apis::Result::WARNINGS)); - - Mock::VerifyAndClearExpectations(&mock_message_helper_); } TEST_F(ShowRequestTest, Run_MediaClock_SUCCESS) { @@ -943,9 +884,6 @@ TEST_F(ShowRequestTest, OnEvent_SuccessResultCode_SUCCESS) { SharedPtr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); - ON_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::eType::SUCCESS)) - .WillByDefault(Return(am::mobile_api::Result::SUCCESS)); EXPECT_CALL(app_mngr_, ManageMobileCommand( MobileResultCodeIs(mobile_apis::Result::eType::SUCCESS), _)); @@ -967,9 +905,6 @@ TEST_F(ShowRequestTest, OnEvent_WarningsResultCode_SUCCESS) { SharedPtr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::WARNINGS)) - .WillOnce(Return(mobile_apis::Result::WARNINGS)); EXPECT_CALL(app_mngr_, ManageMobileCommand(_, _)); Event event(hmi_apis::FunctionID::UI_Show); diff --git a/src/components/application_manager/test/commands/mobile/simple_notification_commands_test.cc b/src/components/application_manager/test/commands/mobile/simple_notification_commands_test.cc index cbc2d702b3..7ded373d29 100644 --- a/src/components/application_manager/test/commands/mobile/simple_notification_commands_test.cc +++ b/src/components/application_manager/test/commands/mobile/simple_notification_commands_test.cc @@ -58,28 +58,12 @@ namespace commands = am::commands; using ::testing::_; using ::testing::Types; using ::testing::Return; -using ::testing::Mock; - -using am::MockMessageHelper; template <class Command> class MobileNotificationCommandsTest : public CommandsTest<CommandsTestMocks::kIsNice> { public: typedef Command CommandType; - - public: - MobileNotificationCommandsTest() - : message_helper_(*MockMessageHelper::message_helper_mock()) { - Mock::VerifyAndClearExpectations(&message_helper_); - } - - ~MobileNotificationCommandsTest() { - Mock::VerifyAndClearExpectations(&message_helper_); - } - - protected: - MockMessageHelper& message_helper_; }; typedef Types<commands::OnAppInterfaceUnregisteredNotification, diff --git a/src/components/application_manager/test/commands/mobile/slider_test.cc b/src/components/application_manager/test/commands/mobile/slider_test.cc index 20262ed35a..53764e3fcd 100644 --- a/src/components/application_manager/test/commands/mobile/slider_test.cc +++ b/src/components/application_manager/test/commands/mobile/slider_test.cc @@ -59,7 +59,6 @@ using am::MockMessageHelper; using policy_test::MockPolicyHandlerInterface; using ::utils::SharedPtr; using ::testing::_; -using ::testing::Mock; using ::testing::Return; using ::testing::ReturnRef; @@ -82,8 +81,7 @@ class SliderRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: SliderRequestTest() - : mock_message_helper_(*MockMessageHelper::message_helper_mock()) - , mock_app_(CreateMockApp()) + : mock_app_(CreateMockApp()) , msg_(CreateMessage(smart_objects::SmartType_Map)) {} MessageSharedPtr CreateFullParamsUISO() { @@ -123,10 +121,6 @@ class SliderRequestTest ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); } - void SetUp() OVERRIDE { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - void ExpectManageMobileCommandWithResultCode( const mobile_apis::Result::eType code) { EXPECT_CALL( @@ -135,12 +129,8 @@ class SliderRequestTest am::commands::Command::CommandOrigin::ORIGIN_SDL)); } - void TearDown() OVERRIDE { - Mock::VerifyAndClearExpectations(&mock_message_helper_); - } sync_primitives::Lock lock_; - MockMessageHelper& mock_message_helper_; MockAppPtr mock_app_; MessageSharedPtr msg_; MockPolicyHandlerInterface mock_policy_handler_; @@ -167,10 +157,6 @@ TEST_F(SliderRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { Event event(hmi_apis::FunctionID::UI_Slider); event.set_smart_object(*msg); - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)) - .WillOnce(Return(mobile_apis::Result::UNSUPPORTED_RESOURCE)); - MessageSharedPtr ui_command_result; EXPECT_CALL( app_mngr_, @@ -193,7 +179,6 @@ TEST_F(SliderRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { .asString() .empty()); } - Mock::VerifyAndClearExpectations(&mock_message_helper_); } class CallOnTimeOut { @@ -297,9 +282,8 @@ TEST_F(SliderRequestTest, OnEvent_UI_OnResetTimeout_UNSUCCESS) { CommandPtr command(CreateCommand<SliderRequest>(msg_)); EXPECT_TRUE(command->Init()); - EXPECT_CALL( - app_mngr_, - updateRequestTimeout(kConnectionKey, kCorrelationId, kDefaultTimeout)); + EXPECT_CALL(app_mngr_, + updateRequestTimeout(kConnectionKey, kCorrelationId, _)); Event event(hmi_apis::FunctionID::UI_OnResetTimeout); event.set_smart_object(*msg_); @@ -325,9 +309,6 @@ TEST_F(SliderRequestTest, OnEvent_UISliderPositionExists_SUCCESS) { (*msg_)[am::strings::params][am::strings::data] [am::strings::slider_position] = "position"; - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::TIMED_OUT)) - .WillOnce(Return(mobile_apis::Result::TIMED_OUT)); ExpectManageMobileCommandWithResultCode(mobile_apis::Result::TIMED_OUT); Event event(hmi_apis::FunctionID::UI_Slider); @@ -343,9 +324,6 @@ TEST_F(SliderRequestTest, OnEvent_UISliderAborted_SUCCESS) { (*msg_)[am::strings::params][am::hmi_response::code] = hmi_apis::Common_Result::ABORTED; - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::ABORTED)) - .WillOnce(Return(mobile_apis::Result::ABORTED)); ExpectManageMobileCommandWithResultCode(mobile_apis::Result::ABORTED); Event event(hmi_apis::FunctionID::UI_Slider); diff --git a/src/components/application_manager/test/commands/mobile/speak_request_test.cc b/src/components/application_manager/test/commands/mobile/speak_request_test.cc index f8a7d22b40..f07012d315 100644 --- a/src/components/application_manager/test/commands/mobile/speak_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/speak_request_test.cc @@ -84,16 +84,9 @@ const uint32_t kConnectionKey = 5u; class SpeakRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: SpeakRequestTest() - : mock_message_helper_(*am::MockMessageHelper::message_helper_mock()) - , request_(CreateMessage(smart_objects::SmartType_Map)) + : request_(CreateMessage(smart_objects::SmartType_Map)) , response_(CreateMessage(smart_objects::SmartType_Map)) - , app_(CreateMockApp()) { - testing::Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - - ~SpeakRequestTest() { - testing::Mock::VerifyAndClearExpectations(&mock_message_helper_); - } + , app_(CreateMockApp()) {} void CheckExpectations(const hmi_apis::Common_Result::eType hmi_response, const mobile_apis::Result::eType mobile_response, @@ -114,10 +107,6 @@ class SpeakRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { MessageSharedPtr response_to_mobile; EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillRepeatedly(Return(state)); - MockMessageHelper* mock_message_helper = - MockMessageHelper::message_helper_mock(); - EXPECT_CALL(*mock_message_helper, HMIToMobileResult(_)) - .WillOnce(Return(mobile_response)); EXPECT_CALL(app_mngr_, ManageMobileCommand( @@ -134,7 +123,6 @@ class SpeakRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { static_cast<int32_t>(mobile_response)); } - am::MockMessageHelper& mock_message_helper_; MessageSharedPtr request_; MessageSharedPtr response_; MockAppPtr app_; @@ -156,9 +144,6 @@ TEST_F(SpeakRequestTest, OnEvent_SUCCESS_Expect_true) { MessageSharedPtr response_to_mobile; - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::SUCCESS)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); EXPECT_CALL( app_mngr_, ManageMobileCommand(_, am::commands::Command::CommandOrigin::ORIGIN_SDL)) @@ -349,8 +334,6 @@ TEST_F(SpeakRequestTest, OnEvent_TTS_Speak_SUCCESS) { ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(hmi_result)) - .WillOnce(Return(am::mobile_api::Result::SUCCESS)); EXPECT_CALL( app_mngr_, ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); @@ -369,8 +352,6 @@ TEST_F(SpeakRequestTest, OnEvent_TTS_SpeakWithWarning_WarningWithSuccess) { ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(hmi_result)) - .WillOnce(Return(am::mobile_api::Result::WARNINGS)); EXPECT_CALL( app_mngr_, ManageMobileCommand(MobileResultCodeIs(mobile_result::WARNINGS), _)); diff --git a/src/components/application_manager/test/commands/mobile/subscribe_way_points_request_test.cc b/src/components/application_manager/test/commands/mobile/subscribe_way_points_request_test.cc index 4546293172..87127231be 100644 --- a/src/components/application_manager/test/commands/mobile/subscribe_way_points_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/subscribe_way_points_request_test.cc @@ -51,16 +51,15 @@ namespace mobile_commands_test { namespace subscribe_way_points_request { using ::testing::_; +using ::testing::A; using ::testing::Return; using ::testing::ReturnRef; using ::testing::DoAll; using ::testing::SaveArg; using ::testing::InSequence; -using ::testing::Mock; namespace am = ::application_manager; using am::commands::SubscribeWayPointsRequest; using am::commands::MessageSharedPtr; -using am::MockMessageHelper; typedef SharedPtr<SubscribeWayPointsRequest> CommandPtr; @@ -72,14 +71,15 @@ TEST_F(SubscribeWayPointsRequestTest, Run_SUCCESS) { MockAppPtr app(CreateMockApp()); ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - ON_CALL(app_mngr_, IsAppSubscribedForWayPoints(_)) + ON_CALL(app_mngr_, IsAppSubscribedForWayPoints(A<am::ApplicationSharedPtr>())) .WillByDefault(Return(false)); ON_CALL(app_mngr_, IsAnyAppSubscribedForWayPoints()) .WillByDefault(Return(true)); { InSequence dummy; - EXPECT_CALL(app_mngr_, SubscribeAppForWayPoints(_)); + EXPECT_CALL(app_mngr_, + SubscribeAppForWayPoints(A<am::ApplicationSharedPtr>())); EXPECT_CALL(*app, UpdateHash()); } @@ -106,16 +106,13 @@ TEST_F(SubscribeWayPointsRequestTest, OnEvent_SUCCESS) { event.set_smart_object(*event_msg); - MockMessageHelper* mock_message_helper = - MockMessageHelper::message_helper_mock(); - Mock::VerifyAndClearExpectations(mock_message_helper); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); { InSequence dummy; - EXPECT_CALL(app_mngr_, SubscribeAppForWayPoints(_)); - EXPECT_CALL(*mock_message_helper, HMIToMobileResult(result_code)) + EXPECT_CALL(app_mngr_, + SubscribeAppForWayPoints(A<am::ApplicationSharedPtr>())); + EXPECT_CALL(mock_message_helper_, HMIToMobileResult(result_code)) .WillOnce(Return(mobile_apis::Result::SUCCESS)); EXPECT_CALL(app_mngr_, ManageMobileCommand(_, _)); EXPECT_CALL(*app, UpdateHash()); @@ -123,8 +120,6 @@ TEST_F(SubscribeWayPointsRequestTest, OnEvent_SUCCESS) { command->Init(); command->on_event(event); - - Mock::VerifyAndClearExpectations(mock_message_helper); } } // namespace subscribe_way_points_request diff --git a/src/components/application_manager/test/commands/mobile/system_request_test.cc b/src/components/application_manager/test/commands/mobile/system_request_test.cc new file mode 100644 index 0000000000..0e07889b4b --- /dev/null +++ b/src/components/application_manager/test/commands/mobile/system_request_test.cc @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2017, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdint.h> +#include <string> +#include <set> + +#include "gtest/gtest.h" + +#include "application_manager/commands/mobile/system_request.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace system_request { + +namespace am = application_manager; +using am::commands::SystemRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockHmiInterfaces; +using am::event_engine::Event; +using policy_test::MockPolicyHandlerInterface; +using ::utils::SharedPtr; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kAppPolicyId = "fake-app-id"; +const uint32_t kDefaultTimeout = 1000u; +const std::string kAppFolderName = "fake-app-name"; +const std::string kAppStorageFolder = "fake-storage"; +const std::string kSystemFilesPath = "/fake/system/files"; +const std::string kFileName = "Filename"; +} // namespace + +class SystemRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + SystemRequestTest() : mock_app_(CreateMockApp()) {} + + protected: + MessageSharedPtr CreateIVSUMessage() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::msg_params][am::strings::request_type] = + mobile_apis::RequestType::HTTP; + (*msg)[am::strings::msg_params][am::strings::file_name] = kFileName; + return msg; + } + + void PreConditions() { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(app_mngr_, GetPolicyHandler()) + .WillByDefault(ReturnRef(mock_policy_handler_)); + + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(*mock_app_, policy_app_id()).WillByDefault(Return(kAppPolicyId)); + ON_CALL(*mock_app_, folder_name()).WillByDefault(Return(kAppFolderName)); + + ON_CALL(app_mngr_settings_, system_files_path()) + .WillByDefault(ReturnRef(kSystemFilesPath)); + ON_CALL(app_mngr_settings_, app_storage_folder()) + .WillByDefault(ReturnRef(kAppStorageFolder)); + + ON_CALL(mock_policy_handler_, IsRequestTypeAllowed(kAppPolicyId, _)) + .WillByDefault(Return(true)); + } + + void ExpectManageMobileCommandWithResultCode( + const mobile_apis::Result::eType code) { + EXPECT_CALL( + app_mngr_, + ManageMobileCommand(MobileResultCodeIs(code), + am::commands::Command::CommandOrigin::ORIGIN_SDL)); + } + + MockAppPtr mock_app_; + MockPolicyHandlerInterface mock_policy_handler_; +}; + +TEST_F(SystemRequestTest, Run_HTTP_FileName_no_binary_data_REJECTED) { + PreConditions(); + MessageSharedPtr msg = CreateIVSUMessage(); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::REJECTED); + + SharedPtr<SystemRequest> command(CreateCommand<SystemRequest>(msg)); + command->Run(); +} + +} // namespace system_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/unregister_app_interface_request_test.cc b/src/components/application_manager/test/commands/mobile/unregister_app_interface_request_test.cc index ae4e46d40b..3d083f5c45 100644 --- a/src/components/application_manager/test/commands/mobile/unregister_app_interface_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/unregister_app_interface_request_test.cc @@ -90,7 +90,7 @@ TEST_F(UnregisterAppInterfaceRequestTest, Run_SUCCESS) { mobile_apis::AppInterfaceUnregisteredReason::INVALID_ENUM; MessageSharedPtr dummy_msg(CreateMessage()); - EXPECT_CALL(*am::MockMessageHelper::message_helper_mock(), + EXPECT_CALL(mock_message_helper_, GetOnAppInterfaceUnregisteredNotificationToMobile( kConnectionKey, kUnregisterReason)) .WillOnce(Return(dummy_msg)); diff --git a/src/components/application_manager/test/commands/mobile/unsubscribe_vehicle_request_test.cc b/src/components/application_manager/test/commands/mobile/unsubscribe_vehicle_request_test.cc index 9652364646..bb4824e8f7 100644 --- a/src/components/application_manager/test/commands/mobile/unsubscribe_vehicle_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/unsubscribe_vehicle_request_test.cc @@ -59,7 +59,8 @@ typedef ::utils::SharedPtr<UnsubscribeVehicleDataRequest> CommandPtr; namespace { const uint32_t kConnectionKey = 1u; const std::string kMsgParamKey = "test_key"; -const am::VehicleDataType kVehicleType = am::VehicleDataType::SPEED; +const mobile_apis::VehicleDataType::eType kVehicleType = + mobile_apis::VehicleDataType::VEHICLEDATA_SPEED; } // namespace class UnsubscribeVehicleRequestTest @@ -91,8 +92,7 @@ TEST_F(UnsubscribeVehicleRequestTest, kVehicleType; am::VehicleData data; - EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()), vehicle_data()) - .WillOnce(ReturnRef(data)); + EXPECT_CALL(mock_message_helper_, vehicle_data()).WillOnce(ReturnRef(data)); CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); MockAppPtr mock_app(CreateMockApp()); @@ -115,7 +115,7 @@ TEST_F(UnsubscribeVehicleRequestTest, am::VehicleData vehicle_data; vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); - EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()), vehicle_data()) + EXPECT_CALL(mock_message_helper_, vehicle_data()) .WillOnce(ReturnRef(vehicle_data)); CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); @@ -139,7 +139,7 @@ TEST_F(UnsubscribeVehicleRequestTest, am::VehicleData vehicle_data; vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); - EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()), vehicle_data()) + EXPECT_CALL(mock_message_helper_, vehicle_data()) .WillOnce(ReturnRef(vehicle_data)); CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); @@ -161,7 +161,7 @@ TEST_F(UnsubscribeVehicleRequestTest, Run_UnsubscribeDataDisabled_UNSUCCESS) { am::VehicleData vehicle_data; vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); - EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()), vehicle_data()) + EXPECT_CALL(mock_message_helper_, vehicle_data()) .WillOnce(ReturnRef(vehicle_data)); CommandPtr command(CreateCommand<UnsubscribeVehicleDataRequest>(command_msg)); @@ -185,7 +185,7 @@ void UnsubscribeVehicleRequestTest::UnsubscribeSuccessfully() { am::VehicleData vehicle_data; vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); - EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()), vehicle_data()) + EXPECT_CALL(mock_message_helper_, vehicle_data()) .WillOnce(ReturnRef(vehicle_data)); am::ApplicationSet application_set_; @@ -228,7 +228,7 @@ TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataNotSubscribed_IGNORED) { EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillRepeatedly(Return(mock_app)); vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); - EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()), vehicle_data()) + EXPECT_CALL(mock_message_helper_, vehicle_data()) .WillOnce(ReturnRef(vehicle_data)); EXPECT_CALL(*mock_app, IsSubscribedToIVI(kVehicleType)) .WillRepeatedly(Return(false)); @@ -243,12 +243,9 @@ TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataNotSubscribed_IGNORED) { SmartObject message(smart_objects::SmartType_Map); const hmi_apis::Common_Result::eType hmi_result = hmi_apis::Common_Result::SUCCESS; - const mobile_apis::Result::eType mob_result = mobile_apis::Result::SUCCESS; message[am::strings::params][am::hmi_response::code] = hmi_result; message[am::strings::msg_params][kMsgParamKey] = true; test_event.set_smart_object(message); - EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()), - HMIToMobileResult(hmi_result)).WillOnce(Return(mob_result)); EXPECT_CALL( app_mngr_, @@ -272,14 +269,10 @@ TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataUnsubscribed_SUCCESS) { SmartObject message(smart_objects::SmartType_Map); const hmi_apis::Common_Result::eType hmi_result = hmi_apis::Common_Result::SUCCESS; - const mobile_apis::Result::eType mob_result = mobile_apis::Result::SUCCESS; message[am::strings::params][am::hmi_response::code] = hmi_result; message[am::strings::msg_params][kMsgParamKey] = true; test_event.set_smart_object(message); - EXPECT_CALL(*(am::MockMessageHelper::message_helper_mock()), - HMIToMobileResult(hmi_result)).WillOnce(Return(mob_result)); - EXPECT_CALL( app_mngr_, ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); diff --git a/src/components/application_manager/test/commands/mobile/unsubscribe_way_points_request_test.cc b/src/components/application_manager/test/commands/mobile/unsubscribe_way_points_request_test.cc index 50567a7c62..5615b0cabd 100644 --- a/src/components/application_manager/test/commands/mobile/unsubscribe_way_points_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/unsubscribe_way_points_request_test.cc @@ -72,20 +72,13 @@ class UnSubscribeWayPointsRequestTest public: UnSubscribeWayPointsRequestTest() : command_msg_(CreateMessage(smart_objects::SmartType_Map)) - , command_(CreateCommand<UnSubscribeWayPointsRequest>(command_msg_)) - , mock_message_helper_(*am::MockMessageHelper::message_helper_mock()) { + , command_(CreateCommand<UnSubscribeWayPointsRequest>(command_msg_)) { (*command_msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; - testing::Mock::VerifyAndClearExpectations(&mock_message_helper_); - } - - ~UnSubscribeWayPointsRequestTest() { - testing::Mock::VerifyAndClearExpectations(&mock_message_helper_); } MessageSharedPtr command_msg_; ::utils::SharedPtr<UnSubscribeWayPointsRequest> command_; - am::MockMessageHelper& mock_message_helper_; }; TEST_F(UnSubscribeWayPointsRequestTest, @@ -107,9 +100,9 @@ TEST_F(UnSubscribeWayPointsRequestTest, EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppId)); - - EXPECT_CALL(app_mngr_, IsAppSubscribedForWayPoints(kAppId)) + EXPECT_CALL(app_mngr_, + IsAppSubscribedForWayPoints( + ::testing::Matcher<am::ApplicationSharedPtr>(mock_app))) .WillOnce(Return(false)); EXPECT_CALL( @@ -124,9 +117,9 @@ TEST_F(UnSubscribeWayPointsRequestTest, Run_AppSubscribedForWayPoints_SUCCESS) { EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppId)); - - EXPECT_CALL(app_mngr_, IsAppSubscribedForWayPoints(kAppId)) + EXPECT_CALL(app_mngr_, + IsAppSubscribedForWayPoints( + ::testing::Matcher<am::ApplicationSharedPtr>(mock_app))) .WillOnce(Return(true)); EXPECT_CALL(app_mngr_, @@ -161,13 +154,9 @@ TEST_F(UnSubscribeWayPointsRequestTest, Event event(hmi_apis::FunctionID::Navigation_UnsubscribeWayPoints); event.set_smart_object(*event_msg); - EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppId)); - - EXPECT_CALL(app_mngr_, UnsubscribeAppFromWayPoints(kAppId)); - - EXPECT_CALL(mock_message_helper_, - HMIToMobileResult(hmi_apis::Common_Result::SUCCESS)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(app_mngr_, + UnsubscribeAppFromWayPoints( + ::testing::Matcher<am::ApplicationSharedPtr>(mock_app))); EXPECT_CALL( app_mngr_, diff --git a/src/components/application_manager/test/commands/mobile/update_turn_list_request_test.cc b/src/components/application_manager/test/commands/mobile/update_turn_list_request_test.cc index cab67e641c..dacabba5fd 100644 --- a/src/components/application_manager/test/commands/mobile/update_turn_list_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/update_turn_list_request_test.cc @@ -79,8 +79,7 @@ class UpdateTurnListRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: UpdateTurnListRequestTest() - : mock_message_helper_(*am::MockMessageHelper::message_helper_mock()) - , command_msg_(CreateMessage(smart_objects::SmartType_Map)) + : command_msg_(CreateMessage(smart_objects::SmartType_Map)) , command_(CreateCommand<UpdateTurnListRequest>(command_msg_)) { (*command_msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; @@ -88,7 +87,6 @@ class UpdateTurnListRequestTest kFunctionId; } - am::MockMessageHelper& mock_message_helper_; MessageSharedPtr command_msg_; ::utils::SharedPtr<UpdateTurnListRequest> command_; TypeIf<kMocksAreNice, @@ -275,9 +273,6 @@ TEST_F(UpdateTurnListRequestTest, OnEvent_UnsupportedResource_SUCCESS) { Event event(hmi_apis::FunctionID::Navigation_UpdateTurnList); event.set_smart_object(*event_msg); - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(hmi_response_code)) - .WillOnce(Return(mobile_response_code)); - EXPECT_CALL(app_mngr_, ManageMobileCommand(MobileResultCodeIs(mobile_response_code), _)); @@ -297,9 +292,6 @@ TEST_F(UpdateTurnListRequestTest, Event event(hmi_apis::FunctionID::Navigation_UpdateTurnList); event.set_smart_object(*event_msg); - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(hmi_response_code)) - .WillOnce(Return(mobile_response_code)); - EXPECT_CALL(app_mngr_, ManageMobileCommand(MobileResultCodeIs(mobile_response_code), _)); diff --git a/src/components/application_manager/test/help_prompt_manager_test.cc b/src/components/application_manager/test/help_prompt_manager_test.cc new file mode 100644 index 0000000000..3b7e68bde7 --- /dev/null +++ b/src/components/application_manager/test/help_prompt_manager_test.cc @@ -0,0 +1,368 @@ +/* + * Copyright (c) 2018, 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 "gtest/gtest.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_help_prompt_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/mock_resumption_data.h" +#include "connection_handler/mock_connection_handler.h" +#include "protocol_handler/mock_session_observer.h" +#include "policy/usage_statistics/mock_statistics_manager.h" +#include "application_manager/application_impl.h" +#include "application_manager/commands/mobile/set_global_properties_request.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/hmi_state.h" +#include "utils/file_system.h" + +namespace test { +namespace components { +namespace application_manager_test { + +namespace { +const uint32_t kConnectionKey = 1u; +const uint32_t kCorrelationKey = 2u; +const uint32_t kAppId = 10u; +const uint32_t kCmdId = 1u; +const std::string kPolicyAppId = "fake_app_id"; +const uint32_t kTimeout = 10000u; +const std::string kText = "one"; +const uint32_t kPosition = 1u; +const std::string kFirstVrCommand = "first"; +const int32_t kGrammarId = 12; +const std::string kDirectoryName = "./test_storage"; +const uint8_t expected_tread_pool_size = 2u; +const uint8_t stop_streaming_timeout = 1u; +const std::vector<std::string> kTimeoutPrompt{"timeoutPrompt"}; +} // namespace + +using namespace application_manager; +using namespace policy; +using namespace test::components::commands_test; +using namespace mobile_apis; + +using testing::Mock; +using testing::NiceMock; +using testing::Return; +using testing::ReturnRef; +using testing::_; +using am::HmiStatePtr; +using am::commands::SetGlobalPropertiesRequest; +using usage_statistics_test::MockStatisticsManager; + +class ApplicationImplTest : public ApplicationImpl { + public: + ApplicationImplTest( + uint32_t application_id, + const std::string& policy_app_id, + const std::string& mac_address, + const connection_handler::DeviceHandle device_id, + const custom_str::CustomString& app_name, + utils::SharedPtr<usage_statistics::StatisticsManager> statistics_manager, + ApplicationManager& application_manager, + MockHelpPromptManager& mock_help_prompt_manager) + : ApplicationImpl(application_id, + policy_app_id, + mac_address, + device_id, + app_name, + statistics_manager, + application_manager) + , mock_help_prompt_manager_(mock_help_prompt_manager) {} + + HelpPromptManager& help_prompt_manager() OVERRIDE { + return mock_help_prompt_manager_; + } + + private: + MockHelpPromptManager& mock_help_prompt_manager_; +}; + +class HelpPromptManagerTest : public ::testing::Test { + public: + HelpPromptManagerTest() + : app_set_(test_app_, app_lock_) + , mock_message_helper_(*MockMessageHelper::message_helper_mock()) {} + void SetUp() OVERRIDE; + void TearDown() OVERRIDE; + MessageSharedPtr CreateMsgParams(); + void VRArraySetupHelper(MessageSharedPtr msg, + SmartObject& vr_help_title, + SmartObject& vr_help_array); + void CreateBasicParamsVRRequest(MessageSharedPtr msg); + void CreateApplication(MockHelpPromptManager& mock_help_prompt_manager); + HmiStatePtr CreateTestHmiState(); + + template <class Command> + SharedPtr<Command> CreateCommand(MessageSharedPtr& msg) { + return ::utils::MakeShared<Command>(msg, app_mngr_); + } + + protected: + typedef CommandsTest<CommandsTestMocks::kIsNice>::MockAppManager + MockAppManager; + MockAppManager app_mngr_; + utils::SharedPtr<ApplicationImplTest> app_impl_; + MockHmiInterfaces mock_hmi_interfaces_; + NiceMock<event_engine_test::MockEventDispatcher> mock_event_dispatcher_; + NiceMock<MockApplicationManagerSettings> app_mngr_settings_; + utils::SharedPtr<application_manager_test::MockApplication> mock_app_; + ApplicationSet test_app_; + sync_primitives::Lock app_lock_; + DataAccessor<ApplicationSet> app_set_; + application_manager::MockMessageHelper& mock_message_helper_; + utils::SharedPtr<MockHelpPromptManager> mock_help_prompt_manager_; +}; + +void HelpPromptManagerTest::SetUp() { + ON_CALL(app_mngr_, hmi_interfaces()) + .WillByDefault(ReturnRef(mock_hmi_interfaces_)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceFromFunction(_)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_SDL)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + ON_CALL(app_mngr_, get_settings()) + .WillByDefault(ReturnRef(app_mngr_settings_)); + ON_CALL(app_mngr_, event_dispatcher()) + .WillByDefault(ReturnRef(mock_event_dispatcher_)); + ON_CALL(app_mngr_settings_, default_timeout()) + .WillByDefault(ReturnRef(kTimeout)); + ON_CALL(app_mngr_settings_, app_icons_folder()) + .WillByDefault(ReturnRef(kDirectoryName)); + ON_CALL(app_mngr_settings_, app_storage_folder()) + .WillByDefault(ReturnRef(kDirectoryName)); + ON_CALL(app_mngr_settings_, audio_data_stopped_timeout()) + .WillByDefault(Return(0)); + ON_CALL(app_mngr_settings_, video_data_stopped_timeout()) + .WillByDefault(Return(0)); + + mock_help_prompt_manager_ = + utils::SharedPtr<MockHelpPromptManager>(new MockHelpPromptManager()); + + HmiStatePtr state = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(mock_app_), + app_mngr_, + HmiState::STATE_ID_REGULAR); + + std::string path = file_system::CreateDirectory("storage"); + file_system::CreateFile(path + "/" + "certificate"); + + mock_app_ = utils::MakeShared<application_manager_test::MockApplication>(); +} + +void HelpPromptManagerTest::TearDown() { + Mock::VerifyAndClearExpectations(&mock_message_helper_); +} + +MessageSharedPtr HelpPromptManagerTest::CreateMsgParams() { + MessageSharedPtr msg = + ::utils::MakeShared<SmartObject>(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + return msg; +} + +void HelpPromptManagerTest::VRArraySetupHelper(MessageSharedPtr msg, + SmartObject& vr_help_title, + SmartObject& vr_help_array) { + (*msg)[am::strings::msg_params][am::strings::vr_help_title] = vr_help_title; + vr_help_array[0] = SmartObject(smart_objects::SmartType_Map); + vr_help_array[0][am::strings::text] = kText; + vr_help_array[0][am::strings::position] = kPosition; + (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help_array; +} + +void HelpPromptManagerTest::CreateBasicParamsVRRequest(MessageSharedPtr msg) { + SmartObject& msg_params = (*msg)[strings::msg_params]; + msg_params[strings::cmd_id] = kCmdId; + msg_params[strings::vr_commands] = + SmartObject(smart_objects::SmartType_Array); + msg_params[strings::vr_commands][0] = kFirstVrCommand; + msg_params[strings::type] = kPosition; + msg_params[strings::grammar_id] = kGrammarId; + msg_params[strings::info] = "VR info"; +} + +HmiStatePtr HelpPromptManagerTest::CreateTestHmiState() { + HmiStatePtr testState = utils::MakeShared<HmiState>( + static_cast<utils::SharedPtr<Application> >(app_impl_), + app_mngr_, + HmiState::STATE_ID_REGULAR); + testState->set_hmi_level(HMILevel::INVALID_ENUM); + testState->set_audio_streaming_state(AudioStreamingState::NOT_AUDIBLE); + testState->set_system_context(SystemContext::SYSCTXT_MAIN); + return testState; +} + +void HelpPromptManagerTest::CreateApplication( + MockHelpPromptManager& mock_help_prompt_manager) { + const std::string policy_app_id = "p_app_id"; + const std::string mac_address = "MA:CA:DD:RE:SS"; + const connection_handler::DeviceHandle device_id = 1; + const custom_str::CustomString app_name(""); + + app_impl_.reset( + new ApplicationImplTest(kAppId, + policy_app_id, + mac_address, + device_id, + app_name, + utils::MakeShared<MockStatisticsManager>(), + app_mngr_, + mock_help_prompt_manager)); + HmiStatePtr initial_state = CreateTestHmiState(); + app_impl_->SetInitialState(initial_state); +} + +TEST_F(HelpPromptManagerTest, AddCommand_OnVrCommandAdded) { + CreateApplication(*mock_help_prompt_manager_.get()); + MessageSharedPtr msg = + ::utils::MakeShared<SmartObject>(smart_objects::SmartType_Map); + CreateBasicParamsVRRequest(msg); + (*msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*msg)[strings::msg_params][strings::cmd_id] = kCmdId; + + EXPECT_CALL(*mock_help_prompt_manager_, + OnVrCommandAdded(kCmdId, (*msg)[strings::msg_params])); + + app_impl_->AddCommand(kCmdId, (*msg)[strings::msg_params]); +} + +TEST_F(HelpPromptManagerTest, RemoveCommand_OnVrCommandDeleted) { + CreateApplication(*mock_help_prompt_manager_.get()); + MessageSharedPtr msg = + ::utils::MakeShared<SmartObject>(smart_objects::SmartType_Map); + CreateBasicParamsVRRequest(msg); + (*msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*msg)[strings::msg_params][strings::cmd_id] = kCmdId; + + EXPECT_CALL(*mock_help_prompt_manager_, + OnVrCommandAdded(kCmdId, (*msg)[strings::msg_params])); + EXPECT_CALL(*mock_help_prompt_manager_, OnVrCommandDeleted(kCmdId)); + + app_impl_->AddCommand(kCmdId, (*msg)[strings::msg_params]); + app_impl_->RemoveCommand(kCmdId); +} + +TEST_F(HelpPromptManagerTest, + Request_OnSetGlobalPropertiesReceived_TTS_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject help_prompt(smart_objects::SmartType_Array); + help_prompt[0][am::strings::text] = "Help_Prompt_One"; + (*msg)[am::strings::msg_params][am::strings::help_prompt] = help_prompt; + SmartObject timeout_prompt(smart_objects::SmartType_Array); + timeout_prompt[0][am::strings::text] = "Timeout_Prompt_One"; + (*msg)[am::strings::msg_params][am::strings::timeout_prompt] = timeout_prompt; + + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL(*mock_app_, set_help_prompt(help_prompt)); + EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(&help_prompt)); + EXPECT_CALL(*mock_app_, set_timeout_prompt(timeout_prompt)); + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(&timeout_prompt)); + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, false)); + + SharedPtr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(HelpPromptManagerTest, + Request_OnSetGlobalPropertiesReceived_UI_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help_title("yes"); + SmartObject vr_help_array(smart_objects::SmartType_Array); + VRArraySetupHelper(msg, vr_help_title, vr_help_array); + (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help_array; + SmartObject menu_title("Menu_Title"); + (*msg)[am::strings::msg_params][am::hmi_request::menu_title] = menu_title; + SmartObject menu_icon(smart_objects::SmartType_Map); + menu_icon[am::strings::value] = "1"; + (*msg)[am::strings::msg_params][am::hmi_request::menu_icon] = menu_icon; + SmartObject keyboard_properties(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = + keyboard_properties; + + EXPECT_CALL(mock_message_helper_, VerifyImage(menu_icon, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(vr_help_array, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app_)); + + EXPECT_CALL(*mock_app_, set_vr_help_title(vr_help_title)); + EXPECT_CALL(*mock_app_, set_vr_help(vr_help_array)); + EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); + EXPECT_CALL(*mock_app_, vr_help()).WillOnce(Return(&vr_help_array)); + EXPECT_CALL(*mock_app_, set_menu_title(menu_title)); + EXPECT_CALL(*mock_app_, set_menu_icon(menu_icon)); + EXPECT_CALL(*mock_app_, set_keyboard_props(keyboard_properties)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, false)); + + SharedPtr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +} // namespace application_manager_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/test/include/application_manager/commands/commands_test.h b/src/components/application_manager/test/include/application_manager/commands/commands_test.h index b6733b5818..553126091f 100644 --- a/src/components/application_manager/test/include/application_manager/commands/commands_test.h +++ b/src/components/application_manager/test/include/application_manager/commands/commands_test.h @@ -44,7 +44,7 @@ #include "test/application_manager/mock_application_manager_settings.h" #include "application_manager/mock_hmi_interface.h" #include "application_manager/mock_application.h" - +#include "application_manager/mock_message_helper.h" namespace test { namespace components { namespace commands_test { @@ -54,6 +54,7 @@ namespace am = ::application_manager; using ::testing::ReturnRef; using ::testing::Return; using ::testing::NiceMock; +using ::testing::Mock; using ::testing::_; using ::utils::SharedPtr; @@ -63,6 +64,7 @@ using ::test::components::application_manager_test::MockApplicationManager; using ::test::components::application_manager_test:: MockApplicationManagerSettings; using am::ApplicationSharedPtr; +using am::MockMessageHelper; using ::test::components::application_manager_test::MockApplication; // Depending on the value type will be selected @@ -100,7 +102,9 @@ class CommandsTest : public ::testing::Test { MockApplication>::Result MockApp; typedef SharedPtr<MockApp> MockAppPtr; - virtual ~CommandsTest() {} + virtual ~CommandsTest() { + Mock::VerifyAndClearExpectations(&mock_message_helper_); + } static MessageSharedPtr CreateMessage( const smart_objects::SmartType type = smart_objects::SmartType_Null) { @@ -136,6 +140,7 @@ class CommandsTest : public ::testing::Test { MockAppManager app_mngr_; MockAppManagerSettings app_mngr_settings_; MOCK(am::MockHmiInterfaces) mock_hmi_interfaces_; + am::MockMessageHelper& mock_message_helper_; protected: virtual void InitCommand(const uint32_t& timeout) { @@ -145,13 +150,64 @@ class CommandsTest : public ::testing::Test { .WillByDefault(ReturnRef(timeout)); } - CommandsTest() { + CommandsTest() + : mock_message_helper_(*am::MockMessageHelper::message_helper_mock()) { ON_CALL(app_mngr_, hmi_interfaces()) .WillByDefault(ReturnRef(mock_hmi_interfaces_)); ON_CALL(mock_hmi_interfaces_, GetInterfaceFromFunction(_)) .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_SDL)); ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + Mock::VerifyAndClearExpectations(&mock_message_helper_); + InitHMIToMobileResultConverter(); + } + + void InitHMIToMobileResultConverter() { + namespace MobileResult = mobile_apis::Result; + namespace HMIResult = hmi_apis::Common_Result; + auto link_hmi_to_mob_result = + [this](HMIResult::eType hmi_result, MobileResult::eType mobile_result) { + ON_CALL(mock_message_helper_, HMIToMobileResult(hmi_result)) + .WillByDefault(Return(mobile_result)); + }; + link_hmi_to_mob_result(HMIResult::INVALID_ENUM, MobileResult::INVALID_ENUM); + link_hmi_to_mob_result(HMIResult::SUCCESS, MobileResult::SUCCESS); + link_hmi_to_mob_result(HMIResult::UNSUPPORTED_REQUEST, + MobileResult::UNSUPPORTED_REQUEST); + link_hmi_to_mob_result(HMIResult::UNSUPPORTED_RESOURCE, + MobileResult::UNSUPPORTED_RESOURCE); + link_hmi_to_mob_result(HMIResult::DISALLOWED, MobileResult::DISALLOWED); + link_hmi_to_mob_result(HMIResult::REJECTED, MobileResult::REJECTED); + link_hmi_to_mob_result(HMIResult::ABORTED, MobileResult::ABORTED); + link_hmi_to_mob_result(HMIResult::IGNORED, MobileResult::IGNORED); + link_hmi_to_mob_result(HMIResult::RETRY, MobileResult::RETRY); + link_hmi_to_mob_result(HMIResult::IN_USE, MobileResult::IN_USE); + link_hmi_to_mob_result(HMIResult::TIMED_OUT, MobileResult::TIMED_OUT); + link_hmi_to_mob_result(HMIResult::INVALID_DATA, MobileResult::INVALID_DATA); + link_hmi_to_mob_result(HMIResult::CHAR_LIMIT_EXCEEDED, + MobileResult::CHAR_LIMIT_EXCEEDED); + link_hmi_to_mob_result(HMIResult::INVALID_ID, MobileResult::INVALID_ID); + link_hmi_to_mob_result(HMIResult::DUPLICATE_NAME, + MobileResult::DUPLICATE_NAME); + link_hmi_to_mob_result(HMIResult::APPLICATION_NOT_REGISTERED, + MobileResult::APPLICATION_NOT_REGISTERED); + link_hmi_to_mob_result(HMIResult::WRONG_LANGUAGE, + MobileResult::WRONG_LANGUAGE); + link_hmi_to_mob_result(HMIResult::OUT_OF_MEMORY, + MobileResult::OUT_OF_MEMORY); + link_hmi_to_mob_result(HMIResult::TOO_MANY_PENDING_REQUESTS, + MobileResult::TOO_MANY_PENDING_REQUESTS); + link_hmi_to_mob_result(HMIResult::WARNINGS, MobileResult::WARNINGS); + link_hmi_to_mob_result(HMIResult::GENERIC_ERROR, + MobileResult::GENERIC_ERROR); + link_hmi_to_mob_result(HMIResult::USER_DISALLOWED, + MobileResult::USER_DISALLOWED); + link_hmi_to_mob_result(HMIResult::TRUNCATED_DATA, + MobileResult::TRUNCATED_DATA); + link_hmi_to_mob_result(HMIResult::SAVED, MobileResult::SAVED); + link_hmi_to_mob_result(HMIResult::DATA_NOT_AVAILABLE, + MobileResult::DATA_NOT_AVAILABLE); + link_hmi_to_mob_result(HMIResult::READ_ONLY, MobileResult::READ_ONLY); } }; diff --git a/src/components/application_manager/test/include/application_manager/mock_application.h b/src/components/application_manager/test/include/application_manager/mock_application.h index c24e4590f5..818a93fe6c 100644 --- a/src/components/application_manager/test/include/application_manager/mock_application.h +++ b/src/components/application_manager/test/include/application_manager/mock_application.h @@ -50,8 +50,11 @@ class MockApplication : public ::application_manager::Application { MOCK_CONST_METHOD0(active_message, const smart_objects::SmartObject*()); MOCK_CONST_METHOD0(curHash, const std::string&()); MOCK_METHOD0(UpdateHash, void()); - MOCK_CONST_METHOD0(flag_sending_hash_change_after_awake, bool()); - MOCK_METHOD1(set_flag_sending_hash_change_after_awake, void(bool flag)); + DEPRECATED MOCK_CONST_METHOD0(flag_sending_hash_change_after_awake, bool()); + DEPRECATED MOCK_METHOD1(set_flag_sending_hash_change_after_awake, + void(bool flag)); + MOCK_CONST_METHOD0(IsHashChangedDuringSuspend, bool()); + MOCK_METHOD1(SetHashChangedDuringSuspend, void(const bool flag)); MOCK_CONST_METHOD0(is_application_data_changed, bool()); MOCK_METHOD1(set_is_application_data_changed, void(bool state_application_data)); @@ -153,6 +156,9 @@ class MockApplication : public ::application_manager::Application { bool(mobile_apis::FunctionID::eType cmd_id, ::application_manager::TLimitSource source)); MOCK_METHOD0(usage_report, ::application_manager::UsageStatistics&()); + MOCK_METHOD0(help_prompt_manager, + ::application_manager::HelpPromptManager&()); + MOCK_METHOD1(SetInitialState, void(::application_manager::HmiStatePtr state)); MOCK_METHOD1(SetRegularState, void(::application_manager::HmiStatePtr state)); MOCK_METHOD1(SetPostponedState, void(::application_manager::HmiStatePtr state)); @@ -288,6 +294,10 @@ class MockApplication : public ::application_manager::Application { MOCK_CONST_METHOD0(IsRegistered, bool()); MOCK_CONST_METHOD0(SchemaUrl, std::string()); MOCK_CONST_METHOD0(PackageName, std::string()); + MOCK_METHOD1(PushMobileMessage, void(smart_objects::SmartObjectSPtr message)); + MOCK_METHOD1( + SwapMobileMessageQueue, + void(::application_manager::MobileMessageQueue& mobile_messages)); #ifdef SDL_REMOTE_CONTROL MOCK_METHOD1( @@ -313,7 +323,8 @@ class MockApplication : public ::application_manager::Application { bool(application_manager::AppExtensionPtr extention)); MOCK_METHOD1(RemoveExtension, bool(application_manager::AppExtensionUID uid)); MOCK_METHOD0(RemoveExtensions, void()); - MOCK_CONST_METHOD0(SubscribesIVI, const std::set<uint32_t>&()); + MOCK_CONST_METHOD0(SubscribesIVI, + const application_manager::VehicleInfoSubscriptions&()); #endif // SDL_REMOTE_CONTROL }; diff --git a/src/components/application_manager/test/include/application_manager/mock_application_helper.h b/src/components/application_manager/test/include/application_manager/mock_application_helper.h new file mode 100644 index 0000000000..1013af26bd --- /dev/null +++ b/src/components/application_manager/test/include/application_manager/mock_application_helper.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2017, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_APPLICATION_HELPER_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_APPLICATION_HELPER_H_ + +#include <gmock/gmock.h> +#include "application_manager/application.h" +#include "application_manager/application_manager.h" + +namespace test { +namespace components { +namespace application_manager_test { + +class MockApplicationHelper { + public: + MOCK_METHOD2(RecallApplicationData, + void(application_manager::ApplicationSharedPtr, + application_manager::ApplicationManager&)); + + static MockApplicationHelper& application_helper_mock(); +}; + +} // namespace application_manager_test +} // namespace components +} // namespace test + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_APPLICATION_HELPER_H_ diff --git a/src/components/application_manager/test/include/application_manager/mock_help_prompt_manager.h b/src/components/application_manager/test/include/application_manager/mock_help_prompt_manager.h new file mode 100644 index 0000000000..26eb8f6610 --- /dev/null +++ b/src/components/application_manager/test/include/application_manager/mock_help_prompt_manager.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2018, 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. +*/ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_HELP_PROMPT_MANAGER_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_HELP_PROMPT_MANAGER_H_ +#include "gmock/gmock.h" + +namespace test { +namespace components { +namespace application_manager_test { + +using namespace application_manager; + +class MockHelpPromptManager : public ::application_manager::HelpPromptManager { + public: + MockHelpPromptManager() {} + MOCK_METHOD2(OnVrCommandAdded, + void(uint32_t cmd_id, + const smart_objects::SmartObject& command)); + MOCK_METHOD1(OnVrCommandDeleted, void(uint32_t cmd_id)); + MOCK_METHOD0(OnTimeoutExpired, void()); + MOCK_METHOD2(OnSetGlobalPropertiesReceived, + void(const smart_objects::SmartObject& msg, bool is_response)); + MOCK_METHOD1(OnAppActivated, void(bool is_restore)); + MOCK_METHOD0(OnAppUnregistered, void()); +}; + +} // namespace application_manager_test +} // namespace components +} // namespace test + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_HELP_PROMPT_MANAGER_H_ diff --git a/src/components/application_manager/test/include/application_manager/mock_hmi_command_factory.h b/src/components/application_manager/test/include/application_manager/mock_hmi_command_factory.h new file mode 100644 index 0000000000..cf40d7b98b --- /dev/null +++ b/src/components/application_manager/test/include/application_manager/mock_hmi_command_factory.h @@ -0,0 +1,60 @@ +/* + Copyright (c) 2017, Ford Motor Company + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following + disclaimer in the documentation and/or other materials provided with the + distribution. + + Neither the name of the Ford Motor Company nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_HMI_COMMAND_FACTORY_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_HMI_COMMAND_FACTORY_H_ + +#include <gmock/gmock.h> +#include "application_manager/application_manager.h" +#include "application_manager/commands/command.h" +#include "smart_objects/smart_object.h" +#include "utils/shared_ptr.h" + +namespace test { +namespace components { +namespace application_manager_test { + +class MockHMICommandFactory { + public: + MOCK_METHOD2(CreateCommand, + utils::SharedPtr<application_manager::commands::Command>( + const utils::SharedPtr<smart_objects::SmartObject>&, + application_manager::ApplicationManager&)); + + static MockHMICommandFactory* mock_hmi_command_factory(); +}; + +} // namespace application_manager_test +} // namespace components +} // namespace test + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_HMI_COMMAND_FACTORY_H_ 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 f927f6bb72..93db0d9795 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 @@ -40,6 +40,7 @@ #include "application_manager/policies/policy_handler_interface.h" #include "application_manager/application_manager.h" #include "smart_objects/smart_object.h" +#include "transport_manager/common.h" namespace application_manager { @@ -266,8 +267,31 @@ class MockMessageHelper { MOCK_METHOD1(StringifiedHMILevel, std::string(const mobile_apis::HMILevel::eType hmi_level)); MOCK_METHOD2(GetDeviceMacAddressForHandle, - std::string(const uint32_t device_handle, + std::string(const transport_manager::DeviceHandle device_handle, const ApplicationManager& app_mngr)); + MOCK_METHOD3(SendDeleteCommandRequest, + void(smart_objects::SmartObject* cmd, + ApplicationSharedPtr application, + ApplicationManager& app_mngr)); + MOCK_METHOD3(SendDeleteSubmenuRequest, + void(smart_objects::SmartObject* cmd, + ApplicationSharedPtr application, + ApplicationManager& app_mngr)); + MOCK_METHOD3(SendDeleteChoiceSetRequest, + void(smart_objects::SmartObject* cmd, + ApplicationSharedPtr application, + ApplicationManager& app_mngr)); + MOCK_METHOD2(SendResetPropertiesRequest, + void(ApplicationSharedPtr application, + ApplicationManager& app_mngr)); + MOCK_METHOD3(SendUnsubscribeButtonNotification, + void(mobile_apis::ButtonName::eType button, + ApplicationSharedPtr application, + ApplicationManager& app_mngr)); + MOCK_METHOD3(SendUnsubscribeIVIRequest, + void(int32_t ivi_id, + ApplicationSharedPtr application, + ApplicationManager& app_mngr)); static MockMessageHelper* message_helper_mock(); }; diff --git a/src/components/application_manager/test/include/application_manager/mock_resume_ctrl.h b/src/components/application_manager/test/include/application_manager/mock_resume_ctrl.h index b06b207f84..fb264b7d82 100644 --- a/src/components/application_manager/test/include/application_manager/mock_resume_ctrl.h +++ b/src/components/application_manager/test/include/application_manager/mock_resume_ctrl.h @@ -48,7 +48,9 @@ class MockResumeCtrl : public resumption::ResumeCtrl { MOCK_METHOD1(RemoveApplicationFromSaved, bool(app_mngr::ApplicationConstSharedPtr application)); MOCK_METHOD0(OnSuspend, void()); + MOCK_METHOD0(OnIgnitionOff, void()); MOCK_METHOD0(OnAwake, void()); + MOCK_CONST_METHOD0(is_suspended, bool()); MOCK_METHOD0(StopSavePersistentDataTimer, void()); MOCK_METHOD2(StartResumption, bool(app_mngr::ApplicationSharedPtr application, diff --git a/src/components/application_manager/test/include/application_manager/mock_resumption_data.h b/src/components/application_manager/test/include/application_manager/mock_resumption_data.h index 7b16a3bf00..cfec034653 100644 --- a/src/components/application_manager/test/include/application_manager/mock_resumption_data.h +++ b/src/components/application_manager/test/include/application_manager/mock_resumption_data.h @@ -60,11 +60,13 @@ class MockResumptionData : public ::resumption::ResumptionData { uint32_t(const std::string& policy_app_id, const std::string& device_id)); MOCK_METHOD0(OnSuspend, void()); + MOCK_METHOD0(IncrementIgnOffCount, void()); MOCK_CONST_METHOD3(GetHashId, bool(const std::string& policy_app_id, const std::string& device_id, std::string& hash_id)); MOCK_METHOD0(OnAwake, void()); + MOCK_METHOD0(DecrementIgnOffCount, void()); MOCK_CONST_METHOD3(GetSavedApplication, bool(const std::string& policy_app_id, const std::string& device_id, diff --git a/src/components/application_manager/test/message_helper/CMakeLists.txt b/src/components/application_manager/test/message_helper/CMakeLists.txt index ccf05fc1c9..8ebb2dea0e 100755 --- a/src/components/application_manager/test/message_helper/CMakeLists.txt +++ b/src/components/application_manager/test/message_helper/CMakeLists.txt @@ -49,8 +49,8 @@ set(LIBRARIES if(REMOTE_CONTROL) SET (LIBRARIES - FunctionalModule - ${LIBRARIES} + FunctionalModule + ${LIBRARIES} ) endif(REMOTE_CONTROL) diff --git a/src/components/application_manager/test/mobile_message_handler_test.cc b/src/components/application_manager/test/mobile_message_handler_test.cc index 3f2ba0a3c5..2fe28d8249 100644 --- a/src/components/application_manager/test/mobile_message_handler_test.cc +++ b/src/components/application_manager/test/mobile_message_handler_test.cc @@ -169,7 +169,7 @@ class MobileMessageHandlerTest : public testing::Test { uint32_t correlation_id, uint32_t connection_key, const std::string& json_msg, - application_manager::BinaryData* data = NULL) { + const application_manager::BinaryData* data = NULL) { MobileMessage message = utils::MakeShared<Message>( MessagePriority::FromServiceType(ServiceType::kRpc)); message->set_function_id(function_id); @@ -256,10 +256,10 @@ TEST(mobile_message_test, basic_test) { MobileMessage message = utils::MakeShared<Message>(protocol_handler::MessagePriority::kDefault); EXPECT_FALSE(message->has_binary_data()); - application_manager::BinaryData* binary_data = - new application_manager::BinaryData; - binary_data->push_back('X'); - message->set_binary_data(binary_data); + application_manager::BinaryData binary_data; + binary_data.push_back('X'); + message->set_binary_data( + (const application_manager::BinaryData*)&binary_data); EXPECT_TRUE(message->has_binary_data()); } diff --git a/src/components/application_manager/test/mock_application_helper.cc b/src/components/application_manager/test/mock_application_helper.cc new file mode 100644 index 0000000000..c64a56e53e --- /dev/null +++ b/src/components/application_manager/test/mock_application_helper.cc @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2017, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "application_manager/mock_application_helper.h" + +namespace test { +namespace components { +namespace application_manager_test { + +MockApplicationHelper& MockApplicationHelper::application_helper_mock() { + static ::testing::NiceMock<MockApplicationHelper> application_helper_mock; + return application_helper_mock; +} + +} // application_manager_test +} // components +} // test + +namespace application_manager { + +void DeleteApplicationData(ApplicationSharedPtr app, + ApplicationManager& app_manager) { + test::components::application_manager_test::MockApplicationHelper:: + application_helper_mock().RecallApplicationData(app, app_manager); +} +} // application_managers diff --git a/src/components/application_manager/test/mock_hmi_command_factory.cc b/src/components/application_manager/test/mock_hmi_command_factory.cc new file mode 100644 index 0000000000..c2b4644f86 --- /dev/null +++ b/src/components/application_manager/test/mock_hmi_command_factory.cc @@ -0,0 +1,57 @@ +/* + Copyright (c) 2017, Ford Motor Company + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following + disclaimer in the documentation and/or other materials provided with the + distribution. + + Neither the name of the Ford Motor Company nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#include <gmock/gmock.h> +#include "application_manager/hmi_command_factory.h" +#include "application_manager/mock_hmi_command_factory.h" + +namespace test { +namespace components { +namespace application_manager_test { + +MockHMICommandFactory* MockHMICommandFactory::mock_hmi_command_factory() { + static MockHMICommandFactory mock_hmi_command_factory; + return &mock_hmi_command_factory; +} + +} // application_manager_test +} // components +} // test + +namespace application_manager { +CommandSharedPtr HMICommandFactory::CreateCommand( + const commands::MessageSharedPtr& message, + ApplicationManager& application_manager) { + return test::components::application_manager_test::MockHMICommandFactory:: + mock_hmi_command_factory()->CreateCommand(message, application_manager); +} +} // 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 5f221a105b..24bba63e71 100644 --- a/src/components/application_manager/test/mock_message_helper.cc +++ b/src/components/application_manager/test/mock_message_helper.cc @@ -33,6 +33,7 @@ #include "application_manager/message_helper.h" #include "application_manager/mock_message_helper.h" #include "application_manager/policies/policy_handler_interface.h" +#include "transport_manager/common.h" #include "gtest/gtest.h" #include "gmock/gmock.h" @@ -496,9 +497,52 @@ std::string MessageHelper::StringifiedHMILevel( } std::string MessageHelper::GetDeviceMacAddressForHandle( - const uint32_t device_handle, const ApplicationManager& app_mngr) { + const transport_manager::DeviceHandle device_handle, + const ApplicationManager& app_mngr) { return MockMessageHelper::message_helper_mock()->GetDeviceMacAddressForHandle( device_handle, app_mngr); } +void MessageHelper::SendDeleteCommandRequest(smart_objects::SmartObject* cmd, + ApplicationSharedPtr application, + ApplicationManager& app_mngr) { + return MockMessageHelper::message_helper_mock()->SendDeleteCommandRequest( + cmd, application, app_mngr); +} + +void MessageHelper::SendDeleteSubmenuRequest(smart_objects::SmartObject* cmd, + ApplicationSharedPtr application, + ApplicationManager& app_mngr) { + return MockMessageHelper::message_helper_mock()->SendDeleteSubmenuRequest( + cmd, application, app_mngr); +} + +void MessageHelper::SendDeleteChoiceSetRequest(smart_objects::SmartObject* cmd, + ApplicationSharedPtr application, + ApplicationManager& app_mngr) { + return MockMessageHelper::message_helper_mock()->SendDeleteChoiceSetRequest( + cmd, application, app_mngr); +} + +void MessageHelper::SendResetPropertiesRequest(ApplicationSharedPtr application, + ApplicationManager& app_mngr) { + return MockMessageHelper::message_helper_mock()->SendResetPropertiesRequest( + application, app_mngr); +} + +void MessageHelper::SendUnsubscribeButtonNotification( + mobile_apis::ButtonName::eType button, + ApplicationSharedPtr application, + ApplicationManager& app_mngr) { + return MockMessageHelper::message_helper_mock() + ->SendUnsubscribeButtonNotification(button, application, app_mngr); +} + +void MessageHelper::SendUnsubscribeIVIRequest(int32_t ivi_id, + ApplicationSharedPtr application, + ApplicationManager& app_mngr) { + return MockMessageHelper::message_helper_mock()->SendUnsubscribeIVIRequest( + ivi_id, application, app_mngr); +} + } // namespace application_manager diff --git a/src/components/application_manager/test/policy_handler_test.cc b/src/components/application_manager/test/policy_handler_test.cc index 4c3e882eae..d9e1cefa01 100644 --- a/src/components/application_manager/test/policy_handler_test.cc +++ b/src/components/application_manager/test/policy_handler_test.cc @@ -40,8 +40,10 @@ #include "connection_handler/connection_handler_impl.h" #include "application_manager/application_manager_impl.h" #include "application_manager/application_impl.h" +#ifdef ENABLE_SECURITY #include "security_manager/mock_security_manager.h" #include "security_manager/mock_crypto_manager.h" +#endif // ENABLE_SECURITY #include "application_manager/mock_message_helper.h" #include "connection_handler/mock_connection_handler_settings.h" #include "transport_manager/mock_transport_manager.h" @@ -406,7 +408,6 @@ TEST_F(PolicyHandlerTest, ReceiveMessageFromSDK_PTNotLoaded) { // Checks EXPECT_CALL(*mock_policy_manager_, LoadPT("", msg)).WillOnce(Return(false)); - EXPECT_CALL(*mock_policy_manager_, ForcePTExchange()).WillOnce(Return("")); EXPECT_CALL(app_manager_, GetNextHMICorrelationID()).Times(0); EXPECT_CALL(mock_message_helper_, CreateGetVehicleDataRequest(_, _, _)) .Times(0); @@ -803,8 +804,14 @@ void PolicyHandlerTest::TestActivateApp(const uint32_t connection_key, EXPECT_CALL(*application1, is_audio()).WillRepeatedly(Return(false)); EXPECT_CALL(mock_message_helper_, SendOnAppPermissionsChangedNotification(kAppId1_, _, _)); - EXPECT_CALL(mock_session_observer, - GetDataOnDeviceID(device_handle, _, _, _, _)); + EXPECT_CALL( + mock_session_observer, + GetDataOnDeviceID( + testing::Matcher<transport_manager::DeviceHandle>(device_handle), + _, + _, + _, + _)); #endif // EXTERNAL_PROPRIETARY_MODE EXPECT_CALL(*application1, policy_app_id()).WillOnce(Return(kPolicyAppId_)); @@ -1162,7 +1169,15 @@ TEST_F(PolicyHandlerTest, OnCurrentDeviceIdUpdateRequired) { EXPECT_CALL(conn_handler, get_session_observer()) .WillOnce(ReturnRef(session_observer)); - EXPECT_CALL(session_observer, GetDataOnDeviceID(0u, _, _, _, _)); + const transport_manager::DeviceHandle handle = 0u; + + EXPECT_CALL(session_observer, + GetDataOnDeviceID( + testing::Matcher<transport_manager::DeviceHandle>(handle), + _, + _, + _, + _)); // Act policy_handler_.OnCurrentDeviceIdUpdateRequired(kPolicyAppId_); @@ -1463,7 +1478,9 @@ TEST_F(PolicyHandlerTest, OnGetListOfPermissions) { EXPECT_CALL(app_manager_, application(app_id)) .WillRepeatedly(Return(mock_app_)); EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(std::string())); - EXPECT_CALL(mock_session_observer, GetDataOnDeviceID(_, _, _, _, _)); + EXPECT_CALL(mock_session_observer, + GetDataOnDeviceID( + testing::An<transport_manager::DeviceHandle>(), _, _, _, _)); policy_handler_.OnGetListOfPermissions(app_id, corr_id); } @@ -1489,7 +1506,9 @@ TEST_F(PolicyHandlerTest, OnGetListOfPermissions_WithoutConnectionKey) { EXPECT_CALL(app_manager_, applications()).WillRepeatedly(Return(app_set)); EXPECT_CALL(*mock_app_, device()).WillOnce(Return(0)); EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(std::string())); - EXPECT_CALL(mock_session_observer, GetDataOnDeviceID(_, _, _, _, _)); + EXPECT_CALL(mock_session_observer, + GetDataOnDeviceID( + testing::An<transport_manager::DeviceHandle>(), _, _, _, _)); #ifdef EXTERNAL_PROPRIETARY_MODE policy::ExternalConsentStatus external_consent_status = @@ -1563,7 +1582,9 @@ TEST_F(PolicyHandlerTest, OnGetListOfPermissions_GroupPermissions_SUCCESS) { EXPECT_CALL(app_manager_, applications()).WillRepeatedly(Return(app_set)); EXPECT_CALL(*mock_app_, device()).WillOnce(Return(0)); EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(std::string())); - EXPECT_CALL(mock_session_observer, GetDataOnDeviceID(_, _, _, _, _)); + EXPECT_CALL(mock_session_observer, + GetDataOnDeviceID( + testing::An<transport_manager::DeviceHandle>(), _, _, _, _)); #ifdef EXTERNAL_PROPRIETARY_MODE policy::ExternalConsentStatus external_consent_status = @@ -1581,6 +1602,7 @@ TEST_F(PolicyHandlerTest, OnGetListOfPermissions_GroupPermissions_SUCCESS) { policy_handler_.OnGetListOfPermissions(app_id, corr_id); } +#ifdef ENABLE_SECURITY TEST_F(PolicyHandlerTest, RetrieveCertificate) { // Arrange EnablePolicyAndPolicyManagerMock(); @@ -1589,6 +1611,7 @@ TEST_F(PolicyHandlerTest, RetrieveCertificate) { .WillOnce(Return(test_certificate)); EXPECT_EQ(test_certificate, policy_handler_.RetrieveCertificate()); } +#endif // ENABLE_SECURITY TEST_F(PolicyHandlerTest, OnSnapshotCreated_UrlNotAdded) { EnablePolicyAndPolicyManagerMock(); @@ -1806,6 +1829,7 @@ TEST_F(PolicyHandlerTest, OnDeviceConsentChanged_PredatePolicyNotAllowed) { policy_handler_.OnDeviceConsentChanged(kPolicyAppId_, is_allowed); } +#ifdef ENABLE_SECURITY #ifdef EXTERNAL_PROPRIETARY_MODE TEST_F(PolicyHandlerTest, OnCertificateUpdated) { const std::string app_storage = "storage"; @@ -1831,7 +1855,8 @@ TEST_F(PolicyHandlerTest, OnCertificateUpdated) { EXPECT_CALL(policy_handler_observer, OnCertificateUpdated(cert_data)); policy_handler_.OnCertificateUpdated(cert_data); } -#endif +#endif // EXTERNAL_PROPRIETARY_MODE +#endif // ENABLE_SECURITY TEST_F(PolicyHandlerTest, GetAppIdForSending_WithoutApps) { // Arrange @@ -1878,7 +1903,9 @@ void PolicyHandlerTest::GetAppIDForSending() { EXPECT_CALL(*mock_app_, IsRegistered()).WillOnce(Return(true)); EXPECT_CALL(*mock_app_, hmi_level()) .WillRepeatedly(Return(mobile_api::HMILevel::HMI_FULL)); - EXPECT_CALL(mock_session_observer, GetDataOnDeviceID(_, _, _, _, _)) + EXPECT_CALL(mock_session_observer, + GetDataOnDeviceID( + testing::An<transport_manager::DeviceHandle>(), _, _, _, _)) .WillOnce(DoAll(SetArgPointee<3>(kMacAddr_), Return(0))); EXPECT_CALL(*mock_policy_manager_, GetUserConsentForDevice(kMacAddr_)) @@ -1944,7 +1971,9 @@ TEST_F(PolicyHandlerTest, GetAppIdForSending_ExpectReturnAnyIdButNone) { // Check expectations - EXPECT_CALL(mock_session_observer, GetDataOnDeviceID(_, _, _, _, _)) + EXPECT_CALL(mock_session_observer, + GetDataOnDeviceID( + testing::An<transport_manager::DeviceHandle>(), _, _, _, _)) .WillOnce(DoAll(SetArgPointee<3>(kMacAddr_), Return(0))); EXPECT_CALL(*mock_policy_manager_, GetUserConsentForDevice(kMacAddr_)) @@ -1984,7 +2013,9 @@ TEST_F(PolicyHandlerTest, GetAppIdForSending_ExpectReturnAnyAppInNone) { // Check expectations - EXPECT_CALL(mock_session_observer, GetDataOnDeviceID(_, _, _, _, _)) + EXPECT_CALL(mock_session_observer, + GetDataOnDeviceID( + testing::An<transport_manager::DeviceHandle>(), _, _, _, _)) .WillOnce(DoAll(SetArgPointee<3>(kMacAddr_), Return(0))); EXPECT_CALL(*mock_policy_manager_, GetUserConsentForDevice(kMacAddr_)) @@ -2077,7 +2108,9 @@ TEST_F(PolicyHandlerTest, CanUpdate_TwoApplicationForSending_SUCCESS) { test_app.insert(mock_app_); test_app.insert(second_mock_app); - EXPECT_CALL(mock_session_observer, GetDataOnDeviceID(_, _, _, _, _)) + EXPECT_CALL(mock_session_observer, + GetDataOnDeviceID( + testing::An<transport_manager::DeviceHandle>(), _, _, _, _)) .WillOnce(DoAll(SetArgPointee<3>(kMacAddr_), Return(0))); EXPECT_CALL(*mock_policy_manager_, GetUserConsentForDevice(kMacAddr_)) @@ -2111,8 +2144,13 @@ TEST_F(PolicyHandlerTest, .WillOnce(ReturnRef(conn_handler)); EXPECT_CALL(conn_handler, get_session_observer()) .WillOnce(ReturnRef(mock_session_observer)); - EXPECT_CALL(mock_session_observer, GetDataOnDeviceID(device, _, NULL, _, _)) - .WillOnce(Return(1u)); + EXPECT_CALL(mock_session_observer, + GetDataOnDeviceID( + testing::Matcher<transport_manager::DeviceHandle>(device), + _, + NULL, + _, + _)).WillOnce(Return(1u)); EXPECT_CALL(app_manager_, application(kConnectionKey_)) .WillOnce(Return(mock_app_)); @@ -2265,7 +2303,10 @@ TEST_F(PolicyHandlerTest, EXPECT_CALL(*mock_app_, policy_app_id()) .WillRepeatedly(Return(kPolicyAppId_)); - EXPECT_CALL(mock_session_observer, GetDataOnDeviceID(_, _, NULL, _, _)) + EXPECT_CALL( + mock_session_observer, + GetDataOnDeviceID( + testing::An<transport_manager::DeviceHandle>(), _, NULL, _, _)) .WillRepeatedly(DoAll(SetDeviceParamsMacAdress(kMacAddr_), (Return(1u)))); EXPECT_CALL(app_manager_, connection_handler()) @@ -2326,7 +2367,10 @@ TEST_F(PolicyHandlerTest, EXPECT_CALL(*mock_app_, policy_app_id()) .WillRepeatedly(Return(kPolicyAppId_)); - EXPECT_CALL(mock_session_observer, GetDataOnDeviceID(_, _, NULL, _, _)) + EXPECT_CALL( + mock_session_observer, + GetDataOnDeviceID( + testing::An<transport_manager::DeviceHandle>(), _, NULL, _, _)) .WillRepeatedly(DoAll(SetDeviceParamsMacAdress(kMacAddr_), (Return(1u)))); EXPECT_CALL(app_manager_, connection_handler()) diff --git a/src/components/application_manager/test/request_controller/request_controller_test.cc b/src/components/application_manager/test/request_controller/request_controller_test.cc index e053d51c34..c2912fdc0b 100644 --- a/src/components/application_manager/test/request_controller/request_controller_test.cc +++ b/src/components/application_manager/test/request_controller/request_controller_test.cc @@ -62,6 +62,7 @@ using ::application_manager::request_controller::RequestInfo; using ::testing::Return; using ::testing::ReturnRef; using ::testing::NiceMock; +using ::testing::_; typedef NiceMock<application_manager_test::MockRequest> MRequest; typedef utils::SharedPtr<MRequest> RequestPtr; @@ -114,6 +115,7 @@ class RequestControllerTestClass : public ::testing::Test { RequestPtr output = utils::MakeShared<MRequest>(connection_key, correlation_id); ON_CALL(*output, default_timeout()).WillByDefault(Return(default_timeout)); + ON_CALL(*output, CheckPermissions()).WillByDefault(Return(true)); return output; } @@ -159,6 +161,40 @@ class RequestControllerTestClass : public ::testing::Test { }; TEST_F(RequestControllerTestClass, + AddMobileRequest_DuplicateCorrelationId_INVALID_ID) { + RequestPtr request_valid = GetMockRequest(); + TestAsyncWaiter waiter_valid; + ON_CALL(*request_valid, default_timeout()).WillByDefault(Return(0)); + EXPECT_CALL(*request_valid, Init()).WillOnce(Return(true)); + EXPECT_CALL(*request_valid, Run()) + .Times(1) + .WillRepeatedly(NotifyTestAsyncWaiter(&waiter_valid)); + + EXPECT_EQ(RequestController::SUCCESS, + AddRequest(default_settings_, + request_valid, + RequestInfo::RequestType::MobileRequest, + mobile_apis::HMILevel::HMI_NONE)); + EXPECT_TRUE(waiter_valid.WaitFor(1, 1000)); + + // The command should not be run if another command with the same + // correlation_id is waiting for a response + RequestPtr request_dup_corr_id = GetMockRequest(); + TestAsyncWaiter waiter_dup; + ON_CALL(*request_dup_corr_id, default_timeout()).WillByDefault(Return(0)); + EXPECT_CALL(*request_dup_corr_id, Init()).WillOnce(Return(true)); + ON_CALL(*request_dup_corr_id, Run()) + .WillByDefault(NotifyTestAsyncWaiter(&waiter_dup)); + + EXPECT_EQ(RequestController::SUCCESS, + AddRequest(default_settings_, + request_dup_corr_id, + RequestInfo::RequestType::MobileRequest, + mobile_apis::HMILevel::HMI_NONE)); + EXPECT_FALSE(waiter_dup.WaitFor(1, 1000)); +} + +TEST_F(RequestControllerTestClass, CheckPosibilitytoAdd_ZeroValueLimiters_SUCCESS) { // Test case than pending_requests_amount, // app_time_scale_max_requests_ and 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 f80842e250..2c2f69af95 100644 --- a/src/components/application_manager/test/resumption/resume_ctrl_test.cc +++ b/src/components/application_manager/test/resumption/resume_ctrl_test.cc @@ -37,6 +37,7 @@ #include "application_manager/resumption/resume_ctrl_impl.h" #include "application_manager/usage_statistics.h" #include "application_manager/mock_application.h" +#include "application_manager/mock_help_prompt_manager.h" #include "application_manager/mock_resumption_data.h" #include "interfaces/MOBILE_API.h" #include "application_manager/application_manager_impl.h" @@ -54,6 +55,7 @@ namespace components { namespace resumption_test { using ::testing::_; +using ::testing::A; using ::testing::Return; using ::testing::ReturnRef; using ::testing::DoAll; @@ -89,6 +91,8 @@ class ResumeCtrlTest : public ::testing::Test { ::utils::MakeShared<NiceMock<resumption_test::MockResumptionData> >( app_mngr_); app_mock_ = utils::MakeShared<NiceMock<MockApplication> >(); + mock_help_prompt_manager_ = + utils::SharedPtr<MockHelpPromptManager>(new MockHelpPromptManager()); const_app_ = static_cast<application_manager::ApplicationConstSharedPtr>(app_mock_); res_ctrl_ = utils::MakeShared<ResumeCtrlImpl>(app_mngr_); @@ -124,6 +128,7 @@ class ResumeCtrlTest : public ::testing::Test { utils::SharedPtr<NiceMock<resumption_test::MockResumptionData> > mock_storage_; utils::SharedPtr<NiceMock<MockApplication> > app_mock_; + utils::SharedPtr<MockHelpPromptManager> mock_help_prompt_manager_; application_manager::ApplicationConstSharedPtr const_app_; const uint32_t kTestAppId_; const std::string kTestPolicyAppId_; @@ -420,7 +425,7 @@ TEST_F(ResumeCtrlTest, StartResumption_AppWithSubscribeOnButtons) { smart_objects::SmartObject saved_app; saved_app[application_manager::strings::hash_id] = kHash_; saved_app[application_manager::strings::grammar_id] = kTestGrammarId_; - saved_app[application_manager::strings::application_subscribtions] = + saved_app[application_manager::strings::application_subscriptions] = test_subscriptions; // Check RestoreApplicationData @@ -452,9 +457,9 @@ TEST_F(ResumeCtrlTest, StartResumption_AppWithSubscriptionToIVI) { smart_objects::SmartObject test_subscriptions; smart_objects::SmartObject app_vi; - int vtype = application_manager::VehicleDataType::GPS; + int vtype = mobile_apis::VehicleDataType::VEHICLEDATA_GPS; uint i = 0; - for (; vtype < application_manager::VehicleDataType::STEERINGWHEEL; + for (; vtype < mobile_apis::VehicleDataType::VEHICLEDATA_STEERINGWHEEL; ++i, ++vtype) { app_vi[i] = vtype; } @@ -465,7 +470,7 @@ TEST_F(ResumeCtrlTest, StartResumption_AppWithSubscriptionToIVI) { smart_objects::SmartObject saved_app; saved_app[application_manager::strings::hash_id] = kHash_; saved_app[application_manager::strings::grammar_id] = kTestGrammarId_; - saved_app[application_manager::strings::application_subscribtions] = + saved_app[application_manager::strings::application_subscriptions] = test_subscriptions; // Check RestoreApplicationData @@ -481,7 +486,7 @@ TEST_F(ResumeCtrlTest, StartResumption_AppWithSubscriptionToIVI) { for (size_t i = 0; i < app_vi.length(); ++i) { EXPECT_CALL( *app_mock_, - SubscribeToIVI(static_cast<application_manager::VehicleDataType>(i))); + SubscribeToIVI(static_cast<mobile_apis::VehicleDataType::eType>(i))); } smart_objects::SmartObjectList requests; @@ -505,7 +510,9 @@ TEST_F(ResumeCtrlTest, StartResumption_AppWithSubscriptionToWayPoints) { GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); EXPECT_CALL(*app_mock_, set_grammar_id(kTestGrammarId_)); - EXPECT_CALL(app_mngr_, SubscribeAppForWayPoints(_)); + EXPECT_CALL( + app_mngr_, + SubscribeAppForWayPoints(A<application_manager::ApplicationSharedPtr>())); const mobile_apis::HMILevel::eType hmi_test_level = mobile_apis::HMILevel::HMI_FULL; ON_CALL(app_mngr_, GetDefaultHmiLevel(const_app_)) @@ -536,9 +543,16 @@ TEST_F(ResumeCtrlTest, StartAppHmiStateResumption_AppInFull) { saved_app[application_manager::strings::ign_off_count] = ign_off_count; saved_app[application_manager::strings::hmi_level] = restored_test_type; + ::application_manager::CommandsMap command; + DataAccessor<application_manager::CommandsMap> data_accessor(command, + app_set_lock_); + EXPECT_CALL(state_controller_, SetRegularState(_, restored_test_type)) .Times(AtLeast(1)); GetInfoFromApp(); + EXPECT_CALL(app_mngr_, GetDefaultHmiLevel(const_app_)) + .WillRepeatedly(Return(kDefaultTestLevel_)); + EXPECT_CALL(*app_mock_, commands_map()).WillRepeatedly(Return(data_accessor)); ON_CALL(*mock_storage_, GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); @@ -549,6 +563,8 @@ TEST_F(ResumeCtrlTest, StartAppHmiStateResumption_AppInFull) { ON_CALL(app_mngr_, GetUserConsentForDevice("12345")) .WillByDefault(Return(policy::kDeviceAllowed)); + EXPECT_CALL(*app_mock_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); res_ctrl_->StartAppHmiStateResumption(app_mock_); } @@ -576,6 +592,10 @@ TEST_F(ResumeCtrlTest, StartAppHmiStateResumption_AppInBackground) { TEST_F(ResumeCtrlTest, RestoreAppHMIState_RestoreHMILevelFull) { mobile_apis::HMILevel::eType restored_test_type = eType::HMI_FULL; + ::application_manager::CommandsMap command; + DataAccessor<application_manager::CommandsMap> data_accessor(command, + app_set_lock_); + smart_objects::SmartObject saved_app; saved_app[application_manager::strings::hash_id] = kHash_; saved_app[application_manager::strings::grammar_id] = kTestGrammarId_; @@ -584,6 +604,9 @@ TEST_F(ResumeCtrlTest, RestoreAppHMIState_RestoreHMILevelFull) { EXPECT_CALL(state_controller_, SetRegularState(_, restored_test_type)) .Times(AtLeast(1)); GetInfoFromApp(); + EXPECT_CALL(app_mngr_, GetDefaultHmiLevel(const_app_)) + .WillRepeatedly(Return(kDefaultTestLevel_)); + EXPECT_CALL(*app_mock_, commands_map()).WillRepeatedly(Return(data_accessor)); ON_CALL(*mock_storage_, GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); @@ -591,7 +614,8 @@ TEST_F(ResumeCtrlTest, RestoreAppHMIState_RestoreHMILevelFull) { ON_CALL(app_mngr_, GetUserConsentForDevice("12345")) .WillByDefault(Return(policy::kDeviceAllowed)); EXPECT_CALL(*app_mock_, set_is_resuming(true)); - + EXPECT_CALL(*app_mock_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); const bool res = res_ctrl_->RestoreAppHMIState(app_mock_); EXPECT_TRUE(res); } @@ -618,6 +642,10 @@ TEST_F(ResumeCtrlTest, SetupDefaultHMILevel) { TEST_F(ResumeCtrlTest, ApplicationResumptiOnTimer_AppInFull) { ON_CALL(app_mngr_, application(kTestAppId_)).WillByDefault(Return(app_mock_)); + ::application_manager::CommandsMap command; + DataAccessor<application_manager::CommandsMap> data_accessor(command, + app_set_lock_); + mobile_apis::HMILevel::eType restored_test_type = eType::HMI_FULL; const uint32_t ign_off_count = 0u; smart_objects::SmartObject saved_app; @@ -630,6 +658,9 @@ TEST_F(ResumeCtrlTest, ApplicationResumptiOnTimer_AppInFull) { EXPECT_CALL(state_controller, SetRegularState(_, restored_test_type)) .Times(AtLeast(1)); GetInfoFromApp(); + EXPECT_CALL(app_mngr_, GetDefaultHmiLevel(const_app_)) + .WillRepeatedly(Return(kDefaultTestLevel_)); + EXPECT_CALL(*app_mock_, commands_map()).WillRepeatedly(Return(data_accessor)); ON_CALL(*mock_storage_, GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); @@ -640,6 +671,8 @@ TEST_F(ResumeCtrlTest, ApplicationResumptiOnTimer_AppInFull) { ON_CALL(app_mngr_, GetUserConsentForDevice(kMacAddress_)) .WillByDefault(Return(policy::kDeviceAllowed)); + EXPECT_CALL(*app_mock_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); res_ctrl_->StartAppHmiStateResumption(app_mock_); } @@ -880,7 +913,7 @@ TEST_F(ResumeCtrlTest, CheckPersistenceFilesForResumption_WithChoiceSet) { // TODO (VVeremjova) APPLINK-16718 TEST_F(ResumeCtrlTest, DISABLED_OnSuspend) { - EXPECT_CALL(*mock_storage_, OnSuspend()); + EXPECT_CALL(*mock_storage_, IncrementIgnOffCount()); res_ctrl_->OnSuspend(); } @@ -896,7 +929,7 @@ TEST_F(ResumeCtrlTest, OnSuspend_EmptyApplicationlist) { ON_CALL(app_mngr_, applications()).WillByDefault(Return(accessor)); EXPECT_CALL(*mock_storage_, SaveApplication(mock_app)).Times(0); - EXPECT_CALL(*mock_storage_, OnSuspend()); + EXPECT_CALL(*mock_storage_, IncrementIgnOffCount()).Times(0); EXPECT_CALL(*mock_storage_, Persist()); res_ctrl_->OnSuspend(); } @@ -906,7 +939,7 @@ TEST_F(ResumeCtrlTest, OnAwake) { EXPECT_CALL(mock_application_manager_settings_, app_resumption_save_persistent_data_timeout()) .WillOnce(ReturnRef(timeout)); - EXPECT_CALL(*mock_storage_, OnAwake()); + EXPECT_CALL(*mock_storage_, DecrementIgnOffCount()).Times(0); res_ctrl_->OnAwake(); } diff --git a/src/components/application_manager/test/resumption/resumption_data_db_test.cc b/src/components/application_manager/test/resumption/resumption_data_db_test.cc index aa4db59eac..001e06ca58 100644 --- a/src/components/application_manager/test/resumption/resumption_data_db_test.cc +++ b/src/components/application_manager/test/resumption/resumption_data_db_test.cc @@ -165,7 +165,7 @@ class ResumptionDataDBTest : public ResumptionDataTest { "DELETE FROM `applicationCommandsArray`; " "DELETE FROM `applicationFilesArray`; " "DELETE FROM `applicationSubMenuArray`; " - "DELETE FROM `applicationSubscribtionsArray`; " + "DELETE FROM `applicationSubscriptionsArray`; " "DELETE FROM `_internal_data`; "; private: @@ -728,7 +728,7 @@ TEST_F(ResumptionDataDBTest, OnSuspend) { res_db()->SaveApplication(app_mock); CheckSavedDB(); - res_db()->OnSuspend(); + res_db()->IncrementIgnOffCount(); ign_off_count_++; CheckSavedDB(); } @@ -740,18 +740,18 @@ TEST_F(ResumptionDataDBTest, OnSuspendFourTimes) { res_db()->SaveApplication(app_mock); CheckSavedDB(); - res_db()->OnSuspend(); + res_db()->IncrementIgnOffCount(); ign_off_count_++; CheckSavedDB(); - res_db()->OnSuspend(); + res_db()->IncrementIgnOffCount(); ign_off_count_++; CheckSavedDB(); - res_db()->OnSuspend(); + res_db()->IncrementIgnOffCount(); ign_off_count_++; CheckSavedDB(); - res_db()->OnSuspend(); + res_db()->IncrementIgnOffCount(); ssize_t result = res_db()->IsApplicationSaved(policy_app_id_, kMacAddress_); EXPECT_EQ(-1, result); @@ -765,11 +765,11 @@ TEST_F(ResumptionDataDBTest, OnSuspendOnAwake) { res_db()->SaveApplication(app_mock); CheckSavedDB(); - res_db()->OnSuspend(); + res_db()->IncrementIgnOffCount(); ign_off_count_++; CheckSavedDB(); - res_db()->OnAwake(); + res_db()->DecrementIgnOffCount(); ign_off_count_ = 0; CheckSavedDB(); } @@ -782,7 +782,7 @@ TEST_F(ResumptionDataDBTest, Awake_AppNotSuspended) { res_db()->SaveApplication(app_mock); CheckSavedDB(); - res_db()->OnAwake(); + res_db()->DecrementIgnOffCount(); ign_off_count_ = 0; CheckSavedDB(); } @@ -795,12 +795,12 @@ TEST_F(ResumptionDataDBTest, TwiceAwake_AppNotSuspended) { res_db()->SaveApplication(app_mock); CheckSavedDB(); - res_db()->OnSuspend(); - res_db()->OnAwake(); + res_db()->IncrementIgnOffCount(); + res_db()->DecrementIgnOffCount(); ign_off_count_ = 0; CheckSavedDB(); - res_db()->OnAwake(); + res_db()->DecrementIgnOffCount(); CheckSavedDB(); } @@ -826,14 +826,14 @@ TEST_F(ResumptionDataDBTest, GetIgnOffTime_AfterSuspendAndAwake) { last_ign_off_time = res_db()->GetIgnOffTime(); EXPECT_EQ(0u, last_ign_off_time); - res_db()->OnSuspend(); + res_db()->IncrementIgnOffCount(); uint32_t after_suspend; after_suspend = res_db()->GetIgnOffTime(); EXPECT_LE(last_ign_off_time, after_suspend); uint32_t after_awake; - res_db()->OnAwake(); + res_db()->DecrementIgnOffCount(); after_awake = res_db()->GetIgnOffTime(); EXPECT_LE(after_suspend, after_awake); @@ -863,8 +863,8 @@ TEST_F(ResumptionDataDBTest, DropAppResumptionData) { EXPECT_TRUE(app.keyExists(am::strings::application_global_properties) && app[am::strings::application_global_properties].empty()); - EXPECT_TRUE(app.keyExists(am::strings::application_subscribtions) && - app[am::strings::application_subscribtions].empty()); + EXPECT_TRUE(app.keyExists(am::strings::application_subscriptions) && + app[am::strings::application_subscriptions].empty()); EXPECT_TRUE(app.keyExists(am::strings::application_files) && app[am::strings::application_files].empty()); diff --git a/src/components/application_manager/test/resumption/resumption_data_json_test.cc b/src/components/application_manager/test/resumption/resumption_data_json_test.cc index 834637fa62..a38afd8bdf 100644 --- a/src/components/application_manager/test/resumption/resumption_data_json_test.cc +++ b/src/components/application_manager/test/resumption/resumption_data_json_test.cc @@ -257,7 +257,7 @@ TEST_F(ResumptionDataJsonTest, OnSuspend) { res_json.SaveApplication(app_mock); CheckSavedJson(); - res_json.OnSuspend(); + res_json.IncrementIgnOffCount(); ign_off_count_++; CheckSavedJson(); } @@ -268,13 +268,13 @@ TEST_F(ResumptionDataJsonTest, OnSuspendFourTimes) { res_json.SaveApplication(app_mock); CheckSavedJson(); - res_json.OnSuspend(); + res_json.IncrementIgnOffCount(); ign_off_count_++; CheckSavedJson(); - res_json.OnSuspend(); - res_json.OnSuspend(); - res_json.OnSuspend(); + res_json.IncrementIgnOffCount(); + res_json.IncrementIgnOffCount(); + res_json.IncrementIgnOffCount(); EXPECT_TRUE(-1 != res_json.IsApplicationSaved(policy_app_id_, kMacAddress_)); } @@ -285,11 +285,11 @@ TEST_F(ResumptionDataJsonTest, OnSuspendOnAwake) { res_json.SaveApplication(app_mock); CheckSavedJson(); - res_json.OnSuspend(); + res_json.IncrementIgnOffCount(); ign_off_count_++; CheckSavedJson(); - res_json.OnAwake(); + res_json.DecrementIgnOffCount(); ign_off_count_ = 0; CheckSavedJson(); } @@ -300,7 +300,7 @@ TEST_F(ResumptionDataJsonTest, Awake_AppNotSuspended) { res_json.SaveApplication(app_mock); CheckSavedJson(); - res_json.OnAwake(); + res_json.DecrementIgnOffCount(); ign_off_count_ = 0; CheckSavedJson(); } @@ -311,12 +311,12 @@ TEST_F(ResumptionDataJsonTest, TwiceAwake_AppNotSuspended) { res_json.SaveApplication(app_mock); CheckSavedJson(); - res_json.OnSuspend(); - res_json.OnAwake(); + res_json.IncrementIgnOffCount(); + res_json.DecrementIgnOffCount(); ign_off_count_ = 0; CheckSavedJson(); - res_json.OnAwake(); + res_json.DecrementIgnOffCount(); CheckSavedJson(); } @@ -339,14 +339,14 @@ TEST_F(ResumptionDataJsonTest, GetIgnOffTime_AfterSuspendAndAwake) { last_ign_off_time = res_json.GetIgnOffTime(); EXPECT_EQ(0u, last_ign_off_time); - res_json.OnSuspend(); + res_json.IncrementIgnOffCount(); uint32_t after_suspend; after_suspend = res_json.GetIgnOffTime(); EXPECT_LE(last_ign_off_time, after_suspend); uint32_t after_awake; - res_json.OnAwake(); + res_json.DecrementIgnOffCount(); after_awake = res_json.GetIgnOffTime(); EXPECT_LE(after_suspend, after_awake); @@ -375,8 +375,8 @@ TEST_F(ResumptionDataJsonTest, DropAppDataResumption) { EXPECT_TRUE(app.keyExists(am::strings::application_global_properties) && app[am::strings::application_global_properties].empty()); - EXPECT_TRUE(app.keyExists(am::strings::application_subscribtions) && - app[am::strings::application_subscribtions].empty()); + EXPECT_TRUE(app.keyExists(am::strings::application_subscriptions) && + app[am::strings::application_subscriptions].empty()); EXPECT_TRUE(app.keyExists(am::strings::application_files) && app[am::strings::application_files].empty()); 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 79397f5175..65e01b6119 100644 --- a/src/components/application_manager/test/resumption/resumption_data_test.cc +++ b/src/components/application_manager/test/resumption/resumption_data_test.cc @@ -72,7 +72,7 @@ void ResumptionDataTest::CheckSavedApp(sm::SmartObject& resume_app_list) { CheckGlobalProporties( resume_app_list[am::strings::application_global_properties]); - CheckSubscriptions(resume_app_list[am::strings::application_subscribtions]); + CheckSubscriptions(resume_app_list[am::strings::application_subscriptions]); } void ResumptionDataTest::CheckCommands(sm::SmartObject& res_list) { @@ -539,8 +539,8 @@ void ResumptionDataTest::SetKeyboardProperties() { void ResumptionDataTest::SetSubscriptions() { btn_subscr.insert(ButtonName::eType::CUSTOM_BUTTON); btn_subscr.insert(ButtonName::eType::OK); - ivi.insert(0); - ivi.insert(5); + ivi.insert(static_cast<mobile_apis::VehicleDataType::eType>(0)); + ivi.insert(static_cast<mobile_apis::VehicleDataType::eType>(5)); } } // namespace resumption_test diff --git a/src/components/application_manager/test/resumption_sql_queries_test.cc b/src/components/application_manager/test/resumption_sql_queries_test.cc index 08fa0a3eb5..28a3383086 100644 --- a/src/components/application_manager/test/resumption_sql_queries_test.cc +++ b/src/components/application_manager/test/resumption_sql_queries_test.cc @@ -79,7 +79,7 @@ const string kDeleteData = "DELETE FROM `applicationCommandsArray`; " "DELETE FROM `applicationFilesArray`; " "DELETE FROM `applicationSubMenuArray`; " - "DELETE FROM `applicationSubscribtionsArray`; " + "DELETE FROM `applicationSubscriptionsArray`; " "DELETE FROM `_internal_data`; " "COMMIT; " "VACUUM;"; @@ -326,7 +326,7 @@ class ResumptionSqlQueriesTest : public ::testing::Test { db_schema.push_back("applicationCommandsArray"); db_schema.push_back("applicationFilesArray"); db_schema.push_back("applicationSubMenuArray"); - db_schema.push_back("applicationSubscribtionsArray"); + db_schema.push_back("applicationSubscriptionsArray"); db_schema.push_back("_internal_data"); std::sort(db_schema.begin(), db_schema.end()); } @@ -1386,7 +1386,7 @@ TEST_F(ResumptionSqlQueriesTest, } TEST_F(ResumptionSqlQueriesTest, - kDeleteApplicationSubscribtionsArray_ExpectDataDeleted) { + kDeleteApplicationSubscriptionsArray_ExpectDataDeleted) { // Arrange SQLQuery temp_query(db()); int64_t key1 = FillImageTable(temp_query, 1, test_image).LastInsertId(); @@ -1410,12 +1410,12 @@ TEST_F(ResumptionSqlQueriesTest, key1 = FillApplicationFilesArrayTable(temp_query, key1, key2).LastInsertId(); FillAppSubscriptionsArrayTable(temp_query, 7, 2, key1); // Check - const std::string select_count_applicationSubscribtionsArray = - "SELECT COUNT(*) FROM applicationSubscribtionsArray;"; + const std::string select_count_applicationSubscriptionsArray = + "SELECT COUNT(*) FROM applicationSubscriptionsArray;"; ValToPosPair p1(0, app_id2); ValToPosPair p2(1, device_id); - CheckDeleteQuery(select_count_applicationSubscribtionsArray, - kDeleteApplicationSubscribtionsArray, + CheckDeleteQuery(select_count_applicationSubscriptionsArray, + kDeleteApplicationSubscriptionsArray, p1, p2, 1, @@ -2211,17 +2211,17 @@ TEST_F(ResumptionSqlQueriesTest, kInsertSubscriptions_ExpectDataInserted) { SQLQuery temp_query(db()); FillAppSubscriptionsArrayTable(temp_query, 2, 3, 4); // Checks - const std::string select_count_applicationSubscribtionsArray = - "SELECT COUNT(*) FROM applicationSubscribtionsArray;"; - CheckSelectQuery(select_count_applicationSubscribtionsArray, 1, 0); + const std::string select_count_applicationSubscriptionsArray = + "SELECT COUNT(*) FROM applicationSubscriptionsArray;"; + CheckSelectQuery(select_count_applicationSubscriptionsArray, 1, 0); const std::string select_idApplication = - "SELECT idApplication FROM applicationSubscribtionsArray;"; + "SELECT idApplication FROM applicationSubscriptionsArray;"; CheckSelectQuery(select_idApplication, 4, 0); const std::string select_vehicleValue = - "SELECT vehicleValue FROM applicationSubscribtionsArray;"; + "SELECT vehicleValue FROM applicationSubscriptionsArray;"; CheckSelectQuery(select_vehicleValue, 2, 0); const std::string select_ButtonNameValue = - "SELECT ButtonNameValue FROM applicationSubscribtionsArray;"; + "SELECT ButtonNameValue FROM applicationSubscriptionsArray;"; CheckSelectQuery(select_ButtonNameValue, 3, 0); } diff --git a/src/components/application_manager/test/sdl_preloaded_pt.json b/src/components/application_manager/test/sdl_preloaded_pt.json index d6f34c12fc..10894516cf 100644 --- a/src/components/application_manager/test/sdl_preloaded_pt.json +++ b/src/components/application_manager/test/sdl_preloaded_pt.json @@ -14,7 +14,7 @@ 625], "endpoints": { "0x07": { - "default": ["http://policies.telematics.ford.com/api/policies"] + "default": ["http://x.x.x.x:3000/api/1/policies"] } }, "notifications_per_minute_by_priority": { diff --git a/src/components/application_manager/test/sdl_pt_update.json b/src/components/application_manager/test/sdl_pt_update.json index a332f92382..f890e8e5ae 100644 --- a/src/components/application_manager/test/sdl_pt_update.json +++ b/src/components/application_manager/test/sdl_pt_update.json @@ -1,7 +1,7 @@ { "policy_table" : { "app_policies" : { - "1766825573" : { + "1010101010" : { "AppHMIType" : [ "MEDIA" ], "certificate" : "akdjfhaliuygrglurng", "default_hmi" : "BACKGROUND", @@ -1698,7 +1698,7 @@ }, "endpoints" : { "0x07" : { - "default" : [ "http://policies.telematics.ford.com/api/policies" ] + "default" : [ "http://x.x.x.x:3000/api/1/policies" ] } }, "exchange_after_x_days" : 30, diff --git a/src/components/application_manager/test/state_controller/state_controller_test.cc b/src/components/application_manager/test/state_controller/state_controller_test.cc index eb718c8b8b..fe4d1d2ee8 100644 --- a/src/components/application_manager/test/state_controller/state_controller_test.cc +++ b/src/components/application_manager/test/state_controller/state_controller_test.cc @@ -213,7 +213,7 @@ class StateControllerImplTest : public ::testing::Test { namespace SystemContext = mobile_apis::SystemContext; am::HmiStatePtr state = - utils::MakeShared<am::HmiState>(simple_app_id_, app_manager_mock_); + utils::MakeShared<am::HmiState>(simple_app_, app_manager_mock_); state->set_hmi_level(hmi_level); state->set_audio_streaming_state(aidio_ss); state->set_system_context(system_context); @@ -229,9 +229,9 @@ class StateControllerImplTest : public ::testing::Test { const mobile_apis::HMILevel::eType hmi_level, const mobile_apis::AudioStreamingState::eType audio_ss, const mobile_apis::SystemContext::eType system_context, - const uint32_t app_id) { + const am::ApplicationSharedPtr app) { am::HmiStatePtr new_state = - utils::MakeShared<HmiStateType>(app_id, app_manager_mock_); + utils::MakeShared<HmiStateType>(app, app_manager_mock_); new_state->set_hmi_level(hmi_level); new_state->set_audio_streaming_state(audio_ss); @@ -591,9 +591,9 @@ class StateControllerImplTest : public ::testing::Test { app_type = AppType(app_id); app = (*it_begin); am::HmiStatePtr state_first = - utils::MakeShared<T>(app_id, app_manager_mock_); + utils::MakeShared<T>(app, app_manager_mock_); am::HmiStatePtr state_second = - utils::MakeShared<Q>(app_id, app_manager_mock_); + utils::MakeShared<Q>(app, app_manager_mock_); TestSetSeveralState( app, state_first, state_second, app_type, call_back_result); TestSetSeveralState( @@ -1829,7 +1829,7 @@ TEST_F(StateControllerImplTest, DISABLED_ActivateAppSuccessReceivedFromHMI) { for (; it != hmi_states.end(); ++it) { am::HmiStatePtr hmi_state = it->first; - am::HmiStatePtr initial_hmi_state = it->first; + am::HmiStatePtr initial_hmi_state = it2->first; Common_HMILevel::eType hmi_level = it->second; SetBCActivateAppRequestToHMI(hmi_level, corr_id); @@ -1981,8 +1981,8 @@ TEST_F(StateControllerImplTest, ApplyTempStatesForMediaNaviVCApp) { } TEST_F(StateControllerImplTest, SetStatePhoneCallForNonMediaApplication) { - am::HmiStatePtr state_phone_call = utils::MakeShared<am::PhoneCallHmiState>( - simple_app_id_, app_manager_mock_); + am::HmiStatePtr state_phone_call = + utils::MakeShared<am::PhoneCallHmiState>(simple_app_, app_manager_mock_); TestSetState(simple_app_, state_phone_call, APP_TYPE_NON_MEDIA, @@ -1990,8 +1990,8 @@ TEST_F(StateControllerImplTest, SetStatePhoneCallForNonMediaApplication) { } TEST_F(StateControllerImplTest, SetStatePhoneCallForMediaApplication) { - am::HmiStatePtr state_phone_call = utils::MakeShared<am::PhoneCallHmiState>( - media_app_id_, app_manager_mock_); + am::HmiStatePtr state_phone_call = + utils::MakeShared<am::PhoneCallHmiState>(media_app_, app_manager_mock_); TestSetState(media_app_, state_phone_call, APP_TYPE_MEDIA, @@ -2000,7 +2000,7 @@ TEST_F(StateControllerImplTest, SetStatePhoneCallForMediaApplication) { TEST_F(StateControllerImplTest, SetStatePhoneCallForMediaNaviApplication) { am::HmiStatePtr state_phone_call = utils::MakeShared<am::PhoneCallHmiState>( - media_navi_app_id_, app_manager_mock_); + media_navi_app_, app_manager_mock_); TestSetState(media_navi_app_, state_phone_call, APP_TYPE_NAVI, @@ -2009,7 +2009,7 @@ TEST_F(StateControllerImplTest, SetStatePhoneCallForMediaNaviApplication) { TEST_F(StateControllerImplTest, SetVRStateForNonMediaApplication) { am::HmiStatePtr state_vr = - utils::MakeShared<am::VRHmiState>(simple_app_id_, app_manager_mock_); + utils::MakeShared<am::VRHmiState>(simple_app_, app_manager_mock_); TestSetState(simple_app_, state_vr, APP_TYPE_NON_MEDIA, @@ -2018,7 +2018,7 @@ TEST_F(StateControllerImplTest, SetVRStateForNonMediaApplication) { TEST_F(StateControllerImplTest, SetVRStateForMediaApplication) { am::HmiStatePtr state_vr = - utils::MakeShared<am::VRHmiState>(media_app_id_, app_manager_mock_); + utils::MakeShared<am::VRHmiState>(media_app_, app_manager_mock_); TestSetState(media_app_, state_vr, APP_TYPE_MEDIA, @@ -2026,8 +2026,8 @@ TEST_F(StateControllerImplTest, SetVRStateForMediaApplication) { } TEST_F(StateControllerImplTest, SetVRStateForMediaNaviVoiceApplication) { - am::HmiStatePtr state_vr = utils::MakeShared<am::VRHmiState>( - media_navi_vc_app_id_, app_manager_mock_); + am::HmiStatePtr state_vr = + utils::MakeShared<am::VRHmiState>(media_navi_vc_app_, app_manager_mock_); TestSetState(media_navi_vc_app_, state_vr, APP_TYPE_MEDIA, @@ -2037,7 +2037,7 @@ TEST_F(StateControllerImplTest, SetVRStateForMediaNaviVoiceApplication) { TEST_F(StateControllerImplTest, SetTTSStateForNonMediaApplicationAttenuatedNotSupported) { am::HmiStatePtr state_tts = - utils::MakeShared<am::TTSHmiState>(simple_app_id_, app_manager_mock_); + utils::MakeShared<am::TTSHmiState>(simple_app_, app_manager_mock_); EXPECT_CALL(app_manager_mock_, is_attenuated_supported()) .WillRepeatedly(Return(false)); TestSetState(simple_app_, @@ -2049,7 +2049,7 @@ TEST_F(StateControllerImplTest, TEST_F(StateControllerImplTest, SetTTSStateForNonMediaApplicationAttenuatedSupported) { am::HmiStatePtr state_tts = - utils::MakeShared<am::TTSHmiState>(simple_app_id_, app_manager_mock_); + utils::MakeShared<am::TTSHmiState>(simple_app_, app_manager_mock_); EXPECT_CALL(app_manager_mock_, is_attenuated_supported()) .WillRepeatedly(Return(true)); TestSetState(simple_app_, @@ -2061,7 +2061,7 @@ TEST_F(StateControllerImplTest, TEST_F(StateControllerImplTest, SetTTSStateForMediaApplicationAttenuatedNotSupported) { am::HmiStatePtr state_tts = - utils::MakeShared<am::TTSHmiState>(media_app_id_, app_manager_mock_); + utils::MakeShared<am::TTSHmiState>(media_app_, app_manager_mock_); EXPECT_CALL(app_manager_mock_, is_attenuated_supported()) .WillRepeatedly(Return(false)); TestSetState(media_app_, @@ -2073,7 +2073,7 @@ TEST_F(StateControllerImplTest, TEST_F(StateControllerImplTest, SetTTSStateForMediaApplicationAttenuatedSupported) { am::HmiStatePtr state_tts = - utils::MakeShared<am::TTSHmiState>(media_app_id_, app_manager_mock_); + utils::MakeShared<am::TTSHmiState>(media_app_, app_manager_mock_); EXPECT_CALL(app_manager_mock_, is_attenuated_supported()) .WillRepeatedly(Return(true)); TestSetState(media_app_, @@ -2084,8 +2084,8 @@ TEST_F(StateControllerImplTest, TEST_F(StateControllerImplTest, SetTTSStateForMediaNaviVCApplicationAttenuatedNotSupported) { - am::HmiStatePtr state_tts = utils::MakeShared<am::TTSHmiState>( - media_navi_vc_app_id_, app_manager_mock_); + am::HmiStatePtr state_tts = + utils::MakeShared<am::TTSHmiState>(media_navi_vc_app_, app_manager_mock_); EXPECT_CALL(app_manager_mock_, is_attenuated_supported()) .WillRepeatedly(Return(false)); TestSetState(media_navi_vc_app_, @@ -2096,8 +2096,8 @@ TEST_F(StateControllerImplTest, TEST_F(StateControllerImplTest, SetTTSStateForMediaNaviVCApplicationAttenuatedSupported) { - am::HmiStatePtr state_tts = utils::MakeShared<am::TTSHmiState>( - media_navi_vc_app_id_, app_manager_mock_); + am::HmiStatePtr state_tts = + utils::MakeShared<am::TTSHmiState>(media_navi_vc_app_, app_manager_mock_); EXPECT_CALL(app_manager_mock_, is_attenuated_supported()) .WillRepeatedly(Return(true)); TestSetState(media_navi_vc_app_, @@ -2108,7 +2108,7 @@ TEST_F(StateControllerImplTest, TEST_F(StateControllerImplTest, SetNaviStreamingStateForNonMediaApplication) { am::HmiStatePtr state_navi_streming = - utils::MakeShared<am::NaviStreamingHmiState>(simple_app_id_, + utils::MakeShared<am::NaviStreamingHmiState>(simple_app_, app_manager_mock_); TestSetState(simple_app_, state_navi_streming, @@ -2119,7 +2119,7 @@ TEST_F(StateControllerImplTest, SetNaviStreamingStateForNonMediaApplication) { TEST_F(StateControllerImplTest, SetNaviStreamingStateMediaApplicationAttenuatedNotSupported) { am::HmiStatePtr state_navi_streming = - utils::MakeShared<am::NaviStreamingHmiState>(media_app_id_, + utils::MakeShared<am::NaviStreamingHmiState>(media_app_, app_manager_mock_); EXPECT_CALL(app_manager_mock_, is_attenuated_supported()) .WillRepeatedly(Return(false)); @@ -2132,7 +2132,7 @@ TEST_F(StateControllerImplTest, TEST_F(StateControllerImplTest, SetNaviStreamingStateMediaApplicationAttenuatedSupported) { am::HmiStatePtr state_navi_streming = - utils::MakeShared<am::NaviStreamingHmiState>(media_app_id_, + utils::MakeShared<am::NaviStreamingHmiState>(media_app_, app_manager_mock_); EXPECT_CALL(app_manager_mock_, is_attenuated_supported()) .WillRepeatedly(Return(true)); @@ -2145,8 +2145,7 @@ TEST_F(StateControllerImplTest, TEST_F(StateControllerImplTest, SetNaviStreamingStateVCApplicationAttenuatedNotSupported) { am::HmiStatePtr state_navi_streming = - utils::MakeShared<am::NaviStreamingHmiState>(vc_app_id_, - app_manager_mock_); + utils::MakeShared<am::NaviStreamingHmiState>(vc_app_, app_manager_mock_); EXPECT_CALL(app_manager_mock_, is_attenuated_supported()) .WillRepeatedly(Return(false)); TestSetState(vc_app_, @@ -2158,8 +2157,7 @@ TEST_F(StateControllerImplTest, TEST_F(StateControllerImplTest, SetNaviStreamingStateVCApplicationAttenuatedSupported) { am::HmiStatePtr state_navi_streming = - utils::MakeShared<am::NaviStreamingHmiState>(vc_app_id_, - app_manager_mock_); + utils::MakeShared<am::NaviStreamingHmiState>(vc_app_, app_manager_mock_); EXPECT_CALL(app_manager_mock_, is_attenuated_supported()) .WillRepeatedly(Return(true)); TestSetState(vc_app_, @@ -2170,7 +2168,7 @@ TEST_F(StateControllerImplTest, TEST_F(StateControllerImplTest, SetNaviStreamingStateNaviApplication) { am::HmiStatePtr state_navi_streming = - utils::MakeShared<am::NaviStreamingHmiState>(navi_app_id_, + utils::MakeShared<am::NaviStreamingHmiState>(navi_app_, app_manager_mock_); TestSetState(navi_app_, state_navi_streming, @@ -2180,7 +2178,7 @@ TEST_F(StateControllerImplTest, SetNaviStreamingStateNaviApplication) { TEST_F(StateControllerImplTest, SetNaviStreamingStateMediaNaviApplication) { am::HmiStatePtr state_navi_streming = - utils::MakeShared<am::NaviStreamingHmiState>(media_navi_app_id_, + utils::MakeShared<am::NaviStreamingHmiState>(media_navi_app_, app_manager_mock_); TestSetState(media_navi_app_, state_navi_streming, @@ -2189,8 +2187,8 @@ TEST_F(StateControllerImplTest, SetNaviStreamingStateMediaNaviApplication) { } TEST_F(StateControllerImplTest, SetSafetyModeStateForNonMediaApplication) { - am::HmiStatePtr state_safety_mode = utils::MakeShared<am::SafetyModeHmiState>( - simple_app_id_, app_manager_mock_); + am::HmiStatePtr state_safety_mode = + utils::MakeShared<am::SafetyModeHmiState>(simple_app_, app_manager_mock_); TestSetState(simple_app_, state_safety_mode, APP_TYPE_NON_MEDIA, @@ -2199,7 +2197,7 @@ TEST_F(StateControllerImplTest, SetSafetyModeStateForNonMediaApplication) { TEST_F(StateControllerImplTest, SetSafetyModeStateForMediaApplication) { am::HmiStatePtr state_safety_mode = - utils::MakeShared<am::VRHmiState>(media_app_id_, app_manager_mock_); + utils::MakeShared<am::VRHmiState>(media_app_, app_manager_mock_); TestSetState(media_app_, state_safety_mode, APP_TYPE_MEDIA, @@ -2208,8 +2206,8 @@ TEST_F(StateControllerImplTest, SetSafetyModeStateForMediaApplication) { TEST_F(StateControllerImplTest, SetSafetyModeStateForMediaNaviVoiceApplication) { - am::HmiStatePtr state_safety_mode = utils::MakeShared<am::VRHmiState>( - media_navi_vc_app_id_, app_manager_mock_); + am::HmiStatePtr state_safety_mode = + utils::MakeShared<am::VRHmiState>(media_navi_vc_app_, app_manager_mock_); TestSetState(media_navi_vc_app_, state_safety_mode, APP_TYPE_MEDIA, @@ -2909,7 +2907,7 @@ TEST_F(StateControllerImplTest, OnApplicationRegisteredDifferentStates) { mobile_apis::HMILevel::HMI_FULL, mobile_apis::AudioStreamingState::AUDIBLE, mobile_apis::SystemContext::SYSCTXT_MAIN, - app_id); + simple_app_); EXPECT_CALL(*simple_app_ptr_, app_id()).WillRepeatedly(Return(app_id)); EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) @@ -2921,7 +2919,7 @@ TEST_F(StateControllerImplTest, OnApplicationRegisteredDifferentStates) { mobile_apis::HMILevel::HMI_BACKGROUND, mobile_apis::AudioStreamingState::AUDIBLE, mobile_apis::SystemContext::SYSCTXT_MAIN, - app_id); + simple_app_); EXPECT_CALL(*simple_app_ptr_, RegularHmiState()).WillOnce(Return(old_state)); EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) @@ -2958,7 +2956,7 @@ TEST_F(StateControllerImplTest, OnApplicationRegisteredEqualStates) { mobile_apis::HMILevel::HMI_FULL, mobile_apis::AudioStreamingState::AUDIBLE, mobile_apis::SystemContext::SYSCTXT_MAIN, - app_id); + simple_app_); EXPECT_CALL(*simple_app_ptr_, app_id()).WillRepeatedly(Return(app_id)); EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) @@ -2970,7 +2968,7 @@ TEST_F(StateControllerImplTest, OnApplicationRegisteredEqualStates) { mobile_apis::HMILevel::HMI_BACKGROUND, mobile_apis::AudioStreamingState::AUDIBLE, mobile_apis::SystemContext::SYSCTXT_MAIN, - app_id); + simple_app_); EXPECT_CALL(*simple_app_ptr_, RegularHmiState()) .WillOnce(Return(default_state)); EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) |