diff options
Diffstat (limited to 'src/components/application_manager/src/application_manager_impl.cc')
-rw-r--r-- | src/components/application_manager/src/application_manager_impl.cc | 1836 |
1 files changed, 537 insertions, 1299 deletions
diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 4e13da694b..55112e153c 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -39,10 +39,11 @@ #include <bson_object.h> #include "application_manager/application_manager_impl.h" -#include "application_manager/mobile_command_factory.h" #include "application_manager/commands/command_impl.h" #include "application_manager/commands/command_notification_impl.h" #include "application_manager/message_helper.h" +#include "application_manager/rpc_service_impl.h" +#include "application_manager/rpc_handler_impl.h" #include "application_manager/mobile_message_handler.h" #include "application_manager/policies/policy_handler.h" #include "application_manager/hmi_capabilities_impl.h" @@ -51,6 +52,7 @@ #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 "application_manager/plugin_manager/rpc_plugin_manager_impl.h" #include "protocol_handler/protocol_handler.h" #include "hmi_message_handler/hmi_message_handler.h" #include "application_manager/command_holder_impl.h" @@ -63,7 +65,7 @@ #include "utils/threads/thread.h" #include "utils/file_system.h" #include "utils/helpers.h" -#include "utils/make_shared.h" + #include "utils/timer_task_impl.h" #include "smart_objects/enum_schema_item.h" #include "interfaces/HMI_API_schema.h" @@ -73,17 +75,11 @@ #include "utils/custom_string.h" #include <time.h> -#ifdef SDL_REMOTE_CONTROL -#include "policy/usage_statistics/counter.h" -#include "functional_module/plugin_manager.h" -#include "application_manager/core_service.h" -#endif // SDL_REMOTE_CONTROL - namespace { int get_rand_from_range(uint32_t from = 0, int to = RAND_MAX) { return std::rand() % to + from; } -} +} // namespace namespace application_manager { @@ -97,7 +93,13 @@ DeviceTypes devicesType = { 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)}; + std::make_pair(std::string("WIFI"), hmi_apis::Common_TransportType::WIFI), + std::make_pair(std::string("USB_IOS_HOST_MODE"), + hmi_apis::Common_TransportType::USB_IOS), + std::make_pair(std::string("USB_IOS_DEVICE_MODE"), + hmi_apis::Common_TransportType::USB_IOS), + std::make_pair(std::string("CARPLAY_WIRELESS_IOS"), + hmi_apis::Common_TransportType::WIFI)}; } /** @@ -141,9 +143,12 @@ ApplicationManagerImpl::ApplicationManagerImpl( const ApplicationManagerSettings& am_settings, const policy::PolicySettings& policy_settings) : settings_(am_settings) - , applications_list_lock_(true) + , applications_list_lock_ptr_( + std::make_shared<sync_primitives::RecursiveLock>()) + , apps_to_register_list_lock_ptr_(std::make_shared<sync_primitives::Lock>()) , audio_pass_thru_active_(false) - , is_distracting_driver_(false) + , audio_pass_thru_app_id_(0) + , driver_distraction_state_(hmi_apis::Common_DriverDistractionState::DD_OFF) , is_vr_session_strated_(false) , hmi_cooperating_(false) , is_all_apps_allowed_(true) @@ -155,22 +160,13 @@ ApplicationManagerImpl::ApplicationManagerImpl( , request_ctrl_(am_settings) , hmi_so_factory_(NULL) , mobile_so_factory_(NULL) - , messages_from_mobile_("AM FromMobile", this) - , messages_to_mobile_("AM ToMobile", this) - , messages_from_hmi_("AM FromHMI", this) - , messages_to_hmi_("AM ToHMI", this) - , audio_pass_thru_messages_("AudioPassThru", this) , hmi_capabilities_(new HMICapabilitiesImpl(*this)) , unregister_reason_( mobile_api::AppInterfaceUnregisteredReason::INVALID_ENUM) , resume_ctrl_(new resumption::ResumeCtrlImpl(*this)) , navi_close_app_timeout_(am_settings.stop_streaming_timeout()) , navi_end_stream_timeout_(am_settings.stop_streaming_timeout()) - , stopping_application_mng_lock_(true) , state_ctrl_(*this) -#ifdef TELEMETRY_MONITOR - , metric_observer_(NULL) -#endif // TELEMETRY_MONITOR , application_list_update_timer_( "AM ListUpdater", new TimerTaskImpl<ApplicationManagerImpl>( @@ -182,7 +178,7 @@ ApplicationManagerImpl::ApplicationManagerImpl( , is_low_voltage_(false) , apps_size_(0) , is_stopping_(false) { - std::srand(std::time(0)); + std::srand(std::time(nullptr)); AddPolicyObserver(this); dir_type_to_string_map_ = {{TYPE_STORAGE, "Storage"}, @@ -190,14 +186,20 @@ ApplicationManagerImpl::ApplicationManagerImpl( {TYPE_ICONS, "Icons"}}; sync_primitives::AutoLock lock(timer_pool_lock_); - TimerSPtr clearing_timer(utils::MakeShared<timer::Timer>( + TimerSPtr clearing_timer(std::make_shared<timer::Timer>( "ClearTimerPoolTimer", new TimerTaskImpl<ApplicationManagerImpl>( this, &ApplicationManagerImpl::ClearTimerPool))); const uint32_t timeout_ms = 10000u; clearing_timer->Start(timeout_ms, timer::kSingleShot); timer_pool_.push_back(clearing_timer); + rpc_handler_.reset(new rpc_handler::RPCHandlerImpl(*this)); commands_holder_.reset(new CommandHolderImpl(*this)); + rpc_service_.reset(new rpc_service::RPCServiceImpl(*this, + request_ctrl_, + protocol_handler_, + hmi_handler_, + *commands_holder_)); } ApplicationManagerImpl::~ApplicationManagerImpl() { @@ -225,10 +227,13 @@ ApplicationManagerImpl::~ApplicationManagerImpl() { navi_app_to_stop_.clear(); navi_app_to_end_stream_.clear(); + + secondary_transport_devices_cache_.clear(); } DataAccessor<ApplicationSet> ApplicationManagerImpl::applications() const { - DataAccessor<ApplicationSet> accessor(applications_, applications_list_lock_); + DataAccessor<ApplicationSet> accessor(applications_, + applications_list_lock_ptr_); return accessor; } @@ -350,8 +355,7 @@ struct IsApplication { connection_handler::DeviceHandle device_handle_; const std::string& policy_app_id_; }; - -std::vector<ApplicationSharedPtr> ApplicationManagerImpl::IviInfoUpdated( +void ApplicationManagerImpl::IviInfoUpdated( mobile_apis::VehicleDataType::eType vehicle_info, int value) { // Notify Policy Manager if available about info it's interested in, // i.e. odometer etc @@ -362,19 +366,21 @@ std::vector<ApplicationSharedPtr> ApplicationManagerImpl::IviInfoUpdated( default: break; } - - SubscribedToIVIPredicate finder(vehicle_info); - DataAccessor<ApplicationSet> accessor = applications(); - return FindAllApps(accessor, finder); } void ApplicationManagerImpl::OnApplicationRegistered(ApplicationSharedPtr app) { LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(app); - sync_primitives::AutoLock lock(applications_list_lock_); + sync_primitives::AutoLock lock(applications_list_lock_ptr_); const mobile_apis::HMILevel::eType default_level = GetDefaultHmiLevel(app); state_ctrl_.OnApplicationRegistered(app, default_level); + std::function<void(plugin_manager::RPCPlugin&)> on_app_registered = + [app](plugin_manager::RPCPlugin& plugin) { + plugin.OnApplicationEvent(plugin_manager::kApplicationRegistered, app); + }; + plugin_manager_->ForEachPlugin(on_app_registered); + // TODO(AOleynik): Is neccessary to be able to know that registration process // has been completed and default HMI level is set, otherwise policy will // block all the requests/notifications to mobile @@ -399,13 +405,14 @@ void ApplicationManagerImpl::OnApplicationSwitched(ApplicationSharedPtr app) { bool ApplicationManagerImpl::IsAppTypeExistsInFullOrLimited( ApplicationConstSharedPtr app) const { + LOG4CXX_AUTO_TRACE(logger_); bool voice_state = app->is_voice_communication_supported(); bool media_state = app->is_media_application(); bool navi_state = app->is_navi(); bool mobile_projection_state = app->mobile_projection_enabled(); ApplicationSharedPtr active_app = active_application(); // Check app in FULL level - if (active_app.valid()) { + if (active_app.use_count() != 0) { // If checking app hmi level FULL, we return false // because we couldn't have two applications with same HMIType in FULL and // LIMITED HMI level @@ -432,28 +439,28 @@ bool ApplicationManagerImpl::IsAppTypeExistsInFullOrLimited( // Check LIMITED apps if (voice_state) { - if (get_limited_voice_application().valid() && + if ((get_limited_voice_application().use_count() != 0) && (get_limited_voice_application()->app_id() != app->app_id())) { return true; } } if (media_state) { - if (get_limited_media_application().valid() && + if ((get_limited_media_application().use_count() != 0) && (get_limited_media_application()->app_id() != app->app_id())) { return true; } } if (navi_state) { - if (get_limited_navi_application().valid() && + if ((get_limited_navi_application().use_count() != 0) && (get_limited_navi_application()->app_id() != app->app_id())) { return true; } } if (mobile_projection_state) { - if (get_limited_mobile_projection_application().valid() && + if ((get_limited_mobile_projection_application().use_count() != 0) && (get_limited_mobile_projection_application()->app_id() != app->app_id())) { return true; @@ -464,7 +471,7 @@ bool ApplicationManagerImpl::IsAppTypeExistsInFullOrLimited( } ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( - const utils::SharedPtr<smart_objects::SmartObject>& + const std::shared_ptr<smart_objects::SmartObject>& request_for_registration) { LOG4CXX_AUTO_TRACE(logger_); @@ -482,18 +489,19 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( 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( + std::shared_ptr<smart_objects::SmartObject> response( MessageHelper::CreateNegativeResponse( connection_key, mobile_apis::FunctionID::RegisterAppInterfaceID, message[strings::params][strings::correlation_id].asUInt(), mobile_apis::Result::GENERIC_ERROR)); - ManageMobileCommand(response, commands::Command::ORIGIN_SDL); + rpc_service_->ManageMobileCommand(response, commands::Command::SOURCE_SDL); return ApplicationSharedPtr(); } smart_objects::SmartObject& params = message[strings::msg_params]; - const std::string& policy_app_id = params[strings::app_id].asString(); + const std::string& policy_app_id = + GetCorrectMobileIDFromMessage(request_for_registration); const custom_str::CustomString& app_name = message[strings::msg_params][strings::app_name].asCustomString(); std::string device_mac; @@ -514,13 +522,13 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( if (!is_all_apps_allowed_) { LOG4CXX_WARN(logger_, "RegisterApplication: access to app's disabled by user"); - utils::SharedPtr<smart_objects::SmartObject> response( + std::shared_ptr<smart_objects::SmartObject> response( MessageHelper::CreateNegativeResponse( connection_key, mobile_apis::FunctionID::RegisterAppInterfaceID, message[strings::params][strings::correlation_id].asUInt(), mobile_apis::Result::DISALLOWED)); - ManageMobileCommand(response, commands::Command::ORIGIN_SDL); + rpc_service_->ManageMobileCommand(response, commands::Command::SOURCE_SDL); return ApplicationSharedPtr(); } @@ -533,20 +541,21 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( GetPolicyHandler().GetStatisticManager(), *this)); if (!application) { - utils::SharedPtr<smart_objects::SmartObject> response( + std::shared_ptr<smart_objects::SmartObject> response( MessageHelper::CreateNegativeResponse( connection_key, mobile_apis::FunctionID::RegisterAppInterfaceID, message[strings::params][strings::correlation_id].asUInt(), mobile_apis::Result::OUT_OF_MEMORY)); - ManageMobileCommand(response, commands::Command::ORIGIN_SDL); + rpc_service_->ManageMobileCommand(response, commands::Command::SOURCE_SDL); return ApplicationSharedPtr(); } HmiStatePtr initial_state = - CreateRegularState(utils::SharedPtr<Application>(application), + CreateRegularState(std::shared_ptr<Application>(application), mobile_apis::HMILevel::INVALID_ENUM, mobile_apis::AudioStreamingState::INVALID_ENUM, + mobile_apis::VideoStreamingState::INVALID_ENUM, mobile_api::SystemContext::SYSCTXT_MAIN); application->SetInitialState(initial_state); @@ -599,13 +608,13 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( } // Keep HMI add id in case app is present in "waiting for registration" list - apps_to_register_list_lock_.Acquire(); + apps_to_register_list_lock_ptr_->Acquire(); AppsWaitRegistrationSet::iterator it = apps_to_register_.find(application); if (apps_to_register_.end() != it) { application->set_hmi_application_id((*it)->hmi_app_id()); apps_to_register_.erase(application); } - apps_to_register_list_lock_.Release(); + apps_to_register_list_lock_ptr_->Release(); if (!application->hmi_app_id()) { const bool is_saved = @@ -621,6 +630,13 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( const std::string& bundle_id = app_info[strings::bundle_id].asString(); application->set_bundle_id(bundle_id); } + + const std::string app_icon_dir(settings_.app_icons_folder()); + const std::string full_icon_path(app_icon_dir + "/" + policy_app_id); + if (file_system::FileExists(full_icon_path)) { + application->set_app_icon_path(full_icon_path); + } + // Stops timer of saving data to resumption in order to // doesn't erase data from resumption storage. // Timer will be started after hmi level resumption. @@ -629,23 +645,25 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( // Add application to registered app list and set appropriate mark. // Lock has to be released before adding app to policy DB to avoid possible // deadlock with simultaneous PTU processing - applications_list_lock_.Acquire(); + applications_list_lock_ptr_->Acquire(); application->MarkRegistered(); applications_.insert(application); apps_size_ = applications_.size(); - applications_list_lock_.Release(); + applications_list_lock_ptr_->Release(); - return application; -} - -DEPRECATED bool ApplicationManagerImpl::RemoveAppDataFromHMI( - ApplicationSharedPtr app) { - return true; -} + // It is possible that secondary transport of this app has been already + // established. Make sure that the information is reflected to application + // instance. + // Also, make sure that this is done *after* we updated applications_ list to + // avoid timing issues. + DeviceMap::iterator itr = + secondary_transport_devices_cache_.find(connection_key); + if (secondary_transport_devices_cache_.end() != itr) { + connection_handler::DeviceHandle secondary_device_handle = itr->second; + application->set_secondary_device(secondary_device_handle); + } -DEPRECATED bool ApplicationManagerImpl::LoadAppDataToHMI( - ApplicationSharedPtr app) { - return true; + return application; } bool ApplicationManagerImpl::ActivateApplication(ApplicationSharedPtr app) { @@ -653,13 +671,18 @@ bool ApplicationManagerImpl::ActivateApplication(ApplicationSharedPtr app) { LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN(app, false); + LOG4CXX_DEBUG(logger_, "Activating application with id:" << app->app_id()); + // remove from resumption if app was activated by user resume_controller().OnAppActivated(app); - HMILevel::eType hmi_level = HMILevel::HMI_FULL; - AudioStreamingState::eType audio_state; - app->IsAudioApplication() ? audio_state = AudioStreamingState::AUDIBLE - : audio_state = AudioStreamingState::NOT_AUDIBLE; - state_ctrl_.SetRegularState(app, hmi_level, audio_state, false); + const HMILevel::eType hmi_level = HMILevel::HMI_FULL; + const AudioStreamingState::eType audio_state = + app->IsAudioApplication() ? AudioStreamingState::AUDIBLE + : AudioStreamingState::NOT_AUDIBLE; + const VideoStreamingState::eType video_state = + app->IsVideoApplication() ? VideoStreamingState::STREAMABLE + : VideoStreamingState::NOT_STREAMABLE; + state_ctrl_.SetRegularState(app, hmi_level, audio_state, video_state, false); return true; } @@ -671,10 +694,10 @@ mobile_api::HMILevel::eType ApplicationManagerImpl::IsHmiLevelFullAllowed( NOTREACHED(); return mobile_api::HMILevel::INVALID_ENUM; } - bool is_audio_app = app->IsAudioApplication(); - bool does_audio_app_with_same_type_exist = + const bool is_audio_app = app->IsAudioApplication(); + const bool does_audio_app_with_same_type_exist = IsAppTypeExistsInFullOrLimited(app); - bool is_active_app_exist = active_application().valid(); + const bool is_active_app_exist = (active_application().use_count() != 0); mobile_api::HMILevel::eType result = mobile_api::HMILevel::HMI_FULL; if (is_audio_app && does_audio_app_with_same_type_exist) { @@ -716,48 +739,46 @@ void ApplicationManagerImpl::OnHMIStartedCooperation() { hmi_cooperating_ = true; MessageHelper::SendGetSystemInfoRequest(*this); - utils::SharedPtr<smart_objects::SmartObject> is_vr_ready( + std::shared_ptr<smart_objects::SmartObject> is_vr_ready( MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::VR_IsReady, *this)); - ManageHMICommand(is_vr_ready); + rpc_service_->ManageHMICommand(is_vr_ready); - utils::SharedPtr<smart_objects::SmartObject> is_tts_ready( + std::shared_ptr<smart_objects::SmartObject> is_tts_ready( MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::TTS_IsReady, *this)); - ManageHMICommand(is_tts_ready); + rpc_service_->ManageHMICommand(is_tts_ready); - utils::SharedPtr<smart_objects::SmartObject> is_ui_ready( + std::shared_ptr<smart_objects::SmartObject> is_ui_ready( MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::UI_IsReady, *this)); - ManageHMICommand(is_ui_ready); + rpc_service_->ManageHMICommand(is_ui_ready); - utils::SharedPtr<smart_objects::SmartObject> is_navi_ready( + std::shared_ptr<smart_objects::SmartObject> is_navi_ready( MessageHelper::CreateModuleInfoSO( hmi_apis::FunctionID::Navigation_IsReady, *this)); - ManageHMICommand(is_navi_ready); + rpc_service_->ManageHMICommand(is_navi_ready); - utils::SharedPtr<smart_objects::SmartObject> is_ivi_ready( + std::shared_ptr<smart_objects::SmartObject> is_ivi_ready( MessageHelper::CreateModuleInfoSO( hmi_apis::FunctionID::VehicleInfo_IsReady, *this)); - ManageHMICommand(is_ivi_ready); + rpc_service_->ManageHMICommand(is_ivi_ready); -#ifdef SDL_REMOTE_CONTROL - utils::SharedPtr<smart_objects::SmartObject> is_rc_ready( + std::shared_ptr<smart_objects::SmartObject> is_rc_ready( MessageHelper::CreateModuleInfoSO(hmi_apis::FunctionID::RC_IsReady, *this)); - ManageHMICommand(is_rc_ready); -#endif + rpc_service_->ManageHMICommand(is_rc_ready); - utils::SharedPtr<smart_objects::SmartObject> button_capabilities( + std::shared_ptr<smart_objects::SmartObject> button_capabilities( MessageHelper::CreateModuleInfoSO( hmi_apis::FunctionID::Buttons_GetCapabilities, *this)); - ManageHMICommand(button_capabilities); + rpc_service_->ManageHMICommand(button_capabilities); - utils::SharedPtr<smart_objects::SmartObject> mixing_audio_supported_request( + std::shared_ptr<smart_objects::SmartObject> mixing_audio_supported_request( MessageHelper::CreateModuleInfoSO( hmi_apis::FunctionID::BasicCommunication_MixingAudioSupported, *this)); - ManageHMICommand(mixing_audio_supported_request); + rpc_service_->ManageHMICommand(mixing_audio_supported_request); resume_controller().ResetLaunchTime(); } @@ -771,33 +792,36 @@ uint32_t ApplicationManagerImpl::GetNextHMICorrelationID() { return corelation_id_; } -bool ApplicationManagerImpl::BeginAudioPassThrough() { +bool ApplicationManagerImpl::BeginAudioPassThru(uint32_t app_id) { sync_primitives::AutoLock lock(audio_pass_thru_lock_); if (audio_pass_thru_active_) { return false; } else { audio_pass_thru_active_ = true; + audio_pass_thru_app_id_ = app_id; return true; } } -bool ApplicationManagerImpl::EndAudioPassThrough() { +bool ApplicationManagerImpl::EndAudioPassThru(uint32_t app_id) { sync_primitives::AutoLock lock(audio_pass_thru_lock_); - if (audio_pass_thru_active_) { + if (audio_pass_thru_active_ && audio_pass_thru_app_id_ == app_id) { audio_pass_thru_active_ = false; + audio_pass_thru_app_id_ = 0; return true; } else { return false; } } -void ApplicationManagerImpl::set_driver_distraction(const bool is_distracting) { - is_distracting_driver_ = is_distracting; +hmi_apis::Common_DriverDistractionState::eType +ApplicationManagerImpl::driver_distraction_state() const { + return driver_distraction_state_; } -DEPRECATED void ApplicationManagerImpl::set_vr_session_started( - const bool state) { - is_vr_session_strated_ = state; +void ApplicationManagerImpl::set_driver_distraction_state( + const hmi_apis::Common_DriverDistractionState::eType state) { + driver_distraction_state_ = state; } void ApplicationManagerImpl::SetAllAppsAllowed(const bool allowed) { @@ -805,35 +829,19 @@ void ApplicationManagerImpl::SetAllAppsAllowed(const bool allowed) { } HmiStatePtr ApplicationManagerImpl::CreateRegularState( - utils::SharedPtr<Application> app, + std::shared_ptr<Application> app, mobile_apis::HMILevel::eType hmi_level, mobile_apis::AudioStreamingState::eType audio_state, + mobile_apis::VideoStreamingState::eType video_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_video_streaming_state(video_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, - mobile_apis::SystemContext::eType system_context) const { - HmiStatePtr state(new HmiState(app_id, *this)); - state->set_hmi_level(hmi_level); - state->set_audio_streaming_state(audio_state); - state->set_system_context(system_context); - return state; -} - -bool ApplicationManagerImpl::IsStateActive(HmiState::StateID state_id) const { - LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG(logger_, "Checking for active state id " << state_id); - return state_ctrl_.IsStateActive(state_id); -} - void ApplicationManagerImpl::StartAudioPassThruThread(int32_t session_key, int32_t correlation_id, int32_t max_duration, @@ -847,23 +855,6 @@ void ApplicationManagerImpl::StartAudioPassThruThread(int32_t session_key, session_key, get_settings().recording_file_name(), max_duration); } -void ApplicationManagerImpl::SendAudioPassThroughNotification( - uint32_t session_key, std::vector<uint8_t>& binary_data) { - LOG4CXX_AUTO_TRACE(logger_); - - if (!audio_pass_thru_active_) { - LOG4CXX_ERROR(logger_, - "Trying to send PassThroughNotification" - " when PassThrough is not active"); - return; - } - - impl::AudioData data; - data.session_key = session_key; - data.binary_data = binary_data; - audio_pass_thru_messages_.PostMessage(data); -} - void ApplicationManagerImpl::StopAudioPassThru(int32_t application_key) { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(audio_pass_thru_lock_); @@ -901,43 +892,6 @@ ApplicationManagerImpl::GetDeviceTransportType( return result; } -void ApplicationManagerImpl::OnMessageReceived( - const ::protocol_handler::RawMessagePtr message) { - LOG4CXX_AUTO_TRACE(logger_); - - if (!message) { - LOG4CXX_ERROR(logger_, "Null-pointer message received."); - NOTREACHED(); - return; - } - - utils::SharedPtr<Message> outgoing_message = ConvertRawMsgToMessage(message); - - if (outgoing_message) { - LOG4CXX_DEBUG(logger_, "Posting new Message"); - messages_from_mobile_.PostMessage( - impl::MessageFromMobile(outgoing_message)); - } -} - -void ApplicationManagerImpl::OnMobileMessageSent( - const ::protocol_handler::RawMessagePtr message) { - LOG4CXX_AUTO_TRACE(logger_); -} - -void ApplicationManagerImpl::OnMessageReceived( - hmi_message_handler::MessageSharedPointer message) { - LOG4CXX_AUTO_TRACE(logger_); - - if (!message) { - LOG4CXX_ERROR(logger_, "Null-pointer message received."); - NOTREACHED(); - return; - } - - messages_from_hmi_.PostMessage(impl::MessageFromHmi(message)); -} - ApplicationConstSharedPtr ApplicationManagerImpl::WaitingApplicationByID( const uint32_t hmi_id) const { AppsWaitRegistrationSet app_list = AppsWaitingForRegistration().GetData(); @@ -956,12 +910,12 @@ ApplicationConstSharedPtr ApplicationManagerImpl::WaitingApplicationByID( DataAccessor<AppsWaitRegistrationSet> ApplicationManagerImpl::AppsWaitingForRegistration() const { return DataAccessor<AppsWaitRegistrationSet>(apps_to_register_, - apps_to_register_list_lock_); + apps_to_register_list_lock_ptr_); } bool ApplicationManagerImpl::IsAppsQueriedFrom( const connection_handler::DeviceHandle handle) const { - sync_primitives::AutoLock lock(apps_to_register_list_lock_); + sync_primitives::AutoLock lock(apps_to_register_list_lock_ptr_); AppsWaitRegistrationSet::iterator it = apps_to_register_.begin(); AppsWaitRegistrationSet::const_iterator it_end = apps_to_register_.end(); for (; it != it_end; ++it) { @@ -980,9 +934,25 @@ const ApplicationManagerSettings& ApplicationManagerImpl::get_settings() const { return settings_; } +// Extract the app ID to use for policy based on the UseFullAppID .ini setting +std::string ApplicationManagerImpl::GetCorrectMobileIDFromMessage( + const commands::MessageSharedPtr& message) const { + // If core is expecting a fullAppID + if (get_settings().use_full_app_id()) { + // fullAppID is present and core is configured to use it + if ((*message)[strings::msg_params].keyExists(strings::full_app_id)) { + return (*message)[strings::msg_params][strings::full_app_id].asString(); + } else { + LOG4CXX_DEBUG(logger_, "UseFullAppID is on but only short ID given!"); + } + } + // If core isn't using full or no full given, use regular appID + return (*message)[strings::msg_params][strings::app_id].asString(); +} + void application_manager::ApplicationManagerImpl::MarkAppsGreyOut( const connection_handler::DeviceHandle handle, bool is_greyed_out) { - sync_primitives::AutoLock lock(apps_to_register_list_lock_); + sync_primitives::AutoLock lock(apps_to_register_list_lock_ptr_); AppsWaitRegistrationSet::iterator it = apps_to_register_.begin(); AppsWaitRegistrationSet::const_iterator it_end = apps_to_register_.end(); for (; it != it_end; ++it) { @@ -991,10 +961,6 @@ void application_manager::ApplicationManagerImpl::MarkAppsGreyOut( } } } -void ApplicationManagerImpl::OnErrorSending( - hmi_message_handler::MessageSharedPointer message) { - return; -} void ApplicationManagerImpl::OnDeviceListUpdated( const connection_handler::DeviceMap& device_list) { @@ -1026,7 +992,8 @@ void ApplicationManagerImpl::OnDeviceListUpdated( return; } - smart_objects::SmartObjectSPtr update_list = new smart_objects::SmartObject; + smart_objects::SmartObjectSPtr update_list = + std::make_shared<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; @@ -1036,7 +1003,7 @@ void ApplicationManagerImpl::OnDeviceListUpdated( 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); + rpc_service_->ManageHMICommand(update_list); } void ApplicationManagerImpl::OnFindNewApplicationsRequest() { @@ -1065,7 +1032,7 @@ void ApplicationManagerImpl::SendUpdateAppList() { PrepareApplicationListSO(applications_, applications, *this); PrepareApplicationListSO(apps_to_register_, applications, *this); - ManageHMICommand(request); + rpc_service_->ManageHMICommand(request); } void ApplicationManagerImpl::RemoveDevice( @@ -1113,7 +1080,7 @@ void ApplicationManagerImpl::OnDeviceSwitchingStart( return; } - auto update_list = utils::MakeShared<smart_objects::SmartObject>(); + auto update_list = std::make_shared<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; @@ -1123,7 +1090,7 @@ void ApplicationManagerImpl::OnDeviceSwitchingStart( 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); + rpc_service_->ManageHMICommand(update_list); } void ApplicationManagerImpl::OnDeviceSwitchingFinish( @@ -1152,7 +1119,7 @@ void ApplicationManagerImpl::SwitchApplication(ApplicationSharedPtr app, const std::string& mac_address) { LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(app); - sync_primitives::AutoLock lock(applications_list_lock_); + sync_primitives::AutoLock lock(applications_list_lock_ptr_); DCHECK_OR_RETURN_VOID(1 == applications_.erase(app)); LOG4CXX_DEBUG(logger_, @@ -1203,127 +1170,95 @@ mobile_apis::HMILevel::eType ApplicationManagerImpl::GetDefaultHmiLevel( return default_hmi; } -uint32_t ApplicationManagerImpl::GenerateGrammarID() { - return rand(); -} - -uint32_t ApplicationManagerImpl::GenerateNewHMIAppID() { +bool ApplicationManagerImpl::CheckResumptionRequiredTransportAvailable( + ApplicationConstSharedPtr application) const { + using namespace mobile_apis; LOG4CXX_AUTO_TRACE(logger_); - uint32_t hmi_app_id = get_rand_from_range(1); - LOG4CXX_DEBUG(logger_, "GenerateNewHMIAppID value is: " << hmi_app_id); - while (resume_controller().IsHMIApplicationIdExist(hmi_app_id)) { - LOG4CXX_DEBUG(logger_, "HMI appID " << hmi_app_id << " is exists."); - hmi_app_id = get_rand_from_range(1); - LOG4CXX_DEBUG(logger_, "Trying new value: " << hmi_app_id); - } + const std::map<std::string, std::vector<std::string> >& transport_map = + get_settings().transport_required_for_resumption_map(); - return hmi_app_id; -} + // retrieve transport type string used in .ini file + const std::string transport_type = + GetTransportTypeProfileString(application->device()); + const std::string secondary_transport_type = + GetTransportTypeProfileString(application->secondary_device()); -void ApplicationManagerImpl::ReplaceMobileByHMIAppId( - smart_objects::SmartObject& message) { - MessageHelper::PrintSmartObject(message); - if (message.keyExists(strings::app_id)) { - ApplicationSharedPtr application_ptr = - application(message[strings::app_id].asUInt()); - if (application_ptr.valid()) { - LOG4CXX_DEBUG(logger_, - "ReplaceMobileByHMIAppId from " - << message[strings::app_id].asInt() << " to " - << application_ptr->hmi_app_id()); - message[strings::app_id] = application_ptr->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); - } - break; - } - case smart_objects::SmartType::SmartType_Map: { - std::set<std::string> keys = message.enumerate(); - std::set<std::string>::const_iterator key = keys.begin(); - for (; key != keys.end(); ++key) { - std::string k = *key; - ReplaceMobileByHMIAppId(message[*key]); - } - break; - } - default: { break; } + const smart_objects::SmartObject* app_types_array = application->app_types(); + if (app_types_array == NULL || app_types_array->length() == 0) { + // This app does not have any AppHMIType. In this case, check "EMPTY_APP" + // entry + std::map<std::string, std::vector<std::string> >::const_iterator it = + transport_map.find(std::string("EMPTY_APP")); + if (it == transport_map.end()) { + // if "EMPTY_APP" is not specified, resumption is always enabled + return true; } - } -} - -void ApplicationManagerImpl::ReplaceHMIByMobileAppId( - smart_objects::SmartObject& message) { - if (message.keyExists(strings::app_id)) { - ApplicationSharedPtr application = - application_by_hmi_app(message[strings::app_id].asUInt()); + const std::vector<std::string>& required_transport_list = it->second; - if (application.valid()) { - LOG4CXX_DEBUG(logger_, - "ReplaceHMIByMobileAppId from " - << message[strings::app_id].asInt() << " to " - << application->app_id()); - message[strings::app_id] = application->app_id(); + for (std::vector<std::string>::const_iterator itr = + required_transport_list.begin(); + itr != required_transport_list.end(); + ++itr) { + if (transport_type == *itr || secondary_transport_type == *itr) { + return true; + } } + return false; } 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); - } - break; + // check all AppHMITypes that the app has + for (size_t i = 0; i < app_types_array->length(); i++) { + const std::string app_type_string = + AppHMITypeToString(static_cast<mobile_apis::AppHMIType::eType>( + app_types_array->getElement(i).asUInt())); + bool transport_is_found = false; + + std::map<std::string, std::vector<std::string> >::const_iterator it = + transport_map.find(app_type_string); + if (it == transport_map.end()) { + // this AppHMIType is not listed in .ini file, so resumption is always + // enabled + continue; } - case smart_objects::SmartType::SmartType_Map: { - std::set<std::string> keys = message.enumerate(); - std::set<std::string>::const_iterator key = keys.begin(); - for (; key != keys.end(); ++key) { - ReplaceHMIByMobileAppId(message[*key]); + + const std::vector<std::string>& required_transport_list = it->second; + for (std::vector<std::string>::const_iterator itr = + required_transport_list.begin(); + itr != required_transport_list.end(); + ++itr) { + if (transport_type == *itr || secondary_transport_type == *itr) { + transport_is_found = true; + break; } - break; } - default: { break; } - } - } -} - -bool ApplicationManagerImpl::StartNaviService( - uint32_t app_id, protocol_handler::ServiceType service_type) { - using namespace protocol_handler; - LOG4CXX_AUTO_TRACE(logger_); - if (HMILevelAllowsStreaming(app_id, service_type)) { - NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); - if (navi_service_status_.end() == it) { - std::pair<NaviServiceStatusMap::iterator, bool> res = - navi_service_status_.insert( - std::pair<uint32_t, std::pair<bool, bool> >( - app_id, std::make_pair(false, false))); - if (!res.second) { - LOG4CXX_WARN(logger_, "Navi service refused"); + // if neither primary or secondary transport type is included in the list, + // then resumption will be disabled + if (!transport_is_found) { return false; } - it = res.first; } - // Fill NaviServices map. Set true to first value of pair if - // we've started video service or to second value if we've - // started audio service - service_type == ServiceType::kMobileNav ? it->second.first = true - : it->second.second = true; - application(app_id)->StartStreaming(service_type); return true; - } else { - LOG4CXX_WARN(logger_, "Refused navi service by HMI level"); } - return false; +} + +uint32_t ApplicationManagerImpl::GenerateGrammarID() { + return rand(); +} + +uint32_t ApplicationManagerImpl::GenerateNewHMIAppID() { + LOG4CXX_AUTO_TRACE(logger_); + uint32_t hmi_app_id = get_rand_from_range(1); + LOG4CXX_DEBUG(logger_, "GenerateNewHMIAppID value is: " << hmi_app_id); + + while (resume_controller().IsHMIApplicationIdExist(hmi_app_id)) { + LOG4CXX_DEBUG(logger_, "HMI appID " << hmi_app_id << " is exists."); + hmi_app_id = get_rand_from_range(1); + LOG4CXX_DEBUG(logger_, "Trying new value: " << hmi_app_id); + } + + return hmi_app_id; } bool ApplicationManagerImpl::StartNaviService( @@ -1465,46 +1400,6 @@ void ApplicationManagerImpl::StopNaviService( app->StopStreaming(service_type); } -// 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, - const protocol_handler::ServiceType& type) { - using namespace helpers; - using namespace protocol_handler; - LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG(logger_, - "ServiceType = " << type << ". Session = " << std::hex - << session_key); - - if (type == kRpc) { - LOG4CXX_DEBUG(logger_, "RPC service is about to be started."); - return true; - } - ApplicationSharedPtr app = application(session_key); - if (!app) { - LOG4CXX_WARN(logger_, - "The application with id:" << session_key - << " doesn't exists."); - return false; - } - - if (Compare<ServiceType, EQ, ONE>( - type, ServiceType::kMobileNav, ServiceType::kAudio)) { - if (app->is_navi()) { - return StartNaviService(session_key, type); - } else { - LOG4CXX_WARN(logger_, "Refuse not navi application"); - } - } else { - LOG4CXX_WARN(logger_, "Refuse unknown service"); - } - return false; -} -#pragma GCC diagnostic pop - void ApplicationManagerImpl::OnServiceStartedCallback( const connection_handler::DeviceHandle& device_handle, const int32_t& session_key, @@ -1591,10 +1486,10 @@ void ApplicationManagerImpl::OnServiceEndedCallback( is_resuming = true; is_unexpected_disconnect = false; - ManageMobileCommand( + rpc_service_->ManageMobileCommand( MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( session_key, AppInterfaceUnregisteredReason::TOO_MANY_REQUESTS), - commands::Command::ORIGIN_SDL); + commands::Command::SOURCE_SDL); break; } case CloseSessionReason::kMalformed: { @@ -1627,6 +1522,88 @@ void ApplicationManagerImpl::OnServiceEndedCallback( } } +void ApplicationManagerImpl::OnSecondaryTransportStartedCallback( + const connection_handler::DeviceHandle device_handle, + const int32_t session_key) { + LOG4CXX_AUTO_TRACE(logger_); + + if (device_handle == 0) { + LOG4CXX_WARN(logger_, + "Invalid device handle passed for secondary transport of app " + << session_key); + return; + } + + secondary_transport_devices_cache_[session_key] = device_handle; + + { + sync_primitives::AutoLock auto_lock(applications_list_lock_ptr_); + ApplicationSharedPtr app = application(session_key); + if (!app) { + // It is possible that secondary transport is established prior to + // RegisterAppInterface request being processed. In this case, we will + // update the app's information during RegisterApplication(). + LOG4CXX_DEBUG(logger_, + "Application with id: " << session_key << " is not found"); + return; + } + app->set_secondary_device(device_handle); + } + + // notify the event to HMI through BC.UpdateAppList request + SendUpdateAppList(); + + // if resumption has not been enabled, run it now + resume_controller().RetryResumption(session_key); +} + +void ApplicationManagerImpl::OnSecondaryTransportEndedCallback( + const int32_t session_key) { + LOG4CXX_AUTO_TRACE(logger_); + + DeviceMap::iterator it = secondary_transport_devices_cache_.find(session_key); + if (it == secondary_transport_devices_cache_.end()) { + LOG4CXX_WARN( + logger_, + "Unknown session_key specified while removing secondary transport: " + << session_key); + } else { + secondary_transport_devices_cache_.erase(it); + } + + { + sync_primitives::AutoLock auto_lock(applications_list_lock_ptr_); + ApplicationSharedPtr app = application(session_key); + if (!app) { + LOG4CXX_DEBUG(logger_, + "Application with id: " << session_key << " is not found"); + return; + } + + connection_handler::DeviceHandle device_handle = app->secondary_device(); + if (device_handle == 0) { + LOG4CXX_WARN(logger_, + "Secondary transport of app " << session_key + << " is not found"); + return; + } + + app->set_secondary_device(0); + } + + // notify the event to HMI through BC.UpdateAppList request + SendUpdateAppList(); +} + +bool ApplicationManagerImpl::CheckAppIsNavi(const uint32_t app_id) const { + LOG4CXX_AUTO_TRACE(logger_); + ApplicationSharedPtr app = application(app_id); + if (app) { + return app->is_navi(); + } + return false; +} + #ifdef ENABLE_SECURITY bool ApplicationManagerImpl::OnHandshakeDone( uint32_t connection_key, @@ -1650,6 +1627,11 @@ bool ApplicationManagerImpl::OnHandshakeDone( return false; } +bool ApplicationManagerImpl::OnHandshakeFailed() { + LOG4CXX_AUTO_TRACE(logger_); + return false; +} + void ApplicationManagerImpl::OnCertificateUpdateRequired() { LOG4CXX_AUTO_TRACE(logger_); GetPolicyHandler().OnPTExchangeNeeded(); @@ -1672,20 +1654,12 @@ 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( hmi_message_handler::HMIMessageHandler* handler) { hmi_handler_ = handler; + rpc_service_->set_hmi_message_handler(handler); } void ApplicationManagerImpl::set_connection_handler( @@ -1706,448 +1680,35 @@ protocol_handler::ProtocolHandler& ApplicationManagerImpl::protocol_handler() void ApplicationManagerImpl::set_protocol_handler( protocol_handler::ProtocolHandler* handler) { protocol_handler_ = handler; + rpc_service_->set_protocol_handler(handler); } void ApplicationManagerImpl::StartDevicesDiscovery() { connection_handler().get_device_discovery_starter().StartDevicesDiscovery(); } -void ApplicationManagerImpl::SendMessageToMobile( - const commands::MessageSharedPtr message, bool final_message) { - LOG4CXX_AUTO_TRACE(logger_); - - if (!message) { - LOG4CXX_ERROR(logger_, "Null-pointer message received."); - NOTREACHED(); - return; - } - - if (!protocol_handler_) { - LOG4CXX_WARN(logger_, "No Protocol Handler set"); - return; - } - - ApplicationSharedPtr app = application( - (*message)[strings::params][strings::connection_key].asUInt()); - - const bool is_result_code_exists = - (*message)[strings::msg_params].keyExists(strings::result_code); - - if (!app) { - LOG4CXX_ERROR(logger_, "No application associated with connection key"); - if (is_result_code_exists && - ((*message)[strings::msg_params][strings::result_code] == - NsSmartDeviceLinkRPC::V1::Result::UNSUPPORTED_VERSION)) { - (*message)[strings::params][strings::protocol_version] = - protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_1; - } else { - (*message)[strings::params][strings::protocol_version] = - SupportedSDLVersion(); - } - } else { - (*message)[strings::params][strings::protocol_version] = - app->protocol_version(); - } - - if (app && is_result_code_exists && - (*message)[strings::msg_params][strings::result_code] == - mobile_apis::Result::OUT_OF_MEMORY) { - app->usage_report().RecordRejectionsSyncOutOfMemory(); - } - - mobile_so_factory().attachSchema(*message, false); - LOG4CXX_DEBUG( - logger_, - "Attached schema to message, result if valid: " << message->isValid()); - - // Messages to mobile are not yet prioritized so use default priority value - utils::SharedPtr<Message> message_to_send( - new Message(protocol_handler::MessagePriority::kDefault)); - if (!ConvertSOtoMessage((*message), (*message_to_send))) { - LOG4CXX_WARN(logger_, "Can't send msg to Mobile: failed to create string"); - return; - } - - smart_objects::SmartObject& msg_to_mobile = *message; - // If correlation_id is not present, it is from-HMI message which should be - // checked against policy permissions - if (msg_to_mobile[strings::params].keyExists(strings::correlation_id)) { - request_ctrl_.OnMobileResponse( - msg_to_mobile[strings::params][strings::correlation_id].asUInt(), - msg_to_mobile[strings::params][strings::connection_key].asUInt(), - msg_to_mobile[strings::params][strings::function_id].asInt()); -#ifdef SDL_REMOTE_CONTROL - const mobile_apis::FunctionID::eType function_id = - static_cast<mobile_apis::FunctionID::eType>( - (*message)[strings::params][strings::function_id].asUInt()); - if (function_id == mobile_apis::FunctionID::RegisterAppInterfaceID && - (*message)[strings::msg_params][strings::success].asBool()) { - LOG4CXX_INFO(logger_, - "Registered app " - << app->app_id() << " is " - << (plugin_manager_.IsAppForPlugins(app) ? "" : "not ") - << "for plugins."); - } -#endif // SDL_REMOTE_CONTROL - } else if (app) { - mobile_apis::FunctionID::eType function_id = - static_cast<mobile_apis::FunctionID::eType>( - (*message)[strings::params][strings::function_id].asUInt()); - RPCParams params; - - const smart_objects::SmartObject& s_map = (*message)[strings::msg_params]; - if (smart_objects::SmartType_Map == s_map.getType()) { - smart_objects::SmartMap::iterator iter = s_map.map_begin(); - smart_objects::SmartMap::iterator iter_end = s_map.map_end(); - - for (; iter != iter_end; ++iter) { - if (true == iter->second.asBool()) { - LOG4CXX_INFO(logger_, "Request's param: " << iter->first); - params.insert(iter->first); - } - } - } - const std::string string_functionID = - MessageHelper::StringifiedFunctionID(function_id); - const mobile_apis::Result::eType check_result = - CheckPolicyPermissions(app, string_functionID, params); - if (mobile_apis::Result::SUCCESS != check_result) { - LOG4CXX_WARN(logger_, - "Function \"" << string_functionID << "\" (#" << function_id - << ") not allowed by policy"); - return; - } - -#ifdef EXTERNAL_PROPRIETARY_MODE - if (function_id == mobile_apis::FunctionID::OnSystemRequestID) { - mobile_apis::RequestType::eType request_type = - static_cast<mobile_apis::RequestType::eType>( - (*message)[strings::msg_params][strings::request_type].asUInt()); - if (mobile_apis::RequestType::PROPRIETARY == request_type || - mobile_apis::RequestType::HTTP == request_type) { - GetPolicyHandler().OnUpdateRequestSentToMobile(); - } - } -#endif // EXTERNAL_PROPRIETARY_MODE - } - - if (message_to_send->binary_data()) { - LOG4CXX_DEBUG( - logger_, - "Binary data size: " << message_to_send->binary_data()->size()); - } - messages_to_mobile_.PostMessage( - impl::MessageToMobile(message_to_send, final_message)); -} - void ApplicationManagerImpl::TerminateRequest(const uint32_t connection_key, const uint32_t corr_id, const int32_t function_id) { request_ctrl_.TerminateRequest(corr_id, connection_key, function_id, true); } -bool ApplicationManagerImpl::ManageMobileCommand( - const commands::MessageSharedPtr message, - commands::Command::CommandOrigin origin) { - LOG4CXX_AUTO_TRACE(logger_); - - if (!message) { - LOG4CXX_WARN(logger_, "Null-pointer message received."); - return false; - } - - if (IsLowVoltage()) { - LOG4CXX_WARN(logger_, "Low Voltage is active"); - return false; - } -#ifdef DEBUG - MessageHelper::PrintSmartObject(*message); -#endif - - LOG4CXX_DEBUG(logger_, "Trying to create message in mobile factory."); - utils::SharedPtr<commands::Command> command( - MobileCommandFactory::CreateCommand(message, origin, *this)); - - if (!command) { - LOG4CXX_WARN(logger_, - "RET Failed to create mobile command from smart object"); - 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()); - - // Notifications from HMI have no such parameter - uint32_t correlation_id = - (*message)[strings::params].keyExists(strings::correlation_id) - ? (*message)[strings::params][strings::correlation_id].asUInt() - : 0; - - int32_t protocol_type = - (*message)[strings::params][strings::protocol_type].asUInt(); - - ApplicationSharedPtr app; - int32_t message_type = - (*message)[strings::params][strings::message_type].asInt(); - - if (((mobile_apis::FunctionID::RegisterAppInterfaceID != function_id) && - (protocol_type == commands::CommandImpl::mobile_protocol_type_)) && - (mobile_apis::FunctionID::UnregisterAppInterfaceID != function_id)) { - app = application(connection_key); - if (!app) { - LOG4CXX_ERROR(logger_, "RET APPLICATION_NOT_REGISTERED"); - smart_objects::SmartObjectSPtr response = - MessageHelper::CreateNegativeResponse( - connection_key, - static_cast<int32_t>(function_id), - correlation_id, - static_cast<int32_t>( - mobile_apis::Result::APPLICATION_NOT_REGISTERED)); - - SendMessageToMobile(response); - return false; - } - - // Message for "CheckPermission" must be with attached schema - mobile_so_factory().attachSchema(*message, false); - } - - if (message_type == mobile_apis::messageType::response) { - if (command->Init()) { - command->Run(); - command->CleanUp(); - } - return true; - } - if (message_type == mobile_apis::messageType::notification) { - request_ctrl_.addNotification(command); - if (command->Init()) { - command->Run(); - if (command->CleanUp()) { - request_ctrl_.removeNotification(command.get()); - } - // If CleanUp returned false notification should remove it self. - } - return true; - } - - if (message_type == mobile_apis::messageType::request) { - // commands will be launched from requesr_ctrl - mobile_apis::HMILevel::eType app_hmi_level = - mobile_apis::HMILevel::INVALID_ENUM; - if (app) { - app_hmi_level = app->hmi_level(); - } - - // commands will be launched from request_ctrl - - const request_controller::RequestController::TResult result = - request_ctrl_.addMobileRequest(command, app_hmi_level); - - if (result == request_controller::RequestController::SUCCESS) { - LOG4CXX_DEBUG(logger_, "Perform request"); - } else if (result == request_controller::RequestController:: - TOO_MANY_PENDING_REQUESTS) { - LOG4CXX_ERROR(logger_, - "RET Unable top perform request: " - << "TOO_MANY_PENDING_REQUESTS"); - - smart_objects::SmartObjectSPtr response = - MessageHelper::CreateNegativeResponse( - connection_key, - static_cast<int32_t>(function_id), - correlation_id, - static_cast<int32_t>( - mobile_apis::Result::TOO_MANY_PENDING_REQUESTS)); - ApplicationSharedPtr app_ptr = application(connection_key); - if (app_ptr) { - app_ptr->usage_report().RecordRemovalsForBadBehavior(); - } - - SendMessageToMobile(response); - return false; - } else if (result == - request_controller::RequestController::TOO_MANY_REQUESTS) { - LOG4CXX_ERROR(logger_, - "RET Unable to perform request: " - << "TOO_MANY_REQUESTS"); - - ManageMobileCommand( - MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( - connection_key, - mobile_api::AppInterfaceUnregisteredReason::TOO_MANY_REQUESTS), - commands::Command::ORIGIN_SDL); - - UnregisterApplication(connection_key, - mobile_apis::Result::TOO_MANY_PENDING_REQUESTS, - false); - ApplicationSharedPtr app_ptr = application(connection_key); - if (app_ptr) { - app_ptr->usage_report().RecordRemovalsForBadBehavior(); - } - return false; - } else if (result == request_controller::RequestController:: - NONE_HMI_LEVEL_MANY_REQUESTS) { - LOG4CXX_ERROR(logger_, - "RET Unable to perform request: " - << "REQUEST_WHILE_IN_NONE_HMI_LEVEL"); - - ManageMobileCommand( - MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( - connection_key, - mobile_api::AppInterfaceUnregisteredReason:: - REQUEST_WHILE_IN_NONE_HMI_LEVEL), - commands::Command::ORIGIN_SDL); - - ApplicationSharedPtr app_ptr = application(connection_key); - if (app_ptr) { - app_ptr->usage_report().RecordRemovalsForBadBehavior(); - } - UnregisterApplication( - connection_key, mobile_apis::Result::INVALID_ENUM, false); - return false; - } else { - LOG4CXX_ERROR(logger_, "RET Unable to perform request: Unknown case"); - return false; - } - return true; - } - - LOG4CXX_ERROR(logger_, "RET UNKNOWN MESSAGE TYPE " << message_type); - return false; -} - void ApplicationManagerImpl::RemoveHMIFakeParameters( - application_manager::MessagePtr& message) { + application_manager::commands::MessageSharedPtr& message) { LOG4CXX_AUTO_TRACE(logger_); - using namespace NsSmartDeviceLink::NsSmartObjects; - using namespace NsSmartDeviceLink::NsJSONHandler; - SmartObject so; - - Formatters::FormatterJsonRpc::FromString<hmi_apis::FunctionID::eType, - hmi_apis::messageType::eType>( - message->json_message(), so); - - std::string formatted_message; - namespace Formatters = NsSmartDeviceLink::NsJSONHandler::Formatters; hmi_apis::HMI_API factory; - factory.attachSchema(so, true); - Formatters::FormatterJsonRpc::ToString(so, formatted_message); - message->set_json_message(formatted_message); -} - -void ApplicationManagerImpl::SendMessageToHMI( - const commands::MessageSharedPtr message) { - LOG4CXX_AUTO_TRACE(logger_); - - if (!message) { - LOG4CXX_WARN(logger_, "Null-pointer message received."); - NOTREACHED(); - return; - } - - if (!hmi_handler_) { - LOG4CXX_WARN(logger_, "No HMI Handler set"); - return; - } - - // SmartObject |message| has no way to declare priority for now - utils::SharedPtr<Message> message_to_send( - new Message(protocol_handler::MessagePriority::kDefault)); - if (!message_to_send) { - LOG4CXX_ERROR(logger_, "Null pointer"); - return; - } - - hmi_so_factory().attachSchema(*message, false); - LOG4CXX_INFO( - logger_, - "Attached schema to message, result if valid: " << message->isValid()); - -#ifdef HMI_DBUS_API - message_to_send->set_smart_object(*message); -#else - if (!ConvertSOtoMessage(*message, *message_to_send)) { - LOG4CXX_WARN(logger_, - "Cannot send message to HMI: failed to create string"); - return; - } -#endif // HMI_DBUS_API - - messages_to_hmi_.PostMessage(impl::MessageToHmi(message_to_send)); -} - -bool ApplicationManagerImpl::ManageHMICommand( - const commands::MessageSharedPtr message) { - LOG4CXX_AUTO_TRACE(logger_); - - if (!message) { - LOG4CXX_WARN(logger_, "Null-pointer message received."); - return false; - } - - if (IsLowVoltage()) { - LOG4CXX_WARN(logger_, "Low Voltage is active"); - return false; - } - - MessageHelper::PrintSmartObject(*message); - - CommandSharedPtr command = HMICommandFactory::CreateCommand(message, *this); - if (!command) { - LOG4CXX_WARN(logger_, "Failed to create command from smart object"); - 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)[strings::params][strings::message_type].asInt(); - - if (kRequest == message_type) { - LOG4CXX_DEBUG(logger_, "ManageHMICommand"); - request_ctrl_.addHMIRequest(command); - } - - if (command->Init()) { - command->Run(); - if (kResponse == message_type) { - const uint32_t correlation_id = - (*message)[strings::params][strings::correlation_id].asUInt(); - const int32_t function_id = - (*message)[strings::params][strings::function_id].asInt(); - request_ctrl_.OnHMIResponse(correlation_id, function_id); - } - return true; - } - return false; + factory.attachSchema(*message, true); } bool ApplicationManagerImpl::Init(resumption::LastState& last_state, media_manager::MediaManager* media_manager) { LOG4CXX_TRACE(logger_, "Init application manager"); + plugin_manager_.reset(new plugin_manager::RPCPluginManagerImpl( + *this, *rpc_service_, *hmi_capabilities_, *policy_handler_)); + if (!plugin_manager_->LoadPlugins(get_settings().plugins_folder())) { + LOG4CXX_ERROR(logger_, "Plugins are not loaded"); + return false; + } const std::string app_storage_folder = get_settings().app_storage_folder(); if (!InitDirectory(app_storage_folder, TYPE_STORAGE) || !IsReadWriteAllowed(app_storage_folder, TYPE_STORAGE)) { @@ -2203,18 +1764,6 @@ bool ApplicationManagerImpl::Init(resumption::LastState& last_state, } app_launch_ctrl_.reset(new app_launch::AppLaunchCtrlImpl( *app_launch_dto_.get(), *this, settings_)); - -#ifdef SDL_REMOTE_CONTROL - if (!hmi_handler_) { - LOG4CXX_ERROR(logger_, "HMI message handler was not initialized"); - return false; - } - plugin_manager_.SetServiceHandler(utils::MakeShared<CoreService>(*this)); - plugin_manager_.LoadPlugins(settings_.plugins_folder()); - plugin_manager_.OnServiceStateChanged( - functional_modules::ServiceState::HMI_ADAPTER_INITIALIZED); -#endif // SDL_REMOTE_CONTROL - return true; } @@ -2225,6 +1774,8 @@ bool ApplicationManagerImpl::Stop() { stopping_application_mng_lock_.Release(); application_list_update_timer_.Stop(); try { + SetUnregisterAllApplicationsReason( + mobile_api::AppInterfaceUnregisteredReason::IGNITION_OFF); UnregisterAllApplications(); } catch (...) { LOG4CXX_ERROR(logger_, @@ -2239,155 +1790,6 @@ bool ApplicationManagerImpl::Stop() { return true; } -bool ApplicationManagerImpl::ConvertMessageToSO( - const Message& message, smart_objects::SmartObject& output) { - LOG4CXX_AUTO_TRACE(logger_); - LOG4CXX_DEBUG(logger_, - "\t\t\tMessage to convert: protocol " - << message.protocol_version() << "; json " - << message.json_message()); - - switch (message.protocol_version()) { - case protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5: - case protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_4: - case protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_3: - case protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_2: { - const bool conversion_result = - formatters::CFormatterJsonSDLRPCv2::fromString( - message.json_message(), - output, - message.function_id(), - message.type(), - message.correlation_id()); - - rpc::ValidationReport report("RPC"); - - if (!conversion_result || - !mobile_so_factory().attachSchema(output, true) || - ((output.validate(&report) != smart_objects::Errors::OK))) { - LOG4CXX_WARN(logger_, - "Failed to parse string to smart object :" - << message.json_message()); - utils::SharedPtr<smart_objects::SmartObject> response( - MessageHelper::CreateNegativeResponse( - message.connection_key(), - 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; - } - LOG4CXX_DEBUG(logger_, - "Convertion result for sdl object is true function_id " - << output[jhs::S_PARAMS][jhs::S_FUNCTION_ID].asInt()); - - output[strings::params][strings::connection_key] = - message.connection_key(); - output[strings::params][strings::protocol_version] = - message.protocol_version(); - if (message.binary_data()) { - if (message.payload_size() < message.data_size()) { - LOG4CXX_ERROR(logger_, - "Incomplete binary" - << " binary size should be " << message.data_size() - << " payload data size is " - << message.payload_size()); - utils::SharedPtr<smart_objects::SmartObject> response( - MessageHelper::CreateNegativeResponse( - message.connection_key(), - message.function_id(), - message.correlation_id(), - mobile_apis::Result::INVALID_DATA)); - ManageMobileCommand(response, commands::Command::ORIGIN_SDL); - return false; - } - output[strings::params][strings::binary_data] = - *(message.binary_data()); - } - break; - } - case protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_HMI: { -#ifdef ENABLE_LOG - int32_t result = -#endif - formatters::FormatterJsonRpc::FromString< - hmi_apis::FunctionID::eType, - hmi_apis::messageType::eType>(message.json_message(), output); - LOG4CXX_DEBUG(logger_, - "Convertion result: " - << result << " function id " - << output[jhs::S_PARAMS][jhs::S_FUNCTION_ID].asInt()); - if (!hmi_so_factory().attachSchema(output, false)) { - LOG4CXX_WARN(logger_, "Failed to attach schema to object."); - return false; - } - - 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; - } - case protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_1: { - static NsSmartDeviceLinkRPC::V1::v4_protocol_v1_2_no_extra v1_shema; - - if (message.function_id() == 0 || message.type() == kUnknownType) { - LOG4CXX_ERROR(logger_, "Message received: UNSUPPORTED_VERSION"); - - int32_t conversation_result = - formatters::CFormatterJsonSDLRPCv1::fromString< - NsSmartDeviceLinkRPC::V1::FunctionID::eType, - NsSmartDeviceLinkRPC::V1::messageType::eType>( - message.json_message(), output); - - if (formatters::CFormatterJsonSDLRPCv1::kSuccess == - conversation_result) { - smart_objects::SmartObject params = smart_objects::SmartObject( - smart_objects::SmartType::SmartType_Map); - - output[strings::params][strings::message_type] = - NsSmartDeviceLinkRPC::V1::messageType::response; - output[strings::params][strings::connection_key] = - message.connection_key(); - - output[strings::msg_params] = smart_objects::SmartObject( - smart_objects::SmartType::SmartType_Map); - output[strings::msg_params][strings::success] = false; - output[strings::msg_params][strings::result_code] = - NsSmartDeviceLinkRPC::V1::Result::UNSUPPORTED_VERSION; - - smart_objects::SmartObjectSPtr msg_to_send = - new smart_objects::SmartObject(output); - v1_shema.attachSchema(*msg_to_send, false); - SendMessageToMobile(msg_to_send); - return false; - } - } - break; - } - default: - LOG4CXX_WARN(logger_, - "Application used unsupported protocol :" - << message.protocol_version() << "."); - return false; - } - - LOG4CXX_DEBUG(logger_, "Successfully parsed message into smart object"); - return true; -} - bool ApplicationManagerImpl::ConvertSOtoMessage( const smart_objects::SmartObject& message, Message& output) { LOG4CXX_AUTO_TRACE(logger_); @@ -2487,162 +1889,6 @@ bool ApplicationManagerImpl::ConvertSOtoMessage( return true; } -MessageValidationResult ApplicationManagerImpl::ValidateMessageBySchema( - const Message& message) { - LOG4CXX_AUTO_TRACE(logger_); - smart_objects::SmartObject so; - using namespace protocol_handler; - switch (message.protocol_version()) { - case MajorProtocolVersion::PROTOCOL_VERSION_5: - case MajorProtocolVersion::PROTOCOL_VERSION_4: - case MajorProtocolVersion::PROTOCOL_VERSION_3: - case MajorProtocolVersion::PROTOCOL_VERSION_2: { - const bool conversion_result = - formatters::CFormatterJsonSDLRPCv2::fromString( - message.json_message(), - so, - message.function_id(), - message.type(), - message.correlation_id()); - if (!conversion_result) { - return INVALID_JSON; - } - - if (!mobile_so_factory().attachSchema(so, true)) { - return INVALID_METADATA; - } - 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; - } - case MajorProtocolVersion::PROTOCOL_VERSION_HMI: { - const int32_t conversion_result = formatters::FormatterJsonRpc:: - FromString<hmi_apis::FunctionID::eType, hmi_apis::messageType::eType>( - message.json_message(), so); - if (0 != conversion_result) { - LOG4CXX_WARN(logger_, - "Failed to parse json from HMI: " << conversion_result); - return INVALID_JSON; - } - - if (!hmi_so_factory().attachSchema(so, true)) { - return INVALID_METADATA; - } - - 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; - } - default: { return UNSUPPORTED_PROTOCOL; } - } - return SUCCESS; -} - -utils::SharedPtr<Message> ApplicationManagerImpl::ConvertRawMsgToMessage( - const ::protocol_handler::RawMessagePtr message) { - LOG4CXX_AUTO_TRACE(logger_); - DCHECK(message); - utils::SharedPtr<Message> outgoing_message; - - LOG4CXX_DEBUG(logger_, "Service type." << message->service_type()); - if (message->service_type() != protocol_handler::kRpc && - message->service_type() != protocol_handler::kBulk) { - // skip this message, not under handling of ApplicationManager - LOG4CXX_TRACE(logger_, "Skipping message; not the under AM handling."); - return outgoing_message; - } - - Message* convertion_result = - MobileMessageHandler::HandleIncomingMessageProtocol(message); - - if (convertion_result) { - outgoing_message = convertion_result; - } else { - LOG4CXX_ERROR(logger_, "Received invalid message"); - } - return outgoing_message; -} - -void ApplicationManagerImpl::ProcessMessageFromMobile( - const utils::SharedPtr<Message> message) { - LOG4CXX_AUTO_TRACE(logger_); -#ifdef TELEMETRY_MONITOR - AMTelemetryObserver::MessageMetricSharedPtr metric( - new AMTelemetryObserver::MessageMetric()); - metric->begin = date_time::DateTime::getCurrentTime(); -#endif // TELEMETRY_MONITOR - smart_objects::SmartObjectSPtr so_from_mobile = - utils::MakeShared<smart_objects::SmartObject>(); - - DCHECK_OR_RETURN_VOID(so_from_mobile); - if (!so_from_mobile) { - LOG4CXX_ERROR(logger_, "Null pointer"); - return; - } - - if (!ConvertMessageToSO(*message, *so_from_mobile)) { - LOG4CXX_ERROR(logger_, "Cannot create smart object from message"); - return; - } -#ifdef TELEMETRY_MONITOR - metric->message = so_from_mobile; -#endif // TELEMETRY_MONITOR - - if (!ManageMobileCommand(so_from_mobile, commands::Command::ORIGIN_MOBILE)) { - LOG4CXX_ERROR(logger_, "Received command didn't run successfully"); - } -#ifdef TELEMETRY_MONITOR - metric->end = date_time::DateTime::getCurrentTime(); - if (metric_observer_) { - metric_observer_->OnMessage(metric); - } -#endif // TELEMETRY_MONITOR -} - -void ApplicationManagerImpl::ProcessMessageFromHMI( - const utils::SharedPtr<Message> message) { - LOG4CXX_AUTO_TRACE(logger_); - smart_objects::SmartObjectSPtr smart_object(new smart_objects::SmartObject); - - if (!smart_object) { - LOG4CXX_ERROR(logger_, "Null pointer"); - return; - } - -#ifdef HMI_DBUS_API - *smart_object = message->smart_object(); -#else - if (!ConvertMessageToSO(*message, *smart_object)) { - if (application_manager::MessageType::kResponse == - (*smart_object)[strings::params][strings::message_type].asInt()) { - (*smart_object).erase(strings::msg_params); - (*smart_object)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::INVALID_DATA; - (*smart_object)[strings::msg_params][strings::info] = - std::string("Received invalid data on HMI response"); - } else { - LOG4CXX_ERROR(logger_, "Cannot create smart object from message"); - return; - } - } -#endif // HMI_DBUS_API - - LOG4CXX_DEBUG(logger_, "Converted message, trying to create hmi command"); - if (!ManageHMICommand(smart_object)) { - LOG4CXX_ERROR(logger_, "Received command didn't run successfully"); - } -} - hmi_apis::HMI_API& ApplicationManagerImpl::hmi_so_factory() { if (!hmi_so_factory_) { hmi_so_factory_ = new hmi_apis::HMI_API; @@ -2824,7 +2070,7 @@ void ApplicationManagerImpl::CreateApplications(SmartArray& obj_array, app->set_vr_synonyms(vrSynonym); app->set_tts_name(ttsName); - sync_primitives::AutoLock lock(apps_to_register_list_lock_); + sync_primitives::AutoLock lock(apps_to_register_list_lock_ptr_); LOG4CXX_DEBUG( logger_, "apps_to_register_ size before: " << apps_to_register_.size()); apps_to_register_.insert(app); @@ -2868,7 +2114,7 @@ bool ApplicationManagerImpl::is_attenuated_supported() const { #ifdef TELEMETRY_MONITOR void ApplicationManagerImpl::SetTelemetryObserver( AMTelemetryObserver* observer) { - metric_observer_ = observer; + rpc_handler_->SetTelemetryObserver(observer); } #endif // TELEMETRY_MONITOR @@ -2909,6 +2155,14 @@ void ApplicationManagerImpl::set_application_id(const int32_t correlation_id, std::pair<const int32_t, const uint32_t>(correlation_id, app_id)); } +uint32_t ApplicationManagerImpl::get_current_audio_source() const { + return current_audio_source_; +} + +void ApplicationManagerImpl::set_current_audio_source(const uint32_t source) { + current_audio_source_ = source; +} + void ApplicationManagerImpl::AddPolicyObserver( policy::PolicyHandlerObserver* listener) { GetPolicyHandler().add_listener(listener); @@ -3001,10 +2255,14 @@ void ApplicationManagerImpl::ClearAppsPersistentData() { void ApplicationManagerImpl::SendOnSDLClose() { LOG4CXX_AUTO_TRACE(logger_); - + if (IsLowVoltage()) { + LOG4CXX_TRACE(logger_, "SDL is in Low Voltage State"); + return; + } // must be sent to PASA HMI on shutdown synchronously smart_objects::SmartObjectSPtr msg = - new smart_objects::SmartObject(smart_objects::SmartType_Map); + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); (*msg)[strings::params][strings::function_id] = hmi_apis::FunctionID::BasicCommunication_OnSDLClose; @@ -3021,7 +2279,7 @@ void ApplicationManagerImpl::SendOnSDLClose() { } // SmartObject |message| has no way to declare priority for now - utils::SharedPtr<Message> message_to_send( + std::shared_ptr<Message> message_to_send( new Message(protocol_handler::MessagePriority::kDefault)); hmi_so_factory().attachSchema(*msg, false); @@ -3029,15 +2287,11 @@ void ApplicationManagerImpl::SendOnSDLClose() { logger_, "Attached schema to message, result if valid: " << msg->isValid()); -#ifdef HMI_DBUS_API - message_to_send->set_smart_object(*msg); -#else if (!ConvertSOtoMessage(*msg, *message_to_send)) { LOG4CXX_WARN(logger_, "Cannot send message to HMI: failed to create string"); return; } -#endif // HMI_DBUS_API if (!hmi_handler_) { LOG4CXX_WARN(logger_, "No HMI Handler set"); @@ -3068,10 +2322,10 @@ void ApplicationManagerImpl::UnregisterAllApplications() { ApplicationSetConstIt it = accessor.GetData().begin(); while (it != accessor.GetData().end()) { ApplicationSharedPtr app_to_remove = *it; - ManageMobileCommand( + rpc_service_->ManageMobileCommand( MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( app_to_remove->app_id(), unregister_reason_), - commands::Command::ORIGIN_SDL); + commands::Command::SOURCE_SDL); UnregisterApplication(app_to_remove->app_id(), mobile_apis::Result::INVALID_ENUM, is_ignition_off, @@ -3090,7 +2344,7 @@ void ApplicationManagerImpl::UnregisterAllApplications() { void ApplicationManagerImpl::RemoveAppsWaitingForRegistration( const connection_handler::DeviceHandle handle) { DevicePredicate device_finder(handle); - apps_to_register_list_lock_.Acquire(); + apps_to_register_list_lock_ptr_->Acquire(); AppsWaitRegistrationSet::iterator it_app = std::find_if( apps_to_register_.begin(), apps_to_register_.end(), device_finder); @@ -3103,7 +2357,7 @@ void ApplicationManagerImpl::RemoveAppsWaitingForRegistration( apps_to_register_.begin(), apps_to_register_.end(), device_finder); } - apps_to_register_list_lock_.Release(); + apps_to_register_list_lock_ptr_->Release(); } void ApplicationManagerImpl::UnregisterApplication( @@ -3174,7 +2428,7 @@ void ApplicationManagerImpl::UnregisterApplication( ApplicationSharedPtr app_to_remove; connection_handler::DeviceHandle handle = 0; { - sync_primitives::AutoLock lock(applications_list_lock_); + sync_primitives::AutoLock lock(applications_list_lock_ptr_); auto it_app = applications_.begin(); while (applications_.end() != it_app) { if (app_id == (*it_app)->app_id()) { @@ -3194,11 +2448,13 @@ void ApplicationManagerImpl::UnregisterApplication( return; } + if (is_resuming) { resume_controller().SaveApplication(app_to_remove); } else { resume_controller().RemoveApplicationFromSaved(app_to_remove); } + (hmi_capabilities_->get_hmi_language_handler()) .OnUnregisterApplication(app_id); AppV4DevicePredicate finder(handle); @@ -3214,18 +2470,17 @@ void ApplicationManagerImpl::UnregisterApplication( commands_holder_->Clear(app_to_remove); - if (audio_pass_thru_active_) { + if (EndAudioPassThru(app_id)) { // May be better to put this code in MessageHelper? - EndAudioPassThrough(); StopAudioPassThru(app_id); MessageHelper::SendStopAudioPathThru(*this); } - -#ifdef SDL_REMOTE_CONTROL - plugin_manager_.OnApplicationEvent( - functional_modules::ApplicationEvent::kApplicationUnregistered, - app_to_remove); -#endif + auto on_app_unregistered = + [app_to_remove](plugin_manager::RPCPlugin& plugin) { + plugin.OnApplicationEvent(plugin_manager::kApplicationUnregistered, + app_to_remove); + }; + plugin_manager_->ForEachPlugin(on_app_unregistered); MessageHelper::SendOnAppUnregNotificationToHMI( app_to_remove, is_unexpected_disconnect, *this); @@ -3238,144 +2493,12 @@ void ApplicationManagerImpl::OnAppUnauthorized(const uint32_t& app_id) { connection_handler::kUnauthorizedApp); } -void ApplicationManagerImpl::Handle(const impl::MessageFromMobile message) { - LOG4CXX_AUTO_TRACE(logger_); - - if (!message) { - LOG4CXX_ERROR(logger_, "Null-pointer message received."); - return; - } - sync_primitives::AutoLock lock(stopping_application_mng_lock_); - if (is_stopping_) { - LOG4CXX_INFO(logger_, "Application manager is stopping"); - return; - } -#ifdef SDL_REMOTE_CONTROL - if (plugin_manager_.IsMessageForPlugin(message)) { - if (functional_modules::ProcessResult::PROCESSED == - plugin_manager_.ProcessMessage(message)) { - LOG4CXX_INFO(logger_, "Message is processed by plugin."); - return; - } - } -#endif - ProcessMessageFromMobile(message); -} - -void ApplicationManagerImpl::Handle(const impl::MessageToMobile message) { - if (!protocol_handler_) { - LOG4CXX_WARN(logger_, - "Protocol Handler is not set; cannot send message to mobile."); - return; - } - - utils::SharedPtr<protocol_handler::RawMessage> rawMessage = - MobileMessageHandler::HandleOutgoingMessageProtocol(message); - - if (!rawMessage) { - LOG4CXX_ERROR(logger_, "Failed to create raw message."); - return; - } - - bool is_final = message.is_final; - bool close_session = false; - if (is_final) { - if (1 < connection_handler().GetConnectionSessionsCount( - message->connection_key())) { - is_final = false; - close_session = true; - } - } - - protocol_handler_->SendMessageToMobileApp(rawMessage, is_final); - LOG4CXX_INFO(logger_, "Message for mobile given away"); - - if (close_session) { - connection_handler().CloseSession(message->connection_key(), - connection_handler::kCommon); - } -} - -void ApplicationManagerImpl::Handle(const impl::MessageFromHmi message) { - LOG4CXX_AUTO_TRACE(logger_); - - if (!message) { - LOG4CXX_ERROR(logger_, "Null-pointer message received."); - return; - } - -#ifdef SDL_REMOTE_CONTROL - if (plugin_manager_.IsHMIMessageForPlugin(message)) { - functional_modules::ProcessResult result = - plugin_manager_.ProcessHMIMessage(message); - if (functional_modules::ProcessResult::PROCESSED == result || - functional_modules::ProcessResult::FAILED == result) { - LOG4CXX_INFO(logger_, "Message is processed by plugin."); - return; - } - } -#endif - - ProcessMessageFromHMI(message); -} - -void ApplicationManagerImpl::Handle(const impl::MessageToHmi message) { - LOG4CXX_AUTO_TRACE(logger_); - if (!hmi_handler_) { - LOG4CXX_ERROR(logger_, "Observer is not set for HMIMessageHandler"); - return; - } - - hmi_handler_->SendMessageToHMI(message); - LOG4CXX_INFO(logger_, "Message for HMI given away"); -} - -void ApplicationManagerImpl::Handle(const impl::AudioData message) { - LOG4CXX_AUTO_TRACE(logger_); - smart_objects::SmartObjectSPtr on_audio_pass = - new smart_objects::SmartObject(); - - if (!on_audio_pass) { - LOG4CXX_ERROR(logger_, "OnAudioPassThru NULL pointer"); - return; - } - - LOG4CXX_DEBUG(logger_, "Fill smart object"); - - (*on_audio_pass)[strings::params][strings::message_type] = - application_manager::MessageType::kNotification; - - (*on_audio_pass)[strings::params][strings::connection_key] = - static_cast<int32_t>(message.session_key); - (*on_audio_pass)[strings::params][strings::function_id] = - mobile_apis::FunctionID::OnAudioPassThruID; - - LOG4CXX_DEBUG(logger_, "Fill binary data"); - // binary data - (*on_audio_pass)[strings::params][strings::binary_data] = - smart_objects::SmartObject(message.binary_data); - - LOG4CXX_DEBUG(logger_, "After fill binary data"); - LOG4CXX_DEBUG(logger_, "Send data"); - CommandSharedPtr command(MobileCommandFactory::CreateCommand( - on_audio_pass, commands::Command::ORIGIN_SDL, *this)); - if (!command) { - LOG4CXX_WARN(logger_, "Failed to create mobile command from smart object"); - return; - } - - if (command->Init()) { - command->Run(); - command->CleanUp(); - } -} - mobile_apis::Result::eType ApplicationManagerImpl::CheckPolicyPermissions( const ApplicationSharedPtr app, const std::string& function_id, const RPCParams& rpc_params, CommandParametersPermissions* params_permissions) { - LOG4CXX_INFO(logger_, "CheckPolicyPermissions"); + LOG4CXX_AUTO_TRACE(logger_); // TODO(AOleynik): Remove check of policy_enable, when this flag will be // unused in config file if (!GetPolicyHandler().PolicyEnabled()) { @@ -3423,17 +2546,36 @@ mobile_apis::Result::eType ApplicationManagerImpl::CheckPolicyPermissions( return mobile_api::Result::SUCCESS; } +bool ApplicationManagerImpl::is_stopping() const { + sync_primitives::AutoLock lock(stopping_application_mng_lock_); + return is_stopping_; +} + +bool ApplicationManagerImpl::is_audio_pass_thru_active() const { + return audio_pass_thru_active_; +} + void ApplicationManagerImpl::OnLowVoltage() { LOG4CXX_AUTO_TRACE(logger_); is_low_voltage_ = true; + resume_ctrl_->SaveLowVoltageTime(); + resume_ctrl_->StopSavePersistentDataTimer(); request_ctrl_.OnLowVoltage(); } -bool ApplicationManagerImpl::IsLowVoltage() { - LOG4CXX_TRACE(logger_, "result: " << is_low_voltage_); +bool ApplicationManagerImpl::IsLowVoltage() const { + LOG4CXX_TRACE(logger_, "Result: " << is_low_voltage_); return is_low_voltage_; } +void ApplicationManagerImpl::OnWakeUp() { + LOG4CXX_AUTO_TRACE(logger_); + is_low_voltage_ = false; + resume_ctrl_->SaveWakeUpTime(); + resume_ctrl_->StartSavePersistentDataTimer(); + request_ctrl_.OnWakeUp(); +} + std::string ApplicationManagerImpl::GetHashedAppID( uint32_t connection_key, const std::string& mobile_app_id) const { connection_handler::DeviceHandle device_id = 0; @@ -3518,10 +2660,10 @@ void ApplicationManagerImpl::ForbidStreaming(uint32_t app_id) { } } if (unregister) { - ManageMobileCommand( + rpc_service_->ManageMobileCommand( MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( app_id, PROTOCOL_VIOLATION), - commands::Command::ORIGIN_SDL); + commands::Command::SOURCE_SDL); UnregisterApplication(app_id, ABORTED); return; } @@ -3530,7 +2672,6 @@ void ApplicationManagerImpl::ForbidStreaming(uint32_t app_id) { void ApplicationManagerImpl::OnAppStreaming( uint32_t app_id, protocol_handler::ServiceType service_type, bool state) { - using namespace protocol_handler; LOG4CXX_AUTO_TRACE(logger_); ApplicationSharedPtr app = application(app_id); @@ -3543,11 +2684,11 @@ void ApplicationManagerImpl::OnAppStreaming( DCHECK_OR_RETURN_VOID(media_manager_); if (state) { - state_ctrl_.OnNaviStreamingStarted(); + state_ctrl_.OnVideoStreamingStarted(app); media_manager_->StartStreaming(app_id, service_type); } else { media_manager_->StopStreaming(app_id, service_type); - state_ctrl_.OnNaviStreamingStopped(); + state_ctrl_.OnVideoStreamingStarted(app); } } @@ -3592,7 +2733,7 @@ void ApplicationManagerImpl::EndNaviServices(uint32_t app_id) { navi_app_to_stop_.push_back(app_id); - TimerSPtr close_timer(utils::MakeShared<timer::Timer>( + TimerSPtr close_timer(std::make_shared<timer::Timer>( "CloseNaviAppTimer", new TimerTaskImpl<ApplicationManagerImpl>( this, &ApplicationManagerImpl::CloseNaviApp))); @@ -3608,6 +2749,40 @@ void ApplicationManagerImpl::OnHMILevelChanged( mobile_apis::HMILevel::eType from, mobile_apis::HMILevel::eType to) { LOG4CXX_AUTO_TRACE(logger_); + ProcessPostponedMessages(app_id); + ProcessApp(app_id, from, to); +} + +void ApplicationManagerImpl::ProcessPostponedMessages(const uint32_t app_id) { + LOG4CXX_AUTO_TRACE(logger_); + + ApplicationSharedPtr app = application(app_id); + if (!app) { + LOG4CXX_WARN(logger_, "The app with id: " << app_id << " does not exist"); + return; + } + MobileMessageQueue messages; + app->SwapMobileMessageQueue(messages); + auto push_allowed_messages = [this, &app]( + smart_objects::SmartObjectSPtr message) { + const std::string function_id = MessageHelper::StringifiedFunctionID( + static_cast<mobile_apis::FunctionID::eType>( + (*message)[strings::params][strings::function_id].asUInt())); + const RPCParams params; + const mobile_apis::Result::eType check_result = + CheckPolicyPermissions(app, function_id, params); + if (mobile_api::Result::SUCCESS == check_result) { + rpc_service_->ManageMobileCommand(message, commands::Command::SOURCE_SDL); + } else { + app->PushMobileMessage(message); + } + }; + std::for_each(messages.begin(), messages.end(), push_allowed_messages); +} + +void ApplicationManagerImpl::ProcessApp(const uint32_t app_id, + const mobile_apis::HMILevel::eType from, + const mobile_apis::HMILevel::eType to) { using namespace mobile_apis::HMILevel; using namespace helpers; @@ -3633,7 +2808,7 @@ void ApplicationManagerImpl::OnHMILevelChanged( if (from == HMI_FULL || from == HMI_LIMITED) { LOG4CXX_TRACE(logger_, "HMILevel from FULL or LIMITED"); navi_app_to_end_stream_.push_back(app_id); - TimerSPtr end_stream_timer(utils::MakeShared<timer::Timer>( + TimerSPtr end_stream_timer(std::make_shared<timer::Timer>( "AppShouldFinishStreaming", new TimerTaskImpl<ApplicationManagerImpl>( this, &ApplicationManagerImpl::EndNaviStreaming))); @@ -3651,11 +2826,11 @@ void ApplicationManagerImpl::OnHMILevelChanged( } void ApplicationManagerImpl::SendHMIStatusNotification( - const utils::SharedPtr<Application> app) { + const std::shared_ptr<Application> app) { LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(app); smart_objects::SmartObjectSPtr notification = - utils::MakeShared<smart_objects::SmartObject>(); + std::make_shared<smart_objects::SmartObject>(); smart_objects::SmartObject& message = *notification; message[strings::params][strings::function_id] = @@ -3673,10 +2848,14 @@ void ApplicationManagerImpl::SendHMIStatusNotification( message[strings::msg_params][strings::audio_streaming_state] = static_cast<int32_t>(app->audio_streaming_state()); + message[strings::msg_params][strings::video_streaming_state] = + static_cast<int32_t>(app->video_streaming_state()); + message[strings::msg_params][strings::system_context] = static_cast<int32_t>(app->system_context()); - ManageMobileCommand(notification, commands::Command::ORIGIN_SDL); + rpc_service_->ManageMobileCommand(notification, + commands::Command::SOURCE_SDL); } void ApplicationManagerImpl::ClearTimerPool() { @@ -3719,10 +2898,10 @@ void ApplicationManagerImpl::CloseNaviApp() { if (unregister) { LOG4CXX_INFO(logger_, "App haven't answered for EndService. Unregister it."); - ManageMobileCommand( + rpc_service_->ManageMobileCommand( MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( app_id, PROTOCOL_VIOLATION), - commands::Command::ORIGIN_SDL); + commands::Command::SOURCE_SDL); UnregisterApplication(app_id, ABORTED); } } @@ -3815,12 +2994,6 @@ policy::DeviceConsent ApplicationManagerImpl::GetUserConsentForDevice( return GetPolicyHandler().GetUserConsentForDevice(device_id); } -void ApplicationManagerImpl::OnWakeUp() { - LOG4CXX_AUTO_TRACE(logger_); - is_low_voltage_ = false; - request_ctrl_.OnWakeUp(); -} - mobile_apis::Result::eType ApplicationManagerImpl::SaveBinary( const std::vector<uint8_t>& binary_data, const std::string& file_path, @@ -3904,9 +3077,9 @@ bool ApplicationManagerImpl::IsHMICooperating() const { void ApplicationManagerImpl::OnApplicationListUpdateTimer() { LOG4CXX_DEBUG(logger_, "Application list update timer finished"); - apps_to_register_list_lock_.Acquire(); + apps_to_register_list_lock_ptr_->Acquire(); const bool trigger_ptu = apps_size_ != applications_.size(); - apps_to_register_list_lock_.Release(); + apps_to_register_list_lock_ptr_->Release(); SendUpdateAppList(); GetPolicyHandler().OnAppsSearchCompleted(trigger_ptu); } @@ -3995,6 +3168,8 @@ mobile_apis::AppHMIType::eType ApplicationManagerImpl::StringToAppHMIType( return mobile_apis::AppHMIType::MESSAGING; } else if ("NAVIGATION" == str) { return mobile_apis::AppHMIType::NAVIGATION; + } else if ("PROJECTION" == str) { + return mobile_apis::AppHMIType::PROJECTION; } else if ("INFORMATION" == str) { return mobile_apis::AppHMIType::INFORMATION; } else if ("SOCIAL" == str) { @@ -4010,6 +3185,39 @@ mobile_apis::AppHMIType::eType ApplicationManagerImpl::StringToAppHMIType( } } +const std::string ApplicationManagerImpl::AppHMITypeToString( + mobile_apis::AppHMIType::eType type) const { + LOG4CXX_AUTO_TRACE(logger_); + switch (type) { + case mobile_apis::AppHMIType::DEFAULT: + return "DEFAULT"; + case mobile_apis::AppHMIType::COMMUNICATION: + return "COMMUNICATION"; + case mobile_apis::AppHMIType::MEDIA: + return "MEDIA"; + case mobile_apis::AppHMIType::MESSAGING: + return "MESSAGING"; + case mobile_apis::AppHMIType::NAVIGATION: + return "NAVIGATION"; + case mobile_apis::AppHMIType::INFORMATION: + return "INFORMATION"; + case mobile_apis::AppHMIType::SOCIAL: + return "SOCIAL"; + case mobile_apis::AppHMIType::BACKGROUND_PROCESS: + return "BACKGROUND_PROCESS"; + case mobile_apis::AppHMIType::TESTING: + return "TESTING"; + case mobile_apis::AppHMIType::SYSTEM: + return "SYSTEM"; + case mobile_apis::AppHMIType::PROJECTION: + return "PROJECTION"; + case mobile_apis::AppHMIType::REMOTE_CONTROL: + return "REMOTE_CONTROL"; + default: + return "INVALID_ENUM"; + } +} + bool ApplicationManagerImpl::CompareAppHMIType( const smart_objects::SmartObject& from_policy, const smart_objects::SmartObject& from_application) { @@ -4136,13 +3344,50 @@ void ApplicationManagerImpl::ProcessReconnection( } void ApplicationManagerImpl::OnPTUFinished(const bool ptu_result) { -#ifdef SDL_REMOTE_CONTROL + LOG4CXX_AUTO_TRACE(logger_); if (!ptu_result) { return; } - plugin_manager_.OnPolicyEvent( - functional_modules::PolicyEvent::kApplicationPolicyUpdated); -#endif // SDL_REMOTE_CONTROL + auto on_app_policy_updated = [](plugin_manager::RPCPlugin& plugin) { + plugin.OnPolicyEvent(plugin_manager::kApplicationPolicyUpdated); + }; + + plugin_manager_->ForEachPlugin(on_app_policy_updated); +} + +void ApplicationManagerImpl::SendDriverDistractionState( + ApplicationSharedPtr application) { + LOG4CXX_AUTO_TRACE(logger_); + if (hmi_apis::Common_DriverDistractionState::INVALID_ENUM == + driver_distraction_state()) { + LOG4CXX_WARN(logger_, "DriverDistractionState is INVALID_ENUM"); + return; + } + smart_objects::SmartObjectSPtr on_driver_distraction = + std::make_shared<smart_objects::SmartObject>(); + + (*on_driver_distraction)[strings::params][strings::message_type] = + static_cast<int32_t>(application_manager::MessageType::kNotification); + (*on_driver_distraction)[strings::params][strings::function_id] = + mobile_api::FunctionID::OnDriverDistractionID; + (*on_driver_distraction)[strings::msg_params][mobile_notification::state] = + driver_distraction_state(); + (*on_driver_distraction)[strings::params][strings::connection_key] = + application->app_id(); + + const std::string function_id = MessageHelper::StringifiedFunctionID( + static_cast<mobile_apis::FunctionID::eType>( + (*on_driver_distraction)[strings::params][strings::function_id] + .asUInt())); + const RPCParams params; + const mobile_apis::Result::eType check_result = + CheckPolicyPermissions(application, function_id, params); + if (mobile_api::Result::SUCCESS == check_result) { + rpc_service_->ManageMobileCommand(on_driver_distraction, + commands::Command::SOURCE_SDL); + } else { + application->PushMobileMessage(on_driver_distraction); + } } protocol_handler::MajorProtocolVersion @@ -4212,37 +3457,13 @@ void ApplicationManagerImpl::ClearTTSGlobalPropertiesList() { } bool ApplicationManagerImpl::IsAppSubscribedForWayPoints( - const uint32_t app_id) const { - LOG4CXX_AUTO_TRACE(logger_); - sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); - if (subscribed_way_points_apps_list_.find(app_id) == - subscribed_way_points_apps_list_.end()) { - return false; - } - return true; -} - -void ApplicationManagerImpl::SubscribeAppForWayPoints(const uint32_t app_id) { - LOG4CXX_AUTO_TRACE(logger_); - sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); - subscribed_way_points_apps_list_.insert(app_id); -} - -void ApplicationManagerImpl::UnsubscribeAppFromWayPoints( - const uint32_t app_id) { - LOG4CXX_AUTO_TRACE(logger_); - sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); - 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) == + if (subscribed_way_points_apps_list_.find(app->app_id()) == subscribed_way_points_apps_list_.end()) { return false; } @@ -4253,7 +3474,7 @@ 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); + subscribed_way_points_apps_list_.insert(app->app_id()); LOG4CXX_DEBUG(logger_, "There are applications subscribed: " << subscribed_way_points_apps_list_.size()); @@ -4263,7 +3484,7 @@ 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); + subscribed_way_points_apps_list_.erase(app->app_id()); LOG4CXX_DEBUG(logger_, "There are applications subscribed: " << subscribed_way_points_apps_list_.size()); @@ -4285,6 +3506,16 @@ const std::set<int32_t> ApplicationManagerImpl::GetAppsSubscribedForWayPoints() return subscribed_way_points_apps_list_; } +// retrieve transport type string used in .ini file, e.g. "TCP_WIFI" +const std::string ApplicationManagerImpl::GetTransportTypeProfileString( + connection_handler::DeviceHandle device_handle) const { + LOG4CXX_AUTO_TRACE(logger_); + + return connection_handler() + .get_session_observer() + .TransportTypeProfileStringFromDeviceHandle(device_handle); +} + static hmi_apis::Common_VideoStreamingProtocol::eType ConvertVideoProtocol( const char* str) { if (strcmp(str, "RAW") == 0) { @@ -4369,15 +3600,36 @@ std::vector<std::string> ApplicationManagerImpl::ConvertRejectedParamList( return output; } +bool ApplicationManagerImpl::IsSOStructValid( + const hmi_apis::StructIdentifiers::eType struct_id, + const smart_objects::SmartObject& display_capabilities) { + smart_objects::SmartObject display_capabilities_so = display_capabilities; + if (hmi_so_factory().AttachSchema(struct_id, display_capabilities_so)) { + if (display_capabilities_so.isValid()) { + return true; + } else { + return false; + } + } else { + LOG4CXX_ERROR(logger_, "Could not find struct id: " << struct_id); + return false; + } + return true; +} + #ifdef BUILD_TESTS void ApplicationManagerImpl::AddMockApplication(ApplicationSharedPtr mock_app) { - applications_list_lock_.Acquire(); + applications_list_lock_ptr_->Acquire(); applications_.insert(mock_app); apps_size_ = applications_.size(); - applications_list_lock_.Release(); + applications_list_lock_ptr_->Release(); +} + +void ApplicationManagerImpl::SetMockMediaManager( + media_manager::MediaManager* mock_media_manager) { + media_manager_ = mock_media_manager; } #endif // BUILD_TESTS -#ifdef SDL_REMOTE_CONTROL struct MobileAppIdPredicate { std::string policy_app_id_; MobileAppIdPredicate(const std::string& policy_app_id) @@ -4431,7 +3683,6 @@ std::vector<std::string> ApplicationManagerImpl::devices( void ApplicationManagerImpl::ChangeAppsHMILevel( uint32_t app_id, mobile_apis::HMILevel::eType level) { - using namespace mobile_apis::HMILevel; LOG4CXX_AUTO_TRACE(logger_); LOG4CXX_DEBUG(logger_, "AppID to change: " << app_id << " -> " << level); ApplicationSharedPtr app = application(app_id); @@ -4439,26 +3690,13 @@ void ApplicationManagerImpl::ChangeAppsHMILevel( LOG4CXX_ERROR(logger_, "There is no app with id: " << app_id); return; } - eType old_level = app->hmi_level(); + const mobile_apis::HMILevel::eType old_level = app->hmi_level(); if (old_level != level) { app->set_hmi_level(level); OnHMILevelChanged(app_id, old_level, level); - - plugin_manager_.OnAppHMILevelChanged(app, old_level); } else { - LOG4CXX_WARN(logger_, "Redudant changing HMI level : " << level); + LOG4CXX_WARN(logger_, "Redundant changing HMI level: " << level); } } -void ApplicationManagerImpl::SendPostMessageToMobile( - const MessagePtr& message) { - messages_to_mobile_.PostMessage(impl::MessageToMobile(message, false)); -} - -void ApplicationManagerImpl::SendPostMessageToHMI(const MessagePtr& message) { - messages_to_hmi_.PostMessage(impl::MessageToHmi(message)); -} - -#endif // SDL_REMOTE_CONTROL - } // namespace application_manager |