diff options
author | JackLivio <jack@livio.io> | 2018-02-12 16:16:18 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-12 16:16:18 -0500 |
commit | 3e0852ef27d0fff950ea4a1dae136c972c40c759 (patch) | |
tree | 4d1aed127f42444c740a1c414c01177e70340b81 /src/components/application_manager | |
parent | 11ce1efd850cadbe63a9ac8017b49b372afc5c3f (diff) | |
parent | 37614e497366fb2a91f788da72fc9046527fcff2 (diff) | |
download | sdl_core-3e0852ef27d0fff950ea4a1dae136c972c40c759.tar.gz |
Merge branch 'release/4.5.0' into fix/OnDriverDistruction
Diffstat (limited to 'src/components/application_manager')
86 files changed, 3980 insertions, 600 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 c0a1007541..0c93f7447b 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -48,6 +48,7 @@ #include "application_manager/application_state.h" #include "protocol_handler/protocol_handler.h" #include "smart_objects/smart_object.h" +#include "utils/macro.h" namespace application_manager { @@ -414,6 +415,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 @@ -552,7 +567,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; @@ -609,6 +625,13 @@ class Application : public virtual InitialApplicationData, virtual UsageStatistics& usage_report() = 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 * * @param state state to setup @@ -698,6 +721,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. * @@ -755,16 +788,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 { 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 2a2c18e116..32804d9e93 100644 --- a/src/components/application_manager/include/application_manager/application_impl.h +++ b/src/components/application_manager/include/application_manager/application_impl.h @@ -52,6 +52,7 @@ #include "utils/atomic_object.h" #include "utils/custom_string.h" #include "utils/timer.h" +#include "utils/macro.h" namespace usage_statistics { @@ -65,6 +66,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 +87,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,17 +221,28 @@ 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(); bool AreCommandLimitsExceeded(mobile_apis::FunctionID::eType cmd_id, @@ -232,6 +266,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 @@ -427,8 +468,8 @@ 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_; @@ -437,6 +478,7 @@ class ApplicationImpl : public virtual Application, 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_; @@ -475,6 +517,11 @@ class ApplicationImpl : public virtual Application, 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 23bc698194..78fe938568 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 @@ -53,6 +53,7 @@ #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" @@ -310,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 @@ -318,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 */ @@ -353,6 +377,13 @@ class ApplicationManagerImpl 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; @@ -422,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; /** @@ -475,6 +507,7 @@ class ApplicationManagerImpl const hmi_apis::Common_DriverDistractionState::eType state) OVERRIDE; /* + * DEPRECATED * @brief Retrieves if VR session has started * * @return Current VR session state (started, stopped) @@ -482,6 +515,7 @@ class ApplicationManagerImpl inline bool vr_session_started() const; /* + * DEPRECATED * @brief Sets VR session state * * @param state Current HMI VR session state @@ -504,13 +538,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, @@ -839,8 +888,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; @@ -855,15 +923,43 @@ class ApplicationManagerImpl const connection_handler::CloseSessionReason& close_reason) 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; + + /** + * @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; #endif // ENABLE_SECURITY /** @@ -992,15 +1088,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); @@ -1057,6 +1153,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 @@ -1064,6 +1161,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 @@ -1170,15 +1268,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) {} @@ -1215,11 +1304,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(); @@ -1429,9 +1539,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 @@ -1523,6 +1632,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 @@ -1655,6 +1786,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 @@ -1669,6 +1809,8 @@ class ApplicationManagerImpl volatile bool is_stopping_; + std::unique_ptr<CommandHolder> commands_holder_; + #ifdef BUILD_TESTS public: /** @@ -1684,7 +1826,7 @@ class ApplicationManagerImpl DISALLOW_COPY_AND_ASSIGN(ApplicationManagerImpl); }; -bool ApplicationManagerImpl::vr_session_started() const { +DEPRECATED bool ApplicationManagerImpl::vr_session_started() const { return is_vr_session_strated_; } 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 96a315f505..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,9 +43,8 @@ namespace application_manager { namespace commands { struct ResponseInfo { - // DEPRECATED - ResponseInfo(hmi_apis::Common_Result::eType result, - HmiInterfaces::InterfaceID interface); + 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, 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 c6366f6ab2..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,16 +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 - */ - // DEPRECATED - virtual void onTimeOut() { - CommandRequestImpl::onTimeOut(); - } - /** * @brief Interface method that is called whenever new event received * 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 c78c57755e..6e0e634459 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 @@ -107,10 +107,10 @@ class PerformAudioPassThruRequest : public CommandRequestImpl { * application * @param result_code contains result code for sending to mobile application * @return result for sending to mobile application. + * @deprecated */ - // 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 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/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 6eacf9fe3e..f399da6870 100644 --- a/src/components/application_manager/include/application_manager/message.h +++ b/src/components/application_manager/include/application_manager/message.h @@ -93,8 +93,7 @@ class Message { void set_correlation_id(int32_t id); void set_connection_key(int32_t key); void set_message_type(MessageType type); - // DEPRECATED - 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); 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 a0b70435b0..dc16e14023 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -701,6 +701,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 @@ -728,11 +793,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..ce5c0818f1 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 @@ -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/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..a8032d1f65 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 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/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/application_impl.cc b/src/components/application_manager/src/application_impl.cc index 0c864b673d..22a0f2628e 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -41,9 +41,11 @@ #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" namespace { @@ -75,10 +77,23 @@ 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) { + 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 +119,14 @@ 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) , 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 +151,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 +355,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 +615,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 { @@ -861,6 +871,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; @@ -872,7 +886,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() { diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 9d656331a5..a2703aca75 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; @@ -165,6 +198,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() { @@ -194,33 +228,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; @@ -331,15 +338,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) @@ -366,7 +364,7 @@ std::vector<ApplicationSharedPtr> ApplicationManagerImpl::IviInfoUpdated( break; } - SubscribedToIVIPredicate finder(static_cast<int32_t>(vehicle_info)); + SubscribedToIVIPredicate finder(vehicle_info); DataAccessor<ApplicationSet> accessor = applications(); return FindAllApps(accessor, finder); } @@ -394,6 +392,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(); @@ -473,10 +477,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( @@ -489,6 +493,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(); @@ -507,22 +525,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)); @@ -537,12 +544,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 = @@ -627,11 +641,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; } @@ -788,7 +804,8 @@ void ApplicationManagerImpl::set_driver_distraction_state( driver_distraction_state_ = state; } -void ApplicationManagerImpl::set_vr_session_started(const bool state) { +DEPRECATED void ApplicationManagerImpl::set_vr_session_started( + const bool state) { is_vr_session_strated_ = state; } @@ -797,6 +814,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, @@ -1053,6 +1082,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; @@ -1175,7 +1303,6 @@ void ApplicationManagerImpl::ReplaceHMIByMobileAppId( } } -// DEPRECATED bool ApplicationManagerImpl::StartNaviService( uint32_t app_id, protocol_handler::ServiceType service_type) { using namespace protocol_handler; @@ -1347,7 +1474,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, @@ -1383,6 +1512,7 @@ bool ApplicationManagerImpl::OnServiceStartedCallback( } return false; } +#pragma GCC diagnostic pop void ApplicationManagerImpl::OnServiceStartedCallback( const connection_handler::DeviceHandle& device_handle, @@ -1441,6 +1571,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 @@ -1523,6 +1664,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_); @@ -1534,6 +1681,15 @@ ApplicationManagerImpl::GetHandshakeContext(uint32_t key) const { } return SSLContext::HandshakeContext(); } + +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; +} #endif // ENABLE_SECURITY void ApplicationManagerImpl::set_hmi_message_handler( @@ -1726,6 +1882,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()); @@ -1736,9 +1902,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(); @@ -1955,8 +2118,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"); @@ -1967,9 +2143,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; @@ -2091,9 +2267,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()); @@ -2103,6 +2282,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; } @@ -2150,8 +2332,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; @@ -2291,7 +2483,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()); @@ -2327,8 +2519,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; @@ -2347,7 +2542,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; @@ -2595,10 +2794,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."); @@ -2620,6 +2819,7 @@ void ApplicationManagerImpl::CreateApplications(SmartArray& obj_array, new ApplicationImpl(0, policy_app_id, device_mac, + device_id, appName, GetPolicyHandler().GetStatisticManager(), *this)); @@ -2628,7 +2828,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); @@ -2891,7 +3090,7 @@ void ApplicationManagerImpl::UnregisterAllApplications() { } } if (is_ignition_off) { - resume_controller().OnSuspend(); + resume_controller().OnIgnitionOff(); } request_ctrl_.terminateAllHMIRequests(); } @@ -2983,13 +3182,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) { @@ -3007,11 +3207,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); @@ -3020,6 +3219,9 @@ void ApplicationManagerImpl::UnregisterApplication( SendUpdateAppList(); } } + + commands_holder_->Clear(app_to_remove); + if (audio_pass_thru_active_) { // May be better to put this code in MessageHelper? EndAudioPassThrough(); @@ -3242,8 +3444,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); @@ -3639,6 +3842,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); @@ -3922,6 +4136,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) { @@ -4044,9 +4300,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(); } 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..4e2cf89f57 --- /dev/null +++ b/src/components/application_manager/src/command_holder_impl.cc @@ -0,0 +1,141 @@ +/* + * 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_hmi_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 09aa4169e5..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,6 +31,7 @@ */ #include <algorithm> +#include <numeric> #include <string> #include "utils/macro.h" #include "utils/make_shared.h" 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/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_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/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/get_vehicle_data_request.cc b/src/components/application_manager/src/commands/mobile/get_vehicle_data_request.cc index 84c6e0ba7c..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"); 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 cff16e577c..a05d41c098 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 @@ -224,7 +224,6 @@ PerformAudioPassThruRequest::PrepareResponseParameters() { return response_params_; } -// DEPRECATED bool PerformAudioPassThruRequest::PrepareResponseParameters( mobile_apis::Result::eType& result_code, std::string& info) { LOG4CXX_AUTO_TRACE(logger_); 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 1a60537874..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,13 @@ void RegisterAppInterfaceRequest::Run() { return; } + if (IsApplicationSwitched()) { + return; + } + + const std::string mobile_app_id = + (*message_)[strings::msg_params][strings::app_id].asString(); + ApplicationSharedPtr application = application_manager_.application(connection_key()); @@ -362,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); @@ -501,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); @@ -572,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()) { @@ -596,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()) { @@ -623,6 +629,7 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile() { ++index; } } + response_params[strings::sdl_version] = application_manager_.get_settings().sdl_version(); const std::string ccpu_version = @@ -631,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); @@ -713,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, @@ -1194,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/subscribe_way_points_request.cc b/src/components/application_manager/src/commands/mobile/subscribe_way_points_request.cc index 965741edf7..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,13 +25,13 @@ 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; } @@ -57,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/unsubscribe_vehicle_data_request.cc b/src/components/application_manager/src/commands/mobile/unsubscribe_vehicle_data_request.cc index f7317d72f9..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 @@ -253,6 +253,14 @@ void UnsubscribeVehicleDataRequest::on_event(const event_engine::Event& event) { } 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(); it != hmi_requests_.end(); @@ -308,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 88ed396250..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,7 +25,7 @@ void UnSubscribeWayPointsRequest::Run() { return; } - if (!application_manager_.IsAppSubscribedForWayPoints(app->app_id())) { + if (!application_manager_.IsAppSubscribedForWayPoints(app)) { SendResponse(false, mobile_apis::Result::IGNORED); return; } @@ -51,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/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 d67a235a76..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()); @@ -194,7 +194,6 @@ void Message::set_message_type(MessageType type) { type_ = type; } -// DEPRECATED void Message::set_binary_data(BinaryData* data) { if (NULL == data) { NOTREACHED(); 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 cf64152315..f544b5161e 100644 --- a/src/components/application_manager/src/message_helper/message_helper.cc +++ b/src/components/application_manager/src/message_helper/message_helper.cc @@ -42,6 +42,7 @@ #include <algorithm> #include <utility> #include <map> +#include <functional> #include "application_manager/application.h" #include "application_manager/application_manager.h" @@ -310,21 +311,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( @@ -344,8 +344,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; @@ -400,6 +400,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_; } @@ -873,7 +1120,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); } @@ -950,7 +1197,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] = @@ -1009,7 +1258,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; } @@ -1044,7 +1293,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; } @@ -1076,8 +1325,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] = @@ -1155,7 +1405,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); @@ -1187,8 +1437,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; } @@ -1228,8 +1478,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; } @@ -1281,8 +1531,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; } @@ -1315,8 +1565,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; } @@ -1372,8 +1622,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; } @@ -1492,7 +1742,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; } @@ -1531,7 +1781,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] = @@ -1681,8 +1931,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; @@ -1863,8 +2113,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; } @@ -1881,8 +2131,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; } @@ -1920,8 +2170,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; } @@ -1937,8 +2187,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; @@ -1977,8 +2227,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; @@ -2027,8 +2277,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; @@ -2039,8 +2289,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; @@ -2399,8 +2649,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 bc3aa32731..2f06c5f3b5 100644 --- a/src/components/application_manager/src/mobile_message_handler.cc +++ b/src/components/application_manager/src/mobile_message_handler.cc @@ -196,9 +196,8 @@ 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); - outgoing_message->set_binary_data(&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..b6b208b39b 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -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(); @@ -1170,7 +1177,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 +1211,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)) { @@ -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/resumption/resume_ctrl_impl.cc b/src/components/application_manager/src/resumption/resume_ctrl_impl.cc index c8740227df..72f2246e7c 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 @@ -263,16 +264,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 +443,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 +597,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); } } } @@ -774,7 +791,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_db.cc b/src/components/application_manager/src/resumption/resumption_data_db.cc index 08de6d8190..b031fd0afd 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(); @@ -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..e99d8bae26 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; @@ -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_); 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..3e9010e22c 100644 --- 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,15 @@ 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 ) if(REMOTE_CONTROL) @@ -130,10 +130,11 @@ 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 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 7d89e00c23..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()); 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..e54bc612ca 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" @@ -54,6 +56,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 +67,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 +87,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 +95,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 +109,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,11 +130,12 @@ 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()); @@ -145,17 +148,42 @@ 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_; }; @@ -181,16 +209,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 +239,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 +673,157 @@ 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)); + + 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()); +} + } // 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 f204c35456..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/* 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/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/hmi_notifications/hmi_notifications_test.cc b/src/components/application_manager/test/commands/hmi/hmi_notifications/hmi_notifications_test.cc index d97f5c1ad2..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,6 +130,8 @@ #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 @@ -1034,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>( @@ -1592,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(_)) @@ -1642,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(_)) 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/subscribe_way_points_request_test.cc b/src/components/application_manager/test/commands/mobile/subscribe_way_points_request_test.cc index d9497cd900..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,6 +51,7 @@ namespace mobile_commands_test { namespace subscribe_way_points_request { using ::testing::_; +using ::testing::A; using ::testing::Return; using ::testing::ReturnRef; using ::testing::DoAll; @@ -70,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()); } @@ -108,7 +110,10 @@ TEST_F(SubscribeWayPointsRequestTest, OnEvent_SUCCESS) { { InSequence dummy; - EXPECT_CALL(app_mngr_, SubscribeAppForWayPoints(_)); + 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()); } 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 733d037afb..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 @@ -100,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( @@ -117,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_, @@ -154,9 +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(app_mngr_, + UnsubscribeAppFromWayPoints( + ::testing::Matcher<am::ApplicationSharedPtr>(mock_app))); EXPECT_CALL( app_mngr_, 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 bce401e141..5bf2f2368e 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,7 @@ 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_METHOD1(SetInitialState, void(::application_manager::HmiStatePtr state)); MOCK_METHOD1(SetRegularState, void(::application_manager::HmiStatePtr state)); MOCK_METHOD1(SetPostponedState, void(::application_manager::HmiStatePtr state)); 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_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..7598e33e19 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 @@ -268,6 +268,29 @@ class MockMessageHelper { MOCK_METHOD2(GetDeviceMacAddressForHandle, std::string(const uint32_t 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..2a74f5b3b1 100644 --- a/src/components/application_manager/test/mock_message_helper.cc +++ b/src/components/application_manager/test/mock_message_helper.cc @@ -501,4 +501,46 @@ std::string MessageHelper::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..66efe45e30 100644 --- a/src/components/application_manager/test/policy_handler_test.cc +++ b/src/components/application_manager/test/policy_handler_test.cc @@ -803,8 +803,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 +1168,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 +1477,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 +1505,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 +1581,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 = @@ -1878,7 +1898,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 +1966,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 +2008,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 +2103,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 +2139,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 +2298,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 +2362,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/resumption/resume_ctrl_test.cc b/src/components/application_manager/test/resumption/resume_ctrl_test.cc index f2fc18ca58..f3e49001fa 100644 --- a/src/components/application_manager/test/resumption/resume_ctrl_test.cc +++ b/src/components/application_manager/test/resumption/resume_ctrl_test.cc @@ -54,6 +54,7 @@ namespace components { namespace resumption_test { using ::testing::_; +using ::testing::A; using ::testing::Return; using ::testing::ReturnRef; using ::testing::DoAll; @@ -505,7 +506,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_)) @@ -880,7 +883,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 +899,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 +909,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..cf0ebb7fd2 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 @@ -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); 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..e017c39497 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); 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()) |