diff options
author | Andrey Oleynik (GitHub) <aoleynik@luxoft.com> | 2017-11-15 15:53:19 +0200 |
---|---|---|
committer | Andrey Oleynik (GitHub) <aoleynik@luxoft.com> | 2017-11-27 09:28:50 +0200 |
commit | b4f2d82ef1632d3dd16821bd43b076e89e4bcadf (patch) | |
tree | 88909750254c0abab56141944588c39c74979685 | |
parent | 4960764ce95f0de854566af1de4fb0dac36a251d (diff) | |
download | sdl_core-b4f2d82ef1632d3dd16821bd43b076e89e4bcadf.tar.gz |
Fixes handling of way points un/subscription for transport switch case
In case app_id is used for way points subscription it being invalidated
on transport switch and SDL can't unsubscribe same application after
switch is done.
15 files changed, 139 insertions, 30 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 aa6184a5e2..edde88ec9a 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 @@ -312,6 +312,7 @@ class ApplicationManagerImpl bool IsAppTypeExistsInFullOrLimited(ApplicationConstSharedPtr app) const; /** + * DEPRECATED * @brief Checks if Application is subscribed for way points * @param Application AppID * @return true if Application is subscribed for way points @@ -320,18 +321,40 @@ class ApplicationManagerImpl bool IsAppSubscribedForWayPoints(const uint32_t app_id) const OVERRIDE; /** + * DEPRECATED * @brief Subscribe Application for way points * @param Application AppID */ void SubscribeAppForWayPoints(const uint32_t app_id) OVERRIDE; /** + * DEPRECATED * @brief Unsubscribe Application for way points * @param Application AppID */ void UnsubscribeAppFromWayPoints(const uint32_t app_id) OVERRIDE; /** + * @brief Checks if Application is subscribed for way points + * @param Application pointer + * @return true if Application is subscribed for way points + * otherwise false + */ + bool IsAppSubscribedForWayPoints(ApplicationSharedPtr app) const OVERRIDE; + + /** + * @brief Subscribe Application for way points + * @param Application pointer + */ + void SubscribeAppForWayPoints(ApplicationSharedPtr app) OVERRIDE; + + /** + * @brief Unsubscribe Application for way points + * @param Application pointer + */ + void UnsubscribeAppFromWayPoints(ApplicationSharedPtr app) OVERRIDE; + + /** * @brief Is Any Application is subscribed for way points * @return true if some app is subscribed otherwise false */ diff --git a/src/components/application_manager/include/application_manager/resumption/resumption_data_db.h b/src/components/application_manager/include/application_manager/resumption/resumption_data_db.h index 862816bf87..f278aacc47 100644 --- a/src/components/application_manager/include/application_manager/resumption/resumption_data_db.h +++ b/src/components/application_manager/include/application_manager/resumption/resumption_data_db.h @@ -55,6 +55,7 @@ struct ApplicationParams { mobile_apis::HMILevel::eType m_hmi_level; bool m_is_media_application; bool m_is_valid; + app_mngr::ApplicationSharedPtr app_ptr; }; /** diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 0313d2036e..8735c5d792 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -4144,9 +4144,46 @@ void ApplicationManagerImpl::UnsubscribeAppFromWayPoints( subscribed_way_points_apps_list_.erase(app_id); } +bool ApplicationManagerImpl::IsAppSubscribedForWayPoints( + ApplicationSharedPtr app) const { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); + LOG4CXX_DEBUG(logger_, + "There are applications subscribed: " + << subscribed_way_points_apps_list_.size()); + if (subscribed_way_points_apps_list_.find(app) == + subscribed_way_points_apps_list_.end()) { + return false; + } + return true; +} + +void ApplicationManagerImpl::SubscribeAppForWayPoints( + ApplicationSharedPtr app) { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); + subscribed_way_points_apps_list_.insert(app); + LOG4CXX_DEBUG(logger_, + "There are applications subscribed: " + << subscribed_way_points_apps_list_.size()); +} + +void ApplicationManagerImpl::UnsubscribeAppFromWayPoints( + ApplicationSharedPtr app) { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); + subscribed_way_points_apps_list_.erase(app); + LOG4CXX_DEBUG(logger_, + "There are applications subscribed: " + << subscribed_way_points_apps_list_.size()); +} + bool ApplicationManagerImpl::IsAnyAppSubscribedForWayPoints() const { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(subscribed_way_points_apps_lock_); + LOG4CXX_DEBUG(logger_, + "There are applications subscribed: " + << subscribed_way_points_apps_list_.size()); return !subscribed_way_points_apps_list_.empty(); } diff --git a/src/components/application_manager/src/commands/mobile/subscribe_way_points_request.cc b/src/components/application_manager/src/commands/mobile/subscribe_way_points_request.cc index 965741edf7..8195697dfc 100644 --- a/src/components/application_manager/src/commands/mobile/subscribe_way_points_request.cc +++ b/src/components/application_manager/src/commands/mobile/subscribe_way_points_request.cc @@ -25,13 +25,13 @@ void SubscribeWayPointsRequest::Run() { return; } - if (application_manager_.IsAppSubscribedForWayPoints(app->app_id())) { + if (application_manager_.IsAppSubscribedForWayPoints(app)) { SendResponse(false, mobile_apis::Result::IGNORED); return; } if (application_manager_.IsAnyAppSubscribedForWayPoints()) { - application_manager_.SubscribeAppForWayPoints(app->app_id()); + application_manager_.SubscribeAppForWayPoints(app); SendResponse(true, mobile_apis::Result::SUCCESS); return; } @@ -57,7 +57,7 @@ void SubscribeWayPointsRequest::on_event(const event_engine::Event& event) { const bool result = PrepareResultForMobileResponse( result_code, HmiInterfaces::HMI_INTERFACE_Navigation); if (result) { - application_manager_.SubscribeAppForWayPoints(app->app_id()); + application_manager_.SubscribeAppForWayPoints(app); } SendResponse(result, MessageHelper::HMIToMobileResult(result_code), diff --git a/src/components/application_manager/src/commands/mobile/unsubscribe_way_points_request.cc b/src/components/application_manager/src/commands/mobile/unsubscribe_way_points_request.cc index 88ed396250..dc3404c022 100644 --- a/src/components/application_manager/src/commands/mobile/unsubscribe_way_points_request.cc +++ b/src/components/application_manager/src/commands/mobile/unsubscribe_way_points_request.cc @@ -25,7 +25,7 @@ void UnSubscribeWayPointsRequest::Run() { return; } - if (!application_manager_.IsAppSubscribedForWayPoints(app->app_id())) { + if (!application_manager_.IsAppSubscribedForWayPoints(app)) { SendResponse(false, mobile_apis::Result::IGNORED); return; } @@ -51,7 +51,7 @@ void UnSubscribeWayPointsRequest::on_event(const event_engine::Event& event) { const bool result = PrepareResultForMobileResponse( result_code, HmiInterfaces::HMI_INTERFACE_Navigation); if (result) { - application_manager_.UnsubscribeAppFromWayPoints(app->app_id()); + application_manager_.UnsubscribeAppFromWayPoints(app); } SendResponse(result, MessageHelper::HMIToMobileResult(result_code), diff --git a/src/components/application_manager/src/helpers/application_helper.cc b/src/components/application_manager/src/helpers/application_helper.cc index 4b4816b273..2007b97434 100644 --- a/src/components/application_manager/src/helpers/application_helper.cc +++ b/src/components/application_manager/src/helpers/application_helper.cc @@ -9,7 +9,7 @@ namespace { using namespace application_manager; void RecallWayPoints(ApplicationSharedPtr app, ApplicationManager& app_manager) { - app_manager.UnsubscribeAppFromWayPoints(app->app_id()); + app_manager.UnsubscribeAppFromWayPoints(app); if (!app_manager.IsAnyAppSubscribedForWayPoints()) { MessageHelper::SendUnsubscribedWayPoints(app_manager); } 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 e7788bf9ff..4120f2a65e 100644 --- a/src/components/application_manager/src/resumption/resume_ctrl_impl.cc +++ b/src/components/application_manager/src/resumption/resume_ctrl_impl.cc @@ -580,7 +580,7 @@ void ResumeCtrlImpl::AddWayPointsSubscription( const smart_objects::SmartObject& subscribed_for_way_points_so = saved_app[strings::subscribed_for_way_points]; if (true == subscribed_for_way_points_so.asBool()) { - application_manager_.SubscribeAppForWayPoints(application->app_id()); + application_manager_.SubscribeAppForWayPoints(application); } } } diff --git a/src/components/application_manager/src/resumption/resumption_data_db.cc b/src/components/application_manager/src/resumption/resumption_data_db.cc index 08de6d8190..edcbc29595 100644 --- a/src/components/application_manager/src/resumption/resumption_data_db.cc +++ b/src/components/application_manager/src/resumption/resumption_data_db.cc @@ -2578,7 +2578,7 @@ bool ResumptionDataDB::InsertApplicationData( const mobile_apis::HMILevel::eType hmi_level = application.m_hmi_level; bool is_media_application = application.m_is_media_application; bool is_subscribed_for_way_points = - application_manager_.IsAppSubscribedForWayPoints(connection_key); + application_manager_.IsAppSubscribedForWayPoints(application.app_ptr); if (!query.Prepare(kInsertApplication)) { LOG4CXX_WARN(logger_, @@ -2804,6 +2804,7 @@ ApplicationParams::ApplicationParams(app_mngr::ApplicationSharedPtr application) m_hmi_app_id = application->hmi_app_id(); m_hmi_level = application->hmi_level(); m_is_media_application = application->IsAudioApplication(); + app_ptr = application; } } diff --git a/src/components/application_manager/src/resumption/resumption_data_json.cc b/src/components/application_manager/src/resumption/resumption_data_json.cc index 7866fc4de1..e7a4dbc4b0 100644 --- a/src/components/application_manager/src/resumption/resumption_data_json.cc +++ b/src/components/application_manager/src/resumption/resumption_data_json.cc @@ -66,7 +66,7 @@ void ResumptionDataJson::SaveApplication( const std::string device_mac = application->mac_address(); const mobile_apis::HMILevel::eType hmi_level = application->hmi_level(); const bool is_subscribed_for_way_points = - application_manager_.IsAppSubscribedForWayPoints(application->app_id()); + application_manager_.IsAppSubscribedForWayPoints(application); sync_primitives::AutoLock autolock(resumption_lock_); Json::Value tmp; diff --git a/src/components/application_manager/test/application_manager_impl_test.cc b/src/components/application_manager/test/application_manager_impl_test.cc index b964c1c0a2..f2af615025 100644 --- a/src/components/application_manager/test/application_manager_impl_test.cc +++ b/src/components/application_manager/test/application_manager_impl_test.cc @@ -66,6 +66,7 @@ namespace policy_test = test::components::policy_handler_test; namespace con_test = connection_handler_test; using testing::_; +using ::testing::Matcher; using ::testing::ByRef; using ::testing::DoAll; using ::testing::Mock; @@ -209,16 +210,20 @@ TEST_F(ApplicationManagerImplTest, ProcessQueryApp_ExpectSuccess) { TEST_F(ApplicationManagerImplTest, SubscribeAppForWayPoints_ExpectSubscriptionApp) { - app_manager_impl_->SubscribeAppForWayPoints(app_id_); - EXPECT_TRUE(app_manager_impl_->IsAppSubscribedForWayPoints(app_id_)); + auto app_ptr = + ApplicationSharedPtr::static_pointer_cast<am::Application>(mock_app_ptr_); + app_manager_impl_->SubscribeAppForWayPoints(app_ptr); + EXPECT_TRUE(app_manager_impl_->IsAppSubscribedForWayPoints(app_ptr)); } TEST_F(ApplicationManagerImplTest, UnsubscribeAppForWayPoints_ExpectUnsubscriptionApp) { - app_manager_impl_->SubscribeAppForWayPoints(app_id_); - EXPECT_TRUE(app_manager_impl_->IsAppSubscribedForWayPoints(app_id_)); - app_manager_impl_->UnsubscribeAppFromWayPoints(app_id_); - EXPECT_FALSE(app_manager_impl_->IsAppSubscribedForWayPoints(app_id_)); + auto app_ptr = + ApplicationSharedPtr::static_pointer_cast<am::Application>(mock_app_ptr_); + app_manager_impl_->SubscribeAppForWayPoints(app_ptr); + EXPECT_TRUE(app_manager_impl_->IsAppSubscribedForWayPoints(app_ptr)); + app_manager_impl_->UnsubscribeAppFromWayPoints(app_ptr); + EXPECT_FALSE(app_manager_impl_->IsAppSubscribedForWayPoints(app_ptr)); const std::set<int32_t> result = app_manager_impl_->GetAppsSubscribedForWayPoints(); EXPECT_TRUE(result.empty()); @@ -235,10 +240,12 @@ TEST_F( TEST_F( ApplicationManagerImplTest, GetAppsSubscribedForWayPoints_SubcribeAppForWayPoints_ExpectCorrectResult) { - app_manager_impl_->SubscribeAppForWayPoints(app_id_); + auto app_ptr = + ApplicationSharedPtr::static_pointer_cast<am::Application>(mock_app_ptr_); + app_manager_impl_->SubscribeAppForWayPoints(app_ptr); std::set<int32_t> result = app_manager_impl_->GetAppsSubscribedForWayPoints(); EXPECT_EQ(1u, result.size()); - EXPECT_TRUE(result.find(app_id_) != result.end()); + EXPECT_TRUE(result.find(app_ptr) != result.end()); } TEST_F(ApplicationManagerImplTest, OnServiceStartedCallback_RpcService) { diff --git a/src/components/application_manager/test/commands/mobile/subscribe_way_points_request_test.cc b/src/components/application_manager/test/commands/mobile/subscribe_way_points_request_test.cc index 26f5ee224f..4431080f0b 100644 --- a/src/components/application_manager/test/commands/mobile/subscribe_way_points_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/subscribe_way_points_request_test.cc @@ -51,6 +51,7 @@ namespace mobile_commands_test { namespace subscribe_way_points_request { using ::testing::_; +using ::testing::A; using ::testing::Return; using ::testing::ReturnRef; using ::testing::DoAll; @@ -72,14 +73,15 @@ TEST_F(SubscribeWayPointsRequestTest, Run_SUCCESS) { MockAppPtr app(CreateMockApp()); ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - ON_CALL(app_mngr_, IsAppSubscribedForWayPoints(_)) + ON_CALL(app_mngr_, IsAppSubscribedForWayPoints(A<am::ApplicationSharedPtr>())) .WillByDefault(Return(false)); ON_CALL(app_mngr_, IsAnyAppSubscribedForWayPoints()) .WillByDefault(Return(true)); { InSequence dummy; - EXPECT_CALL(app_mngr_, SubscribeAppForWayPoints(_)); + EXPECT_CALL(app_mngr_, + SubscribeAppForWayPoints(A<am::ApplicationSharedPtr>())); EXPECT_CALL(*app, UpdateHash()); } @@ -114,7 +116,10 @@ TEST_F(SubscribeWayPointsRequestTest, OnEvent_SUCCESS) { { InSequence dummy; - EXPECT_CALL(app_mngr_, SubscribeAppForWayPoints(_)); + EXPECT_CALL(app_mngr_, + SubscribeAppForWayPoints(A<am::ApplicationSharedPtr>())); + EXPECT_CALL(*mock_message_helper, HMIToMobileResult(result_code)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); EXPECT_CALL(app_mngr_, ManageMobileCommand(_, _)); EXPECT_CALL(*app, UpdateHash()); } diff --git a/src/components/application_manager/test/commands/mobile/unsubscribe_way_points_request_test.cc b/src/components/application_manager/test/commands/mobile/unsubscribe_way_points_request_test.cc index edba1b01bd..57c0dbe75e 100644 --- a/src/components/application_manager/test/commands/mobile/unsubscribe_way_points_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/unsubscribe_way_points_request_test.cc @@ -107,9 +107,9 @@ TEST_F(UnSubscribeWayPointsRequestTest, EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppId)); - - EXPECT_CALL(app_mngr_, IsAppSubscribedForWayPoints(kAppId)) + EXPECT_CALL(app_mngr_, + IsAppSubscribedForWayPoints( + ::testing::Matcher<am::ApplicationSharedPtr>(mock_app))) .WillOnce(Return(false)); EXPECT_CALL( @@ -124,9 +124,9 @@ TEST_F(UnSubscribeWayPointsRequestTest, Run_AppSubscribedForWayPoints_SUCCESS) { EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppId)); - - EXPECT_CALL(app_mngr_, IsAppSubscribedForWayPoints(kAppId)) + EXPECT_CALL(app_mngr_, + IsAppSubscribedForWayPoints( + ::testing::Matcher<am::ApplicationSharedPtr>(mock_app))) .WillOnce(Return(true)); EXPECT_CALL(app_mngr_, @@ -161,9 +161,9 @@ TEST_F(UnSubscribeWayPointsRequestTest, Event event(hmi_apis::FunctionID::Navigation_UnsubscribeWayPoints); event.set_smart_object(*event_msg); - EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppId)); - - EXPECT_CALL(app_mngr_, UnsubscribeAppFromWayPoints(kAppId)); + EXPECT_CALL(app_mngr_, + UnsubscribeAppFromWayPoints( + ::testing::Matcher<am::ApplicationSharedPtr>(mock_app))); EXPECT_CALL( app_mngr_, 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 f80842e250..98760fa28b 100644 --- a/src/components/application_manager/test/resumption/resume_ctrl_test.cc +++ b/src/components/application_manager/test/resumption/resume_ctrl_test.cc @@ -54,6 +54,7 @@ namespace components { namespace resumption_test { using ::testing::_; +using ::testing::A; using ::testing::Return; using ::testing::ReturnRef; using ::testing::DoAll; @@ -505,7 +506,9 @@ TEST_F(ResumeCtrlTest, StartResumption_AppWithSubscriptionToWayPoints) { GetSavedApplication(kTestPolicyAppId_, kMacAddress_, _)) .WillByDefault(DoAll(SetArgReferee<2>(saved_app), Return(true))); EXPECT_CALL(*app_mock_, set_grammar_id(kTestGrammarId_)); - EXPECT_CALL(app_mngr_, SubscribeAppForWayPoints(_)); + EXPECT_CALL( + app_mngr_, + SubscribeAppForWayPoints(A<application_manager::ApplicationSharedPtr>())); const mobile_apis::HMILevel::eType hmi_test_level = mobile_apis::HMILevel::HMI_FULL; ON_CALL(app_mngr_, GetDefaultHmiLevel(const_app_)) diff --git a/src/components/include/application_manager/application_manager.h b/src/components/include/application_manager/application_manager.h index 427c6a9c2e..a9717a9214 100644 --- a/src/components/include/application_manager/application_manager.h +++ b/src/components/include/application_manager/application_manager.h @@ -255,6 +255,7 @@ class ApplicationManager { const utils::SharedPtr<Application> app) = 0; /** + * DEPRECATED * @brief Checks if Application is subscribed for way points * @param Application AppID * @return true if Application is subscribed for way points @@ -263,18 +264,40 @@ class ApplicationManager { virtual bool IsAppSubscribedForWayPoints(const uint32_t app_id) const = 0; /** + * DEPRECATED * @brief Subscribe Application for way points * @param Application AppID */ virtual void SubscribeAppForWayPoints(const uint32_t app_id) = 0; /** + * DEPRECATED * @brief Unsubscribe Application for way points * @param Application AppID */ virtual void UnsubscribeAppFromWayPoints(const uint32_t app_id) = 0; /** + * @brief Checks if Application is subscribed for way points + * @param Application pointer + * @return true if Application is subscribed for way points + * otherwise false + */ + virtual bool IsAppSubscribedForWayPoints(ApplicationSharedPtr app) const = 0; + + /** + * @brief Subscribe Application for way points + * @param Application pointer + */ + virtual void SubscribeAppForWayPoints(ApplicationSharedPtr app) = 0; + + /** + * @brief Unsubscribe Application for way points + * @param Application pointer + */ + virtual void UnsubscribeAppFromWayPoints(ApplicationSharedPtr app) = 0; + + /** * @brief Is Any Application is subscribed for way points * @return true if some app is subscribed otherwise false */ 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 eb9aaad412..3ad14fe676 100644 --- a/src/components/include/test/application_manager/mock_application_manager.h +++ b/src/components/include/test/application_manager/mock_application_manager.h @@ -270,9 +270,18 @@ class MockApplicationManager : public application_manager::ApplicationManager { MOCK_METHOD0(event_dispatcher, application_manager::event_engine::EventDispatcher&()); + // DEPRECATED MOCK_CONST_METHOD1(IsAppSubscribedForWayPoints, bool(const uint32_t)); + // DEPRECATED MOCK_METHOD1(SubscribeAppForWayPoints, void(const uint32_t)); + // DEPRECATED MOCK_METHOD1(UnsubscribeAppFromWayPoints, void(const uint32_t)); + MOCK_CONST_METHOD1(IsAppSubscribedForWayPoints, + bool(application_manager::ApplicationSharedPtr)); + MOCK_METHOD1(SubscribeAppForWayPoints, + void(application_manager::ApplicationSharedPtr)); + MOCK_METHOD1(UnsubscribeAppFromWayPoints, + void(application_manager::ApplicationSharedPtr)); MOCK_CONST_METHOD0(IsAnyAppSubscribedForWayPoints, bool()); MOCK_CONST_METHOD0(GetAppsSubscribedForWayPoints, const std::set<int32_t>()); MOCK_CONST_METHOD1( |