diff options
author | Andrey Oleynik (GitHub) <aoleynik@luxoft.com> | 2017-09-19 16:51:35 +0300 |
---|---|---|
committer | Andriy Byzhynar <AByzhynar@luxoft.com> | 2018-01-18 11:26:30 +0200 |
commit | a6791129fb1cfcd5dad96e4987b1c2664aafb61e (patch) | |
tree | 82d991edadfd29485946fd07c0f31174c97b0e17 /src/components/application_manager/src/commands | |
parent | e8911d03dde016a29b01fe80533bc6ac56531678 (diff) | |
download | sdl_core-a6791129fb1cfcd5dad96e4987b1c2664aafb61e.tar.gz |
Adds main logic and related bugfixes for transport switching
Diffstat (limited to 'src/components/application_manager/src/commands')
6 files changed, 89 insertions, 31 deletions
diff --git a/src/components/application_manager/src/commands/command_impl.cc b/src/components/application_manager/src/commands/command_impl.cc index 0a3e65a790..d17f6cdc10 100644 --- a/src/components/application_manager/src/commands/command_impl.cc +++ b/src/components/application_manager/src/commands/command_impl.cc @@ -94,18 +94,20 @@ void CommandImpl::SetAllowedToTerminate(const bool allowed) { allowed_to_terminate_ = allowed; } -void CommandImpl::ReplaceMobileByHMIAppId( +bool CommandImpl::ReplaceMobileByHMIAppId( NsSmartDeviceLink::NsSmartObjects::SmartObject& message) { if (message.keyExists(strings::app_id)) { ApplicationSharedPtr application = application_manager_.application(message[strings::app_id].asUInt()); - if (application.valid()) { - LOG4CXX_DEBUG(logger_, - "ReplaceMobileByHMIAppId from " - << message[strings::app_id].asInt() << " to " - << application->hmi_app_id()); - message[strings::app_id] = application->hmi_app_id(); + if (!application) { + LOG4CXX_ERROR(logger_, "Substitution mobile --> HMI id is failed."); + return false; } + LOG4CXX_DEBUG(logger_, + "ReplaceMobileByHMIAppId from " + << message[strings::app_id].asInt() << " to " + << application->hmi_app_id()); + message[strings::app_id] = application->hmi_app_id(); } else { switch (message.getType()) { case smart_objects::SmartType::SmartType_Array: { @@ -128,22 +130,26 @@ void CommandImpl::ReplaceMobileByHMIAppId( default: { break; } } } + + return true; } -void CommandImpl::ReplaceHMIByMobileAppId( +bool CommandImpl::ReplaceHMIByMobileAppId( NsSmartDeviceLink::NsSmartObjects::SmartObject& message) { if (message.keyExists(strings::app_id)) { ApplicationSharedPtr application = application_manager_.application_by_hmi_app( message[strings::app_id].asUInt()); - if (application.valid()) { - LOG4CXX_DEBUG(logger_, - "ReplaceHMIByMobileAppId from " - << message[strings::app_id].asInt() << " to " - << application->app_id()); - message[strings::app_id] = application->app_id(); + if (!application) { + LOG4CXX_ERROR(logger_, "Substitution HMI --> mobile id is failed."); + return false; } + LOG4CXX_DEBUG(logger_, + "ReplaceHMIByMobileAppId from " + << message[strings::app_id].asInt() << " to " + << application->app_id()); + message[strings::app_id] = application->app_id(); } else { switch (message.getType()) { case smart_objects::SmartType::SmartType_Array: { @@ -165,6 +171,8 @@ void CommandImpl::ReplaceHMIByMobileAppId( default: { break; } } } + + return true; } } // namespace commands diff --git a/src/components/application_manager/src/commands/hmi/notification_to_hmi.cc b/src/components/application_manager/src/commands/hmi/notification_to_hmi.cc index f1e933b7ef..7e24dce8d9 100644 --- a/src/components/application_manager/src/commands/hmi/notification_to_hmi.cc +++ b/src/components/application_manager/src/commands/hmi/notification_to_hmi.cc @@ -39,15 +39,12 @@ namespace commands { NotificationToHMI::NotificationToHMI(const MessageSharedPtr& message, ApplicationManager& application_manager) - : CommandImpl(message, application_manager) { - // Replace Mobile connection id with HMI app id - ReplaceMobileByHMIAppId(*(message.get())); -} + : CommandImpl(message, application_manager) {} NotificationToHMI::~NotificationToHMI() {} bool NotificationToHMI::Init() { - return true; + return ReplaceMobileByHMIAppId(*message_); } bool NotificationToHMI::CleanUp() { diff --git a/src/components/application_manager/src/commands/hmi/on_app_unregistered_notification.cc b/src/components/application_manager/src/commands/hmi/on_app_unregistered_notification.cc index 10ea1ea303..f64e3e111b 100644 --- a/src/components/application_manager/src/commands/hmi/on_app_unregistered_notification.cc +++ b/src/components/application_manager/src/commands/hmi/on_app_unregistered_notification.cc @@ -44,6 +44,12 @@ OnAppUnregisteredNotification::OnAppUnregisteredNotification( OnAppUnregisteredNotification::~OnAppUnregisteredNotification() {} +bool OnAppUnregisteredNotification::Init() { + LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, "Replacement of hmi id is skipped."); + return true; +} + void OnAppUnregisteredNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); diff --git a/src/components/application_manager/src/commands/hmi/request_to_hmi.cc b/src/components/application_manager/src/commands/hmi/request_to_hmi.cc index 39d549ac72..f26dc26ef6 100644 --- a/src/components/application_manager/src/commands/hmi/request_to_hmi.cc +++ b/src/components/application_manager/src/commands/hmi/request_to_hmi.cc @@ -61,15 +61,12 @@ bool ChangeInterfaceState(ApplicationManager& application_manager, RequestToHMI::RequestToHMI(const MessageSharedPtr& message, ApplicationManager& application_manager) - : CommandImpl(message, application_manager) { - // Replace Mobile connection id with HMI app id - ReplaceMobileByHMIAppId(*(message.get())); -} + : CommandImpl(message, application_manager) {} RequestToHMI::~RequestToHMI() {} bool RequestToHMI::Init() { - return true; + return ReplaceMobileByHMIAppId(*message_); } bool RequestToHMI::CleanUp() { diff --git a/src/components/application_manager/src/commands/hmi/response_to_hmi.cc b/src/components/application_manager/src/commands/hmi/response_to_hmi.cc index e6f64047ba..77e523378a 100644 --- a/src/components/application_manager/src/commands/hmi/response_to_hmi.cc +++ b/src/components/application_manager/src/commands/hmi/response_to_hmi.cc @@ -39,15 +39,12 @@ namespace commands { ResponseToHMI::ResponseToHMI(const MessageSharedPtr& message, ApplicationManager& application_manager) - : CommandImpl(message, application_manager) { - // Replace Mobile connection id with HMI app id - ReplaceMobileByHMIAppId(*(message.get())); -} + : CommandImpl(message, application_manager) {} ResponseToHMI::~ResponseToHMI() {} bool ResponseToHMI::Init() { - return true; + return ReplaceMobileByHMIAppId(*message_); } bool ResponseToHMI::CleanUp() { diff --git a/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc b/src/components/application_manager/src/commands/mobile/register_app_interface_request.cc index 1a60537874..1939150541 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 @@ -217,6 +217,13 @@ void RegisterAppInterfaceRequest::Run() { return; } + if (IsApplicationSwitched()) { + return; + } + + const std::string mobile_app_id = + (*message_)[strings::msg_params][strings::app_id].asString(); + ApplicationSharedPtr application = application_manager_.application(connection_key()); @@ -362,7 +369,7 @@ void RegisterAppInterfaceRequest::Run() { GetPolicyHandler().SetDeviceInfo(device_mac, device_info); - SendRegisterAppInterfaceResponseToMobile(); + SendRegisterAppInterfaceResponseToMobile(AppicationType::kNewApplication); smart_objects::SmartObjectSPtr so = GetLockScreenIconUrlNotification(connection_key(), application); application_manager_.ManageMobileCommand(so, commands::Command::ORIGIN_SDL); @@ -501,7 +508,8 @@ void FillUIRelatedFields(smart_objects::SmartObject& response_params, hmi_capabilities.rc_supported(); } -void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile() { +void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile( + AppicationType app_type) { LOG4CXX_AUTO_TRACE(logger_); smart_objects::SmartObject response_params(smart_objects::SmartType_Map); @@ -631,6 +639,14 @@ void RegisterAppInterfaceRequest::SendRegisterAppInterfaceResponseToMobile() { response_params[strings::system_software_version] = ccpu_version; } + if (AppicationType::kSwitchedApplication == app_type) { + LOG4CXX_DEBUG(logger_, + "Application has been switched from another transport."); + + SendResponse(true, result_code, NULL, &response_params); + return; + } + bool resumption = (*message_)[strings::msg_params].keyExists(strings::hash_id); @@ -1194,6 +1210,43 @@ void RegisterAppInterfaceRequest::SendSubscribeCustomButtonNotification() { CreateHMINotification(FunctionID::Buttons_OnButtonSubscription, msg_params); } +bool RegisterAppInterfaceRequest::IsApplicationSwitched() { + const smart_objects::SmartObject& msg_params = + (*message_)[strings::msg_params]; + + const std::string& policy_app_id = msg_params[strings::app_id].asString(); + + LOG4CXX_DEBUG(logger_, "Looking for application id " << policy_app_id); + + auto app = application_manager_.application_by_policy_id(policy_app_id); + + if (!app) { + LOG4CXX_DEBUG(logger_, + "Application with policy id " << policy_app_id + << " is not found."); + return false; + } + + LOG4CXX_DEBUG(logger_, + "Application with policy id " << policy_app_id << " is found."); + if (!application_manager_.IsAppInReconnectMode(policy_app_id)) { + LOG4CXX_DEBUG(logger_, + "Policy id " << policy_app_id + << " is not found in reconnection list."); + SendResponse(false, mobile_apis::Result::APPLICATION_REGISTERED_ALREADY); + return false; + } + + LOG4CXX_DEBUG(logger_, "Application is found in reconnection list."); + application_manager_.ProcessReconnection(app, connection_key()); + SendRegisterAppInterfaceResponseToMobile( + AppicationType::kSwitchedApplication); + + application_manager_.SendHMIStatusNotification(app); + + return true; +} + policy::PolicyHandlerInterface& RegisterAppInterfaceRequest::GetPolicyHandler() { return application_manager_.GetPolicyHandler(); |