diff options
author | Alexander Kutsan (GitHub) <akutsan@luxoft.com> | 2018-06-19 14:23:10 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-19 14:23:10 +0300 |
commit | cf7ffa02a4a9ae1e6a563a357139b26f5f47a692 (patch) | |
tree | 7dcd23d0da79bf7d6b18ae78e80507654c33be7a | |
parent | 1faf0e389a207a67cbd6362f395d6b0b45103026 (diff) | |
parent | 9994f3f193782f0e262d6df84e3a7290d62bb50a (diff) | |
download | sdl_core-feature/rc_refactoring.tar.gz |
Merge pull request #2197 from smartdevicelink/fix/rc_disablingfeature/rc_refactoring
Fix behavior in case when RC functionality is disabled from HMI
11 files changed, 69 insertions, 35 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..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 @@ -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)); @@ -115,42 +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"); - if ((*message_)[app_mngr::strings::msg_params].keyExists( - message_params::kAccessMode)) { - access_mode = static_cast<hmi_apis::Common_RCAccessMode::eType>( - (*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<hmi_apis::Common_RCAccessMode::eType>( + (*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_.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 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/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<std::string> 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/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()); 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 <class Command> 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 |