summaryrefslogtreecommitdiff
path: root/src/components/policy/policy_external/include/policy/cache_manager.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/policy/policy_external/include/policy/cache_manager.h')
-rw-r--r--src/components/policy/policy_external/include/policy/cache_manager.h270
1 files changed, 227 insertions, 43 deletions
diff --git a/src/components/policy/policy_external/include/policy/cache_manager.h b/src/components/policy/policy_external/include/policy/cache_manager.h
index f41ddb14cd..b826f4e5ce 100644
--- a/src/components/policy/policy_external/include/policy/cache_manager.h
+++ b/src/components/policy/policy_external/include/policy/cache_manager.h
@@ -33,18 +33,19 @@
#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_CACHE_MANAGER_H_
#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_CACHE_MANAGER_H_
+#include <atomic>
#include <map>
+#include "boost/optional.hpp"
-#include "utils/shared_ptr.h"
-#include "policy/pt_representation.h"
+#include "policy/cache_manager_interface.h"
#include "policy/pt_ext_representation.h"
+#include "policy/pt_representation.h"
#include "policy/usage_statistics/statistics_manager.h"
-#include "policy/cache_manager_interface.h"
#include "utils/threads/thread.h"
#include "utils/threads/thread_delegate.h"
-#include "utils/lock.h"
#include "utils/conditional_variable.h"
+#include "utils/lock.h"
namespace policy {
class PolicySettings;
@@ -154,10 +155,114 @@ class CacheManager : public CacheManagerInterface {
*/
virtual bool SecondsBetweenRetries(std::vector<int>& seconds);
+ const boost::optional<bool> LockScreenDismissalEnabledState() const OVERRIDE;
+
+ const boost::optional<std::string> LockScreenDismissalWarningMessage(
+ const std::string& language) const OVERRIDE;
+
+ /**
+ * @brief Gets vehicle data items
+ * @return Structure with vehicle data items
+ */
+ virtual const std::vector<policy_table::VehicleDataItem> GetVehicleDataItems()
+ const OVERRIDE;
+
+ std::vector<policy_table::VehicleDataItem> GetRemovedVehicleDataItems()
+ const OVERRIDE;
+
+ /**
+ * @brief Gets copy of current policy table data
+ * @return policy_table as json object
+ */
+ virtual Json::Value GetPolicyTableData() const OVERRIDE;
+
+ /**
+ * @brief Get a list of enabled cloud applications
+ * @param enabled_apps List filled with the policy app id of each enabled
+ * cloud application
+ */
+ void GetEnabledCloudApps(
+ std::vector<std::string>& enabled_apps) const OVERRIDE;
+
+ /**
+ * @brief Get a list of enabled local applications
+ * @return enabled_apps List filled with the policy app id
+ * of each enabled local application
+ */
+ std::vector<std::string> GetEnabledLocalApps() const OVERRIDE;
+
+ bool GetAppProperties(const std::string& policy_app_id,
+ AppProperties& out_app_properties) const OVERRIDE;
+
+ /**
+ * Initializes a new cloud application with default policies
+ * Then adds cloud specific policies
+ * @param app_id application id
+ * @return true if success
+ */
+ virtual void InitCloudApp(const std::string& policy_app_id);
+
+ /**
+ * @brief Enable or disable a cloud application in the HMI
+ * @param enabled Cloud app enabled state
+ */
+ virtual void SetCloudAppEnabled(const std::string& policy_app_id,
+ const bool enabled);
+
+ /**
+ * @brief Set an app's auth token
+ * @param auth_token Cloud app authentication token
+ */
+ virtual void SetAppAuthToken(const std::string& policy_app_id,
+ const std::string& auth_token);
+
+ /**
+ * @brief Set a cloud app's transport type
+ * @param cloud_transport_type Cloud app transport type
+ */
+ virtual void SetAppCloudTransportType(
+ const std::string& policy_app_id,
+ const std::string& cloud_transport_type);
+
+ /**
+ * @brief Set a cloud app's endpoint url
+ * @param endpoint URL for websocket connection
+ */
+ virtual void SetAppEndpoint(const std::string& policy_app_id,
+ const std::string& endpoint);
+
+ /**
+ * @brief Set a cloud app's nicknames
+ * @param nicknames Nicknames for cloud app
+ */
+ virtual void SetAppNicknames(const std::string& policy_app_id,
+ const StringArray& nicknames);
+
/**
- * @brief Gets information about vehicle
+ * @brief Set the user preference for how a hybrid (cloud and mobile) app
+ * should be used
+ * @param hybrid_app_preference Hybrid app user preference
*/
- virtual const VehicleInfo GetVehicleInfo() const;
+ virtual void SetHybridAppPreference(const std::string& policy_app_id,
+ const std::string& hybrid_app_preference);
+
+ /**
+ * @brief Get app service parameters from the policy table
+ * @param policy_app_id Unique application id
+ * @param app_service_parameters Pointer to struct containing all app service
+ * information
+ */
+ virtual void GetAppServiceParameters(
+ const std::string& policy_app_id,
+ policy_table::AppServiceParameters* app_service_parameters) const;
+
+ /**
+ * @brief Check if an app can send unknown rpc requests to an app service
+ * provider
+ * @param policy_app_id Unique application id
+ */
+ virtual bool UnknownRPCPassthroughAllowed(
+ const std::string& policy_app_id) const;
/**
* @brief Allows to update 'vin' field in module_meta table.
@@ -182,26 +287,27 @@ class CacheManager : public CacheManagerInterface {
std::vector<UserFriendlyMessage> GetUserFriendlyMsg(
const std::vector<std::string>& msg_codes,
const std::string& language,
- const std::string& active_hmi_language);
+ const std::string& active_hmi_language) const;
/**
- * @brief GetLockScreenIcon allows to obtain lock screen icon url;
+ * @brief Get Icon Url used for showing a cloud apps icon before the intial
+ *registration
*
- * @return url which point to the resourse where lock screen icon could be
+ * @return url which point to the resourse where icon could be
*obtained.
*/
- virtual std::string GetLockScreenIconUrl() const;
+ virtual std::string GetIconUrl(const std::string& policy_app_id) const;
/**
* @brief Gets list of URL to send PTS to
* @param service_type If URLs for specific service are preset,
* return them otherwise default URLs.
*/
- virtual void GetUpdateUrls(const std::string& service_type,
- EndpointUrls& out_end_points);
+ void GetUpdateUrls(const std::string& service_type,
+ EndpointUrls& out_end_points) const OVERRIDE;
- virtual void GetUpdateUrls(const uint32_t service_type,
- EndpointUrls& out_end_points);
+ void GetUpdateUrls(const uint32_t service_type,
+ EndpointUrls& out_end_points) const OVERRIDE;
/**
* @brief Gets allowed number of notifications
@@ -232,7 +338,7 @@ class CacheManager : public CacheManagerInterface {
* device_info, statistics, excluding user messages
* @return Generated structure for obtaining Json string.
*/
- virtual utils::SharedPtr<policy_table::Table> GenerateSnapshot();
+ virtual std::shared_ptr<policy_table::Table> GenerateSnapshot();
/**
* Applies policy table to the current table
@@ -298,6 +404,12 @@ class CacheManager : public CacheManagerInterface {
bool GetFunctionalGroupings(policy_table::FunctionalGroupings& groups);
/**
+ * @brief Get policy app names from PT
+ * @return container of strings representing policy application names
+ */
+ const policy_table::Strings GetPolicyAppIDs() const OVERRIDE;
+
+ /**
* Checks if the application is represented in policy table
* @param app_id application id
* @return true if application is represented in policy table
@@ -688,39 +800,40 @@ class CacheManager : public CacheManagerInterface {
ExternalConsentStatus GetExternalConsentEntities() OVERRIDE;
/**
- * @brief Creates collection of ExternalConsent items known by current
- * functional
- * groupings and appropiate section
- * (disallowed_by_external_consent_entities_on/off) where
- * is item is being holded. If item is not found it's not included into
- * collection
- * @param status Current status containing collection of ExternalConsent items
- * @return Collection of ExternalConsent items mapped to list of groups with
- * section
- * marker where the item is found
- */
+ * @brief Creates collection of ExternalConsent items known by current
+ * functional
+ * groupings and appropiate section
+ * (disallowed_by_external_consent_entities_on/off) where
+ * is item is being holded. If item is not found it's not included into
+ * collection
+ * @param status Current status containing collection of ExternalConsent items
+ * @return Collection of ExternalConsent items mapped to list of groups with
+ * section
+ * marker where the item is found
+ */
GroupsByExternalConsentStatus GetGroupsWithSameEntities(
const ExternalConsentStatus& status) OVERRIDE;
/**
- * @brief Gets collection of links device-to-application from device_data
- * section of policy table if there any application records present, i.e. if
- * any specific user consent is present
- * @return Collection of device-to-application links
- */
+ * @brief Gets collection of links device-to-application from device_data
+ * section of policy table if there any application records present, i.e. if
+ * any specific user consent is present
+ * @return Collection of device-to-application links
+ */
std::map<std::string, std::string> GetKnownLinksFromPT() OVERRIDE;
/**
- * @brief Sets groups permissions affected by customer connectivity settings
- * entities status, i.e. groups assigned to particular application on
- * particular device which have same entities as current ExternalConsent status
- * @param permissions Groups permissions which result current ExternalConsent
- * status
- */
+ * @brief Sets groups permissions affected by customer connectivity settings
+ * entities status, i.e. groups assigned to particular application on
+ * particular device which have same entities as current ExternalConsent
+ * status
+ * @param permissions Groups permissions which result current ExternalConsent
+ * status
+ */
void SetExternalConsentForApp(const PermissionConsent& permissions) OVERRIDE;
#ifdef BUILD_TESTS
- utils::SharedPtr<policy_table::Table> GetPT() const {
+ std::shared_ptr<policy_table::Table> GetPT() const {
return pt_;
}
#endif
@@ -736,6 +849,14 @@ class CacheManager : public CacheManagerInterface {
void OnDeviceSwitching(const std::string& device_id_from,
const std::string& device_id_to) OVERRIDE;
+ /**
+ * @brief Method for separate standard vehicle data items from custom
+ * @param full vehicle data items during PTU
+ * @return array with only custom vehicle items
+ */
+ static policy_table::VehicleDataItems CollectCustomVDItems(
+ const policy_table::VehicleDataItems& vd_items);
+
private:
std::string currentDateTime();
struct AppHMITypeToString {
@@ -754,6 +875,24 @@ class CacheManager : public CacheManagerInterface {
*/
void CheckSnapshotInitialization();
+ /**
+ * @brief Calculates difference between two provided custom vehicle data items
+ * @param items_before list of vehicle data items before PTU was applied
+ * @param items_after list of vehicle data items after PTU was applied
+ * @return list with calculated difference or empty list if two input lists
+ * are equal
+ */
+ policy_table::VehicleDataItems CalculateCustomVdItemsDiff(
+ const policy_table::VehicleDataItems& items_before,
+ const policy_table::VehicleDataItems& items_after) const;
+
+ /**
+ * @brief Sets the custom vehicle data items
+ * @param removed_items list of vehicle data items to set
+ */
+ void SetRemovedCustomVdItems(
+ const policy_table::VehicleDataItems& removed_items);
+
void PersistData();
/**
@@ -781,16 +920,27 @@ class CacheManager : public CacheManagerInterface {
const std::string& policy_app_id,
policy::Permissions& permission);
+ EncryptionRequired GetAppEncryptionRequiredFlag(
+ const std::string& application_policy_name) const OVERRIDE;
+
+ EncryptionRequired GetFunctionalGroupingEncryptionRequiredFlag(
+ const std::string& functional_group) const OVERRIDE;
+
+ void GetApplicationParams(
+ const std::string& application_name,
+ policy_table::ApplicationParams& application_policies) const OVERRIDE;
+
private:
- utils::SharedPtr<policy_table::Table> pt_;
- utils::SharedPtr<policy_table::Table> snapshot_;
- utils::SharedPtr<PTRepresentation> backup_;
- utils::SharedPtr<PTExtRepresentation> ex_backup_;
+ std::shared_ptr<policy_table::Table> pt_;
+ std::shared_ptr<policy_table::Table> snapshot_;
+ std::shared_ptr<PTRepresentation> backup_;
+ std::shared_ptr<PTExtRepresentation> ex_backup_;
bool update_required;
typedef std::set<std::string> UnpairedDevices;
UnpairedDevices is_unpaired_;
+ policy_table::VehicleDataItems removed_custom_vd_items_;
- mutable sync_primitives::Lock cache_lock_;
+ mutable sync_primitives::RecursiveLock cache_lock_;
sync_primitives::Lock unpaired_lock_;
typedef std::map<std::string, Permissions> AppCalculatedPermissions;
@@ -910,6 +1060,24 @@ class CacheManager : public CacheManagerInterface {
void MergeCFM(const policy_table::PolicyTable& new_pt,
policy_table::PolicyTable& pt);
+ /**
+ * @brief MergeVD allows to merge VehicleDataItems section by
+ *definite rules.
+ *
+ * The rules are:
+ * 1. If vehicle_data_items key is not presented in the updated PolicyTable,
+ * update for VehicleDataItems should be ignored.
+ * 2. If vehicle_data_items presented in updated PolicyTable, the
+ * VehicleDataItems in the database (LocalPT) should be overwritten with
+ * updated data.
+ *
+ * @param new_pt the policy table loaded from updated preload JSON file.
+ *
+ * @param pt the exists database
+ */
+ void MergeVD(const policy_table::PolicyTable& new_pt,
+ policy_table::PolicyTable& pt);
+
void InitBackupThread();
/**
@@ -940,12 +1108,28 @@ class CacheManager : public CacheManagerInterface {
~BackgroundBackuper();
virtual void threadMain();
virtual void exitThreadMain();
+
+ /**
+ * @brief Notifies BackgroundBackuper thread that new data is available and
+ * new backup iteration should be scheduled
+ */
void DoBackup();
+ /**
+ * @brief Waits for BackgroundBackuper thread finish its own backup
+ * iteration. If currently no backup iteration in progress - function just
+ * returns the control back
+ */
+ void WaitForBackupIsDone();
+
private:
void InternalBackup();
CacheManager* cache_manager_;
sync_primitives::ConditionalVariable backup_notifier_;
+ sync_primitives::ConditionalVariable backup_done_;
+ sync_primitives::Lock backup_done_lock_;
+
+ std::atomic_bool backup_is_in_progress_;
volatile bool stop_flag_;
volatile bool new_data_available_;