From 6710b2e04ba5417ce1c0e1794b473963bf51df08 Mon Sep 17 00:00:00 2001 From: "Mykola Korniichuk (GitHub)" <42380041+mkorniichuk@users.noreply.github.com> Date: Fri, 17 Jan 2020 18:36:02 +0200 Subject: Fix SDL app stream processing with non-streamable state. (#3151) * Fix SDL app stream processing with non-streamable state. For determining whether an application is allowed to stream, SDL considered only HMI_Level. Now streaming state is also taken into account. Fix notifications for not streamable apps * Fix unit tests after rename function in new inplimentation * Minor fixes * const parameter for StartEndStreamTimer * Fix logging messages * end_stream_timer shanged to SingleShot * fix unit test for state_controller * fixup! Minor fixes * const parameter for StartEndStreamTimer * Fix logging messages * end_stream_timer shanged to SingleShot * fix unit test for state_controller * rename HMILevelAllowsStreaming -> HMIStateAllowsStreaming * fixup! Fix SDL app stream processing with non-streamable state. Co-authored-by: Yevhenii Dementieiev (GitHub) <57259850+ydementieiev@users.noreply.github.com> --- .../application_manager/application_manager_impl.h | 21 ++- .../hmi/navi_audio_start_stream_request.cc | 2 +- .../src/commands/hmi/navi_start_stream_request.cc | 2 +- .../src/application_manager_impl.cc | 150 ++++++++++++++------- .../src/state_controller_impl.cc | 3 +- .../test/application_manager_impl_test.cc | 66 +++++++-- .../test/state_controller/state_controller_test.cc | 49 +++---- .../application_manager/application_manager.h | 19 +-- .../application_manager/mock_application_manager.h | 10 +- 9 files changed, 209 insertions(+), 113 deletions(-) diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index ee4e3a05a0..7ac8658dd4 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -213,9 +213,9 @@ class ApplicationManagerImpl void set_current_audio_source(const uint32_t source) OVERRIDE; - void OnHMILevelChanged(uint32_t app_id, - mobile_apis::HMILevel::eType from, - mobile_apis::HMILevel::eType to) OVERRIDE; + void OnHMIStateChanged(const uint32_t app_id, + const HmiStatePtr from, + const HmiStatePtr to) OVERRIDE; void ProcessOnDataStreamingNotification( const protocol_handler::ServiceType service_type, @@ -798,12 +798,13 @@ class ApplicationManagerImpl void RemovePolicyObserver(PolicyHandlerObserver* listener); /** - * @brief Checks HMI level and returns true if streaming is allowed + * @brief Checks application HMI state and returns true if streaming is + * allowed * @param app_id Application id * @param service_type Service type to check * @return True if streaming is allowed, false in other case */ - bool HMILevelAllowsStreaming( + bool HMIStateAllowsStreaming( uint32_t app_id, protocol_handler::ServiceType service_type) const OVERRIDE; @@ -1289,8 +1290,14 @@ class ApplicationManagerImpl * @param to the new HMILevel for the certain app. */ void ProcessApp(const uint32_t app_id, - const mobile_apis::HMILevel::eType from, - const mobile_apis::HMILevel::eType to); + const HmiStatePtr from, + const HmiStatePtr to); + + /** + * @brief Starts EndStream timer for a specified application + * @param app_id Application to process + */ + void StartEndStreamTimer(const uint32_t app_id); /** * @brief Allows to send appropriate message to mobile device. diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_audio_start_stream_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_audio_start_stream_request.cc index 371f47a759..060a2bda34 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_audio_start_stream_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_audio_start_stream_request.cc @@ -113,7 +113,7 @@ void AudioStartStreamRequest::on_event(const event_engine::Event& event) { if (hmi_apis::Common_Result::SUCCESS == code) { LOG4CXX_INFO(logger_, "StartAudioStream response SUCCESS"); - if (application_manager_.HMILevelAllowsStreaming(app->app_id(), + if (application_manager_.HMIStateAllowsStreaming(app->app_id(), ServiceType::kAudio)) { app->set_audio_streaming_approved(true); } else { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_start_stream_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_start_stream_request.cc index 90f7c2d0f1..4228eb8859 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_start_stream_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/navi_start_stream_request.cc @@ -115,7 +115,7 @@ void NaviStartStreamRequest::on_event(const event_engine::Event& event) { if (hmi_apis::Common_Result::SUCCESS == code) { LOG4CXX_INFO(logger_, "NaviStartStreamResponse SUCCESS"); - if (application_manager_.HMILevelAllowsStreaming( + if (application_manager_.HMIStateAllowsStreaming( app->app_id(), ServiceType::kMobileNav)) { app->set_video_streaming_approved(true); } else { 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( - 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( + 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( - "AppShouldFinishStreaming", - new TimerTaskImpl( - 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( + 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( + "DisallowAppStreamTimer", + new TimerTaskImpl( + 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); } diff --git a/src/components/application_manager/src/state_controller_impl.cc b/src/components/application_manager/src/state_controller_impl.cc index 8368597370..1bf4c2bf66 100644 --- a/src/components/application_manager/src/state_controller_impl.cc +++ b/src/components/application_manager/src/state_controller_impl.cc @@ -881,8 +881,7 @@ void StateControllerImpl::OnStateChanged(ApplicationSharedPtr app, app->ResetDataInNone(); } - app_mngr_.OnHMILevelChanged( - app->app_id(), old_state->hmi_level(), new_state->hmi_level()); + app_mngr_.OnHMIStateChanged(app->app_id(), old_state, new_state); app->usage_report().RecordHmiStateChanged(new_state->hmi_level()); } diff --git a/src/components/application_manager/test/application_manager_impl_test.cc b/src/components/application_manager/test/application_manager_impl_test.cc index aa82c6b86b..a70015c9ed 100644 --- a/src/components/application_manager/test/application_manager_impl_test.cc +++ b/src/components/application_manager/test/application_manager_impl_test.cc @@ -531,10 +531,16 @@ TEST_F(ApplicationManagerImplTest, OnServiceStartedCallback_VideoServiceStart) { const protocol_handler::ServiceType service_type = protocol_handler::ServiceType::kMobileNav; const int32_t session_key = 123; + HmiStatePtr hmi_state(std::make_shared( + mock_app_ptr_, mock_app_mngr_, HmiState::STATE_ID_REGULAR)); + hmi_state->set_video_streaming_state( + mobile_apis::VideoStreamingState::eType::STREAMABLE); + hmi_state->set_hmi_level(mobile_apis::HMILevel::HMI_FULL); + + EXPECT_CALL(*mock_app_ptr_, CurrentHmiState(_)) + .WillRepeatedly(Return(hmi_state)); EXPECT_CALL(*mock_app_ptr_, app_id()).WillRepeatedly(Return(session_key)); EXPECT_CALL(*mock_app_ptr_, is_navi()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_app_ptr_, hmi_level(kDefaultWindowId)) - .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL)); bool result = false; std::vector rejected_params; @@ -595,8 +601,14 @@ TEST_F(ApplicationManagerImplTest, EXPECT_CALL(*mock_app_ptr_, app_id()).WillRepeatedly(Return(session_key)); EXPECT_CALL(*mock_app_ptr_, is_navi()).WillRepeatedly(Return(true)); // HMI level is not FULL nor LIMITED - EXPECT_CALL(*mock_app_ptr_, hmi_level(kDefaultWindowId)) - .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_BACKGROUND)); + HmiStatePtr hmi_state(std::make_shared( + mock_app_ptr_, mock_app_mngr_, HmiState::STATE_ID_REGULAR)); + hmi_state->set_video_streaming_state( + mobile_apis::VideoStreamingState::eType::STREAMABLE); + hmi_state->set_hmi_level(mobile_apis::HMILevel::HMI_BACKGROUND); + + EXPECT_CALL(*mock_app_ptr_, CurrentHmiState(_)) + .WillRepeatedly(Return(hmi_state)); bool result = false; std::vector rejected_params; @@ -625,8 +637,14 @@ TEST_F(ApplicationManagerImplTest, const int32_t session_key = 123; EXPECT_CALL(*mock_app_ptr_, app_id()).WillRepeatedly(Return(session_key)); EXPECT_CALL(*mock_app_ptr_, is_navi()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_app_ptr_, hmi_level(kDefaultWindowId)) - .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_LIMITED)); + HmiStatePtr hmi_state(std::make_shared( + mock_app_ptr_, mock_app_mngr_, HmiState::STATE_ID_REGULAR)); + hmi_state->set_video_streaming_state( + mobile_apis::VideoStreamingState::eType::STREAMABLE); + hmi_state->set_hmi_level(mobile_apis::HMILevel::HMI_LIMITED); + + EXPECT_CALL(*mock_app_ptr_, CurrentHmiState(_)) + .WillRepeatedly(Return(hmi_state)); bool result = false; std::vector rejected_params; @@ -709,8 +727,13 @@ TEST_F(ApplicationManagerImplTest, const int32_t session_key = 123; EXPECT_CALL(*mock_app_ptr_, app_id()).WillRepeatedly(Return(session_key)); EXPECT_CALL(*mock_app_ptr_, is_navi()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_app_ptr_, hmi_level(kDefaultWindowId)) - .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL)); + HmiStatePtr hmi_state(std::make_shared( + mock_app_ptr_, mock_app_mngr_, HmiState::STATE_ID_REGULAR)); + hmi_state->set_video_streaming_state( + mobile_apis::VideoStreamingState::eType::STREAMABLE); + hmi_state->set_hmi_level(mobile_apis::HMILevel::HMI_FULL); + EXPECT_CALL(*mock_app_ptr_, CurrentHmiState(_)) + .WillRepeatedly(Return(hmi_state)); bool result = false; std::vector rejected_params; @@ -783,8 +806,13 @@ TEST_F(ApplicationManagerImplTest, const int32_t session_key = 123; EXPECT_CALL(*mock_app_ptr_, app_id()).WillRepeatedly(Return(session_key)); EXPECT_CALL(*mock_app_ptr_, is_navi()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_app_ptr_, hmi_level(kDefaultWindowId)) - .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL)); + HmiStatePtr hmi_state(std::make_shared( + mock_app_ptr_, mock_app_mngr_, HmiState::STATE_ID_REGULAR)); + hmi_state->set_video_streaming_state( + mobile_apis::VideoStreamingState::eType::STREAMABLE); + hmi_state->set_hmi_level(mobile_apis::HMILevel::HMI_FULL); + EXPECT_CALL(*mock_app_ptr_, CurrentHmiState(_)) + .WillRepeatedly(Return(hmi_state)); bool result = false; std::vector rejected_params; @@ -818,8 +846,13 @@ TEST_F(ApplicationManagerImplTest, OnServiceStartedCallback_AudioServiceStart) { const int32_t session_key = 123; EXPECT_CALL(*mock_app_ptr_, app_id()).WillRepeatedly(Return(session_key)); EXPECT_CALL(*mock_app_ptr_, is_navi()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_app_ptr_, hmi_level(kDefaultWindowId)) - .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL)); + HmiStatePtr hmi_state(std::make_shared( + mock_app_ptr_, mock_app_mngr_, HmiState::STATE_ID_REGULAR)); + hmi_state->set_video_streaming_state( + mobile_apis::VideoStreamingState::eType::STREAMABLE); + hmi_state->set_hmi_level(mobile_apis::HMILevel::HMI_FULL); + EXPECT_CALL(*mock_app_ptr_, CurrentHmiState(_)) + .WillRepeatedly(Return(hmi_state)); bool result = false; std::vector rejected_params; @@ -848,8 +881,13 @@ TEST_F(ApplicationManagerImplTest, const int32_t session_key = 123; EXPECT_CALL(*mock_app_ptr_, app_id()).WillRepeatedly(Return(session_key)); EXPECT_CALL(*mock_app_ptr_, is_navi()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_app_ptr_, hmi_level(kDefaultWindowId)) - .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL)); + HmiStatePtr hmi_state(std::make_shared( + mock_app_ptr_, mock_app_mngr_, HmiState::STATE_ID_REGULAR)); + hmi_state->set_video_streaming_state( + mobile_apis::VideoStreamingState::eType::STREAMABLE); + hmi_state->set_hmi_level(mobile_apis::HMILevel::HMI_FULL); + EXPECT_CALL(*mock_app_ptr_, CurrentHmiState(_)) + .WillRepeatedly(Return(hmi_state)); bool result = false; std::vector rejected_params; diff --git a/src/components/application_manager/test/state_controller/state_controller_test.cc b/src/components/application_manager/test/state_controller/state_controller_test.cc index 9799dbcac2..93565b8719 100644 --- a/src/components/application_manager/test/state_controller/state_controller_test.cc +++ b/src/components/application_manager/test/state_controller/state_controller_test.cc @@ -1096,10 +1096,8 @@ class StateControllerImplTest : public ::testing::Test { EXPECT_CALL(message_helper_mock_, SendHMIStatusNotification(app, window_id, _)); if (kDefaultWindowId == window_id) { - EXPECT_CALL( - app_manager_mock_, - OnHMILevelChanged( - app->app_id(), old_state->hmi_level(), new_state->hmi_level())); + EXPECT_CALL(app_manager_mock_, + OnHMIStateChanged(app->app_id(), _, new_state)); } } } @@ -1124,7 +1122,7 @@ class StateControllerImplTest : public ::testing::Test { EXPECT_CALL(message_helper_mock_, SendHMIStatusNotification(app, window_id, _)) .Times(0); - EXPECT_CALL(app_manager_mock_, OnHMILevelChanged(app->app_id(), _, _)) + EXPECT_CALL(app_manager_mock_, OnHMIStateChanged(app->app_id(), _, _)) .Times(0); } @@ -1367,7 +1365,7 @@ class StateControllerImplTest : public ::testing::Test { TEST_F(StateControllerImplTest, OnStateChangedWithEqualStates) { EXPECT_CALL(app_manager_mock_, SendHMIStatusNotification(_)).Times(0); - EXPECT_CALL(app_manager_mock_, OnHMILevelChanged(_, _, _)).Times(0); + EXPECT_CALL(app_manager_mock_, OnHMIStateChanged(_, _, _)).Times(0); EXPECT_CALL(*simple_app_ptr_, ResetDataInNone()).Times(0); for (uint32_t i = 0; i < valid_states_for_not_audio_app_.size(); ++i) { @@ -1386,11 +1384,10 @@ TEST_F(StateControllerImplTest, OnStateChangedWithDifferentStates) { EXPECT_CALL( message_helper_mock_, SendHMIStatusNotification(simple_app_, kDefaultWindowId, _)); - EXPECT_CALL( - app_manager_mock_, - OnHMILevelChanged(simple_app_id_, - valid_states_for_not_audio_app_[i]->hmi_level(), - valid_states_for_not_audio_app_[j]->hmi_level())) + EXPECT_CALL(app_manager_mock_, + OnHMIStateChanged(simple_app_id_, + valid_states_for_not_audio_app_[i], + valid_states_for_not_audio_app_[j])) .Times(1); if (mobile_apis::HMILevel::HMI_NONE == valid_states_for_not_audio_app_[j]->hmi_level()) { @@ -1403,7 +1400,7 @@ TEST_F(StateControllerImplTest, OnStateChangedWithDifferentStates) { EXPECT_CALL(message_helper_mock_, SendHMIStatusNotification(_, _, _)) .Times(0); - EXPECT_CALL(app_manager_mock_, OnHMILevelChanged(_, _, _)).Times(0); + EXPECT_CALL(app_manager_mock_, OnHMIStateChanged(_, _, _)).Times(0); EXPECT_CALL(*simple_app_ptr_, ResetDataInNone()).Times(0); } } @@ -1454,9 +1451,9 @@ TEST_F(StateControllerImplTest, MoveSimpleAppToValidStates) { EXPECT_CALL(message_helper_mock_, SendHMIStatusNotification(simple_app_, kDefaultWindowId, _)); EXPECT_CALL(app_manager_mock_, - OnHMILevelChanged(simple_app_id_, - initial_state->hmi_level(), - state_to_setup->hmi_level())); + OnHMIStateChanged(simple_app_id_, + Truly(HmiStatesComparator(initial_state)), + state_to_setup)); EXPECT_CALL(*simple_app_ptr_, SetRegularState(kDefaultWindowId, @@ -1493,9 +1490,7 @@ TEST_F(StateControllerImplTest, MoveAudioNotResumeAppToValidStates) { EXPECT_CALL(message_helper_mock_, SendHMIStatusNotification(audio_app, kDefaultWindowId, _)); EXPECT_CALL(app_manager_mock_, - OnHMILevelChanged(audio_app->app_id(), - initial_state->hmi_level(), - state_to_setup->hmi_level())); + OnHMIStateChanged(audio_app->app_id(), _, state_to_setup)); EXPECT_CALL(*audio_app_mock, SetRegularState(kDefaultWindowId, @@ -1550,9 +1545,7 @@ TEST_F(StateControllerImplTest, MoveAudioResumeAppToValidStates) { EXPECT_CALL(app_manager_mock_, SendHMIStatusNotification(audio_app)) .Times(AtLeast(0)); EXPECT_CALL(app_manager_mock_, - OnHMILevelChanged(audio_app->app_id(), - initial_state->hmi_level(), - state_to_setup->hmi_level())) + OnHMIStateChanged(audio_app->app_id(), _, state_to_setup)) .Times(AtLeast(0)); // Check that we set correct state @@ -1575,7 +1568,7 @@ TEST_F(StateControllerImplTest, MoveAppFromValidStateToInvalid) { HmiStatePtr invalid_state = *invalid_state_it; EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)).Times(0); EXPECT_CALL(*simple_app_ptr_, is_resuming()).Times(0); - EXPECT_CALL(app_manager_mock_, OnHMILevelChanged(_, _, _)).Times(0); + EXPECT_CALL(app_manager_mock_, OnHMIStateChanged(_, _, _)).Times(0); EXPECT_CALL(*simple_app_ptr_, SetRegularState(kDefaultWindowId, _)) .Times(0); state_ctrl_->SetRegularState( @@ -1590,7 +1583,7 @@ TEST_F(StateControllerImplTest, MoveAppFromValidStateToInvalid) { EXPECT_CALL(*media_navi_vc_app_ptr_, CurrentHmiState(kDefaultWindowId)) .Times(0); EXPECT_CALL(*media_navi_vc_app_ptr_, is_resuming()).Times(0); - EXPECT_CALL(app_manager_mock_, OnHMILevelChanged(_, _, _)).Times(0); + EXPECT_CALL(app_manager_mock_, OnHMIStateChanged(_, _, _)).Times(0); EXPECT_CALL(*media_navi_vc_app_ptr_, SetRegularState(kDefaultWindowId, _)) .Times(0); state_ctrl_->SetRegularState( @@ -2157,7 +2150,7 @@ TEST_F(StateControllerImplTest, SendEventBCActivateApp_HMIReceivesError) { EXPECT_CALL(app_manager_mock_, SendHMIStatusNotification(simple_app_)) .Times(0); EXPECT_CALL(app_manager_mock_, - OnHMILevelChanged(simple_app_->app_id(), _, _)) + OnHMIStateChanged(simple_app_->app_id(), _, _)) .Times(0); smart_objects::SmartObject message; @@ -2181,7 +2174,7 @@ TEST_F(StateControllerImplTest, ActivateAppInvalidCorrelationId) { EXPECT_CALL(*simple_app_ptr_, SetRegularState(kDefaultWindowId, _)).Times(0); EXPECT_CALL(app_manager_mock_, SendHMIStatusNotification(simple_app_)) .Times(0); - EXPECT_CALL(app_manager_mock_, OnHMILevelChanged(simple_app_->app_id(), _, _)) + EXPECT_CALL(app_manager_mock_, OnHMIStateChanged(simple_app_->app_id(), _, _)) .Times(0); SetBCActivateAppRequestToHMI(Common_HMILevel::FULL, corr_id); state_ctrl_->SetRegularState( @@ -3317,7 +3310,7 @@ TEST_F(StateControllerImplTest, OnApplicationRegisteredDifferentStates) { EXPECT_CALL(*simple_app_ptr_, ResetDataInNone()).Times(0); EXPECT_CALL(message_helper_mock_, SendHMIStatusNotification(simple_app_, kDefaultWindowId, _)); - EXPECT_CALL(app_manager_mock_, OnHMILevelChanged(_, _, _)); + EXPECT_CALL(app_manager_mock_, OnHMIStateChanged(_, _, _)); state_ctrl_->OnApplicationRegistered(simple_app_, mobile_apis::HMILevel::HMI_BACKGROUND); @@ -3368,7 +3361,7 @@ TEST_F(StateControllerImplTest, OnApplicationRegisteredEqualStates) { EXPECT_CALL(*simple_app_ptr_, ResetDataInNone()).Times(0); EXPECT_CALL(app_manager_mock_, SendHMIStatusNotification(_)).Times(0); - EXPECT_CALL(app_manager_mock_, OnHMILevelChanged(_, _, _)).Times(0); + EXPECT_CALL(app_manager_mock_, OnHMIStateChanged(_, _, _)).Times(0); state_ctrl_->OnApplicationRegistered(simple_app_, mobile_apis::HMILevel::HMI_BACKGROUND); @@ -3688,7 +3681,7 @@ TEST_F(StateControllerImplTest, .WillOnce(Return(expected_state)); EXPECT_CALL(message_helper_mock_, SendHMIStatusNotification(simple_app_, kCustomWindowId, _)); - EXPECT_CALL(app_manager_mock_, OnHMILevelChanged(_, _, _)).Times(0); + EXPECT_CALL(app_manager_mock_, OnHMIStateChanged(_, _, _)).Times(0); state_ctrl_->OnAppWindowAdded(simple_app_, kCustomWindowId, diff --git a/src/components/include/application_manager/application_manager.h b/src/components/include/application_manager/application_manager.h index 6d5c7607cc..04b5049c3d 100644 --- a/src/components/include/application_manager/application_manager.h +++ b/src/components/include/application_manager/application_manager.h @@ -286,17 +286,17 @@ class ApplicationManager { virtual void set_current_audio_source(const uint32_t source) = 0; /** - * @brief OnHMILevelChanged the callback that allows SDL to react when + * @brief OnHMIStateChanged the callback that allows SDL to react when * application's HMI level has been changed. * - * @param app_id application identifier for which HMILevel has been chaned. + * @param app_id application identifier for which HMIState has been chaned. * - * @param from previous HMILevel. - * @param to current HMILevel. + * @param from previous HMIState. + * @param to current HMIState. */ - virtual void OnHMILevelChanged(uint32_t app_id, - mobile_apis::HMILevel::eType from, - mobile_apis::HMILevel::eType to) = 0; + virtual void OnHMIStateChanged(const uint32_t app_id, + const HmiStatePtr from, + const HmiStatePtr to) = 0; /** * @brief Updates streaming service status for specified session and notifies @@ -619,12 +619,13 @@ class ApplicationManager { mobile_api::AppInterfaceUnregisteredReason::eType reason) = 0; /** - * @brief Checks HMI level and returns true if streaming is allowed + * @brief Checks application HMI state and returns true if streaming is + * allowed * @param app_id Application id * @param service_type Service type to check * @return True if streaming is allowed, false in other case */ - virtual bool HMILevelAllowsStreaming( + virtual bool HMIStateAllowsStreaming( uint32_t app_id, protocol_handler::ServiceType service_type) const = 0; /** diff --git a/src/components/include/test/application_manager/mock_application_manager.h b/src/components/include/test/application_manager/mock_application_manager.h index 92677b12bb..e5706c2003 100644 --- a/src/components/include/test/application_manager/mock_application_manager.h +++ b/src/components/include/test/application_manager/mock_application_manager.h @@ -139,10 +139,10 @@ class MockApplicationManager : public application_manager::ApplicationManager { MOCK_METHOD1(application_id, uint32_t(const int32_t correlation_id)); MOCK_METHOD2(set_application_id, void(const int32_t correlation_id, const uint32_t app_id)); - MOCK_METHOD3(OnHMILevelChanged, - void(uint32_t app_id, - mobile_apis::HMILevel::eType from, - mobile_apis::HMILevel::eType to)); + MOCK_METHOD3(OnHMIStateChanged, + void(const uint32_t app_id, + const application_manager::HmiStatePtr from, + const application_manager::HmiStatePtr to)); MOCK_METHOD3(ProcessOnDataStreamingNotification, void(const protocol_handler::ServiceType service_type, const uint32_t app_id, @@ -260,7 +260,7 @@ class MockApplicationManager : public application_manager::ApplicationManager { void(mobile_apis::AppInterfaceUnregisteredReason::eType reason)); MOCK_METHOD1(HeadUnitReset, void(mobile_apis::AppInterfaceUnregisteredReason::eType reason)); - MOCK_CONST_METHOD2(HMILevelAllowsStreaming, + MOCK_CONST_METHOD2(HMIStateAllowsStreaming, bool(uint32_t app_id, protocol_handler::ServiceType service_type)); MOCK_METHOD5(CheckPolicyPermissions, -- cgit v1.2.1