summaryrefslogtreecommitdiff
path: root/src/components/application_manager/src/policies/policy_handler.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/application_manager/src/policies/policy_handler.cc')
-rw-r--r--src/components/application_manager/src/policies/policy_handler.cc200
1 files changed, 131 insertions, 69 deletions
diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc
index 559b9c0035..1b64c5d7b4 100644
--- a/src/components/application_manager/src/policies/policy_handler.cc
+++ b/src/components/application_manager/src/policies/policy_handler.cc
@@ -42,6 +42,7 @@
#include "application_manager/application_manager.h"
#include "application_manager/state_controller.h"
#include "application_manager/message_helper.h"
+#include "application_manager/rpc_service.h"
#include "policy/policy_manager_impl.h"
#include "connection_handler/connection_handler.h"
#include "utils/macro.h"
@@ -53,11 +54,9 @@
#include "interfaces/MOBILE_API.h"
#include "utils/file_system.h"
#include "utils/scope_guard.h"
-#include "utils/make_shared.h"
+
+#include "utils/helpers.h"
#include "policy/policy_manager.h"
-#ifdef SDL_REMOTE_CONTROL
-#include "functional_module/plugin_manager.h"
-#endif // SDL_REMOTE_CONTROL
namespace policy {
@@ -90,7 +89,8 @@ RequestTypeMap TypeToString = {
{mobile_apis::RequestType::VEHICLE_DIAGNOSTICS, "VEHICLE_DIAGNOSTICS"},
{mobile_apis::RequestType::EMERGENCY, "EMERGENCY"},
{mobile_apis::RequestType::MEDIA, "MEDIA"},
- {mobile_apis::RequestType::FOTA, "FOTA"}};
+ {mobile_apis::RequestType::FOTA, "FOTA"},
+ {mobile_apis::RequestType::OEM_SPECIFIC, "OEM_SPECIFIC"}};
const std::string RequestTypeToString(mobile_apis::RequestType::eType type) {
RequestTypeMap::const_iterator it = TypeToString.find(type);
@@ -162,10 +162,12 @@ struct DeactivateApplication {
void operator()(const ApplicationSharedPtr& app) {
if (device_id_ == app->device()) {
- state_ctrl_.SetRegularState(app,
- mobile_apis::HMILevel::HMI_NONE,
- mobile_apis::AudioStreamingState::NOT_AUDIBLE,
- true);
+ state_ctrl_.SetRegularState(
+ app,
+ mobile_apis::HMILevel::HMI_NONE,
+ mobile_apis::AudioStreamingState::NOT_AUDIBLE,
+ mobile_apis::VideoStreamingState::NOT_STREAMABLE,
+ true);
}
}
@@ -222,7 +224,7 @@ struct LinksCollector {
}
void operator()(const ApplicationSharedPtr& app) {
- if (!app.valid()) {
+ if (app.use_count() == 0) {
LOG4CXX_WARN(logger_,
"Invalid pointer to application was passed."
"Skip current application.");
@@ -256,7 +258,7 @@ struct LinkAppToDevice {
}
void operator()(const ApplicationSharedPtr& app) {
- if (!app.valid()) {
+ if (app.use_count() == 0) {
LOG4CXX_WARN(logger_,
"Invalid pointer to application was passed."
"Skip current application.");
@@ -325,8 +327,7 @@ PolicyHandler::PolicyHandler(const PolicySettings& settings,
: AsyncRunner("PolicyHandler async runner thread")
, dl_handle_(0)
, last_activated_app_id_(0)
- , app_to_device_link_lock_(true)
- , statistic_manager_impl_(utils::MakeShared<StatisticManagerImpl>(this))
+ , statistic_manager_impl_(std::make_shared<StatisticManagerImpl>(this))
, settings_(settings)
, application_manager_(application_manager) {}
@@ -353,14 +354,14 @@ bool PolicyHandler::LoadPolicyLibrary() {
if (CreateManager()) {
policy_manager_->set_listener(this);
event_observer_ =
- utils::SharedPtr<PolicyEventObserver>(new PolicyEventObserver(
+ std::shared_ptr<PolicyEventObserver>(new PolicyEventObserver(
this, application_manager_.event_dispatcher()));
}
} else {
LOG4CXX_ERROR(logger_, error);
}
- return policy_manager_.valid();
+ return (policy_manager_.use_count() != 0);
}
bool PolicyHandler::CreateManager() {
@@ -373,11 +374,11 @@ bool PolicyHandler::CreateManager() {
char* error_string = dlerror();
if (NULL == error_string) {
policy_manager_ =
- utils::SharedPtr<PolicyManager>(create_manager(), delete_manager);
+ std::shared_ptr<PolicyManager>(create_manager(), delete_manager);
} else {
LOG4CXX_WARN(logger_, error_string);
}
- return policy_manager_.valid();
+ return (policy_manager_.use_count() != 0);
}
const PolicySettings& PolicyHandler::get_settings() const {
@@ -518,7 +519,7 @@ void PolicyHandler::SendOnAppPermissionsChanged(
<< policy_app_id);
ApplicationSharedPtr app =
application_manager_.application_by_policy_id(policy_app_id);
- if (!app.valid()) {
+ if (app.use_count() == 0) {
LOG4CXX_WARN(logger_, "No app found for policy app id = " << policy_app_id);
return;
}
@@ -553,7 +554,7 @@ struct SmartObjectToInt {
StatusNotifier PolicyHandler::AddApplication(
const std::string& application_id,
const rpc::policy_table_interface_base::AppHmiTypes& hmi_types) {
- POLICY_LIB_CHECK(utils::MakeShared<utils::CallNothing>());
+ POLICY_LIB_CHECK(std::make_shared<utils::CallNothing>());
return policy_manager_->AddApplication(application_id, hmi_types);
}
@@ -589,7 +590,7 @@ void PolicyHandler::OnAppPermissionConsentInternal(
if (connection_key) {
ApplicationSharedPtr app = application_manager_.application(connection_key);
- if (app.valid()) {
+ if (app.use_count() != 0) {
out_permissions.policy_app_id = app->policy_app_id();
DeviceParams device_params = GetDeviceParams(
app->device(),
@@ -616,7 +617,7 @@ void PolicyHandler::OnAppPermissionConsentInternal(
// If list of apps sent to HMI for user consents is not the same as
// current,
// permissions should be set only for coincident to registered apps
- if (!app.valid()) {
+ if (app.use_count() == 0) {
LOG4CXX_WARN(logger_,
"Invalid pointer to application was passed."
"Permissions setting skipped.");
@@ -657,9 +658,9 @@ void PolicyHandler::OnAppPermissionConsentInternal(
void policy::PolicyHandler::SetDaysAfterEpoch() {
POLICY_LIB_CHECK_VOID();
- TimevalStruct current_time = date_time::DateTime::getCurrentTime();
+ date_time::TimeDuration current_time = date_time::getCurrentTime();
const int kSecondsInDay = 60 * 60 * 24;
- int days_after_epoch = current_time.tv_sec / kSecondsInDay;
+ int days_after_epoch = date_time::getSecs(current_time) / kSecondsInDay;
PTUpdatedAt(Counters::DAYS_AFTER_EPOCH, days_after_epoch);
}
@@ -731,7 +732,7 @@ std::vector<FunctionalGroupPermission> PolicyHandler::CollectAppPermissions(
ApplicationSharedPtr app = application_manager_.application(connection_key);
std::vector<FunctionalGroupPermission> group_permissions;
- if (NULL == app.get() || !app.valid()) {
+ if (NULL == app.get() || app.use_count() == 0) {
LOG4CXX_WARN(logger_,
"Connection key '"
<< connection_key
@@ -881,7 +882,7 @@ std::string PolicyHandler::OnCurrentDeviceIdUpdateRequired(
ApplicationSharedPtr app =
application_manager_.application_by_policy_id(policy_app_id);
- if (!app.valid()) {
+ if (app.use_count() == 0) {
LOG4CXX_WARN(logger_,
"Application with id '"
<< policy_app_id
@@ -950,13 +951,14 @@ void PolicyHandler::OnVehicleDataUpdated(
void PolicyHandler::OnPendingPermissionChange(
const std::string& policy_app_id) {
+ LOG4CXX_AUTO_TRACE(logger_);
LOG4CXX_DEBUG(logger_,
"PolicyHandler::OnPendingPermissionChange for "
<< policy_app_id);
POLICY_LIB_CHECK_VOID();
ApplicationSharedPtr app =
application_manager_.application_by_policy_id(policy_app_id);
- if (!app.valid()) {
+ if (app.use_count() == 0) {
LOG4CXX_WARN(logger_,
"No app found for " << policy_app_id << " policy app id.");
return;
@@ -974,6 +976,7 @@ void PolicyHandler::OnPendingPermissionChange(
app,
mobile_apis::HMILevel::HMI_NONE,
mobile_apis::AudioStreamingState::NOT_AUDIBLE,
+ mobile_apis::VideoStreamingState::NOT_STREAMABLE,
true);
policy_manager_->RemovePendingPermissionChanges(policy_app_id);
return;
@@ -987,8 +990,6 @@ void PolicyHandler::OnPendingPermissionChange(
if (permissions.appPermissionsConsentNeeded) {
MessageHelper::SendOnAppPermissionsChangedNotification(
app->app_id(), permissions, application_manager_);
-
- policy_manager_->RemovePendingPermissionChanges(policy_app_id);
// "Break" statement has to be here to continue processing in case of
// there is another "true" flag in permissions struct
break;
@@ -998,8 +999,6 @@ void PolicyHandler::OnPendingPermissionChange(
if (permissions.isAppPermissionsRevoked) {
MessageHelper::SendOnAppPermissionsChangedNotification(
app->app_id(), permissions, application_manager_);
-
- policy_manager_->RemovePendingPermissionChanges(policy_app_id);
}
break;
}
@@ -1013,22 +1012,21 @@ void PolicyHandler::OnPendingPermissionChange(
MessageHelper::SendOnAppPermissionsChangedNotification(
app->app_id(), permissions, application_manager_);
}
- application_manager_.ManageMobileCommand(
+ application_manager_.GetRPCService().ManageMobileCommand(
MessageHelper::GetOnAppInterfaceUnregisteredNotificationToMobile(
app->app_id(),
mobile_api::AppInterfaceUnregisteredReason::APP_UNAUTHORIZED),
- commands::Command::ORIGIN_SDL);
+ commands::Command::SOURCE_SDL);
application_manager_.OnAppUnauthorized(app->app_id());
-
- policy_manager_->RemovePendingPermissionChanges(policy_app_id);
}
- if (permissions.requestTypeChanged) {
+ if (permissions.requestTypeChanged || permissions.requestSubTypeChanged) {
MessageHelper::SendOnAppPermissionsChangedNotification(
app->app_id(), permissions, application_manager_);
- policy_manager_->RemovePendingPermissionChanges(policy_app_id);
}
+
+ policy_manager_->RemovePendingPermissionChanges(policy_app_id);
}
bool PolicyHandler::SendMessageToSDK(const BinaryMessage& pt_string,
@@ -1080,12 +1078,7 @@ bool PolicyHandler::ReceiveMessageFromSDK(const std::string& file,
SetDaysAfterEpoch();
event_observer_->subscribe_on_event(
-#ifdef HMI_DBUS_API
- hmi_apis::FunctionID::VehicleInfo_GetOdometer, correlation_id
-#else
- hmi_apis::FunctionID::VehicleInfo_GetVehicleData, correlation_id
-#endif
- );
+ hmi_apis::FunctionID::VehicleInfo_GetVehicleData, correlation_id);
std::vector<std::string> vehicle_data_args;
vehicle_data_args.push_back(strings::odometer);
MessageHelper::CreateGetVehicleDataRequest(
@@ -1193,10 +1186,6 @@ void PolicyHandler::OnAllowSDLFunctionalityNotification(
accessor.GetData().end(),
DeactivateApplication(device_handle,
application_manager_.state_controller()));
-#ifdef SDL_REMOTE_CONTROL
- application_manager_.GetPluginManager().OnPolicyEvent(
- functional_modules::PolicyEvent::kApplicationsDisabled);
-#endif // SDL_REMOTE_CONTROL
} else {
std::for_each(
accessor.GetData().begin(),
@@ -1245,12 +1234,15 @@ void PolicyHandler::OnAllowSDLFunctionalityNotification(
if (is_allowed) {
// Send HMI status notification to mobile
// Put application in full
- AudioStreamingState::eType state = app->is_audio()
- ? AudioStreamingState::AUDIBLE
- : AudioStreamingState::NOT_AUDIBLE;
+ AudioStreamingState::eType audio_state =
+ app->IsAudioApplication() ? AudioStreamingState::AUDIBLE
+ : AudioStreamingState::NOT_AUDIBLE;
+ VideoStreamingState::eType video_state =
+ app->IsVideoApplication() ? VideoStreamingState::STREAMABLE
+ : VideoStreamingState::NOT_STREAMABLE;
application_manager_.state_controller().SetRegularState(
- app, mobile_apis::HMILevel::HMI_FULL, state, true);
+ app, mobile_apis::HMILevel::HMI_FULL, audio_state, video_state, true);
last_activated_app_id_ = 0;
} else {
DeactivateApplication deactivate_notification(
@@ -1270,9 +1262,8 @@ void PolicyHandler::OnIgnitionCycleOver() {
void PolicyHandler::OnActivateApp(uint32_t connection_key,
uint32_t correlation_id) {
LOG4CXX_AUTO_TRACE(logger_);
- POLICY_LIB_CHECK_VOID();
ApplicationSharedPtr app = application_manager_.application(connection_key);
- if (!app.valid()) {
+ if (app.use_count() == 0) {
LOG4CXX_WARN(logger_, "Activated App failed: no app found.");
return;
}
@@ -1366,7 +1357,7 @@ void PolicyHandler::OnPermissionsUpdated(const std::string& policy_app_id,
ApplicationSharedPtr app =
application_manager_.application_by_policy_id(policy_app_id);
- if (!app.valid()) {
+ if (app.use_count() == 0) {
LOG4CXX_WARN(
logger_,
"Connection_key not found for application_id:" << policy_app_id);
@@ -1419,7 +1410,7 @@ void PolicyHandler::OnPermissionsUpdated(const std::string& policy_app_id,
LOG4CXX_AUTO_TRACE(logger_);
ApplicationSharedPtr app =
application_manager_.application_by_policy_id(policy_app_id);
- if (!app.valid()) {
+ if (app.use_count() == 0) {
LOG4CXX_WARN(
logger_,
"Connection_key not found for application_id:" << policy_app_id);
@@ -1462,7 +1453,7 @@ void PolicyHandler::OnSnapshotCreated(
std::string policy_snapshot_full_path;
if (SaveSnapshot(pt_string, policy_snapshot_full_path)) {
const uint32_t timeout_exchange_s =
- timeout_exchange_ms / date_time::DateTime::MILLISECONDS_IN_SECOND;
+ timeout_exchange_ms / date_time::MILLISECONDS_IN_SECOND;
MessageHelper::SendPolicyUpdate(policy_snapshot_full_path,
timeout_exchange_s,
retry_delay_seconds,
@@ -1519,6 +1510,13 @@ void PolicyHandler::CheckPermissions(
POLICY_LIB_CHECK_VOID();
const std::string hmi_level =
MessageHelper::StringifiedHMILevel(app->hmi_level());
+ if (hmi_level.empty()) {
+ LOG4CXX_WARN(logger_,
+ "HMI level for " << app->policy_app_id() << " is invalid, rpc "
+ << rpc << " is not allowed.");
+ result.hmi_level_permitted = policy::kRpcDisallowed;
+ return;
+ }
const std::string device_id = MessageHelper::GetDeviceMacAddressForHandle(
app->device(), application_manager_);
LOG4CXX_INFO(logger_,
@@ -1584,7 +1582,7 @@ uint32_t PolicyHandler::NextRetryTimeout() {
}
uint32_t PolicyHandler::TimeoutExchangeSec() const {
- return TimeoutExchangeMSec() / date_time::DateTime::MILLISECONDS_IN_SECOND;
+ return TimeoutExchangeMSec() / date_time::MILLISECONDS_IN_SECOND;
}
uint32_t PolicyHandler::TimeoutExchangeMSec() const {
@@ -1623,7 +1621,7 @@ void PolicyHandler::remove_listener(PolicyHandlerObserver* listener) {
listeners_.remove(listener);
}
-utils::SharedPtr<usage_statistics::StatisticsManager>
+std::shared_ptr<usage_statistics::StatisticsManager>
PolicyHandler::GetStatisticManager() const {
return statistic_manager_impl_;
}
@@ -1665,7 +1663,7 @@ custom_str::CustomString PolicyHandler::GetAppName(
ApplicationSharedPtr app =
application_manager_.application_by_policy_id(policy_app_id);
- if (!app.valid()) {
+ if (app.use_count() == 0) {
LOG4CXX_WARN(
logger_,
"Connection_key not found for application_id:" << policy_app_id);
@@ -1879,6 +1877,18 @@ void PolicyHandler::OnAppRegisteredOnMobile(const std::string& application_id) {
policy_manager_->OnAppRegisteredOnMobile(application_id);
}
+RequestType::State PolicyHandler::GetAppRequestTypeState(
+ const std::string& policy_app_id) const {
+ POLICY_LIB_CHECK(RequestType::State::UNAVAILABLE);
+ return policy_manager_->GetAppRequestTypesState(policy_app_id);
+}
+
+RequestSubType::State PolicyHandler::GetAppRequestSubTypeState(
+ const std::string& policy_app_id) const {
+ POLICY_LIB_CHECK(RequestSubType::State::UNAVAILABLE);
+ return policy_manager_->GetAppRequestSubTypesState(policy_app_id);
+}
+
bool PolicyHandler::IsRequestTypeAllowed(
const std::string& policy_app_id,
mobile_apis::RequestType::eType type) const {
@@ -1891,17 +1901,66 @@ bool PolicyHandler::IsRequestTypeAllowed(
return false;
}
- std::vector<std::string> request_types =
- policy_manager_->GetAppRequestTypes(policy_app_id);
+ const RequestType::State request_type_state =
+ policy_manager_->GetAppRequestTypesState(policy_app_id);
+
+ switch (request_type_state) {
+ case RequestType::State::EMPTY: {
+ // If empty array of request types is assigned to app - any is allowed
+ LOG4CXX_TRACE(logger_, "Any Request Type is allowed by policies.");
+ return true;
+ }
+ case RequestType::State::OMITTED: {
+ // If RequestType parameter omitted for app - any is disallowed
+ LOG4CXX_TRACE(logger_, "All Request Types are disallowed by policies.");
+ return false;
+ }
+ case RequestType::State::AVAILABLE: {
+ // If any of request types is available for current application - get them
+ const auto request_types =
+ policy_manager_->GetAppRequestTypes(policy_app_id);
+ return helpers::in_range(request_types, stringified_type);
+ }
+ default:
+ return false;
+ }
+}
+
+bool PolicyHandler::IsRequestSubTypeAllowed(
+ const std::string& policy_app_id,
+ const std::string& request_subtype) const {
+ POLICY_LIB_CHECK(false);
+ using namespace mobile_apis;
- // If no request types are assigned to app - any is allowed
- if (request_types.empty()) {
- return true;
+ if (request_subtype.empty()) {
+ LOG4CXX_ERROR(logger_, "Request subtype to check is empty.");
+ return false;
}
- std::vector<std::string>::const_iterator it =
- std::find(request_types.begin(), request_types.end(), stringified_type);
- return request_types.end() != it;
+ const RequestSubType::State request_subtype_state =
+ policy_manager_->GetAppRequestSubTypesState(policy_app_id);
+ switch (request_subtype_state) {
+ case RequestSubType::State::EMPTY: {
+ // If empty array of request subtypes is assigned to app - any is allowed
+ LOG4CXX_TRACE(logger_, "Any Request SubType is allowed by policies.");
+ return true;
+ }
+ case RequestSubType::State::OMITTED: {
+ // If RequestSubType parameter omitted for app - any is disallowed
+ LOG4CXX_TRACE(logger_,
+ "All Request SubTypes are disallowed by policies.");
+ return false;
+ }
+ case RequestSubType::State::AVAILABLE: {
+ // If any of request subtypes is available for current application
+ // get them all
+ const auto request_subtypes =
+ policy_manager_->GetAppRequestSubTypes(policy_app_id);
+ return helpers::in_range(request_subtypes, request_subtype);
+ }
+ default:
+ return false;
+ }
}
const std::vector<std::string> PolicyHandler::GetAppRequestTypes(
@@ -1910,6 +1969,12 @@ const std::vector<std::string> PolicyHandler::GetAppRequestTypes(
return policy_manager_->GetAppRequestTypes(policy_app_id);
}
+const std::vector<std::string> PolicyHandler::GetAppRequestSubTypes(
+ const std::string& policy_app_id) const {
+ POLICY_LIB_CHECK(std::vector<std::string>());
+ return policy_manager_->GetAppRequestSubTypes(policy_app_id);
+}
+
const VehicleInfo policy::PolicyHandler::GetVehicleInfo() const {
POLICY_LIB_CHECK(VehicleInfo());
return policy_manager_->GetVehicleInfo();
@@ -1961,8 +2026,6 @@ bool PolicyHandler::IsUrlAppIdValid(const uint32_t app_idx,
return ((is_registered && !is_empty_urls) || is_default);
}
-#ifdef SDL_REMOTE_CONTROL
-
std::vector<std::string> PolicyHandler::GetDevicesIds(
const std::string& policy_app_id) {
return application_manager_.devices(policy_app_id);
@@ -2096,5 +2159,4 @@ void PolicyHandler::OnUpdateHMILevel(const std::string& device_id,
}
UpdateHMILevel(app, level);
}
-#endif // SDL_REMOTE_CONTROL
} // namespace policy