From 0bd0303698e2545b62e9890f134d39dd87143deb Mon Sep 17 00:00:00 2001 From: "Ira Lytvynenko (GitHub)" Date: Thu, 5 Apr 2018 14:25:45 +0300 Subject: Fix SDL sends multiple OnRCStatus notification in case of app unregistration Fix disabling RC-functionality --- .../rc_rpc_plugin/resource_allocation_manager.h | 4 ++ .../resource_allocation_manager_impl.h | 11 ++-- .../rc_on_remote_control_settings_notification.cc | 2 + .../mobile/set_interior_vehicle_data_request.cc | 1 + .../src/commands/rc_command_request.cc | 8 +++ .../rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc | 4 +- .../src/resource_allocation_manager_impl.cc | 60 +++++++++++++--------- .../test/commands/button_press_request_test.cc | 2 + .../get_interior_vehicle_data_request_test.cc | 2 + .../rc_get_interior_vehicle_data_consent_test.cc | 2 + .../set_interior_vehicle_data_request_test.cc | 2 + .../mock/mock_resource_allocation_manager.h | 2 + .../test/resource_allocation_manager_impl_test.cc | 14 ++--- 13 files changed, 80 insertions(+), 34 deletions(-) (limited to 'src/components/application_manager/rpc_plugins/rc_rpc_plugin') diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h index 71ee5fddff..98da8bc27d 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h @@ -150,6 +150,10 @@ class ResourceAllocationManager { */ virtual void SendOnRCStatusNotification() = 0; + virtual bool is_rc_enabled() const = 0; + + virtual void set_rc_enabled(const bool value) = 0; + virtual ~ResourceAllocationManager() {} }; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h index 434bde2a82..4c72e9ea2c 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager_impl.h @@ -120,6 +120,10 @@ class ResourceAllocationManagerImpl : public ResourceAllocationManager { void SendOnRCStatusNotification() FINAL; + bool is_rc_enabled() const FINAL; + + void set_rc_enabled(const bool value) FINAL; + private: typedef std::vector Apps; @@ -130,11 +134,10 @@ class ResourceAllocationManagerImpl : public ResourceAllocationManager { * @return smart object with mobile OnRCStatusNotification */ smart_objects::SmartObjectSPtr CreateOnRCStatusNotificationToMobile( - const uint32_t app_id); + const application_manager::ApplicationSharedPtr app); smart_objects::SmartObjectSPtr CreateOnRCStatusNotificationToHmi( - const uint32_t app_id); - + const application_manager::ApplicationSharedPtr app); /** * @brief IsModuleTypeRejected check if current resource was rejected by @@ -194,6 +197,7 @@ class ResourceAllocationManagerImpl : public ResourceAllocationManager { void SetResourceFree(const std::string& module_type, const uint32_t app_id); std::vector all_supported_modules(); + /** * @brief AllocatedResources contains link between resource and application * owning that resource @@ -221,6 +225,7 @@ class ResourceAllocationManagerImpl : public ResourceAllocationManager { hmi_apis::Common_RCAccessMode::eType current_access_mode_; application_manager::ApplicationManager& app_mngr_; application_manager::rpc_service::RPCService& rpc_service_; + bool is_rc_enabled_; }; } // rc_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_on_remote_control_settings_notification.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_on_remote_control_settings_notification.cc index 817223a369..dda59ea296 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_on_remote_control_settings_notification.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/hmi/rc_on_remote_control_settings_notification.cc @@ -131,6 +131,7 @@ void RCOnRemoteControlSettingsNotification::Run() { hmi_apis::Common_RCAccessMode::eType access_mode = hmi_apis::Common_RCAccessMode::INVALID_ENUM; LOG4CXX_DEBUG(logger_, "Allowing RC Functionality"); + resource_allocation_manager_.set_rc_enabled(true); if ((*message_)[app_mngr::strings::msg_params].keyExists( message_params::kAccessMode)) { access_mode = static_cast( @@ -149,6 +150,7 @@ void RCOnRemoteControlSettingsNotification::Run() { } else { LOG4CXX_DEBUG(logger_, "Disallowing RC Functionality"); DisallowRCFunctionality(); + resource_allocation_manager_.set_rc_enabled(false); resource_allocation_manager_.ResetAllAllocations(); } } 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 160915f347..e76572c773 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 @@ -32,6 +32,7 @@ #include "rc_rpc_plugin/commands/mobile/set_interior_vehicle_data_request.h" #include "rc_rpc_plugin/rc_module_constants.h" +#include "rc_rpc_plugin/rc_rpc_plugin.h" #include "smart_objects/enum_schema_item.h" #include "utils/macro.h" #include "json/json.h" diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc index 4f968dd2d8..524e4db7fa 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc @@ -140,6 +140,14 @@ void RCCommandRequest::Run() { SendResponse(false, mobile_apis::Result::DISALLOWED, ""); return; } + if (!resource_allocation_manager_.is_rc_enabled()) { + LOG4CXX_WARN(logger_, "Remote control is disabled by user"); + SetResourceState(ModuleType(), ResourceState::FREE); + SendResponse(false, + mobile_apis::Result::USER_DISALLOWED, + "Remote control is disabled by user"); + return; + } if (CheckDriverConsent()) { if (AcquireResources()) { diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc index f423a66fc6..a001e4734f 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/rc_rpc_plugin.cc @@ -91,7 +91,9 @@ void RCRPCPlugin::OnApplicationEvent( switch (event) { case plugins::kApplicationRegistered: { application->AddExtension(new RCAppExtension(kRCPluginID)); - resource_allocation_manager_->SendOnRCStatusNotification(); + if (resource_allocation_manager_->is_rc_enabled()) { + resource_allocation_manager_->SendOnRCStatusNotification(); + } break; } case plugins::kApplicationExit: { diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc index 4b70830de7..e9a56007df 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc @@ -52,7 +52,8 @@ ResourceAllocationManagerImpl::ResourceAllocationManagerImpl( application_manager::rpc_service::RPCService& rpc_service) : current_access_mode_(hmi_apis::Common_RCAccessMode::AUTO_ALLOW) , app_mngr_(app_mngr) - , rpc_service_(rpc_service) {} + , rpc_service_(rpc_service) + , is_rc_enabled_(true) {} ResourceAllocationManagerImpl::~ResourceAllocationManagerImpl() {} @@ -173,6 +174,7 @@ void ResourceAllocationManagerImpl::ProcessApplicationPolicyUpdate() { if (rc_extention) { rc_extention->UnsubscribeFromInteriorVehicleData(*module); } + SendOnRCStatusNotification(); } } } @@ -234,7 +236,8 @@ EnumType StringToEnum(const std::string& str) { void ConstructOnRCStatusNotificationParams( smart_objects::SmartObject& msg_params, const std::map& allocated_resources, - const std::vector& supported_resources) { + const std::vector& supported_resources, + const u_int32_t app_id) { namespace strings = application_manager::strings; namespace message_params = rc_rpc_plugin::message_params; using smart_objects::SmartObject; @@ -253,8 +256,10 @@ void ConstructOnRCStatusNotificationParams( }; }; SmartObject allocated_modules = SmartObject(SmartType_Array); - for (auto& module : allocated_resources) { - modules_inserter(allocated_modules)(module.first); + for (const auto& module : allocated_resources) { + if (module.second == app_id) { + modules_inserter(allocated_modules)(module.first); + } } SmartObject free_modules = SmartObject(SmartType_Array); for (auto& module : supported_resources) { @@ -268,29 +273,29 @@ void ConstructOnRCStatusNotificationParams( smart_objects::SmartObjectSPtr ResourceAllocationManagerImpl::CreateOnRCStatusNotificationToMobile( - const uint32_t app_id) { + const application_manager::ApplicationSharedPtr app) { LOG4CXX_AUTO_TRACE(logger_); using application_manager::MessageHelper; - auto to_mobile_msg = MessageHelper::CreateNotification( - mobile_apis::FunctionID::OnRCStatusID, app_id); - auto& msg_params = (*to_mobile_msg)[application_manager::strings::msg_params]; + auto msg_to_mobile = MessageHelper::CreateNotification( + mobile_apis::FunctionID::OnRCStatusID, app->app_id()); + auto& msg_params = (*msg_to_mobile)[application_manager::strings::msg_params]; ConstructOnRCStatusNotificationParams( - msg_params, allocated_resources_, all_supported_modules()); - return to_mobile_msg; + msg_params, allocated_resources_, all_supported_modules(), app->app_id()); + return msg_to_mobile; } smart_objects::SmartObjectSPtr ResourceAllocationManagerImpl::CreateOnRCStatusNotificationToHmi( - const uint32_t app_id) { + const application_manager::ApplicationSharedPtr app) { LOG4CXX_AUTO_TRACE(logger_); using application_manager::MessageHelper; - auto to_hmi_msg = + auto msg_to_hmi = MessageHelper::CreateHMINotification(hmi_apis::FunctionID::RC_OnRCStatus); - auto& msg_params = (*to_hmi_msg)[application_manager::strings::msg_params]; + auto& msg_params = (*msg_to_hmi)[application_manager::strings::msg_params]; ConstructOnRCStatusNotificationParams( - msg_params, allocated_resources_, all_supported_modules()); - msg_params[application_manager::strings::app_id] = app_id; - return to_hmi_msg; + msg_params, allocated_resources_, all_supported_modules(), app->app_id()); + msg_params[application_manager::strings::app_id] = app->hmi_app_id(); + return msg_to_hmi; } void ResourceAllocationManagerImpl::SetResourceAquired( @@ -303,14 +308,22 @@ void ResourceAllocationManagerImpl::SetResourceAquired( void ResourceAllocationManagerImpl::SendOnRCStatusNotification() { LOG4CXX_AUTO_TRACE(logger_); auto rc_apps = RCRPCPlugin::GetRCApplications(app_mngr_); - for (auto& rc_app : rc_apps) { - auto to_mobile = CreateOnRCStatusNotificationToMobile(rc_app->app_id()); - rpc_service_.SendMessageToMobile(to_mobile); - auto to_HMI = CreateOnRCStatusNotificationToHmi(rc_app->hmi_app_id()); - rpc_service_.SendMessageToHMI(to_HMI); + for (const auto& rc_app : rc_apps) { + auto msg_to_mobile = CreateOnRCStatusNotificationToMobile(rc_app); + rpc_service_.SendMessageToMobile(msg_to_mobile); + auto msg_to_hmi = CreateOnRCStatusNotificationToHmi(rc_app); + rpc_service_.SendMessageToHMI(msg_to_hmi); } } +bool ResourceAllocationManagerImpl::is_rc_enabled() const { + return is_rc_enabled_; +} + +void ResourceAllocationManagerImpl::set_rc_enabled(const bool value) { + is_rc_enabled_ = value; +} + void ResourceAllocationManagerImpl::SetResourceFree( const std::string& module_type, const uint32_t app_id) { AllocatedResources::const_iterator allocation = @@ -327,7 +340,6 @@ void ResourceAllocationManagerImpl::SetResourceFree( } allocated_resources_.erase(allocation); LOG4CXX_DEBUG(logger_, "Resource " << module_type << " is released."); - SendOnRCStatusNotification(); } std::vector @@ -473,7 +485,9 @@ void ResourceAllocationManagerImpl::OnApplicationEvent( for (; acquired_modules.end() != module; ++module) { ReleaseResource(*module, application->app_id()); } - + if (!acquired_modules.empty()) { + SendOnRCStatusNotification(); + } Apps app_list; app_list.push_back(application); RemoveAppsSubscriptions(app_list); diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc index 5098f6472e..7ab4819002 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc @@ -130,6 +130,8 @@ class ButtonPressRequestTest CheckHMIType(kPolicyAppId, mobile_apis::AppHMIType::eType::REMOTE_CONTROL, nullptr)).WillByDefault(Return(true)); + ON_CALL(mock_allocation_manager_, is_rc_enabled()) + .WillByDefault(Return(true)); } MessageSharedPtr CreateBasicMessage() { diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc index 7074bfb9c5..685bc1fd42 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc @@ -100,6 +100,8 @@ class GetInteriorVehicleDataRequestTest CheckHMIType( _, mobile_apis::AppHMIType::eType::REMOTE_CONTROL, nullptr)) .WillByDefault(Return(true)); + ON_CALL(mock_allocation_manager_, is_rc_enabled()) + .WillByDefault(Return(true)); } MessageSharedPtr CreateBasicMessage() { diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc index 8fad1aef60..c5a8e54c6d 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc @@ -141,6 +141,8 @@ class RCGetInteriorVehicleDataConsentTest .WillByDefault(Return(rpc_plugin)); ON_CALL(mock_allocation_manager_, IsResourceFree(kResource)) .WillByDefault(Return(true)); + ON_CALL(mock_allocation_manager_, is_rc_enabled()) + .WillByDefault(Return(true)); } template diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc index 68985e5f94..1d5e63e2df 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc @@ -89,6 +89,8 @@ class SetInteriorVehicleDataRequestTest CheckHMIType(kPolicyAppId, mobile_apis::AppHMIType::eType::REMOTE_CONTROL, nullptr)).WillByDefault(Return(true)); + ON_CALL(mock_allocation_manager_, is_rc_enabled()) + .WillByDefault(Return(true)); } MessageSharedPtr CreateBasicMessage() { diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h index ba61620d1d..df0daad0b9 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h @@ -66,6 +66,8 @@ class MockResourceAllocationManager application_manager::ApplicationSharedPtr application)); MOCK_METHOD0(ResetAllAllocations, void()); MOCK_METHOD0(SendOnRCStatusNotification, void()); + MOCK_CONST_METHOD0(is_rc_enabled, bool()); + MOCK_METHOD1(set_rc_enabled, void(const bool value)); }; } // namespace rc_rpc_plugin_test diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager_impl_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager_impl_test.cc index 8c1b16ee7a..03c06404a3 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager_impl_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager_impl_test.cc @@ -103,7 +103,7 @@ class RAManagerTest : public ::testing::Test { void OnRCStatusNotoficationExpectations(); -protected: + protected: NiceMock mock_app_mngr_; NiceMock mock_rpc_service_; test::components::policy_test::MockPolicyHandlerInterface @@ -139,12 +139,12 @@ void RAManagerTest::CheckResultWithHMILevelAndAccessMode( } void RAManagerTest::OnRCStatusNotoficationExpectations() { - ON_CALL(mock_app_mngr_, application(kAppId1)) - .WillByDefault(Return(mock_app_1_)); - ON_CALL(*mock_app_1_, QueryInterface(rc_rpc_plugin::RCRPCPlugin::kRCPluginID)) - .WillByDefault(Return(app_ext_ptr_)); - apps_.insert(mock_app_1_); - ON_CALL(mock_app_mngr_, applications()).WillByDefault(Return(apps_da_)); + ON_CALL(mock_app_mngr_, application(kAppId1)) + .WillByDefault(Return(mock_app_1_)); + ON_CALL(*mock_app_1_, QueryInterface(rc_rpc_plugin::RCRPCPlugin::kRCPluginID)) + .WillByDefault(Return(app_ext_ptr_)); + apps_.insert(mock_app_1_); + ON_CALL(mock_app_mngr_, applications()).WillByDefault(Return(apps_da_)); } TEST_F(RAManagerTest, AcquireResource_NoAppRegistered_Expect_InUse) { -- cgit v1.2.1