From a0d9827e1ac5a16f2905cb93066cc52fcb20490e Mon Sep 17 00:00:00 2001 From: Andriy Byzhynar Date: Thu, 11 Jul 2019 17:59:41 +0300 Subject: Implement StateController changes Implemented changes in State Controller Fixed related dependencies Fixed unit tests --- .../application_manager/state_controller_impl.h | 232 +++--- .../hmi/on_exit_application_notification.cc | 7 +- .../commands/hmi/on_system_context_notification.cc | 9 +- .../src/commands/hmi/on_vr_command_notification.cc | 5 +- .../hmi/on_vr_language_change_notification.cc | 5 +- .../commands/mobile/close_application_request.cc | 1 + .../test/commands/hmi/hmi_notifications_test.cc | 32 +- .../src/application_manager_impl.cc | 20 +- .../application_manager/src/hmi_state.cc | 33 +- .../src/policies/policy_handler.cc | 45 +- .../src/resumption/resume_ctrl_impl.cc | 4 +- .../src/state_controller_impl.cc | 351 +++++++-- .../test/policy_handler_test.cc | 1 + .../test/resumption/resume_ctrl_test.cc | 53 +- .../test/state_controller/state_controller_test.cc | 841 ++++++++++++++++----- .../application_manager/application_manager.h | 10 +- .../include/application_manager/state_controller.h | 128 +++- .../application_manager/mock_state_controller.h | 41 +- 18 files changed, 1340 insertions(+), 478 deletions(-) diff --git a/src/components/application_manager/include/application_manager/state_controller_impl.h b/src/components/application_manager/include/application_manager/state_controller_impl.h index 77da28cc91..000569e450 100644 --- a/src/components/application_manager/include/application_manager/state_controller_impl.h +++ b/src/components/application_manager/include/application_manager/state_controller_impl.h @@ -52,138 +52,79 @@ class StateControllerImpl : public event_engine::EventObserver, public: explicit StateControllerImpl(ApplicationManager& app_mngr); - /** - * @brief SetRegularState setup regular hmi state, that will appear if - * no specific events are active - * @param app appication to setup regular State - * @param state state of new regular state - */ - - virtual void SetRegularState(ApplicationSharedPtr app, - HmiStatePtr state, - const bool SendActivateApp); - - /** - * @brief SetRegularState Change regular hmi level and audio state - * @param app appication to setup regular State - * @param hmi_level of new regular state - * @param audio_state of new regular state - * @paran video_state of new regular state - * @param SendActivateApp: if true, ActivateAppRequest will be sent on HMI */ + void SetRegularState(ApplicationSharedPtr app, + const WindowID window_id, + HmiStatePtr state, + const bool SendActivateApp) OVERRIDE; - virtual void SetRegularState( + void 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 SendActivateApp); - - /** - * @brief SetRegularState Change regular hmi level - * @param app appication to setup regular State - * @param hmi_level of new regular state - * @param SendActivateApp: if true, ActivateAppRequest will be sent on HMI - */ - virtual void SetRegularState(ApplicationSharedPtr app, - const mobile_apis::HMILevel::eType hmi_level, - const bool SendActivateApp); + const bool SendActivateApp) OVERRIDE; - /** - * @brief SetRegularState Change regular hmi level, audio state and system - * context - * @param app appication to setup regular State - * @param hmi_level of new regular state - * @param audio_state of new regular state - * @param video_state of new regular state - * @param system_context of new regular state - * @param SendActivateApp: if true, ActivateAppRequest will be sent on HMI */ + void SetRegularState(ApplicationSharedPtr app, + const WindowID window_id, + const mobile_apis::HMILevel::eType hmi_level, + const bool SendActivateApp) OVERRIDE; - virtual void SetRegularState( + void 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 mobile_apis::SystemContext::eType system_context, - const bool SendActivateApp); + const bool SendActivateApp) OVERRIDE; - /** - * @brief SetRegularState Sets regular state with new hmi level - * to application - * @param app appication to setup regular state - * @param hmi_level new hmi level for application - */ - virtual void SetRegularState(ApplicationSharedPtr app, - const mobile_apis::HMILevel::eType hmi_level); + void SetRegularState(ApplicationSharedPtr app, + const WindowID window_id, + const mobile_apis::HMILevel::eType hmi_level) OVERRIDE; - /** - * @brief SetRegularState Change regular audio state - * @param app appication to setup regular State - * @param audio_state of new regular state - * @param video_state of new regular state - */ - virtual void SetRegularState( + void SetRegularState( ApplicationSharedPtr app, + const WindowID window_id, const mobile_apis::AudioStreamingState::eType audio_state, - const mobile_apis::VideoStreamingState::eType video_state); + const mobile_apis::VideoStreamingState::eType video_state) OVERRIDE; - /** - * @brief SetRegularState Change regular system context - * @param app appication to setup regular State - * @param system_context of new regular state - */ - virtual void SetRegularState( + void SetRegularState( ApplicationSharedPtr app, - const mobile_apis::SystemContext::eType system_context); + const WindowID window_id, + const mobile_apis::SystemContext::eType system_context) OVERRIDE; - /** - * @brief SetRegularState Sets new regular state to application - * @param app appication to setup regular state - * @param state new hmi state for application - */ - virtual void SetRegularState(ApplicationSharedPtr app, HmiStatePtr state); + void SetRegularState(ApplicationSharedPtr app, + const WindowID window_id, + HmiStatePtr state) OVERRIDE; - // EventObserver interface - void on_event(const event_engine::Event& event); - void on_event(const event_engine::MobileEvent& event); + void OnApplicationRegistered( + ApplicationSharedPtr app, + const mobile_apis::HMILevel::eType default_level) OVERRIDE; - /** - * @brief Sets default application state and apply currently active HMI states - * on application registration - * @param app application to apply states - * @param default_level default HMI level - */ - virtual void OnApplicationRegistered( + void OnAppWindowAdded( ApplicationSharedPtr app, - const mobile_apis::HMILevel::eType default_level); + const WindowID window_id, + const mobile_apis::WindowType::eType window_type, + const mobile_apis::HMILevel::eType default_level) OVERRIDE; - /** - * @brief OnVideoStreamingStarted process video streaming started - * @param app projection or navigation application starting streaming - */ - virtual void OnVideoStreamingStarted(ApplicationConstSharedPtr app); + void OnVideoStreamingStarted(ApplicationConstSharedPtr app) OVERRIDE; - /** - * @brief OnVideoStreamingStopped process video streaming stopped - * @param app projection or navigation application stopping streaming - */ - virtual void OnVideoStreamingStopped(ApplicationConstSharedPtr app); + void OnVideoStreamingStopped(ApplicationConstSharedPtr app) OVERRIDE; - /** - * @brief OnStateChanged send HMIStatusNotification if needed - * @param app application - * @param old_state state before change - * @param new_state state after change - */ - virtual void OnStateChanged(ApplicationSharedPtr app, - HmiStatePtr old_state, - HmiStatePtr new_state); + void OnStateChanged(ApplicationSharedPtr app, + const WindowID window_id, + HmiStatePtr old_state, + HmiStatePtr new_state) OVERRIDE; - /** - * @brief Checks activity of Deactivate HMI state. - * @return Returns TRUE if deactivate HMI state is active, otherwise returns - * FALSE. - */ - virtual bool IsStateActive(HmiState::StateID state_id) const; + bool IsStateActive(HmiState::StateID state_id) const OVERRIDE; + + // EventObserver interface + void on_event(const event_engine::Event& event) OVERRIDE; + void on_event(const event_engine::MobileEvent& event) OVERRIDE; + + void ActivateDefaultWindow(ApplicationSharedPtr app) OVERRIDE; + void ExitDefaultWindow(ApplicationSharedPtr app) OVERRIDE; private: int64_t RequestHMIStateChange(ApplicationConstSharedPtr app, @@ -195,12 +136,17 @@ class StateControllerImpl : public event_engine::EventObserver, */ struct HmiLevelConflictResolver { const ApplicationSharedPtr applied_; + const WindowID window_id_; const HmiStatePtr state_; StateControllerImpl* state_ctrl_; HmiLevelConflictResolver(const ApplicationSharedPtr app, + const WindowID window_id, const HmiStatePtr state, StateControllerImpl* state_ctrl) - : applied_(app), state_(state), state_ctrl_(state_ctrl) {} + : applied_(app) + , window_id_(window_id) + , state_(state) + , state_ctrl_(state_ctrl) {} void operator()(ApplicationSharedPtr to_resolve); }; @@ -298,14 +244,19 @@ class StateControllerImpl : public event_engine::EventObserver, template void HMIStateStarted(ApplicationSharedPtr app) { DCHECK_OR_RETURN_VOID(app); - HmiStatePtr old_hmi_state = app->CurrentHmiState(); - HmiStatePtr new_hmi_state = CreateHmiState(app, ID); - DCHECK_OR_RETURN_VOID(new_hmi_state); - DCHECK_OR_RETURN_VOID(new_hmi_state->state_id() != - HmiState::STATE_ID_REGULAR); - new_hmi_state->set_parent(old_hmi_state); - app->AddHMIState(new_hmi_state); - OnStateChanged(app, old_hmi_state, new_hmi_state); + const WindowIds window_ids = app->GetWindowIds(); + + for (auto window_id : window_ids) { + HmiStatePtr old_hmi_state = app->CurrentHmiState(window_id); + HmiStatePtr new_hmi_state = CreateHmiState(app, ID); + DCHECK_OR_RETURN_VOID(new_hmi_state); + DCHECK_OR_RETURN_VOID(new_hmi_state->state_id() != + HmiState::STATE_ID_REGULAR); + new_hmi_state->set_parent(old_hmi_state); + new_hmi_state->set_window_type(old_hmi_state->window_type()); + app->AddHMIState(window_id, new_hmi_state); + OnStateChanged(app, window_id, old_hmi_state, new_hmi_state); + } } /** @@ -326,7 +277,7 @@ class StateControllerImpl : public event_engine::EventObserver, * depends on application type * @param app Application to deactivate */ - void DeactivateApp(ApplicationSharedPtr app); + void DeactivateApp(ApplicationSharedPtr app, const WindowID window_id); /** * Function to remove temporary HmiState for application @@ -334,45 +285,68 @@ class StateControllerImpl : public event_engine::EventObserver, template void HMIStateStopped(ApplicationSharedPtr app) { DCHECK_OR_RETURN_VOID(app); - HmiStatePtr cur = app->CurrentHmiState(); - HmiStatePtr old_hmi_state = - CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); - DCHECK_OR_RETURN_VOID(old_hmi_state); - old_hmi_state->set_hmi_level(cur->hmi_level()); - old_hmi_state->set_audio_streaming_state(cur->audio_streaming_state()); - old_hmi_state->set_video_streaming_state(cur->video_streaming_state()); - old_hmi_state->set_system_context(cur->system_context()); - app->RemoveHMIState(ID); - HmiStatePtr new_hmi_state = app->CurrentHmiState(); - OnStateChanged(app, old_hmi_state, new_hmi_state); + const WindowIds window_ids = app->GetWindowIds(); + + for (auto window_id : window_ids) { + HmiStatePtr cur = app->CurrentHmiState(window_id); + HmiStatePtr old_hmi_state = + CreateHmiState(app, HmiState::StateID::STATE_ID_REGULAR); + DCHECK_OR_RETURN_VOID(old_hmi_state); + old_hmi_state->set_hmi_level(cur->hmi_level()); + old_hmi_state->set_window_type(cur->window_type()); + old_hmi_state->set_audio_streaming_state(cur->audio_streaming_state()); + old_hmi_state->set_video_streaming_state(cur->video_streaming_state()); + old_hmi_state->set_system_context(cur->system_context()); + app->RemoveHMIState(window_id, ID); + HmiStatePtr new_hmi_state = app->CurrentHmiState(window_id); + OnStateChanged(app, window_id, old_hmi_state, new_hmi_state); + } } /** * @brief ApplyRegularState setup regular hmi state, that will appear if no * specific events are active, without sending ActivateApp * @param app appication to setup default State + * @param window_id id of applicaion's window to apply HMI state * @param state state of new defailt state */ - void ApplyRegularState(ApplicationSharedPtr app, HmiStatePtr state); + void ApplyRegularState(ApplicationSharedPtr app, + const WindowID window_id, + HmiStatePtr state); + + /** + * @brief UpdateAppWindowsStreamingState updates all application windows + * audio/video streaming state according to a new HMI state of the main window + * @param app pointer to affected application + * @param state pointer to state with the new streaming state of the main + * window + */ + void UpdateAppWindowsStreamingState(ApplicationSharedPtr app, + HmiStatePtr state); /** * @brief SetupRegularHmiState set regular HMI State without * resolving conflicts and ActivateApp request * @param app application + * @param window_id id of applicaion's window to apply HMI state * @param state hmi_state to setup */ - void SetupRegularHmiState(ApplicationSharedPtr app, HmiStatePtr state); + void SetupRegularHmiState(ApplicationSharedPtr app, + const WindowID window_id, + HmiStatePtr state); /** * @brief SetupRegularHmiState set regular HMI State without * resolving conflicts and ActivateApp request * @param app application + * @param window_id id of applicaion's window to apply HMI state * @param hmi_level of new regular state * @param audio_state of new regular state * @param video_state of new regular state */ void 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); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_exit_application_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_exit_application_notification.cc index 11647e2140..3eec6c5d1a 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_exit_application_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_exit_application_notification.cc @@ -119,12 +119,7 @@ void OnExitApplicationNotification::Run() { } } - application_manager_.state_controller().SetRegularState( - app_impl, - HMILevel::HMI_NONE, - AudioStreamingState::NOT_AUDIBLE, - VideoStreamingState::NOT_STREAMABLE, - false); + application_manager_.state_controller().ExitDefaultWindow(app_impl); } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_context_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_context_notification.cc index 38b87f23d3..055093384d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_context_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_system_context_notification.cc @@ -76,8 +76,13 @@ void OnSystemContextNotification::Run() { } if (app && mobile_api::SystemContext::INVALID_ENUM != system_context) { - application_manager_.state_controller().SetRegularState(app, - system_context); + 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].asUInt(); + } + + application_manager_.state_controller().SetRegularState( + app, window_id, system_context); } else { LOG4CXX_ERROR(logger_, "Application does not exist"); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_command_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_command_notification.cc index 7680b74426..19b4047b1b 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_command_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_command_notification.cc @@ -72,7 +72,10 @@ void OnVRCommandNotification::Run() { ApplicationSharedPtr app = application_manager_.application(app_id); if (app) { application_manager_.state_controller().SetRegularState( - app, mobile_apis::HMILevel::HMI_FULL, true); + app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + mobile_apis::HMILevel::HMI_FULL, + true); } else { LOG4CXX_ERROR(logger_, "Unable to find appication " << app_id); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_language_change_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_language_change_notification.cc index 55c6eb8881..c308af9b92 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_language_change_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_vr_language_change_notification.cc @@ -83,7 +83,10 @@ void OnVRLanguageChangeNotification::Run() { if (static_cast(app->language()) != (*message_)[strings::msg_params][strings::language].asInt()) { application_manager_.state_controller().SetRegularState( - app, mobile_api::HMILevel::HMI_NONE, false); + app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + mobile_apis::HMILevel::HMI_NONE, + false); rpc_service_.ManageMobileCommand( MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/close_application_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/close_application_request.cc index 736f0355dc..275f1d82a6 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/close_application_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/close_application_request.cc @@ -101,6 +101,7 @@ void CloseApplicationRequest::on_event(const event_engine::Event& event) { application_manager_.GetPluginManager().ForEachPlugin(on_app_exit); application_manager_.state_controller().SetRegularState( app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, mobile_apis::HMILevel::HMI_NONE, mobile_apis::AudioStreamingState::NOT_AUDIBLE, mobile_apis::VideoStreamingState::NOT_STREAMABLE, diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc index cda1f56444..26f7a63872 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc @@ -148,6 +148,11 @@ typedef NiceMock< #define NAVI true #define NOT_NAVI false +namespace { +const am::WindowID kDefaultWindowId = + mobile_apis::PredefinedWindows::DEFAULT_WINDOW; +} + ACTION_P(GetEventId, event_id) { *event_id = arg0.id(); } @@ -155,8 +160,8 @@ ACTION_P(GetArg, arg) { *arg = arg0; } -ACTION_P(GetArg3, result) { - arg3 = *result; +ACTION_P(GetArg4, result) { + arg4 = *result; } ACTION_P2(GetConnectIdPermissionConsent, connect_id, consent) { @@ -1103,6 +1108,7 @@ TEST_F(HMICommandsNotificationsTest, .WillOnce(ReturnRef(mock_state_controller_)); EXPECT_CALL(mock_state_controller_, SetRegularState(app_, + kDefaultWindowId, mobile_apis::HMILevel::HMI_NONE, mobile_apis::AudioStreamingState::NOT_AUDIBLE, mobile_apis::VideoStreamingState::NOT_STREAMABLE, @@ -1127,12 +1133,7 @@ TEST_F(HMICommandsNotificationsTest, EXPECT_CALL(app_mngr_, UnregisterApplication(_, _, _, _)).Times(0); EXPECT_CALL(app_mngr_, state_controller()) .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, - SetRegularState(app_, - mobile_apis::HMILevel::HMI_NONE, - mobile_apis::AudioStreamingState::NOT_AUDIBLE, - mobile_apis::VideoStreamingState::NOT_STREAMABLE, - false)); + EXPECT_CALL(mock_state_controller_, ExitDefaultWindow(app_)); command->Run(); } @@ -1150,7 +1151,8 @@ TEST_F(HMICommandsNotificationsTest, EXPECT_CALL(app_mngr_, state_controller()) .WillOnce(ReturnRef(mock_state_controller_)); EXPECT_CALL(mock_state_controller_, - SetRegularState(_, mobile_apis::HMILevel::HMI_FULL, true)); + SetRegularState( + _, kDefaultWindowId, mobile_apis::HMILevel::HMI_FULL, true)); EXPECT_CALL(app_mngr_, get_settings()) .WillOnce(ReturnRef(app_mngr_settings_)); @@ -1351,8 +1353,10 @@ TEST_F(HMICommandsNotificationsTest, EXPECT_CALL(*app_ptr_, language()).WillRepeatedly(ReturnRef(kLang)); EXPECT_CALL(app_mngr_, state_controller()) .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, - SetRegularState(app_, mobile_apis::HMILevel::HMI_NONE, false)); + EXPECT_CALL( + mock_state_controller_, + SetRegularState( + app_, kDefaultWindowId, mobile_apis::HMILevel::HMI_NONE, false)); EXPECT_CALL(mock_message_helper_, GetOnAppInterfaceUnregisteredNotificationToMobile( kAppId_, @@ -1429,7 +1433,8 @@ TEST_F(HMICommandsNotificationsTest, EXPECT_CALL(app_mngr_, active_application()).WillOnce(Return(app_)); EXPECT_CALL(app_mngr_, state_controller()) .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, SetRegularState(app_, *it)); + EXPECT_CALL(mock_state_controller_, + SetRegularState(app_, kDefaultWindowId, *it)); command->Run(); } } @@ -1478,7 +1483,8 @@ TEST_F(HMICommandsNotificationsTest, EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(app_)); EXPECT_CALL(app_mngr_, state_controller()) .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, SetRegularState(app_, *it)); + EXPECT_CALL(mock_state_controller_, + SetRegularState(app_, kDefaultWindowId, *it)); command->Run(); } } diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 4cc8fdceda..6451de2a33 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -744,18 +744,15 @@ bool ApplicationManagerImpl::ActivateApplication(ApplicationSharedPtr app) { LOG4CXX_DEBUG(logger_, "Activating application with id:" << app->app_id()); - // remove from resumption if app was activated by user + // Remove from resumption if app was activated by user resume_controller().OnAppActivated(app); + // Activate any app services published by the app GetAppServiceManager().OnAppActivated(app); - 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; - state_ctrl_.SetRegularState(app, hmi_level, audio_state, video_state, false); + + // Activate main window in state controller + state_ctrl_.ActivateDefaultWindow(app); + return true; } @@ -3828,7 +3825,10 @@ void ApplicationManagerImpl::OnUpdateHMIAppType( (app_hmi_level == mobile_api::HMILevel::HMI_LIMITED)) { MessageHelper::SendUIChangeRegistrationRequestToHMI(*it, *this); state_controller().SetRegularState( - *it, mobile_apis::HMILevel::HMI_BACKGROUND, true); + *it, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + mobile_apis::HMILevel::HMI_BACKGROUND, + true); } } } diff --git a/src/components/application_manager/src/hmi_state.cc b/src/components/application_manager/src/hmi_state.cc index ff689408f1..844d0254cf 100644 --- a/src/components/application_manager/src/hmi_state.cc +++ b/src/components/application_manager/src/hmi_state.cc @@ -184,17 +184,25 @@ PhoneCallHmiState::PhoneCallHmiState(std::shared_ptr app, mobile_apis::HMILevel::eType PhoneCallHmiState::hmi_level() const { using namespace helpers; using namespace mobile_apis; + + if (WindowType::WIDGET == window_type()) { + return parent()->hmi_level(); + } + if (Compare(parent()->hmi_level(), HMILevel::HMI_BACKGROUND, HMILevel::HMI_NONE)) { return parent()->hmi_level(); } + if (is_navi_app() || is_mobile_projection_app()) { return HMILevel::HMI_LIMITED; } + if (!is_media_app()) { return parent()->hmi_level(); } + return HMILevel::HMI_BACKGROUND; } @@ -209,6 +217,11 @@ DeactivateHMI::DeactivateHMI(std::shared_ptr app, mobile_apis::HMILevel::eType DeactivateHMI::hmi_level() const { using namespace helpers; using namespace mobile_apis; + + if (WindowType::WIDGET == window_type()) { + return parent()->hmi_level(); + } + if (Compare(parent()->hmi_level(), HMILevel::HMI_BACKGROUND, HMILevel::HMI_NONE)) { @@ -226,14 +239,19 @@ AudioSource::AudioSource(std::shared_ptr app, } mobile_apis::HMILevel::eType AudioSource::hmi_level() const { + using namespace mobile_apis; + + if (WindowType::WIDGET == window_type()) { + return parent()->hmi_level(); + } + // Checking for NONE is necessary to avoid issue during // calculation of HMI level during setting default HMI level - if (keep_context_ || - mobile_apis::HMILevel::HMI_NONE == parent()->hmi_level()) { + if (keep_context_ || HMILevel::HMI_NONE == parent()->hmi_level()) { return parent()->hmi_level(); } - return mobile_apis::HMILevel::HMI_BACKGROUND; + return HMILevel::HMI_BACKGROUND; } EmbeddedNavi::EmbeddedNavi(std::shared_ptr app, @@ -243,11 +261,17 @@ EmbeddedNavi::EmbeddedNavi(std::shared_ptr app, mobile_apis::HMILevel::eType EmbeddedNavi::hmi_level() const { using namespace mobile_apis; using namespace helpers; + + if (WindowType::WIDGET == window_type()) { + return parent()->hmi_level(); + } + if (Compare(parent()->hmi_level(), HMILevel::HMI_BACKGROUND, HMILevel::HMI_NONE)) { return parent()->hmi_level(); } + return HMILevel::HMI_BACKGROUND; } @@ -289,7 +313,8 @@ std::ostream& operator<<(std::ostream& os, const HmiState& src) { } else { os << "(none)"; } - os << ", hmi app id:" << src.hmi_app_id_ << ", state:" << src.state_id() + os << ", hmi app id:" << src.hmi_app_id_ + << ", window_type:" << src.window_type_ << ", state:" << src.state_id() << ", hmi_level:" << src.hmi_level() << ", audio:" << src.audio_streaming_state() << ", video:" << src.video_streaming_state() diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index b4a96f73e7..39be0d08d3 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -168,6 +168,7 @@ struct DeactivateApplication { if (device_id_ == app->device()) { state_ctrl_.SetRegularState( app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, mobile_apis::HMILevel::HMI_NONE, mobile_apis::AudioStreamingState::NOT_AUDIBLE, mobile_apis::VideoStreamingState::NOT_STREAMABLE, @@ -881,6 +882,9 @@ std::string PolicyHandler::OnCurrentDeviceIdUpdateRequired( "not found within registered applications."); return std::string(); } + DeviceParams device_params = GetDeviceParams( + app->device(), + application_manager_.connection_handler().get_session_observer()); return device_params.device_mac_address; } @@ -962,6 +966,7 @@ void PolicyHandler::OnPendingPermissionChange( app_id, permissions, application_manager_); application_manager_.state_controller().SetRegularState( app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, mobile_apis::HMILevel::HMI_NONE, mobile_apis::AudioStreamingState::NOT_AUDIBLE, mobile_apis::VideoStreamingState::NOT_STREAMABLE, @@ -1126,7 +1131,11 @@ struct SDLAlowedNotification { } else { return; } - state_controller_.SetRegularState(app, default_mobile_hmi, true); + state_controller_.SetRegularState( + app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + default_mobile_hmi, + true); } } @@ -1235,7 +1244,12 @@ void PolicyHandler::OnAllowSDLFunctionalityNotification( : VideoStreamingState::NOT_STREAMABLE; application_manager_.state_controller().SetRegularState( - app, mobile_apis::HMILevel::HMI_FULL, audio_state, video_state, true); + app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + mobile_apis::HMILevel::HMI_FULL, + audio_state, + video_state, + true); last_activated_app_id_ = 0; } else { DeactivateApplication deactivate_notification( @@ -1383,12 +1397,19 @@ void PolicyHandler::OnPermissionsUpdated(const std::string& device_id, << policy_app_id << " to default hmi level " << default_hmi); - const bool is_full_hmi_level = - mobile_apis::HMILevel::HMI_FULL == hmi_level; - - application_manager_.state_controller().SetRegularState( - app, hmi_level, is_full_hmi_level); - + if (hmi_level == mobile_apis::HMILevel::HMI_FULL) { + application_manager_.state_controller().SetRegularState( + app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + hmi_level, + true); + } else { + application_manager_.state_controller().SetRegularState( + app, + mobile_apis::PredefinedWindows::DEFAULT_WINDOW, + hmi_level, + false); + } break; } default: @@ -1520,9 +1541,13 @@ void PolicyHandler::CheckPermissions( "Checking permissions for " << app->policy_app_id() << " in " << hmi_level << " on device " << device_id << " rpc " << rpc); - +#ifdef EXTERNAL_PROPRIETARY_MODE + policy_manager_->CheckPermissions( + app->policy_app_id(), hmi_level, rpc, rpc_params, result); +#else // EXTERNAL_PROPRIETARY_MODE policy_manager_->CheckPermissions( device_id, app->policy_app_id(), hmi_level, rpc, rpc_params, result); +#endif // EXTERNAL_PROPRIETARY_MODE } uint32_t PolicyHandler::GetNotificationsNumber( @@ -2249,6 +2274,8 @@ bool PolicyHandler::IsUrlAppIdValid(const uint32_t app_idx, const EndpointUrls& urls) const { const EndpointData& app_data = urls[app_idx]; const std::vector app_urls = app_data.url; + const ApplicationSharedPtr app = + application_manager_.application_by_policy_id(app_data.app_id); if (policy::kDefaultId == app_data.app_id) { return true; diff --git a/src/components/application_manager/src/resumption/resume_ctrl_impl.cc b/src/components/application_manager/src/resumption/resume_ctrl_impl.cc index fff1aefed3..bb796e8267 100644 --- a/src/components/application_manager/src/resumption/resume_ctrl_impl.cc +++ b/src/components/application_manager/src/resumption/resume_ctrl_impl.cc @@ -292,8 +292,8 @@ bool ResumeCtrlImpl::SetAppHMIState( return false; } application->set_is_resuming(true); - application_manager_.state_controller().SetRegularState(application, - hmi_level); + application_manager_.state_controller().SetRegularState( + application, mobile_apis::PredefinedWindows::DEFAULT_WINDOW, hmi_level); LOG4CXX_INFO(logger_, "Application with policy id " << application->policy_app_id() << " got HMI level " << hmi_level); diff --git a/src/components/application_manager/src/state_controller_impl.cc b/src/components/application_manager/src/state_controller_impl.cc index 994c7b8b7f..b8f9dcf31a 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( @@ -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,9 +616,11 @@ 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"); @@ -593,18 +628,19 @@ void StateControllerImpl::SetupRegularHmiState(ApplicationSharedPtr app, } 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 +649,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 +809,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 +895,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 +922,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 +936,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 +978,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 +1014,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(*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 +1052,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 +1068,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 +1086,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].asUInt(); + } + + 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 +1127,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].asUInt(); + } + + 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( diff --git a/src/components/application_manager/test/policy_handler_test.cc b/src/components/application_manager/test/policy_handler_test.cc index aa140dfa49..7a1a2e8fee 100644 --- a/src/components/application_manager/test/policy_handler_test.cc +++ b/src/components/application_manager/test/policy_handler_test.cc @@ -1024,6 +1024,7 @@ TEST_F(PolicyHandlerTest, OnPendingPermissionChange_AppLimitedAndRevoked) { SendOnAppPermissionsChangedNotification(kAppId1_, _, _)); EXPECT_CALL(mock_state_controller, SetRegularState(_, + kDefaultWindowId, mobile_apis::HMILevel::HMI_NONE, mobile_apis::AudioStreamingState::NOT_AUDIBLE, mobile_apis::VideoStreamingState::NOT_STREAMABLE, diff --git a/src/components/application_manager/test/resumption/resume_ctrl_test.cc b/src/components/application_manager/test/resumption/resume_ctrl_test.cc index a82358b451..19c688c9b4 100644 --- a/src/components/application_manager/test/resumption/resume_ctrl_test.cc +++ b/src/components/application_manager/test/resumption/resume_ctrl_test.cc @@ -73,6 +73,11 @@ using namespace application_manager_test; using namespace resumption; using namespace mobile_apis::HMILevel; +namespace { +const WindowID kDefaultWindowId = + mobile_apis::PredefinedWindows::DEFAULT_WINDOW; +} + class ResumeCtrlTest : public ::testing::Test { protected: ResumeCtrlTest() @@ -572,7 +577,8 @@ TEST_F(ResumeCtrlTest, StartResumption_AppWithSubscriptionToWayPoints) { mobile_apis::HMILevel::HMI_FULL; ON_CALL(mock_app_mngr_, GetDefaultHmiLevel(const_app_)) .WillByDefault(Return(hmi_test_level)); - EXPECT_CALL(mock_state_controller_, SetRegularState(_, hmi_test_level)); + EXPECT_CALL(mock_state_controller_, + SetRegularState(_, kDefaultWindowId, hmi_test_level)); const bool result = res_ctrl_->StartResumption(mock_app_, kHash_); EXPECT_TRUE(result); @@ -632,7 +638,8 @@ TEST_F(ResumeCtrlTest, StartAppHmiStateResumption_AppInFull) { DataAccessor data_accessor( command, app_set_lock_ptr_); - EXPECT_CALL(mock_state_controller_, SetRegularState(_, restored_test_type)) + EXPECT_CALL(mock_state_controller_, + SetRegularState(_, kDefaultWindowId, restored_test_type)) .Times(AtLeast(1)); GetInfoFromApp(); EXPECT_CALL(mock_app_mngr_, GetDefaultHmiLevel(const_app_)) @@ -681,7 +688,8 @@ TEST_F(ResumeCtrlTest, StartAppHmiStateResumption_AppHasDeferredResumption) { saved_app[application_manager::strings::time_stamp] = time_stamp; // resume into deferred level instead of restored level - EXPECT_CALL(mock_state_controller_, SetRegularState(_, deferred_level)) + EXPECT_CALL(mock_state_controller_, + SetRegularState(_, kDefaultWindowId, deferred_level)) .Times(AtLeast(1)); GetInfoFromApp(); ON_CALL(*mock_storage_, @@ -716,7 +724,8 @@ TEST_F(ResumeCtrlTest, saved_app[application_manager::strings::hmi_level] = restored_test_type; saved_app[application_manager::strings::time_stamp] = time_stamp; - EXPECT_CALL(mock_state_controller_, SetRegularState(_, eType::HMI_LIMITED)) + EXPECT_CALL(mock_state_controller_, + SetRegularState(_, kDefaultWindowId, eType::HMI_LIMITED)) .Times(AtLeast(1)); GetInfoFromApp(); ON_CALL(*mock_storage_, @@ -760,7 +769,8 @@ TEST_F( // in this test, it is expected that the app will resume into LIMITED, which // is the higher level among NONE and LIMITED - EXPECT_CALL(mock_state_controller_, SetRegularState(_, eType::HMI_LIMITED)) + EXPECT_CALL(mock_state_controller_, + SetRegularState(_, kDefaultWindowId, eType::HMI_LIMITED)) .Times(AtLeast(1)); GetInfoFromApp(); ON_CALL(*mock_storage_, @@ -816,7 +826,8 @@ TEST_F(ResumeCtrlTest, RestoreAppHMIState_RestoreHMILevelFull) { saved_app[application_manager::strings::grammar_id] = kTestGrammarId_; saved_app[application_manager::strings::hmi_level] = restored_test_type; - EXPECT_CALL(mock_state_controller_, SetRegularState(_, restored_test_type)) + EXPECT_CALL(mock_state_controller_, + SetRegularState(_, kDefaultWindowId, restored_test_type)) .Times(AtLeast(1)); GetInfoFromApp(); EXPECT_CALL(mock_app_mngr_, GetDefaultHmiLevel(const_app_)) @@ -847,7 +858,8 @@ TEST_F(ResumeCtrlTest, SetupDefaultHMILevel) { ON_CALL(mock_app_mngr_, GetDefaultHmiLevel(const_app_)) .WillByDefault(Return(kDefaultTestLevel_)); - EXPECT_CALL(mock_state_controller_, SetRegularState(_, kDefaultTestLevel_)) + EXPECT_CALL(mock_state_controller_, + SetRegularState(_, kDefaultWindowId, kDefaultTestLevel_)) .Times(AtLeast(1)); res_ctrl_->SetupDefaultHMILevel(mock_app_); @@ -876,7 +888,8 @@ TEST_F(ResumeCtrlTest, EXPECT_CALL(*mock_app_, is_media_application()).WillRepeatedly(Return(false)); // SetRegularState() should be called with kProjectionLowbandwidthLevel_ - EXPECT_CALL(mock_state_controller_, SetRegularState(_, eType::HMI_NONE)) + EXPECT_CALL(mock_state_controller_, + SetRegularState(_, kDefaultWindowId, eType::HMI_NONE)) .Times(AtLeast(1)); res_ctrl_->SetupDefaultHMILevel(mock_app_); @@ -903,7 +916,8 @@ TEST_F(ResumeCtrlTest, ApplicationResumptiOnTimer_AppInFull) { MockStateController state_controller; EXPECT_CALL(mock_app_mngr_, state_controller()) .WillOnce(ReturnRef(state_controller)); - EXPECT_CALL(state_controller, SetRegularState(_, restored_test_type)) + EXPECT_CALL(state_controller, + SetRegularState(_, kDefaultWindowId, restored_test_type)) .Times(AtLeast(1)); GetInfoFromApp(); EXPECT_CALL(mock_app_mngr_, GetDefaultHmiLevel(const_app_)) @@ -932,7 +946,8 @@ TEST_F(ResumeCtrlTest, SetAppHMIState_HMINone_WithoutCheckPolicy) { EXPECT_CALL(mock_app_mngr_, GetUserConsentForDevice("12345")).Times(0); EXPECT_CALL(*mock_app_, set_is_resuming(true)); - EXPECT_CALL(mock_state_controller_, SetRegularState(_, kDefaultTestLevel_)) + EXPECT_CALL(mock_state_controller_, + SetRegularState(_, kDefaultWindowId, kDefaultTestLevel_)) .Times(AtLeast(1)); const bool res = res_ctrl_->SetAppHMIState(mock_app_, kDefaultTestLevel_, false); @@ -945,7 +960,8 @@ TEST_F(ResumeCtrlTest, SetAppHMIState_HMILimited_WithoutCheckPolicy) { EXPECT_CALL(mock_app_mngr_, GetUserConsentForDevice("12345")).Times(0); EXPECT_CALL(*mock_app_, set_is_resuming(true)); - EXPECT_CALL(mock_state_controller_, SetRegularState(_, test_type)) + EXPECT_CALL(mock_state_controller_, + SetRegularState(_, kDefaultWindowId, test_type)) .Times(AtLeast(1)); const bool res = res_ctrl_->SetAppHMIState(mock_app_, test_type, false); EXPECT_TRUE(res); @@ -959,7 +975,8 @@ TEST_F(ResumeCtrlTest, SetAppHMIState_HMIFull_WithoutCheckPolicy) { EXPECT_CALL(mock_app_mngr_, GetUserConsentForDevice("12345")).Times(0); EXPECT_CALL(*mock_app_, set_is_resuming(true)); - EXPECT_CALL(mock_state_controller_, SetRegularState(_, test_type)) + EXPECT_CALL(mock_state_controller_, + SetRegularState(_, kDefaultWindowId, test_type)) .Times(AtLeast(1)); const bool res = res_ctrl_->SetAppHMIState(mock_app_, test_type, false); @@ -974,7 +991,8 @@ TEST_F(ResumeCtrlTest, SetAppHMIState_HMIFull_WithPolicy_DevAllowed) { .WillByDefault(Return(policy::kDeviceAllowed)); EXPECT_CALL(*mock_app_, set_is_resuming(true)); - EXPECT_CALL(mock_state_controller_, SetRegularState(_, test_type)) + EXPECT_CALL(mock_state_controller_, + SetRegularState(_, kDefaultWindowId, test_type)) .Times(AtLeast(1)); const bool res = res_ctrl_->SetAppHMIState(mock_app_, test_type, true); @@ -991,7 +1009,8 @@ TEST_F(ResumeCtrlTest, SetAppHMIState_HMIFull_WithPolicy_DevDisallowed) { EXPECT_CALL(*mock_app_, set_is_resuming(true)); ON_CALL(mock_app_mngr_, GetDefaultHmiLevel(const_app_)) .WillByDefault(Return(kDefaultTestLevel_)); - EXPECT_CALL(mock_state_controller_, SetRegularState(_, kDefaultTestLevel_)) + EXPECT_CALL(mock_state_controller_, + SetRegularState(_, kDefaultWindowId, kDefaultTestLevel_)) .Times(AtLeast(1)); const bool res = res_ctrl_->SetAppHMIState(mock_app_, test_type, true); EXPECT_FALSE(res); @@ -1246,7 +1265,8 @@ TEST_F( DataAccessor data_accessor( command, app_set_lock_ptr_); - EXPECT_CALL(mock_state_controller_, SetRegularState(_, restored_test_type)) + EXPECT_CALL(mock_state_controller_, + SetRegularState(_, kDefaultWindowId, restored_test_type)) .Times(AtLeast(1)); GetInfoFromApp(); EXPECT_CALL(mock_app_mngr_, GetDefaultHmiLevel(const_app_)) @@ -1353,7 +1373,8 @@ TEST_F( DataAccessor data_accessor( command, app_set_lock_ptr_); - EXPECT_CALL(mock_state_controller_, SetRegularState(_, restored_test_type)) + EXPECT_CALL(mock_state_controller_, + SetRegularState(_, kDefaultWindowId, restored_test_type)) .Times(AtLeast(1)); GetInfoFromApp(); EXPECT_CALL(mock_app_mngr_, GetDefaultHmiLevel(const_app_)) 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 9621e20629..0fe40366d6 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 @@ -75,10 +75,13 @@ namespace test { namespace components { namespace state_controller_test { -namespace constants { +namespace { const uint32_t kCorrID = 314u; const uint32_t kHMIAppID = 2718u; -} // namespace constants +const am::WindowID kDefaultWindowId = + mobile_apis::PredefinedWindows::DEFAULT_WINDOW; +const am::WindowID kCustomWindowId = 2; +} // namespace struct HmiStatesComparator { mobile_apis::HMILevel::eType hmi_level_; @@ -213,7 +216,11 @@ class StateControllerImplTest : public ::testing::Test { std::vector invalid_states_for_not_audio_app; std::vector invalid_states_for_audio_app; std::vector valid_state_ids_; - std::vector applications_list_; + + typedef std::map*> + AppPtrMockMapping; + AppPtrMockMapping applications_list_; connection_handler_test::MockConnectionHandlerSettings mock_connection_handler__settings; @@ -554,21 +561,26 @@ class StateControllerImplTest : public ::testing::Test { // application properties, i.e. is_media_application flag from RAI and // AppHmiTypes (NAVIGATION, etc.). Most likely logic should be changed // after conclusion on APPLINK-20231 - std::vector::iterator app = std::find_if( - applications_list_.begin(), - applications_list_.end(), - [app_id](am::ApplicationSharedPtr a) { return app_id == a->app_id(); }); - - if (app == applications_list_.end()) { + AppPtrMockMapping::iterator it = + std::find_if(applications_list_.begin(), + applications_list_.end(), + [app_id](AppPtrMockMapping::value_type& item) { + return app_id == item.first->app_id(); + }); + + if (applications_list_.end() == it) { return APP_TYPE_NON_MEDIA; } - if ((*app)->is_navi()) { + auto app = it->first; + if (app->is_navi()) { return APP_TYPE_NAVI; } - if ((*app)->is_media_application()) { + + if (app->is_media_application()) { return APP_TYPE_MEDIA; } + return APP_TYPE_NON_MEDIA; } @@ -644,17 +656,16 @@ class StateControllerImplTest : public ::testing::Test { template void TestMixState(void (StateControllerImplTest::*call_back_result)( std::vector&, ApplicationType)) { - std::vector::iterator it_begin = - applications_list_.begin(); - std::vector::iterator it_end = - applications_list_.end(); + AppPtrMockMapping::iterator it_begin = applications_list_.begin(); + AppPtrMockMapping::iterator it_end = applications_list_.end(); ApplicationType app_type; uint32_t app_id; am::ApplicationSharedPtr app; + for (; it_begin != it_end; ++it_begin) { - app_id = (*it_begin)->app_id(); + app_id = it_begin->first->app_id(); app_type = AppType(app_id); - app = (*it_begin); + app = it_begin->first; am::HmiStatePtr state_first = std::make_shared(app, app_manager_mock_); am::HmiStatePtr state_second = std::make_shared(app, app_manager_mock_); @@ -925,14 +936,14 @@ class StateControllerImplTest : public ::testing::Test { MEDIA, NAVI, VC); - applications_list_.push_back(simple_app_); - applications_list_.push_back(media_app_); - applications_list_.push_back(navi_app_); - applications_list_.push_back(vc_app_); - applications_list_.push_back(media_navi_app_); - applications_list_.push_back(media_vc_app_); - applications_list_.push_back(navi_vc_app_); - applications_list_.push_back(media_navi_vc_app_); + applications_list_[simple_app_] = simple_app_ptr_; + applications_list_[media_app_] = media_app_ptr_; + applications_list_[navi_app_] = navi_app_ptr_; + applications_list_[vc_app_] = vc_app_ptr_; + applications_list_[media_navi_app_] = media_navi_app_ptr_; + applications_list_[media_vc_app_] = media_vc_app_ptr_; + applications_list_[navi_vc_app_] = navi_vc_app_ptr_; + applications_list_[media_navi_vc_app_] = media_navi_vc_app_ptr_; } void CheckAppConfiguration() { ASSERT_EQ(simple_app_.get(), simple_app_ptr_); @@ -1044,22 +1055,36 @@ class StateControllerImplTest : public ::testing::Test { .WillByDefault(Return(true)); } - void ExpectSuccesfullSetHmiState( + void ExpectSuccessfulSetHmiState( + am::ApplicationSharedPtr app, + NiceMock* app_mock, + am::HmiStatePtr old_state, + am::HmiStatePtr new_state) { + ExpectSuccessfulSetHmiState( + app, app_mock, kDefaultWindowId, old_state, new_state); + } + + void ExpectSuccessfulSetHmiState( am::ApplicationSharedPtr app, NiceMock* app_mock, + am::WindowID window_id, am::HmiStatePtr old_state, am::HmiStatePtr new_state) { - EXPECT_CALL(*app_mock, CurrentHmiState()) + EXPECT_CALL(*app_mock, CurrentHmiState(window_id)) .WillOnce(Return(old_state)) .WillOnce(Return(new_state)); - EXPECT_CALL(*app_mock, - SetRegularState(Truly(HmiStatesComparator(new_state)))); + EXPECT_CALL( + *app_mock, + SetRegularState(window_id, Truly(HmiStatesComparator(new_state)))); if (!HmiStatesComparator(old_state)(new_state)) { - EXPECT_CALL(app_manager_mock_, SendHMIStatusNotification(app)); - EXPECT_CALL( - app_manager_mock_, - OnHMILevelChanged( - app->app_id(), old_state->hmi_level(), new_state->hmi_level())); + 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())); + } } } @@ -1068,22 +1093,33 @@ class StateControllerImplTest : public ::testing::Test { NiceMock* app_mock, am::HmiStatePtr old_state, am::HmiStatePtr new_state) { - EXPECT_CALL(*app_mock, RegularHmiState()) + EXPECT_CALL(*app_mock, RegularHmiState(kDefaultWindowId)) .WillOnce(Return(old_state)) .WillOnce(Return(old_state)); - ExpectSuccesfullSetHmiState(app, app_mock, old_state, new_state); + ExpectSuccessfulSetHmiState(app, app_mock, old_state, new_state); } void ExpectAppWontChangeHmiStateDueToConflictResolving( am::ApplicationSharedPtr app, NiceMock* app_mock, + const am::WindowID window_id, am::HmiStatePtr state) { - ON_CALL(*app_mock, RegularHmiState()).WillByDefault(Return(state)); - EXPECT_CALL(app_manager_mock_, SendHMIStatusNotification(app)).Times(0); + ON_CALL(*app_mock, RegularHmiState(window_id)).WillByDefault(Return(state)); + EXPECT_CALL(message_helper_mock_, + SendHMIStatusNotification(app, window_id, _)) + .Times(0); EXPECT_CALL(app_manager_mock_, OnHMILevelChanged(app->app_id(), _, _)) .Times(0); } + void ExpectAppWontChangeHmiStateDueToConflictResolving( + am::ApplicationSharedPtr app, + NiceMock* app_mock, + am::HmiStatePtr state) { + ExpectAppWontChangeHmiStateDueToConflictResolving( + app, app_mock, kDefaultWindowId, state); + } + void InsertApplication(am::ApplicationSharedPtr app) { application_set_.insert(app); ON_CALL(app_manager_mock_, application(app->app_id())) @@ -1135,13 +1171,14 @@ class StateControllerImplTest : public ::testing::Test { using smart_objects::SmartObject; namespace FunctionID = hmi_apis::FunctionID; - EXPECT_CALL(app_mock, CurrentHmiState()) + EXPECT_CALL(app_mock, CurrentHmiState(kDefaultWindowId)) .WillRepeatedly(Return(NoneNotAudibleState())); for (size_t i = 0; i < state_ids.size(); ++i) { am::HmiState::StateID state_id = state_ids[i]; EXPECT_CALL(app_mock, - AddHMIState(Truly(HmiStatesIDComparator(state_id)))); + AddHMIState(kDefaultWindowId, + Truly(HmiStatesIDComparator(state_id)))); switch (state_id) { case am::HmiState::StateID::STATE_ID_VR_SESSION: { Event vr_start_event(FunctionID::VR_Started); @@ -1182,7 +1219,7 @@ class StateControllerImplTest : public ::testing::Test { default: break; } - EXPECT_CALL(app_mock, AddHMIState(_)).Times(0); + EXPECT_CALL(app_mock, AddHMIState(kDefaultWindowId, _)).Times(0); } } @@ -1194,12 +1231,17 @@ class StateControllerImplTest : public ::testing::Test { using smart_objects::SmartObject; namespace FunctionID = hmi_apis::FunctionID; - EXPECT_CALL(app_mock, CurrentHmiState()) + EXPECT_CALL(app_mock, CurrentHmiState(kDefaultWindowId)) .WillRepeatedly(Return(NoneNotAudibleState())); + am::WindowIds window_ids = {kDefaultWindowId}; + EXPECT_CALL(app_mock, GetWindowIds()).WillRepeatedly(Return(window_ids)); + for (uint32_t i = 0; i < state_ids.size(); ++i) { am::HmiState::StateID state_id = state_ids[i]; - EXPECT_CALL(app_mock, AddHMIState(Truly(HmiStatesIDComparator(state_id)))) + EXPECT_CALL( + app_mock, + AddHMIState(kDefaultWindowId, Truly(HmiStatesIDComparator(state_id)))) .Times(1); switch (state_id) { @@ -1243,16 +1285,17 @@ class StateControllerImplTest : public ::testing::Test { break; } - EXPECT_CALL(app_mock, AddHMIState(_)).Times(0); + EXPECT_CALL(app_mock, AddHMIState(kDefaultWindowId, _)).Times(0); } for (uint32_t i = 0; i < state_ids.size(); ++i) { am::HmiState::StateID state_id = state_ids[i]; - EXPECT_CALL(app_mock, RemoveHMIState(state_id)).Times(1); + EXPECT_CALL(app_mock, RemoveHMIState(kDefaultWindowId, state_id)) + .Times(1); - EXPECT_CALL(app_mock, PostponedHmiState()) + EXPECT_CALL(app_mock, PostponedHmiState(kDefaultWindowId)) .WillOnce(Return(NoneNotAudibleState())); - EXPECT_CALL(app_mock, RemovePostponedState()); + EXPECT_CALL(app_mock, RemovePostponedState(kDefaultWindowId)); switch (state_id) { case am::HmiState::StateID::STATE_ID_VR_SESSION: { @@ -1295,7 +1338,7 @@ class StateControllerImplTest : public ::testing::Test { break; } - EXPECT_CALL(app_mock, RemoveHMIState(_)).Times(0); + EXPECT_CALL(app_mock, RemoveHMIState(kDefaultWindowId, _)).Times(0); } } }; @@ -1307,6 +1350,7 @@ TEST_F(StateControllerImplTest, OnStateChangedWithEqualStates) { for (uint32_t i = 0; i < valid_states_for_not_audio_app_.size(); ++i) { state_ctrl_->OnStateChanged(simple_app_, + kDefaultWindowId, valid_states_for_not_audio_app_[i], valid_states_for_not_audio_app_[i]); } @@ -1317,8 +1361,9 @@ TEST_F(StateControllerImplTest, OnStateChangedWithDifferentStates) { for (uint32_t j = 0; j < valid_states_for_not_audio_app_.size(); ++j) { HmiStatesComparator comp(valid_states_for_not_audio_app_[i]); if (!comp(valid_states_for_not_audio_app_[j])) { - EXPECT_CALL(app_manager_mock_, SendHMIStatusNotification(simple_app_)) - .Times(1); + EXPECT_CALL( + message_helper_mock_, + SendHMIStatusNotification(simple_app_, kDefaultWindowId, _)); EXPECT_CALL( app_manager_mock_, OnHMILevelChanged(simple_app_id_, @@ -1330,10 +1375,12 @@ TEST_F(StateControllerImplTest, OnStateChangedWithDifferentStates) { EXPECT_CALL(*simple_app_ptr_, ResetDataInNone()).Times(1); } state_ctrl_->OnStateChanged(simple_app_, + kDefaultWindowId, valid_states_for_not_audio_app_[i], valid_states_for_not_audio_app_[j]); - EXPECT_CALL(app_manager_mock_, SendHMIStatusNotification(_)).Times(0); + EXPECT_CALL(message_helper_mock_, SendHMIStatusNotification(_, _, _)) + .Times(0); EXPECT_CALL(app_manager_mock_, OnHMILevelChanged(_, _, _)).Times(0); EXPECT_CALL(*simple_app_ptr_, ResetDataInNone()).Times(0); } @@ -1356,10 +1403,12 @@ TEST_F(StateControllerImplTest, OnStateChangedToNone) { SystemContext::SYSCTXT_MAIN); EXPECT_CALL(*simple_app_ptr_, ResetDataInNone()).Times(0); - state_ctrl_->OnStateChanged(simple_app_, none_state, not_none_state); + state_ctrl_->OnStateChanged( + simple_app_, kDefaultWindowId, none_state, not_none_state); EXPECT_CALL(*simple_app_ptr_, ResetDataInNone()).Times(1); - state_ctrl_->OnStateChanged(simple_app_, not_none_state, none_state); + state_ctrl_->OnStateChanged( + simple_app_, kDefaultWindowId, not_none_state, none_state); } TEST_F(StateControllerImplTest, MoveSimpleAppToValidStates) { @@ -1377,18 +1426,21 @@ TEST_F(StateControllerImplTest, MoveSimpleAppToValidStates) { it != valid_states_for_not_audio_app_.end(); ++it) { HmiStatePtr state_to_setup = *it; - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillOnce(Return(initial_state)) .WillOnce(Return(state_to_setup)); - EXPECT_CALL(app_manager_mock_, SendHMIStatusNotification(simple_app_)); + 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())); EXPECT_CALL(*simple_app_ptr_, - SetRegularState(Truly(HmiStatesComparator(state_to_setup)))); - state_ctrl_->SetRegularState(simple_app_, state_to_setup, false); + SetRegularState(kDefaultWindowId, + Truly(HmiStatesComparator(state_to_setup)))); + state_ctrl_->SetRegularState( + simple_app_, kDefaultWindowId, state_to_setup, false); initial_state = state_to_setup; } } @@ -1413,18 +1465,21 @@ TEST_F(StateControllerImplTest, MoveAudioNotResumeAppToValidStates) { it != valid_states_for_audio_app_.end(); ++it) { HmiStatePtr state_to_setup = *it; - EXPECT_CALL(*audio_app_mock, CurrentHmiState()) + EXPECT_CALL(*audio_app_mock, CurrentHmiState(kDefaultWindowId)) .WillOnce(Return(initial_state)) .WillOnce(Return(state_to_setup)); - EXPECT_CALL(app_manager_mock_, SendHMIStatusNotification(audio_app)); + 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())); EXPECT_CALL(*audio_app_mock, - SetRegularState(Truly(HmiStatesComparator(state_to_setup)))); - state_ctrl_->SetRegularState(media_navi_vc_app_, state_to_setup, false); + SetRegularState(kDefaultWindowId, + Truly(HmiStatesComparator(state_to_setup)))); + state_ctrl_->SetRegularState( + media_navi_vc_app_, kDefaultWindowId, state_to_setup, false); initial_state = state_to_setup; } } @@ -1452,7 +1507,7 @@ TEST_F(StateControllerImplTest, MoveAudioResumeAppToValidStates) { HmiStatePtr state_to_setup = *it; HmiStatePtr state_to_check = state_to_setup; // First time current state is initial, then it changes to setup state - EXPECT_CALL(*audio_app_mock, CurrentHmiState()) + EXPECT_CALL(*audio_app_mock, CurrentHmiState(kDefaultWindowId)) .WillOnce(Return(initial_state)) .WillOnce(Return(state_to_setup)); // Audio resume app when HMI level is LIMITED or FULL gets audible state @@ -1480,8 +1535,10 @@ TEST_F(StateControllerImplTest, MoveAudioResumeAppToValidStates) { // Check that we set correct state EXPECT_CALL(*audio_app_mock, - SetRegularState(Truly(HmiStatesComparator(state_to_check)))); - state_ctrl_->SetRegularState(media_navi_vc_app_, state_to_setup, false); + SetRegularState(kDefaultWindowId, + Truly(HmiStatesComparator(state_to_check)))); + state_ctrl_->SetRegularState( + media_navi_vc_app_, kDefaultWindowId, state_to_setup, false); initial_state = state_to_setup; } } @@ -1494,11 +1551,13 @@ TEST_F(StateControllerImplTest, MoveAppFromValidStateToInvalid) { invalid_state_it != common_invalid_states_.end(); ++invalid_state_it) { HmiStatePtr invalid_state = *invalid_state_it; - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()).Times(0); + 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(*simple_app_ptr_, SetRegularState(_)).Times(0); - state_ctrl_->SetRegularState(simple_app_, invalid_state, false); + EXPECT_CALL(*simple_app_ptr_, SetRegularState(kDefaultWindowId, _)) + .Times(0); + state_ctrl_->SetRegularState( + simple_app_, kDefaultWindowId, invalid_state, false); } for (std::vector::iterator invalid_state_it = @@ -1506,11 +1565,14 @@ TEST_F(StateControllerImplTest, MoveAppFromValidStateToInvalid) { invalid_state_it != common_invalid_states_.end(); ++invalid_state_it) { HmiStatePtr invalid_state = *invalid_state_it; - EXPECT_CALL(*media_navi_vc_app_ptr_, CurrentHmiState()).Times(0); + 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(*media_navi_vc_app_ptr_, SetRegularState(_)).Times(0); - state_ctrl_->SetRegularState(media_navi_vc_app_, invalid_state, false); + EXPECT_CALL(*media_navi_vc_app_ptr_, SetRegularState(kDefaultWindowId, _)) + .Times(0); + state_ctrl_->SetRegularState( + media_navi_vc_app_, kDefaultWindowId, invalid_state, false); } } @@ -1532,7 +1594,7 @@ TEST_F(StateControllerImplTest, InsertApplication(app_in_full); InsertApplication(app_moved_to_full); - ExpectSuccesfullSetHmiState(app_moved_to_full, + ExpectSuccessfulSetHmiState(app_moved_to_full, app_moved_to_full_mock, BackgroundState(), FullNotAudibleState()); @@ -1540,7 +1602,8 @@ TEST_F(StateControllerImplTest, ExpectAppChangeHmiStateDueToConflictResolving( app_in_full, app_in_full_mock, FullNotAudibleState(), BackgroundState()); - state_ctrl_->SetRegularState(app_moved_to_full, FullNotAudibleState(), false); + state_ctrl_->SetRegularState( + app_moved_to_full, kDefaultWindowId, FullNotAudibleState(), false); } TEST_F(StateControllerImplTest, SetFullToSimpleAppWhileAudioAppAppIsInFull) { @@ -1557,14 +1620,15 @@ TEST_F(StateControllerImplTest, SetFullToSimpleAppWhileAudioAppAppIsInFull) { InsertApplication(app_in_full); InsertApplication(app_moved_to_full); - ExpectSuccesfullSetHmiState(app_moved_to_full, + ExpectSuccessfulSetHmiState(app_moved_to_full, app_moved_to_full_mock, BackgroundState(), FullNotAudibleState()); ExpectAppChangeHmiStateDueToConflictResolving( app_in_full, app_in_full_mock, FullAudibleState(), LimitedState()); - state_ctrl_->SetRegularState(app_moved_to_full, FullNotAudibleState(), false); + state_ctrl_->SetRegularState( + app_moved_to_full, kDefaultWindowId, FullNotAudibleState(), false); } TEST_F(StateControllerImplTest, @@ -1583,14 +1647,15 @@ TEST_F(StateControllerImplTest, InsertApplication(app_in_full); InsertApplication(app_moved_to_full); - ExpectSuccesfullSetHmiState(app_moved_to_full, + ExpectSuccessfulSetHmiState(app_moved_to_full, app_moved_to_full_mock, BackgroundState(), FullAudibleState()); ExpectAppChangeHmiStateDueToConflictResolving( app_in_full, app_in_full_mock, FullAudibleState(), LimitedState()); - state_ctrl_->SetRegularState(app_moved_to_full, FullAudibleState(), false); + state_ctrl_->SetRegularState( + app_moved_to_full, kDefaultWindowId, FullAudibleState(), false); } TEST_F(StateControllerImplTest, @@ -1607,7 +1672,7 @@ TEST_F(StateControllerImplTest, InsertApplication(app_in_full); InsertApplication(app_moved_to_full); - ExpectSuccesfullSetHmiState(app_moved_to_full, + ExpectSuccessfulSetHmiState(app_moved_to_full, app_moved_to_full_mock, BackgroundState(), FullAudibleState()); @@ -1615,7 +1680,8 @@ TEST_F(StateControllerImplTest, ExpectAppChangeHmiStateDueToConflictResolving( app_in_full, app_in_full_mock, FullAudibleState(), BackgroundState()); - state_ctrl_->SetRegularState(app_moved_to_full, FullAudibleState(), false); + state_ctrl_->SetRegularState( + app_moved_to_full, kDefaultWindowId, FullAudibleState(), false); } TEST_F(StateControllerImplTest, @@ -1633,7 +1699,7 @@ TEST_F(StateControllerImplTest, InsertApplication(app_in_limited); InsertApplication(app_moved_to_full); - ExpectSuccesfullSetHmiState(app_moved_to_full, + ExpectSuccessfulSetHmiState(app_moved_to_full, app_moved_to_full_mock, BackgroundState(), FullAudibleState()); @@ -1641,7 +1707,8 @@ TEST_F(StateControllerImplTest, ExpectAppChangeHmiStateDueToConflictResolving( app_in_limited, app_in_limited_mock, LimitedState(), BackgroundState()); - state_ctrl_->SetRegularState(app_moved_to_full, FullAudibleState(), false); + state_ctrl_->SetRegularState( + app_moved_to_full, kDefaultWindowId, FullAudibleState(), false); } TEST_F(StateControllerImplTest, @@ -1660,7 +1727,7 @@ TEST_F(StateControllerImplTest, InsertApplication(app_in_limited); InsertApplication(app_moved_to_limited); - ExpectSuccesfullSetHmiState(app_moved_to_limited, + ExpectSuccessfulSetHmiState(app_moved_to_limited, app_moved_to_limited_mock, BackgroundState(), LimitedState()); @@ -1668,7 +1735,8 @@ TEST_F(StateControllerImplTest, ExpectAppChangeHmiStateDueToConflictResolving( app_in_limited, app_in_limited_mock, LimitedState(), BackgroundState()); - state_ctrl_->SetRegularState(app_moved_to_limited, LimitedState(), false); + state_ctrl_->SetRegularState( + app_moved_to_limited, kDefaultWindowId, LimitedState(), false); } TEST_F(StateControllerImplTest, @@ -1686,14 +1754,15 @@ TEST_F(StateControllerImplTest, InsertApplication(app_in_limited); InsertApplication(app_moved_to_limited); - ExpectSuccesfullSetHmiState(app_moved_to_limited, + ExpectSuccessfulSetHmiState(app_moved_to_limited, app_moved_to_limited_mock, BackgroundState(), LimitedState()); ExpectAppWontChangeHmiStateDueToConflictResolving( app_in_limited, app_in_limited_mock, LimitedState()); - state_ctrl_->SetRegularState(app_moved_to_limited, LimitedState(), false); + state_ctrl_->SetRegularState( + app_moved_to_limited, kDefaultWindowId, LimitedState(), false); } TEST_F(StateControllerImplTest, @@ -1712,14 +1781,15 @@ TEST_F(StateControllerImplTest, InsertApplication(app_in_full); InsertApplication(app_moved_to_limited); - ExpectSuccesfullSetHmiState(app_moved_to_limited, + ExpectSuccessfulSetHmiState(app_moved_to_limited, app_moved_to_limited_mock, BackgroundState(), LimitedState()); ExpectAppWontChangeHmiStateDueToConflictResolving( app_in_full, app_in_full_mock, FullAudibleState()); - state_ctrl_->SetRegularState(app_moved_to_limited, LimitedState(), false); + state_ctrl_->SetRegularState( + app_moved_to_limited, kDefaultWindowId, LimitedState(), false); } TEST_F(StateControllerImplTest, SetFullToSimpleAppWhile2AudioAppsInLimited) { @@ -1743,7 +1813,7 @@ TEST_F(StateControllerImplTest, SetFullToSimpleAppWhile2AudioAppsInLimited) { InsertApplication(limited_app1); InsertApplication(limited_app2); - ExpectSuccesfullSetHmiState(app_moved_to_full, + ExpectSuccessfulSetHmiState(app_moved_to_full, app_moved_to_full_mock, BackgroundState(), FullNotAudibleState()); @@ -1753,7 +1823,8 @@ TEST_F(StateControllerImplTest, SetFullToSimpleAppWhile2AudioAppsInLimited) { ExpectAppWontChangeHmiStateDueToConflictResolving( limited_app2, limited_app2_mock, LimitedState()); - state_ctrl_->SetRegularState(app_moved_to_full, FullNotAudibleState(), false); + state_ctrl_->SetRegularState( + app_moved_to_full, kDefaultWindowId, FullNotAudibleState(), false); } TEST_F(StateControllerImplTest, @@ -1778,7 +1849,7 @@ TEST_F(StateControllerImplTest, InsertApplication(limited_app); InsertApplication(full_app); - ExpectSuccesfullSetHmiState(app_moved_to_full, + ExpectSuccessfulSetHmiState(app_moved_to_full, app_moved_to_full_mock, BackgroundState(), FullNotAudibleState()); @@ -1789,7 +1860,8 @@ TEST_F(StateControllerImplTest, ExpectAppChangeHmiStateDueToConflictResolving( full_app, full_app_mock, FullAudibleState(), LimitedState()); - state_ctrl_->SetRegularState(app_moved_to_full, FullNotAudibleState(), false); + state_ctrl_->SetRegularState( + app_moved_to_full, kDefaultWindowId, FullNotAudibleState(), false); } TEST_F(StateControllerImplTest, @@ -1814,7 +1886,7 @@ TEST_F(StateControllerImplTest, InsertApplication(limited_app); InsertApplication(full_app); - ExpectSuccesfullSetHmiState(app_moved_to_full, + ExpectSuccessfulSetHmiState(app_moved_to_full, app_moved_to_full_mock, BackgroundState(), FullNotAudibleState()); @@ -1825,7 +1897,8 @@ TEST_F(StateControllerImplTest, ExpectAppChangeHmiStateDueToConflictResolving( full_app, full_app_mock, FullNotAudibleState(), BackgroundState()); - state_ctrl_->SetRegularState(app_moved_to_full, FullNotAudibleState(), false); + state_ctrl_->SetRegularState( + app_moved_to_full, kDefaultWindowId, FullNotAudibleState(), false); } TEST_F( @@ -1851,7 +1924,7 @@ TEST_F( InsertApplication(limited_app); InsertApplication(full_app); - ExpectSuccesfullSetHmiState(app_moved_to_full, + ExpectSuccessfulSetHmiState(app_moved_to_full, app_moved_to_full_mock, BackgroundState(), FullAudibleState()); @@ -1862,7 +1935,8 @@ TEST_F( ExpectAppChangeHmiStateDueToConflictResolving( full_app, full_app_mock, FullNotAudibleState(), BackgroundState()); - state_ctrl_->SetRegularState(app_moved_to_full, FullAudibleState(), false); + state_ctrl_->SetRegularState( + app_moved_to_full, kDefaultWindowId, FullAudibleState(), false); } TEST_F( @@ -1888,7 +1962,7 @@ TEST_F( InsertApplication(limited_app); InsertApplication(full_app); - ExpectSuccesfullSetHmiState(app_moved_to_full, + ExpectSuccessfulSetHmiState(app_moved_to_full, app_moved_to_full_mock, BackgroundState(), FullAudibleState()); @@ -1899,7 +1973,8 @@ TEST_F( ExpectAppChangeHmiStateDueToConflictResolving( full_app, full_app_mock, FullAudibleState(), LimitedState()); - state_ctrl_->SetRegularState(app_moved_to_full, FullAudibleState(), false); + state_ctrl_->SetRegularState( + app_moved_to_full, kDefaultWindowId, FullAudibleState(), false); } TEST_F(StateControllerImplTest, @@ -1912,19 +1987,20 @@ TEST_F(StateControllerImplTest, InsertApplication(media_app_); InsertApplication(navi_app_); InsertApplication(vc_app_); - ExpectSuccesfullSetHmiState(media_navi_vc_app_, + ExpectSuccessfulSetHmiState(media_navi_vc_app_, media_navi_vc_app_ptr_, BackgroundState(), FullAudibleState()); - EXPECT_CALL(*media_app_ptr_, RegularHmiState()) + EXPECT_CALL(*media_app_ptr_, RegularHmiState(kDefaultWindowId)) .WillOnce(Return(LimitedState())); ExpectAppChangeHmiStateDueToConflictResolving( navi_app_, navi_app_ptr_, LimitedState(), BackgroundState()); ExpectAppChangeHmiStateDueToConflictResolving( vc_app_, vc_app_ptr_, LimitedState(), BackgroundState()); - state_ctrl_->SetRegularState(media_navi_vc_app_, FullAudibleState(), false); + state_ctrl_->SetRegularState( + media_navi_vc_app_, kDefaultWindowId, FullAudibleState(), false); } TEST_F(StateControllerImplTest, @@ -1937,19 +2013,20 @@ TEST_F(StateControllerImplTest, InsertApplication(media_app_); InsertApplication(navi_app_); InsertApplication(vc_app_); - ExpectSuccesfullSetHmiState(media_navi_vc_app_, + ExpectSuccessfulSetHmiState(media_navi_vc_app_, media_navi_vc_app_ptr_, BackgroundState(), FullAudibleState()); - EXPECT_CALL(*media_app_ptr_, RegularHmiState()) + EXPECT_CALL(*media_app_ptr_, RegularHmiState(kDefaultWindowId)) .WillOnce(Return(LimitedState())); ExpectAppChangeHmiStateDueToConflictResolving( navi_app_, navi_app_ptr_, LimitedState(), BackgroundState()); ExpectAppChangeHmiStateDueToConflictResolving( vc_app_, vc_app_ptr_, FullAudibleState(), BackgroundState()); - state_ctrl_->SetRegularState(media_navi_vc_app_, FullAudibleState(), false); + state_ctrl_->SetRegularState( + media_navi_vc_app_, kDefaultWindowId, FullAudibleState(), false); } // TODO {AKozoriz} Changed logic in state_controller @@ -1992,9 +2069,9 @@ TEST_F(StateControllerImplTest, DISABLED_ActivateAppSuccessReceivedFromHMI) { .WillOnce(Return(hmi_app_id)); EXPECT_CALL(app_manager_mock_, application_by_hmi_app(hmi_app_id)) .WillOnce(Return(media_app_)); - ExpectSuccesfullSetHmiState( + ExpectSuccessfulSetHmiState( media_app_, media_app_ptr_, initial_hmi_state, hmi_state); - state_ctrl_->SetRegularState(media_app_, hmi_state, true); + state_ctrl_->SetRegularState(media_app_, kDefaultWindowId, hmi_state, true); smart_objects::SmartObject message; message[am::strings::params][am::hmi_response::code] = Common_Result::SUCCESS; @@ -2050,9 +2127,10 @@ TEST_F(StateControllerImplTest, SendEventBCActivateApp_HMIReceivesError) { EXPECT_CALL(app_manager_mock_, application_by_hmi_app(hmi_app_id)) .WillOnce(Return(simple_app_)); - EXPECT_CALL(*simple_app_ptr_, RegularHmiState()).Times(0); - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()).Times(0); - EXPECT_CALL(*simple_app_ptr_, SetRegularState(_)).Times(0); + EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kDefaultWindowId)).Times(0); + EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)).Times(0); + EXPECT_CALL(*simple_app_ptr_, SetRegularState(kDefaultWindowId, _)) + .Times(0); EXPECT_CALL(app_manager_mock_, SendHMIStatusNotification(simple_app_)) .Times(0); @@ -2078,13 +2156,14 @@ TEST_F(StateControllerImplTest, ActivateAppInvalidCorrelationId) { .WillOnce(Return(hmi_app_id)); EXPECT_CALL(app_manager_mock_, application_by_hmi_app(hmi_app_id)) .WillOnce(Return(am::ApplicationSharedPtr())); - EXPECT_CALL(*simple_app_ptr_, SetRegularState(_)).Times(0); + 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(), _, _)) .Times(0); SetBCActivateAppRequestToHMI(Common_HMILevel::FULL, corr_id); - state_ctrl_->SetRegularState(simple_app_, FullNotAudibleState(), true); + state_ctrl_->SetRegularState( + simple_app_, kDefaultWindowId, FullNotAudibleState(), true); smart_objects::SmartObject message; message[am::strings::params][am::hmi_response::code] = Common_Result::SUCCESS; message[am::strings::params][am::strings::correlation_id] = corr_id; @@ -2510,43 +2589,43 @@ TEST_F(StateControllerImplTest, SetRegularStateWithNewHmiLvl) { using namespace mobile_apis; HMILevel::eType set_lvl = HMILevel::HMI_NONE; - EXPECT_CALL(*simple_app_ptr_, RegularHmiState()) + EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kDefaultWindowId)) .WillOnce(Return(BackgroundState())); - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillOnce(Return(BackgroundState())) .WillOnce(Return(BackgroundState())); - state_ctrl_->SetRegularState(simple_app_, set_lvl); + state_ctrl_->SetRegularState(simple_app_, kDefaultWindowId, set_lvl); set_lvl = HMILevel::HMI_LIMITED; - EXPECT_CALL(*simple_app_ptr_, RegularHmiState()) + EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kDefaultWindowId)) .WillOnce(Return(BackgroundState())); - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillOnce(Return(BackgroundState())) .WillOnce(Return(BackgroundState())); - state_ctrl_->SetRegularState(simple_app_, set_lvl); + state_ctrl_->SetRegularState(simple_app_, kDefaultWindowId, set_lvl); set_lvl = HMILevel::HMI_FULL; - EXPECT_CALL(*simple_app_ptr_, RegularHmiState()) + EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kDefaultWindowId)) .WillOnce(Return(BackgroundState())); const uint32_t corr_id = 314; SetBCActivateAppRequestToHMI( static_cast(set_lvl), corr_id); - state_ctrl_->SetRegularState(simple_app_, set_lvl); + state_ctrl_->SetRegularState(simple_app_, kDefaultWindowId, set_lvl); set_lvl = HMILevel::HMI_BACKGROUND; - EXPECT_CALL(*simple_app_ptr_, RegularHmiState()) + EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kDefaultWindowId)) .WillOnce(Return(BackgroundState())); - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillOnce(Return(BackgroundState())) .WillOnce(Return(BackgroundState())); - state_ctrl_->SetRegularState(simple_app_, set_lvl); + state_ctrl_->SetRegularState(simple_app_, kDefaultWindowId, set_lvl); } TEST_F(StateControllerImplTest, SetRegularStateWithAudioStateAudible) { @@ -2556,16 +2635,18 @@ TEST_F(StateControllerImplTest, SetRegularStateWithAudioStateAudible) { AudioStreamingState::AUDIBLE, VideoStreamingState::STREAMABLE, SystemContext::SYSCTXT_MAIN); - EXPECT_CALL(*simple_app_ptr_, RegularHmiState()) + EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kDefaultWindowId)) .WillRepeatedly(Return(BackgroundState())); - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillOnce(Return(check_state)) .WillOnce(Return(check_state)); EXPECT_CALL(*simple_app_ptr_, - SetRegularState(Truly(HmiStatesComparator(check_state)))); + SetRegularState(kDefaultWindowId, + Truly(HmiStatesComparator(check_state)))); state_ctrl_->SetRegularState(simple_app_, + kDefaultWindowId, AudioStreamingState::AUDIBLE, VideoStreamingState::STREAMABLE); } @@ -2582,23 +2663,27 @@ TEST_F(StateControllerImplTest, // Non-media app can't have LIMITED-AUDIO state EXPECT_CALL(*simple_app_ptr_, is_resuming()).WillRepeatedly(Return(true)); - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()).Times(0); - EXPECT_CALL(*simple_app_ptr_, SetRegularState(_)).Times(0); + EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)).Times(0); + EXPECT_CALL(*simple_app_ptr_, SetRegularState(kDefaultWindowId, _)).Times(0); EXPECT_CALL(app_manager_mock_, GetDefaultHmiLevel(_)) .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_NONE)); EXPECT_CALL(app_manager_mock_, active_application()) .WillRepeatedly(Return(am::ApplicationSharedPtr())); EXPECT_CALL(*simple_app_ptr_, - SetPostponedState(Truly(HmiStatesComparator(check_state)))); - state_ctrl_->SetRegularState(simple_app_, check_state, false); + SetPostponedState(kDefaultWindowId, + Truly(HmiStatesComparator(check_state)))); + state_ctrl_->SetRegularState( + simple_app_, kDefaultWindowId, check_state, false); check_state = LimitedState(); EXPECT_CALL(*media_app_ptr_, is_resuming()).WillRepeatedly(Return(true)); - EXPECT_CALL(*media_app_ptr_, CurrentHmiState()).Times(0); - EXPECT_CALL(*media_app_ptr_, SetRegularState(_)).Times(0); + EXPECT_CALL(*media_app_ptr_, CurrentHmiState(kDefaultWindowId)).Times(0); + EXPECT_CALL(*media_app_ptr_, SetRegularState(kDefaultWindowId, _)).Times(0); EXPECT_CALL(*media_app_ptr_, - SetPostponedState(Truly(HmiStatesComparator(check_state)))); - state_ctrl_->SetRegularState(media_app_, check_state, false); + SetPostponedState(kDefaultWindowId, + Truly(HmiStatesComparator(check_state)))); + state_ctrl_->SetRegularState( + media_app_, kDefaultWindowId, check_state, false); } TEST_F(StateControllerImplTest, SetRegularStateMediaToNonMediaApp_VR_Stopped) { @@ -2615,7 +2700,7 @@ TEST_F(StateControllerImplTest, SetRegularStateMediaToNonMediaApp_VR_Stopped) { HmiStatePtr check_state = FullNotAudibleState(); // Non-media app can't have LIMITED-AUDIO state - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillOnce(Return(check_state)) .WillOnce(Return(check_state)); @@ -2625,16 +2710,19 @@ TEST_F(StateControllerImplTest, SetRegularStateMediaToNonMediaApp_VR_Stopped) { SendOnResumeAudioSourceToHMI(simple_app_id_, _)) .Times(0); EXPECT_CALL(*simple_app_ptr_, - SetPostponedState(Truly(HmiStatesComparator(check_state)))) + SetPostponedState(kDefaultWindowId, + Truly(HmiStatesComparator(check_state)))) .Times(0); EXPECT_CALL(*simple_app_ptr_, - SetRegularState(Truly(HmiStatesComparator(check_state)))); - state_ctrl_->SetRegularState(simple_app_, check_state, false); + SetRegularState(kDefaultWindowId, + Truly(HmiStatesComparator(check_state)))); + state_ctrl_->SetRegularState( + simple_app_, kDefaultWindowId, check_state, false); // Set state of media app after vr has stopped check_state = LimitedState(); - EXPECT_CALL(*media_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*media_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillOnce(Return(check_state)) .WillOnce(Return(check_state)); @@ -2643,11 +2731,14 @@ TEST_F(StateControllerImplTest, SetRegularStateMediaToNonMediaApp_VR_Stopped) { EXPECT_CALL(message_helper_mock_, SendOnResumeAudioSourceToHMI(media_app_id_, _)); EXPECT_CALL(*media_app_ptr_, - SetPostponedState(Truly(HmiStatesComparator(check_state)))) + SetPostponedState(kDefaultWindowId, + Truly(HmiStatesComparator(check_state)))) .Times(0); EXPECT_CALL(*media_app_ptr_, - SetRegularState(Truly(HmiStatesComparator(check_state)))); - state_ctrl_->SetRegularState(media_app_, check_state, false); + SetRegularState(kDefaultWindowId, + Truly(HmiStatesComparator(check_state)))); + state_ctrl_->SetRegularState( + media_app_, kDefaultWindowId, check_state, false); } TEST_F(StateControllerImplTest, @@ -2670,28 +2761,32 @@ TEST_F(StateControllerImplTest, HmiStatePtr check_state = FullNotAudibleState(); EXPECT_CALL(*simple_app_ptr_, is_resuming()).WillRepeatedly(Return(true)); - EXPECT_CALL(*simple_app_ptr_, RegularHmiState()).Times(0); - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()).Times(0); - EXPECT_CALL(*simple_app_ptr_, SetRegularState(_)).Times(0); + EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kDefaultWindowId)).Times(0); + EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)).Times(0); + EXPECT_CALL(*simple_app_ptr_, SetRegularState(kDefaultWindowId, _)).Times(0); EXPECT_CALL(app_manager_mock_, GetDefaultHmiLevel(_)) .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_NONE)); EXPECT_CALL(app_manager_mock_, active_application()) .WillRepeatedly(Return(am::ApplicationSharedPtr())); EXPECT_CALL(*simple_app_ptr_, - SetPostponedState(Truly(HmiStatesComparator(check_state)))); - state_ctrl_->SetRegularState(simple_app_, check_state, false); + SetPostponedState(kDefaultWindowId, + Truly(HmiStatesComparator(check_state)))); + state_ctrl_->SetRegularState( + simple_app_, kDefaultWindowId, check_state, false); // Set media app check_state = LimitedState(); EXPECT_CALL(*media_app_ptr_, is_resuming()).WillRepeatedly(Return(true)); - EXPECT_CALL(*media_app_ptr_, RegularHmiState()).Times(0); - EXPECT_CALL(*media_app_ptr_, CurrentHmiState()).Times(0); - EXPECT_CALL(*media_app_ptr_, SetRegularState(_)).Times(0); + EXPECT_CALL(*media_app_ptr_, RegularHmiState(kDefaultWindowId)).Times(0); + EXPECT_CALL(*media_app_ptr_, CurrentHmiState(kDefaultWindowId)).Times(0); + EXPECT_CALL(*media_app_ptr_, SetRegularState(kDefaultWindowId, _)).Times(0); EXPECT_CALL(*media_app_ptr_, - SetPostponedState(Truly(HmiStatesComparator(check_state)))); - state_ctrl_->SetRegularState(media_app_, check_state, false); + SetPostponedState(kDefaultWindowId, + Truly(HmiStatesComparator(check_state)))); + state_ctrl_->SetRegularState( + media_app_, kDefaultWindowId, check_state, false); } TEST_F(StateControllerImplTest, @@ -2724,8 +2819,10 @@ TEST_F(StateControllerImplTest, .WillRepeatedly(Return(am::ApplicationSharedPtr())); EXPECT_CALL(*media_app_ptr_, - SetPostponedState(Truly(HmiStatesComparator(check_state)))); - state_ctrl_->SetRegularState(media_app_, check_state, false); + SetPostponedState(kDefaultWindowId, + Truly(HmiStatesComparator(check_state)))); + state_ctrl_->SetRegularState( + media_app_, kDefaultWindowId, check_state, false); } TEST_F(StateControllerImplTest, @@ -2753,13 +2850,13 @@ TEST_F(StateControllerImplTest, EXPECT_CALL(app_manager_mock_, IsAppTypeExistsInFullOrLimited(_)) .WillRepeatedly(Return(false)); - EXPECT_CALL(*navi_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*navi_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillRepeatedly(Return(hmi_state)); EXPECT_CALL(app_manager_mock_, active_application()) .WillRepeatedly(Return(am::ApplicationSharedPtr())); - state_ctrl_->SetRegularState(navi_app_, hmi_state, false); + state_ctrl_->SetRegularState(navi_app_, kDefaultWindowId, hmi_state, false); } TEST_F(StateControllerImplTest, @@ -2787,15 +2884,15 @@ TEST_F(StateControllerImplTest, EXPECT_CALL(app_manager_mock_, IsAppTypeExistsInFullOrLimited(_)) .WillRepeatedly(Return(false)); - EXPECT_CALL(*navi_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*navi_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillRepeatedly(Return(hmi_state)); EXPECT_CALL(app_manager_mock_, active_application()) .WillRepeatedly(Return(am::ApplicationSharedPtr())); - EXPECT_CALL(*navi_app_ptr_, SetPostponedState(_)).Times(0); + EXPECT_CALL(*navi_app_ptr_, SetPostponedState(kDefaultWindowId, _)).Times(0); - state_ctrl_->SetRegularState(navi_app_, hmi_state, false); + state_ctrl_->SetRegularState(navi_app_, kDefaultWindowId, hmi_state, false); } TEST_F(StateControllerImplTest, @@ -2803,7 +2900,6 @@ TEST_F(StateControllerImplTest, using namespace hmi_apis; using namespace smart_objects; using namespace am::event_engine; - using namespace constants; const uint32_t app_id = navi_app_->app_id(); // Precondition @@ -2827,13 +2923,13 @@ TEST_F(StateControllerImplTest, EXPECT_CALL(app_manager_mock_, IsAppTypeExistsInFullOrLimited(_)) .WillRepeatedly(Return(false)); - EXPECT_CALL(*navi_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*navi_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillRepeatedly(Return(hmi_state)); EXPECT_CALL(app_manager_mock_, active_application()) .WillRepeatedly(Return(am::ApplicationSharedPtr())); - state_ctrl_->SetRegularState(navi_app_, hmi_state, true); + state_ctrl_->SetRegularState(navi_app_, kDefaultWindowId, hmi_state, true); } TEST_F(StateControllerImplTest, @@ -2841,7 +2937,6 @@ TEST_F(StateControllerImplTest, using namespace hmi_apis; using namespace smart_objects; using namespace am::event_engine; - using namespace constants; const uint32_t app_id = navi_app_->app_id(); // Precondition @@ -2865,15 +2960,15 @@ TEST_F(StateControllerImplTest, EXPECT_CALL(app_manager_mock_, IsAppTypeExistsInFullOrLimited(_)) .WillRepeatedly(Return(false)); - EXPECT_CALL(*navi_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*navi_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillRepeatedly(Return(hmi_state)); EXPECT_CALL(app_manager_mock_, active_application()) .WillRepeatedly(Return(am::ApplicationSharedPtr())); - EXPECT_CALL(*navi_app_ptr_, SetPostponedState(_)).Times(0); + EXPECT_CALL(*navi_app_ptr_, SetPostponedState(kDefaultWindowId, _)).Times(0); - state_ctrl_->SetRegularState(navi_app_, hmi_state, true); + state_ctrl_->SetRegularState(navi_app_, kDefaultWindowId, hmi_state, true); } TEST_F(StateControllerImplTest, @@ -2894,13 +2989,16 @@ TEST_F(StateControllerImplTest, EXPECT_CALL(*simple_app_ptr_, keep_context()).WillOnce(Return(true)); EXPECT_CALL(*simple_app_ptr_, IsAudioApplication()) .WillRepeatedly(Return(true)); - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillOnce(Return(FullAudibleState())); EXPECT_CALL(*simple_app_ptr_, set_keep_context(false)); HmiStatePtr new_state; - EXPECT_CALL(*simple_app_ptr_, AddHMIState(_)) - .WillOnce(SaveArg<0>(&new_state)); + EXPECT_CALL(*simple_app_ptr_, AddHMIState(kDefaultWindowId, _)) + .WillOnce(SaveArg<1>(&new_state)); + + am::WindowIds window_ids = {kDefaultWindowId}; + EXPECT_CALL(*simple_app_ptr_, GetWindowIds()).WillOnce(Return(window_ids)); state_ctrl_->on_event(event); @@ -2925,12 +3023,15 @@ TEST_F(StateControllerImplTest, OnEventChangedAudioSourceAppToBackground) { EXPECT_CALL(*simple_app_ptr_, IsAudioApplication()) .WillRepeatedly(Return(true)); - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillOnce(Return(LimitedState())); HmiStatePtr new_state; - EXPECT_CALL(*simple_app_ptr_, AddHMIState(_)) - .WillOnce(SaveArg<0>(&new_state)); + EXPECT_CALL(*simple_app_ptr_, AddHMIState(kDefaultWindowId, _)) + .WillOnce(SaveArg<1>(&new_state)); + + am::WindowIds window_ids = {kDefaultWindowId}; + EXPECT_CALL(*simple_app_ptr_, GetWindowIds()).WillOnce(Return(window_ids)); state_ctrl_->on_event(event); @@ -2949,9 +3050,13 @@ TEST_F(StateControllerImplTest, OnEventOnAppDeactivatedIncorrectHmiLevel) { event.set_smart_object(msg); EXPECT_CALL(app_manager_mock_, application(app_id)) .WillOnce(Return(simple_app_)); - EXPECT_CALL(*simple_app_ptr_, hmi_level()) + EXPECT_CALL(*simple_app_ptr_, hmi_level(kDefaultWindowId)) .WillOnce(Return(mobile_apis::HMILevel::HMI_BACKGROUND)); - EXPECT_CALL(*simple_app_ptr_, RegularHmiState()).Times(0); + EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kDefaultWindowId)).Times(0); + + am::WindowIds window_ids = {kDefaultWindowId}; + EXPECT_CALL(*simple_app_ptr_, GetWindowIds()).WillOnce(Return(window_ids)); + state_ctrl_->on_event(event); } @@ -2965,7 +3070,7 @@ TEST_F(StateControllerImplTest, OnEventOnAppDeactivatedIncorrectApp) { const am::ApplicationSharedPtr incorrect_app; EXPECT_CALL(app_manager_mock_, application(_)) .WillOnce(Return(incorrect_app)); - EXPECT_CALL(*simple_app_ptr_, hmi_level()).Times(0); + EXPECT_CALL(*simple_app_ptr_, hmi_level(kDefaultWindowId)).Times(0); state_ctrl_->on_event(event); } @@ -2986,15 +3091,20 @@ TEST_F(StateControllerImplTest, OnEventOnAppDeactivatedAudioApplication) { EXPECT_CALL(app_manager_mock_, application(app_id)) .WillOnce(Return(simple_app_)); EXPECT_CALL(*simple_app_ptr_, app_id()).WillRepeatedly(Return(app_id)); - EXPECT_CALL(*simple_app_ptr_, hmi_level()) + EXPECT_CALL(*simple_app_ptr_, hmi_level(kDefaultWindowId)) .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL)); // DeactivateApp - EXPECT_CALL(*simple_app_ptr_, RegularHmiState()).WillOnce(Return(state)); + EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kDefaultWindowId)) + .WillOnce(Return(state)); EXPECT_CALL(*simple_app_ptr_, IsAudioApplication()) .WillRepeatedly(Return(true)); - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillOnce(Return(BackgroundState())) .WillOnce(Return(BackgroundState())); + + am::WindowIds window_ids = {kDefaultWindowId}; + EXPECT_CALL(*simple_app_ptr_, GetWindowIds()).WillOnce(Return(window_ids)); + state_ctrl_->on_event(event); } @@ -3015,16 +3125,21 @@ TEST_F(StateControllerImplTest, OnEventOnAppDeactivatedNotAudioApplication) { EXPECT_CALL(app_manager_mock_, application(app_id)) .WillOnce(Return(simple_app_)); EXPECT_CALL(*simple_app_ptr_, app_id()).WillRepeatedly(Return(app_id)); - EXPECT_CALL(*simple_app_ptr_, hmi_level()) + EXPECT_CALL(*simple_app_ptr_, hmi_level(kDefaultWindowId)) .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL)); // DeactivateApp - EXPECT_CALL(*simple_app_ptr_, RegularHmiState()).WillOnce(Return(state)); + EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kDefaultWindowId)) + .WillOnce(Return(state)); EXPECT_CALL(*simple_app_ptr_, IsAudioApplication()) .WillRepeatedly(Return(false)); - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillOnce(Return(BackgroundState())) .WillOnce(Return(BackgroundState())); + + am::WindowIds window_ids = {kDefaultWindowId}; + EXPECT_CALL(*simple_app_ptr_, GetWindowIds()).WillOnce(Return(window_ids)); + state_ctrl_->on_event(event); } @@ -3044,25 +3159,35 @@ TEST_F(StateControllerImplTest, OnEventOnAppActivatedIncorrectApp) { } TEST_F(StateControllerImplTest, OnEventOnAppActivated) { - using namespace constants; - smart_objects::SmartObject msg; - for (std::vector::const_iterator it = - applications_list_.begin(); + am::WindowIds window_ids = {kDefaultWindowId}; + + for (AppPtrMockMapping::const_iterator it = applications_list_.begin(); it != applications_list_.end(); ++it) { - uint32_t app_id = (*it)->app_id(); + uint32_t app_id = it->first->app_id(); msg[am::strings::msg_params][am::strings::app_id] = app_id; const hmi_apis::FunctionID::eType event_id = hmi_apis::FunctionID::BasicCommunication_OnAppActivated; am::event_engine::Event event(event_id); event.set_smart_object(msg); - EXPECT_CALL(app_manager_mock_, application(app_id)).WillOnce(Return(*it)); + EXPECT_CALL(app_manager_mock_, application(app_id)) + .WillOnce(Return(it->first)); // SetRegularState - EXPECT_CALL(*simple_app_ptr_, app_id()).WillRepeatedly(Return(app_id)); - EXPECT_CALL(*simple_app_ptr_, IsAudioApplication()) - .WillRepeatedly(Return(true)); + EXPECT_CALL(*it->second, app_id()).WillRepeatedly(Return(app_id)); + EXPECT_CALL(*it->second, IsAudioApplication()).WillRepeatedly(Return(true)); + EXPECT_CALL(*it->second, GetWindowIds()).WillOnce(Return(window_ids)); + + const am::HmiStatePtr old_state = + CreateHmiStateByHmiStateType( + mobile_apis::HMILevel::HMI_NONE, + mobile_apis::AudioStreamingState::NOT_AUDIBLE, + mobile_apis::VideoStreamingState::NOT_STREAMABLE, + mobile_apis::SystemContext::SYSCTXT_MAIN, + simple_app_); + EXPECT_CALL(*it->second, RegularHmiState(kDefaultWindowId)) + .WillOnce(Return(old_state)); smart_objects::SmartObjectSPtr activate_app = std::make_shared(); @@ -3143,9 +3268,9 @@ TEST_F(StateControllerImplTest, OnApplicationRegisteredDifferentStates) { simple_app_); EXPECT_CALL(*simple_app_ptr_, app_id()).WillRepeatedly(Return(app_id)); - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillRepeatedly(Return(old_state)); - EXPECT_CALL(*simple_app_ptr_, AddHMIState(_)).Times(4); + EXPECT_CALL(*simple_app_ptr_, AddHMIState(kDefaultWindowId, _)).Times(4); const am::HmiStatePtr default_state = CreateHmiStateByHmiStateType( @@ -3155,12 +3280,14 @@ TEST_F(StateControllerImplTest, OnApplicationRegisteredDifferentStates) { mobile_apis::SystemContext::SYSCTXT_MAIN, simple_app_); - EXPECT_CALL(*simple_app_ptr_, RegularHmiState()).WillOnce(Return(old_state)); - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kDefaultWindowId)) + .WillOnce(Return(old_state)); + EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillRepeatedly(Return(default_state)); EXPECT_CALL(*simple_app_ptr_, ResetDataInNone()).Times(0); - EXPECT_CALL(app_manager_mock_, SendHMIStatusNotification(_)); + EXPECT_CALL(message_helper_mock_, + SendHMIStatusNotification(simple_app_, kDefaultWindowId, _)); EXPECT_CALL(app_manager_mock_, OnHMILevelChanged(_, _, _)); state_ctrl_->OnApplicationRegistered(simple_app_, @@ -3194,9 +3321,9 @@ TEST_F(StateControllerImplTest, OnApplicationRegisteredEqualStates) { simple_app_); EXPECT_CALL(*simple_app_ptr_, app_id()).WillRepeatedly(Return(app_id)); - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillRepeatedly(Return(old_state)); - EXPECT_CALL(*simple_app_ptr_, AddHMIState(_)).Times(2); + EXPECT_CALL(*simple_app_ptr_, AddHMIState(kDefaultWindowId, _)).Times(2); const am::HmiStatePtr default_state = CreateHmiStateByHmiStateType( @@ -3205,9 +3332,9 @@ TEST_F(StateControllerImplTest, OnApplicationRegisteredEqualStates) { mobile_apis::VideoStreamingState::NOT_STREAMABLE, mobile_apis::SystemContext::SYSCTXT_MAIN, simple_app_); - EXPECT_CALL(*simple_app_ptr_, RegularHmiState()) + EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kDefaultWindowId)) .WillOnce(Return(default_state)); - EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) + EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kDefaultWindowId)) .WillRepeatedly(Return(default_state)); EXPECT_CALL(*simple_app_ptr_, ResetDataInNone()).Times(0); @@ -3218,6 +3345,328 @@ TEST_F(StateControllerImplTest, OnApplicationRegisteredEqualStates) { mobile_apis::HMILevel::HMI_BACKGROUND); } +TEST_F( + StateControllerImplTest, + SetRegularState_AppIsResumingAndAudioSourceIsActive_HmiStateIsNotChanged) { + am::event_engine::Event audio_source_event( + hmi_apis::FunctionID::BasicCommunication_OnEventChanged); + smart_objects::SmartObject message; + message[am::strings::msg_params][am::hmi_notification::is_active] = true; + message[am::strings::msg_params][am::hmi_notification::event_name] = + hmi_apis::Common_EventTypes::AUDIO_SOURCE; + audio_source_event.set_smart_object(message); + state_ctrl_->on_event(audio_source_event); + + EXPECT_CALL(*media_app_ptr_, is_resuming()).WillRepeatedly(Return(true)); + EXPECT_CALL(*media_app_ptr_, SetRegularState(_, _)).Times(0); + + const am::HmiStatePtr new_state = FullAudibleState(); + const bool send_activate_app = true; + state_ctrl_->SetRegularState( + media_app_, kDefaultWindowId, new_state, send_activate_app); +} + +TEST_F(StateControllerImplTest, + SetRegularState_BcActivateAppSendFailed_HmiLevelIsNotChanged) { + const am::HmiStatePtr new_state = FullAudibleState(); + SetBCActivateAppRequestToHMI( + static_cast(new_state->hmi_level()), + kCorrID); + + smart_objects::SmartObjectSPtr bc_activate_app_request; + EXPECT_CALL(message_helper_mock_, GetBCActivateAppRequestToHMI(_, _, _, _, _)) + .WillOnce(Return(bc_activate_app_request)); + EXPECT_CALL(*simple_app_ptr_, SetRegularState(_, _)).Times(0); + + const bool send_activate_app = true; + state_ctrl_->SetRegularState( + simple_app_, kDefaultWindowId, new_state, send_activate_app); +} + +TEST_F(StateControllerImplTest, + SetRegularState_SetLevelAudioAndVideoState_HmiStateIsChanged) { + HmiStatePtr old_state = NoneNotAudibleState(); + HmiStatePtr new_state = BackgroundState(); + + EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kDefaultWindowId)) + .WillOnce(Return(old_state)); + ExpectSuccessfulSetHmiState( + simple_app_, simple_app_ptr_, old_state, new_state); + + const bool send_activate_app = false; + state_ctrl_->SetRegularState(simple_app_, + kDefaultWindowId, + new_state->hmi_level(), + new_state->audio_streaming_state(), + new_state->video_streaming_state(), + send_activate_app); +} + +TEST_F(StateControllerImplTest, + SetRegularState_SetLevelAudioVideoStatesAndContext_HmiStateIsChanged) { + HmiStatePtr old_state = NoneNotAudibleState(); + HmiStatePtr new_state = BackgroundState(); + + EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kDefaultWindowId)) + .WillOnce(Return(old_state)); + ExpectSuccessfulSetHmiState( + simple_app_, simple_app_ptr_, old_state, new_state); + + const bool send_activate_app = false; + state_ctrl_->SetRegularState(simple_app_, + kDefaultWindowId, + new_state->hmi_level(), + new_state->audio_streaming_state(), + new_state->video_streaming_state(), + new_state->system_context(), + send_activate_app); +} + +TEST_F(StateControllerImplTest, + SetRegularState_SetSystemContextOnly_HmiStateIsChanged) { + HmiStatePtr old_state = FullAudibleState(); + HmiStatePtr new_state = FullNotAudibleState(); + + EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kDefaultWindowId)) + .WillOnce(Return(old_state)); + ExpectSuccessfulSetHmiState( + simple_app_, simple_app_ptr_, old_state, new_state); + + state_ctrl_->SetRegularState( + simple_app_, kDefaultWindowId, new_state->system_context()); +} + +TEST_F(StateControllerImplTest, + OnAppActivated_ActivateNotExistingWindow_HmiLevelIsNotChanged) { + InsertApplication(simple_app_); + + am::event_engine::Event activate_widget_event( + hmi_apis::FunctionID::BasicCommunication_OnAppActivated); + smart_objects::SmartObject message; + message[am::strings::msg_params][am::strings::app_id] = simple_app_id_; + message[am::strings::msg_params][am::strings::window_id] = kCustomWindowId; + activate_widget_event.set_smart_object(message); + + const am::WindowIds window_ids = {kDefaultWindowId}; + ON_CALL(*simple_app_ptr_, GetWindowIds()).WillByDefault(Return(window_ids)); + + ExpectAppWontChangeHmiStateDueToConflictResolving( + simple_app_, simple_app_ptr_, kCustomWindowId, NoneNotAudibleState()); + + state_ctrl_->on_event(activate_widget_event); +} + +TEST_F(StateControllerImplTest, + OnAppActivated_ActivateCustomWindow_HmiStateIsChanged) { + InsertApplication(simple_app_); + + am::event_engine::Event activate_widget_event( + hmi_apis::FunctionID::BasicCommunication_OnAppActivated); + smart_objects::SmartObject message; + message[am::strings::msg_params][am::strings::app_id] = simple_app_id_; + message[am::strings::msg_params][am::strings::window_id] = kCustomWindowId; + activate_widget_event.set_smart_object(message); + + const am::WindowIds window_ids = {kDefaultWindowId, kCustomWindowId}; + ON_CALL(*simple_app_ptr_, GetWindowIds()).WillByDefault(Return(window_ids)); + + std::vector > states_transition = { + std::make_pair(NoneNotAudibleState(), BackgroundState()), + std::make_pair(BackgroundState(), FullNotAudibleState())}; + + for (auto& states_pair : states_transition) { + HmiStatePtr old_state = states_pair.first; + HmiStatePtr new_state = states_pair.second; + + EXPECT_CALL(*simple_app_ptr_, hmi_level(kCustomWindowId)) + .WillOnce(Return(old_state->hmi_level())); + EXPECT_CALL(*simple_app_ptr_, audio_streaming_state()) + .WillOnce(Return(old_state->audio_streaming_state())); + EXPECT_CALL(*simple_app_ptr_, video_streaming_state()) + .WillOnce(Return(old_state->video_streaming_state())); + + EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kCustomWindowId)) + .WillOnce(Return(old_state)); + ExpectSuccessfulSetHmiState( + simple_app_, simple_app_ptr_, kCustomWindowId, old_state, new_state); + + EXPECT_CALL(message_helper_mock_, + GetBCActivateAppRequestToHMI(_, _, _, _, _)) + .Times(0); + + state_ctrl_->on_event(activate_widget_event); + } +} + +TEST_F(StateControllerImplTest, + OnAppDeactivated_DeactivateNotExistingWindow_HmiStateIsNotChanged) { + InsertApplication(simple_app_); + + am::event_engine::Event activate_widget_event( + hmi_apis::FunctionID::BasicCommunication_OnAppDeactivated); + smart_objects::SmartObject message; + message[am::strings::msg_params][am::strings::app_id] = simple_app_id_; + message[am::strings::msg_params][am::strings::window_id] = kCustomWindowId; + activate_widget_event.set_smart_object(message); + + const am::WindowIds window_ids = {kDefaultWindowId}; + ON_CALL(*simple_app_ptr_, GetWindowIds()).WillByDefault(Return(window_ids)); + + ExpectAppWontChangeHmiStateDueToConflictResolving( + simple_app_, simple_app_ptr_, kCustomWindowId, FullNotAudibleState()); + + state_ctrl_->on_event(activate_widget_event); +} + +TEST_F(StateControllerImplTest, + OnAppDeactivated_DeactivateCustomWindow_HmiStateIsChanged) { + InsertApplication(simple_app_); + + am::event_engine::Event activate_widget_event( + hmi_apis::FunctionID::BasicCommunication_OnAppDeactivated); + smart_objects::SmartObject message; + message[am::strings::msg_params][am::strings::app_id] = simple_app_id_; + message[am::strings::msg_params][am::strings::window_id] = kCustomWindowId; + activate_widget_event.set_smart_object(message); + + const am::WindowIds window_ids = {kDefaultWindowId, kCustomWindowId}; + ON_CALL(*simple_app_ptr_, GetWindowIds()).WillByDefault(Return(window_ids)); + + std::vector > states_transition = { + std::make_pair(FullNotAudibleState(), BackgroundState()), + std::make_pair(BackgroundState(), NoneNotAudibleState())}; + + for (auto& states_pair : states_transition) { + HmiStatePtr old_state = states_pair.first; + HmiStatePtr new_state = states_pair.second; + + EXPECT_CALL(*simple_app_ptr_, hmi_level(kCustomWindowId)) + .WillOnce(Return(old_state->hmi_level())); + EXPECT_CALL(*simple_app_ptr_, audio_streaming_state()) + .WillOnce(Return(old_state->audio_streaming_state())); + EXPECT_CALL(*simple_app_ptr_, video_streaming_state()) + .WillOnce(Return(old_state->video_streaming_state())); + + EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kCustomWindowId)) + .WillOnce(Return(old_state)); + ExpectSuccessfulSetHmiState( + simple_app_, simple_app_ptr_, kCustomWindowId, old_state, new_state); + + EXPECT_CALL(message_helper_mock_, + GetBCActivateAppRequestToHMI(_, _, _, _, _)) + .Times(0); + + state_ctrl_->on_event(activate_widget_event); + } +} + +TEST_F( + StateControllerImplTest, + ActivateDefaultWindow_AppWithWindowWasActivated_WindowStreamingStateIsUpdated) { + HmiStatePtr old_state = NoneNotAudibleState(); + HmiStatePtr new_state = FullAudibleState(); + + EXPECT_CALL(*media_app_ptr_, RegularHmiState(kDefaultWindowId)) + .WillOnce(Return(old_state)) + .WillRepeatedly(Return(new_state)); + ExpectSuccessfulSetHmiState( + media_app_, media_app_ptr_, kDefaultWindowId, old_state, new_state); + + const am::WindowIds window_ids = {kDefaultWindowId, kCustomWindowId}; + ON_CALL(*media_app_ptr_, GetWindowIds()).WillByDefault(Return(window_ids)); + + EXPECT_CALL(*media_app_ptr_, RegularHmiState(kCustomWindowId)) + .WillOnce(Return(old_state)); + + HmiStatePtr expected_window_state = NoneNotAudibleState(); + expected_window_state->set_audio_streaming_state( + new_state->audio_streaming_state()); + expected_window_state->set_video_streaming_state( + new_state->video_streaming_state()); + + EXPECT_CALL( + *media_app_ptr_, + SetRegularState(kCustomWindowId, + Truly(HmiStatesComparator(expected_window_state)))); + EXPECT_CALL(message_helper_mock_, + SendHMIStatusNotification(media_app_, kCustomWindowId, _)); + + state_ctrl_->ActivateDefaultWindow(media_app_); +} + +TEST_F(StateControllerImplTest, + ExitDefaultWindow_AppWithWindowWasExited_WindowStreamingStateIsUpdated) { + HmiStatePtr old_state = FullAudibleState(); + HmiStatePtr new_state = NoneNotAudibleState(); + + EXPECT_CALL(*media_app_ptr_, RegularHmiState(kDefaultWindowId)) + .WillOnce(Return(old_state)) + .WillRepeatedly(Return(new_state)); + ExpectSuccessfulSetHmiState( + media_app_, media_app_ptr_, kDefaultWindowId, old_state, new_state); + + const am::WindowIds window_ids = {kDefaultWindowId, kCustomWindowId}; + ON_CALL(*media_app_ptr_, GetWindowIds()).WillByDefault(Return(window_ids)); + + EXPECT_CALL(*media_app_ptr_, RegularHmiState(kCustomWindowId)) + .WillOnce(Return(old_state)); + + HmiStatePtr expected_window_state = FullAudibleState(); + expected_window_state->set_audio_streaming_state( + new_state->audio_streaming_state()); + expected_window_state->set_video_streaming_state( + new_state->video_streaming_state()); + + EXPECT_CALL( + *media_app_ptr_, + SetRegularState(kCustomWindowId, + Truly(HmiStatesComparator(expected_window_state)))); + EXPECT_CALL(message_helper_mock_, + SendHMIStatusNotification(media_app_, kCustomWindowId, _)); + + state_ctrl_->ExitDefaultWindow(media_app_); +} + +TEST_F(StateControllerImplTest, + OnAppWindowAdded_NewAppWindowWasAdded_HmiNotificationIsSent) { + am::event_engine::Event audio_source_event( + hmi_apis::FunctionID::BasicCommunication_OnEventChanged); + smart_objects::SmartObject message; + message[am::strings::msg_params][am::hmi_notification::is_active] = true; + message[am::strings::msg_params][am::hmi_notification::event_name] = + hmi_apis::Common_EventTypes::AUDIO_SOURCE; + audio_source_event.set_smart_object(message); + state_ctrl_->on_event(audio_source_event); + + HmiStatePtr initial_state = + createHmiState(mobile_apis::HMILevel::INVALID_ENUM, + mobile_apis::AudioStreamingState::INVALID_ENUM, + mobile_apis::VideoStreamingState::INVALID_ENUM, + mobile_apis::SystemContext::INVALID_ENUM); + HmiStatePtr expected_state = NoneNotAudibleState(); + + EXPECT_CALL(*simple_app_ptr_, + AddHMIState(kCustomWindowId, + Truly(HmiStatesIDComparator( + HmiState::StateID::STATE_ID_AUDIO_SOURCE)))); + EXPECT_CALL(*simple_app_ptr_, RegularHmiState(kCustomWindowId)) + .WillOnce(Return(initial_state)); + EXPECT_CALL(*simple_app_ptr_, + SetRegularState(kCustomWindowId, + Truly(HmiStatesComparator(expected_state)))); + EXPECT_CALL(*simple_app_ptr_, CurrentHmiState(kCustomWindowId)) + .WillOnce(Return(initial_state)) + .WillOnce(Return(expected_state)); + EXPECT_CALL(message_helper_mock_, + SendHMIStatusNotification(simple_app_, kCustomWindowId, _)); + EXPECT_CALL(app_manager_mock_, OnHMILevelChanged(_, _, _)).Times(0); + + state_ctrl_->OnAppWindowAdded(simple_app_, + kCustomWindowId, + mobile_apis::WindowType::WIDGET, + mobile_apis::HMILevel::HMI_NONE); +} + } // namespace state_controller_test } // namespace components } // namespace test diff --git a/src/components/include/application_manager/application_manager.h b/src/components/include/application_manager/application_manager.h index 022c46615e..cfabd3c6d6 100644 --- a/src/components/include/application_manager/application_manager.h +++ b/src/components/include/application_manager/application_manager.h @@ -702,6 +702,7 @@ class ApplicationManager { /** * @brief CreateRegularState create regular HMI state for application * @param app Application + * @param window_type type of window * @param hmi_level of returned state * @param audio_state of returned state * @param system_context of returned state @@ -709,10 +710,11 @@ class ApplicationManager { */ virtual HmiStatePtr CreateRegularState( std::shared_ptr app, - mobile_apis::HMILevel::eType hmi_level, - mobile_apis::AudioStreamingState::eType audio_state, - mobile_apis::VideoStreamingState::eType video_state, - mobile_apis::SystemContext::eType system_context) const = 0; + const mobile_apis::WindowType::eType window_type, + const mobile_apis::HMILevel::eType hmi_level, + const mobile_apis::AudioStreamingState::eType audio_state, + const mobile_apis::VideoStreamingState::eType video_state, + const mobile_apis::SystemContext::eType system_context) const = 0; /** * @brief Checks if application can stream (streaming service is started and diff --git a/src/components/include/application_manager/state_controller.h b/src/components/include/application_manager/state_controller.h index fa0d65eb0c..2fa4b0c218 100644 --- a/src/components/include/application_manager/state_controller.h +++ b/src/components/include/application_manager/state_controller.h @@ -41,47 +41,144 @@ namespace application_manager { class StateController { public: + /** + * @brief SetRegularState setup regular hmi state, that will appear if + * no specific events are active + * @param app appication to setup regular State + * @param window_id id of applicaion's window to apply HMI state + * @param state state of new regular state + * @param request_hmi_state_change: if true, ActivateAppRequest or + * CloseApplication will be sent to HMI dependent on hmi level of resolved hmi + * state + */ virtual void SetRegularState(ApplicationSharedPtr app, + const WindowID window_id, HmiStatePtr state, const bool request_hmi_state_change) = 0; + /** + * @brief SetRegularState Change regular hmi level and audio state + * @param app appication to setup regular State + * @param window_id id of applicaion's window to apply HMI state + * @param hmi_level of new regular state + * @param audio_state of new regular state + * @paran video_state of new regular state + * @param request_hmi_state_change: if true, ActivateAppRequest or + * CloseApplication will be sent to HMI dependent on hmi level of resolved hmi + * state + */ virtual void 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) = 0; + /** + * @brief SetRegularState Change regular hmi level + * @param app appication to setup regular State + * @param window_id id of applicaion's window to apply HMI state + * @param hmi_level of new regular state + * @param request_hmi_state_change: if true, ActivateAppRequest or + * CloseApplication will be sent to HMI dependent on hmi level of resolved hmi + * state + */ virtual void SetRegularState(ApplicationSharedPtr app, + const WindowID window_id, const mobile_apis::HMILevel::eType hmi_level, const bool request_hmi_state_change) = 0; + /** + * @brief SetRegularState Change regular hmi level, audio state and system + * context + * @param app appication to setup regular State + * @param window_id id of applicaion's window to apply HMI state + * @param hmi_level of new regular state + * @param audio_state of new regular state + * @param video_state of new regular state + * @param system_context of new regular state + * @param request_hmi_state_change: if true, ActivateAppRequest or + * CloseApplication will be sent to HMI dependent on hmi level of resolved hmi + * state + */ virtual void 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 mobile_apis::SystemContext::eType system_context, const bool request_hmi_state_change) = 0; + /** + * @brief SetRegularState Sets regular state with new hmi level + * to application + * @param app appication to setup regular state + * @param window_id id of applicaion's window to apply HMI state + * @param hmi_level new hmi level for application + */ virtual void SetRegularState( ApplicationSharedPtr app, + const WindowID window_id, const mobile_apis::HMILevel::eType hmi_level) = 0; + /** + * @brief SetRegularState Change regular audio state + * @param app appication to setup regular State + * @param window_id id of applicaion's window to apply HMI state + * @param audio_state of new regular state + * @param video_state of new regular state + */ virtual void SetRegularState( ApplicationSharedPtr app, + const WindowID window_id, const mobile_apis::AudioStreamingState::eType audio_state, const mobile_apis::VideoStreamingState::eType video_state) = 0; + /** + * @brief SetRegularState Change regular system context + * @param app appication to setup regular State + * @param window_id id of applicaion's window to apply HMI state + * @param system_context of new regular state + */ virtual void SetRegularState( ApplicationSharedPtr app, + const WindowID window_id, const mobile_apis::SystemContext::eType system_context) = 0; - virtual void SetRegularState(ApplicationSharedPtr app, HmiStatePtr state) = 0; + /** + * @brief SetRegularState Sets new regular state to application + * @param app appication to setup regular state + * @param window_id id of applicaion's window to apply HMI state + * @param state new hmi state for application + */ + virtual void SetRegularState(ApplicationSharedPtr app, + const WindowID window_id, + HmiStatePtr state) = 0; + /** + * @brief Sets default application state and apply currently active HMI states + * on application registration + * @param app application to apply states + * @param default_level default HMI level + */ virtual void OnApplicationRegistered( ApplicationSharedPtr app, const mobile_apis::HMILevel::eType default_level) = 0; + /** + * @brief OnAppWidgetAdded Sets default state for widget and apply currently + * active HMI states + * @param app application to apply states + * @param window_id id of window to add + * @param default_level default HMI level + */ + virtual void OnAppWindowAdded( + ApplicationSharedPtr app, + const WindowID window_id, + const mobile_apis::WindowType::eType window_type, + const mobile_apis::HMILevel::eType default_level) = 0; + /** * @brief OnVideoStreamingStarted process video streaming started * @param app projection or navigation application starting streaming @@ -93,12 +190,41 @@ class StateController { * @param app projection or navigation application stopping streaming */ virtual void OnVideoStreamingStopped(ApplicationConstSharedPtr app) = 0; + + /** + * @brief OnStateChanged send HMIStatusNotification if needed + * @param app application + * @param window_id id of applicaion's window to apply HMI state + * @param old_state state before change + * @param new_state state after change + */ virtual void OnStateChanged(ApplicationSharedPtr app, + const WindowID window_id, HmiStatePtr old_state, HmiStatePtr new_state) = 0; + /** + * @brief Checks activity of Deactivate HMI state. + * @return Returns TRUE if deactivate HMI state is active, otherwise returns + * FALSE. + */ virtual bool IsStateActive(HmiState::StateID state_id) const = 0; + + /** + * @brief ActivateDefaultWindow performs set of actions required for a proper + * application activation (i.e. main window activation) + * @param app pointer to application to be activated + */ + virtual void ActivateDefaultWindow(ApplicationSharedPtr app) = 0; + + /** + * @brief ExitDefaultWindow performs set of action required for a proper + * application exiting (i.e. main window exit) + * @param app pointer to application to be exited + */ + virtual void ExitDefaultWindow(ApplicationSharedPtr app) = 0; }; + } // namespace application_manager #endif // SRC_COMPONENTS_INCLUDE_APPLICATION_MANAGER_STATE_CONTROLLER_H_ diff --git a/src/components/include/test/application_manager/mock_state_controller.h b/src/components/include/test/application_manager/mock_state_controller.h index 20a84e7f00..545090bf30 100644 --- a/src/components/include/test/application_manager/mock_state_controller.h +++ b/src/components/include/test/application_manager/mock_state_controller.h @@ -46,55 +46,68 @@ namespace am = application_manager; class MockStateController : public am::StateController { public: - MOCK_METHOD3(SetRegularState, + MOCK_METHOD4(SetRegularState, void(am::ApplicationSharedPtr app, + const am::WindowID window_id, am::HmiStatePtr state, const bool request_hmi_state_change)); - MOCK_METHOD5(SetRegularState, + MOCK_METHOD6(SetRegularState, void(am::ApplicationSharedPtr app, + const am::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)); - MOCK_METHOD3(SetRegularState, + MOCK_METHOD4(SetRegularState, void(am::ApplicationSharedPtr app, + const am::WindowID window_id, const mobile_apis::HMILevel::eType hmi_level, const bool request_hmi_state_change)); - MOCK_METHOD6(SetRegularState, + MOCK_METHOD7(SetRegularState, void(am::ApplicationSharedPtr app, + const am::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 mobile_apis::SystemContext::eType system_context, const bool request_hmi_state_change)); - MOCK_METHOD2(SetRegularState, + MOCK_METHOD3(SetRegularState, void(am::ApplicationSharedPtr app, + const am::WindowID window_id, const mobile_apis::HMILevel::eType hmi_level)); - MOCK_METHOD3(SetRegularState, + MOCK_METHOD4(SetRegularState, void(am::ApplicationSharedPtr app, + const am::WindowID window_id, const mobile_apis::AudioStreamingState::eType audio_state, const mobile_apis::VideoStreamingState::eType video_state)); - MOCK_METHOD2(SetRegularState, + MOCK_METHOD3(SetRegularState, void(am::ApplicationSharedPtr app, + const am::WindowID window_id, const mobile_apis::SystemContext::eType system_context)); - MOCK_METHOD2(SetRegularState, - void(am::ApplicationSharedPtr app, am::HmiStatePtr state)); + MOCK_METHOD3(SetRegularState, + void(am::ApplicationSharedPtr app, + const am::WindowID window_id, + am::HmiStatePtr state)); MOCK_METHOD2(OnApplicationRegistered, void(am::ApplicationSharedPtr app, const mobile_apis::HMILevel::eType default_level)); - MOCK_METHOD3(RequestHMIStateChange, - int64_t(am::ApplicationConstSharedPtr app, - hmi_apis::Common_HMILevel::eType level, - bool send_policy_priority)); + MOCK_METHOD4(OnAppWindowAdded, + void(am::ApplicationSharedPtr app, + const am::WindowID window_id, + const mobile_apis::WindowType::eType window_type, + const mobile_apis::HMILevel::eType default_level)); MOCK_METHOD1(OnVideoStreamingStarted, void(am::ApplicationConstSharedPtr app)); MOCK_METHOD1(OnVideoStreamingStopped, void(am::ApplicationConstSharedPtr app)); - MOCK_METHOD3(OnStateChanged, + MOCK_METHOD4(OnStateChanged, void(am::ApplicationSharedPtr app, + const am::WindowID window_id, am::HmiStatePtr old_state, am::HmiStatePtr new_state)); MOCK_CONST_METHOD1(IsStateActive, bool(am::HmiState::StateID state_id)); + MOCK_METHOD1(ActivateDefaultWindow, void(am::ApplicationSharedPtr app)); + MOCK_METHOD1(ExitDefaultWindow, void(am::ApplicationSharedPtr app)); }; } // namespace application_manager_test -- cgit v1.2.1