diff options
author | jacobkeeler <jacob.keeler@livioradio.com> | 2018-09-18 16:19:33 -0400 |
---|---|---|
committer | jacobkeeler <jacob.keeler@livioradio.com> | 2018-09-18 16:19:33 -0400 |
commit | 8fe9d54458b162fb9eb895a45a02af5656b655b0 (patch) | |
tree | 919953e4a7bee40b2239906357f219cecc9b00a3 | |
parent | ed95b345449e132c94d6ee23625c9846d94f23af (diff) | |
download | sdl_core-8fe9d54458b162fb9eb895a45a02af5656b655b0.tar.gz |
Add keepContext logic to AudioSource HMI Statefix/video_streaming_in_background
8 files changed, 62 insertions, 31 deletions
diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index c3a4ecbb30..ad7570955e 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -589,6 +589,18 @@ class Application : public virtual InitialApplicationData, * @return flag tts_properties_in_full */ virtual bool tts_properties_in_full() = 0; + /** + * @brief sets true if application should keep it's HMI Level after an audio + * source change + * @param value of keep context + */ + virtual void set_keep_context(bool keep_context) = 0; + /** + * @brief returns true if application should keep keep it's HMI Level after + * an audio source change, otherwise return false + * @return value of keep_context flag + */ + virtual bool keep_context() = 0; virtual void set_version(const Version& version) = 0; virtual void set_name(const custom_str::CustomString& name) = 0; virtual void set_is_media_application(bool is_media) = 0; diff --git a/src/components/application_manager/include/application_manager/application_impl.h b/src/components/application_manager/include/application_manager/application_impl.h index f937ebebe1..8dc3b2da20 100644 --- a/src/components/application_manager/include/application_manager/application_impl.h +++ b/src/components/application_manager/include/application_manager/application_impl.h @@ -177,6 +177,8 @@ class ApplicationImpl : public virtual Application, bool tts_properties_in_none(); void set_tts_properties_in_full(bool active); bool tts_properties_in_full(); + void set_keep_context(bool keep_context); + bool keep_context(); void set_version(const Version& ver); void set_name(const custom_str::CustomString& name); void set_is_media_application(bool is_media); @@ -481,6 +483,7 @@ class ApplicationImpl : public virtual Application, bool has_been_activated_; bool tts_properties_in_none_; bool tts_properties_in_full_; + bool keep_context_; bool is_foreground_; bool is_application_data_changed_; uint32_t put_file_in_none_count_; diff --git a/src/components/application_manager/include/application_manager/hmi_state.h b/src/components/application_manager/include/application_manager/hmi_state.h index 4b7779e08c..07d9c8dc23 100644 --- a/src/components/application_manager/include/application_manager/hmi_state.h +++ b/src/components/application_manager/include/application_manager/hmi_state.h @@ -368,6 +368,9 @@ class AudioSource : public HmiState { const OVERRIDE { return mobile_apis::VideoStreamingState::NOT_STREAMABLE; } + + private: + bool keep_context_; }; /** diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc index cfd8caae39..0473dd1791 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc @@ -506,13 +506,20 @@ void SetInteriorVehicleDataRequest::Execute() { module_data[message_params::kAudioControlData].keyExists( message_params::kSource); - if (app_wants_to_set_audio_src && !app->IsAllowedToChangeAudioSource()) { - LOG4CXX_WARN(logger_, "App is not allowed to change audio source"); - SetResourceState(ModuleType(), ResourceState::FREE); - SendResponse(false, - mobile_apis::Result::REJECTED, - "App is not allowed to change audio source"); - return; + if (app_wants_to_set_audio_src) { + if (!app->IsAllowedToChangeAudioSource()) { + LOG4CXX_WARN(logger_, "App is not allowed to change audio source"); + SetResourceState(ModuleType(), ResourceState::FREE); + SendResponse(false, + mobile_apis::Result::REJECTED, + "App is not allowed to change audio source"); + return; + } else if (module_data[message_params::kAudioControlData].keyExists( + message_params::kKeepContext)) { + app->set_keep_context( + module_data[message_params::kAudioControlData] + [message_params::kKeepContext].asBool()); + } } SendHMIRequest(hmi_apis::FunctionID::RC_SetInteriorVehicleData, @@ -555,6 +562,10 @@ void SetInteriorVehicleDataRequest::on_event( *message_)[app_mngr::strings::msg_params][message_params::kModuleData] [message_params::kAudioControlData]); } + } else { + app_mngr::ApplicationSharedPtr app = + application_manager_.application(connection_key()); + app->set_keep_context(false); } std::string info; GetInfo(hmi_response, info); @@ -580,27 +591,10 @@ const smart_objects::SmartObject& SetInteriorVehicleDataRequest::ControlData( void SetInteriorVehicleDataRequest::CheckAudioSource( const smart_objects::SmartObject& audio_data) { LOG4CXX_AUTO_TRACE(logger_); - const bool should_keep_context = - audio_data.keyExists(message_params::kKeepContext) && - audio_data[message_params::kKeepContext].asBool(); - const bool switch_source_from_app = - mobile_apis::PrimaryAudioSource::MOBILE_APP == - application_manager_.get_current_audio_source() && - mobile_apis::PrimaryAudioSource::MOBILE_APP != - audio_data[message_params::kSource].asInt(); - if (!should_keep_context && switch_source_from_app) { - app_mngr::ApplicationSharedPtr app = - application_manager_.application(connection_key()); - if (app->mobile_projection_enabled()) { - application_manager_.ChangeAppsHMILevel( - app->app_id(), mobile_apis::HMILevel::eType::HMI_LIMITED); - } else { - application_manager_.ChangeAppsHMILevel( - app->app_id(), mobile_apis::HMILevel::eType::HMI_BACKGROUND); - } + if (audio_data.keyExists(message_params::kSource)) { + application_manager_.set_current_audio_source( + audio_data[message_params::kSource].asUInt()); } - application_manager_.set_current_audio_source( - audio_data[message_params::kSource].asUInt()); } bool SetInteriorVehicleDataRequest::AreAllParamsReadOnly( diff --git a/src/components/application_manager/src/application_impl.cc b/src/components/application_manager/src/application_impl.cc index 1168d94245..8a611195c7 100644 --- a/src/components/application_manager/src/application_impl.cc +++ b/src/components/application_manager/src/application_impl.cc @@ -116,6 +116,7 @@ ApplicationImpl::ApplicationImpl( , has_been_activated_(false) , tts_properties_in_none_(false) , tts_properties_in_full_(false) + , keep_context_(false) , is_foreground_(false) , is_application_data_changed_(false) , put_file_in_none_count_(0) @@ -438,6 +439,14 @@ bool ApplicationImpl::tts_properties_in_full() { return tts_properties_in_full_; } +void ApplicationImpl::set_keep_context(bool keep_context) { + keep_context_ = keep_context; +} + +bool ApplicationImpl::keep_context() { + return keep_context_; +} + void ApplicationImpl::set_video_streaming_approved(bool state) { video_streaming_approved_ = state; } diff --git a/src/components/application_manager/src/hmi_state.cc b/src/components/application_manager/src/hmi_state.cc index 41850a3ef2..7be9668543 100644 --- a/src/components/application_manager/src/hmi_state.cc +++ b/src/components/application_manager/src/hmi_state.cc @@ -199,13 +199,17 @@ mobile_apis::HMILevel::eType DeactivateHMI::hmi_level() const { AudioSource::AudioSource(std::shared_ptr<Application> app, const ApplicationManager& app_mngr) - : HmiState(app, app_mngr, STATE_ID_AUDIO_SOURCE) {} + : HmiState(app, app_mngr, STATE_ID_AUDIO_SOURCE) + , keep_context_(app->keep_context()) { + app_->set_keep_context(false); +} mobile_apis::HMILevel::eType AudioSource::hmi_level() const { // Checking for NONE is necessary to avoid issue during // calculation of HMI level during setting default HMI level - if (mobile_apis::HMILevel::HMI_NONE == parent()->hmi_level()) { - return mobile_apis::HMILevel::HMI_NONE; + if (keep_context_ || + mobile_apis::HMILevel::HMI_NONE == parent()->hmi_level()) { + return parent()->hmi_level(); } return mobile_apis::HMILevel::HMI_BACKGROUND; diff --git a/src/components/application_manager/test/include/application_manager/mock_application.h b/src/components/application_manager/test/include/application_manager/mock_application.h index d7552060ff..fe16e8ce6e 100644 --- a/src/components/application_manager/test/include/application_manager/mock_application.h +++ b/src/components/application_manager/test/include/application_manager/mock_application.h @@ -118,6 +118,8 @@ class MockApplication : public ::application_manager::Application { MOCK_METHOD0(tts_properties_in_none, bool()); MOCK_METHOD1(set_tts_properties_in_full, void(bool active)); MOCK_METHOD0(tts_properties_in_full, bool()); + MOCK_METHOD1(set_keep_context, void(bool keep_context)); + MOCK_METHOD0(keep_context, bool()); MOCK_METHOD1(set_version, void(const ::application_manager::Version& version)); MOCK_METHOD1(set_name, void(const custom_str::CustomString& name)); 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 3731848d89..1d4cead52b 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 @@ -2830,7 +2830,8 @@ TEST_F(StateControllerImplTest, state_ctrl_->SetRegularState(navi_app_, hmi_state, true); } -TEST_F(StateControllerImplTest, OnEventChangedAudioSourceAppRemainInFull) { +TEST_F(StateControllerImplTest, + OnEventChangedAudioSource_KeepContext_AppRemainInFull) { const uint32_t app_id = simple_app_->app_id(); InsertApplication(simple_app_); smart_objects::SmartObject msg; @@ -2849,11 +2850,14 @@ TEST_F(StateControllerImplTest, OnEventChangedAudioSourceAppRemainInFull) { mobile_apis::AudioStreamingState::AUDIBLE, mobile_apis::VideoStreamingState::NOT_STREAMABLE, mobile_apis::SystemContext::SYSCTXT_MAIN); + + EXPECT_CALL(*simple_app_ptr_, keep_context()).WillOnce(Return(true)); EXPECT_CALL(*simple_app_ptr_, RegularHmiState()).WillOnce(Return(state)); EXPECT_CALL(*simple_app_ptr_, IsAudioApplication()) .WillRepeatedly(Return(true)); EXPECT_CALL(*simple_app_ptr_, CurrentHmiState()) .WillOnce(Return(FullAudibleState())); + EXPECT_CALL(*simple_app_ptr_, set_keep_context(false)); HmiStatePtr new_state; EXPECT_CALL(*simple_app_ptr_, AddHMIState(_)) |