summaryrefslogtreecommitdiff
path: root/src/components/policy/policy_regular/src
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/policy/policy_regular/src')
-rw-r--r--src/components/policy/policy_regular/src/access_remote_impl.cc2
-rw-r--r--src/components/policy/policy_regular/src/cache_manager.cc108
-rw-r--r--src/components/policy/policy_regular/src/policy_helper.cc69
-rw-r--r--src/components/policy/policy_regular/src/policy_manager_impl.cc282
-rw-r--r--src/components/policy/policy_regular/src/policy_table.cc2
-rw-r--r--src/components/policy/policy_regular/src/policy_table/enums.cc738
-rw-r--r--src/components/policy/policy_regular/src/policy_table/types.cc42
-rw-r--r--src/components/policy/policy_regular/src/policy_table/validation.cc47
-rw-r--r--src/components/policy/policy_regular/src/sql_pt_ext_queries.cc268
-rw-r--r--src/components/policy/policy_regular/src/sql_pt_ext_representation.cc1807
-rw-r--r--src/components/policy/policy_regular/src/sql_pt_queries.cc26
-rw-r--r--src/components/policy/policy_regular/src/sql_pt_representation.cc161
-rw-r--r--src/components/policy/policy_regular/src/status.cc25
-rw-r--r--src/components/policy/policy_regular/src/update_status_manager.cc24
-rw-r--r--src/components/policy/policy_regular/src/usage_statistics/counter.cc15
15 files changed, 1353 insertions, 2263 deletions
diff --git a/src/components/policy/policy_regular/src/access_remote_impl.cc b/src/components/policy/policy_regular/src/access_remote_impl.cc
index f99b226f2e..f743a4d56e 100644
--- a/src/components/policy/policy_regular/src/access_remote_impl.cc
+++ b/src/components/policy/policy_regular/src/access_remote_impl.cc
@@ -89,7 +89,7 @@ struct ToModuleType {
AccessRemoteImpl::AccessRemoteImpl() : cache_(new CacheManager()) {}
-AccessRemoteImpl::AccessRemoteImpl(utils::SharedPtr<CacheManager> cache)
+AccessRemoteImpl::AccessRemoteImpl(std::shared_ptr<CacheManager> cache)
: cache_(cache) {}
bool AccessRemoteImpl::CheckModuleType(const PTString& app_id,
diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc
index 6a142374d5..bd95fc8e7c 100644
--- a/src/components/policy/policy_regular/src/cache_manager.cc
+++ b/src/components/policy/policy_regular/src/cache_manager.cc
@@ -39,6 +39,7 @@
#include <sstream>
#include "utils/file_system.h"
+#include "utils/helpers.h"
#include "json/reader.h"
#include "json/features.h"
#include "json/writer.h"
@@ -103,7 +104,7 @@ CacheManager::CacheManager()
, pt_(new policy_table::Table)
, backup_(new SQLPTRepresentation())
, update_required(false)
- , cache_lock_(true) {
+ , settings_(nullptr) {
LOG4CXX_AUTO_TRACE(logger_);
backuper_ = new BackgroundBackuper(this);
backup_thread_ = threads::CreateThread("Backup thread", backuper_);
@@ -645,7 +646,7 @@ int CacheManager::TimeoutResponse() {
CACHE_MANAGER_CHECK(0);
sync_primitives::AutoLock auto_lock(cache_lock_);
return pt_->policy_table.module_config.timeout_after_x_seconds *
- date_time::DateTime::MILLISECONDS_IN_SECOND;
+ date_time::MILLISECONDS_IN_SECOND;
}
bool CacheManager::SecondsBetweenRetries(std::vector<int>& seconds) {
@@ -825,6 +826,9 @@ void CacheManager::CheckSnapshotInitialization() {
*(snapshot_->policy_table.module_config.preloaded_pt) = false;
+ *(snapshot_->policy_table.module_config.full_app_id_supported) =
+ get_settings().use_full_app_id();
+
// SDL must not send certificate in snapshot
snapshot_->policy_table.module_config.certificate =
rpc::Optional<rpc::String<0, 65535> >();
@@ -933,8 +937,8 @@ void CacheManager::CheckSnapshotInitialization() {
void CacheManager::PersistData() {
LOG4CXX_AUTO_TRACE(logger_);
- if (backup_.valid()) {
- if (pt_.valid()) {
+ if (backup_.use_count() != 0) {
+ if (pt_.use_count() != 0) {
// Comma expression is used to hold the lock only during the constructor
// call
policy_table::Table copy_pt(
@@ -1028,10 +1032,10 @@ bool CacheManager::IsPermissionsCalculated(const std::string& device_id,
return false;
}
-utils::SharedPtr<policy_table::Table> CacheManager::GenerateSnapshot() {
+std::shared_ptr<policy_table::Table> CacheManager::GenerateSnapshot() {
CACHE_MANAGER_CHECK(snapshot_);
- snapshot_ = new policy_table::Table();
+ snapshot_ = std::make_shared<policy_table::Table>();
// Copy all members of policy table except messages in consumer friendly
// messages
@@ -1425,7 +1429,7 @@ bool CacheManager::Init(const std::string& file_name,
result = LoadFromFile(file_name, *pt_);
- utils::SharedPtr<policy_table::Table> snapshot = GenerateSnapshot();
+ std::shared_ptr<policy_table::Table> snapshot = GenerateSnapshot();
result &= snapshot->is_valid();
LOG4CXX_DEBUG(logger_,
"Check if snapshot is valid: " << std::boolalpha << result);
@@ -1450,10 +1454,13 @@ bool CacheManager::Init(const std::string& file_name,
void CacheManager::FillDeviceSpecificData() {}
bool CacheManager::LoadFromBackup() {
+ LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock lock(cache_lock_);
pt_ = backup_->GenerateSnapshot();
update_required = backup_->UpdateRequired();
-
+ LOG4CXX_DEBUG(logger_,
+ "Update required flag from backup: " << std::boolalpha
+ << update_required);
FillDeviceSpecificData();
return true;
@@ -1550,6 +1557,32 @@ int32_t CacheManager::GenerateHash(const std::string& str_to_hash) {
return result;
}
+RequestType::State CacheManager::GetAppRequestTypesState(
+ const std::string& policy_app_id) const {
+ LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock auto_lock(cache_lock_);
+ policy_table::ApplicationPolicies::iterator app_policies_iter =
+ pt_->policy_table.app_policies_section.apps.find(policy_app_id);
+ if (pt_->policy_table.app_policies_section.apps.end() == app_policies_iter) {
+ LOG4CXX_DEBUG(logger_,
+ "Can't find request types for app_id " << policy_app_id);
+ return RequestType::State::UNAVAILABLE;
+ }
+ const policy_table::RequestTypes& request_types =
+ *app_policies_iter->second.RequestType;
+ if (!request_types.is_initialized()) {
+ LOG4CXX_DEBUG(logger_,
+ "Request types for " << policy_app_id << " are OMITTED");
+ return RequestType::State::OMITTED;
+ }
+ if (request_types.empty()) {
+ LOG4CXX_DEBUG(logger_,
+ "Request types for " << policy_app_id << " are EMPTY");
+ return RequestType::State::EMPTY;
+ }
+ return RequestType::State::AVAILABLE;
+}
+
void CacheManager::GetAppRequestTypes(
const std::string& policy_app_id,
std::vector<std::string>& request_types) const {
@@ -1568,11 +1601,60 @@ void CacheManager::GetAppRequestTypes(
"Can't find request types for app_id " << policy_app_id);
return;
}
- policy_table::RequestTypes::iterator it_request_type =
- policy_iter->second.RequestType->begin();
- for (; it_request_type != policy_iter->second.RequestType->end();
- ++it_request_type) {
- request_types.push_back(EnumToJsonString(*it_request_type));
+
+ for (const auto& request_type : *policy_iter->second.RequestType) {
+ request_types.push_back(EnumToJsonString(request_type));
+ }
+ return;
+}
+
+RequestSubType::State CacheManager::GetAppRequestSubTypesState(
+ const std::string& policy_app_id) const {
+ LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock auto_lock(cache_lock_);
+ policy_table::ApplicationPolicies::iterator app_policies_iter =
+ pt_->policy_table.app_policies_section.apps.find(policy_app_id);
+ if (pt_->policy_table.app_policies_section.apps.end() == app_policies_iter) {
+ LOG4CXX_DEBUG(logger_,
+ "Can't find request subtypes for app_id " << policy_app_id);
+ return RequestSubType::State::UNAVAILABLE;
+ }
+ const policy_table::RequestSubTypes& request_subtypes =
+ *app_policies_iter->second.RequestSubType;
+ if (!request_subtypes.is_initialized()) {
+ LOG4CXX_DEBUG(logger_,
+ "Request subtypes for " << policy_app_id << " are OMITTED");
+ return RequestSubType::State::OMITTED;
+ }
+ if (request_subtypes.empty()) {
+ LOG4CXX_DEBUG(logger_,
+ "Request subtypes for " << policy_app_id << " are EMPTY");
+ return RequestSubType::State::EMPTY;
+ }
+ return RequestSubType::State::AVAILABLE;
+}
+
+void CacheManager::GetAppRequestSubTypes(
+ const std::string& policy_app_id,
+ std::vector<std::string>& request_types) const {
+ LOG4CXX_AUTO_TRACE(logger_);
+ CACHE_MANAGER_CHECK_VOID();
+ sync_primitives::AutoLock auto_lock(cache_lock_);
+ if (kDeviceId == policy_app_id) {
+ LOG4CXX_DEBUG(logger_,
+ "Request subtypes not applicable for app_id " << kDeviceId);
+ return;
+ }
+ policy_table::ApplicationPolicies::iterator policy_iter =
+ pt_->policy_table.app_policies_section.apps.find(policy_app_id);
+ if (pt_->policy_table.app_policies_section.apps.end() == policy_iter) {
+ LOG4CXX_DEBUG(logger_,
+ "Can't find request subtypes for app_id " << policy_app_id);
+ return;
+ }
+
+ for (const auto& request_subtype : *policy_iter->second.RequestSubType) {
+ request_types.push_back(request_subtype);
}
return;
}
diff --git a/src/components/policy/policy_regular/src/policy_helper.cc b/src/components/policy/policy_regular/src/policy_helper.cc
index 95f275769c..bae9fceb49 100644
--- a/src/components/policy/policy_regular/src/policy_helper.cc
+++ b/src/components/policy/policy_regular/src/policy_helper.cc
@@ -121,8 +121,8 @@ bool operator!=(const policy_table::ApplicationParams& first,
CheckAppPolicy::CheckAppPolicy(
PolicyManagerImpl* pm,
- const utils::SharedPtr<policy_table::Table> update,
- const utils::SharedPtr<policy_table::Table> snapshot)
+ const std::shared_ptr<policy_table::Table> update,
+ const std::shared_ptr<policy_table::Table> snapshot)
: pm_(pm), update_(update), snapshot_(snapshot) {}
bool policy::CheckAppPolicy::HasRevokedGroups(
@@ -339,9 +339,20 @@ bool CheckAppPolicy::operator()(const AppPoliciesValueType& app_policy) {
}
PermissionsCheckResult result = CheckPermissionsChanges(app_policy);
- if (!IsPredefinedApp(app_policy) && IsRequestTypeChanged(app_policy)) {
- SetPendingPermissions(app_policy, RESULT_REQUEST_TYPE_CHANGED);
- NotifySystem(app_policy);
+ if (!IsPredefinedApp(app_policy)) {
+ const bool is_request_type_changed = IsRequestTypeChanged(app_policy);
+ const bool is_request_subtype_changed = IsRequestSubTypeChanged(app_policy);
+
+ if (is_request_type_changed) {
+ SetPendingPermissions(app_policy, RESULT_REQUEST_TYPE_CHANGED);
+ }
+ if (is_request_subtype_changed) {
+ SetPendingPermissions(app_policy, RESULT_REQUEST_SUBTYPE_CHANGED);
+ }
+
+ if (is_request_type_changed || is_request_subtype_changed) {
+ NotifySystem(app_policy);
+ }
}
if (RESULT_NO_CHANGES == result) {
LOG4CXX_INFO(logger_,
@@ -412,17 +423,19 @@ void policy::CheckAppPolicy::SetPendingPermissions(
case RESULT_REQUEST_TYPE_CHANGED:
permissions_diff.priority.clear();
permissions_diff.requestTypeChanged = true;
- {
- // Getting RequestTypes from PTU (not from cache)
- policy_table::RequestTypes::const_iterator it_request_type =
- app_policy.second.RequestType->begin();
- for (; app_policy.second.RequestType->end() != it_request_type;
- ++it_request_type) {
- permissions_diff.requestType.push_back(
- EnumToJsonString(*it_request_type));
- }
- }
+ // Getting Request Types from PTU (not from cache)
+ for (const auto& request_type : *app_policy.second.RequestType) {
+ permissions_diff.requestType.push_back(EnumToJsonString(request_type));
+ }
+ break;
+ case RESULT_REQUEST_SUBTYPE_CHANGED:
+ permissions_diff.priority.clear();
+ permissions_diff.requestSubTypeChanged = true;
+ // Getting Request SubTypes from PTU (not from cache)
+ for (const auto& request_subtype : *app_policy.second.RequestSubType) {
+ permissions_diff.requestSubType.push_back(request_subtype);
+ }
break;
default:
return;
@@ -491,6 +504,32 @@ bool CheckAppPolicy::IsRequestTypeChanged(
return diff.size();
}
+bool CheckAppPolicy::IsRequestSubTypeChanged(
+ const AppPoliciesValueType& app_policy) const {
+ policy::AppPoliciesConstItr it =
+ snapshot_->policy_table.app_policies_section.apps.find(app_policy.first);
+
+ if (it == snapshot_->policy_table.app_policies_section.apps.end()) {
+ if (!app_policy.second.RequestSubType->empty()) {
+ return true;
+ }
+ return false;
+ }
+
+ if (it->second.RequestSubType->size() !=
+ app_policy.second.RequestSubType->size()) {
+ return true;
+ }
+
+ policy_table::RequestSubTypes diff;
+ std::set_difference(it->second.RequestSubType->begin(),
+ it->second.RequestSubType->end(),
+ app_policy.second.RequestSubType->begin(),
+ app_policy.second.RequestSubType->end(),
+ std::back_inserter(diff));
+ return diff.size();
+}
+
FillNotificationData::FillNotificationData(Permissions& data,
GroupConsent group_state,
GroupConsent undefined_group_consent)
diff --git a/src/components/policy/policy_regular/src/policy_manager_impl.cc b/src/components/policy/policy_regular/src/policy_manager_impl.cc
index 3e08147a4c..4985035629 100644
--- a/src/components/policy/policy_regular/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc
@@ -44,17 +44,14 @@
#include "utils/file_system.h"
#include "utils/logger.h"
#include "utils/date_time.h"
-#include "utils/make_shared.h"
+
#include "policy/cache_manager.h"
#include "policy/update_status_manager.h"
#include "config_profile/profile.h"
#include "utils/timer_task_impl.h"
-#include "utils/make_shared.h"
-#ifdef SDL_REMOTE_CONTROL
#include "policy/access_remote.h"
#include "policy/access_remote_impl.h"
-#endif // SDL_REMOTE_CONTROL
policy::PolicyManager* CreateManager() {
return new policy::PolicyManagerImpl();
@@ -65,7 +62,7 @@ void DeleteManager(policy::PolicyManager* pm) {
namespace {
const uint32_t kDefaultRetryTimeoutInMSec =
- 60u * date_time::DateTime::MILLISECONDS_IN_SECOND;
+ 60u * date_time::MILLISECONDS_IN_SECOND;
} // namespace
namespace policy {
@@ -76,10 +73,8 @@ PolicyManagerImpl::PolicyManagerImpl()
: PolicyManager()
, listener_(NULL)
, cache_(new CacheManager)
-#ifdef SDL_REMOTE_CONTROL
- , access_remote_(new AccessRemoteImpl(
- CacheManagerInterfaceSPtr::static_pointer_cast<CacheManager>(cache_)))
-#endif // SDL_REMOTE_CONTROL
+ , access_remote_(
+ new AccessRemoteImpl(std::static_pointer_cast<CacheManager>(cache_)))
, retry_sequence_timeout_(kDefaultRetryTimeoutInMSec)
, retry_sequence_index_(0)
, timer_retry_sequence_("Retry sequence timer",
@@ -89,8 +84,7 @@ PolicyManagerImpl::PolicyManagerImpl()
, retry_sequence_url_(0, 0, "")
, wrong_ptu_update_received_(false)
, send_on_update_sent_out_(false)
- , trigger_ptu_(false) {
-}
+ , trigger_ptu_(false) {}
void PolicyManagerImpl::set_listener(PolicyListener* listener) {
listener_ = listener;
@@ -99,21 +93,21 @@ void PolicyManagerImpl::set_listener(PolicyListener* listener) {
#ifdef USE_HMI_PTU_DECRYPTION
-utils::SharedPtr<policy_table::Table> PolicyManagerImpl::Parse(
+std::shared_ptr<policy_table::Table> PolicyManagerImpl::Parse(
const BinaryMessage& pt_content) {
std::string json(pt_content.begin(), pt_content.end());
Json::Value value;
Json::Reader reader;
if (reader.parse(json.c_str(), value)) {
- return new policy_table::Table(&value);
+ return std::make_shared<policy_table::Table>(&value);
} else {
- return utils::SharedPtr<policy_table::Table>();
+ return std::make_shared<policy_table::Table>();
}
}
#else
-utils::SharedPtr<policy_table::Table> PolicyManagerImpl::ParseArray(
+std::shared_ptr<policy_table::Table> PolicyManagerImpl::ParseArray(
const BinaryMessage& pt_content) {
std::string json(pt_content.begin(), pt_content.end());
Json::Value value;
@@ -122,12 +116,12 @@ utils::SharedPtr<policy_table::Table> PolicyManagerImpl::ParseArray(
// For PT Update received from SDL Server.
if (value["data"].size() != 0) {
Json::Value data = value["data"];
- return new policy_table::Table(&data[0]);
+ return std::make_shared<policy_table::Table>(&data[0]);
} else {
- return new policy_table::Table(&value);
+ return std::make_shared<policy_table::Table>(&value);
}
} else {
- return utils::SharedPtr<policy_table::Table>();
+ return std::shared_ptr<policy_table::Table>();
}
}
@@ -149,6 +143,149 @@ void PolicyManagerImpl::CheckTriggers() {
}
}
+/**
+ * @brief FilterInvalidFunctions filter functions that are absent in schema
+ * @param rpcs list of functions to filter
+ */
+void FilterInvalidFunctions(policy_table::Rpc& rpcs) {
+ policy_table::Rpc valid_rpcs;
+ for (const auto& rpc : rpcs) {
+ const std::string& rpc_name = rpc.first;
+ policy_table::FunctionID function_id;
+ if (policy_table::EnumFromJsonString(rpc_name, &function_id)) {
+ valid_rpcs.insert(rpc);
+ }
+ }
+ rpcs.swap(valid_rpcs);
+}
+
+/**
+ * @brief FilterInvalidRPCParameters filter parameters that not present in
+ * schema
+ * @param rpc_parameters parameters to filter
+ */
+void FilterInvalidRPCParameters(policy_table::RpcParameters& rpc_parameters) {
+ policy_table::HmiLevels valid_hmi_levels;
+ for (const auto& hmi_level : rpc_parameters.hmi_levels) {
+ if (hmi_level.is_valid()) {
+ valid_hmi_levels.push_back(hmi_level);
+ }
+ }
+ rpc_parameters.hmi_levels.swap(valid_hmi_levels);
+
+ policy_table::Parameters valid_params;
+ const policy_table::Parameters& params = *(rpc_parameters.parameters);
+ for (const auto& param : params) {
+ if (param.is_valid()) {
+ valid_params.push_back(param);
+ }
+ }
+ rpc_parameters.parameters->swap(valid_params);
+}
+
+/**
+ * @brief FilterInvalidPriorityValues filter notification priorities that are
+ * not present in schema
+ * @param notifications priorities to filter
+ */
+void FilterInvalidPriorityValues(
+ policy_table::NumberOfNotificationsPerMinute& notifications) {
+ policy_table::NumberOfNotificationsPerMinute valid_notifications;
+ for (const auto& notification : notifications) {
+ policy_table::Priority priority;
+ if (policy_table::EnumFromJsonString(notification.first, &priority)) {
+ valid_notifications.insert(notification);
+ }
+ }
+ notifications.swap(valid_notifications);
+}
+
+/**
+ * @brief FilterInvalidApplicationParameters filter app params that are not
+ * present in schema
+ * @param app_params object of app policy params to filter
+ */
+void FilterInvalidApplicationParameters(
+ policy_table::ApplicationParams& app_params) {
+ // Filter AppHMIType array
+ policy_table::AppHMITypes valid_app_hmi_types;
+ const policy_table::AppHMITypes& app_hmi_types = *(app_params.AppHMIType);
+ for (const auto& app_hmi_type : app_hmi_types) {
+ if (app_hmi_type.is_valid()) {
+ valid_app_hmi_types.push_back(app_hmi_type);
+ }
+ }
+ app_params.AppHMIType->swap(valid_app_hmi_types);
+
+ // Filter RquestTypes array
+ policy_table::RequestTypes valid_request_types;
+ const policy_table::RequestTypes& request_types = *(app_params.RequestType);
+ for (const auto& request_type : request_types) {
+ if (request_type.is_valid()) {
+ valid_request_types.push_back(request_type);
+ }
+ }
+ if (valid_request_types.empty() && !request_types.empty()) {
+ // An empty RequestType array will allow all request types. No valid
+ // parameters are in the filtered array, so assign an uninitialized value to
+ // for array to be "omitted"
+ *(app_params.RequestType) = policy_table::RequestTypes();
+ } else {
+ app_params.RequestType->swap(valid_request_types);
+ }
+
+ // Filter moduleType array
+ policy_table::ModuleTypes valid_module_types;
+ const policy_table::ModuleTypes& module_types = *(app_params.moduleType);
+ for (const auto& module_type : module_types) {
+ if (module_type.is_valid()) {
+ valid_module_types.push_back(module_type);
+ }
+ }
+ if (valid_module_types.empty() && !module_types.empty()) {
+ // An empty moduleType array will allow all request types. No valid
+ // parameters are in the filtered array, so assign an uninitialized value to
+ // for array to be "omitted"
+ *(app_params.moduleType) = policy_table::ModuleTypes();
+ } else {
+ app_params.moduleType->swap(valid_module_types);
+ }
+
+ // Filter priority
+ if (!app_params.priority.is_valid()) {
+ app_params.priority = policy_table::Priority();
+ }
+}
+
+/**
+ * @brief FilterPolicyTable filter values that not present in schema
+ * @param pt policy table to filter
+ */
+void FilterPolicyTable(policy_table::PolicyTable& pt) {
+ policy_table::ModuleConfig& module_config = pt.module_config;
+ if (module_config.is_initialized() &&
+ module_config.notifications_per_minute_by_priority.is_initialized()) {
+ FilterInvalidPriorityValues(
+ module_config.notifications_per_minute_by_priority);
+ }
+
+ if (pt.app_policies_section.is_initialized()) {
+ policy_table::ApplicationPolicies& apps = pt.app_policies_section.apps;
+ for (auto& app_policy : apps) {
+ FilterInvalidApplicationParameters(app_policy.second);
+ }
+ }
+
+ for (auto& group : pt.functional_groupings) {
+ policy_table::Rpc& rpcs = group.second.rpcs;
+ FilterInvalidFunctions(rpcs);
+
+ for (auto& func : rpcs) {
+ FilterInvalidRPCParameters(func.second);
+ }
+ }
+}
+
bool PolicyManagerImpl::LoadPT(const std::string& file,
const BinaryMessage& pt_content) {
LOG4CXX_INFO(logger_, "LoadPT of size " << pt_content.size());
@@ -160,11 +297,11 @@ bool PolicyManagerImpl::LoadPT(const std::string& file,
// Assuemes Policy Table was parsed, formatted, and/or decrypted by
// the HMI after system request before calling OnReceivedPolicyUpdate
// Parse message into table struct
- utils::SharedPtr<policy_table::Table> pt_update = Parse(pt_content);
+ std::shared_ptr<policy_table::Table> pt_update = Parse(pt_content);
#else
// Message Received from server unecnrypted with PTU in first element
// of 'data' array. No Parsing was done by HMI.
- utils::SharedPtr<policy_table::Table> pt_update = ParseArray(pt_content);
+ std::shared_ptr<policy_table::Table> pt_update = ParseArray(pt_content);
#endif
if (!pt_update) {
LOG4CXX_WARN(logger_, "Parsed table pointer is 0.");
@@ -174,6 +311,7 @@ bool PolicyManagerImpl::LoadPT(const std::string& file,
file_system::DeleteFile(file);
+ FilterPolicyTable(pt_update->policy_table);
if (!IsPTValid(pt_update, policy_table::PT_UPDATE)) {
wrong_ptu_update_received_ = true;
update_status_manager_.OnWrongUpdateReceived();
@@ -193,7 +331,7 @@ bool PolicyManagerImpl::LoadPT(const std::string& file,
sync_primitives::AutoLock lock(apps_registration_lock_);
// Get current DB data, since it could be updated during awaiting of PTU
- utils::SharedPtr<policy_table::Table> policy_table_snapshot =
+ std::shared_ptr<policy_table::Table> policy_table_snapshot =
cache_->GenerateSnapshot();
if (!policy_table_snapshot) {
LOG4CXX_ERROR(
@@ -219,10 +357,8 @@ bool PolicyManagerImpl::LoadPT(const std::string& file,
return false;
}
- if (pt_update->policy_table.module_config.certificate.is_initialized()) {
- listener_->OnCertificateUpdated(
- *(pt_update->policy_table.module_config.certificate));
- }
+ listener_->OnCertificateUpdated(
+ *(pt_update->policy_table.module_config.certificate));
std::map<std::string, StringArray> app_hmi_types;
cache_->GetHMIAppTypeAfterUpdate(app_hmi_types);
@@ -246,8 +382,8 @@ bool PolicyManagerImpl::LoadPT(const std::string& file,
}
void PolicyManagerImpl::CheckPermissionsChanges(
- const utils::SharedPtr<policy_table::Table> pt_update,
- const utils::SharedPtr<policy_table::Table> snapshot) {
+ const std::shared_ptr<policy_table::Table> pt_update,
+ const std::shared_ptr<policy_table::Table> snapshot) {
LOG4CXX_INFO(logger_, "Checking incoming permissions.");
// Replace predefined policies with its actual setting, e.g. "123":"default"
@@ -282,7 +418,7 @@ void PolicyManagerImpl::GetUpdateUrls(const uint32_t service_type,
bool PolicyManagerImpl::RequestPTUpdate() {
LOG4CXX_AUTO_TRACE(logger_);
- utils::SharedPtr<policy_table::Table> policy_table_snapshot =
+ std::shared_ptr<policy_table::Table> policy_table_snapshot =
cache_->GenerateSnapshot();
if (!policy_table_snapshot) {
LOG4CXX_ERROR(logger_, "Failed to create snapshot of policy table");
@@ -385,6 +521,25 @@ const std::vector<std::string> PolicyManagerImpl::GetAppRequestTypes(
return request_types;
}
+RequestType::State PolicyManagerImpl::GetAppRequestTypesState(
+ const std::string& policy_app_id) const {
+ LOG4CXX_AUTO_TRACE(logger_);
+ return cache_->GetAppRequestTypesState(policy_app_id);
+}
+
+RequestSubType::State PolicyManagerImpl::GetAppRequestSubTypesState(
+ const std::string& policy_app_id) const {
+ LOG4CXX_AUTO_TRACE(logger_);
+ return cache_->GetAppRequestSubTypesState(policy_app_id);
+}
+
+const std::vector<std::string> PolicyManagerImpl::GetAppRequestSubTypes(
+ const std::string& policy_app_id) const {
+ std::vector<std::string> request_subtypes;
+ cache_->GetAppRequestSubTypes(policy_app_id, request_subtypes);
+ return request_subtypes;
+}
+
const VehicleInfo PolicyManagerImpl::GetVehicleInfo() const {
return cache_->GetVehicleInfo();
}
@@ -406,12 +561,16 @@ void PolicyManagerImpl::CheckPermissions(const PTString& device_id,
"CheckPermissions for " << app_id << " and rpc " << rpc
<< " for " << hmi_level << " level.");
-#ifdef SDL_REMOTE_CONTROL
ApplicationOnDevice who = {device_id, app_id};
- const policy_table::Strings& groups = access_remote_->GetGroups(who);
-#else // SDL_REMOTE_CONTROL
- const policy_table::Strings& groups = cache_->GetGroups(app_id);
-#endif // SDL_REMOTE_CONTROL
+ policy_table::Strings groups;
+ if (access_remote_->IsAppRemoteControl(who)) {
+ groups = access_remote_->GetGroups(who);
+ LOG4CXX_INFO(logger_,
+ "CheckPermissions for " << app_id << " and rpc " << rpc
+ << " for " << hmi_level << " level.");
+ } else {
+ groups = cache_->GetGroups(app_id);
+ }
cache_->CheckPermissions(groups, hmi_level, rpc, result);
if (cache_->IsApplicationRevoked(app_id)) {
@@ -467,13 +626,11 @@ void PolicyManagerImpl::SendNotificationOnPermissionsUpdated(
std::string default_hmi;
default_hmi = "NONE";
-#ifdef SDL_REMOTE_CONTROL
const ApplicationOnDevice who = {device_id, application_id};
if (access_remote_->IsAppRemoteControl(who)) {
listener()->OnPermissionsUpdated(application_id, notification_data);
return;
}
-#endif // SDL_REMOTE_CONTROL
listener()->OnPermissionsUpdated(
application_id, notification_data, default_hmi);
@@ -711,14 +868,15 @@ void PolicyManagerImpl::GetPermissionsForApp(
}
FunctionalIdType group_types;
-#ifdef SDL_REMOTE_CONTROL
- allowed_by_default = false;
- bool ret = access_remote_->GetPermissionsForApp(
- device_id, policy_app_id, group_types);
-#else
- bool ret =
- cache_->GetPermissionsForApp(device_id, app_id_to_check, group_types);
-#endif // REMOTE_CONTROL
+ const ApplicationOnDevice who = {device_id, app_id_to_check};
+ bool ret = false;
+ if (access_remote_->IsAppRemoteControl(who)) {
+ allowed_by_default = false;
+ ret = access_remote_->GetPermissionsForApp(
+ device_id, policy_app_id, group_types);
+ } else {
+ ret = cache_->GetPermissionsForApp(device_id, app_id_to_check, group_types);
+ }
if (!ret) {
LOG4CXX_WARN(logger_,
@@ -792,7 +950,7 @@ bool PolicyManagerImpl::ExceededIgnitionCycles() {
}
bool PolicyManagerImpl::IsPTValid(
- utils::SharedPtr<policy_table::Table> policy_table,
+ std::shared_ptr<policy_table::Table> policy_table,
policy_table::PolicyTableType type) const {
policy_table->SetPolicyTableType(type);
if (!policy_table->is_valid()) {
@@ -813,9 +971,9 @@ const PolicySettings& PolicyManagerImpl::get_settings() const {
bool PolicyManagerImpl::ExceededDays() {
LOG4CXX_AUTO_TRACE(logger_);
- TimevalStruct current_time = date_time::DateTime::getCurrentTime();
+ date_time::TimeDuration current_time = date_time::getCurrentTime();
const int kSecondsInDay = 60 * 60 * 24;
- const int days = current_time.tv_sec / kSecondsInDay;
+ const int days = date_time::getSecs(current_time) / kSecondsInDay;
return 0 == cache_->DaysBeforeExchange(days);
}
@@ -865,8 +1023,7 @@ uint32_t PolicyManagerImpl::NextRetryTimeout() {
}
for (uint32_t i = 0u; i < retry_sequence_index_; ++i) {
- next += retry_sequence_seconds_[i] *
- date_time::DateTime::MILLISECONDS_IN_SECOND;
+ next += retry_sequence_seconds_[i] * date_time::MILLISECONDS_IN_SECOND;
next += retry_sequence_timeout_;
}
++retry_sequence_index_;
@@ -1052,19 +1209,12 @@ StatusNotifier PolicyManagerImpl::AddApplication(
sync_primitives::AutoLock lock(apps_registration_lock_);
if (IsNewApplication(application_id)) {
AddNewApplication(application_id, device_consent);
- return utils::MakeShared<CallStatusChange>(update_status_manager_,
- device_consent);
- } else {
- PromoteExistedApplication(application_id, device_consent);
- const policy_table::AppHMIType type = policy_table::AHT_NAVIGATION;
- if (helpers::in_range(hmi_types,
- (rpc::Enum<policy_table::AppHMIType>)type) &&
- !HasCertificate()) {
- LOG4CXX_DEBUG(logger_, "Certificate does not exist, scheduling update.");
- update_status_manager_.ScheduleUpdate();
- }
- return utils::MakeShared<utils::CallNothing>();
+ return std::make_shared<CallStatusChange>(update_status_manager_,
+ device_consent);
}
+ PromoteExistedApplication(application_id, device_consent);
+ update_status_manager_.OnExistedApplicationAdded(cache_->UpdateRequired());
+ return std::make_shared<utils::CallNothing>();
}
void PolicyManagerImpl::RemoveAppConsentForGroup(
@@ -1087,6 +1237,7 @@ void PolicyManagerImpl::AddNewApplication(const std::string& application_id,
void PolicyManagerImpl::PromoteExistedApplication(
const std::string& application_id, DeviceConsent device_consent) {
+ LOG4CXX_AUTO_TRACE(logger_);
// If device consent changed to allowed during application being
// disconnected, app permissions should be changed also
if (kDeviceAllowed == device_consent &&
@@ -1139,7 +1290,10 @@ bool PolicyManagerImpl::InitPT(const std::string& file_name,
const bool ret = cache_->Init(file_name, settings);
if (ret) {
RefreshRetrySequence();
- update_status_manager_.OnPolicyInit(cache_->UpdateRequired());
+ const std::string certificate_data = cache_->GetCertificate();
+ if (!certificate_data.empty()) {
+ listener_->OnCertificateUpdated(certificate_data);
+ }
}
return ret;
}
@@ -1154,7 +1308,7 @@ void PolicyManagerImpl::SaveUpdateStatusRequired(bool is_update_needed) {
void PolicyManagerImpl::set_cache_manager(
CacheManagerInterface* cache_manager) {
- cache_ = cache_manager;
+ cache_ = std::shared_ptr<CacheManagerInterface>(cache_manager);
}
void PolicyManagerImpl::RetrySequence() {
@@ -1174,7 +1328,6 @@ void PolicyManagerImpl::RetrySequence() {
timer_retry_sequence_.Start(timeout_msec, timer::kPeriodic);
}
-#ifdef SDL_REMOTE_CONTROL
void PolicyManagerImpl::SetDefaultHmiTypes(const std::string& application_id,
const std::vector<int>& hmi_types) {
LOG4CXX_INFO(logger_, "SetDefaultHmiTypes");
@@ -1277,9 +1430,8 @@ bool PolicyManagerImpl::GetModuleTypes(
}
void PolicyManagerImpl::set_access_remote(
- utils::SharedPtr<AccessRemote> access_remote) {
+ std::shared_ptr<AccessRemote> access_remote) {
access_remote_ = access_remote;
}
-#endif // SDL_REMOTE_CONTROL
} // namespace policy
diff --git a/src/components/policy/policy_regular/src/policy_table.cc b/src/components/policy/policy_regular/src/policy_table.cc
index c5c6e3e132..b0fa5739da 100644
--- a/src/components/policy/policy_regular/src/policy_table.cc
+++ b/src/components/policy/policy_regular/src/policy_table.cc
@@ -42,7 +42,7 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "Policy")
PolicyTable::PolicyTable() : pt_data_(new SQLPTRepresentation()) {}
-PolicyTable::PolicyTable(utils::SharedPtr<PTRepresentation> pt_data)
+PolicyTable::PolicyTable(std::shared_ptr<PTRepresentation> pt_data)
: pt_data_(pt_data) {}
PolicyTable::~PolicyTable() {
diff --git a/src/components/policy/policy_regular/src/policy_table/enums.cc b/src/components/policy/policy_regular/src/policy_table/enums.cc
index 34d12420d8..428e18d0bd 100644
--- a/src/components/policy/policy_regular/src/policy_table/enums.cc
+++ b/src/components/policy/policy_regular/src/policy_table/enums.cc
@@ -15,6 +15,8 @@ bool IsValidEnum(Priority val) {
return true;
case P_NORMAL:
return true;
+ case P_PROJECTION:
+ return true;
case P_NONE:
return true;
default:
@@ -33,6 +35,8 @@ const char* EnumToJsonString(Priority val) {
return "COMMUNICATION";
case P_NORMAL:
return "NORMAL";
+ case P_PROJECTION:
+ return "PROJECTION";
case P_NONE:
return "NONE";
default:
@@ -55,6 +59,9 @@ bool EnumFromJsonString(const std::string& literal, Priority* result) {
} else if ("NORMAL" == literal) {
*result = P_NORMAL;
return true;
+ } else if ("PROJECTION" == literal) {
+ *result = P_PROJECTION;
+ return true;
} else if ("NONE" == literal) {
*result = P_NONE;
return true;
@@ -119,6 +126,8 @@ bool IsValidEnum(Parameter val) {
return true;
case P_EXTERNALTEMPERATURE:
return true;
+ case P_TURNSIGNAL:
+ return true;
case P_FUELLEVEL:
return true;
case P_FUELLEVEL_STATE:
@@ -127,6 +136,8 @@ bool IsValidEnum(Parameter val) {
return true;
case P_INSTANTFUELCONSUMPTION:
return true;
+ case P_FUELRANGE:
+ return true;
case P_ODOMETER:
return true;
case P_TIREPRESSURE:
@@ -139,6 +150,8 @@ bool IsValidEnum(Parameter val) {
return true;
case P_BELTSTATUS:
return true;
+ case P_ELECTRONICPARKBRAKESTATUS:
+ return true;
case P_DRIVERBRAKING:
return true;
case P_PRNDL:
@@ -147,6 +160,8 @@ bool IsValidEnum(Parameter val) {
return true;
case P_STEERINGWHEELANGLE:
return true;
+ case P_ENGINEOILLIFE:
+ return true;
case P_MYKEY:
return true;
case P_AIRBAGSTATUS:
@@ -177,6 +192,8 @@ const char* EnumToJsonString(Parameter val) {
return "engineTorque";
case P_EXTERNALTEMPERATURE:
return "externalTemperature";
+ case P_TURNSIGNAL:
+ return "turnSignal";
case P_FUELLEVEL:
return "fuelLevel";
case P_FUELLEVEL_STATE:
@@ -185,6 +202,8 @@ const char* EnumToJsonString(Parameter val) {
return "headLampStatus";
case P_INSTANTFUELCONSUMPTION:
return "instantFuelConsumption";
+ case P_FUELRANGE:
+ return "fuelRange";
case P_ODOMETER:
return "odometer";
case P_TIREPRESSURE:
@@ -197,6 +216,8 @@ const char* EnumToJsonString(Parameter val) {
return "accPedalPosition";
case P_BELTSTATUS:
return "beltStatus";
+ case P_ELECTRONICPARKBRAKESTATUS:
+ return "electronicParkBrakeStatus";
case P_DRIVERBRAKING:
return "driverBraking";
case P_PRNDL:
@@ -205,6 +226,8 @@ const char* EnumToJsonString(Parameter val) {
return "rpm";
case P_STEERINGWHEELANGLE:
return "steeringWheelAngle";
+ case P_ENGINEOILLIFE:
+ return "engineOilLife";
case P_MYKEY:
return "myKey";
case P_AIRBAGSTATUS:
@@ -239,6 +262,9 @@ bool EnumFromJsonString(const std::string& literal, Parameter* result) {
} else if ("externalTemperature" == literal) {
*result = P_EXTERNALTEMPERATURE;
return true;
+ } else if ("turnSignal" == literal) {
+ *result = P_TURNSIGNAL;
+ return true;
} else if ("fuelLevel" == literal) {
*result = P_FUELLEVEL;
return true;
@@ -251,6 +277,9 @@ bool EnumFromJsonString(const std::string& literal, Parameter* result) {
} else if ("instantFuelConsumption" == literal) {
*result = P_INSTANTFUELCONSUMPTION;
return true;
+ } else if ("fuelRange" == literal) {
+ *result = P_FUELRANGE;
+ return true;
} else if ("odometer" == literal) {
*result = P_ODOMETER;
return true;
@@ -269,6 +298,9 @@ bool EnumFromJsonString(const std::string& literal, Parameter* result) {
} else if ("beltStatus" == literal) {
*result = P_BELTSTATUS;
return true;
+ } else if ("electronicParkBrakeStatus" == literal) {
+ *result = P_ELECTRONICPARKBRAKESTATUS;
+ return true;
} else if ("driverBraking" == literal) {
*result = P_DRIVERBRAKING;
return true;
@@ -281,6 +313,9 @@ bool EnumFromJsonString(const std::string& literal, Parameter* result) {
} else if ("steeringWheelAngle" == literal) {
*result = P_STEERINGWHEELANGLE;
return true;
+ } else if ("engineOilLife" == literal) {
+ *result = P_ENGINEOILLIFE;
+ return true;
} else if ("myKey" == literal) {
*result = P_MYKEY;
return true;
@@ -454,6 +489,10 @@ bool IsValidEnum(RequestType val) {
return true;
case RT_FOTA:
return true;
+ case RT_OEM_SPECIFIC:
+ return true;
+ case RT_EMPTY:
+ return true;
default:
return false;
}
@@ -501,6 +540,10 @@ const char* EnumToJsonString(RequestType val) {
return "MEDIA";
case RT_FOTA:
return "FOTA";
+ case RT_OEM_SPECIFIC:
+ return "OEM_SPECIFIC";
+ case RT_EMPTY:
+ return "EMPTY";
default:
return "";
}
@@ -586,18 +629,35 @@ bool EnumFromJsonString(const std::string& literal, RequestType* result) {
if ("FOTA" == literal) {
*result = RT_FOTA;
return true;
+ }
+ if ("OEM_SPECIFIC" == literal) {
+ *result = RT_OEM_SPECIFIC;
+ return true;
+ }
+ if ("EMPTY" == literal) {
+ *result = RT_EMPTY;
+ return true;
} else {
return false;
}
}
-#ifdef SDL_REMOTE_CONTROL
bool IsValidEnum(ModuleType val) {
switch (val) {
case MT_CLIMATE:
return true;
case MT_RADIO:
return true;
+ case MT_SEAT:
+ return true;
+ case MT_AUDIO:
+ return true;
+ case MT_LIGHT:
+ return true;
+ case MT_HMI_SETTINGS:
+ return true;
+ case MT_EMPTY:
+ return true;
default:
return false;
}
@@ -608,6 +668,16 @@ const char* EnumToJsonString(ModuleType val) {
return "CLIMATE";
case MT_RADIO:
return "RADIO";
+ case MT_SEAT:
+ return "SEAT";
+ case MT_AUDIO:
+ return "AUDIO";
+ case MT_LIGHT:
+ return "LIGHT";
+ case MT_HMI_SETTINGS:
+ return "HMI_SETTINGS";
+ case MT_EMPTY:
+ return "EMPTY";
default:
return "";
}
@@ -620,11 +690,671 @@ bool EnumFromJsonString(const std::string& literal, ModuleType* result) {
} else if ("RADIO" == literal) {
*result = MT_RADIO;
return true;
- } else {
- return false;
+ } else if ("SEAT" == literal) {
+ *result = MT_SEAT;
+ return true;
+ } else if ("AUDIO" == literal) {
+ *result = MT_AUDIO;
+ return true;
+ } else if ("LIGHT" == literal) {
+ *result = MT_LIGHT;
+ return true;
+ } else if ("HMI_SETTINGS" == literal) {
+ *result = MT_HMI_SETTINGS;
+ return true;
+ } else if ("EMPTY" == literal) {
+ *result = MT_EMPTY;
+ return true;
}
+ return false;
}
-#endif // SDL_REMOTE_CONTROL
+
+bool IsValidEnum(FunctionID val) {
+ switch (val) {
+ case RegisterAppInterfaceID:
+ return true;
+ case UnregisterAppInterfaceID:
+ return true;
+ case SetGlobalPropertiesID:
+ return true;
+ case ResetGlobalPropertiesID:
+ return true;
+ case AddCommandID:
+ return true;
+ case DeleteCommandID:
+ return true;
+ case AddSubMenuID:
+ return true;
+ case DeleteSubMenuID:
+ return true;
+ case CreateInteractionChoiceSetID:
+ return true;
+ case PerformInteractionID:
+ return true;
+ case DeleteInteractionChoiceSetID:
+ return true;
+ case AlertID:
+ return true;
+ case ShowID:
+ return true;
+ case SpeakID:
+ return true;
+ case SetMediaClockTimerID:
+ return true;
+ case PerformAudioPassThruID:
+ return true;
+ case EndAudioPassThruID:
+ return true;
+ case SubscribeButtonID:
+ return true;
+ case UnsubscribeButtonID:
+ return true;
+ case SubscribeVehicleDataID:
+ return true;
+ case UnsubscribeVehicleDataID:
+ return true;
+ case GetVehicleDataID:
+ return true;
+ case ReadDIDID:
+ return true;
+ case GetDTCsID:
+ return true;
+ case ScrollableMessageID:
+ return true;
+ case SliderID:
+ return true;
+ case ShowConstantTBTID:
+ return true;
+ case AlertManeuverID:
+ return true;
+ case UpdateTurnListID:
+ return true;
+ case ChangeRegistrationID:
+ return true;
+ case GenericResponseID:
+ return true;
+ case PutFileID:
+ return true;
+ case DeleteFileID:
+ return true;
+ case ListFilesID:
+ return true;
+ case SetAppIconID:
+ return true;
+ case SetDisplayLayoutID:
+ return true;
+ case DiagnosticMessageID:
+ return true;
+ case SystemRequestID:
+ return true;
+ case SendLocationID:
+ return true;
+ case DialNumberID:
+ return true;
+ case ButtonPressID:
+ return true;
+ case GetInteriorVehicleDataID:
+ return true;
+ case SetInteriorVehicleDataID:
+ return true;
+ case GetWayPointsID:
+ return true;
+ case SubscribeWayPointsID:
+ return true;
+ case UnsubscribeWayPointsID:
+ return true;
+ case GetSystemCapabilityID:
+ return true;
+ case SendHapticDataID:
+ return true;
+ case OnHMIStatusID:
+ return true;
+ case OnAppInterfaceUnregisteredID:
+ return true;
+ case OnButtonEventID:
+ return true;
+ case OnButtonPressID:
+ return true;
+ case OnVehicleDataID:
+ return true;
+ case OnCommandID:
+ return true;
+ case OnTBTClientStateID:
+ return true;
+ case OnDriverDistractionID:
+ return true;
+ case OnPermissionsChangeID:
+ return true;
+ case OnAudioPassThruID:
+ return true;
+ case OnLanguageChangeID:
+ return true;
+ case OnKeyboardInputID:
+ return true;
+ case OnTouchEventID:
+ return true;
+ case OnSystemRequestID:
+ return true;
+ case OnHashChangeID:
+ return true;
+ case OnInteriorVehicleDataID:
+ return true;
+ case OnWayPointChangeID:
+ return true;
+ case OnRCStatusID:
+ return true;
+ case EncodedSyncPDataID:
+ return true;
+ case SyncPDataID:
+ return true;
+ case OnEncodedSyncPDataID:
+ return true;
+ case OnSyncPDataID:
+ return true;
+ default:
+ return false;
+ }
+};
+
+const char* EnumToJsonString(FunctionID val) {
+ switch (val) {
+ case RegisterAppInterfaceID:
+ return "RegisterAppInterface";
+ case UnregisterAppInterfaceID:
+ return "UnregisterAppInterface";
+ case SetGlobalPropertiesID:
+ return "SetGlobalProperties";
+ case ResetGlobalPropertiesID:
+ return "ResetGlobalProperties";
+ case AddCommandID:
+ return "AddCommand";
+ case DeleteCommandID:
+ return "DeleteCommand";
+ case AddSubMenuID:
+ return "AddSubMenu";
+ case DeleteSubMenuID:
+ return "DeleteSubMenu";
+ case CreateInteractionChoiceSetID:
+ return "CreateInteractionChoiceSet";
+ case PerformInteractionID:
+ return "PerformInteraction";
+ case DeleteInteractionChoiceSetID:
+ return "DeleteInteractionChoiceSet";
+ case AlertID:
+ return "Alert";
+ case ShowID:
+ return "Show";
+ case SpeakID:
+ return "Speak";
+ case SetMediaClockTimerID:
+ return "SetMediaClockTimer";
+ case PerformAudioPassThruID:
+ return "PerformAudioPassThru";
+ case EndAudioPassThruID:
+ return "EndAudioPassThru";
+ case SubscribeButtonID:
+ return "SubscribeButton";
+ case UnsubscribeButtonID:
+ return "UnsubscribeButton";
+ case SubscribeVehicleDataID:
+ return "SubscribeVehicleData";
+ case UnsubscribeVehicleDataID:
+ return "UnsubscribeVehicleData";
+ case GetVehicleDataID:
+ return "GetVehicleData";
+ case ReadDIDID:
+ return "ReadDID";
+ case GetDTCsID:
+ return "GetDTCs";
+ case ScrollableMessageID:
+ return "ScrollableMessage";
+ case SliderID:
+ return "Slider";
+ case ShowConstantTBTID:
+ return "ShowConstantTBT";
+ case AlertManeuverID:
+ return "AlertManeuver";
+ case UpdateTurnListID:
+ return "UpdateTurnList";
+ case ChangeRegistrationID:
+ return "ChangeRegistration";
+ case GenericResponseID:
+ return "GenericResponse";
+ case PutFileID:
+ return "PutFile";
+ case DeleteFileID:
+ return "DeleteFile";
+ case ListFilesID:
+ return "ListFiles";
+ case SetAppIconID:
+ return "SetAppIcon";
+ case SetDisplayLayoutID:
+ return "SetDisplayLayout";
+ case DiagnosticMessageID:
+ return "DiagnosticMessage";
+ case SystemRequestID:
+ return "SystemRequest";
+ case SendLocationID:
+ return "SendLocation";
+ case DialNumberID:
+ return "DialNumber";
+ case ButtonPressID:
+ return "ButtonPress";
+ case GetInteriorVehicleDataID:
+ return "GetInteriorVehicleData";
+ case SetInteriorVehicleDataID:
+ return "SetInteriorVehicleData";
+ case GetWayPointsID:
+ return "GetWayPoints";
+ case SubscribeWayPointsID:
+ return "SubscribeWayPoints";
+ case UnsubscribeWayPointsID:
+ return "UnsubscribeWayPoints";
+ case GetSystemCapabilityID:
+ return "GetSystemCapability";
+ case SendHapticDataID:
+ return "SendHapticData";
+ case OnHMIStatusID:
+ return "OnHMIStatus";
+ case OnAppInterfaceUnregisteredID:
+ return "OnAppInterfaceUnregistered";
+ case OnButtonEventID:
+ return "OnButtonEvent";
+ case OnButtonPressID:
+ return "OnButtonPress";
+ case OnVehicleDataID:
+ return "OnVehicleData";
+ case OnCommandID:
+ return "OnCommand";
+ case OnTBTClientStateID:
+ return "OnTBTClientState";
+ case OnDriverDistractionID:
+ return "OnDriverDistraction";
+ case OnPermissionsChangeID:
+ return "OnPermissionsChange";
+ case OnAudioPassThruID:
+ return "OnAudioPassThru";
+ case OnLanguageChangeID:
+ return "OnLanguageChange";
+ case OnKeyboardInputID:
+ return "OnKeyboardInput";
+ case OnTouchEventID:
+ return "OnTouchEvent";
+ case OnSystemRequestID:
+ return "OnSystemRequest";
+ case OnHashChangeID:
+ return "OnHashChange";
+ case OnInteriorVehicleDataID:
+ return "OnInteriorVehicleData";
+ case OnWayPointChangeID:
+ return "OnWayPointChange";
+ case OnRCStatusID:
+ return "OnRCStatus";
+ case EncodedSyncPDataID:
+ return "EncodedSyncPData";
+ case SyncPDataID:
+ return "SyncPData";
+ case OnEncodedSyncPDataID:
+ return "OnEncodedSyncPData";
+ case OnSyncPDataID:
+ return "OnSyncPData";
+ default:
+ return "";
+ }
+};
+
+bool EnumFromJsonString(const std::string& literal, FunctionID* result) {
+ if ("RegisterAppInterface" == literal) {
+ *result = RegisterAppInterfaceID;
+ return true;
+ }
+
+ if ("UnregisterAppInterface" == literal) {
+ *result = UnregisterAppInterfaceID;
+ return true;
+ }
+
+ if ("SetGlobalProperties" == literal) {
+ *result = SetGlobalPropertiesID;
+ return true;
+ }
+
+ if ("ResetGlobalProperties" == literal) {
+ *result = ResetGlobalPropertiesID;
+ return true;
+ }
+
+ if ("AddCommand" == literal) {
+ *result = AddCommandID;
+ return true;
+ }
+
+ if ("DeleteCommand" == literal) {
+ *result = DeleteCommandID;
+ return true;
+ }
+
+ if ("AddSubMenu" == literal) {
+ *result = AddSubMenuID;
+ return true;
+ }
+
+ if ("DeleteSubMenu" == literal) {
+ *result = DeleteSubMenuID;
+ return true;
+ }
+
+ if ("CreateInteractionChoiceSet" == literal) {
+ *result = CreateInteractionChoiceSetID;
+ return true;
+ }
+
+ if ("PerformInteraction" == literal) {
+ *result = PerformInteractionID;
+ return true;
+ }
+
+ if ("DeleteInteractionChoiceSet" == literal) {
+ *result = DeleteInteractionChoiceSetID;
+ return true;
+ }
+
+ if ("Alert" == literal) {
+ *result = AlertID;
+ return true;
+ }
+
+ if ("Show" == literal) {
+ *result = ShowID;
+ return true;
+ }
+
+ if ("Speak" == literal) {
+ *result = SpeakID;
+ return true;
+ }
+
+ if ("SetMediaClockTimer" == literal) {
+ *result = SetMediaClockTimerID;
+ return true;
+ }
+
+ if ("PerformAudioPassThru" == literal) {
+ *result = PerformAudioPassThruID;
+ return true;
+ }
+
+ if ("EndAudioPassThru" == literal) {
+ *result = EndAudioPassThruID;
+ return true;
+ }
+
+ if ("SubscribeButton" == literal) {
+ *result = SubscribeButtonID;
+ return true;
+ }
+
+ if ("UnsubscribeButton" == literal) {
+ *result = UnsubscribeButtonID;
+ return true;
+ }
+
+ if ("SubscribeVehicleData" == literal) {
+ *result = SubscribeVehicleDataID;
+ return true;
+ }
+
+ if ("UnsubscribeVehicleData" == literal) {
+ *result = UnsubscribeVehicleDataID;
+ return true;
+ }
+
+ if ("GetVehicleData" == literal) {
+ *result = GetVehicleDataID;
+ return true;
+ }
+
+ if ("ReadDID" == literal) {
+ *result = ReadDIDID;
+ return true;
+ }
+
+ if ("GetDTCs" == literal) {
+ *result = GetDTCsID;
+ return true;
+ }
+
+ if ("ScrollableMessage" == literal) {
+ *result = ScrollableMessageID;
+ return true;
+ }
+
+ if ("Slider" == literal) {
+ *result = SliderID;
+ return true;
+ }
+
+ if ("ShowConstantTBT" == literal) {
+ *result = ShowConstantTBTID;
+ return true;
+ }
+
+ if ("AlertManeuver" == literal) {
+ *result = AlertManeuverID;
+ return true;
+ }
+
+ if ("UpdateTurnList" == literal) {
+ *result = UpdateTurnListID;
+ return true;
+ }
+
+ if ("ChangeRegistration" == literal) {
+ *result = ChangeRegistrationID;
+ return true;
+ }
+
+ if ("GenericResponse" == literal) {
+ *result = GenericResponseID;
+ return true;
+ }
+
+ if ("PutFile" == literal) {
+ *result = PutFileID;
+ return true;
+ }
+
+ if ("DeleteFile" == literal) {
+ *result = DeleteFileID;
+ return true;
+ }
+
+ if ("ListFiles" == literal) {
+ *result = ListFilesID;
+ return true;
+ }
+
+ if ("SetAppIcon" == literal) {
+ *result = SetAppIconID;
+ return true;
+ }
+
+ if ("SetDisplayLayout" == literal) {
+ *result = SetDisplayLayoutID;
+ return true;
+ }
+
+ if ("DiagnosticMessage" == literal) {
+ *result = DiagnosticMessageID;
+ return true;
+ }
+
+ if ("SystemRequest" == literal) {
+ *result = SystemRequestID;
+ return true;
+ }
+
+ if ("SendLocation" == literal) {
+ *result = SendLocationID;
+ return true;
+ }
+
+ if ("DialNumber" == literal) {
+ *result = DialNumberID;
+ return true;
+ }
+
+ if ("ButtonPress" == literal) {
+ *result = ButtonPressID;
+ return true;
+ }
+
+ if ("GetInteriorVehicleData" == literal) {
+ *result = GetInteriorVehicleDataID;
+ return true;
+ }
+
+ if ("SetInteriorVehicleData" == literal) {
+ *result = SetInteriorVehicleDataID;
+ return true;
+ }
+
+ if ("GetWayPoints" == literal) {
+ *result = GetWayPointsID;
+ return true;
+ }
+
+ if ("SubscribeWayPoints" == literal) {
+ *result = SubscribeWayPointsID;
+ return true;
+ }
+
+ if ("UnsubscribeWayPoints" == literal) {
+ *result = UnsubscribeWayPointsID;
+ return true;
+ }
+
+ if ("GetSystemCapability" == literal) {
+ *result = GetSystemCapabilityID;
+ return true;
+ }
+
+ if ("SendHapticData" == literal) {
+ *result = SendHapticDataID;
+ return true;
+ }
+
+ if ("OnHMIStatus" == literal) {
+ *result = OnHMIStatusID;
+ return true;
+ }
+
+ if ("OnAppInterfaceUnregistered" == literal) {
+ *result = OnAppInterfaceUnregisteredID;
+ return true;
+ }
+
+ if ("OnButtonEvent" == literal) {
+ *result = OnButtonEventID;
+ return true;
+ }
+
+ if ("OnButtonPress" == literal) {
+ *result = OnButtonPressID;
+ return true;
+ }
+
+ if ("OnVehicleData" == literal) {
+ *result = OnVehicleDataID;
+ return true;
+ }
+
+ if ("OnCommand" == literal) {
+ *result = OnCommandID;
+ return true;
+ }
+
+ if ("OnTBTClientState" == literal) {
+ *result = OnTBTClientStateID;
+ return true;
+ }
+
+ if ("OnDriverDistraction" == literal) {
+ *result = OnDriverDistractionID;
+ return true;
+ }
+
+ if ("OnPermissionsChange" == literal) {
+ *result = OnPermissionsChangeID;
+ return true;
+ }
+
+ if ("OnAudioPassThru" == literal) {
+ *result = OnAudioPassThruID;
+ return true;
+ }
+
+ if ("OnLanguageChange" == literal) {
+ *result = OnLanguageChangeID;
+ return true;
+ }
+
+ if ("OnKeyboardInput" == literal) {
+ *result = OnKeyboardInputID;
+ return true;
+ }
+
+ if ("OnTouchEvent" == literal) {
+ *result = OnTouchEventID;
+ return true;
+ }
+
+ if ("OnSystemRequest" == literal) {
+ *result = OnSystemRequestID;
+ return true;
+ }
+
+ if ("OnHashChange" == literal) {
+ *result = OnHashChangeID;
+ return true;
+ }
+
+ if ("OnInteriorVehicleData" == literal) {
+ *result = OnInteriorVehicleDataID;
+ return true;
+ }
+
+ if ("OnWayPointChange" == literal) {
+ *result = OnWayPointChangeID;
+ return true;
+ }
+
+ if ("OnRCStatus" == literal) {
+ *result = OnRCStatusID;
+ return true;
+ }
+
+ if ("EncodedSyncPData" == literal) {
+ *result = EncodedSyncPDataID;
+ return true;
+ }
+
+ if ("SyncPData" == literal) {
+ *result = SyncPDataID;
+ return true;
+ }
+
+ if ("OnEncodedSyncPData" == literal) {
+ *result = OnEncodedSyncPDataID;
+ return true;
+ }
+
+ if ("OnSyncPData" == literal) {
+ *result = OnSyncPDataID;
+ return true;
+ }
+ return false;
+};
const std::string kDefaultApp = "default";
const std::string kPreDataConsentApp = "pre_DataConsent";
diff --git a/src/components/policy/policy_regular/src/policy_table/types.cc b/src/components/policy/policy_regular/src/policy_table/types.cc
index 5f6f85f5dd..851ed1bd18 100644
--- a/src/components/policy/policy_regular/src/policy_table/types.cc
+++ b/src/components/policy/policy_regular/src/policy_table/types.cc
@@ -164,14 +164,11 @@ ApplicationParams::ApplicationParams(const Json::Value* value__)
, nicknames(impl::ValueMember(value__, "nicknames"))
, AppHMIType(impl::ValueMember(value__, "AppHMIType"))
, RequestType(impl::ValueMember(value__, "RequestType"))
+ , RequestSubType(impl::ValueMember(value__, "RequestSubType"))
, memory_kb(impl::ValueMember(value__, "memory_kb"), 0)
, heart_beat_timeout_ms(impl::ValueMember(value__, "heart_beat_timeout_ms"))
, certificate(impl::ValueMember(value__, "certificate"), "not_specified")
-#ifdef SDL_REMOTE_CONTROL
- , moduleType(impl::ValueMember(value__, "moduleType"))
-#endif // SDL_REMOTE_CONTROL
-{
-}
+ , moduleType(impl::ValueMember(value__, "moduleType")) {}
Json::Value ApplicationParams::ToJsonValue() const {
Json::Value result__(PolicyBase::ToJsonValue());
@@ -179,17 +176,17 @@ Json::Value ApplicationParams::ToJsonValue() const {
impl::WriteJsonField("nicknames", nicknames, &result__);
impl::WriteJsonField("AppHMIType", AppHMIType, &result__);
impl::WriteJsonField("RequestType", RequestType, &result__);
+ impl::WriteJsonField("RequestSubType", RequestSubType, &result__);
impl::WriteJsonField("memory_kb", memory_kb, &result__);
impl::WriteJsonField(
"heart_beat_timeout_ms", heart_beat_timeout_ms, &result__);
-#ifdef SDL_REMOTE_CONTROL
impl::WriteJsonField("moduleType", moduleType, &result__);
-#endif // SDL_REMOTE_CONTROL
return result__;
}
bool ApplicationParams::is_valid() const {
- // RequestType is not validated since there is high-level validation logic,
+ // RequestType and RequestSubType are not validated since there is high-level
+ // validation logic,
// which takes into account information not available here.
if (!PolicyBase::is_valid()) {
return false;
@@ -212,11 +209,9 @@ bool ApplicationParams::is_valid() const {
if (!certificate.is_valid()) {
return false;
}
-#ifdef SDL_REMOTE_CONTROL
if (!moduleType.is_valid()) {
return false;
}
-#endif // SDL_REMOTE_CONTROL
return Validate();
}
@@ -240,6 +235,9 @@ bool ApplicationParams::struct_empty() const {
if (RequestType.is_initialized()) {
return false;
}
+ if (RequestSubType.is_initialized()) {
+ return false;
+ }
if (memory_kb.is_initialized()) {
return false;
}
@@ -249,11 +247,9 @@ bool ApplicationParams::struct_empty() const {
if (certificate.is_initialized()) {
return false;
}
-#ifdef SDL_REMOTE_CONTROL
if (moduleType.is_initialized()) {
return false;
}
-#endif // SDL_REMOTE_CONTROL
return true;
}
@@ -273,6 +269,9 @@ void ApplicationParams::ReportErrors(rpc::ValidationReport* report__) const {
if (!RequestType.is_valid()) {
RequestType.ReportErrors(&report__->ReportSubobject("RequestType"));
}
+ if (!RequestSubType.is_valid()) {
+ RequestSubType.ReportErrors(&report__->ReportSubobject("RequestSubType"));
+ }
if (!priority.is_valid()) {
priority.ReportErrors(&report__->ReportSubobject("priority"));
}
@@ -286,11 +285,9 @@ void ApplicationParams::ReportErrors(rpc::ValidationReport* report__) const {
if (!certificate.is_valid()) {
certificate.ReportErrors(&report__->ReportSubobject("certificate"));
}
-#ifdef SDL_REMOTE_CONTROL
if (!moduleType.is_valid()) {
moduleType.ReportErrors(&report__->ReportSubobject("moduleType"));
}
-#endif // SDL_REMOTE_CONTROL
}
void ApplicationParams::SetPolicyTableType(PolicyTableType pt_type) {
@@ -298,12 +295,11 @@ void ApplicationParams::SetPolicyTableType(PolicyTableType pt_type) {
groups.SetPolicyTableType(pt_type);
AppHMIType.SetPolicyTableType(pt_type);
RequestType.SetPolicyTableType(pt_type);
+ RequestSubType.SetPolicyTableType(pt_type);
memory_kb.SetPolicyTableType(pt_type);
heart_beat_timeout_ms.SetPolicyTableType(pt_type);
certificate.SetPolicyTableType(pt_type);
-#ifdef SDL_REMOTE_CONTROL
moduleType.SetPolicyTableType(pt_type);
-#endif // SDL_REMOTE_CONTROL
}
// RpcParameters methods
@@ -459,6 +455,7 @@ ModuleConfig::ModuleConfig(const Json::Value* value__)
: CompositeType(InitHelper(value__, &Json::Value::isObject))
, device_certificates(impl::ValueMember(value__, "device_certificates"))
, preloaded_pt(impl::ValueMember(value__, "preloaded_pt"))
+ , full_app_id_supported(impl::ValueMember(value__, "full_app_id_supported"))
, exchange_after_x_ignition_cycles(
impl::ValueMember(value__, "exchange_after_x_ignition_cycles"))
, exchange_after_x_kilometers(
@@ -498,6 +495,8 @@ void ModuleConfig::SafeCopyFrom(const ModuleConfig& from) {
Json::Value ModuleConfig::ToJsonValue() const {
Json::Value result__(Json::objectValue);
impl::WriteJsonField("preloaded_pt", preloaded_pt, &result__);
+ impl::WriteJsonField(
+ "full_app_id_supported", full_app_id_supported, &result__);
impl::WriteJsonField("exchange_after_x_ignition_cycles",
exchange_after_x_ignition_cycles,
&result__);
@@ -525,6 +524,9 @@ bool ModuleConfig::is_valid() const {
if (!preloaded_pt.is_valid()) {
return false;
}
+ if (!full_app_id_supported.is_valid()) {
+ return false;
+ }
if (!exchange_after_x_ignition_cycles.is_valid()) {
return false;
}
@@ -572,6 +574,9 @@ bool ModuleConfig::struct_empty() const {
if (preloaded_pt.is_initialized()) {
return false;
}
+ if (full_app_id_supported.is_initialized()) {
+ return false;
+ }
if (exchange_after_x_ignition_cycles.is_initialized()) {
return false;
@@ -621,6 +626,10 @@ void ModuleConfig::ReportErrors(rpc::ValidationReport* report__) const {
if (!preloaded_pt.is_valid()) {
preloaded_pt.ReportErrors(&report__->ReportSubobject("preloaded_pt"));
}
+ if (!full_app_id_supported.is_valid()) {
+ full_app_id_supported.ReportErrors(
+ &report__->ReportSubobject("full_app_id_supported"));
+ }
if (!exchange_after_x_ignition_cycles.is_valid()) {
exchange_after_x_ignition_cycles.ReportErrors(
&report__->ReportSubobject("exchange_after_x_ignition_cycles"));
@@ -679,6 +688,7 @@ void ModuleConfig::ReportErrors(rpc::ValidationReport* report__) const {
void ModuleConfig::SetPolicyTableType(PolicyTableType pt_type) {
CompositeType::SetPolicyTableType(pt_type);
preloaded_pt.SetPolicyTableType(pt_type);
+ full_app_id_supported.SetPolicyTableType(pt_type);
exchange_after_x_ignition_cycles.SetPolicyTableType(pt_type);
exchange_after_x_kilometers.SetPolicyTableType(pt_type);
exchange_after_x_days.SetPolicyTableType(pt_type);
diff --git a/src/components/policy/policy_regular/src/policy_table/validation.cc b/src/components/policy/policy_regular/src/policy_table/validation.cc
index 10b8e4bf7c..714dfaae5a 100644
--- a/src/components/policy/policy_regular/src/policy_table/validation.cc
+++ b/src/components/policy/policy_regular/src/policy_table/validation.cc
@@ -40,11 +40,12 @@ bool ApplicationPoliciesSection::Validate() const {
return false;
}
- PolicyTableType pt_type = GetPolicyTableType();
+ const PolicyTableType pt_type = GetPolicyTableType();
if (PT_PRELOADED != pt_type && PT_UPDATE != pt_type) {
return true;
}
+ LOG4CXX_TRACE(logger_, "Checking app Request Types...");
if (!it_default_policy->second.RequestType.is_valid()) {
LOG4CXX_WARN(logger_,
"Default policy RequestTypes are not valid. Will be cleaned.");
@@ -65,10 +66,15 @@ bool ApplicationPoliciesSection::Validate() const {
ApplicationPolicies::iterator end_iter = apps.end();
while (iter != end_iter) {
+ if (it_default_policy == iter || it_pre_data_policy == iter) {
+ ++iter;
+ continue;
+ }
ApplicationParams& app_params = (*iter).second;
- bool is_request_type_omitted = !app_params.RequestType.is_initialized();
- bool is_request_type_valid = app_params.RequestType.is_valid();
- bool is_request_type_empty = app_params.RequestType->empty();
+ const bool is_request_type_omitted =
+ !app_params.RequestType.is_initialized();
+ const bool is_request_type_valid = app_params.RequestType.is_valid();
+ const bool is_request_type_empty = app_params.RequestType->empty();
if (PT_PRELOADED == pt_type) {
if (!is_request_type_valid) {
@@ -111,10 +117,36 @@ bool ApplicationPoliciesSection::Validate() const {
++iter;
}
+ LOG4CXX_TRACE(logger_, "Checking app Request SubTypes...");
+ iter = apps.begin();
+ while (iter != end_iter) {
+ if (it_default_policy == iter || it_pre_data_policy == iter) {
+ ++iter;
+ continue;
+ }
+ ApplicationParams& app_params = (*iter).second;
+ const bool is_request_subtype_omitted =
+ !app_params.RequestSubType.is_initialized();
+
+ if (is_request_subtype_omitted) {
+ LOG4CXX_WARN(logger_,
+ "App policy RequestSubTypes omitted."
+ " Will be replaced with default.");
+ app_params.RequestSubType = apps[kDefaultApp].RequestSubType;
+ ++iter;
+ continue;
+ }
+
+ const bool is_request_subtype_empty = app_params.RequestSubType->empty();
+ if (is_request_subtype_empty) {
+ LOG4CXX_WARN(logger_, "App policy RequestSubTypes empty.");
+ }
+ ++iter;
+ }
+
return true;
}
-#ifdef SDL_REMOTE_CONTROL
bool ApplicationParams::ValidateModuleTypes() const {
// moduleType is optional so see Optional<T>::is_valid()
bool is_initialized = moduleType->is_initialized();
@@ -148,11 +180,6 @@ bool ApplicationParams::ValidateModuleTypes() const {
bool ApplicationParams::Validate() const {
return ValidateModuleTypes();
}
-#else // SDL_REMOTE_CONTROL
-bool ApplicationParams::Validate() const {
- return true;
-}
-#endif // SDL_REMOTE_CONTROL
bool RpcParameters::Validate() const {
return true;
diff --git a/src/components/policy/policy_regular/src/sql_pt_ext_queries.cc b/src/components/policy/policy_regular/src/sql_pt_ext_queries.cc
deleted file mode 100644
index 3fde462a32..0000000000
--- a/src/components/policy/policy_regular/src/sql_pt_ext_queries.cc
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- Copyright (c) 2013, " Ford Motor Company
- All rights reserved.
-
- Redistribution and use in source and binary forms, " with or without
- modification, " are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice, " this
- list of conditions and the following disclaimer.
-
- Redistributions in binary form must reproduce the above copyright notice, "
- this list of conditions and the following
- disclaimer in the documentation and/or other materials provided with the
- distribution.
-
- Neither the name of the Ford Motor Company nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, " INCLUDING, " BUT NOT LIMITED TO, " THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, " INDIRECT, " INCIDENTAL, " SPECIAL, " EXEMPLARY, " OR
- CONSEQUENTIAL DAMAGES (INCLUDING, " BUT NOT LIMITED TO, " PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, " DATA, " OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, " WHETHER IN
- CONTRACT, " STRICT LIABILITY, " OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, " EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "policy/sql_pt_ext_queries.h"
-
-namespace policy {
-namespace sql_pt_ext {
-
-const std::string kSelectKeepContext =
- "SELECT `keep_context` FROM `application` WHERE `id` = ? LIMIT 1";
-
-const std::string kSelectStealFocus =
- "SELECT `steal_focus` FROM `application` WHERE `id` = ? LIMIT 1";
-
-const std::string kSelectDefaultHmi =
- "SELECT `default_hmi` FROM `application` WHERE `id` = ? LIMIT 1";
-
-const std::string kResetDeviceConsents = "DELETE FROM `device_consent_group`";
-
-const std::string kResetAppConsents = "DELETE FROM `consent_group`";
-
-const std::string kCountDeviceConsentGroup =
- "SELECT COUNT (`device_id`) "
- "FROM `device_consent_group` WHERE `device_id` = ?";
-
-const std::string kCountDevice =
- "SELECT COUNT (`id`) "
- "FROM `device` WHERE `id` = ?";
-
-const std::string kSelectDeviceConsentedGroup =
- "SELECT * FROM `device_consent_group` WHERE `device_id` = ?";
-
-const std::string kUpdateDeviceConsentedGroup =
- "UPDATE `device_consent_group` SET `is_consented` = ?, `input` = ? WHERE "
- "(`device_id` = ? AND `functional_group_id` = ?)";
-
-const std::string kUpdateDevice =
- "UPDATE `device` SET `hardware` = ?, `firmware_rev` = ?, `os` = ?, "
- "`os_version` = ?, `carrier` = ?, `max_number_rfcom_ports` = ?, "
- " `connection_type` = ? WHERE `id` = ? ";
-
-const std::string kInsertDeviceConsentedGroup =
- "INSERT OR REPLACE INTO `device_consent_group` "
- "(`device_id`, `functional_group_id`, `is_consented`, `input`, "
- "`time_stamp`) "
- "VALUES (?,?,?,?,?)";
-
-const std::string kInsertDevice =
- "INSERT OR IGNORE INTO `device` "
- "(`id`, `hardware`, `firmware_rev`, `os`, `os_version`, `carrier`,"
- "`max_number_rfcom_ports`, `connection_type`) "
- "VALUES (?,?,?,?,?,?,?,?)";
-
-const std::string kSelectDeviceData = "SELECT * FROM `device`";
-
-const std::string kSelectConsentGroup =
- "SELECT * FROM `consent_group` WHERE `device_id` = ? ";
-
-const std::string kInsertPreconsentedGroups =
- "INSERT INTO `preconsented_group` (`application_id`, `functional_group_id`)"
- " SELECT ?, `id` FROM `functional_group` WHERE `name` = ? LIMIT 1";
-
-const std::string kSelectPreconsentedGroups =
- "SELECT `f`.`name` FROM `preconsented_group` AS `p`"
- " LEFT JOIN `functional_group` AS `f` "
- " ON (`f`.`id` = `p`.`functional_group_id`)"
- " WHERE `p`.`application_id` = ?";
-
-const std::string kDeletePreconsentedGroups =
- "DELETE FROM `preconsented_group`";
-
-const std::string kSelectUsageAndErrorCount =
- "SELECT `count_of_iap_buffer_full`, `count_sync_out_of_memory`, "
- " `count_of_sync_reboots` "
- "FROM `usage_and_error_count` LIMIT 1";
-
-const std::string kSelectAppLevels =
- "SELECT `application_id`, `minutes_in_hmi_full`, `minutes_in_hmi_limited`, "
- " `minutes_in_hmi_background`, `minutes_in_hmi_none`, "
- " `count_of_user_selections`, "
- " `count_of_rejections_sync_out_of_memory`, "
- " `count_of_rejections_nickname_mismatch`, "
- " `count_of_rejections_duplicate_name`, "
- " `count_of_rejected_rpcs_calls`, "
- " `count_of_rpcs_sent_in_hmi_none`, "
- " `count_of_removals_for_bad_behavior`, "
- " `count_of_run_attempts_while_revoked`, "
- " `app_registration_language_gui`, "
- " `app_registration_language_vui`, "
- " `count_of_tls_errors` "
- "FROM `app_level`";
-
-const std::string kUpdateGlobalCounters =
- "UPDATE `usage_and_error_count` SET "
- "`count_of_iap_buffer_full` = ?, "
- "`count_sync_out_of_memory` = ?, "
- "`count_of_sync_reboots` = ? ";
-
-const std::string kInsertDeviceData =
- "INSERT OR IGNORE INTO `device` "
- "(`id`, `hardware`, `firmware_rev`, `os`, `os_version`, `carrier`, "
- "`max_number_rfcom_ports`,`connection_type`) VALUES (?,?,?,?,?,?,?,?) ";
-
-const std::string kInsertConsentGroups =
- "INSERT OR REPLACE INTO `consent_group` "
- "(`device_id`, `application_id`, `functional_group_id`, `is_consented`, "
- "`input`, `time_stamp`) "
- "VALUES (?,?,?,?,?,?)";
-
-const std::string kDeleteAppGroupConsent =
- "DELETE FROM `consent_group` WHERE "
- "`application_id` = ? AND `functional_group_id` = ? ";
-
-const std::string kSelectGroupId =
- "SELECT `id` FROM `functional_group` WHERE `name` = ? ";
-
-const std::string kCountUnconsentedGroups =
- "SELECT COUNT(`a`.`functional_group_id`) FROM `app_group` AS `a` "
- " WHERE `a`.`application_id` = ? AND NOT EXISTS "
- " (SELECT NULL FROM `preconsented_group` AS `p` WHERE "
- " (`p`.`functional_group_id` = `a`.`functional_group_id` AND "
- " `p`.`application_id` = `a`.`application_id`)) "
- " AND NOT EXISTS (SELECT NULL FROM `consent_group` AS `c` "
- " WHERE (`c`.`application_id` = `a`.`application_id` "
- " AND `c`.`functional_group_id` = `a`.`functional_group_id` "
- " AND `c`.`device_id` = ?)) AND NOT EXISTS "
- " (SELECT NULL FROM `app_group` AS `def` WHERE "
- " (`def`.`application_id` = ? OR "
- " `def`.`application_id` = ?) "
- " AND `def`.`functional_group_id` = `a`.`functional_group_id`)"
- " AND NOT EXISTS (SELECT NULL FROM `functional_group` AS `f` "
- " WHERE (`a`.`functional_group_id` = `f`.`id`"
- " AND`f`.`user_consent_prompt` IS NULL))";
-
-const std::string kSelectModuleMeta = "SELECT* FROM `module_meta`";
-
-const std::string kUpdateMetaParams =
- "UPDATE `module_meta` SET "
- "`ccpu_version` = ?, `wers_country_code` = ?, `language` = ? ";
-
-const std::string kUpdateModuleMetaVinParam =
- "UPDATE `module_meta` SET `vin` = ? ";
-
-const std::string kSaveModuleMeta =
- "UPDATE `module_meta` SET `ccpu_version` = ?, `language` = ?,"
- "`wers_country_code` = ?, `pt_exchanged_at_odometer_x` = ?,"
- "`pt_exchanged_x_days_after_epoch` = ?,"
- "`ignition_cycles_since_last_exchange` = ?, `vin` = ?";
-
-const std::string kSelectMetaParams =
- "SELECT `ccpu_version`, "
- "`wers_country_code`, `language` from `module_meta`";
-
-const std::string kUpdateMetaLanguage =
- "UPDATE `module_meta` SET `language` = ? ";
-
-const std::string kCountAppLevel =
- "SELECT COUNT(`application_id`) FROM `app_level`"
- " WHERE `application_id` = ? ";
-
-const std::string kUpdateGroupPermissions =
- "UPDATE `consent_group` "
- "SET `is_consented` = ?, `input` = ? "
- "WHERE(`application_id` = ? AND `functional_group_id` = ? AND `device_id` "
- "= ?) ";
-
-const std::string kInsertApplication =
- "INSERT OR IGNORE INTO `application`(`id`, `keep_context`, `steal_focus`, "
- " `default_hmi`, `priority_value`, `is_revoked`, `memory_kb`, "
- " `heart_beat_timeout_ms`, `certificate`) VALUES( ?, ?, ?, ?, ?, ?, ?, ?, "
- "?) ";
-
-const std::string kCollectFriendlyMsg = "SELECT * FROM `message`";
-
-const std::string kSelectFriendlyMsg =
- "SELECT `tts`, `label`, `line1`, `line2`, `textBody` FROM `message` "
- "WHERE `message_type_name` = ? AND `language_code` = ? LIMIT 1";
-
-const std::string kSelectAppGroupsId =
- "SELECT `functional_group_id` "
- "FROM `app_group` WHERE `application_id` = ? ";
-
-const std::string kSelectConsentedGroupsId =
- "SELECT `functional_group_id`, `is_consented` "
- "FROM `consent_group` WHERE(`application_id` = ? AND `device_id` = ?) ";
-
-const std::string kCountAppConsents =
- "SELECT COUNT(*) from `consent_group`"
- "WHERE(`device_id` = ? AND `application_id` = ? AND "
- "`functional_group_id` = ?) ";
-
-const std::string kSelectPreconsentedGroupsId =
- "SELECT `functional_group_id` "
- "FROM `preconsented_group` WHERE `application_id` = ? ";
-
-const std::string kSelectAppPolicies =
- "SELECT `id`, `priority_value`, `default_hmi`, `keep_context`, "
- "`steal_focus`, "
- " `memory_kb`, `heart_beat_timeout_ms`, `certificate` FROM `application`";
-
-const std::string kSelectFunctionalGroupNames =
- "SELECT `id`, `user_consent_prompt`, `name`"
- " FROM `functional_group`";
-
-const std::string kDeleteDeviceConsent =
- "DELETE FROM `device_consent_group` "
- "WHERE `device_id` = ? ";
-
-const std::string kDeleteAppConsent =
- "DELETE FROM `consent_group` "
- "WHERE `device_id` = ? ";
-
-const std::string kSelectApplicationIsPreData =
- "SELECT `is_predata` FROM `application` WHERE `id` = ? ";
-
-const std::string kUpdateIsPredata =
- "UPDATE `application` SET `is_predata` = ? WHERE `id` = ? ";
-
-const std::string kHasAppPreloadedGroups =
- "SELECT COUNT(`a1`.`functional_group_id`) FROM `app_group` "
- " AS `a1` JOIN `app_group` AS `a2` "
- " ON `a1`.`functional_group_id` = `a2`.`functional_group_id` "
- " WHERE `a1`.`application_id` = ? AND `a2`.`application_id` = ? ";
-
-const std::string kUpdateUnpairedDevice =
- "UPDATE `device` SET `unpaired` = ? WHERE `id` = ? ";
-
-const std::string kSelectUnpairedDevices =
- "SELECT `id` FROM `device` WHERE `unpaired` = 1";
-
-const std::string kHasMsgLanguageCode =
- "SELECT COUNT (`id`) FROM message "
- "WHERE `message_type_name` = ? AND `language_code` = ? ";
-
-const std::string kDeletePreconsentedGroupsByApplicationId =
- "DELETE FROM `preconsented_group` WHERE `application_id` = ?";
-
-} // namespace sql_pt_ext
-} // namespace policy
diff --git a/src/components/policy/policy_regular/src/sql_pt_ext_representation.cc b/src/components/policy/policy_regular/src/sql_pt_ext_representation.cc
deleted file mode 100644
index c64efaaede..0000000000
--- a/src/components/policy/policy_regular/src/sql_pt_ext_representation.cc
+++ /dev/null
@@ -1,1807 +0,0 @@
-/*
- Copyright (c) 2015, Ford Motor Company
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
- Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following
- disclaimer in the documentation and/or other materials provided with the
- distribution.
-
- Neither the name of the Ford Motor Company nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
- */
-#include <algorithm>
-#include <utility>
-#include "utils/logger.h"
-#include "policy/sql_pt_ext_representation.h"
-#include "policy/sql_wrapper.h"
-#include "policy/sql_pt_queries.h"
-#include "policy/sql_pt_ext_queries.h"
-#include "policy/policy_helper.h"
-#include "policy/cache_manager.h"
-
-namespace policy {
-
-CREATE_LOGGERPTR_GLOBAL(logger_, "Policy")
-
-bool SQLPTExtRepresentation::CanAppKeepContext(const std::string& app_id) {
- utils::dbms::SQLQuery query(db());
- if (query.Prepare(sql_pt_ext::kSelectKeepContext)) {
- query.Bind(0, app_id);
- if (query.Exec()) {
- return query.GetBoolean(0);
- }
- }
- return false;
-}
-
-bool SQLPTExtRepresentation::CanAppStealFocus(const std::string& app_id) {
- utils::dbms::SQLQuery query(db());
- if (query.Prepare(sql_pt_ext::kSelectStealFocus)) {
- query.Bind(0, app_id);
- if (query.Exec()) {
- return query.GetBoolean(0);
- }
- }
- return false;
-}
-
-bool SQLPTExtRepresentation::ResetUserConsent() {
- return ResetDeviceConsents() && ResetAppConsents();
-}
-
-bool SQLPTExtRepresentation::ResetDeviceConsents() {
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kResetDeviceConsents)) {
- LOG4CXX_WARN(logger_, "Incorrect delete statement from device_consents.");
- return false;
- }
- return query.Exec();
-}
-
-bool SQLPTExtRepresentation::ResetAppConsents() {
- return utils::dbms::SQLQuery(db()).Exec(sql_pt_ext::kResetAppConsents);
-}
-
-bool SQLPTExtRepresentation::GetUserPermissionsForDevice(
- const std::string& device_id,
- StringArray* consented_groups,
- StringArray* disallowed_groups) {
- LOG4CXX_AUTO_TRACE(logger_);
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kSelectDeviceConsentedGroup)) {
- LOG4CXX_WARN(logger_, "Incorrect select from device consented groups");
- return false;
- }
- query.Bind(0, device_id);
- while (query.Next()) {
- if (query.GetBoolean(2)) {
- if (!consented_groups) {
- continue;
- }
- consented_groups->push_back(query.GetString(1));
- } else {
- if (!disallowed_groups) {
- continue;
- }
- disallowed_groups->push_back(query.GetString(1));
- }
- }
-
- return true;
-}
-
-bool SQLPTExtRepresentation::GetPermissionsForApp(
- const std::string& device_id,
- const std::string& policy_app_id,
- FunctionalIdType* group_types) {
- LOG4CXX_AUTO_TRACE(logger_);
- if (!group_types) {
- LOG4CXX_WARN(logger_, "Input parameter for group types is null.");
- return false;
- }
- // Get all app groups for specified device and application
- FunctionalGroupIDs all_groups;
- if (!GetAllAppGroups(policy_app_id, all_groups)) {
- return false;
- }
- // Get preconsented group
- FunctionalGroupIDs preconsented_groups;
- if (!GetPreconsentedGroups(policy_app_id, preconsented_groups)) {
- return false;
- }
- // Get consented (allowed/disallowed) groups
- FunctionalGroupIDs allowed_groups;
- FunctionalGroupIDs disallowed_groups;
- if (!GetConsentedGroups(
- policy_app_id, device_id, allowed_groups, disallowed_groups)) {
- return false;
- }
- // Get all default groups
- FunctionalGroupIDs default_groups;
- if (!GetAllAppGroups(kDefaultId, default_groups)) {
- return false;
- }
-
- // Get all pre_DataConsent groups
- FunctionalGroupIDs predataconsented_groups;
- if (!GetAllAppGroups(kPreDataConsentId, predataconsented_groups)) {
- return false;
- }
-
- // Get all device groups
- FunctionalGroupIDs device_groups;
- if (!GetAllAppGroups(kDeviceId, device_groups)) {
- return false;
- }
-
- (*group_types)[kTypeDefault] = default_groups;
- (*group_types)[kTypeAllowed] = allowed_groups;
- (*group_types)[kTypeDisallowed] = disallowed_groups;
- (*group_types)[kTypePreconsented] = preconsented_groups;
- (*group_types)[kTypeGeneral] = all_groups;
- (*group_types)[kTypePreDataConsented] = predataconsented_groups;
- (*group_types)[kTypeDevice] = device_groups;
-
- return true;
-}
-
-bool SQLPTExtRepresentation::GetDeviceGroupsFromPolicies(
- policy_table::Strings* groups, policy_table::Strings* preconsented_groups) {
- LOG4CXX_AUTO_TRACE(logger_);
- if (groups) {
- GatherAppGroup(kDeviceId, groups);
- }
- if (preconsented_groups) {
- GatherPreconsentedGroup(kDeviceId, preconsented_groups);
- }
- return true;
-}
-
-bool SQLPTExtRepresentation::SetDeviceData(const std::string& device_id,
- const std::string& hardware,
- const std::string& firmware,
- const std::string& os,
- const std::string& os_version,
- const std::string& carrier,
- const uint32_t number_of_ports,
- const std::string& connection_type) {
- LOG4CXX_AUTO_TRACE(logger_);
- utils::dbms::SQLQuery count_query(db());
- if (!count_query.Prepare(sql_pt_ext::kCountDevice)) {
- LOG4CXX_WARN(logger_, "Incorrect statement for count of device.");
- return false;
- }
-
- count_query.Bind(0, device_id);
-
- if (!count_query.Exec()) {
- LOG4CXX_WARN(logger_, "Incorrect count of device.");
- return false;
- }
-
- bool update = count_query.GetInteger(0);
-
- // Update old value
- if (update) {
- utils::dbms::SQLQuery update_query(db());
- if (!update_query.Prepare(sql_pt_ext::kUpdateDevice)) {
- LOG4CXX_WARN(logger_, "Incorrect statement for udpate device.");
- return false;
- }
-
- update_query.Bind(0, hardware);
- update_query.Bind(1, firmware);
- update_query.Bind(2, os);
- update_query.Bind(3, os_version);
- update_query.Bind(4, carrier);
- update_query.Bind(5, static_cast<int>(number_of_ports));
- update_query.Bind(6, device_id);
- update_query.Bind(7, connection_type);
-
- if (!update_query.Exec() || !update_query.Reset()) {
- LOG4CXX_WARN(logger_, "Incorrect update for device.");
- return false;
- }
-
- return true;
- }
-
- // Insert new data
- utils::dbms::SQLQuery insert_query(db());
- if (!insert_query.Prepare(sql_pt_ext::kInsertDevice)) {
- LOG4CXX_WARN(logger_, "Incorrect insert statement for device.");
- return false;
- }
-
- insert_query.Bind(0, device_id);
- insert_query.Bind(1, hardware);
- insert_query.Bind(2, firmware);
- insert_query.Bind(3, os);
- insert_query.Bind(4, os_version);
- insert_query.Bind(5, carrier);
- insert_query.Bind(6, static_cast<int>(number_of_ports));
- insert_query.Bind(7, connection_type);
-
- if (!insert_query.Exec() || !insert_query.Reset()) {
- LOG4CXX_WARN(logger_, "Incorrect insert to device.");
- return false;
- }
-
- SetPreloaded(false);
-
- return true;
-}
-
-bool SQLPTExtRepresentation::SetUserPermissionsForDevice(
- const std::string& device_id,
- const StringArray& consented_groups,
- const StringArray& disallowed_groups) {
- LOG4CXX_AUTO_TRACE(logger_);
- utils::dbms::SQLQuery count_query(db());
- if (!count_query.Prepare(sql_pt_ext::kCountDeviceConsentGroup)) {
- LOG4CXX_WARN(logger_, "Incorrect count of device consented groups");
- return false;
- }
-
- count_query.Bind(0, device_id);
-
- if (!count_query.Exec()) {
- LOG4CXX_WARN(logger_, "Failed count of device consented groups");
- return false;
- }
-
- bool update = count_query.GetInteger(0);
-
- // TODO(AOleynik): Split to several methods?
- utils::dbms::SQLQuery query(db());
- // Update old values
- if (update) {
- if (!query.Prepare(sql_pt_ext::kUpdateDeviceConsentedGroup)) {
- LOG4CXX_WARN(
- logger_,
- "Incorrect statement for updating consented groups on device");
- return false;
- }
-
- StringArray::const_iterator it_consented_groups = consented_groups.begin();
- StringArray::const_iterator it_consented_groups_end =
- consented_groups.end();
- for (; it_consented_groups != it_consented_groups_end;
- ++it_consented_groups) {
- query.Bind(0, true);
- query.Bind(1, std::string("GUI"));
- query.Bind(2, device_id);
- query.Bind(3, *it_consented_groups);
- // TODO(AOleynik): Get this info from external data
- if (!query.Exec() || !query.Reset()) {
- LOG4CXX_WARN(logger_,
- "Failed update of device allowed consented groups.");
- return false;
- }
- }
-
- StringArray::const_iterator it_disallowed_groups =
- disallowed_groups.begin();
- StringArray::const_iterator it_disallowed_groups_end =
- disallowed_groups.end();
- for (; it_disallowed_groups != it_disallowed_groups_end;
- ++it_disallowed_groups) {
- query.Bind(0, false);
- query.Bind(1);
- query.Bind(2, device_id);
- query.Bind(3, *it_disallowed_groups);
- if (!query.Exec() || !query.Reset()) {
- LOG4CXX_WARN(logger_,
- "Failed update of device disallowed consented groups.");
- return false;
- }
- }
-
- return true;
- }
-
- // Insert new values
- if (!query.Prepare(sql_pt_ext::kInsertDeviceConsentedGroup)) {
- LOG4CXX_WARN(logger_,
- "Incorrect statement of inserting to device consented groups");
- return false;
- }
-
- StringArray::const_iterator it_consented_groups = consented_groups.begin();
- StringArray::const_iterator it_consented_groups_end = consented_groups.end();
- for (; it_consented_groups != it_consented_groups_end;
- ++it_consented_groups) {
- query.Bind(0, device_id);
- query.Bind(1, *it_consented_groups);
- query.Bind(2, true);
- // TODO(AOleynik): Get this info from external data
- query.Bind(3, std::string("GUI"));
- if (!query.Exec() || !query.Reset()) {
- LOG4CXX_WARN(logger_,
- "Failed insert to device allowed consented groups.");
- return false;
- }
- }
-
- StringArray::const_iterator it_disallowed_groups = disallowed_groups.begin();
- StringArray::const_iterator it_disallowed_groups_end =
- disallowed_groups.end();
- for (; it_disallowed_groups != it_disallowed_groups_end;
- ++it_disallowed_groups) {
- query.Bind(0, device_id);
- query.Bind(1, *it_disallowed_groups);
- query.Bind(2, false);
- query.Bind(3);
- if (!query.Exec() || !query.Reset()) {
- LOG4CXX_WARN(logger_,
- "Failed insert to device disallowed consented groups.");
- return false;
- }
- }
-
- return true;
-}
-
-bool SQLPTExtRepresentation::ReactOnUserDevConsentForApp(
- const std::string& app_id, bool is_device_allowed) {
- bool result = true;
- if (is_device_allowed) {
- // If app has pre_DataConsented groups it should be 'promoted' to default
- // If app has only pre_DataConsented flag it should be only set to false and
- // all groups get restored automatically
- if (IsPredataPolicy(app_id)) {
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kHasAppPreloadedGroups)) {
- LOG4CXX_WARN(logger_,
- "Incorrect statement for has app preloaded groups");
- return false;
- }
- query.Bind(0, app_id);
- query.Bind(1, kPreDataConsentId);
- if (!query.Exec()) {
- LOG4CXX_WARN(logger_,
- "Incorrect select for app has predataconsted groups");
- return false;
- }
- if (query.GetInteger(0) > 0) {
- result = result && SetDefaultPolicy(app_id);
- } else {
- result = result && SetIsPredata(app_id, false);
- }
- }
- } else {
- // If app has default groups change them to pre_DataConsented
- // If app has 'normal' groups leave them as is and set
- // pre_DataConsented flag to true.
- if (IsDefaultPolicy(app_id)) {
- result = result && SetPredataPolicy(app_id);
- } else {
- result = result && SetIsPredata(app_id, true);
- }
- }
- return result;
-}
-
-bool SQLPTExtRepresentation::SetUserPermissionsForApp(
- const PermissionConsent& permissions) {
- LOG4CXX_AUTO_TRACE(logger_);
- // TODO(AOleynik): Handle situation, when no application was specified, i.e.
- // general permissions were set
- std::vector<FunctionalGroupPermission>::const_iterator it =
- permissions.group_permissions.begin();
- std::vector<FunctionalGroupPermission>::const_iterator it_end =
- permissions.group_permissions.end();
-
- utils::dbms::SQLQuery query(db());
- for (; it != it_end; ++it) {
- utils::dbms::SQLQuery counter(db());
- if (!counter.Prepare(sql_pt_ext::kCountAppConsents)) {
- LOG4CXX_WARN(logger_, "Incorrect statement for consent group count.");
- return false;
- }
-
- counter.Bind(0, permissions.device_id);
- counter.Bind(1, permissions.policy_app_id);
- counter.Bind(2, static_cast<int>((*it).group_id));
- if (!counter.Exec()) {
- LOG4CXX_WARN(logger_, "Incorrent count on consent groups.");
- return false;
- }
-
- bool update_required = counter.GetInteger(0);
-
- // Update already present consent record
- if (update_required) {
- if (!query.Prepare(sql_pt_ext::kUpdateGroupPermissions)) {
- LOG4CXX_WARN(logger_, "Incorrect statement for update consent groups.");
- return false;
- }
-
- // Skip consent saving, if user didn't choose any state
- if (policy::kGroupUndefined == (*it).state) {
- continue;
- }
- query.Bind(0, (*it).state == kGroupAllowed ? 1 : 0);
- query.Bind(1, permissions.consent_source);
- query.Bind(2, permissions.policy_app_id);
- query.Bind(3, static_cast<int>((*it).group_id));
- query.Bind(4, permissions.device_id);
-
- if (!query.Exec() || !query.Reset()) {
- LOG4CXX_WARN(logger_,
- "Incorrect update on user defined permissions "
- "for app groups.");
- return false;
- }
- continue;
- }
-
- // Insert new consent record
- if (!query.Prepare(sql_pt_ext::kInsertConsentGroups)) {
- LOG4CXX_WARN(logger_,
- "Incorrect statement for update app group permissions.");
- return false;
- }
-
- // Skip consent saving, if user didn't choose any state
- if (policy::kGroupUndefined == (*it).state) {
- continue;
- }
- query.Bind(0, permissions.device_id);
- query.Bind(1, permissions.policy_app_id);
- query.Bind(2, static_cast<int>((*it).group_id));
- query.Bind(3, (*it).state == kGroupAllowed ? 1 : 0);
- query.Bind(4, permissions.consent_source);
-
- if (!query.Exec() || !query.Reset()) {
- LOG4CXX_WARN(logger_,
- "Incorrect insert to user defined permissions "
- "for app groups.");
- return false;
- }
- continue;
- }
- return true;
-}
-
-std::vector<UserFriendlyMessage> SQLPTExtRepresentation::GetUserFriendlyMsg(
- const std::vector<std::string>& msg_codes, const std::string& language) {
- utils::dbms::SQLQuery query(db());
- std::vector<UserFriendlyMessage> result;
- if (!query.Prepare(sql_pt_ext::kSelectFriendlyMsg)) {
- LOG4CXX_WARN(logger_, "Incorrect statement for select friendly messages.");
- return result;
- }
-
- const std::string fallback_language = "en-us";
- std::vector<std::string>::const_iterator it = msg_codes.begin();
- std::vector<std::string>::const_iterator it_end = msg_codes.end();
- for (; it != it_end; ++it) {
- std::string msg_language = language;
- // If message has no records with required language, fallback language
- // should be used instead.
- if (!IsMsgLanguagePresent((*it), language)) {
- msg_language = fallback_language;
- }
- query.Bind(0, *it);
- query.Bind(1, msg_language);
-
- if (!query.Exec() || !query.Reset()) {
- LOG4CXX_WARN(logger_, "Incorrect select from friendly messages.");
- return result;
- }
-
- UserFriendlyMessage msg;
-
- msg.message_code = *it;
- msg.tts = query.GetString(0);
- msg.label = query.GetString(1);
- msg.line1 = query.GetString(2);
- msg.line2 = query.GetString(3);
- msg.text_body = query.GetString(4);
-
- result.push_back(msg);
-
- if (!query.Reset()) {
- LOG4CXX_WARN(logger_,
- "Failed reset statement for selecting friendly "
- "messages.");
- return result;
- }
- }
-
- return result;
-}
-
-bool SQLPTExtRepresentation::GatherConsumerFriendlyMessages(
- policy_table::ConsumerFriendlyMessages* messages) const {
- if (NULL == messages) {
- LOG4CXX_ERROR(logger_, "NULL pointer has been passed to fill");
- return false;
- }
-
- if (!SQLPTRepresentation::GatherConsumerFriendlyMessages(messages)) {
- return false;
- }
-
- utils::dbms::SQLQuery query(db());
- bool result = query.Prepare(sql_pt_ext::kCollectFriendlyMsg);
-
- if (result) {
- while (query.Next()) {
- UserFriendlyMessage msg;
-
- msg.tts = query.GetString(1);
- msg.label = query.GetString(2);
- msg.line1 = query.GetString(3);
- msg.line2 = query.GetString(4);
- msg.text_body = query.GetString(5);
- msg.message_code = query.GetString(7);
-
- std::string language = query.GetString(6);
-
- *(*messages->messages)[msg.message_code].languages[language].tts =
- msg.tts;
- *(*messages->messages)[msg.message_code].languages[language].label =
- msg.label;
- *(*messages->messages)[msg.message_code].languages[language].line1 =
- msg.line1;
- *(*messages->messages)[msg.message_code].languages[language].line2 =
- msg.line2;
- *(*messages->messages)[msg.message_code].languages[language].textBody =
- msg.text_body;
- }
- } else {
- LOG4CXX_WARN(logger_, "Incorrect statement for select friendly messages.");
- }
- return result;
-}
-
-bool SQLPTExtRepresentation::SetMetaInfo(const std::string& ccpu_version,
- const std::string& wers_country_code,
- const std::string& language) {
- LOG4CXX_AUTO_TRACE(logger_);
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kUpdateMetaParams)) {
- LOG4CXX_WARN(logger_, "Incorrect statement for insert to module meta.");
- return false;
- }
-
- query.Bind(0, ccpu_version);
- query.Bind(1, wers_country_code);
- query.Bind(2, language);
-
- if (!query.Exec() || !query.Reset()) {
- LOG4CXX_WARN(logger_, "Incorrect insert to module meta.");
- return false;
- }
- return true;
-}
-
-bool SQLPTExtRepresentation::IsMetaInfoPresent() {
- LOG4CXX_AUTO_TRACE(logger_);
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kSelectMetaParams)) {
- LOG4CXX_WARN(logger_, "Incorrect statement for selecting meta info.");
- return false;
- }
-
- if (!query.Exec()) {
- LOG4CXX_WARN(logger_, "Incorrect select from module meta.");
- return false;
- }
-
- return !query.IsNull(0) && !query.IsNull(1) && !query.IsNull(2);
-}
-
-bool SQLPTExtRepresentation::SetSystemLanguage(const std::string& language) {
- LOG4CXX_AUTO_TRACE(logger_);
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kUpdateMetaLanguage)) {
- LOG4CXX_WARN(logger_, "Incorrect statement for update meta language.");
- return false;
- }
-
- query.Bind(0, language);
-
- if (!query.Exec()) {
- LOG4CXX_WARN(logger_, "Incorrect update for meta language.");
- return false;
- }
-
- return true;
-}
-
-bool SQLPTExtRepresentation::SaveApplicationPoliciesSection(
- const policy_table::ApplicationPoliciesSection& policies) {
- LOG4CXX_INFO(logger_, "SaveApplicationPolicies ext");
- utils::dbms::SQLQuery query_delete(db());
- if (!query_delete.Exec(sql_pt::kDeleteAppGroup)) {
- LOG4CXX_WARN(logger_, "Incorrect delete from app_group.");
- return false;
- }
-
- utils::dbms::SQLQuery query_delete_preconsented(db());
- if (!query_delete_preconsented.Exec(sql_pt_ext::kDeletePreconsentedGroups)) {
- LOG4CXX_WARN(logger_, "Incorrect delete from preconsented_group.");
- return false;
- }
-
- if (!query_delete.Exec(sql_pt::kDeleteApplication)) {
- LOG4CXX_WARN(logger_, "Incorrect delete from application.");
- return false;
- }
-
- if (!query_delete.Exec(sql_pt::kDeleteRequestType)) {
- LOG4CXX_WARN(logger_, "Incorrect delete from request type.");
- return false;
- }
-
- // First, all predefined apps (e.g. default, pre_DataConsent) should be saved,
- // otherwise another app with the predefined permissions can get incorrect
- // permissions
- policy_table::ApplicationPolicies::const_iterator it_default =
- policies.apps.find(kDefaultId);
- if (policies.apps.end() != it_default) {
- if (!SaveSpecificAppPolicy(*it_default)) {
- return false;
- }
- }
- policy_table::ApplicationPolicies::const_iterator it_pre_data_consent =
- policies.apps.find(kPreDataConsentId);
- if (policies.apps.end() != it_pre_data_consent) {
- if (!SaveSpecificAppPolicy(*it_pre_data_consent)) {
- return false;
- }
- }
-
- if (!SaveDevicePolicy(policies.device)) {
- return false;
- }
-
- policy_table::ApplicationPolicies::const_iterator it;
- for (it = policies.apps.begin(); it != policies.apps.end(); ++it) {
- // Skip saving of predefined app, since they should be saved before
- if (IsPredefinedApp(*it)) {
- continue;
- }
- if (!SaveSpecificAppPolicy(*it)) {
- return false;
- }
- }
-
- return true;
-}
-
-bool SQLPTExtRepresentation::SaveSpecificAppPolicy(
- const policy_table::ApplicationPolicies::value_type& app) {
- if (app.second.is_string()) {
- if (kDefaultId.compare(app.second.get_string()) == 0) {
- if (!SetDefaultPolicy(app.first)) {
- return false;
- }
- if (!SaveRequestType(app.first, *app.second.RequestType)) {
- return false;
- }
- } else if (kPreDataConsentId.compare(app.second.get_string()) == 0) {
- if (!SetPredataPolicy(app.first)) {
- return false;
- }
- if (!SaveRequestType(app.first, *app.second.RequestType)) {
- return false;
- }
- }
-
- // Stop saving other params, since predefined permissions already set
- return true;
- }
-
- SetIsDefault(app.first, false);
- SetIsPredata(app.first, false);
-
- utils::dbms::SQLQuery app_query(db());
- if (!app_query.Prepare(sql_pt_ext::kInsertApplication)) {
- LOG4CXX_WARN(logger_, "Incorrect insert statement into application.");
- return false;
- }
-
- app_query.Bind(0, app.first);
- app_query.Bind(1, app.second.keep_context);
- app_query.Bind(2, app.second.steal_focus);
- app_query.Bind(
- 3, std::string(policy_table::EnumToJsonString(app.second.default_hmi)));
- app_query.Bind(
- 4, std::string(policy_table::EnumToJsonString(app.second.priority)));
- app_query.Bind(5, app.second.is_null());
- app_query.Bind(6, *app.second.memory_kb);
- app_query.Bind(7, static_cast<int64_t>(*app.second.heart_beat_timeout_ms));
- app.second.certificate.is_initialized()
- ? app_query.Bind(8, *app.second.certificate)
- : app_query.Bind(8, std::string());
-
- if (!app_query.Exec() || !app_query.Reset()) {
- LOG4CXX_WARN(logger_, "Incorrect insert into application.");
- return false;
- }
-
- if (!SaveAppGroup(app.first, app.second.groups)) {
- return false;
- }
- // TODO(IKozyrenko): Check logic if optional container is missing
- if (!SaveNickname(app.first, *app.second.nicknames)) {
- return false;
- }
- // TODO(IKozyrenko): Check logic if optional container is missing
- if (!SaveAppType(app.first, *app.second.AppHMIType)) {
- return false;
- }
- // TODO(IKozyrenko): Check logic if optional container is missing
- if (!SavePreconsentedGroup(app.first, *app.second.preconsented_groups)) {
- return false;
- }
-
- return true;
-}
-
-bool policy::SQLPTExtRepresentation::SaveDevicePolicy(
- const policy_table::DevicePolicy& device) {
- dbms::SQLQuery app_query(db());
- if (!app_query.Prepare(sql_pt_ext::kInsertApplication)) {
- LOG4CXX_WARN(logger_,
- "Incorrect insert statement into application (device).");
- return false;
- }
- app_query.Bind(0, kDeviceId);
- app_query.Bind(1, device.keep_context);
- app_query.Bind(2, device.steal_focus);
- app_query.Bind(
- 3, std::string(policy_table::EnumToJsonString(device.default_hmi)));
- app_query.Bind(4,
- std::string(policy_table::EnumToJsonString(device.priority)));
- app_query.Bind(5, false);
- app_query.Bind(6, 0);
- app_query.Bind(7, 0);
- app_query.Bind(8, std::string());
-
- if (!app_query.Exec() || !app_query.Reset()) {
- LOG4CXX_WARN(logger_, "Incorrect insert into application.");
- return false;
- }
-
- if (!SaveAppGroup(kDeviceId, device.groups)) {
- return false;
- }
- if (!SavePreconsentedGroup(kDeviceId, *device.preconsented_groups)) {
- return false;
- }
-
- return true;
-}
-
-bool SQLPTExtRepresentation::GatherApplicationPoliciesSection(
- policy_table::ApplicationPoliciesSection* policies) const {
- LOG4CXX_INFO(logger_, "Gather applications policies");
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kSelectAppPolicies)) {
- LOG4CXX_WARN(logger_, "Incorrect select from app_policies");
- return false;
- }
-
- while (query.Next()) {
- rpc::Nullable<policy_table::ApplicationParams> params;
- const std::string& app_id = query.GetString(0);
- if (IsApplicationRevoked(app_id)) {
- params.set_to_null();
- (*policies).apps[app_id] = params;
- continue;
- }
- if (IsDefaultPolicy(app_id)) {
- (*policies).apps[app_id].set_to_string(kDefaultId);
- }
- if (IsPredataPolicy(app_id)) {
- (*policies).apps[app_id].set_to_string(kPreDataConsentId);
- }
- if (kDeviceId == app_id) {
- policy_table::DevicePolicy device_policy;
- policy_table::Priority priority;
- policy_table::EnumFromJsonString(query.GetString(1), &priority);
- device_policy.priority = priority;
- policy_table::HmiLevel hmi;
- policy_table::EnumFromJsonString(query.GetString(2), &hmi);
- device_policy.default_hmi = hmi;
- device_policy.keep_context = query.GetBoolean(3);
- device_policy.steal_focus = query.GetBoolean(4);
- if (!GatherAppGroup(app_id, &device_policy.groups)) {
- return false;
- }
- GatherPreconsentedGroup(app_id, &*device_policy.preconsented_groups);
- (*policies).device = device_policy;
- continue;
- }
- policy_table::Priority priority;
- policy_table::EnumFromJsonString(query.GetString(1), &priority);
- params.priority = priority;
- policy_table::HmiLevel hmi;
- policy_table::EnumFromJsonString(query.GetString(2), &hmi);
- params.default_hmi = hmi;
- params.keep_context = query.GetBoolean(3);
- params.steal_focus = query.GetBoolean(4);
- *params.memory_kb = query.GetInteger(5);
- *params.heart_beat_timeout_ms = query.GetUInteger(6);
- if (!query.IsNull(7)) {
- *params.certificate = query.GetString(7);
- }
- if (!GatherAppGroup(app_id, &params.groups)) {
- return false;
- }
- if (!GatherNickName(app_id, &*params.nicknames)) {
- return false;
- }
- if (!GatherAppType(app_id, &*params.AppHMIType)) {
- return false;
- }
- if (!GatherRequestType(app_id, &*params.RequestType)) {
- return false;
- }
- GatherPreconsentedGroup(app_id, &*params.preconsented_groups);
- (*policies).apps[app_id] = params;
- }
- return true;
-}
-
-void SQLPTExtRepresentation::GatherPreconsentedGroup(
- const std::string& app_id, policy_table::Strings* groups) const {
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kSelectPreconsentedGroups)) {
- LOG4CXX_WARN(logger_, "Incorrect select from preconsented group");
- return;
- }
-
- query.Bind(0, app_id);
- while (query.Next()) {
- groups->push_back(query.GetString(0));
- }
-}
-
-bool SQLPTExtRepresentation::GatherUsageAndErrorCounts(
- policy_table::UsageAndErrorCounts* counts) const {
- LOG4CXX_INFO(logger_, "Gather Usage and Error Counts.");
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kSelectUsageAndErrorCount) || !query.Exec()) {
- LOG4CXX_INFO(logger_, "Failed select from user_and_error_count");
- return false;
- }
-
- *counts->count_of_iap_buffer_full = query.GetInteger(0);
- *counts->count_sync_out_of_memory = query.GetInteger(1);
- *counts->count_of_sync_reboots = query.GetInteger(2);
-
- return GatherAppLevels(&*counts->app_level);
-}
-
-bool SQLPTExtRepresentation::GatherAppLevels(
- policy_table::AppLevels* apps) const {
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kSelectAppLevels)) {
- LOG4CXX_INFO(logger_,
- "Failed select from app_level. SQLError = "
- << query.LastError().text());
- return false;
- }
- while (query.Next()) {
- policy_table::AppLevel level;
- // value of time fields database is seconds
- level.minutes_in_hmi_full = query.GetInteger(1);
- level.minutes_in_hmi_limited = query.GetInteger(2);
- level.minutes_in_hmi_background = query.GetInteger(3);
- level.minutes_in_hmi_none = query.GetInteger(4);
- level.count_of_user_selections = query.GetInteger(5);
- level.count_of_rejections_sync_out_of_memory = query.GetInteger(6);
- level.count_of_rejections_nickname_mismatch = query.GetInteger(7);
- level.count_of_rejections_duplicate_name = query.GetInteger(8);
- level.count_of_rejected_rpc_calls = query.GetInteger(9);
- level.count_of_rpcs_sent_in_hmi_none = query.GetInteger(10);
- level.count_of_removals_for_bad_behavior = query.GetInteger(11);
- level.count_of_run_attempts_while_revoked = query.GetInteger(12);
- level.app_registration_language_gui = query.GetString(13);
- level.app_registration_language_vui = query.GetString(14);
- level.count_of_tls_errors = query.GetInteger(15);
- (*apps)[query.GetString(0)] = level;
- }
-
- return true;
-}
-
-void SQLPTExtRepresentation::GatherDeviceData(
- policy_table::DeviceData* data) const {
- LOG4CXX_INFO(logger_, "Gather device data.");
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kSelectDeviceData)) {
- LOG4CXX_WARN(logger_, "Incorrect select statement for device data.");
- return;
- }
- data->mark_initialized();
- while (query.Next()) {
- policy_table::DeviceParams* specific_device = &(*data)[query.GetString(0)];
- *specific_device->hardware = query.GetString(1);
- *specific_device->firmware_rev = query.GetString(2);
- *specific_device->os = query.GetString(3);
- *specific_device->os_version = query.GetString(4);
- *specific_device->carrier = query.GetString(5);
- *specific_device->max_number_rfcom_ports = query.GetInteger(6);
-
- // TODO(IKozyrenko): Check logic if optional container is missing
- GatherConsentGroup(query.GetString(0),
- &(*specific_device->user_consent_records));
- }
-}
-
-void SQLPTExtRepresentation::GatherConsentGroup(
- const std::string& device_id,
- policy_table::UserConsentRecords* records) const {
- LOG4CXX_INFO(logger_, "Gather consent records.");
- utils::dbms::SQLQuery query(db());
- // Fill data for device
- if (!query.Prepare(sql_pt_ext::kSelectDeviceConsentedGroup)) {
- LOG4CXX_WARN(logger_,
- "Incorrect select statement for device consented groups.");
- return;
- }
-
- query.Bind(0, device_id);
-
- // Fill device_data -> user_consent_records -> "device"
- while (query.Next()) {
- policy_table::ConsentRecords* device_consent_records =
- &(*records)[kDeviceId];
- // TODO(IKozyrenko): Check logic if optional container is missing
- policy_table::ConsentGroups& consent_groups =
- *device_consent_records->consent_groups;
- consent_groups[query.GetString(1)] = query.GetBoolean(2);
- policy_table::Input input;
- policy_table::EnumFromJsonString(query.GetString(3), &input);
- *device_consent_records->input = input;
- *device_consent_records->time_stamp = query.GetString(4);
- }
-
- if (!query.Reset()) {
- return;
- }
-
- // Fill data for applications
- if (!query.Prepare(sql_pt_ext::kSelectConsentGroup)) {
- LOG4CXX_WARN(logger_,
- "Incorrect select statement for app consented groups.");
- return;
- }
-
- query.Bind(0, device_id);
-
- // Fill device_data -> user_consent_records -> <app_id>
- while (query.Next()) {
- policy_table::ConsentRecords* app_consent_records =
- &(*records)[query.GetString(1)];
- // TODO(IKozyrenko): Check logic if optional container is missing
- policy_table::ConsentGroups& consent_groups =
- *app_consent_records->consent_groups;
-
- consent_groups[query.GetString(2)] = query.GetBoolean(3);
- policy_table::Input input;
- policy_table::EnumFromJsonString(query.GetString(4), &input);
- *app_consent_records->input = input;
- *app_consent_records->time_stamp = query.GetString(5);
- }
-}
-
-bool SQLPTExtRepresentation::SaveDeviceData(
- const policy_table::DeviceData& devices) {
- LOG4CXX_AUTO_TRACE(logger_);
- utils::dbms::SQLQuery drop_device_query(db());
- const std::string drop_device = "DELETE FROM `device`";
- if (!drop_device_query.Exec(drop_device)) {
- LOG4CXX_WARN(logger_, "Could not clear device table.");
- return false;
- }
-
- utils::dbms::SQLQuery drop_device_consents_query(db());
- const std::string drop_device_consents = "DELETE FROM `device_consent_group`";
- if (!drop_device_consents_query.Exec(drop_device_consents)) {
- LOG4CXX_WARN(logger_, "Could not clear device consents.");
- return false;
- }
-
- utils::dbms::SQLQuery drop_user_consents_query(db());
- const std::string drop_user_consents = "DELETE FROM `consent_group`";
- if (!drop_user_consents_query.Exec(drop_user_consents)) {
- LOG4CXX_WARN(logger_, "Could not clear user consents.");
- return false;
- }
-
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kInsertDeviceData)) {
- LOG4CXX_WARN(logger_, "Incorrect insert statement for device data.");
- return false;
- }
-
- policy_table::DeviceData::const_iterator it = devices.begin();
- policy_table::DeviceData::const_iterator it_end = devices.end();
- for (; it != it_end; ++it) {
- query.Bind(0, it->first);
- query.Bind(1, *(it->second.hardware));
- query.Bind(2, *(it->second.firmware_rev));
- query.Bind(3, *(it->second.os));
- query.Bind(4, *(it->second.os_version));
- query.Bind(5, *(it->second.carrier));
- query.Bind(6, *(it->second.max_number_rfcom_ports));
- query.Bind(7, *(it->second.connection_type));
-
- if (!query.Exec() || !query.Reset()) {
- LOG4CXX_WARN(logger_, "Incorrect insert into device data.");
- return false;
- }
-
- // TODO(IKozyrenko): Check logic if optional container is missing
- if (!SaveConsentGroup(it->first, *it->second.user_consent_records)) {
- return false;
- }
- }
-
- return true;
-}
-
-bool SQLPTExtRepresentation::SaveConsentGroup(
- const std::string& device_id,
- const policy_table::UserConsentRecords& records) {
- LOG4CXX_AUTO_TRACE(logger_);
- utils::dbms::SQLQuery query(db());
-
- policy_table::UserConsentRecords::const_iterator it = records.begin();
- policy_table::UserConsentRecords::const_iterator it_end = records.end();
- for (; it != it_end; ++it) {
- // TODO(IKozyrenko): Check logic if optional container is missing
- policy_table::ConsentGroups::const_iterator it_groups =
- it->second.consent_groups->begin();
- policy_table::ConsentGroups::const_iterator it_groups_end =
- it->second.consent_groups->end();
- for (; it_groups != it_groups_end; ++it_groups) {
- if (kDeviceId == it->first) {
- if (!query.Prepare(sql_pt_ext::kInsertDeviceConsentedGroup)) {
- LOG4CXX_WARN(logger_,
- "Incorrect insert statement for device consent group.");
- return false;
- }
- query.Bind(0, device_id);
- query.Bind(1, it_groups->first);
- query.Bind(2, it_groups->second);
- query.Bind(
- 3,
- std::string(policy_table::EnumToJsonString(*(it->second.input))));
- query.Bind(4, std::string(*(it->second.time_stamp)));
- LOG4CXX_INFO(logger_,
- "Device:"
- << "time stamp "
- << std::string(*(it->second.time_stamp)) << " group "
- << it_groups->first << " consent "
- << it_groups->second);
- } else {
- if (!query.Prepare(sql_pt_ext::kInsertConsentGroups)) {
- LOG4CXX_WARN(logger_,
- "Incorrect insert statement for consent group.");
- return false;
- }
- query.Bind(0, device_id);
- query.Bind(1, it->first);
- query.Bind(2, it_groups->first);
- query.Bind(3, it_groups->second);
- query.Bind(
- 4,
- std::string(policy_table::EnumToJsonString(*(it->second.input))));
- query.Bind(5, std::string(*(it->second.time_stamp)));
- LOG4CXX_INFO(logger_,
- "Device:"
- << "time stamp "
- << std::string(*(it->second.time_stamp)) << " group "
- << it_groups->first << " consent "
- << it_groups->second);
- }
-
- if (!query.Exec() || !query.Reset()) {
- LOG4CXX_WARN(logger_, "Incorrect insert into consent group.");
- return false;
- }
- }
- }
-
- return true;
-}
-
-bool SQLPTExtRepresentation::SavePreconsentedGroup(
- const std::string& app_id, const policy_table::Strings& groups) {
- LOG4CXX_AUTO_TRACE(logger_);
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kInsertPreconsentedGroups)) {
- LOG4CXX_WARN(logger_, "Incorrect insert statement for preconsented groups");
- return false;
- }
-
- policy_table::Strings::const_iterator it;
- for (it = groups.begin(); it != groups.end(); ++it) {
- query.Bind(0, app_id);
- query.Bind(1, *it);
- if (!query.Exec() || !query.Reset()) {
- LOG4CXX_WARN(logger_, "Incorrect insert into preconsented groups.");
- return false;
- }
- }
-
- return true;
-}
-
-void SQLPTExtRepresentation::GatherModuleMeta(
- policy_table::ModuleMeta* meta) const {
- LOG4CXX_INFO(logger_, "Gather Module Meta Info");
- utils::dbms::SQLQuery query(db());
- if (query.Prepare(sql_pt_ext::kSelectModuleMeta) && query.Next()) {
- *meta->ccpu_version = query.GetString(0);
- *meta->language = query.GetString(1);
- *meta->wers_country_code = query.GetString(2);
- *meta->pt_exchanged_at_odometer_x = query.GetInteger(3);
- *meta->pt_exchanged_x_days_after_epoch = query.GetInteger(4);
- *meta->ignition_cycles_since_last_exchange = query.GetInteger(5);
- *meta->vin = query.GetString(6);
- }
-}
-
-void SQLPTExtRepresentation::Increment(const std::string& type) const {
- utils::dbms::SQLQuery query(db());
- std::string update_counter =
- "UPDATE `usage_and_error_count` SET `" + type + "` = `" + type + "` + 1";
- if (!query.Exec(update_counter)) {
- LOG4CXX_INFO(logger_, "Failed updating global counter");
- }
-}
-
-bool SQLPTExtRepresentation::IsExistAppLevel(const std::string& app_id) const {
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kCountAppLevel)) {
- LOG4CXX_INFO(logger_, "Incorrect statement of count app_level");
- return false;
- }
- query.Bind(0, app_id);
- if (!query.Exec()) {
- LOG4CXX_INFO(logger_, "Failed count app_level");
- return false;
- }
- return query.GetInteger(0) > 0;
-}
-
-bool SQLPTExtRepresentation::GetAllAppGroups(const std::string& policy_app_id,
- FunctionalGroupIDs& all_groups) {
- LOG4CXX_INFO(logger_, "GetAllAppGroups for '" << policy_app_id << "'");
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kSelectAppGroupsId)) {
- LOG4CXX_WARN(logger_, "Incorrect statement for select app groups id.");
- return false;
- }
-
- query.Bind(0, policy_app_id);
-
- while (query.Next()) {
- all_groups.push_back(query.GetInteger(0));
- }
-
- return true;
-}
-
-bool SQLPTExtRepresentation::GetConsentedGroups(
- const std::string& policy_app_id,
- const std::string& device_id,
- FunctionalGroupIDs& allowed_groups,
- FunctionalGroupIDs& disallowed_groups) {
- LOG4CXX_AUTO_TRACE(logger_);
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kSelectConsentedGroupsId)) {
- LOG4CXX_WARN(logger_, "Incorrect statement for select consent groups id.");
- return false;
- }
-
- query.Bind(0, policy_app_id);
- query.Bind(1, device_id);
-
- while (query.Next()) {
- if (query.GetBoolean(1)) {
- allowed_groups.push_back(query.GetInteger(0));
- } else {
- disallowed_groups.push_back(query.GetInteger(0));
- }
- }
-
- return true;
-}
-
-bool SQLPTExtRepresentation::GetPreconsentedGroups(
- const std::string& policy_app_id, FunctionalGroupIDs& preconsented_groups) {
- LOG4CXX_AUTO_TRACE(logger_);
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kSelectPreconsentedGroupsId)) {
- LOG4CXX_WARN(logger_,
- "Incorrect statement for select preconsented groups id.");
- return false;
- }
-
- query.Bind(0, policy_app_id);
-
- while (query.Next()) {
- preconsented_groups.push_back(query.GetInteger(0));
- }
-
- return true;
-}
-
-bool SQLPTExtRepresentation::GetFunctionalGroupNames(
- FunctionalGroupNames& names) {
- LOG4CXX_AUTO_TRACE(logger_);
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kSelectFunctionalGroupNames)) {
- LOG4CXX_WARN(logger_,
- "Incorrect statement for select functional groups names.");
- return false;
- }
-
- while (query.Next()) {
- // Some of functional grous doesn't have filled user_consent_prompt
- if (query.IsNull(1)) {
- names[query.GetInteger(0)] =
- std::make_pair<std::string, std::string>("", query.GetString(2));
- } else {
- names[query.GetInteger(0)] = std::make_pair<std::string, std::string>(
- query.GetString(1), query.GetString(2));
- }
- }
-
- return true;
-}
-
-void SQLPTExtRepresentation::FillFunctionalGroupPermissions(
- FunctionalGroupIDs& ids,
- FunctionalGroupNames& names,
- GroupConsent state,
- std::vector<FunctionalGroupPermission>& permissions) {
- FunctionalGroupIDs::const_iterator it = ids.begin();
- FunctionalGroupIDs::const_iterator it_end = ids.end();
- for (; it != it_end; ++it) {
- FunctionalGroupPermission current_group;
- current_group.group_id = *it;
- current_group.group_alias = names[*it].first;
- current_group.group_name = names[*it].second;
- current_group.state = state;
- permissions.push_back(current_group);
- }
-}
-
-void SQLPTExtRepresentation::Increment(const std::string& app_id,
- const std::string& type) const {
- utils::dbms::SQLQuery query(db());
- std::string sql_counter;
- if (IsExistAppLevel(app_id)) {
- // update
- sql_counter = "UPDATE `app_level` SET `" + type + "` = `" + type +
- "` + 1 WHERE `application_id` = ?";
- } else {
- // insert
- sql_counter = "INSERT INTO `app_level` (`application_id`, `" + type +
- "`) "
- "VALUES (?, 1)";
- }
- if (!query.Prepare(sql_counter)) {
- LOG4CXX_INFO(logger_, "Incorrect statement of update app counter");
- return;
- }
- query.Bind(0, app_id);
- if (!query.Exec()) {
- LOG4CXX_INFO(logger_, "Failed updating app counter");
- }
-}
-
-void SQLPTExtRepresentation::Set(const std::string& app_id,
- const std::string& type,
- const std::string& value) const {
- utils::dbms::SQLQuery query(db());
- std::string sql_info;
- if (IsExistAppLevel(app_id)) {
- // update
- sql_info = "UPDATE `app_level` SET `" + type +
- "` = ? "
- "WHERE `application_id` = ?";
- } else {
- // insert
- sql_info = "INSERT INTO `app_level` (`" + type +
- "`, `application_id`) "
- "VALUES (?, ?)";
- }
- if (!query.Prepare(sql_info)) {
- LOG4CXX_INFO(logger_, "Incorrect statement of update app info");
- return;
- }
- query.Bind(0, value);
- query.Bind(1, app_id);
- if (!query.Exec()) {
- LOG4CXX_INFO(logger_, "Failed updating app info");
- }
-}
-
-void SQLPTExtRepresentation::Add(const std::string& app_id,
- const std::string& type,
- int seconds) const {
- utils::dbms::SQLQuery query(db());
- std::string sql_stopwatch;
- if (IsExistAppLevel(app_id)) {
- // update
- sql_stopwatch = "UPDATE `app_level` SET `" + type + "` = `" + type +
- "` + ? WHERE `application_id` = ?";
- } else {
- // insert
- sql_stopwatch = "INSERT INTO `app_level` (`" + type +
- "`, `application_id`) "
- "VALUES (?, ?)";
- }
- if (!query.Prepare(sql_stopwatch)) {
- LOG4CXX_INFO(logger_, "Incorrect statement of update app stopwatch");
- return;
- }
- query.Bind(0, seconds);
- query.Bind(1, app_id);
- if (!query.Exec()) {
- LOG4CXX_INFO(logger_, "Failed updating app stopwatch");
- }
-}
-
-bool SQLPTExtRepresentation::GetDefaultHMI(const std::string& policy_app_id,
- std::string* default_hmi) {
- LOG4CXX_AUTO_TRACE(logger_);
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kSelectDefaultHmi)) {
- LOG4CXX_INFO(logger_, "Incorrect statement for default hmi.");
- return false;
- }
-
- query.Bind(0, policy_app_id);
-
- if (!query.Exec()) {
- LOG4CXX_INFO(logger_, "Error during default hmi getting.");
- return false;
- }
-
- if (query.IsNull(0)) {
- default_hmi->clear();
- return true;
- }
-
- default_hmi->assign(query.GetString(0));
-
- return true;
-}
-
-bool SQLPTExtRepresentation::CountUnconsentedGroups(
- const std::string& policy_app_id,
- const std::string& device_id,
- int* result) const {
- LOG4CXX_AUTO_TRACE(logger_);
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kCountUnconsentedGroups)) {
- LOG4CXX_WARN(logger_, "Incorrect select for unconsented groups.");
- return false;
- }
-
- query.Bind(0, policy_app_id);
- query.Bind(1, device_id);
- query.Bind(2, kDefaultId);
- query.Bind(3, kPreDataConsentId);
-
- if (!query.Exec()) {
- LOG4CXX_INFO(logger_, "Error during executing unconsented groups.");
- return false;
- }
- *result = query.GetInteger(0);
- return true;
-}
-
-bool SQLPTExtRepresentation::IsMsgLanguagePresent(const std::string& message,
- const std::string& language) {
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kHasMsgLanguageCode)) {
- LOG4CXX_WARN(logger_, "Incorrect statement for message language check.");
- return false;
- }
-
- query.Bind(0, message);
- query.Bind(1, language);
-
- if (!query.Exec()) {
- LOG4CXX_WARN(logger_, "Failed to check message language code.");
- return false;
- }
-
- return query.GetInteger(0) != 0;
-}
-
-bool SQLPTExtRepresentation::SaveMessageString(
- const std::string& type,
- const std::string& lang,
- const policy_table::MessageString& strings) {
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt::kInsertMessageString)) {
- LOG4CXX_WARN(logger_, "Incorrect insert statement for message.");
- return false;
- }
-
- query.Bind(0, *strings.tts);
- query.Bind(1, *strings.label);
- query.Bind(2, *strings.line1);
- query.Bind(3, *strings.line2);
- query.Bind(4, lang);
- query.Bind(5, type);
- query.Bind(6, *strings.textBody);
-
- if (!query.Exec() || !query.Reset()) {
- LOG4CXX_WARN(logger_, "Incorrect insert into message.");
- return false;
- }
-
- return true;
-}
-
-bool SQLPTExtRepresentation::SaveUsageAndErrorCounts(
- const policy_table::UsageAndErrorCounts& counts) {
- return SaveAppCounters(*counts.app_level) && SaveGlobalCounters(counts);
-}
-
-bool SQLPTExtRepresentation::SaveModuleMeta(
- const policy_table::ModuleMeta& meta) {
- utils::dbms::SQLQuery query(db());
-
- if (!query.Prepare(sql_pt_ext::kSaveModuleMeta)) {
- LOG4CXX_WARN(logger_, "Incorrect insert statement for module_meta.");
- return false;
- }
- const int64_t odometer = *(meta.pt_exchanged_at_odometer_x);
-
- query.Bind(0, *(meta.ccpu_version));
- query.Bind(1, *(meta.language));
- query.Bind(2, *(meta.wers_country_code));
- query.Bind(3, odometer);
- query.Bind(4, *(meta.pt_exchanged_x_days_after_epoch));
- query.Bind(5, *(meta.ignition_cycles_since_last_exchange));
- query.Bind(6, *(meta.vin));
-
- if (!query.Exec()) {
- LOG4CXX_WARN(logger_, "Incorrect update for module_meta.");
- return false;
- }
-
- return true;
-}
-
-bool SQLPTExtRepresentation::SaveAppCounters(
- const rpc::policy_table_interface_base::AppLevels& app_levels) {
- utils::dbms::SQLQuery query(db());
- if (!query.Exec(sql_pt::kDeleteAppLevel)) {
- LOG4CXX_WARN(logger_, "Incorrect delete from app level.");
- return false;
- }
- if (!query.Prepare(sql_pt::kInsertAppLevel)) {
- LOG4CXX_WARN(logger_, "Incorrect insert statement for app level.");
- return false;
- }
-
- policy_table::AppLevels::const_iterator it;
- for (it = app_levels.begin(); it != app_levels.end(); ++it) {
- query.Bind(0, it->first);
- query.Bind(1, it->second.minutes_in_hmi_full);
- query.Bind(2, it->second.minutes_in_hmi_limited);
- query.Bind(3, it->second.minutes_in_hmi_background);
- query.Bind(4, it->second.minutes_in_hmi_none);
- query.Bind(5, it->second.count_of_user_selections);
- query.Bind(6, it->second.count_of_rejections_sync_out_of_memory);
- query.Bind(7, it->second.count_of_rejections_nickname_mismatch);
- query.Bind(8, it->second.count_of_rejections_duplicate_name);
- query.Bind(9, it->second.count_of_rejected_rpc_calls);
- query.Bind(10, it->second.count_of_rpcs_sent_in_hmi_none);
- query.Bind(11, it->second.count_of_removals_for_bad_behavior);
- query.Bind(12, it->second.count_of_run_attempts_while_revoked);
- query.Bind(13, it->second.app_registration_language_gui);
- query.Bind(14, it->second.app_registration_language_vui);
- query.Bind(15, it->second.count_of_tls_errors);
-
- if (!query.Exec() || !query.Reset()) {
- LOG4CXX_WARN(logger_, "Incorrect insert into app level.");
- return false;
- }
- }
- return true;
-}
-
-bool SQLPTExtRepresentation::SaveGlobalCounters(
- const rpc::policy_table_interface_base::UsageAndErrorCounts& counts) {
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kUpdateGlobalCounters)) {
- LOG4CXX_WARN(logger_, "Incorrect insert statement for global counters.");
- return false;
- }
-
- query.Bind(0, *counts.count_of_iap_buffer_full);
- query.Bind(1, *counts.count_sync_out_of_memory);
- query.Bind(2, *counts.count_of_sync_reboots);
-
- if (!query.Exec()) {
- LOG4CXX_WARN(logger_, "Incorrect insert into global counters.");
- return false;
- }
-
- return true;
-}
-
-bool SQLPTExtRepresentation::CleanupUnpairedDevices(
- const DeviceIds& device_ids) const {
- LOG4CXX_AUTO_TRACE(logger_);
- utils::dbms::SQLQuery delete_device_query(db());
- if (!delete_device_query.Prepare(sql_pt::kDeleteDevice)) {
- LOG4CXX_WARN(logger_, "Incorrect statement for device delete.");
- return true;
- }
-
- utils::dbms::SQLQuery delete_device_consent_query(db());
- if (!delete_device_consent_query.Prepare(sql_pt_ext::kDeleteDeviceConsent)) {
- LOG4CXX_WARN(logger_, "Incorrect statement for delete device consent.");
- return false;
- }
-
- utils::dbms::SQLQuery delete_app_consent_query(db());
- if (!delete_app_consent_query.Prepare(sql_pt_ext::kDeleteAppConsent)) {
- LOG4CXX_WARN(logger_, "Incorrect statement for delete app consent.");
- return false;
- }
-
- DeviceIds::const_iterator it = device_ids.begin();
- DeviceIds::const_iterator it_end = device_ids.end();
- for (; it != it_end; ++it) {
- delete_device_query.Bind(0, (*it));
- if (!delete_device_query.Exec() || !delete_device_query.Reset()) {
- LOG4CXX_WARN(logger_, "Failed to delete from device");
- return false;
- }
-
- delete_device_consent_query.Bind(0, (*it));
- if (!delete_device_consent_query.Exec() ||
- !delete_device_consent_query.Reset()) {
- LOG4CXX_WARN(logger_, "Failed to delete from device consent.");
- return false;
- }
-
- delete_app_consent_query.Bind(0, (*it));
- if (!delete_app_consent_query.Exec() || !delete_app_consent_query.Reset()) {
- LOG4CXX_WARN(logger_, "Failed to delete from app consent.");
- return false;
- }
- }
- return true;
-}
-
-bool SQLPTExtRepresentation::SetDefaultPolicy(const std::string& app_id) {
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt::kDeleteAppGroupByApplicationId)) {
- LOG4CXX_ERROR(logger_, "Incorrect statement to delete from app_group.");
- return false;
- }
- query.Bind(0, app_id);
- if (!query.Exec()) {
- LOG4CXX_ERROR(logger_, "Failed deleting from app_group.");
- return false;
- }
-
- if (!query.Prepare(sql_pt_ext::kDeletePreconsentedGroupsByApplicationId)) {
- LOG4CXX_ERROR(logger_, "Incorrect statement to delete from app_group.");
- return false;
- }
- query.Bind(0, app_id);
- if (!query.Exec()) {
- LOG4CXX_ERROR(logger_, "Failed deleting from app_group.");
- return false;
- }
-
- if (!CopyApplication(kDefaultId, app_id)) {
- return false;
- }
-
- SetPreloaded(false);
-
- policy_table::Strings default_groups;
- policy_table::Strings default_preconsented_groups;
- GatherAppGroup(kDefaultId, &default_groups);
- GatherPreconsentedGroup(kDefaultId, &default_preconsented_groups);
- if (SaveAppGroup(app_id, default_groups) &&
- SavePreconsentedGroup(app_id, default_preconsented_groups)) {
- return SetIsDefault(app_id, true) && SetIsPredata(app_id, false);
- }
-
- return false;
-}
-
-bool SQLPTExtRepresentation::SetPredataPolicy(const std::string& app_id) {
- LOG4CXX_INFO(logger_,
- "SQLPTExtRepresentation::SetPredataPolicy for " << app_id);
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt::kDeleteAppGroupByApplicationId)) {
- LOG4CXX_ERROR(logger_, "Incorrect statement to delete from app_group.");
- return false;
- }
- query.Bind(0, app_id);
- if (!query.Exec()) {
- LOG4CXX_ERROR(logger_, "Failed deleting from app_group.");
- return false;
- }
-
- if (!query.Prepare(sql_pt_ext::kDeletePreconsentedGroupsByApplicationId)) {
- LOG4CXX_ERROR(logger_, "Incorrect statement to delete from app_group.");
- return false;
- }
- query.Bind(0, app_id);
- if (!query.Exec()) {
- LOG4CXX_ERROR(logger_, "Failed deleting from app_group.");
- return false;
- }
-
- if (!CopyApplication(kPreDataConsentId, app_id)) {
- return false;
- }
-
- SetPreloaded(false);
-
- policy_table::Strings predataconsent_groups;
- policy_table::Strings predataconsent_preconsented_groups;
- GatherAppGroup(kPreDataConsentId, &predataconsent_groups);
- GatherPreconsentedGroup(kPreDataConsentId, &predataconsent_groups);
- if (SaveAppGroup(app_id, predataconsent_groups) &&
- SavePreconsentedGroup(app_id, predataconsent_groups)) {
- return SetIsDefault(app_id, false) && SetIsPredata(app_id, true);
- }
- return false;
-}
-
-bool SQLPTExtRepresentation::IsPredataPolicy(const std::string& app_id) const {
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kSelectApplicationIsPreData)) {
- LOG4CXX_WARN(logger_, "Incorrect select application is pre_dataConsented");
- return false;
- }
-
- query.Bind(0, app_id);
- if (!query.Exec()) {
- LOG4CXX_WARN(logger_, "Failed select application is pre_dataConsented");
- return false;
- }
- return query.IsNull(0) ? false : query.GetBoolean(0);
-}
-
-bool SQLPTExtRepresentation::SetIsPredata(const std::string& app_id,
- bool is_pre_data) {
- LOG4CXX_TRACE(logger_, "Set flag is_predata of application");
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kUpdateIsPredata)) {
- LOG4CXX_WARN(logger_, "Incorect statement for updating is_predata");
- return false;
- }
-
- query.Bind(0, is_pre_data);
- query.Bind(1, app_id);
- if (!query.Exec()) {
- LOG4CXX_WARN(logger_, "Failed update is_predata");
- return false;
- }
- return true;
-}
-
-bool SQLPTExtRepresentation::SetUnpairedDevice(const std::string& device_id,
- bool unpaired) const {
- LOG4CXX_TRACE(logger_, "Set unpaired device: " << device_id);
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kUpdateUnpairedDevice)) {
- LOG4CXX_WARN(logger_, "Incorect statement for updating unpaired device");
- return false;
- }
-
- query.Bind(0, unpaired);
- query.Bind(1, device_id);
- if (!query.Exec()) {
- LOG4CXX_WARN(logger_, "Failed update unpaired device");
- return false;
- }
- return true;
-}
-
-bool SQLPTExtRepresentation::UnpairedDevicesList(DeviceIds* device_ids) const {
- LOG4CXX_TRACE(logger_, "Get list of unpaired devices");
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kSelectUnpairedDevices)) {
- LOG4CXX_WARN(logger_, "Incorect statement for selecting unpaired devices");
- return false;
- }
-
- while (query.Next()) {
- device_ids->push_back(query.GetString(0));
- }
- return true;
-}
-
-bool SQLPTExtRepresentation::SetVINValue(const std::string& value) {
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kUpdateModuleMetaVinParam)) {
- LOG4CXX_WARN(logger_, "Incorect statement for updating module_meta params");
- return false;
- }
-
- query.Bind(0, value);
- const bool result = query.Exec();
-
- if (!result) {
- LOG4CXX_WARN(logger_, "Failed update module_meta");
- }
- return result;
-}
-
-bool SQLPTExtRepresentation::RemoveAppConsentForGroup(
- const std::string& policy_app_id,
- const std::string& functional_group_name) const {
- utils::dbms::SQLQuery query_group_id(db());
- if (!query_group_id.Prepare(sql_pt_ext::kSelectGroupId)) {
- LOG4CXX_WARN(logger_, "Incorect statement for select group name.");
- return false;
- }
-
- query_group_id.Bind(0, functional_group_name);
-
- if (!query_group_id.Exec()) {
- LOG4CXX_WARN(logger_, "Failed to select group id.");
- return false;
- }
-
- const int id = query_group_id.GetInteger(0);
-
- utils::dbms::SQLQuery query(db());
- if (!query.Prepare(sql_pt_ext::kDeleteAppGroupConsent)) {
- LOG4CXX_WARN(logger_, "Incorect statement for remove app consent.");
- return false;
- }
-
- query.Bind(0, policy_app_id);
- query.Bind(1, id);
-
- if (!query.Exec()) {
- LOG4CXX_WARN(logger_, "Failed to remove app consent.");
- return false;
- }
-
- return true;
-}
-
-} // namespace policy
diff --git a/src/components/policy/policy_regular/src/sql_pt_queries.cc b/src/components/policy/policy_regular/src/sql_pt_queries.cc
index ef4ef49273..f5ccffce3b 100644
--- a/src/components/policy/policy_regular/src/sql_pt_queries.cc
+++ b/src/components/policy/policy_regular/src/sql_pt_queries.cc
@@ -258,13 +258,21 @@ const std::string kCreateSchema =
" REFERENCES `application`(`id`) "
"); "
"CREATE TABLE IF NOT EXISTS `request_type`( "
- " `request_type` VARCHAR(50) NOT NULL, "
+ " `request_type` VARCHAR(50), "
" `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, "
" PRIMARY KEY(`request_type`,`application_id`), "
" CONSTRAINT `fk_app_type_application1` "
" FOREIGN KEY(`application_id`) "
" REFERENCES `application`(`id`) "
"); "
+ "CREATE TABLE IF NOT EXISTS `request_subtype`( "
+ " `request_subtype` VARCHAR(50), "
+ " `application_id` VARCHAR(45) NOT NULL COLLATE NOCASE, "
+ " PRIMARY KEY(`request_subtype`,`application_id`), "
+ " CONSTRAINT `fk_request_subtype_app_id` "
+ " FOREIGN KEY(`application_id`) "
+ " REFERENCES `application`(`id`) "
+ "); "
"CREATE INDEX IF NOT EXISTS `app_type.fk_app_type_application1_idx` "
" ON `app_type`(`application_id` COLLATE NOCASE); "
"CREATE TABLE IF NOT EXISTS `consent_group`( "
@@ -440,6 +448,8 @@ const std::string kDropSchema =
"DROP TABLE IF EXISTS `consent_group`; "
"DROP INDEX IF EXISTS `app_type.fk_app_type_application1_idx`; "
"DROP TABLE IF EXISTS `app_type`; "
+ "DROP TABLE IF EXISTS `request_type`; "
+ "DROP TABLE IF EXISTS `request_subtype`; "
"DROP INDEX IF EXISTS `nickname.fk_nickname_application1_idx`; "
"DROP TABLE IF EXISTS `nickname`; "
"DROP INDEX IF EXISTS `app_level.fk_app_level_language2_idx`; "
@@ -582,7 +592,12 @@ const std::string kInsertAppType =
"INSERT OR IGNORE INTO `app_type` (`application_id`, `name`) VALUES (?, ?)";
const std::string kInsertRequestType =
- "INSERT OR IGNORE INTO `request_type` (`application_id`, `request_type`) "
+ "INSERT INTO `request_type` (`application_id`, `request_type`) "
+ "VALUES (?, ?)";
+
+const std::string kInsertRequestSubType =
+ "INSERT INTO `request_subtype` (`application_id`, "
+ "`request_subtype`) "
"VALUES (?, ?)";
const std::string kUpdateVersion = "UPDATE `version` SET `number`= ?";
@@ -695,6 +710,11 @@ const std::string kSelectRequestTypes =
"SELECT DISTINCT `request_type` FROM `request_type` WHERE `application_id` "
"= ?";
+const std::string kSelectRequestSubTypes =
+ "SELECT DISTINCT `request_subtype` FROM `request_subtype` WHERE "
+ "`application_id` "
+ "= ?";
+
const std::string kSelectSecondsBetweenRetries =
"SELECT `value` FROM `seconds_between_retry` ORDER BY `index`";
@@ -740,6 +760,8 @@ const std::string kDeleteApplication = "DELETE FROM `application`";
const std::string kDeleteRequestType = "DELETE FROM `request_type`";
+const std::string kDeleteRequestSubType = "DELETE FROM `request_subtype`";
+
const std::string kSelectApplicationRevoked =
"SELECT `is_revoked` FROM `application` WHERE `id` = ?";
diff --git a/src/components/policy/policy_regular/src/sql_pt_representation.cc b/src/components/policy/policy_regular/src/sql_pt_representation.cc
index 9840a08b26..75f8be74eb 100644
--- a/src/components/policy/policy_regular/src/sql_pt_representation.cc
+++ b/src/components/policy/policy_regular/src/sql_pt_representation.cc
@@ -187,10 +187,10 @@ int SQLPTRepresentation::TimeoutResponse() {
utils::dbms::SQLQuery query(db());
if (!query.Prepare(sql_pt::kSelectTimeoutResponse) || !query.Exec()) {
LOG4CXX_INFO(logger_, "Can not select timeout response for retry sequence");
- const int defaultTimeout = 30 * date_time::DateTime::MILLISECONDS_IN_SECOND;
+ const int defaultTimeout = 30 * date_time::MILLISECONDS_IN_SECOND;
return defaultTimeout;
}
- return query.GetInteger(0) * date_time::DateTime::MILLISECONDS_IN_SECOND;
+ return query.GetInteger(0) * date_time::MILLISECONDS_IN_SECOND;
}
bool SQLPTRepresentation::SecondsBetweenRetries(std::vector<int>* seconds) {
@@ -483,10 +483,10 @@ bool SQLPTRepresentation::RefreshDB() {
return true;
}
-utils::SharedPtr<policy_table::Table> SQLPTRepresentation::GenerateSnapshot()
+std::shared_ptr<policy_table::Table> SQLPTRepresentation::GenerateSnapshot()
const {
LOG4CXX_AUTO_TRACE(logger_);
- utils::SharedPtr<policy_table::Table> table = new policy_table::Table();
+ auto table = std::make_shared<policy_table::Table>();
GatherModuleMeta(&*table->policy_table.module_meta);
GatherModuleConfig(&table->policy_table.module_config);
GatherUsageAndErrorCounts(&*table->policy_table.usage_and_error_counts);
@@ -692,6 +692,7 @@ bool SQLPTRepresentation::GatherApplicationPoliciesSection(
while (query.Next()) {
rpc::Nullable<policy_table::ApplicationParams> params;
const std::string& app_id = query.GetString(0);
+
if (IsApplicationRevoked(app_id)) {
params.set_to_null();
(*policies).apps[app_id] = params;
@@ -720,27 +721,36 @@ bool SQLPTRepresentation::GatherApplicationPoliciesSection(
if (!query.IsNull(3)) {
*params.certificate = query.GetString(4);
}
- if (!GatherAppGroup(app_id, &params.groups)) {
+
+ const auto& gather_app_id = ((*policies).apps[app_id].is_string())
+ ? (*policies).apps[app_id].get_string()
+ : app_id;
+ // Data should be gathered from db by "default" key if application has
+ // default policies
+
+ if (!GatherAppGroup(gather_app_id, &params.groups)) {
return false;
}
-#ifdef SDL_REMOTE_CONTROL
bool denied = false;
- if (!GatherRemoteControlDenied(app_id, &denied)) {
+ if (!GatherRemoteControlDenied(gather_app_id, &denied)) {
return false;
}
if (!denied) {
- if (!GatherModuleType(app_id, &*params.moduleType)) {
+ if (!GatherModuleType(gather_app_id, &*params.moduleType)) {
return false;
}
}
-#endif // SDL_REMOTE_CONTROL
- if (!GatherNickName(app_id, &*params.nicknames)) {
+ if (!GatherNickName(gather_app_id, &*params.nicknames)) {
return false;
}
- if (!GatherAppType(app_id, &*params.AppHMIType)) {
+ if (!GatherAppType(gather_app_id, &*params.AppHMIType)) {
return false;
}
- if (!GatherRequestType(app_id, &*params.RequestType)) {
+ if (!GatherRequestType(gather_app_id, &*params.RequestType)) {
+ return false;
+ }
+
+ if (!GatherRequestSubType(gather_app_id, &*params.RequestSubType)) {
return false;
}
@@ -837,6 +847,7 @@ bool SQLPTRepresentation::SaveFunctionalGroupings(
bool SQLPTRepresentation::SaveRpcs(int64_t group_id,
const policy_table::Rpc& rpcs) {
+ LOG4CXX_AUTO_TRACE(logger_);
utils::dbms::SQLQuery query(db());
utils::dbms::SQLQuery query_parameter(db());
if (!query.Prepare(sql_pt::kInsertRpc) ||
@@ -900,12 +911,10 @@ bool SQLPTRepresentation::SaveApplicationPoliciesSection(
LOG4CXX_WARN(logger_, "Incorrect delete from app_group.");
return false;
}
-#ifdef SDL_REMOTE_CONTROL
if (!query_delete.Exec(sql_pt::kDeleteModuleTypes)) {
LOG4CXX_WARN(logger_, "Incorrect delete from module_type.");
return false;
}
-#endif // SDL_REMOTE_CONTROL
if (!query_delete.Exec(sql_pt::kDeleteApplication)) {
LOG4CXX_WARN(logger_, "Incorrect delete from application.");
return false;
@@ -916,6 +925,11 @@ bool SQLPTRepresentation::SaveApplicationPoliciesSection(
return false;
}
+ if (!query_delete.Exec(sql_pt::kDeleteRequestSubType)) {
+ LOG4CXX_WARN(logger_, "Incorrect delete from request subtype.");
+ return false;
+ }
+
// All predefined apps (e.g. default, pre_DataConsent) should be saved first,
// otherwise another app with the predefined permissions can get incorrect
// permissions
@@ -988,13 +1002,11 @@ bool SQLPTRepresentation::SaveSpecificAppPolicy(
if (!SaveAppGroup(app.first, app.second.groups)) {
return false;
}
-#ifdef SDL_REMOTE_CONTROL
bool denied = !app.second.moduleType->is_initialized();
if (!SaveRemoteControlDenied(app.first, denied) ||
!SaveModuleType(app.first, *app.second.moduleType)) {
return false;
}
-#endif // SDL_REMOTE_CONTROL
if (!SaveNickname(app.first, *app.second.nicknames)) {
return false;
}
@@ -1006,6 +1018,10 @@ bool SQLPTRepresentation::SaveSpecificAppPolicy(
return false;
}
+ if (!SaveRequestSubType(app.first, *app.second.RequestSubType)) {
+ return false;
+ }
+
return true;
}
@@ -1109,15 +1125,59 @@ bool SQLPTRepresentation::SaveRequestType(
}
policy_table::RequestTypes::const_iterator it;
- for (it = types.begin(); it != types.end(); ++it) {
+ if (!types.empty()) {
+ LOG4CXX_WARN(logger_, "Request types not empty.");
+ for (it = types.begin(); it != types.end(); ++it) {
+ query.Bind(0, app_id);
+ query.Bind(1, std::string(policy_table::EnumToJsonString(*it)));
+ if (!query.Exec() || !query.Reset()) {
+ LOG4CXX_WARN(logger_, "Incorrect insert into request types.");
+ return false;
+ }
+ }
+ } else if (types.is_initialized()) {
+ LOG4CXX_WARN(logger_, "Request types empty.");
query.Bind(0, app_id);
- query.Bind(1, std::string(policy_table::EnumToJsonString(*it)));
+ query.Bind(1,
+ std::string(policy_table::EnumToJsonString(
+ policy_table::RequestType::RT_EMPTY)));
if (!query.Exec() || !query.Reset()) {
LOG4CXX_WARN(logger_, "Incorrect insert into request types.");
return false;
}
}
+ return true;
+}
+
+bool SQLPTRepresentation::SaveRequestSubType(
+ const std::string& app_id,
+ const policy_table::RequestSubTypes& request_subtypes) {
+ utils::dbms::SQLQuery query(db());
+ if (!query.Prepare(sql_pt::kInsertRequestSubType)) {
+ LOG4CXX_WARN(logger_, "Incorrect insert statement for request subtypes.");
+ return false;
+ }
+ policy_table::Strings::const_iterator it;
+ if (!request_subtypes.empty()) {
+ LOG4CXX_TRACE(logger_, "Request subtypes are not empty.");
+ for (it = request_subtypes.begin(); it != request_subtypes.end(); ++it) {
+ query.Bind(0, app_id);
+ query.Bind(1, *it);
+ if (!query.Exec() || !query.Reset()) {
+ LOG4CXX_WARN(logger_, "Incorrect insert into request subtypes.");
+ return false;
+ }
+ }
+ } else if (request_subtypes.is_initialized()) {
+ LOG4CXX_WARN(logger_, "Request subtypes empty.");
+ query.Bind(0, app_id);
+ query.Bind(1, std::string("EMPTY"));
+ if (!query.Exec() || !query.Reset()) {
+ LOG4CXX_WARN(logger_, "Incorrect insert into request subtypes.");
+ return false;
+ }
+ }
return true;
}
@@ -1529,11 +1589,36 @@ bool SQLPTRepresentation::GatherRequestType(
if (!policy_table::EnumFromJsonString(query.GetString(0), &type)) {
return false;
}
+ if (policy_table::RequestType::RT_EMPTY == type) {
+ request_types->mark_initialized();
+ continue;
+ }
request_types->push_back(type);
}
return true;
}
+bool SQLPTRepresentation::GatherRequestSubType(
+ const std::string& app_id,
+ policy_table::RequestSubTypes* request_subtypes) const {
+ utils::dbms::SQLQuery query(db());
+ if (!query.Prepare(sql_pt::kSelectRequestSubTypes)) {
+ LOG4CXX_WARN(logger_, "Incorrect select from request subtypes.");
+ return false;
+ }
+
+ query.Bind(0, app_id);
+ while (query.Next()) {
+ const std::string request_subtype = query.GetString(0);
+ if ("EMPTY" == request_subtype) {
+ request_subtypes->mark_initialized();
+ continue;
+ }
+ request_subtypes->push_back(request_subtype);
+ }
+ return true;
+}
+
bool SQLPTRepresentation::GatherNickName(
const std::string& app_id, policy_table::Strings* nicknames) const {
utils::dbms::SQLQuery query(db());
@@ -1564,8 +1649,6 @@ bool SQLPTRepresentation::GatherAppGroup(
return true;
}
-#ifdef SDL_REMOTE_CONTROL
-
bool SQLPTRepresentation::GatherRemoteControlDenied(const std::string& app_id,
bool* denied) const {
LOG4CXX_AUTO_TRACE(logger_);
@@ -1597,6 +1680,10 @@ bool SQLPTRepresentation::GatherModuleType(
if (!policy_table::EnumFromJsonString(query.GetString(0), &type)) {
return false;
}
+ if (policy_table::ModuleType::MT_EMPTY == type) {
+ app_types->mark_initialized();
+ continue;
+ }
app_types->push_back(type);
}
return true;
@@ -1629,18 +1716,30 @@ bool SQLPTRepresentation::SaveModuleType(
}
policy_table::ModuleTypes::const_iterator it;
- for (it = types.begin(); it != types.end(); ++it) {
+ if (!types.empty()) {
+ for (it = types.begin(); it != types.end(); ++it) {
+ query.Bind(0, app_id);
+ std::string module(policy_table::EnumToJsonString(*it));
+ query.Bind(1, module);
+ LOG4CXX_DEBUG(logger_,
+ "Module(app: " << app_id << ", type: " << module << ")");
+ if (!query.Exec() || !query.Reset()) {
+ LOG4CXX_WARN(logger_, "Incorrect insert into module type.");
+ return false;
+ }
+ }
+ } else if (types.is_initialized()) {
query.Bind(0, app_id);
- std::string module(policy_table::EnumToJsonString(*it));
- query.Bind(1, module);
- LOG4CXX_DEBUG(logger_,
- "Module(app: " << app_id << ", type: " << module << ")");
+ query.Bind(1,
+ std::string(policy_table::EnumToJsonString(
+ policy_table::ModuleType::MT_EMPTY)));
if (!query.Exec() || !query.Reset()) {
- LOG4CXX_WARN(logger_, "Incorrect insert into module type.");
+ LOG4CXX_WARN(logger_, "Incorrect insert into module types.");
return false;
}
+ } else {
+ LOG4CXX_WARN(logger_, "Module Type omitted.");
}
-
return true;
}
@@ -1755,7 +1854,6 @@ bool SQLPTRepresentation::GatherRemoteRpc(
}
return true;
}
-#endif // SDL_REMOTE_CONTROL
bool SQLPTRepresentation::SaveApplicationCustomData(const std::string& app_id,
bool is_revoked,
@@ -1858,6 +1956,13 @@ bool SQLPTRepresentation::SetDefaultPolicy(const std::string& app_id) {
!SaveRequestType(app_id, request_types)) {
return false;
}
+
+ policy_table::Strings request_subtypes;
+ if (!GatherRequestSubType(kDefaultId, &request_subtypes) ||
+ !SaveRequestSubType(app_id, request_subtypes)) {
+ return false;
+ }
+
policy_table::AppHMITypes app_types;
if (!GatherAppType(kDefaultId, &app_types) ||
!SaveAppType(app_id, app_types)) {
diff --git a/src/components/policy/policy_regular/src/status.cc b/src/components/policy/policy_regular/src/status.cc
index 8d65c606d0..00a6a95af3 100644
--- a/src/components/policy/policy_regular/src/status.cc
+++ b/src/components/policy/policy_regular/src/status.cc
@@ -32,7 +32,6 @@
#include "policy/status.h"
#include "policy/update_status_manager_interface.h"
-#include "utils/make_shared.h"
policy::UpToDateStatus::UpToDateStatus()
: Status("UP_TO_DATE", policy::PolicyTableStatus::StatusUpToDate) {}
@@ -44,7 +43,7 @@ void policy::UpToDateStatus::ProcessEvent(UpdateStatusManagerInterface* manager,
case kOnResetPolicyTableRequireUpdate:
case kScheduleUpdate:
case kOnResetRetrySequence:
- manager->SetNextStatus(utils::MakeShared<UpdateNeededStatus>());
+ manager->SetNextStatus(std::make_shared<UpdateNeededStatus>());
break;
default:
break;
@@ -59,17 +58,17 @@ void policy::UpdateNeededStatus::ProcessEvent(
policy::UpdateStatusManagerInterface* manager, policy::UpdateEvent event) {
switch (event) {
case kOnUpdateSentOut:
- manager->SetNextStatus(utils::MakeShared<UpdatingStatus>());
+ manager->SetNextStatus(std::make_shared<UpdatingStatus>());
break;
case kOnResetPolicyTableRequireUpdate:
- manager->SetNextStatus(utils::MakeShared<UpToDateStatus>());
- manager->SetPostponedStatus(utils::MakeShared<UpdateNeededStatus>());
+ manager->SetNextStatus(std::make_shared<UpToDateStatus>());
+ manager->SetPostponedStatus(std::make_shared<UpdateNeededStatus>());
break;
case kOnResetPolicyTableNoUpdate:
- manager->SetNextStatus(utils::MakeShared<UpToDateStatus>());
+ manager->SetNextStatus(std::make_shared<UpToDateStatus>());
break;
case kOnNewAppRegistered:
- manager->SetNextStatus(utils::MakeShared<UpdateNeededStatus>());
+ manager->SetNextStatus(std::make_shared<UpdateNeededStatus>());
break;
default:
break;
@@ -88,22 +87,22 @@ void policy::UpdatingStatus::ProcessEvent(
switch (event) {
case kOnValidUpdateReceived:
case kOnResetPolicyTableNoUpdate:
- manager->SetNextStatus(utils::MakeShared<UpToDateStatus>());
+ manager->SetNextStatus(std::make_shared<UpToDateStatus>());
break;
case kOnNewAppRegistered:
- manager->SetPostponedStatus(utils::MakeShared<UpdateNeededStatus>());
+ manager->SetPostponedStatus(std::make_shared<UpdateNeededStatus>());
break;
case kOnWrongUpdateReceived:
case kOnUpdateTimeout:
- manager->SetNextStatus(utils::MakeShared<UpdateNeededStatus>());
+ manager->SetNextStatus(std::make_shared<UpdateNeededStatus>());
break;
case kOnResetPolicyTableRequireUpdate:
- manager->SetNextStatus(utils::MakeShared<UpToDateStatus>());
- manager->SetPostponedStatus(utils::MakeShared<UpdateNeededStatus>());
+ manager->SetNextStatus(std::make_shared<UpToDateStatus>());
+ manager->SetPostponedStatus(std::make_shared<UpdateNeededStatus>());
break;
case kScheduleUpdate:
case kOnResetRetrySequence:
- manager->SetPostponedStatus(utils::MakeShared<UpdateNeededStatus>());
+ manager->SetPostponedStatus(std::make_shared<UpdateNeededStatus>());
break;
default:
break;
diff --git a/src/components/policy/policy_regular/src/update_status_manager.cc b/src/components/policy/policy_regular/src/update_status_manager.cc
index 941113c753..c37f8bbadc 100644
--- a/src/components/policy/policy_regular/src/update_status_manager.cc
+++ b/src/components/policy/policy_regular/src/update_status_manager.cc
@@ -33,7 +33,6 @@
#include "policy/update_status_manager.h"
#include "policy/policy_listener.h"
#include "utils/logger.h"
-#include "utils/make_shared.h"
namespace policy {
@@ -41,7 +40,7 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "Policy")
UpdateStatusManager::UpdateStatusManager()
: listener_(NULL)
- , current_status_(utils::MakeShared<UpToDateStatus>())
+ , current_status_(std::make_shared<UpToDateStatus>())
, last_processed_event_(kNoEvent)
, apps_search_in_progress_(false)
, app_registered_from_non_consented_device_(true) {}
@@ -55,11 +54,11 @@ void UpdateStatusManager::ProcessEvent(UpdateEvent event) {
DoTransition();
}
-void UpdateStatusManager::SetNextStatus(utils::SharedPtr<Status> status) {
+void UpdateStatusManager::SetNextStatus(std::shared_ptr<Status> status) {
next_status_ = status;
}
-void UpdateStatusManager::SetPostponedStatus(utils::SharedPtr<Status> status) {
+void UpdateStatusManager::SetPostponedStatus(std::shared_ptr<Status> status) {
postponed_status_ = status;
}
@@ -101,6 +100,15 @@ void UpdateStatusManager::OnResetRetrySequence() {
ProcessEvent(kOnResetRetrySequence);
}
+void UpdateStatusManager::OnExistedApplicationAdded(
+ const bool is_update_required) {
+ LOG4CXX_AUTO_TRACE(logger_);
+ if (is_update_required) {
+ current_status_.reset(new UpToDateStatus());
+ ProcessEvent(kScheduleUpdate);
+ }
+}
+
void UpdateStatusManager::OnNewApplicationAdded(const DeviceConsent consent) {
LOG4CXX_AUTO_TRACE(logger_);
if (kDeviceAllowed != consent) {
@@ -111,14 +119,6 @@ void UpdateStatusManager::OnNewApplicationAdded(const DeviceConsent consent) {
ProcessEvent(kOnNewAppRegistered);
}
-void UpdateStatusManager::OnPolicyInit(bool is_update_required) {
- LOG4CXX_AUTO_TRACE(logger_);
- if (is_update_required) {
- current_status_.reset(new UpToDateStatus());
- ProcessEvent(kScheduleUpdate);
- }
-}
-
void UpdateStatusManager::OnDeviceConsented() {
LOG4CXX_AUTO_TRACE(logger_);
if (app_registered_from_non_consented_device_) {
diff --git a/src/components/policy/policy_regular/src/usage_statistics/counter.cc b/src/components/policy/policy_regular/src/usage_statistics/counter.cc
index 60e34a929d..ed16fa3e8d 100644
--- a/src/components/policy/policy_regular/src/usage_statistics/counter.cc
+++ b/src/components/policy/policy_regular/src/usage_statistics/counter.cc
@@ -36,13 +36,13 @@
#include <cassert>
#include "policy/usage_statistics/counter.h"
#include "utils/date_time.h"
-#include "utils/make_shared.h"
+
#include "utils/timer_task_impl.h"
namespace usage_statistics {
GlobalCounter::GlobalCounter(
- utils::SharedPtr<StatisticsManager> statistics_manager,
+ std::shared_ptr<StatisticsManager> statistics_manager,
GlobalCounterId counter_type)
: counter_type_(counter_type), statistics_manager_(statistics_manager) {}
@@ -52,7 +52,7 @@ void GlobalCounter::operator++() const {
}
}
-AppCounter::AppCounter(utils::SharedPtr<StatisticsManager> statistics_manager,
+AppCounter::AppCounter(std::shared_ptr<StatisticsManager> statistics_manager,
const std::string& app_id,
AppCounterId counter_type)
: app_id_(app_id)
@@ -65,7 +65,7 @@ void AppCounter::operator++() const {
}
}
-AppInfo::AppInfo(utils::SharedPtr<StatisticsManager> statistics_manager,
+AppInfo::AppInfo(std::shared_ptr<StatisticsManager> statistics_manager,
const std::string& app_id,
AppInfoId info_type)
: app_id_(app_id)
@@ -79,7 +79,7 @@ void AppInfo::Update(const std::string& new_info) const {
}
AppStopwatchImpl::AppStopwatchImpl(
- utils::SharedPtr<StatisticsManager> statistics_manager,
+ std::shared_ptr<StatisticsManager> statistics_manager,
const std::string& app_id)
: app_id_(app_id)
, stopwatch_type_(SECONDS_HMI_NONE)
@@ -90,7 +90,7 @@ AppStopwatchImpl::AppStopwatchImpl(
, time_out_(60) {}
AppStopwatchImpl::AppStopwatchImpl(
- utils::SharedPtr<StatisticsManager> statistics_manager,
+ std::shared_ptr<StatisticsManager> statistics_manager,
const std::string& app_id,
uint32_t timeout)
: app_id_(app_id)
@@ -103,8 +103,7 @@ AppStopwatchImpl::AppStopwatchImpl(
void AppStopwatchImpl::Start(AppStopwatchId stopwatch_type) {
stopwatch_type_ = stopwatch_type;
- timer_.Start(time_out_ * date_time::DateTime::MILLISECONDS_IN_SECOND,
- timer::kPeriodic);
+ timer_.Start(time_out_ * date_time::MILLISECONDS_IN_SECOND, timer::kPeriodic);
}
void AppStopwatchImpl::Switch(AppStopwatchId stopwatch_type) {