From a1986cd003c0cd410fee8edc63cec1bfa95b649b Mon Sep 17 00:00:00 2001 From: "Ira Lytvynenko (GitHub)" Date: Mon, 21 May 2018 12:02:51 +0300 Subject: Fix behavior in case when RC functionality is disabled from HMI --- .../include/rc_rpc_plugin/resource_allocation_manager.h | 4 ++++ .../include/rc_rpc_plugin/resource_allocation_manager_impl.h | 5 +++++ .../hmi/rc_on_remote_control_settings_notification.cc | 5 ++--- .../rc_rpc_plugin/src/commands/rc_command_request.cc | 8 ++++++++ .../rc_rpc_plugin/src/resource_allocation_manager_impl.cc | 11 ++++++++++- .../rc_rpc_plugin/test/commands/button_press_request_test.cc | 2 ++ .../test/commands/get_interior_vehicle_data_request_test.cc | 2 ++ .../commands/rc_get_interior_vehicle_data_consent_test.cc | 2 ++ .../test/commands/set_interior_vehicle_data_request_test.cc | 2 ++ .../rc_rpc_plugin/mock/mock_resource_allocation_manager.h | 2 ++ 10 files changed, 39 insertions(+), 4 deletions(-) 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 0dc8b59f8f..374c4884fe 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 @@ -145,6 +145,10 @@ class ResourceAllocationManager { application_manager::ApplicationSharedPtr application) = 0; virtual ~ResourceAllocationManager() {} + + virtual bool is_rc_enabled() const = 0; + + virtual void set_rc_enabled(const bool value) = 0; }; } // namespace rc_rpc_plugin 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 bb875bb180..07d23a2f20 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 @@ -118,6 +118,10 @@ class ResourceAllocationManagerImpl : public ResourceAllocationManager { RCAppExtensionPtr GetApplicationExtention( application_manager::ApplicationSharedPtr application) FINAL; + bool is_rc_enabled() const FINAL; + + void set_rc_enabled(const bool value) FINAL; + private: /** * @brief IsModuleTypeRejected check if current resource was rejected by @@ -204,6 +208,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..a14f09d397 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 @@ -101,9 +101,6 @@ void RCOnRemoteControlSettingsNotification::DisallowRCFunctionality() { for (Apps::iterator it = apps.begin(); it != apps.end(); ++it) { application_manager::ApplicationSharedPtr app = *it; DCHECK(app); - application_manager_.ChangeAppsHMILevel( - app->app_id(), mobile_apis::HMILevel::eType::HMI_NONE); - const RCAppExtensionPtr extension = application_manager::AppExtensionPtr::static_pointer_cast< RCAppExtension>(app->QueryInterface(RCRPCPlugin::kRCPluginID)); @@ -131,6 +128,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 +147,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/rc_command_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/rc_command_request.cc index 4f968dd2d8..00b9420bfb 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 denied by user"); + SetResourceState(ModuleType(), ResourceState::FREE); + SendResponse(false, + mobile_apis::Result::REJECTED, + "Remote control is denied by user"); + return; + } if (CheckDriverConsent()) { if (AcquireResources()) { 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 c2962863e3..f11897b38d 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() {} @@ -237,6 +238,14 @@ void ResourceAllocationManagerImpl::SetResourceFree( LOG4CXX_DEBUG(logger_, "Resource " << module_type << " is released."); } +bool ResourceAllocationManagerImpl::is_rc_enabled() const { + return is_rc_enabled_; +} + +void ResourceAllocationManagerImpl::set_rc_enabled(const bool value) { + is_rc_enabled_ = value; +} + std::vector ResourceAllocationManagerImpl::GetAcquiredResources( const uint32_t application_id) const { LOG4CXX_AUTO_TRACE(logger_); 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 fb9326209c..ad9544702c 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 @@ -65,6 +65,8 @@ class MockResourceAllocationManager rc_rpc_plugin::RCAppExtensionPtr( application_manager::ApplicationSharedPtr application)); MOCK_METHOD0(ResetAllAllocations, void()); + MOCK_CONST_METHOD0(is_rc_enabled, bool()); + MOCK_METHOD1(set_rc_enabled, void(const bool value)); }; } // namespace rc_rpc_plugin_test -- cgit v1.2.1 From 9994f3f193782f0e262d6df84e3a7290d62bb50a Mon Sep 17 00:00:00 2001 From: "Ira Lytvynenko (GitHub)" Date: Tue, 22 May 2018 11:35:29 +0300 Subject: Fix comments after review --- .../rc_on_remote_control_settings_notification.cc | 60 ++++++++++------------ .../src/commands/rc_command_request.cc | 6 +-- .../commands/on_remote_control_settings_test.cc | 5 ++ 3 files changed, 35 insertions(+), 36 deletions(-) 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 a14f09d397..70f2a37d59 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 @@ -112,44 +112,38 @@ void RCOnRemoteControlSettingsNotification::DisallowRCFunctionality() { void RCOnRemoteControlSettingsNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); - - if (!(*message_)[app_mngr::strings::msg_params].keyExists( + if ((*message_)[app_mngr::strings::msg_params].keyExists( message_params::kAllowed)) { - LOG4CXX_DEBUG(logger_, - "Notification is ignored due to \"allow\" parameter absense"); - LOG4CXX_DEBUG(logger_, "RC Functionality remains unchanged"); - return; - } - - const bool is_allowed = - (*message_)[app_mngr::strings::msg_params][message_params::kAllowed] - .asBool(); - if (is_allowed) { - 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( - (*message_)[app_mngr::strings::msg_params] - [message_params::kAccessMode].asUInt()); - LOG4CXX_DEBUG( - logger_, - "Setting up access mode : " << AccessModeToString(access_mode)); + const bool is_allowed = + (*message_)[app_mngr::strings::msg_params][message_params::kAllowed] + .asBool(); + if (is_allowed) { + LOG4CXX_DEBUG(logger_, "Allowing RC Functionality"); + resource_allocation_manager_.set_rc_enabled(true); } else { - access_mode = resource_allocation_manager_.GetAccessMode(); - LOG4CXX_DEBUG(logger_, - "No access mode received. Using last known: " - << AccessModeToString(access_mode)); + LOG4CXX_DEBUG(logger_, "Disallowing RC Functionality"); + DisallowRCFunctionality(); + resource_allocation_manager_.set_rc_enabled(false); + resource_allocation_manager_.ResetAllAllocations(); } - resource_allocation_manager_.SetAccessMode(access_mode); + } + hmi_apis::Common_RCAccessMode::eType access_mode = + hmi_apis::Common_RCAccessMode::INVALID_ENUM; + if ((*message_)[app_mngr::strings::msg_params].keyExists( + message_params::kAccessMode)) { + access_mode = static_cast( + (*message_)[app_mngr::strings::msg_params][message_params::kAccessMode] + .asUInt()); + LOG4CXX_DEBUG( + logger_, + "Setting up access mode : " << AccessModeToString(access_mode)); } else { - LOG4CXX_DEBUG(logger_, "Disallowing RC Functionality"); - DisallowRCFunctionality(); - resource_allocation_manager_.set_rc_enabled(false); - resource_allocation_manager_.ResetAllAllocations(); + access_mode = resource_allocation_manager_.GetAccessMode(); + LOG4CXX_DEBUG(logger_, + "No access mode received. Using last known: " + << AccessModeToString(access_mode)); } + resource_allocation_manager_.SetAccessMode(access_mode); } } // namespace commands 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 00b9420bfb..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 @@ -141,11 +141,11 @@ void RCCommandRequest::Run() { return; } if (!resource_allocation_manager_.is_rc_enabled()) { - LOG4CXX_WARN(logger_, "Remote control is denied by user"); + LOG4CXX_WARN(logger_, "Remote control is disabled by user"); SetResourceState(ModuleType(), ResourceState::FREE); SendResponse(false, - mobile_apis::Result::REJECTED, - "Remote control is denied by user"); + mobile_apis::Result::USER_DISALLOWED, + "Remote control is disabled by user"); return; } diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_remote_control_settings_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_remote_control_settings_test.cc index 0c61a7d118..1412941ac5 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_remote_control_settings_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_remote_control_settings_test.cc @@ -145,6 +145,11 @@ TEST_F(RCOnRemoteControlSettingsNotificationTest, rc_extention_ptr->SubscribeToInteriorVehicleData(enums_value::kClimate); ON_CALL(*mock_app_, QueryInterface(_)) .WillByDefault(Return(rc_extention_ptr)); + ON_CALL(mock_allocation_manager_, GetAccessMode()) + .WillByDefault(Return(hmi_apis::Common_RCAccessMode::ASK_DRIVER)); + + EXPECT_CALL(mock_allocation_manager_, + SetAccessMode(hmi_apis::Common_RCAccessMode::ASK_DRIVER)); EXPECT_CALL(mock_allocation_manager_, ResetAllAllocations()); -- cgit v1.2.1