diff options
author | Yevhenii <ydementieiev@luxoft.com> | 2020-05-28 18:21:54 +0300 |
---|---|---|
committer | Yevhenii <ydementieiev@luxoft.com> | 2020-06-02 15:59:42 +0300 |
commit | 0c4f9c1aacde0e5a348d7be2e20e83e92ee62f32 (patch) | |
tree | 4389e017d6070e70122acd28a956321e168534f2 | |
parent | 40d1d3ee62583e6dee24dad1edd394bf08800a2f (diff) | |
download | sdl_core-fix/app_freezes_after_usb_disconnect.tar.gz |
Do not add application to application list in case when this app missing in connectionsfix/app_freezes_after_usb_disconnect
6 files changed, 67 insertions, 1 deletions
diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index b1a348dafb..c61797b03c 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -757,6 +757,13 @@ ApplicationSharedPtr ApplicationManagerImpl::RegisterApplication( // Timer will be started after hmi level resumption. resume_controller().OnAppRegistrationStart(policy_app_id, device_mac); + if (!connection_handler_->IsAppConnected(connection_key)) { + LOG4CXX_DEBUG(logger_, + "Application with connection_key " << connection_key + << " is not connected"); + return ApplicationSharedPtr(); + } + AddAppToRegisteredAppList(application); // Update cloud app information, in case any pending apps are unable to be @@ -3275,6 +3282,12 @@ void ApplicationManagerImpl::UnregisterApplication( if (app_id == (*it_app)->app_id()) { app_to_remove = *it_app; applications_.erase(it_app++); + LOG4CXX_DEBUG( + logger_, + "App with app_id: " << app_id + << " has been removed from registered " + "applications list. New list size: " + << applications_.size()); break; } else { ++it_app; @@ -4555,7 +4568,9 @@ void ApplicationManagerImpl::AddAppToRegisteredAppList( LOG4CXX_DEBUG( logger_, "App with app_id: " << application->app_id() - << " has been added to registered applications list"); + << " has been added to registered applications list. " + "New list size: " + << applications_.size()); if (application_list_update_timer_.is_running() && !registered_during_timer_execution_) { GetPolicyHandler().OnAddedNewApplicationToAppList( 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 2c16048e97..9081f56adf 100644 --- a/src/components/application_manager/test/application_manager_impl_test.cc +++ b/src/components/application_manager/test/application_manager_impl_test.cc @@ -1645,6 +1645,8 @@ TEST_F(ApplicationManagerImplTest, file_system::CreateDirectory(kDirectoryName); const std::string full_icon_path = kDirectoryName + "/" + kAppId; ASSERT_TRUE(file_system::CreateFile(full_icon_path)); + ON_CALL(mock_connection_handler_, IsAppConnected(kConnectionKey)) + .WillByDefault(Return(true)); smart_objects::SmartObject request_for_registration( smart_objects::SmartType_Map); @@ -1785,6 +1787,8 @@ TEST_F(ApplicationManagerImplTest, EXPECT_CALL(*waiting_app, hybrid_app_preference()) .WillOnce(ReturnRef(kHybridAppPreference)); ON_CALL(*waiting_app, is_cloud_app()).WillByDefault(Return(true)); + ON_CALL(mock_connection_handler_, IsAppConnected(kConnectionKey)) + .WillByDefault(Return(true)); EXPECT_CALL(*waiting_app, policy_app_id()).WillRepeatedly(Return(kAppId)); app_manager_impl_->AddMockPendingApplication(waiting_app); @@ -1849,6 +1853,8 @@ TEST_F(ApplicationManagerImplTest, EXPECT_CALL(*waiting_app, policy_app_id()) .WillRepeatedly(Return("Fake" + kAppId)); app_manager_impl_->AddMockPendingApplication(waiting_app); + ON_CALL(mock_connection_handler_, IsAppConnected(kConnectionKey)) + .WillByDefault(Return(true)); EXPECT_CALL( mock_session_observer_, @@ -2028,6 +2034,29 @@ TEST_F(ApplicationManagerImplTest, AddAndRemoveQueryAppDevice_SUCCESS) { EXPECT_FALSE(app_manager_impl_->IsAppsQueriedFrom(device_handle)); } +TEST_F( + ApplicationManagerImplTest, + RegisterApplication_ApplicationMissingInConnections_DoNotAddApplicationToAppList) { + smart_objects::SmartObject request_for_registration( + smart_objects::SmartType_Map); + + request_for_registration[strings::params][strings::connection_key] = + kConnectionKey; + + const auto request_for_registration_ptr = + std::make_shared<smart_objects::SmartObject>(request_for_registration); + std::unique_ptr<plugin_manager::RPCPluginManager> rpc_plugin_manager( + new MockRPCPluginManager()); + app_manager_impl_->SetPluginManager(rpc_plugin_manager); + + ON_CALL(mock_connection_handler_, IsAppConnected(kConnectionKey)) + .WillByDefault(Return(false)); + + EXPECT_CALL(*mock_policy_handler_, OnAddedNewApplicationToAppList(_, _)) + .Times(0); + app_manager_impl_->RegisterApplication(request_for_registration_ptr); +} + } // namespace application_manager_test } // namespace components } // namespace test diff --git a/src/components/connection_handler/include/connection_handler/connection_handler_impl.h b/src/components/connection_handler/include/connection_handler/connection_handler_impl.h index b2b4c5a970..db27b3f78e 100644 --- a/src/components/connection_handler/include/connection_handler/connection_handler_impl.h +++ b/src/components/connection_handler/include/connection_handler/connection_handler_impl.h @@ -610,6 +610,8 @@ class ConnectionHandlerImpl void CreateWebEngineDevice() OVERRIDE; + bool IsAppConnected(const uint32_t connection_key) const OVERRIDE; + private: /** * \brief Disconnect application. diff --git a/src/components/connection_handler/src/connection_handler_impl.cc b/src/components/connection_handler/src/connection_handler_impl.cc index 1ad938332a..38c31bda7c 100644 --- a/src/components/connection_handler/src/connection_handler_impl.cc +++ b/src/components/connection_handler/src/connection_handler_impl.cc @@ -874,6 +874,18 @@ void ConnectionHandlerImpl::CreateWebEngineDevice() { transport_manager_.CreateWebEngineDevice(); } +bool ConnectionHandlerImpl::IsAppConnected( + const uint32_t connection_key) const { + LOG4CXX_AUTO_TRACE(logger_); + + transport_manager::ConnectionUID connection_handle = 0; + uint8_t session_id = 0; + PairFromKey(connection_key, &connection_handle, &session_id); + + sync_primitives::AutoReadLock lock(connection_list_lock_); + return (nullptr != GetPrimaryConnection(connection_handle)); +} + const std::string ConnectionHandlerImpl::TransportTypeProfileStringFromConnHandle( transport_manager::ConnectionUID connection_handle) const { diff --git a/src/components/include/connection_handler/connection_handler.h b/src/components/include/connection_handler/connection_handler.h index e98a78f377..c42cd6dc5a 100644 --- a/src/components/include/connection_handler/connection_handler.h +++ b/src/components/include/connection_handler/connection_handler.h @@ -325,6 +325,13 @@ class ConnectionHandler { */ virtual void CreateWebEngineDevice() = 0; + /** + * @brief Checks if such an application is connected. + * @param connection_key Application's connection key. + * @return True if the application is connected. + **/ + virtual bool IsAppConnected(const uint32_t connection_key) const = 0; + protected: /** * \brief Destructor diff --git a/src/components/include/test/connection_handler/mock_connection_handler.h b/src/components/include/test/connection_handler/mock_connection_handler.h index 6acffea0ed..e13a510b39 100644 --- a/src/components/include/test/connection_handler/mock_connection_handler.h +++ b/src/components/include/test/connection_handler/mock_connection_handler.h @@ -135,6 +135,7 @@ class MockConnectionHandler : public connection_handler::ConnectionHandler { const transport_manager::ConnectionUID secondary_connection_handle)); MOCK_METHOD0(CreateWebEngineDevice, void()); MOCK_CONST_METHOD0(GetWebEngineDeviceInfo, transport_manager::DeviceInfo&()); + MOCK_CONST_METHOD1(IsAppConnected, bool(const uint32_t connection_key)); }; } // namespace connection_handler_test |