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 | 352 |
1 files changed, 281 insertions, 71 deletions
diff --git a/src/components/application_manager/src/state_controller_impl.cc b/src/components/application_manager/src/state_controller_impl.cc index 994c7b8b7f..8368597370 100644 --- a/src/components/application_manager/src/state_controller_impl.cc +++ b/src/components/application_manager/src/state_controller_impl.cc @@ -67,6 +67,7 @@ StateControllerImpl::StateControllerImpl(ApplicationManager& app_mngr) } void StateControllerImpl::SetRegularState(ApplicationSharedPtr app, + const WindowID window_id, HmiStatePtr state, const bool request_hmi_state_change) { LOG4CXX_AUTO_TRACE(logger_); @@ -74,7 +75,8 @@ void StateControllerImpl::SetRegularState(ApplicationSharedPtr app, DCHECK_OR_RETURN_VOID(state); DCHECK_OR_RETURN_VOID(HmiState::STATE_ID_REGULAR == state->state_id()); - LOG4CXX_DEBUG(logger_, "Set regular state " << *state); + LOG4CXX_DEBUG(logger_, + "Set window #" << window_id << " regular state " << *state); if (state->hmi_level() == mobile_apis::HMILevel::INVALID_ENUM || state->audio_streaming_state() == @@ -93,9 +95,10 @@ void StateControllerImpl::SetRegularState(ApplicationSharedPtr app, HmiStatePtr resolved_state = ResolveHmiState(app, state); if (!resolved_state) { state->set_state_id(HmiState::STATE_ID_POSTPONED); - app->SetPostponedState(state); + app->SetPostponedState(window_id, state); return; } + LOG4CXX_DEBUG(logger_, "Resolved state: " << *resolved_state); const hmi_apis::Common_HMILevel::eType hmi_level = static_cast<hmi_apis::Common_HMILevel::eType>( @@ -117,18 +120,19 @@ void StateControllerImpl::SetRegularState(ApplicationSharedPtr app, LOG4CXX_ERROR(logger_, "Unable to send BC.ActivateApp"); return; } - ApplyRegularState(app, resolved_state); + ApplyRegularState(app, window_id, resolved_state); } void StateControllerImpl::SetRegularState( ApplicationSharedPtr app, + const WindowID window_id, const mobile_apis::HMILevel::eType hmi_level, const mobile_apis::AudioStreamingState::eType audio_state, const mobile_apis::VideoStreamingState::eType video_state, const bool request_hmi_state_change) { LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(app); - HmiStatePtr prev_regular = app->RegularHmiState(); + HmiStatePtr prev_regular = app->RegularHmiState(window_id); DCHECK_OR_RETURN_VOID(prev_regular); HmiStatePtr hmi_state = CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); @@ -137,16 +141,22 @@ void StateControllerImpl::SetRegularState( hmi_state->set_audio_streaming_state(audio_state); hmi_state->set_video_streaming_state(video_state); hmi_state->set_system_context(prev_regular->system_context()); - SetRegularState(app, hmi_state, request_hmi_state_change); + hmi_state->set_window_type(prev_regular->window_type()); + SetRegularState(app, window_id, hmi_state, request_hmi_state_change); } void StateControllerImpl::SetRegularState( ApplicationSharedPtr app, + const WindowID window_id, const mobile_apis::HMILevel::eType hmi_level, const bool request_hmi_state_change) { using namespace mobile_apis; LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(app); + + HmiStatePtr prev_regular = app->RegularHmiState(window_id); + DCHECK_OR_RETURN_VOID(prev_regular); + const HmiStatePtr hmi_state = CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); @@ -155,11 +165,13 @@ void StateControllerImpl::SetRegularState( hmi_state->set_audio_streaming_state(CalcAudioState(app, hmi_level)); hmi_state->set_video_streaming_state(CalcVideoState(app, hmi_level)); hmi_state->set_system_context(SystemContext::SYSCTXT_MAIN); - SetRegularState(app, hmi_state, request_hmi_state_change); + hmi_state->set_window_type(prev_regular->window_type()); + SetRegularState(app, window_id, hmi_state, request_hmi_state_change); } void StateControllerImpl::SetRegularState( ApplicationSharedPtr app, + const WindowID window_id, const mobile_apis::HMILevel::eType hmi_level, const mobile_apis::AudioStreamingState::eType audio_state, const mobile_apis::VideoStreamingState::eType video_state, @@ -167,21 +179,29 @@ void StateControllerImpl::SetRegularState( const bool request_hmi_state_change) { LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(app); + + HmiStatePtr prev_regular = app->RegularHmiState(window_id); + DCHECK_OR_RETURN_VOID(prev_regular); + HmiStatePtr hmi_state = CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN_VOID(hmi_state); + hmi_state->set_hmi_level(hmi_level); hmi_state->set_audio_streaming_state(audio_state); hmi_state->set_video_streaming_state(video_state); hmi_state->set_system_context(system_context); - SetRegularState(app, hmi_state, request_hmi_state_change); + hmi_state->set_window_type(prev_regular->window_type()); + SetRegularState(app, window_id, hmi_state, request_hmi_state_change); } void StateControllerImpl::SetRegularState( - ApplicationSharedPtr app, const mobile_apis::HMILevel::eType hmi_level) { + ApplicationSharedPtr app, + const WindowID window_id, + const mobile_apis::HMILevel::eType hmi_level) { LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(app); - HmiStatePtr prev_state = app->RegularHmiState(); + HmiStatePtr prev_state = app->RegularHmiState(window_id); HmiStatePtr hmi_state = CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN_VOID(hmi_state); @@ -191,15 +211,16 @@ void StateControllerImpl::SetRegularState( hmi_state->set_system_context(prev_state ? prev_state->system_context() : mobile_apis::SystemContext::SYSCTXT_MAIN); - SetRegularState(app, hmi_state); + SetRegularState(app, window_id, hmi_state); } void StateControllerImpl::SetRegularState( ApplicationSharedPtr app, + const WindowID window_id, const mobile_apis::SystemContext::eType system_context) { LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(app); - HmiStatePtr prev_regular = app->RegularHmiState(); + HmiStatePtr prev_regular = app->RegularHmiState(window_id); DCHECK_OR_RETURN_VOID(prev_regular); HmiStatePtr hmi_state = CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); @@ -210,16 +231,18 @@ void StateControllerImpl::SetRegularState( hmi_state->set_video_streaming_state( CalcVideoState(app, prev_regular->hmi_level())); hmi_state->set_system_context(system_context); - SetRegularState(app, hmi_state, false); + hmi_state->set_window_type(prev_regular->window_type()); + SetRegularState(app, window_id, hmi_state, false); } void StateControllerImpl::SetRegularState( ApplicationSharedPtr app, + const WindowID window_id, const mobile_apis::AudioStreamingState::eType audio_state, const mobile_apis::VideoStreamingState::eType video_state) { LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(app); - HmiStatePtr prev_state = app->RegularHmiState(); + HmiStatePtr prev_state = app->RegularHmiState(window_id); DCHECK_OR_RETURN_VOID(prev_state); HmiStatePtr hmi_state = CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); @@ -228,18 +251,23 @@ void StateControllerImpl::SetRegularState( hmi_state->set_audio_streaming_state(audio_state); hmi_state->set_video_streaming_state(video_state); hmi_state->set_system_context(prev_state->system_context()); - SetRegularState(app, hmi_state, false); + hmi_state->set_window_type(prev_state->window_type()); + SetRegularState(app, window_id, hmi_state, false); } void StateControllerImpl::SetRegularState(ApplicationSharedPtr app, + const WindowID window_id, HmiStatePtr state) { LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(app); DCHECK_OR_RETURN_VOID(state); - if (mobile_apis::HMILevel::HMI_FULL == state->hmi_level()) { - SetRegularState(app, state, true); + + // SDL should send BC.ActivateApp for main window during resumption + if (mobile_apis::PredefinedWindows::DEFAULT_WINDOW == window_id && + mobile_apis::HMILevel::HMI_FULL == state->hmi_level()) { + SetRegularState(app, window_id, state, true); } else { - SetRegularState(app, state, false); + SetRegularState(app, window_id, state, false); } } @@ -300,7 +328,8 @@ void StateControllerImpl::HmiLevelConflictResolver::operator()( return; } - const HmiStatePtr state_to_resolve = app_to_resolve->RegularHmiState(); + const HmiStatePtr state_to_resolve = + app_to_resolve->RegularHmiState(window_id_); DCHECK_OR_RETURN_VOID(state_to_resolve); // If applied HMI state is FULL: @@ -384,22 +413,23 @@ void StateControllerImpl::HmiLevelConflictResolver::operator()( std::make_tuple( result_hmi_level, result_audio_state, result_video_state)) { LOG4CXX_DEBUG(logger_, - "Application " - << app_to_resolve->app_id() << " will change state to: " - << "HMI level " << to_resolve_hmi_level << " --> " - << result_hmi_level << ", audio " - << state_to_resolve->audio_streaming_state() << " --> " - << result_audio_state << ", video " - << state_to_resolve->video_streaming_state() << " --> " - << result_video_state); + "Application " << app_to_resolve->app_id() << " window " + << window_id_ << " will change state to: " + << "HMI level " << to_resolve_hmi_level + << " --> " << result_hmi_level << ", audio " + << state_to_resolve->audio_streaming_state() + << " --> " << result_audio_state << ", video " + << state_to_resolve->video_streaming_state() + << " --> " << result_video_state); state_ctrl_->SetupRegularHmiState(app_to_resolve, + window_id_, result_hmi_level, result_audio_state, result_video_state); } else { LOG4CXX_DEBUG(logger_, - "Application " << app_to_resolve->app_id() - << " will NOT change HMI level"); + "Application " << app_to_resolve->app_id() << " window " + << window_id_ << " will NOT change HMI level"); } } @@ -413,6 +443,7 @@ HmiStatePtr StateControllerImpl::ResolveHmiState(ApplicationSharedPtr app, CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN(available_state, HmiStatePtr()); available_state->set_hmi_level(state->hmi_level()); + available_state->set_window_type(state->window_type()); available_state->set_audio_streaming_state(state->audio_streaming_state()); available_state->set_video_streaming_state(state->video_streaming_state()); available_state->set_system_context(state->system_context()); @@ -570,12 +601,14 @@ bool StateControllerImpl::IsStateAvailableForResumption( } void StateControllerImpl::SetupRegularHmiState(ApplicationSharedPtr app, + const WindowID window_id, HmiStatePtr state) { using namespace mobile_apis; LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(state); - LOG4CXX_DEBUG(logger_, "Setup regular state: " << *state); - HmiStatePtr curr_state = app->CurrentHmiState(); + LOG4CXX_DEBUG(logger_, + "Setup window #" << window_id << " regular state: " << *state); + HmiStatePtr curr_state = app->CurrentHmiState(window_id); HmiStatePtr old_state = CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); DCHECK_OR_RETURN_VOID(old_state); @@ -583,28 +616,30 @@ void StateControllerImpl::SetupRegularHmiState(ApplicationSharedPtr app, old_state->set_audio_streaming_state(curr_state->audio_streaming_state()); old_state->set_video_streaming_state(curr_state->video_streaming_state()); old_state->set_system_context(curr_state->system_context()); - app->SetRegularState(state); + old_state->set_window_type(curr_state->window_type()); + app->SetRegularState(window_id, state); - if (HMILevel::HMI_LIMITED == state->hmi_level() && app->is_resuming()) { + if (mobile_apis::PredefinedWindows::DEFAULT_WINDOW == window_id && + HMILevel::HMI_LIMITED == state->hmi_level() && app->is_resuming()) { LOG4CXX_DEBUG(logger_, "Resuming to LIMITED level. " << "Send OnResumeAudioSource notification"); MessageHelper::SendOnResumeAudioSourceToHMI(app->app_id(), app_mngr_); } - app->set_is_resuming(false); - HmiStatePtr new_state = app->CurrentHmiState(); - OnStateChanged(app, old_state, new_state); + HmiStatePtr new_state = app->CurrentHmiState(window_id); + OnStateChanged(app, window_id, old_state, new_state); } void StateControllerImpl::SetupRegularHmiState( ApplicationSharedPtr app, + const WindowID window_id, const mobile_apis::HMILevel::eType hmi_level, const mobile_apis::AudioStreamingState::eType audio_state, const mobile_apis::VideoStreamingState::eType video_state) { LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(app); - HmiStatePtr prev_state = app->RegularHmiState(); + HmiStatePtr prev_state = app->RegularHmiState(window_id); DCHECK_OR_RETURN_VOID(prev_state); HmiStatePtr new_state = CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); @@ -613,22 +648,64 @@ void StateControllerImpl::SetupRegularHmiState( new_state->set_audio_streaming_state(audio_state); new_state->set_video_streaming_state(video_state); new_state->set_system_context(prev_state->system_context()); - SetupRegularHmiState(app, new_state); + new_state->set_window_type(prev_state->window_type()); + SetupRegularHmiState(app, window_id, new_state); } void StateControllerImpl::ApplyRegularState(ApplicationSharedPtr app, + const WindowID window_id, HmiStatePtr state) { LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(app); DCHECK_OR_RETURN_VOID(state); DCHECK_OR_RETURN_VOID(state->state_id() == HmiState::STATE_ID_REGULAR); LOG4CXX_DEBUG(logger_, - "Applying to app " << app->app_id() << " state " << *state); - SetupRegularHmiState(app, state); + "Applying to app " << app->app_id() << " window #" << window_id + << " state " << *state); + SetupRegularHmiState(app, window_id, state); + + if (mobile_apis::PredefinedWindows::DEFAULT_WINDOW != window_id) { + LOG4CXX_DEBUG(logger_, "No need to resolve conflicts for a widget"); + return; + } + LOG4CXX_DEBUG(logger_, "Resolving HMI level conflicts for app " << app->app_id()); - ForEachApplication(HmiLevelConflictResolver(app, state, this)); + ForEachApplication(HmiLevelConflictResolver(app, window_id, state, this)); +} + +void StateControllerImpl::UpdateAppWindowsStreamingState( + ApplicationSharedPtr app, HmiStatePtr state) { + LOG4CXX_AUTO_TRACE(logger_); + const auto window_ids = app->GetWindowIds(); + for (auto window_id : window_ids) { + HmiStatePtr window_hmi_state = app->RegularHmiState(window_id); + LOG4CXX_DEBUG( + logger_, "State: " << *state << " window state: " << *window_hmi_state); + if (window_hmi_state->audio_streaming_state() != + state->audio_streaming_state() || + window_hmi_state->video_streaming_state() != + state->video_streaming_state()) { + LOG4CXX_DEBUG(logger_, + "Updating streaming state for window #" << window_id); + + HmiStatePtr new_window_state = + CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); + DCHECK_OR_RETURN_VOID(new_window_state); + new_window_state->set_hmi_level(window_hmi_state->hmi_level()); + new_window_state->set_audio_streaming_state( + state->audio_streaming_state()); + new_window_state->set_video_streaming_state( + state->video_streaming_state()); + new_window_state->set_system_context(window_hmi_state->system_context()); + new_window_state->set_window_type(window_hmi_state->window_type()); + app->SetRegularState(window_id, new_window_state); + + MessageHelper::SendHMIStatusNotification(app, window_id, app_mngr_); + } + } } + void StateControllerImpl::on_event(const event_engine::MobileEvent& event) {} void StateControllerImpl::on_event(const event_engine::Event& event) { @@ -731,26 +808,82 @@ void StateControllerImpl::on_event(const event_engine::Event& event) { } } +void StateControllerImpl::ActivateDefaultWindow(ApplicationSharedPtr app) { + LOG4CXX_AUTO_TRACE(logger_); + using namespace mobile_apis; + + const WindowID window_id = PredefinedWindows::DEFAULT_WINDOW; + 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; + + 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 + HmiStatePtr new_state = + app->RegularHmiState(PredefinedWindows::DEFAULT_WINDOW); + UpdateAppWindowsStreamingState(app, new_state); +} + +void StateControllerImpl::ExitDefaultWindow(ApplicationSharedPtr app) { + LOG4CXX_AUTO_TRACE(logger_); + using namespace mobile_apis; + + const WindowID window_id = PredefinedWindows::DEFAULT_WINDOW; + const HMILevel::eType hmi_level = HMILevel::HMI_NONE; + const AudioStreamingState::eType audio_state = + AudioStreamingState::NOT_AUDIBLE; + const VideoStreamingState::eType video_state = + VideoStreamingState::NOT_STREAMABLE; + + SetRegularState(app, window_id, hmi_level, audio_state, video_state, false); + + // After main window exiting, streaming state should be updated for another + // windows of the app + HmiStatePtr new_state = + app->RegularHmiState(PredefinedWindows::DEFAULT_WINDOW); + UpdateAppWindowsStreamingState(app, new_state); +} + void StateControllerImpl::OnStateChanged(ApplicationSharedPtr app, + const WindowID window_id, HmiStatePtr old_state, HmiStatePtr new_state) { LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(app); DCHECK_OR_RETURN_VOID(old_state); DCHECK_OR_RETURN_VOID(new_state); - LOG4CXX_DEBUG(logger_, "Old state: " << *old_state); - LOG4CXX_DEBUG(logger_, "New state: " << *new_state); - if (IsStateChanged(*old_state, *new_state)) { - app_mngr_.SendHMIStatusNotification(app); - if (new_state->hmi_level() == mobile_apis::HMILevel::HMI_NONE) { - app->ResetDataInNone(); - } - app_mngr_.OnHMILevelChanged( - app->app_id(), old_state->hmi_level(), new_state->hmi_level()); - app->usage_report().RecordHmiStateChanged(new_state->hmi_level()); - } else { - LOG4CXX_ERROR(logger_, "State has NOT been changed."); + LOG4CXX_DEBUG(logger_, + "Window #" << window_id << " old state: " << *old_state); + LOG4CXX_DEBUG(logger_, + "Window #" << window_id << " new state: " << *new_state); + + if (!IsStateChanged(*old_state, *new_state)) { + LOG4CXX_DEBUG(logger_, "State has NOT been changed."); + return; + } + + MessageHelper::SendHMIStatusNotification(app, window_id, app_mngr_); + + if (mobile_apis::PredefinedWindows::DEFAULT_WINDOW != window_id) { + LOG4CXX_DEBUG(logger_, + "State was changed not for a main application window. No " + "additional actions required"); + return; } + + if (new_state->hmi_level() == mobile_apis::HMILevel::HMI_NONE) { + app->ResetDataInNone(); + } + + app_mngr_.OnHMILevelChanged( + app->app_id(), old_state->hmi_level(), new_state->hmi_level()); + app->usage_report().RecordHmiStateChanged(new_state->hmi_level()); } bool StateControllerImpl::IsTempStateActive(HmiState::StateID id) const { @@ -761,6 +894,20 @@ bool StateControllerImpl::IsTempStateActive(HmiState::StateID id) const { void StateControllerImpl::OnApplicationRegistered( ApplicationSharedPtr app, const mobile_apis::HMILevel::eType default_level) { + LOG4CXX_AUTO_TRACE(logger_); + + // After app registration HMI level should be set for DEFAUL_WINDOW only + OnAppWindowAdded(app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + mobile_apis::WindowType::MAIN, + default_level); +} + +void StateControllerImpl::OnAppWindowAdded( + ApplicationSharedPtr app, + const WindowID window_id, + const mobile_apis::WindowType::eType window_type, + const mobile_apis::HMILevel::eType default_level) { namespace HMILevel = mobile_apis::HMILevel; namespace AudioStreamingState = mobile_apis::AudioStreamingState; namespace SystemContext = mobile_apis::SystemContext; @@ -774,9 +921,10 @@ void StateControllerImpl::OnApplicationRegistered( DCHECK_OR_RETURN_VOID(new_state); DCHECK_OR_RETURN_VOID(new_state->state_id() != HmiState::STATE_ID_REGULAR); - HmiStatePtr old_hmi_state = app->CurrentHmiState(); + HmiStatePtr old_hmi_state = app->CurrentHmiState(window_id); new_state->set_parent(old_hmi_state); - app->AddHMIState(new_state); + new_state->set_window_type(old_hmi_state->window_type()); + app->AddHMIState(window_id, new_state); } } @@ -787,14 +935,15 @@ void StateControllerImpl::OnApplicationRegistered( default_state->set_audio_streaming_state(CalcAudioState(app, default_level)); default_state->set_video_streaming_state(CalcVideoState(app, default_level)); default_state->set_system_context(SystemContext::SYSCTXT_MAIN); + default_state->set_window_type(window_type); - HmiStatePtr initial_state = app->RegularHmiState(); + HmiStatePtr initial_state = app->RegularHmiState(window_id); - app->SetRegularState(default_state); + app->SetRegularState(window_id, default_state); - HmiStatePtr new_state = app->CurrentHmiState(); + HmiStatePtr new_state = app->CurrentHmiState(window_id); - OnStateChanged(app, initial_state, new_state); + OnStateChanged(app, window_id, initial_state, new_state); } int64_t StateControllerImpl::RequestHMIStateChange( @@ -828,11 +977,15 @@ int64_t StateControllerImpl::RequestHMIStateChange( void StateControllerImpl::ApplyPostponedStateForApp(ApplicationSharedPtr app) { LOG4CXX_AUTO_TRACE(logger_); - HmiStatePtr state = app->PostponedHmiState(); - if (state) { - app->RemovePostponedState(); - state->set_state_id(HmiState::STATE_ID_REGULAR); - SetRegularState(app, state); + const WindowIds window_ids = app->GetWindowIds(); + + for (const auto& window_id : window_ids) { + HmiStatePtr state = app->PostponedHmiState(window_id); + if (state) { + app->RemovePostponedState(window_id); + state->set_state_id(HmiState::STATE_ID_REGULAR); + SetRegularState(app, window_id, state); + } } } @@ -860,16 +1013,19 @@ void StateControllerImpl::TempStateStopped(HmiState::StateID ID) { std::mem_fun(&StateControllerImpl::ApplyPostponedStateForApp), this)); } -void StateControllerImpl::DeactivateApp(ApplicationSharedPtr app) { +void StateControllerImpl::DeactivateApp(ApplicationSharedPtr app, + const WindowID window_id) { using namespace mobile_apis; LOG4CXX_AUTO_TRACE(logger_); DCHECK_OR_RETURN_VOID(app); - const HmiStatePtr regular = app->RegularHmiState(); + const HmiStatePtr regular = app->RegularHmiState(window_id); DCHECK_OR_RETURN_VOID(regular); HmiStatePtr new_regular = std::make_shared<HmiState>(*regular); - LOG4CXX_DEBUG(logger_, "Current HMI level: '" << app->hmi_level() << "'"); + LOG4CXX_DEBUG(logger_, + "Window #" << window_id << " current HMI level: '" + << app->hmi_level(window_id) << "'"); const bool is_audio_app = app->IsAudioApplication(); const bool is_video_app = app->IsVideoApplication(); @@ -895,7 +1051,7 @@ void StateControllerImpl::DeactivateApp(ApplicationSharedPtr app) { new_regular->set_video_streaming_state(VideoStreamingState::NOT_STREAMABLE); } - SetRegularState(app, new_regular, false); + SetRegularState(app, window_id, new_regular, false); } void StateControllerImpl::OnHMIResponse( @@ -911,7 +1067,9 @@ void StateControllerImpl::OnHMIResponse( if (application && hmi_apis::Common_Result::SUCCESS == code) { HmiStatePtr pending_state = waiting_for_response_[application->app_id()]; DCHECK_OR_RETURN_VOID(pending_state); - ApplyRegularState(application, pending_state); + ApplyRegularState(application, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + pending_state); } } @@ -927,7 +1085,33 @@ void StateControllerImpl::OnAppActivated( return; } - SetRegularState(app, HMILevel::HMI_FULL, true); + WindowID window_id = mobile_apis::PredefinedWindows::DEFAULT_WINDOW; + if (message[strings::msg_params].keyExists(strings::window_id)) { + window_id = message[strings::msg_params][strings::window_id].asInt(); + } + + const auto window_ids = app->GetWindowIds(); + if (!helpers::in_range(window_ids, window_id)) { + LOG4CXX_ERROR( + logger_, + "Application " << app_id << " does not contain window #" << window_id); + return; + } + + if (PredefinedWindows::DEFAULT_WINDOW != window_id) { + const auto window_hmi_level = app->hmi_level(window_id); + const HMILevel::eType new_hmi_level = HMILevel::HMI_NONE == window_hmi_level + ? HMILevel::HMI_BACKGROUND + : HMILevel::HMI_FULL; + const AudioStreamingState::eType audio_state = app->audio_streaming_state(); + const VideoStreamingState::eType video_state = app->video_streaming_state(); + + SetRegularState( + app, window_id, new_hmi_level, audio_state, video_state, false); + return; + } + + SetRegularState(app, window_id, HMILevel::HMI_FULL, true); } void StateControllerImpl::OnAppDeactivated( @@ -942,13 +1126,39 @@ void StateControllerImpl::OnAppDeactivated( return; } - if (HMILevel::HMI_FULL != app->hmi_level()) { + WindowID window_id = mobile_apis::PredefinedWindows::DEFAULT_WINDOW; + if (message[strings::msg_params].keyExists(strings::window_id)) { + window_id = message[strings::msg_params][strings::window_id].asInt(); + } + + const auto window_ids = app->GetWindowIds(); + if (!helpers::in_range(window_ids, window_id)) { + LOG4CXX_ERROR( + logger_, + "Application " << app_id << " does not contain window #" << window_id); + return; + } + + const auto window_hmi_level = app->hmi_level(window_id); + if (PredefinedWindows::DEFAULT_WINDOW != window_id) { + const HMILevel::eType new_hmi_level = HMILevel::HMI_FULL == window_hmi_level + ? HMILevel::HMI_BACKGROUND + : HMILevel::HMI_NONE; + const AudioStreamingState::eType audio_state = app->audio_streaming_state(); + const VideoStreamingState::eType video_state = app->video_streaming_state(); + + SetRegularState( + app, window_id, new_hmi_level, audio_state, video_state, false); + return; + } + + if (HMILevel::HMI_FULL != window_hmi_level) { return; } // TODO(AOleynik): Need to delete DeactivateReason and modify OnAppDeactivated // when HMI will support that, otherwise won't be testable - DeactivateApp(app); + DeactivateApp(app, window_id); } void StateControllerImpl::OnVideoStreamingStarted( |