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 | 150 |
1 files changed, 104 insertions, 46 deletions
diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 974f125def..c02bedc80c 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -1807,7 +1807,7 @@ bool ApplicationManagerImpl::StartNaviService( using namespace protocol_handler; LOG4CXX_AUTO_TRACE(logger_); - if (HMILevelAllowsStreaming(app_id, service_type)) { + if (HMIStateAllowsStreaming(app_id, service_type)) { { sync_primitives::AutoLock lock(navi_service_status_lock_); @@ -3281,10 +3281,12 @@ std::string ApplicationManagerImpl::GetHashedAppID( return mobile_app_id + device_name; } -bool ApplicationManagerImpl::HMILevelAllowsStreaming( +bool ApplicationManagerImpl::HMIStateAllowsStreaming( uint32_t app_id, protocol_handler::ServiceType service_type) const { LOG4CXX_AUTO_TRACE(logger_); using namespace mobile_apis::HMILevel; + using namespace mobile_apis::PredefinedWindows; + using namespace mobile_apis::VideoStreamingState; using namespace helpers; ApplicationSharedPtr app = application(app_id); @@ -3292,10 +3294,15 @@ bool ApplicationManagerImpl::HMILevelAllowsStreaming( LOG4CXX_WARN(logger_, "An application is not registered."); return false; } - return Compare<eType, EQ, ONE>( - app->hmi_level(mobile_api::PredefinedWindows::DEFAULT_WINDOW), - HMI_FULL, - HMI_LIMITED); + + const auto hmi_state = app->CurrentHmiState(DEFAULT_WINDOW); + const bool allow_streaming_by_hmi_level = + Compare<mobile_apis::HMILevel::eType, EQ, ONE>( + hmi_state->hmi_level(), HMI_FULL, HMI_LIMITED); + const bool allow_streaming_by_streaming_state = + hmi_state->video_streaming_state() == STREAMABLE; + + return allow_streaming_by_hmi_level && allow_streaming_by_streaming_state; } bool ApplicationManagerImpl::CanAppStream( @@ -3318,7 +3325,7 @@ bool ApplicationManagerImpl::CanAppStream( LOG4CXX_WARN(logger_, "Unsupported service_type " << service_type); } - return HMILevelAllowsStreaming(app_id, service_type) && is_allowed; + return HMIStateAllowsStreaming(app_id, service_type) && is_allowed; } void ApplicationManagerImpl::ForbidStreaming(uint32_t app_id) { @@ -3441,10 +3448,9 @@ void ApplicationManagerImpl::EndNaviServices(uint32_t app_id) { } } -void ApplicationManagerImpl::OnHMILevelChanged( - uint32_t app_id, - mobile_apis::HMILevel::eType from, - mobile_apis::HMILevel::eType to) { +void ApplicationManagerImpl::OnHMIStateChanged(const uint32_t app_id, + const HmiStatePtr from, + const HmiStatePtr to) { LOG4CXX_AUTO_TRACE(logger_); ProcessPostponedMessages(app_id); ProcessApp(app_id, from, to); @@ -3520,48 +3526,92 @@ void ApplicationManagerImpl::ProcessOnDataStreamingNotification( } void ApplicationManagerImpl::ProcessApp(const uint32_t app_id, - const mobile_apis::HMILevel::eType from, - const mobile_apis::HMILevel::eType to) { + const HmiStatePtr from, + const HmiStatePtr to) { using namespace mobile_apis::HMILevel; + using namespace mobile_apis::VideoStreamingState; using namespace helpers; - if (from == to) { - LOG4CXX_TRACE(logger_, "HMILevel from = to"); - return; - } - ApplicationSharedPtr app = application(app_id); if (!app || (!app->is_navi() && !app->mobile_projection_enabled())) { LOG4CXX_ERROR(logger_, "Navi/Projection application not found"); return; } - if (to == HMI_FULL || to == HMI_LIMITED) { - LOG4CXX_TRACE(logger_, "HMILevel to FULL or LIMITED"); - if (from == HMI_BACKGROUND) { - LOG4CXX_TRACE(logger_, "HMILevel from BACKGROUND"); - AllowStreaming(app_id); - } - } else if (to == HMI_BACKGROUND) { - LOG4CXX_TRACE(logger_, "HMILevel to BACKGROUND"); - 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(std::make_shared<timer::Timer>( - "AppShouldFinishStreaming", - new TimerTaskImpl<ApplicationManagerImpl>( - this, &ApplicationManagerImpl::EndNaviStreaming))); - end_stream_timer->Start(navi_end_stream_timeout_, timer::kPeriodic); + const auto hmi_level_from = from->hmi_level(); + const auto hmi_level_to = to->hmi_level(); + const auto streaming_state_from = from->video_streaming_state(); + const auto streaming_state_to = to->video_streaming_state(); - sync_primitives::AutoLock lock(timer_pool_lock_); - timer_pool_.push_back(end_stream_timer); - } - } else if (to == HMI_NONE) { - LOG4CXX_TRACE(logger_, "HMILevel to NONE"); - if (from == HMI_FULL || from == HMI_LIMITED || from == HMI_BACKGROUND) { - EndNaviServices(app_id); - } + if (hmi_level_from == hmi_level_to && + streaming_state_from == streaming_state_to) { + LOG4CXX_TRACE(logger_, "HMILevel && streaming state were not changed"); + return; } + + auto full_or_limited_hmi_level = [](mobile_apis::HMILevel::eType hmi_level) { + return Compare<mobile_apis::HMILevel::eType, EQ, ONE>( + hmi_level, HMI_FULL, HMI_LIMITED); + }; + + const bool allow_streaming_by_streaming_state = + NOT_STREAMABLE == streaming_state_from && + STREAMABLE == streaming_state_to; + const bool allow_streaming_by_hmi_level = + HMI_BACKGROUND == hmi_level_from && + full_or_limited_hmi_level(hmi_level_to) && + STREAMABLE == streaming_state_to; + if (allow_streaming_by_streaming_state || allow_streaming_by_hmi_level) { + LOG4CXX_TRACE(logger_, + "Allow streaming by streaming state: " + << std::boolalpha << allow_streaming_by_streaming_state + << "; by hmi level: " << std::boolalpha + << allow_streaming_by_hmi_level); + AllowStreaming(app_id); + return; + } + + const bool end_streaming_by_streaming_state = + STREAMABLE == streaming_state_from && + NOT_STREAMABLE == streaming_state_to && + full_or_limited_hmi_level(hmi_level_to); + const bool start_timer_by_hmi_level = + full_or_limited_hmi_level(hmi_level_from) && + HMI_BACKGROUND == hmi_level_to; + if (end_streaming_by_streaming_state || start_timer_by_hmi_level) { + LOG4CXX_TRACE(logger_, + "Start EndStream timer by streaming state: " + << std::boolalpha << end_streaming_by_streaming_state + << "; by hmi level: " << std::boolalpha + << start_timer_by_hmi_level); + StartEndStreamTimer(app_id); + return; + } + + const bool end_streaming_by_hmi_level = + full_or_limited_hmi_level(hmi_level_from) && HMI_NONE == hmi_level_to; + if (end_streaming_by_hmi_level) { + LOG4CXX_TRACE(logger_, + "End streaming services by hmi level: " + << std::boolalpha << end_streaming_by_hmi_level); + EndNaviServices(app_id); + return; + } + + LOG4CXX_TRACE(logger_, "No actions required for app " << app_id); +} + +void ApplicationManagerImpl::StartEndStreamTimer(const uint32_t app_id) { + LOG4CXX_DEBUG(logger_, "Start end stream timer for app " << app_id); + navi_app_to_end_stream_.push_back(app_id); + TimerSPtr end_stream_timer(std::make_shared<timer::Timer>( + "DisallowAppStreamTimer", + new TimerTaskImpl<ApplicationManagerImpl>( + this, &ApplicationManagerImpl::EndNaviStreaming))); + end_stream_timer->Start(navi_end_stream_timeout_, timer::kSingleShot); + + sync_primitives::AutoLock lock(timer_pool_lock_); + timer_pool_.push_back(end_stream_timer); } void ApplicationManagerImpl::ClearTimerPool() { @@ -4550,11 +4600,19 @@ void ApplicationManagerImpl::ChangeAppsHMILevel( LOG4CXX_ERROR(logger_, "There is no app with id: " << app_id); return; } - const mobile_apis::HMILevel::eType old_level = - app->hmi_level(mobile_api::PredefinedWindows::DEFAULT_WINDOW); - if (old_level != level) { + + const auto old_hmi_state = + app->CurrentHmiState(mobile_apis::PredefinedWindows::DEFAULT_WINDOW); + if (old_hmi_state->hmi_level() != level) { app->set_hmi_level(mobile_apis::PredefinedWindows::DEFAULT_WINDOW, level); - OnHMILevelChanged(app_id, old_level, level); + const auto new_hmi_state = + CreateRegularState(app, + mobile_apis::WindowType::MAIN, + level, + old_hmi_state->audio_streaming_state(), + old_hmi_state->video_streaming_state(), + old_hmi_state->system_context()); + OnHMIStateChanged(app_id, old_hmi_state, new_hmi_state); } else { LOG4CXX_WARN(logger_, "Redundant changing HMI level: " << level); } |