summaryrefslogtreecommitdiff
path: root/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc')
-rw-r--r--src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/resource_allocation_manager_impl.cc265
1 files changed, 192 insertions, 73 deletions
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 ecd263b77a..97ff2b23da 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
@@ -33,14 +33,14 @@
#include "rc_rpc_plugin/resource_allocation_manager_impl.h"
#include "application_manager/application.h"
#include "application_manager/application_manager.h"
+#include "application_manager/message_helper.h"
#include "interfaces/HMI_API.h"
#include "interfaces/MOBILE_API.h"
-#include "smart_objects/enum_schema_item.h"
-#include "application_manager/message_helper.h"
-#include "rc_rpc_plugin/rc_rpc_plugin.h"
-#include "rc_rpc_plugin/rc_module_constants.h"
-#include "rc_rpc_plugin/rc_helpers.h"
#include "json/json.h"
+#include "rc_rpc_plugin/rc_helpers.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/helpers.h"
namespace rc_rpc_plugin {
@@ -49,16 +49,20 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "RemoteControlModule")
ResourceAllocationManagerImpl::ResourceAllocationManagerImpl(
application_manager::ApplicationManager& app_mngr,
- application_manager::rpc_service::RPCService& rpc_service)
+ application_manager::rpc_service::RPCService& rpc_service,
+ RCCapabilitiesManager& rc_capabilities_manager)
: current_access_mode_(hmi_apis::Common_RCAccessMode::AUTO_ALLOW)
, app_mngr_(app_mngr)
, rpc_service_(rpc_service)
+ , rc_capabilities_manager_(rc_capabilities_manager)
, is_rc_enabled_(true) {}
ResourceAllocationManagerImpl::~ResourceAllocationManagerImpl() {}
AcquireResult::eType ResourceAllocationManagerImpl::AcquireResource(
- const std::string& module_type, const uint32_t app_id) {
+ const std::string& module_type,
+ const std::string& module_id,
+ const uint32_t app_id) {
LOG4CXX_AUTO_TRACE(logger_);
const application_manager::ApplicationSharedPtr acquiring_app =
app_mngr_.application(app_id);
@@ -67,40 +71,57 @@ AcquireResult::eType ResourceAllocationManagerImpl::AcquireResource(
return AcquireResult::IN_USE;
}
+ ModuleUid module(module_type, module_id);
+
+ if (rc_capabilities_manager_.IsSeatLocationCapabilityProvided() &&
+ !IsUserLocationValid(module, acquiring_app)) {
+ LOG4CXX_WARN(logger_,
+ "Resource acquisition is not allowed "
+ "according to location verification.");
+ return AcquireResult::REJECTED;
+ }
+
sync_primitives::AutoLock lock(allocated_resources_lock_);
const AllocatedResources::const_iterator allocated_it =
- allocated_resources_.find(module_type);
+ allocated_resources_.find(module);
if (allocated_resources_.end() == allocated_it) {
- SetResourceAquired(module_type, app_id);
LOG4CXX_DEBUG(logger_,
"Resource is not acquired yet. "
<< "App: " << app_id << " is allowed to acquire "
- << module_type);
+ << module_type << " " << module_id);
return AcquireResult::ALLOWED;
}
- if (app_id == allocated_resources_[module_type]) {
+ if (app_id == allocated_resources_[module]) {
LOG4CXX_DEBUG(logger_,
"App: " << app_id << " is already acquired resource "
- << module_type);
+ << module_type << " " << module_id);
return AcquireResult::ALLOWED;
}
- if (IsModuleTypeRejected(module_type, app_id)) {
+ if (IsModuleTypeRejected(module_type, module_id, app_id)) {
LOG4CXX_DEBUG(logger_,
"Driver disallowed app: " << app_id << " to acquire "
- << module_type);
+ << module_type << " " << module_id);
return AcquireResult::REJECTED;
}
const mobile_apis::HMILevel::eType acquiring_app_hmi_level =
- acquiring_app->hmi_level();
+ acquiring_app->hmi_level(mobile_apis::PredefinedWindows::DEFAULT_WINDOW);
if (mobile_apis::HMILevel::HMI_FULL != acquiring_app_hmi_level) {
LOG4CXX_DEBUG(logger_,
"Aquiring resources is not allowed in HMI level: "
<< acquiring_app_hmi_level << ". App: " << app_id
- << " is disallowed to acquire " << module_type);
+ << " is disallowed to acquire " << module_type << " "
+ << module_id);
+ return AcquireResult::REJECTED;
+ }
+
+ if (!rc_capabilities_manager_.IsMultipleAccessAllowed(module)) {
+ LOG4CXX_DEBUG(logger_,
+ "Multiple access for the: " << module_type << " " << module_id
+ << " isn't allowed");
return AcquireResult::REJECTED;
}
@@ -109,34 +130,57 @@ AcquireResult::eType ResourceAllocationManagerImpl::AcquireResource(
LOG4CXX_DEBUG(logger_,
"Current access_mode is AUTO_DENY. "
<< "App: " << app_id << " is disallowed to acquire "
- << module_type);
+ << module_type << " " << module_id);
return AcquireResult::IN_USE;
}
case hmi_apis::Common_RCAccessMode::ASK_DRIVER: {
LOG4CXX_DEBUG(logger_,
"Current access_mode is ASK_DRIVER. "
"Driver confirmation is required for app: "
- << app_id << " to acquire " << module_type);
+ << app_id << " to acquire " << module_type << " "
+ << module_id);
return AcquireResult::ASK_DRIVER;
}
case hmi_apis::Common_RCAccessMode::AUTO_ALLOW: {
LOG4CXX_DEBUG(logger_,
"Current access_mode is AUTO_ALLOW. "
<< "App: " << app_id << " is allowed to acquire "
- << module_type);
-
- SetResourceAquired(module_type, app_id);
+ << module_type << " " << module_id);
return AcquireResult::ALLOWED;
}
default: { DCHECK_OR_RETURN(false, AcquireResult::IN_USE); }
}
}
-void ResourceAllocationManagerImpl::ReleaseResource(
+bool ResourceAllocationManagerImpl::IsUserLocationValid(
+ ModuleUid& module, application_manager::ApplicationSharedPtr app) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ const auto extension = RCHelpers::GetRCExtension(*app);
+ const auto user_location = extension->GetUserLocation();
+ const auto module_service_area =
+ rc_capabilities_manager_.GetModuleServiceArea(module);
+ const auto driver =
+ rc_capabilities_manager_.GetDriverLocationFromSeatLocationCapability();
+ const bool is_driver = user_location == driver;
+ if (is_driver || user_location.IntersectionExists(module_service_area)) {
+ return true;
+ }
+ LOG4CXX_DEBUG(logger_, "User location is not valid");
+ return false;
+}
+
+void ResourceAllocationManagerImpl::ReleaseModuleType(
const std::string& module_type, const uint32_t application_id) {
LOG4CXX_AUTO_TRACE(logger_);
- LOG4CXX_DEBUG(logger_, "Release " << module_type << " by " << application_id);
- SetResourceFree(module_type, application_id);
+ LOG4CXX_DEBUG(logger_,
+ "Release " << module_type << " "
+ << " by " << application_id);
+ Resources allocated_resources = GetAcquiredResources(application_id);
+ for (const auto& resource : allocated_resources) {
+ if (module_type == resource.first) {
+ SetResourceFree(module_type, resource.second, application_id);
+ }
+ }
}
void ResourceAllocationManagerImpl::ProcessApplicationPolicyUpdate() {
@@ -147,10 +191,10 @@ void ResourceAllocationManagerImpl::ProcessApplicationPolicyUpdate() {
for (; app_list.end() != app; ++app) {
application_manager::ApplicationSharedPtr app_ptr = *app;
const uint32_t application_id = app_ptr->app_id();
- Resources acquired_modules = GetAcquiredResources(application_id);
- std::sort(acquired_modules.begin(), acquired_modules.end());
+ std::set<std::string> acquired_modules =
+ GetAcquiredModuleTypes(application_id);
- Resources allowed_modules;
+ std::vector<std::string> allowed_modules;
app_mngr_.GetPolicyHandler().GetModuleTypes((*app)->policy_app_id(),
&allowed_modules);
std::sort(allowed_modules.begin(), allowed_modules.end());
@@ -160,17 +204,16 @@ void ResourceAllocationManagerImpl::ProcessApplicationPolicyUpdate() {
<< " , allowed modules: "
<< allowed_modules.size());
- Resources disallowed_modules;
+ std::vector<std::string> disallowed_modules;
std::set_difference(acquired_modules.begin(),
acquired_modules.end(),
allowed_modules.begin(),
allowed_modules.end(),
std::back_inserter(disallowed_modules));
- auto rc_extention = RCHelpers::GetRCExtension(**app);
- Resources::const_iterator module = disallowed_modules.begin();
+ auto module = disallowed_modules.begin();
for (; disallowed_modules.end() != module; ++module) {
- ReleaseResource(*module, application_id);
+ ReleaseModuleType(*module, application_id);
}
if (!disallowed_modules.empty()) {
SendOnRCStatusNotifications(
@@ -190,23 +233,24 @@ EnumType StringToEnum(const std::string& str) {
void ConstructOnRCStatusNotificationParams(
smart_objects::SmartObject& msg_params,
- const std::map<std::string, uint32_t>& allocated_resources,
- const std::vector<std::string>& supported_resources,
+ const std::map<ModuleUid, uint32_t>& allocated_resources,
+ const std::vector<ModuleUid>& supported_resources,
const uint32_t app_id) {
namespace strings = application_manager::strings;
namespace message_params = rc_rpc_plugin::message_params;
using smart_objects::SmartObject;
- using smart_objects::SmartType_Map;
using smart_objects::SmartType_Array;
+ using smart_objects::SmartType_Map;
LOG4CXX_AUTO_TRACE(logger_);
auto modules_inserter = [](SmartObject& result_modules) {
- return [&result_modules](const std::string& module_name) {
+ return [&result_modules](const ModuleUid& module) {
smart_objects::SmartObject module_data =
SmartObject(smart_objects::SmartType_Map);
auto module_type =
- StringToEnum<mobile_apis::ModuleType::eType>(module_name);
+ StringToEnum<mobile_apis::ModuleType::eType>(module.first);
module_data[message_params::kModuleType] = module_type;
+ module_data[message_params::kModuleId] = module.second;
result_modules.asArray()->push_back(module_data);
};
};
@@ -236,10 +280,11 @@ ResourceAllocationManagerImpl::CreateOnRCStatusNotificationToMobile(
mobile_apis::FunctionID::OnRCStatusID, app->app_id());
auto& msg_params = (*msg_to_mobile)[application_manager::strings::msg_params];
if (is_rc_enabled()) {
- ConstructOnRCStatusNotificationParams(msg_params,
- allocated_resources_,
- RCHelpers::GetModulesList(),
- app->app_id());
+ ConstructOnRCStatusNotificationParams(
+ msg_params,
+ allocated_resources_,
+ rc_capabilities_manager_.GetResources(),
+ app->app_id());
} else {
msg_params[message_params::kAllocatedModules] =
smart_objects::SmartObject(smart_objects::SmartType_Array);
@@ -259,21 +304,12 @@ ResourceAllocationManagerImpl::CreateOnRCStatusNotificationToHmi(
auto& msg_params = (*msg_to_hmi)[application_manager::strings::msg_params];
ConstructOnRCStatusNotificationParams(msg_params,
allocated_resources_,
- RCHelpers::GetModulesList(),
+ rc_capabilities_manager_.GetResources(),
app->app_id());
msg_params[application_manager::strings::app_id] = app->hmi_app_id();
return msg_to_hmi;
}
-void ResourceAllocationManagerImpl::SetResourceAquired(
- const std::string& module_type, const uint32_t app_id) {
- LOG4CXX_AUTO_TRACE(logger_);
- allocated_resources_[module_type] = app_id;
- SendOnRCStatusNotifications(
- NotificationTrigger::MODULE_ALLOCATION,
- std::shared_ptr<application_manager::Application>());
-}
-
void ResourceAllocationManagerImpl::SendOnRCStatusNotifications(
NotificationTrigger::eType event,
application_manager::ApplicationSharedPtr application) {
@@ -310,25 +346,81 @@ void ResourceAllocationManagerImpl::set_rc_enabled(const bool value) {
std::shared_ptr<application_manager::Application>());
}
-void ResourceAllocationManagerImpl::SetResourceFree(
- const std::string& module_type, const uint32_t app_id) {
+ResourceReleasedState::eType ResourceAllocationManagerImpl::ReleaseResource(
+ const std::string& module_type,
+ const std::string& module_id,
+ const uint32_t application_id) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ LOG4CXX_DEBUG(logger_,
+ "Release " << module_type << " " << module_id << " by "
+ << application_id);
+ return SetResourceFree(module_type, module_id, application_id);
+}
+
+void ResourceAllocationManagerImpl::SetResourceAcquired(
+ const std::string& module_type,
+ const std::string& module_id,
+ const uint32_t app_id) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ ModuleUid module(module_type, module_id);
+ allocated_resources_[module] = app_id;
+}
+
+bool ResourceAllocationManagerImpl::IsResourceAlreadyAcquiredByApp(
+ const ModuleUid& moduleUid, const uint32_t app_id) const {
+ LOG4CXX_AUTO_TRACE(logger_);
+
+ auto allocation = allocated_resources_.find(moduleUid);
+
+ if (allocated_resources_.end() == allocation) {
+ LOG4CXX_DEBUG(logger_,
+ "Resource " << moduleUid.first
+ << " is not allocated for any application.");
+ return false;
+ }
+
+ if (allocation->second != app_id) {
+ LOG4CXX_DEBUG(logger_,
+ "Resource "
+ << moduleUid.first
+ << " is already allocated by app:" << allocation->second
+ << ". Asquire has been asked for app:" << app_id);
+ return false;
+ }
+
+ LOG4CXX_DEBUG(logger_,
+ "Resource " << moduleUid.first
+ << " is allocated by app:" << allocation->second);
+
+ return true;
+}
+
+ResourceReleasedState::eType ResourceAllocationManagerImpl::SetResourceFree(
+ const std::string& module_type,
+ const std::string& module_id,
+ const uint32_t app_id) {
+ ModuleUid module(module_type, module_id);
AllocatedResources::const_iterator allocation =
- allocated_resources_.find(module_type);
+ allocated_resources_.find(module);
if (allocated_resources_.end() == allocation) {
LOG4CXX_DEBUG(logger_, "Resource " << module_type << " is not allocated.");
- return;
+ return ResourceReleasedState::NOT_ALLOCATED;
}
if (app_id != allocation->second) {
LOG4CXX_ERROR(logger_,
"Resource " << module_type
<< " is allocated by different application "
<< allocation->second);
+ return ResourceReleasedState::IS_ALLOCATED;
}
allocated_resources_.erase(allocation);
- LOG4CXX_DEBUG(logger_, "Resource " << module_type << " is released.");
+ LOG4CXX_DEBUG(
+ logger_,
+ "Resource " << module_type << ":" << module_id << " is released.");
+ return ResourceReleasedState::IS_RELEASED;
}
-std::vector<std::string> ResourceAllocationManagerImpl::GetAcquiredResources(
+std::vector<ModuleUid> ResourceAllocationManagerImpl::GetAcquiredResources(
const uint32_t application_id) const {
LOG4CXX_AUTO_TRACE(logger_);
Resources allocated_resources;
@@ -347,18 +439,37 @@ std::vector<std::string> ResourceAllocationManagerImpl::GetAcquiredResources(
return allocated_resources;
}
+std::set<std::string> ResourceAllocationManagerImpl::GetAcquiredModuleTypes(
+ const uint32_t application_id) const {
+ LOG4CXX_AUTO_TRACE(logger_);
+ Resources allocated_resources = GetAcquiredResources(application_id);
+ std::set<std::string> acquired_module_types;
+ for (const auto& resource : allocated_resources) {
+ acquired_module_types.insert(resource.first);
+ }
+
+ LOG4CXX_DEBUG(logger_,
+ "Application " << application_id << " acquired "
+ << acquired_module_types.size()
+ << " module type(s).");
+
+ return acquired_module_types;
+}
+
void ResourceAllocationManagerImpl::SetResourceState(
const std::string& module_type,
+ const std::string& module_id,
const uint32_t app_id,
const ResourceState::eType state) {
LOG4CXX_AUTO_TRACE(logger_);
LOG4CXX_DEBUG(logger_,
"Setting state for " << module_type << " by app_id " << app_id
<< " to state " << state);
+ ModuleUid module(module_type, module_id);
{
sync_primitives::AutoLock lock(allocated_resources_lock_);
const AllocatedResources::const_iterator allocated_it =
- allocated_resources_.find(module_type);
+ allocated_resources_.find(module);
const bool acquired = allocated_resources_.end() != allocated_it;
if (acquired) {
@@ -374,16 +485,16 @@ void ResourceAllocationManagerImpl::SetResourceState(
}
sync_primitives::AutoLock lock(resources_state_lock_);
- resources_state_[module_type] = state;
+ resources_state_[module] = state;
LOG4CXX_DEBUG(logger_, "Resource " << module_type << " got state " << state);
}
bool ResourceAllocationManagerImpl::IsResourceFree(
- const std::string& module_type) const {
+ const std::string& module_type, const std::string& module_id) const {
LOG4CXX_AUTO_TRACE(logger_);
+ ModuleUid module(module_type, module_id);
sync_primitives::AutoLock lock(resources_state_lock_);
- const ResourcesState::const_iterator resource =
- resources_state_.find(module_type);
+ const ResourcesState::const_iterator resource = resources_state_.find(module);
if (resources_state_.end() == resource) {
LOG4CXX_DEBUG(logger_, "Resource " << module_type << " is free.");
@@ -411,15 +522,20 @@ ResourceAllocationManagerImpl::GetAccessMode() const {
}
void ResourceAllocationManagerImpl::ForceAcquireResource(
- const std::string& module_type, const uint32_t app_id) {
+ const std::string& module_type,
+ const std::string& module_id,
+ const uint32_t app_id) {
LOG4CXX_DEBUG(logger_, "Force " << app_id << " acquiring " << module_type);
sync_primitives::AutoLock lock(allocated_resources_lock_);
- SetResourceAquired(module_type, app_id);
+ SetResourceAcquired(module_type, module_id, app_id);
}
bool ResourceAllocationManagerImpl::IsModuleTypeRejected(
- const std::string& module_type, const uint32_t app_id) {
+ const std::string& module_type,
+ const std::string& module_id,
+ const uint32_t app_id) {
LOG4CXX_AUTO_TRACE(logger_);
+ ModuleUid module(module_type, module_id);
sync_primitives::AutoLock lock(rejected_resources_for_application_lock_);
RejectedResources::iterator it =
rejected_resources_for_application_.find(app_id);
@@ -428,24 +544,27 @@ bool ResourceAllocationManagerImpl::IsModuleTypeRejected(
return false;
}
- const std::vector<std::string>& list_of_rejected_resources =
+ const std::vector<ModuleUid>& list_of_rejected_resources =
rejected_resources_for_application_[app_id];
- return helpers::in_range(list_of_rejected_resources, module_type);
+ return helpers::in_range(list_of_rejected_resources, module);
}
void ResourceAllocationManagerImpl::OnDriverDisallowed(
- const std::string& module_type, const uint32_t app_id) {
+ const std::string& module_type,
+ const std::string& module_id,
+ const uint32_t app_id) {
LOG4CXX_AUTO_TRACE(logger_);
+ ModuleUid module(module_type, module_id);
sync_primitives::AutoLock lock(rejected_resources_for_application_lock_);
auto it = rejected_resources_for_application_.find(app_id);
if (rejected_resources_for_application_.end() == it) {
- rejected_resources_for_application_[app_id] = std::vector<std::string>();
+ rejected_resources_for_application_[app_id] = std::vector<ModuleUid>();
}
- std::vector<std::string>& list_of_rejected_resources =
+ std::vector<ModuleUid>& list_of_rejected_resources =
rejected_resources_for_application_[app_id];
- list_of_rejected_resources.push_back(module_type);
+ list_of_rejected_resources.push_back(module);
}
void ResourceAllocationManagerImpl::OnApplicationEvent(
@@ -458,10 +577,10 @@ void ResourceAllocationManagerImpl::OnApplicationEvent(
if (ApplicationEvent::kApplicationExit == event ||
ApplicationEvent::kApplicationUnregistered == event) {
- Resources acquired_modules = GetAcquiredResources(application->app_id());
- Resources::const_iterator module = acquired_modules.begin();
+ auto acquired_modules = GetAcquiredModuleTypes(application->app_id());
+ auto module = acquired_modules.begin();
for (; acquired_modules.end() != module; ++module) {
- ReleaseResource(*module, application->app_id());
+ ReleaseModuleType(*module, application->app_id());
}
if (!acquired_modules.empty()) {
SendOnRCStatusNotifications(