diff options
Diffstat (limited to 'src/components/application_manager/src')
4 files changed, 84 insertions, 35 deletions
diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index 8af4c97543..fcdbc25a3e 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -79,12 +79,14 @@ namespace application_manager { void SwitchApplicationParameters(ApplicationSharedPtr app, const uint32_t app_id, - const uint32_t device_id) { + const size_t device_id, + const std::string& mac_address) { utils::SharedPtr<ApplicationImpl> application = ApplicationSharedPtr::dynamic_pointer_cast<ApplicationImpl>(app); DCHECK_OR_RETURN_VOID(application); application->app_id_ = app_id; application->device_id_ = device_id; + application->mac_address_ = mac_address; } ApplicationImpl::ApplicationImpl( diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index f9fa396d80..b4cb692740 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -1073,18 +1073,25 @@ void ApplicationManagerImpl::RemoveDevice( } void ApplicationManagerImpl::OnDeviceSwitchingStart( - const std::string& device_uid) { + const connection_handler::Device& device_from, + const connection_handler::Device& device_to) { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(reregister_wait_list_lock_); { auto apps_data_accessor = applications(); - std::copy_if(apps_data_accessor.GetData().begin(), + std::copy_if( + apps_data_accessor.GetData().begin(), apps_data_accessor.GetData().end(), std::back_inserter(reregister_wait_list_), - std::bind1st(std::ptr_fun(&device_id_comparator), device_uid)); + std::bind1st(std::ptr_fun(&device_id_comparator), + device_from.mac_address())); } + { + // During sending of UpdateDeviceList this lock is acquired also so making + // it scoped + sync_primitives::AutoLock lock(reregister_wait_list_lock_); for (auto i = reregister_wait_list_.begin(); reregister_wait_list_.end() != i; ++i) { auto app = *i; @@ -1093,6 +1100,28 @@ void ApplicationManagerImpl::OnDeviceSwitchingStart( } } + policy_handler_->OnDeviceSwitching(device_from.mac_address(), + device_to.mac_address()); + + connection_handler::DeviceMap device_list; + device_list.insert(std::make_pair(device_to.device_handle(), device_to)); + + smart_objects::SmartObjectSPtr msg_params = + MessageHelper::CreateDeviceListSO(device_list, GetPolicyHandler(), *this); + + auto update_list = utils::MakeShared<smart_objects::SmartObject>(); + smart_objects::SmartObject& so_to_send = *update_list; + so_to_send[jhs::S_PARAMS][jhs::S_FUNCTION_ID] = + hmi_apis::FunctionID::BasicCommunication_UpdateDeviceList; + so_to_send[jhs::S_PARAMS][jhs::S_MESSAGE_TYPE] = + hmi_apis::messageType::request; + so_to_send[jhs::S_PARAMS][jhs::S_PROTOCOL_VERSION] = 3; + so_to_send[jhs::S_PARAMS][jhs::S_PROTOCOL_TYPE] = 1; + so_to_send[jhs::S_PARAMS][jhs::S_CORRELATION_ID] = GetNextHMICorrelationID(); + so_to_send[jhs::S_MSG_PARAMS] = *msg_params; + ManageHMICommand(update_list); +} + void ApplicationManagerImpl::OnDeviceSwitchingFinish( const std::string& device_uid) { LOG4CXX_AUTO_TRACE(logger_); @@ -1115,8 +1144,9 @@ void ApplicationManagerImpl::OnDeviceSwitchingFinish( void ApplicationManagerImpl::SwitchApplication(ApplicationSharedPtr app, const uint32_t connection_key, - const uint32_t device_id) { - LOG4CXX_AUTO_TRACE(logger_); + const size_t device_id, + const std::string& mac_address) { + LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(applications_list_lock_); DCHECK_OR_RETURN_VOID(1 == applications_.erase(app)); @@ -1125,7 +1155,7 @@ void ApplicationManagerImpl::SwitchApplication(ApplicationSharedPtr app, << ". Changing device id to " << device_id); - SwitchApplicationParameters(app, connection_key, device_id); + SwitchApplicationParameters(app, connection_key, device_id, mac_address); // Normally this is done during registration, however since switched apps are // not being registered again need to set protocol version on session. @@ -4056,11 +4086,9 @@ void ApplicationManagerImpl::ProcessReconnection( connection_handler().get_session_observer().GetDataOnDeviceID( new_device_id, NULL, NULL, &device_mac, &connection_type); - DCHECK_OR_RETURN_VOID(application->mac_address() == device_mac); - EraseAppFromReconnectionList(application); - SwitchApplication(application, connection_key, new_device_id); + SwitchApplication(application, connection_key, new_device_id, device_mac); // Update connection type for existed device. GetPolicyHandler().AddDevice(device_mac, connection_type); diff --git a/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc b/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc index 4dd14e2075..fda4d09de2 100644 --- a/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc +++ b/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc @@ -370,7 +370,7 @@ void RegisterAppInterfaceRequest::Run() { GetPolicyHandler().SetDeviceInfo(device_mac, device_info); - SendRegisterAppInterfaceResponseToMobile(AppicationType::kNewApplication); + SendRegisterAppInterfaceResponseToMobile(ApplicationType::kNewApplication); smart_objects::SmartObjectSPtr so = GetLockScreenIconUrlNotification(connection_key(), application); application_manager_.ManageMobileCommand(so, commands::Command::ORIGIN_SDL); @@ -510,7 +510,7 @@ void FillUIRelatedFields(smart_objects::SmartObject& response_params, } void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( - AppicationType app_type) { + ApplicationType app_type) { LOG4CXX_AUTO_TRACE(logger_); smart_objects::SmartObject response_params(smart_objects::SmartType_Map); @@ -640,6 +640,28 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( response_params[strings::system_software_version] = ccpu_version; } + if (ApplicationType::kSwitchedApplicationWrongHashId == app_type) { + LOG4CXX_DEBUG(logger_, + "Application has been switched from another transport, " + "but doesn't have correct hashID."); + + application_manager::RecallApplicationData(application, + application_manager_); + + SendResponse(true, mobile_apis::Result::RESUME_FAILED, NULL, + &response_params); + return; + } + + if (ApplicationType::kSwitchedApplicationHashOk == app_type) { + LOG4CXX_DEBUG(logger_, + "Application has been switched from another transport " + "and has correct hashID."); + SendResponse(true, mobile_apis::Result::SUCCESS, NULL, + &response_params); + return; + } + bool resumption = (*message_)[strings::msg_params].keyExists(strings::hash_id); @@ -670,27 +692,6 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( result_code = result_checking_app_hmi_type_; } - if (AppicationType::kSwitchedApplication == app_type) { - LOG4CXX_DEBUG(logger_, - "Application has been switched from another transport."); - - if (hash_id.empty() && resumer.CheckApplicationHash(application, hash_id)) { - LOG4CXX_INFO(logger_, - "Application does not have hashID saved and neither " - "provided it with RAI. Nothing to resume."); - result_code = mobile_apis::Result::SUCCESS; - } else if (!resumption || - mobile_apis::Result::RESUME_FAILED == result_code) { - application_manager::RecallApplicationData(application, - application_manager_); - resumer.RemoveApplicationFromSaved(application); - result_code = mobile_apis::Result::RESUME_FAILED; - } - - SendResponse(true, result_code, add_info.c_str(), &response_params); - return; - } - // in case application exist in resumption we need to send resumeVrgrammars if (false == resumption) { resumption = resumer.IsApplicationSaved(application->policy_app_id(), @@ -1465,9 +1466,20 @@ bool RegisterAppInterfaceRequest::IsApplicationSwitched() { } LOG4CXX_DEBUG(logger_, "Application is found in reconnection list."); + + auto app_type = ApplicationType::kSwitchedApplicationWrongHashId; + if ((*message_)[strings::msg_params].keyExists(strings::hash_id)) { + const auto hash_id = + (*message_)[strings::msg_params][strings::hash_id].asString(); + + auto& resume_ctrl = application_manager_.resume_controller(); + if (resume_ctrl.CheckApplicationHash(app, hash_id)) { + app_type = ApplicationType::kSwitchedApplicationHashOk; + } + } + application_manager_.ProcessReconnection(app, connection_key()); - SendRegisterAppInterfaceResponseToMobile( - AppicationType::kSwitchedApplication); + SendRegisterAppInterfaceResponseToMobile(app_type); application_manager_.SendHMIStatusNotification(app); diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 570aee180c..e5bf7a2a7c 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -852,6 +852,13 @@ uint32_t PolicyHandler::ChooseRandomAppForPolicyUpdate( return 0; } +void PolicyHandler::OnDeviceSwitching(const std::string& device_id_from, + const std::string& device_id_to) { + LOG4CXX_AUTO_TRACE(logger_); + POLICY_LIB_CHECK_VOID(); + policy_manager_->OnDeviceSwitching(device_id_from, device_id_to); +} + void PolicyHandler::OnGetStatusUpdate(const uint32_t correlation_id) { LOG4CXX_AUTO_TRACE(logger_); POLICY_LIB_CHECK_VOID(); |