diff options
author | Serhii Niukalov (GitHub) <36993782+SNiukalov@users.noreply.github.com> | 2020-03-19 18:16:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-19 12:16:54 -0400 |
commit | 15b80391c957d7cc16bce40ff69b14fb1958a3f6 (patch) | |
tree | b0c1690cb572880a4ea362470fed147b78dedb3d | |
parent | 9bc0cfd17259601f8e9eb71724b29cecf3d15be0 (diff) | |
download | sdl_core-15b80391c957d7cc16bce40ff69b14fb1958a3f6.tar.gz |
Fix/consider timeouts during streaming switching (#3293)
* Consider video and audio status before send end of service
Co-authored-by: sniukalov <sniukaov@luxoft.com>
6 files changed, 79 insertions, 9 deletions
diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index 0bab0243d0..1e171ed81b 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -834,12 +834,12 @@ class ApplicationManagerImpl */ void EndNaviServices(uint32_t app_id) OVERRIDE; - /** - * @brief ForbidStreaming forbid the stream over the certain application. - * @param app_id the application's id which should stop streaming. - */ + DEPRECATED void ForbidStreaming(uint32_t app_id) OVERRIDE; + void ForbidStreaming(uint32_t app_id, + protocol_handler::ServiceType service_type) OVERRIDE; + /** * @brief Called when application completes streaming configuration * @param app_id Streaming application id diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 303dca3b65..344240add9 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -3510,6 +3510,65 @@ void ApplicationManagerImpl::ForbidStreaming(uint32_t app_id) { EndNaviServices(app_id); } +void ApplicationManagerImpl::ForbidStreaming( + uint32_t app_id, protocol_handler::ServiceType service_type) { + using namespace mobile_apis::AppInterfaceUnregisteredReason; + using namespace mobile_apis::Result; + using namespace protocol_handler; + + LOG4CXX_AUTO_TRACE(logger_); + + ApplicationSharedPtr app = application(app_id); + if (!app || (!app->is_navi() && !app->mobile_projection_enabled())) { + LOG4CXX_DEBUG( + logger_, + "There is no navi or projection application with id: " << app_id); + return; + } + + if (navi_app_to_stop_.end() != std::find(navi_app_to_stop_.begin(), + navi_app_to_stop_.end(), + app_id) || + navi_app_to_end_stream_.end() != + std::find(navi_app_to_end_stream_.begin(), + navi_app_to_end_stream_.end(), + app_id)) { + return; + } + + bool unregister = false; + { + sync_primitives::AutoLock lock(navi_service_status_lock_); + + NaviServiceStatusMap::iterator it = navi_service_status_.find(app_id); + if (navi_service_status_.end() == it || + (!it->second.first && !it->second.second)) { + unregister = true; + } + } + if (unregister) { + rpc_service_->ManageMobileCommand( + MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile( + app_id, PROTOCOL_VIOLATION), + commands::Command::SOURCE_SDL); + UnregisterApplication(app_id, ABORTED); + return; + } + + if (ServiceType::kMobileNav == service_type && + app->video_streaming_allowed()) { + LOG4CXX_DEBUG(logger_, "Video streaming is still allowed"); + return; + } + + if (ServiceType::kAudio == service_type && app->audio_streaming_allowed()) { + LOG4CXX_DEBUG(logger_, "Audio streaming is still allowed"); + return; + } + + EndNaviServices(app_id); +} + void ApplicationManagerImpl::OnAppStreaming( uint32_t app_id, protocol_handler::ServiceType service_type, bool state) { LOG4CXX_AUTO_TRACE(logger_); diff --git a/src/components/include/application_manager/application_manager.h b/src/components/include/application_manager/application_manager.h index 31729aad75..a3aace0f3f 100644 --- a/src/components/include/application_manager/application_manager.h +++ b/src/components/include/application_manager/application_manager.h @@ -785,11 +785,16 @@ class ApplicationManager { virtual bool CanAppStream( uint32_t app_id, protocol_handler::ServiceType service_type) const = 0; + DEPRECATED + virtual void ForbidStreaming(uint32_t app_id) = 0; + /** * @brief ForbidStreaming forbid the stream over the certain application. * @param app_id the application's id which should stop streaming. + * @param service_type Service type to check */ - virtual void ForbidStreaming(uint32_t app_id) = 0; + virtual void ForbidStreaming(uint32_t app_id, + protocol_handler::ServiceType service_type) = 0; /** * @brief Called when application completes streaming configuration diff --git a/src/components/include/test/application_manager/mock_application_manager.h b/src/components/include/test/application_manager/mock_application_manager.h index 5e9b65fec5..3bd3b9b7d6 100644 --- a/src/components/include/test/application_manager/mock_application_manager.h +++ b/src/components/include/test/application_manager/mock_application_manager.h @@ -321,7 +321,11 @@ class MockApplicationManager : public application_manager::ApplicationManager { MOCK_CONST_METHOD2(CanAppStream, bool(uint32_t app_id, protocol_handler::ServiceType service_type)); + DEPRECATED MOCK_METHOD1(ForbidStreaming, void(uint32_t app_id)); + MOCK_METHOD2(ForbidStreaming, + void(uint32_t app_id, + protocol_handler::ServiceType service_type)); MOCK_CONST_METHOD0(get_settings, const application_manager::ApplicationManagerSettings&()); MOCK_CONST_METHOD1( diff --git a/src/components/media_manager/src/media_manager_impl.cc b/src/components/media_manager/src/media_manager_impl.cc index 44f9601242..b04381605d 100644 --- a/src/components/media_manager/src/media_manager_impl.cc +++ b/src/components/media_manager/src/media_manager_impl.cc @@ -313,9 +313,11 @@ void MediaManagerImpl::OnMessageReceived( } if (!application_manager_.CanAppStream(streaming_app_id, service_type)) { - application_manager_.ForbidStreaming(streaming_app_id); + application_manager_.ForbidStreaming(streaming_app_id, service_type); LOG4CXX_ERROR(logger_, - "The application trying to stream when it should not."); + "The application is trying to stream when it should not." + " service type: " + << service_type); return; } diff --git a/src/components/media_manager/test/media_manager_impl_test.cc b/src/components/media_manager/test/media_manager_impl_test.cc index ff35ac7dbb..627e2f57ed 100644 --- a/src/components/media_manager/test/media_manager_impl_test.cc +++ b/src/components/media_manager/test/media_manager_impl_test.cc @@ -246,7 +246,7 @@ TEST_F(MediaManagerImplTest, const ServiceType audio_type = ServiceType::kAudio; EXPECT_CALL(app_mngr_, CanAppStream(kConnectionKey, audio_type)) .WillOnce(Return(false)); - EXPECT_CALL(app_mngr_, ForbidStreaming(kConnectionKey)); + EXPECT_CALL(app_mngr_, ForbidStreaming(kConnectionKey, audio_type)); EmulateMobileMessage(audio_type); } @@ -255,7 +255,7 @@ TEST_F(MediaManagerImplTest, const ServiceType video_type = ServiceType::kMobileNav; EXPECT_CALL(app_mngr_, CanAppStream(kConnectionKey, video_type)) .WillOnce(Return(false)); - EXPECT_CALL(app_mngr_, ForbidStreaming(kConnectionKey)); + EXPECT_CALL(app_mngr_, ForbidStreaming(kConnectionKey, video_type)); EmulateMobileMessage(video_type); } |