diff options
Diffstat (limited to 'src/components/application_manager/src/state_controller_impl.cc')
-rw-r--r-- | src/components/application_manager/src/state_controller_impl.cc | 89 |
1 files changed, 76 insertions, 13 deletions
diff --git a/src/components/application_manager/src/state_controller_impl.cc b/src/components/application_manager/src/state_controller_impl.cc index ec77e30db7..e7ec998a2f 100644 --- a/src/components/application_manager/src/state_controller_impl.cc +++ b/src/components/application_manager/src/state_controller_impl.cc @@ -394,7 +394,7 @@ void StateControllerImpl::HmiLevelConflictResolver::operator()( result_video_state = mobile_apis::VideoStreamingState::STREAMABLE; } - mobile_apis::HMILevel::eType result_hmi_level = state_to_resolve->hmi_level(); + mobile_apis::HMILevel::eType result_hmi_level; using namespace helpers; if (mobile_apis::VideoStreamingState::STREAMABLE == result_video_state || @@ -714,7 +714,52 @@ void StateControllerImpl::UpdateAppWindowsStreamingState( } } -void StateControllerImpl::on_event(const event_engine::MobileEvent& event) {} +void StateControllerImpl::on_event(const event_engine::MobileEvent& event) { + using namespace mobile_apis; + + SDL_LOG_AUTO_TRACE(); + SDL_LOG_DEBUG("Received event for function" << event.id()); + switch (event.id()) { + case FunctionID::RegisterAppInterfaceID: { + auto message = event.smart_object(); + uint32_t connection_key = + message[strings::params][strings::connection_key].asUInt(); + ApplicationSharedPtr app = app_mngr_.application(connection_key); + + if (app.use_count() == 0) { + SDL_LOG_WARN("Application doesn't exist"); + return; + } + { + sync_primitives::AutoLock autolock( + apps_with_pending_hmistatus_notification_lock_); + + auto it = apps_with_pending_hmistatus_notification_.find(app->app_id()); + if (it == apps_with_pending_hmistatus_notification_.end()) { + SDL_LOG_WARN("Application does not have a pending OnHMIStatus"); + return; + } + + bool success = message[strings::msg_params][strings::success].asBool(); + if (success) { + // Only send notification if RAI was a success + auto notification = + MessageHelper::CreateHMIStatusNotification(app, 0); + app_mngr_.GetRPCService().ManageMobileCommand( + notification, commands::Command::SOURCE_SDL); + } + + apps_with_pending_hmistatus_notification_.erase(app->app_id()); + if (apps_with_pending_hmistatus_notification_.empty()) { + unsubscribe_from_event(FunctionID::RegisterAppInterfaceID); + } + } + } break; + + default: + break; + } +} void StateControllerImpl::on_event(const event_engine::Event& event) { using event_engine::Event; @@ -758,11 +803,11 @@ void StateControllerImpl::on_event(const event_engine::Event& event) { case FunctionID::BasicCommunication_OnEventChanged: { bool is_active = message[strings::msg_params][hmi_notification::is_active].asBool(); - const uint32_t id = + const uint32_t event_id = message[strings::msg_params][hmi_notification::event_name].asUInt(); // TODO(AOleynik): Add verification/conversion check here const Common_EventTypes::eType state_id = - static_cast<Common_EventTypes::eType>(id); + static_cast<Common_EventTypes::eType>(event_id); if (is_active) { if (Common_EventTypes::AUDIO_SOURCE == state_id) { ApplyTempState<HmiState::STATE_ID_AUDIO_SOURCE>(); @@ -830,8 +875,8 @@ void StateControllerImpl::ActivateDefaultWindow(ApplicationSharedPtr app) { SetRegularState(app, window_id, hmi_level, audio_state, video_state, false); - // After main window activation, streaming state should be updated for another - // windows of the app + // After main window activation, streaming state should be updated for + // another windows of the app HmiStatePtr new_state = app->RegularHmiState(PredefinedWindows::DEFAULT_WINDOW); UpdateAppWindowsStreamingState(app, new_state); @@ -873,11 +918,24 @@ void StateControllerImpl::OnStateChanged(ApplicationSharedPtr app, return; } - auto notification = - MessageHelper::CreateHMIStatusNotification(app, window_id); - app_mngr_.GetRPCService().ManageMobileCommand(notification, - commands::Command::SOURCE_SDL); - + if (app->is_ready()) { + SDL_LOG_DEBUG("Sending OnHMIStatus to application " << app->app_id()); + auto notification = + MessageHelper::CreateHMIStatusNotification(app, window_id); + app_mngr_.GetRPCService().ManageMobileCommand( + notification, commands::Command::SOURCE_SDL); + } else { + SDL_LOG_DEBUG( + "Application " + << app->app_id() + << " not ready to receive OnHMIStatus. Delaying notification"); + { + sync_primitives::AutoLock autolock( + apps_with_pending_hmistatus_notification_lock_); + apps_with_pending_hmistatus_notification_.insert(app->app_id()); + } + subscribe_on_event(mobile_apis::FunctionID::RegisterAppInterfaceID); + } if (mobile_apis::PredefinedWindows::DEFAULT_WINDOW != window_id) { SDL_LOG_DEBUG( "State was changed not for a main application window. No " @@ -943,6 +1001,11 @@ void StateControllerImpl::OnApplicationRegistered( const mobile_apis::HMILevel::eType default_level) { SDL_LOG_AUTO_TRACE(); + if (app->is_cloud_app()) { + // Return here, there should already be an onHMIStatus=FULL being processed + // for when the cloud app was initially activated by the hmi + return; + } // After app registration HMI level should be set for DEFAULT_WINDOW only OnAppWindowAdded(app, mobile_apis::PredefinedWindows::DEFAULT_WINDOW, @@ -1220,8 +1283,8 @@ void StateControllerImpl::OnAppDeactivated( return; } - // TODO(AOleynik): Need to delete DeactivateReason and modify OnAppDeactivated - // when HMI will support that, otherwise won't be testable + // TODO(AOleynik): Need to delete DeactivateReason and modify + // OnAppDeactivated when HMI will support that, otherwise won't be testable DeactivateApp(app, window_id); } |