diff options
Diffstat (limited to 'src/components/application_manager/include')
27 files changed, 1034 insertions, 140 deletions
diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index 3a03cb5343..eca22afa63 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 { @@ -161,7 +162,7 @@ typedef std::set<uint32_t> SoftButtonID; /** * @brief Defines set of vehicle info types */ -typedef std::set<uint32_t> VehicleInfoSubscriptions; +typedef std::set<mobile_apis::VehicleDataType::eType> VehicleInfoSubscriptions; /** * @brief Defines set of buttons subscription @@ -409,6 +410,20 @@ class Application : public virtual InitialApplicationData, virtual void UpdateHash() = 0; /** + * @brief checks is hashID was changed during suspended state + * @return Returns TRUE if hashID was changed during suspended state + * otherwise returns FALSE. + */ + virtual bool IsHashChangedDuringSuspend() const = 0; + + /** + * @brief changes state of the flag which tracks is hashID was changed during + * suspended state or not + * @param state new state of the flag + */ + virtual void SetHashChangedDuringSuspend(const bool state) = 0; + + /** * @brief method is called when SDL is saving application data for resumption * @return TRUE if data of application need to save for resumption, otherwise * return FALSE @@ -547,7 +562,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; @@ -604,6 +620,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 @@ -693,6 +716,16 @@ class Application : public virtual InitialApplicationData, virtual bool IsAudioApplication() const = 0; /** + * DEPRECATED + * @brief GetDeviceId allows to obtain device id which posseses + * by this application. + * @return device the device id. + */ + std::string GetDeviceId() const { + return device_id_; + } + + /** * @brief IsRegistered allows to distinguish if this * application has been registered. * @@ -750,16 +783,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 { @@ -837,7 +860,7 @@ class Application : public virtual InitialApplicationData, * @brief Get list of subscriptions to vehicle info notifications * @return list of subscriptions to vehicle info notifications */ - virtual const std::set<uint32_t>& SubscribesIVI() const = 0; + virtual const VehicleInfoSubscriptions& SubscribesIVI() const = 0; #endif // SDL_REMOTE_CONTROL protected: diff --git a/src/components/application_manager/include/application_manager/application_impl.h b/src/components/application_manager/include/application_manager/application_impl.h index dc2d8ce528..fd6dd13e39 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 @@ -331,7 +372,7 @@ class ApplicationImpl : public virtual Application, * @brief Get list of subscriptions to vehicle info notifications * @return list of subscriptions to vehicle info notifications */ - const std::set<uint32_t>& SubscribesIVI() const OVERRIDE; + const VehicleInfoSubscriptions& SubscribesIVI() const OVERRIDE; /** * @brief Return pointer to extension by uid @@ -422,8 +463,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_; @@ -432,6 +473,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_; @@ -467,6 +509,12 @@ class ApplicationImpl : public virtual Application, sync_primitives::Lock button_lock_; std::string folder_name_; ApplicationManager& application_manager_; + + friend void SwitchApplicationParameters(ApplicationSharedPtr app, + const uint32_t app_id, + const size_t device_id, + const std::string& mac_address); + DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); }; diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index 7a26501afc..22ae032a00 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -48,12 +48,12 @@ #include "application_manager/message_helper.h" #include "application_manager/request_controller.h" #include "application_manager/resumption/resume_ctrl.h" -#include "application_manager/vehicle_info_data.h" #include "application_manager/state_controller_impl.h" #include "application_manager/app_launch/app_launch_data.h" #include "application_manager/application_manager_settings.h" #include "application_manager/event_engine/event_dispatcher_impl.h" #include "application_manager/hmi_interfaces_impl.h" +#include "application_manager/command_holder.h" #include "protocol_handler/protocol_observer.h" #include "protocol_handler/protocol_handler.h" @@ -311,6 +311,7 @@ class ApplicationManagerImpl bool IsAppTypeExistsInFullOrLimited(ApplicationConstSharedPtr app) const; /** + * DEPRECATED * @brief Checks if Application is subscribed for way points * @param Application AppID * @return true if Application is subscribed for way points @@ -319,18 +320,40 @@ class ApplicationManagerImpl bool IsAppSubscribedForWayPoints(const uint32_t app_id) const OVERRIDE; /** + * DEPRECATED * @brief Subscribe Application for way points * @param Application AppID */ void SubscribeAppForWayPoints(const uint32_t app_id) OVERRIDE; /** + * DEPRECATED * @brief Unsubscribe Application for way points * @param Application AppID */ void UnsubscribeAppFromWayPoints(const uint32_t app_id) OVERRIDE; /** + * @brief Checks if Application is subscribed for way points + * @param Application pointer + * @return true if Application is subscribed for way points + * otherwise false + */ + bool IsAppSubscribedForWayPoints(ApplicationSharedPtr app) const OVERRIDE; + + /** + * @brief Subscribe Application for way points + * @param Application pointer + */ + void SubscribeAppForWayPoints(ApplicationSharedPtr app) OVERRIDE; + + /** + * @brief Unsubscribe Application for way points + * @param Application pointer + */ + void UnsubscribeAppFromWayPoints(ApplicationSharedPtr app) OVERRIDE; + + /** * @brief Is Any Application is subscribed for way points * @return true if some app is subscribed otherwise false */ @@ -349,11 +372,18 @@ class ApplicationManagerImpl * @param vehicle_info Enum value of type of vehicle data * @param new value (for integer values currently) of vehicle data */ - std::vector<ApplicationSharedPtr> IviInfoUpdated(VehicleDataType vehicle_info, - int value) OVERRIDE; + std::vector<ApplicationSharedPtr> IviInfoUpdated( + mobile_apis::VehicleDataType::eType vehicle_info, int value) OVERRIDE; void OnApplicationRegistered(ApplicationSharedPtr app) OVERRIDE; + /** + * @brief OnApplicationSwitched starts processing of commands collected + * during device switching process + * @param app Application + */ + void OnApplicationSwitched(ApplicationSharedPtr app) OVERRIDE; + HMICapabilities& hmi_capabilities() OVERRIDE; const HMICapabilities& hmi_capabilities() const OVERRIDE; @@ -423,8 +453,9 @@ class ApplicationManagerImpl */ void UnregisterAllApplications(); - bool RemoveAppDataFromHMI(ApplicationSharedPtr app); - bool LoadAppDataToHMI(ApplicationSharedPtr app); + DEPRECATED bool RemoveAppDataFromHMI(ApplicationSharedPtr app); + + DEPRECATED bool LoadAppDataToHMI(ApplicationSharedPtr app); bool ActivateApplication(ApplicationSharedPtr app) OVERRIDE; /** @@ -474,6 +505,7 @@ class ApplicationManagerImpl void set_driver_distraction(const bool is_distracting) OVERRIDE; /* + * DEPRECATED * @brief Retrieves if VR session has started * * @return Current VR session state (started, stopped) @@ -481,6 +513,7 @@ class ApplicationManagerImpl inline bool vr_session_started() const; /* + * DEPRECATED * @brief Sets VR session state * * @param state Current HMI VR session state @@ -503,13 +536,28 @@ class ApplicationManagerImpl /** * @brief CreateRegularState create regular HMI state for application - * @param app_id + * @param app Application * @param hmi_level of returned state * @param audio_state of returned state * @param system_context of returned state * @return new regular HMI state */ HmiStatePtr CreateRegularState( + utils::SharedPtr<Application> app, + mobile_apis::HMILevel::eType hmi_level, + mobile_apis::AudioStreamingState::eType audio_state, + mobile_apis::SystemContext::eType system_context) const OVERRIDE; + + /** + * DEPRECATED + * @brief CreateRegularState create regular HMI state for application + * @param app_id Application id + * @param hmi_level of returned state + * @param audio_state of returned state + * @param system_context of returned state + * @return new regular HMI state + */ + DEPRECATED HmiStatePtr CreateRegularState( uint32_t app_id, mobile_apis::HMILevel::eType hmi_level, mobile_apis::AudioStreamingState::eType audio_state, @@ -838,8 +886,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; @@ -854,15 +921,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 /** @@ -991,15 +1086,15 @@ class ApplicationManagerImpl uint32_t GenerateNewHMIAppID() OVERRIDE; /** + * DERPECATED * @brief Parse smartObject and replace mobile app Id by HMI app ID - * * @param message Smartobject to be parsed */ void ReplaceMobileByHMIAppId(smart_objects::SmartObject& message); /** + * DEPRECATED * @brief Parse smartObject and replace HMI app ID by mobile app Id - * * @param message Smartobject to be parsed */ void ReplaceHMIByMobileAppId(smart_objects::SmartObject& message); @@ -1056,6 +1151,7 @@ class ApplicationManagerImpl void RemoveAppFromTTSGlobalPropertiesList(const uint32_t app_id) OVERRIDE; /** + * DEPRECATED * @brief method adds application in FULL and LIMITED state * to on_phone_call_app_list_. * Also OnHMIStateNotification with BACKGROUND state sent for these apps @@ -1063,6 +1159,7 @@ class ApplicationManagerImpl void CreatePhoneCallAppList(); /** + * DEPRECATED * @brief method removes application from on_phone_call_app_list_. * * Also OnHMIStateNotification with previous HMI state sent for these apps @@ -1169,15 +1266,6 @@ class ApplicationManagerImpl } }; - struct SubscribedToIVIPredicate { - int32_t vehicle_info_; - SubscribedToIVIPredicate(int32_t vehicle_info) - : vehicle_info_(vehicle_info) {} - bool operator()(const ApplicationSharedPtr app) const { - return app ? app->IsSubscribedToIVI(vehicle_info_) : false; - } - }; - struct GrammarIdPredicate { uint32_t grammar_id_; GrammarIdPredicate(uint32_t grammar_id) : grammar_id_(grammar_id) {} @@ -1214,11 +1302,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(); @@ -1402,9 +1511,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 @@ -1488,6 +1596,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 @@ -1620,6 +1750,15 @@ class ApplicationManagerImpl std::auto_ptr<app_launch::AppLaunchData> app_launch_dto_; std::auto_ptr<app_launch::AppLaunchCtrl> app_launch_ctrl_; + /** + * @brief ReregisterWaitList is list of applications expected to be + * re-registered after transport switching is complete + */ + typedef std::vector<ApplicationSharedPtr> ReregisterWaitList; + ReregisterWaitList reregister_wait_list_; + + mutable sync_primitives::Lock reregister_wait_list_lock_; + #ifdef TELEMETRY_MONITOR AMTelemetryObserver* metric_observer_; #endif // TELEMETRY_MONITOR @@ -1634,6 +1773,8 @@ class ApplicationManagerImpl volatile bool is_stopping_; + std::unique_ptr<CommandHolder> commands_holder_; + #ifdef BUILD_TESTS public: /** @@ -1649,7 +1790,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 aa3c216d4d..74a884a223 100644 --- a/src/components/application_manager/include/application_manager/commands/command_request_impl.h +++ b/src/components/application_manager/include/application_manager/commands/command_request_impl.h @@ -43,27 +43,18 @@ namespace application_manager { namespace commands { struct ResponseInfo { - ResponseInfo() - : result_code(hmi_apis::Common_Result::INVALID_ENUM) - , interface(HmiInterfaces::HMI_INTERFACE_INVALID_ENUM) - , interface_state(HmiInterfaces::STATE_NOT_RESPONSE) - , is_ok(false) - , is_unsupported_resource(false) - , is_invalid_enum(false) {} - ResponseInfo(hmi_apis::Common_Result::eType result, - HmiInterfaces::InterfaceID interface) - : result_code(result) - , interface(interface) - , interface_state(HmiInterfaces::STATE_NOT_RESPONSE) - , is_ok(false) - , is_unsupported_resource(false) - , is_invalid_enum(false) {} + DEPRECATED ResponseInfo(hmi_apis::Common_Result::eType result, + HmiInterfaces::InterfaceID interface); + ResponseInfo(); + ResponseInfo(const hmi_apis::Common_Result::eType result, + const HmiInterfaces::InterfaceID hmi_interface, + ApplicationManager& application_manager); hmi_apis::Common_Result::eType result_code; HmiInterfaces::InterfaceID interface; HmiInterfaces::InterfaceState interface_state; bool is_ok; bool is_unsupported_resource; - bool is_invalid_enum; + bool is_not_used; }; namespace NsSmart = NsSmartDeviceLink::NsSmartObjects; @@ -290,6 +281,19 @@ class CommandRequestImpl : public CommandImpl, mobile_apis::Result::eType PrepareResultCodeForResponse( const ResponseInfo& first, const ResponseInfo& second); + /** + * @brief Resolves if the return code must be + * UNSUPPORTED_RESOURCE + * @param first contains result_code from HMI response and + * interface that returns response + * @param second contains result_code from HMI response and + * interface that returns response. + * @return True, if the communication return code must be + * UNSUPPORTED_RESOURCE, otherwise false. + */ + bool IsResultCodeUnsupported(const ResponseInfo& first, + const ResponseInfo& second) const; + protected: /** * @brief Returns policy parameters permissions @@ -297,6 +301,35 @@ class CommandRequestImpl : public CommandImpl, */ const CommandParametersPermissions& parameters_permissions() const; + /** + * @brief Adds interface to be awaited for by sdl request command + @param interface_id interface which SDL expects to response in given time + */ + void StartAwaitForInterface(const HmiInterfaces::InterfaceID interface_id); + + /** + * @brief Gets interface await state. + * @param interface_id interface which SDL awaits for response in given time + * @return true if SDL awaits for response from given interface in + * interface_id + */ + bool IsInterfaceAwaited(const HmiInterfaces::InterfaceID& interface_id) const; + + /** + * @brief Sets given HMI interface await status to false + * @param interface_id interface which SDL no longer awaits for response in + * given time + */ + void EndAwaitForInterface(const HmiInterfaces::InterfaceID& interface_id); + + /** + * @brief This set stores all the interfaces which are awaited by SDL to + * return a response on some request + */ + std::set<HmiInterfaces::InterfaceID> awaiting_response_interfaces_; + + mutable sync_primitives::Lock awaiting_response_interfaces_lock_; + RequestState current_state_; sync_primitives::Lock state_lock_; CommandParametersPermissions parameters_permissions_; @@ -331,10 +364,10 @@ class CommandRequestImpl : public CommandImpl, const hmi_apis::FunctionID::eType& function_id); /** - * @brief UpdateHash updates hash field for application and sends - * OnHashChanged notification to mobile side in case of approriate hash mode - * is set - */ + * @brief UpdateHash updates hash field for application and sends + * OnHashChanged notification to mobile side in case of approriate hash mode + * is set + */ void UpdateHash(); /** @@ -342,6 +375,13 @@ class CommandRequestImpl : public CommandImpl, * it is value of 'success' field of appropriate response sent to mobile */ bool is_success_result_; + + /** + * @brief Add information for the component of response in case of timeout + * @param response Response message, which info should be extended + */ + void AddTimeOutComponentInfoToMessage( + smart_objects::SmartObject& response) const; }; } // namespace commands diff --git a/src/components/application_manager/include/application_manager/commands/hmi/basic_communication_on_awake_sdl.h b/src/components/application_manager/include/application_manager/commands/hmi/basic_communication_on_awake_sdl.h index f789a14780..daa71e68b5 100644 --- a/src/components/application_manager/include/application_manager/commands/hmi/basic_communication_on_awake_sdl.h +++ b/src/components/application_manager/include/application_manager/commands/hmi/basic_communication_on_awake_sdl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Ford Motor Company + * Copyright (c) 2017, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,3 +29,45 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_HMI_BASIC_COMMUNICATION_ON_AWAKE_SDL_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_HMI_BASIC_COMMUNICATION_ON_AWAKE_SDL_H_ + +#include "application_manager/commands/hmi/notification_from_hmi.h" + +namespace application_manager { + +namespace commands { + +/** + * @brief OnAwakeSDLNotification command class + **/ +class OnAwakeSDLNotification : public NotificationFromHMI { + public: + /** + * @brief OnAwakeSDLNotification class constructor + * @param message Incoming SmartObject message + * @param application_manager reference to ApplicationManager instance + **/ + OnAwakeSDLNotification(const MessageSharedPtr& message, + ApplicationManager& application_manager); + + /** + * @brief OnAwakeSDLNotification class destructor + **/ + virtual ~OnAwakeSDLNotification(); + + /** + * @brief Execute command + **/ + void Run() FINAL; + + private: + DISALLOW_COPY_AND_ASSIGN(OnAwakeSDLNotification); +}; + +} // namespace commands + +} // namespace application_manager + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_COMMANDS_HMI_BASIC_COMMUNICATION_ON_AWAKE_SDL_H_ diff --git a/src/components/application_manager/include/application_manager/commands/hmi/on_app_unregistered_notification.h b/src/components/application_manager/include/application_manager/commands/hmi/on_app_unregistered_notification.h index 980e558d6f..f49dac071f 100644 --- a/src/components/application_manager/include/application_manager/commands/hmi/on_app_unregistered_notification.h +++ b/src/components/application_manager/include/application_manager/commands/hmi/on_app_unregistered_notification.h @@ -55,12 +55,22 @@ class OnAppUnregisteredNotification : public NotificationToHMI { /** * @brief OnAppUnregisteredNotification class destructor **/ - virtual ~OnAppUnregisteredNotification(); + ~OnAppUnregisteredNotification() FINAL; + + /** + * @brief Init overrides and skips replacement of app id with hmi id since + * 1) at the moment this notification is being sent there is no application + * registered in application manager + * 2) hmi id is already used whenever this message is being constructed, so + * its already there + * @return True in any case + */ + bool Init() FINAL; /** * @brief Execute command **/ - virtual void Run(); + virtual void Run() FINAL; private: DISALLOW_COPY_AND_ASSIGN(OnAppUnregisteredNotification); diff --git a/src/components/application_manager/include/application_manager/commands/hmi/on_exit_all_applications_notification.h b/src/components/application_manager/include/application_manager/commands/hmi/on_exit_all_applications_notification.h index a752e00801..92ef97a4aa 100644 --- a/src/components/application_manager/include/application_manager/commands/hmi/on_exit_all_applications_notification.h +++ b/src/components/application_manager/include/application_manager/commands/hmi/on_exit_all_applications_notification.h @@ -60,7 +60,7 @@ class OnExitAllApplicationsNotification : public NotificationFromHMI { /** * @brief Execute command **/ - virtual void Run(); + void Run() FINAL; private: /** diff --git a/src/components/application_manager/include/application_manager/commands/mobile/alert_request.h b/src/components/application_manager/include/application_manager/commands/mobile/alert_request.h index 77f1813e46..01b9782662 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/alert_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/alert_request.h @@ -72,13 +72,6 @@ class AlertRequest : public CommandRequestImpl { **/ virtual void Run(); - /* - * @brief Will caled by request controller, when default will be expired. - * If Alert request has soft buttons, timeout response should not be sent to - * mobile - */ - virtual void onTimeOut(); - /** * @brief Interface method that is called whenever new event received * diff --git a/src/components/application_manager/include/application_manager/commands/mobile/change_registration_request.h b/src/components/application_manager/include/application_manager/commands/mobile/change_registration_request.h index f783af12b3..2cd8e386e0 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/change_registration_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/change_registration_request.h @@ -167,6 +167,16 @@ class ChangeRegistrationRequest : public CommandRequestImpl { std::string vr_response_info_; std::string tts_response_info_; + void SendVRRequest(ApplicationSharedPtr app, + smart_objects::SmartObject& msg_params); + + void SendTTSRequest(ApplicationSharedPtr app, + smart_objects::SmartObject& msg_params); + + void SendUIRequest(ApplicationSharedPtr app, + smart_objects::SmartObject& msg_params, + const int32_t hmi_language); + DISALLOW_COPY_AND_ASSIGN(ChangeRegistrationRequest); }; diff --git a/src/components/application_manager/include/application_manager/commands/mobile/perform_audio_pass_thru_request.h b/src/components/application_manager/include/application_manager/commands/mobile/perform_audio_pass_thru_request.h index 99f86ea1d5..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 @@ -87,12 +87,38 @@ class PerformAudioPassThruRequest : public CommandRequestImpl { private: /** * @brief Prepare result code, result and info for sending to mobile + * @brief Response params + * success for sending to mobile application + * result code for sending to mobile application + * info for sending to mobile application + */ + struct ResponseParams { + bool success; + mobile_apis::Result::eType result_code; + std::string info; + ResponseParams() + : success(false), result_code(mobile_apis::Result::INVALID_ENUM) {} + }; + + ResponseParams response_params_; + + /** + * @brief Prepare result code, result and info for sending to mobile * application * @param result_code contains result code for sending to mobile application * @return result for sending to mobile application. + * @deprecated */ - bool PrepareResponseParameters(mobile_apis::Result::eType& result_code, - std::string& info); + DEPRECATED bool PrepareResponseParameters( + mobile_apis::Result::eType& result_code, std::string& info); + /** + * @brief Prepare result code, 'success' result and info for sending + * to mobile application + * @param result_code contains result code for sending to mobile application + * @return result for sending to mobile application. + */ + const ResponseParams& PrepareResponseParameters(); + /** * @brief Sends TTS Speak request */ @@ -137,6 +163,23 @@ class PerformAudioPassThruRequest : public CommandRequestImpl { during perform audio pass thru*/ bool awaiting_tts_speak_response_; bool awaiting_ui_response_; + /** + * @brief Pair of result_code and success for mobile app + */ + typedef std::pair<mobile_apis::Result::eType, bool> AudioPassThruResults; + + /** + * @brief Checks result code from HMI for splitted RPC + * and returns parameter for sending to mobile app in + * audioPassThru communication. + * @param ui_response contains result_code from UI + * @param tts_response contains result_code from TTS + * @return pair of result code (UI error code has precedence than TTS's, + * error_code from TTS is turned to WARNINGS) and + * result for mobile app + */ + AudioPassThruResults PrepareAudioPassThruResultCodeForResponse( + const ResponseInfo& ui_response, const ResponseInfo& tts_response); hmi_apis::Common_Result::eType result_tts_speak_; hmi_apis::Common_Result::eType result_ui_; diff --git a/src/components/application_manager/include/application_manager/commands/mobile/register_app_interface_request.h b/src/components/application_manager/include/application_manager/commands/mobile/register_app_interface_request.h index cc3d5b685c..5713e2e814 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/register_app_interface_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/register_app_interface_request.h @@ -78,14 +78,29 @@ class RegisterAppInterfaceRequest : public CommandRequestImpl { virtual void Run(); /** - * @brief Sends RegisterAppInterface response to mobile - * - *@param application_impl application - * + * @brief Prepares and sends RegisterAppInterface response to mobile + * considering application type **/ void SendRegisterAppInterfaceResponseToMobile(); private: + /** + * @brief The AppicationType enum defines whether application is newly + * registered or existing and being switched over another transport + */ + enum class ApplicationType { + kNewApplication, + kSwitchedApplicationHashOk, + kSwitchedApplicationWrongHashId + }; + + /** + * @brief Prepares and sends RegisterAppInterface response to mobile + * considering application type + * @param app_type Type of application + **/ + void SendRegisterAppInterfaceResponseToMobile(ApplicationType app_type); + smart_objects::SmartObjectSPtr GetLockScreenIconUrlNotification( const uint32_t connection_key, ApplicationSharedPtr app); @@ -184,6 +199,15 @@ class RegisterAppInterfaceRequest : public CommandRequestImpl { */ void SendSubscribeCustomButtonNotification(); + /** + * @brief IsApplicationSwitched checks whether application is switched from + * another transport. If application id is found, but not in reconnection + * list, returns 'already registered' code. Otherwise - proceed with + * switching. + * @return True if application is detected as switched, otherwise false. + */ + bool IsApplicationSwitched(); + private: std::string response_info_; mobile_apis::Result::eType result_checking_app_hmi_type_; diff --git a/src/components/application_manager/include/application_manager/commands/mobile/reset_global_properties_request.h b/src/components/application_manager/include/application_manager/commands/mobile/reset_global_properties_request.h index eb955df197..c16a014c9f 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/reset_global_properties_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/reset_global_properties_request.h @@ -131,12 +131,6 @@ class ResetGlobalPropertiesRequest : public CommandRequestImpl { DISALLOW_COPY_AND_ASSIGN(ResetGlobalPropertiesRequest); - bool is_ui_send_; - bool is_tts_send_; - - bool is_ui_received_; - bool is_tts_received_; - hmi_apis::Common_Result::eType ui_result_; hmi_apis::Common_Result::eType tts_result_; std::string ui_response_info_; diff --git a/src/components/application_manager/include/application_manager/commands/mobile/subscribe_vehicle_data_request.h b/src/components/application_manager/include/application_manager/commands/mobile/subscribe_vehicle_data_request.h index eb360b50d8..f556f81764 100644 --- a/src/components/application_manager/include/application_manager/commands/mobile/subscribe_vehicle_data_request.h +++ b/src/components/application_manager/include/application_manager/commands/mobile/subscribe_vehicle_data_request.h @@ -148,6 +148,11 @@ class SubscribeVehicleDataRequest : public CommandRequestImpl { */ VehicleInfoSubscriptions vi_already_subscribed_by_this_app_; + /** + * @brief VI parameters which wait for subscribe after HMI respond + */ + VehicleInfoSubscriptions vi_waiting_for_subscribe_; + DISALLOW_COPY_AND_ASSIGN(SubscribeVehicleDataRequest); }; diff --git a/src/components/application_manager/include/application_manager/helpers/application_helper.h b/src/components/application_manager/include/application_manager/helpers/application_helper.h new file mode 100644 index 0000000000..cecda0cd6f --- /dev/null +++ b/src/components/application_manager/include/application_manager/helpers/application_helper.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2017, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_HELPERS_APPLICATION_HELPER_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_HELPERS_APPLICATION_HELPER_H_ + +#include "application_manager/application.h" +#include "application_manager/application_manager.h" + +/* + * This file is for code w/o direct usage of ApplicationManagerImpl internals + */ +namespace application_manager { + +/** + * Helper function for lookup through applications list and returning first + * application satisfying predicate logic + */ +template <class UnaryPredicate> +ApplicationSharedPtr FindApp(DataAccessor<ApplicationSet> accessor, + UnaryPredicate finder) { + ApplicationSet::iterator it = std::find_if( + accessor.GetData().begin(), accessor.GetData().end(), finder); + if (accessor.GetData().end() == it) { + return ApplicationSharedPtr(); + } + ApplicationSharedPtr app = *it; + return app; +} + +/** + * Helper function for lookup through applications list and returning all + * applications satisfying predicate logic + */ +template <class UnaryPredicate> +std::vector<ApplicationSharedPtr> FindAllApps( + DataAccessor<ApplicationSet> accessor, UnaryPredicate finder) { + std::vector<ApplicationSharedPtr> result; + ApplicationSetConstIt it = std::find_if( + accessor.GetData().begin(), accessor.GetData().end(), finder); + while (it != accessor.GetData().end()) { + result.push_back(*it); + it = std::find_if(++it, accessor.GetData().end(), finder); + } + return result; +} + +/** + * @brief The SubscribedToIVIPredicate is predicate for lookup within + * applications list for apps subscribed for specific vehicle data + */ +struct SubscribedToIVIPredicate { + uint32_t vehicle_info_; + explicit SubscribedToIVIPredicate(uint32_t vehicle_info); + bool operator()(const ApplicationSharedPtr app) const; +}; + +/** + * @brief RecallApplicationData cleans up data within application instance to + * its initial state and notifies HMI to delete same data on its side + * @param app Application to clean its data + * @param app_manager Application manager + */ +void DeleteApplicationData(ApplicationSharedPtr app, + ApplicationManager& app_manager); +} // namespace application_manager + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_HELPERS_APPLICATION_HELPER_H_ diff --git a/src/components/application_manager/include/application_manager/hmi_state.h b/src/components/application_manager/include/application_manager/hmi_state.h index 939b8b86d0..f2d665d998 100644 --- a/src/components/application_manager/include/application_manager/hmi_state.h +++ b/src/components/application_manager/include/application_manager/hmi_state.h @@ -36,11 +36,13 @@ #include <list> #include "interfaces/MOBILE_API.h" #include "utils/shared_ptr.h" +#include "utils/macro.h" namespace application_manager { class HmiState; class ApplicationManager; +class Application; typedef utils::SharedPtr<HmiState> HmiStatePtr; @@ -70,7 +72,39 @@ class HmiState { STATE_ID_EMBEDDED_NAVI }; + /** + * @brief HmiState constructor + * @param app Application pointer + * @param app_mngr Application manager + */ + HmiState(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr); + + /** + * @brief HmiState constructor + * @param app Application pointer + * @param app_mngr Application manager + * @param state_id HMI state to assign + */ + HmiState(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr, + StateID state_id); + + /** + * DEPRECATED + * @brief HmiState constructor + * @param app_id Application id + * @param app_mngr Application manager + */ HmiState(uint32_t app_id, const ApplicationManager& app_mngr); + + /** + * DEPRECATED + * @brief HmiState constructor + * @param app_id Application id + * @param app_mngr Application manager + * @param state_id HMI state to assign + */ HmiState(uint32_t app_id, const ApplicationManager& app_mngr, StateID state_id); @@ -166,7 +200,7 @@ class HmiState { } protected: - uint32_t app_id_; + utils::SharedPtr<Application> app_; StateID state_id_; const ApplicationManager& app_mngr_; HmiStatePtr parent_; @@ -177,26 +211,28 @@ class HmiState { protected: /** * @brief is_navi_app check if app is navi - * @param app_id application id * @return true if app is navi, otherwise return false */ - bool is_navi_app(const uint32_t app_id) const; + bool is_navi_app() const; /** * @brief is_media_app check if app is media - * @param app_id application id * @return true if media_app, otherwise return false */ - bool is_media_app(const uint32_t app_id) const; + bool is_media_app() const; /** * @brief is_voice_communicationn_app check if app is voice comunication - * @param app_id application id * @return true if voice_communicationn_app, otherwise return false */ - bool is_voice_communication_app(const uint32_t app_id) const; + bool is_voice_communication_app() const; - bool is_mobile_projection_app(const uint32_t app_id) const; + /** + * @brief is_mobile_projection_app checks if application of 'projection' + * HMI type + * @return True if application is of 'projection' HMI type, otherwise - false + */ + bool is_mobile_projection_app() const; private: void operator=(const HmiState&); @@ -209,7 +245,10 @@ class VRHmiState : public HmiState { public: virtual mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE; - VRHmiState(uint32_t app_id, const ApplicationManager& app_mngr); + VRHmiState(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr); + + DEPRECATED VRHmiState(uint32_t app_id, const ApplicationManager& app_mngr); }; /** @@ -217,7 +256,11 @@ class VRHmiState : public HmiState { */ class TTSHmiState : public HmiState { public: - TTSHmiState(uint32_t app_id, const ApplicationManager& app_mngr); + TTSHmiState(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr); + + DEPRECATED TTSHmiState(uint32_t app_id, const ApplicationManager& app_mngr); + virtual mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE; }; @@ -228,7 +271,12 @@ class TTSHmiState : public HmiState { */ class NaviStreamingHmiState : public HmiState { public: - NaviStreamingHmiState(uint32_t app_id, const ApplicationManager& app_mngr); + NaviStreamingHmiState(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr); + + DEPRECATED NaviStreamingHmiState(uint32_t app_id, + const ApplicationManager& app_mngr); + mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE; }; @@ -239,7 +287,12 @@ class NaviStreamingHmiState : public HmiState { */ class PhoneCallHmiState : public HmiState { public: - PhoneCallHmiState(uint32_t app_id, const ApplicationManager& app_mngr); + PhoneCallHmiState(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr); + + DEPRECATED PhoneCallHmiState(uint32_t app_id, + const ApplicationManager& app_mngr); + mobile_apis::HMILevel::eType hmi_level() const OVERRIDE; mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE { @@ -253,7 +306,12 @@ class PhoneCallHmiState : public HmiState { */ class SafetyModeHmiState : public HmiState { public: - SafetyModeHmiState(uint32_t app_id, const ApplicationManager& app_mngr); + SafetyModeHmiState(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr); + + DEPRECATED SafetyModeHmiState(uint32_t app_id, + const ApplicationManager& app_mngr); + mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE { return mobile_apis::AudioStreamingState::NOT_AUDIBLE; @@ -266,7 +324,11 @@ class SafetyModeHmiState : public HmiState { */ class DeactivateHMI : public HmiState { public: - DeactivateHMI(uint32_t app_id, const ApplicationManager& app_mngr); + DeactivateHMI(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr); + + DEPRECATED DeactivateHMI(uint32_t app_id, const ApplicationManager& app_mngr); + mobile_apis::HMILevel::eType hmi_level() const OVERRIDE; mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE { @@ -280,7 +342,11 @@ class DeactivateHMI : public HmiState { */ class AudioSource : public HmiState { public: - AudioSource(uint32_t app_id, const ApplicationManager& app_mngr); + AudioSource(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr); + + DEPRECATED AudioSource(uint32_t app_id, const ApplicationManager& app_mngr); + mobile_apis::HMILevel::eType hmi_level() const OVERRIDE; mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE { @@ -295,7 +361,11 @@ class AudioSource : public HmiState { */ class EmbeddedNavi : public HmiState { public: - EmbeddedNavi(uint32_t app_id, const ApplicationManager& app_mngr); + EmbeddedNavi(utils::SharedPtr<Application> app, + const ApplicationManager& app_mngr); + + DEPRECATED EmbeddedNavi(uint32_t app_id, const ApplicationManager& app_mngr); + mobile_apis::HMILevel::eType hmi_level() const OVERRIDE; mobile_apis::AudioStreamingState::eType audio_streaming_state() const OVERRIDE { diff --git a/src/components/application_manager/include/application_manager/message.h b/src/components/application_manager/include/application_manager/message.h index 77ef5479ee..f399da6870 100644 --- a/src/components/application_manager/include/application_manager/message.h +++ b/src/components/application_manager/include/application_manager/message.h @@ -93,7 +93,8 @@ class Message { void set_correlation_id(int32_t id); void set_connection_key(int32_t key); void set_message_type(MessageType type); - void set_binary_data(BinaryData* data); + DEPRECATED void set_binary_data(BinaryData* data); + void set_binary_data(const BinaryData* data); void set_json_message(const std::string& json_message); void set_protocol_version(protocol_handler::MajorProtocolVersion version); void set_smart_object(const smart_objects::SmartObject& object); diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h index c0a3f37c34..dc16e14023 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -42,7 +42,6 @@ #include "utils/macro.h" #include "connection_handler/device.h" #include "application_manager/application.h" -#include "application_manager/vehicle_info_data.h" #include "policy/policy_types.h" #include "protocol_handler/session_observer.h" #include "application_manager/policies/policy_handler_interface.h" @@ -61,7 +60,7 @@ namespace mobile_api = mobile_apis; * @param const char* Name of the parameter in mobile request * @param VehicleDataType Enum for vehicle data */ -typedef std::map<std::string, VehicleDataType> VehicleData; +typedef std::map<std::string, mobile_apis::VehicleDataType::eType> VehicleData; /** * @brief MessageHelper class @@ -702,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 @@ -729,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, |