summaryrefslogtreecommitdiff
path: root/src/components/policy/policy_external/include/policy
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/policy/policy_external/include/policy')
-rw-r--r--src/components/policy/policy_external/include/policy/cache_manager.h919
-rw-r--r--src/components/policy/policy_external/include/policy/cache_manager_interface.h794
-rw-r--r--src/components/policy/policy_external/include/policy/policy_helper.h328
-rw-r--r--src/components/policy/policy_external/include/policy/policy_manager_impl.h508
-rw-r--r--src/components/policy/policy_external/include/policy/policy_table.h62
-rw-r--r--src/components/policy/policy_external/include/policy/policy_table/enums.h178
-rw-r--r--src/components/policy/policy_external/include/policy/policy_table/functions.h39
-rw-r--r--src/components/policy/policy_external/include/policy/policy_table/types.h583
-rw-r--r--src/components/policy/policy_external/include/policy/policy_table_interface_ext.xml284
-rw-r--r--src/components/policy/policy_external/include/policy/policy_types.h507
-rw-r--r--src/components/policy/policy_external/include/policy/pt_ext_representation.h347
-rw-r--r--src/components/policy/policy_external/include/policy/pt_representation.h328
-rw-r--r--src/components/policy/policy_external/include/policy/sql_pt_ext_queries.h104
-rw-r--r--src/components/policy/policy_external/include/policy/sql_pt_ext_representation.h218
-rw-r--r--src/components/policy/policy_external/include/policy/sql_pt_queries.h148
-rw-r--r--src/components/policy/policy_external/include/policy/sql_pt_representation.h211
-rw-r--r--src/components/policy/policy_external/include/policy/sql_wrapper.h45
-rw-r--r--src/components/policy/policy_external/include/policy/status.h195
-rw-r--r--src/components/policy/policy_external/include/policy/update_status_manager.h240
-rw-r--r--src/components/policy/policy_external/include/policy/usage_statistics/counter.h108
-rw-r--r--src/components/policy/policy_external/include/policy/user_consent_manager.h44
21 files changed, 6190 insertions, 0 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
new file mode 100644
index 0000000000..95aed36f89
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/cache_manager.h
@@ -0,0 +1,919 @@
+/*
+ * Copyright (c) 2016, 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_CACHE_MANAGER_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_CACHE_MANAGER_H_
+
+#include <map>
+
+#include "utils/shared_ptr.h"
+#include "policy/pt_representation.h"
+#include "policy/pt_ext_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"
+
+namespace policy {
+class PolicySettings;
+
+class CacheManager : public CacheManagerInterface {
+ public:
+ CacheManager();
+ explicit CacheManager(bool in_memory);
+ ~CacheManager();
+
+ /**
+ * @brief GetConsentsPriority provides priority for group consents
+ * i.e. which consents take priority for group - user consent or external
+ * consent based on timestamps
+ * @param device_id Device id
+ * @param application_id Application id
+ * @return Container with group consents priorities
+ */
+ ConsentPriorityType GetConsentsPriority(
+ const std::string& device_id, const std::string& application_id) const;
+
+ const policy_table::Strings& GetGroups(const PTString& app_id);
+
+ /**
+ * @brief Checks if specified RPC for specified application
+ * has permission to be executed in specified HMI Level
+ * and also its permitted params.
+ * @param app_id Id of application provided during registration
+ * @param hmi_level Current HMI Level of application
+ * @param rpc Name of RPC
+ * @return CheckPermissionResult containing flag if HMI Level is allowed
+ * and list of allowed params.
+ */
+ virtual void CheckPermissions(const PTString& app_id,
+ const PTString& hmi_level,
+ const PTString& rpc,
+ CheckPermissionResult& result);
+
+ /**
+ * @brief Returns true if Policy Table was not updated yet
+ * from preloaded pt file.
+ */
+ virtual bool IsPTPreloaded();
+
+ /**
+ * Gets number of ignition cycles before next update policy table
+ * @return number of ignition cycles
+ */
+ virtual int IgnitionCyclesBeforeExchange();
+
+ /**
+ * Gets value in kilometers before next update policy table
+ * @param current value in kilometers from the odometers
+ * @return value in kilometers
+ */
+ virtual int KilometersBeforeExchange(int current);
+
+ /**
+ * @brief Sets counter value that passed for recieved successful PT UPdate
+ */
+ virtual bool SetCountersPassedForSuccessfulUpdate(Counters counter,
+ int value);
+
+ /**
+ * Gets value in days before next update policy table
+ * @param current value in days after epoch
+ * @return value in days
+ */
+ virtual int DaysBeforeExchange(uint16_t current);
+
+ /**
+ * @brief Increments number of ignition cycles since last exchange by 1
+ */
+ virtual void IncrementIgnitionCycles();
+
+ /**
+ * @brief Resets number of ignition cycles since last exchange to 0
+ */
+ virtual void ResetIgnitionCycles();
+
+ /**
+ * @brief Returns timeout to wait for a response of PT update
+ * @return value in seconds
+ */
+ virtual int TimeoutResponse();
+
+ /**
+ * @brief Returns number of seconds between each try of sending PTS
+ * @param seconds Return value: array of 5 elements
+ * @return bool Success of operation
+ */
+ virtual bool SecondsBetweenRetries(std::vector<int>& seconds);
+
+ /**
+ * @brief Gets information about vehicle
+ */
+ virtual const VehicleInfo GetVehicleInfo() const;
+
+ /**
+ * @brief Allows to update 'vin' field in module_meta table.
+ *
+ * @param new 'vin' value.
+ *
+ * @return true in case when data has been successfully updated,
+ * false otherwise.
+ */
+ bool SetVINValue(const std::string& value);
+
+ /**
+ * @brief Gets message text for displaying/pronouncing for user
+ * dependent on language and context.
+ * @param msg_codes Context of message (Driver distraction, Grant permission
+ * etc)
+ * @param language Requested language of the message
+ * @param active_hmi_language Last language has been received
+ * via UI.GetLanguage (used as first fallback language)
+ * @return Array of appropriate messages parameters
+ */
+ std::vector<UserFriendlyMessage> GetUserFriendlyMsg(
+ const std::vector<std::string>& msg_codes,
+ const std::string& language,
+ const std::string& active_hmi_language);
+
+ /**
+ * @brief GetLockScreenIcon allows to obtain lock screen icon url;
+ *
+ * @return url which point to the resourse where lock screen icon could be
+ *obtained.
+ */
+ virtual std::string GetLockScreenIconUrl() 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);
+
+ virtual void GetUpdateUrls(const uint32_t service_type,
+ EndpointUrls& out_end_points);
+
+ /**
+ * @brief Gets allowed number of notifications
+ * depending on application priority.
+ * @param priority Priority of application
+ */
+ virtual rpc::policy_table_interface_base::NumberOfNotificationsType
+ GetNotificationsNumber(const std::string& priority);
+
+ /**
+ * @brief Gets priority for given application
+ * @param policy_app_id Unique application id
+ * @param priority Priority for application or empty, if value was not set
+ * @return true, if succedeed, otherwise - false
+ */
+ virtual bool GetPriority(const std::string& policy_app_id,
+ std::string& priority) const OVERRIDE;
+
+ /**
+ * @brief Initialized Policy Table (load)
+ * @return bool Success of operation
+ */
+ bool Init(const std::string& file_name, const PolicySettings* settings);
+
+ /**
+ * @brief Gets snapshot of Policy Table
+ * including app_policies, functional_groups,
+ * device_info, statistics, excluding user messages
+ * @return Generated structure for obtaining Json string.
+ */
+ virtual utils::SharedPtr<policy_table::Table> GenerateSnapshot();
+
+ /**
+ * Applies policy table to the current table
+ * @param update_pt policy table
+ * @return true if successfully
+ */
+ bool ApplyUpdate(const policy_table::Table& update_pt);
+
+ /**
+ * @brief Gets list of appHMIType associated with mobile appID
+ * @param container of appHMIType
+ */
+ virtual void GetHMIAppTypeAfterUpdate(
+ std::map<std::string, StringArray>& app_hmi_types);
+
+ /**
+ * @brief AppHasHMIType checks whether app has been registered with certain
+ *HMI type.
+ *
+ * @return true in case app contains certain HMI type, false otherwise.
+ */
+ virtual bool AppHasHMIType(const std::string& application_id,
+ policy_table::AppHMIType hmi_type) const;
+
+ /**
+ * Gets flag updateRequired
+ * @return true if update is required
+ */
+ bool UpdateRequired() const;
+
+ /**
+ * @brief Saves flag updateRequired
+ * @param status update status if true then update required.
+ */
+ void SaveUpdateRequired(bool status);
+
+ /**
+ * @brief GetInitialAppData Retrieves data from app_policies
+ * about app on its registration
+ * @param app_id id of registered app.
+ * All outputs are filled in only if not null
+ * @param nicknames Synonyms for application
+ * @param app_hmi_types app_types Section on HMI where app can
+ * appear (Navigation, Phone etc)
+ * @return true in case initial application data was obtained successfuly.
+ */
+ bool GetInitialAppData(const std::string& app_id,
+ StringArray& nicknames,
+ StringArray& app_hmi_types);
+
+ /**
+ * Checks if the application is revoked
+ * @param app_id application id
+ * @return true if application is revoked
+ */
+ bool IsApplicationRevoked(const std::string& app_id) const;
+
+ /**
+ * @brief Gets functional groupings from DB
+ * @param groups Known functional groupings
+ * @return true, if succeeded, otherwise - false
+ */
+ bool GetFunctionalGroupings(policy_table::FunctionalGroupings& groups);
+
+ /**
+ * Checks if the application is represented in policy table
+ * @param app_id application id
+ * @return true if application is represented in policy table
+ */
+ bool IsApplicationRepresented(const std::string& app_id) const;
+
+ /**
+ * Checks if the application has default policy
+ * @param app_id application id
+ * @return true if application has default policy
+ */
+ bool IsDefaultPolicy(const std::string& app_id) const OVERRIDE;
+
+ /**
+ * @brief SetIsDefault Sets is_default flag for application
+ * @param app_id app specific application
+ * @return true in case opperation was done successfully.
+ */
+ bool SetIsDefault(const std::string& app_id);
+
+ /**
+ * @brief SetIsPredata Sets is_predata flag for application
+ * @param app_id app specific application
+ * @return true in case opperation was done successfully.
+ */
+ bool SetIsPredata(const std::string& app_id);
+
+ /**
+ * Checks if the application has pre_data policy
+ * @param app_id application id
+ * @return true if application has pre_data policy
+ */
+ bool IsPredataPolicy(const std::string& app_id) const OVERRIDE;
+
+ /**
+ * Sets default policy for application
+ * @param app_id application id
+ * @return true if success
+ */
+ bool SetDefaultPolicy(const std::string& app_id);
+
+ /**
+ * @brief Is application allowed to send notifications while in
+ * Backgound or limited mode.
+ * @param app_id Application id
+ * @return bool Allowed/disallowed.
+ */
+ bool CanAppKeepContext(const std::string& app_id) const OVERRIDE;
+
+ /**
+ * @brief Is application allowed to move foreground at will?
+ * @param app_id Application id
+ * @return bool Allowed/disallowed.
+ */
+ bool CanAppStealFocus(const std::string& app_id) const;
+
+ /**
+ * @brief Gets default_hmi for given application
+ * @param policy_app_id Unique application id
+ * @param default_hmi Default HMI level for application or empty, if value was
+ * not set
+ * @return true, if succedeed, otherwise - false
+ */
+ bool GetDefaultHMI(const std::string& app_id, std::string& default_hmi) const;
+
+ /**
+ * Gets HMI types from specific policy
+ * @param app_id ID application
+ * @return list of HMI types
+ */
+ const policy_table::AppHMITypes* GetHMITypes(const std::string& app_id);
+
+ /**
+ * @brief Allows to generate hash from the specified string.
+ * The djb2 algorithm uses for hash generation.
+ * @param str_to_hash - the string from which hash should be generated.
+ * @return integer hash for the specified string.
+ */
+ static int32_t GenerateHash(const std::string& str_to_hash);
+
+ /**
+ * @brief Resets user consent for device data and applications permissions
+ * @return
+ */
+ bool ResetUserConsent();
+
+ /**
+ * @brief Gets user permissions for device data usage
+ * @param device_id Generated or obtained id of device
+ * @param consented_groups Groups consented by user
+ * @param disallowed_groups Groups not consented by user
+ * @return true, if query was successfull, otherwise - false
+ */
+ bool GetUserPermissionsForDevice(const std::string& device_id,
+ StringArray& consented_groups,
+ StringArray& disallowed_groups) const;
+
+ /**
+ * @brief Gets list of groups permissions from policy table
+ * @param device_id Unique device id, which hosts specific application
+ * @param policy_app_id Unique application id
+ * @param group_types Group list sorted by permission status
+ * @return true, if query was successfull, otherwise - false
+ */
+ bool GetPermissionsForApp(const std::string& device_id,
+ const std::string& app_id,
+ FunctionalIdType& group_types);
+
+ /**
+ * @brief Gets device groups and preconsented groups from policies section
+ * @param groups List of groups to be consented for device usage
+ * @param preconsented_groups List of preconsented groups for device usage
+ * @return true, if query was successful, otherwise - false
+ */
+ bool GetDeviceGroupsFromPolicies(
+ rpc::policy_table_interface_base::Strings& groups,
+ rpc::policy_table_interface_base::Strings& preconsented_groups) const;
+
+ /**
+ * @brief Adds information about mobile device in Policy Table.
+ * @param device_id Generated or obtained id of device
+ * @param connection_type device connection type
+ * @return bool Success of operation
+ */
+ bool AddDevice(const std::string& device_id,
+ const std::string& connection_type);
+
+ /**
+ * @brief Records information about mobile device in Policy Table.
+ * @param device_id Generated or obtained id of device
+ * @return bool Success of operation
+ */
+ bool 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 = 0,
+ const std::string& connection_type = "");
+
+ /**
+ * @brief Sets user consent for particular mobile device,
+ * i.e. to use device for exchanging of Policy Table.
+ * @return bool Success of operation
+ */
+ bool SetUserPermissionsForDevice(
+ const std::string& device_id,
+ const StringArray& consented_groups = StringArray(),
+ const StringArray& disallowed_groups = StringArray());
+
+ /**
+ * @brief Checks if particular mobile device has user consent in cache
+ * @return bool Suceess, if has, otherwise - false
+ */
+ bool IsDeviceConsentCached(const std::string& device_id) const;
+ /**
+ * @brief Update Application Policies as reaction
+ * on User allowing/disallowing device this app is running on.
+ */
+
+ /**
+ * @brief Gets user consent for particular mobile device
+ * @return actual consent for device
+ */
+ DeviceConsent GetDeviceConsent(const std::string& device_id) const OVERRIDE;
+
+ /**
+ * @brief Sets user consent for particular mobile device
+ */
+ void SetDeviceConsent(const std::string& device_id,
+ const bool is_allowed) OVERRIDE;
+
+ bool ReactOnUserDevConsentForApp(const std::string& app_id,
+ bool is_device_allowed);
+
+ /**
+ * @brief Set user consent on functional groups
+ * @param permissions User consent on functional group
+ * @param out_app_permissions_changed Indicates whether the permissions were
+ * changed
+ * @return true, if operation succedeed, otherwise - false
+ */
+ bool SetUserPermissionsForApp(const PermissionConsent& permissions,
+ bool* out_app_permissions_changed);
+
+ /**
+ * @brief Records information about head unit system to PT
+ * @return bool Success of operation
+ */
+ bool SetMetaInfo(const std::string& ccpu_version,
+ const std::string& wers_country_code,
+ const std::string& language);
+
+ /**
+ * @brief Checks, if specific head unit is present in PT
+ * @return boot Suceess, if present, otherwise - false
+ */
+ bool IsMetaInfoPresent() const;
+
+ /**
+ * @brief Set current system language
+ * @param language System language
+ * @return true, if succedeed, otherwise - false
+ */
+ bool SetSystemLanguage(const std::string& language);
+
+ /**
+ * Increments global counter
+ * @param type type of counter
+ */
+ void Increment(usage_statistics::GlobalCounterId type);
+
+ /**
+ * Increments counter of application
+ * @param app_id id application
+ * @param type type of counter
+ */
+ void Increment(const std::string& app_id,
+ usage_statistics::AppCounterId type);
+
+ /**
+ * Sets value of application information
+ * @param app_id id application
+ * @param type type of information
+ * @param value value of information
+ */
+ void Set(const std::string& app_id,
+ usage_statistics::AppInfoId type,
+ const std::string& value);
+
+ /**
+ * Adds value to stopwatch of application
+ * @param app_id id application
+ * @param type type of stopwatch
+ * @param seconds value for adding in seconds
+ */
+ void Add(const std::string& app_id,
+ usage_statistics::AppStopwatchId type,
+ int seconds);
+
+ /**
+ * @brief CountUnconsentedGroups allows to obtain the count of unconsented
+ * groups for specific application.
+ * @param policy_app_id application id.
+ * @param device_id device id.
+ * @return the count of unconsented groups
+ */
+ int CountUnconsentedGroups(const std::string& policy_app_id,
+ const std::string& device_id);
+
+ /**
+ * @brief Gets functional group names and user_consent_prompts, if any
+ * @param Array to be filled with group ids, names and functional prompts
+ * @return true, if succeeded, otherwise - false
+ */
+ bool GetFunctionalGroupNames(FunctionalGroupNames& names);
+
+ /**
+ * @brief GetAllAppGroups allows to obtain all groups for certain application.
+ * @param app_id specific application id.
+ * @param all_group_ids parameter to fill.
+ */
+ void GetAllAppGroups(const std::string& app_id,
+ FunctionalGroupIDs& all_group_ids);
+ /**
+ * @brief GetPreConsentedGroups allows to obtain all pre-consented groups for
+ * specific application.
+ * @param app_id specific application id.
+ * @param preconsented_groups parameter to fill.
+ */
+ void GetPreConsentedGroups(const std::string& app_id,
+ FunctionalGroupIDs& preconsented_groups);
+ /**
+ * @brief GetConsentedGroups allows to obtain list of allowed and disallowed
+ * groups for specific application on certain device.
+ * @param device_id certain device
+ * @param app_id application id.
+ * @param allowed_groups list of allowed groups
+ * @param disallowed_groups list of disallowed groups
+ */
+ void GetConsentedGroups(const std::string& device_id,
+ const std::string& app_id,
+ FunctionalGroupIDs& allowed_groups,
+ FunctionalGroupIDs& disallowed_groups);
+
+ /**
+ * @brief GetUnconsentedGroups allows to obtain list of allowed and disallowed
+ * groups for specific application on certain device.
+ * @param device_id certain device
+ * @param policy_app_id application id.
+ * @param unconsented_groups list of unconsented groups.
+ */
+ void GetUnconsentedGroups(const std::string& device_id,
+ const std::string& policy_app_id,
+ FunctionalGroupIDs& unconsented_groups);
+
+ void RemoveAppConsentForGroup(const std::string& app_id,
+ const std::string& group_name);
+
+ /**
+ * @brief Set app policy to pre_DataConsented policy
+ * @param app_id Policy ID of application to be changed
+ * @return true, if succeeded, otherwise - false
+ */
+ bool SetPredataPolicy(const std::string& app_id);
+
+ /**
+ * @brief Removes unpaired devices
+ * @return true if success
+ */
+ bool CleanupUnpairedDevices();
+
+ /**
+ * Sets flag of unpaired device
+ * @param device_id Unique device id
+ * @param unpaired True, if should be marked as unpaired, otherwise - false
+ * @return true if success
+ */
+ bool SetUnpairedDevice(const std::string& device_id, bool unpaired = true);
+
+ /**
+ * Resets Policy Table
+ * @param file_name Path to preloaded PT file
+ * @return true if successfully
+ */
+ bool ResetPT(const std::string& file_name);
+
+ /**
+ * @brief LoadFromBackup allows to load policy into the cache from backup.
+ * @return true in case operation was successful.
+ */
+ bool LoadFromBackup();
+
+ /**
+ * @brief LoadFromFile allows to load policy cache from preloaded table.
+ * @param file_name preloaded
+ * @param table object which will be filled during file parsing.
+ * @return true in case file was successfuly loaded, false otherwise.
+ */
+ bool LoadFromFile(const std::string& file_name, policy_table::Table& table);
+
+ /**
+ * @brief Backup allows to save cache onto hard drive.
+ */
+ void Backup();
+
+ /**
+ * Returns heart beat timeout
+ * @param app_id application id
+ * @return if timeout was set then value in milliseconds greater zero
+ * otherwise heart beat for specific application isn't set
+ */
+ uint32_t HeartBeatTimeout(const std::string& app_id) const;
+
+ /**
+ * @brief Gets request types for application
+ * @param policy_app_id Unique application id
+ * @param request_types Request types of application
+ */
+ void GetAppRequestTypes(const std::string& policy_app_id,
+ std::vector<std::string>& request_types) const;
+
+ virtual const MetaInfo GetMetaInfo() const OVERRIDE;
+
+ /**
+ * @brief GetCertificate allows to obtain certificate in order to
+ * make secure connection
+ *
+ * @return The certificate in PKCS#7.
+ */
+ virtual std::string GetCertificate() const OVERRIDE;
+
+ virtual void SetDecryptedCertificate(const std::string& certificate) OVERRIDE;
+
+ bool SetExternalConsentStatus(const ExternalConsentStatus& status) OVERRIDE;
+ ExternalConsentStatus GetExternalConsentStatus() OVERRIDE;
+ 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
+ */
+ 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
+ */
+ 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
+ */
+ void SetExternalConsentForApp(const PermissionConsent& permissions) OVERRIDE;
+
+#ifdef BUILD_TESTS
+ utils::SharedPtr<policy_table::Table> GetPT() const {
+ return pt_;
+ }
+#endif
+
+ const PolicySettings& get_settings() const;
+
+ private:
+ std::string currentDateTime();
+ struct AppHMITypeToString {
+ std::string operator()(rpc::Enum<policy_table::AppHMIType> value) {
+ return std::string(policy_table::EnumToJsonString(value));
+ }
+ };
+
+ void GetGroupNameByHashID(const int32_t group_id, std::string& group_name);
+ void FillDeviceSpecificData();
+ long ConvertSecondsToMinute(int seconds);
+
+ /**
+ * @brief Checks snapshot initialization and initializes to default values, if
+ * necessary
+ */
+ void CheckSnapshotInitialization();
+
+ void PersistData();
+
+ /**
+ * @brief Resets all calculated permissions in cache
+ */
+ void ResetCalculatedPermissions();
+
+ /**
+ * @brief Resets all calculated permissions for specified device in cache
+ */
+ void ResetCalculatedPermissionsForDevice(const std::string& device_id);
+
+ void AddCalculatedPermissions(const std::string& device_id,
+ const std::string& policy_app_id,
+ const policy::Permissions& permissions);
+
+ bool IsPermissionsCalculated(const std::string& device_id,
+ const std::string& policy_app_id,
+ policy::Permissions& permission);
+
+ private:
+ utils::SharedPtr<policy_table::Table> pt_;
+ utils::SharedPtr<policy_table::Table> snapshot_;
+ utils::SharedPtr<PTRepresentation> backup_;
+ utils::SharedPtr<PTExtRepresentation> ex_backup_;
+ bool update_required;
+ typedef std::set<std::string> UnpairedDevices;
+ UnpairedDevices is_unpaired_;
+
+ sync_primitives::Lock cache_lock_;
+ sync_primitives::Lock unpaired_lock_;
+
+ typedef std::map<std::string, Permissions> AppCalculatedPermissions;
+ typedef std::map<std::string, AppCalculatedPermissions> CalculatedPermissions;
+ typedef std::map<std::string, DeviceConsent> CachedDevicePermissions;
+ CalculatedPermissions calculated_permissions_;
+ CachedDevicePermissions cached_device_permissions_;
+ mutable sync_primitives::Lock cached_device_permissions_lock_;
+ sync_primitives::Lock calculated_permissions_lock_;
+
+ /**
+ * @brief MergePreloadPT allows to load policy table from certain JSON file,
+ * and then decide if merge is needed. The merge is needed in case when
+ *preload
+ * JSON date is different than current database.
+ *
+ * @param file_name the preloaded policy table JSON file.
+ * @return false in case of invalid preloaded_pt
+ */
+ bool MergePreloadPT(const std::string& file_name);
+
+ bool GetPermissionsList(StringArray& perm_list) const;
+
+ /**
+ * @brief Gets user consent from cache for particular mobile device
+ * @return actual consent for device
+ */
+ DeviceConsent GetCachedDeviceConsent(
+ const std::string& device_id) const OVERRIDE;
+
+ /**
+ * @brief Checks if specified device has specified consent
+ * @return True if consent for device is set, otherwise - false
+ */
+ bool HasDeviceSpecifiedConsent(const std::string& device_id,
+ const bool is_allowed) const OVERRIDE;
+
+ /**
+ * @brief Saves user consent to cache for particular mobile device
+ */
+ void SaveDeviceConsentToCache(const std::string& device_id,
+ const bool is_allowed);
+
+ /**
+ * @brief MergeMC allows to merge ModuleConfig section by definite rules.
+ *
+ * The rules are:
+ * 1. Add new fields (known to PoliciesManager) & sub-sections if such are
+ * present in the updated Preloaded PT
+ * 2. "vehicle_make", “model”, “year” – leave the fields & values as they were
+ * in the database
+ * 3. For all other fields – overwrite the values with the new ones from
+ *preloaded PT.
+ *
+ * @param new_pt the policy table loaded from updated preload JSON file.
+ *
+ * @param pt the exists database.
+ */
+ void MergeMC(const policy_table::PolicyTable& new_pt,
+ policy_table::PolicyTable& pt);
+
+ /**
+ * @brief MergeFG allows to merge FunctionalGroupings sections by definite
+ *rules.
+ *
+ * The rules are:
+ * 1. If functional_group_name exists in both database (LocalPT) and updated
+ * PreloadedPT -> PoliciesManager must overwrite it (that is, replace such
+ * functional_group_name in the database by the one from Pre-PT).
+ * 2. If functional_group_name exists in updated PreloadedPT and does not
+ * exist in database (LocalPT), PoliciesManager must add such group to the
+ *database.
+ * 3. If functional_group_name does not exist in updated PreloadedPT and
+ * exists in the database (LocalPT), PoliciesManager must leave such group in
+ * the database without changes.
+ *
+ * @param new_pt the policy table loaded from updated preload JSON file.
+ *
+ * @param pt the exists database.
+ */
+ void MergeFG(const policy_table::PolicyTable& new_pt,
+ policy_table::PolicyTable& pt);
+
+ /**
+ * @brief MergeAP Allows to merge ApplicationPolicies section by definite
+ *relues.
+ * The rules are:
+ * 1. Leave “<appID>” sub-sections as they were in the database (fields &
+ *their values).
+ * 2. Over-write "default", "device", "pre_DataConsent" subsections.
+ *
+ * @param new_pt the policy table loaded from updated preload JSON file.
+ *
+ * @param pt the exists database.
+ */
+ void MergeAP(const policy_table::PolicyTable& new_pt,
+ policy_table::PolicyTable& pt);
+
+ /**
+ * @brief MergeCFM allows to merge ConsumerFriendlyMessages section by
+ *definite rules.
+ *
+ * The rules are:
+ * 1. If friendly_message_name exists in both database (LocalPT) and updated
+ * Preloaded PT -> PoliciesManager must overwrite it.
+ * 2. If friendly_message_name exists in updated Preloaded PT and does not
+ * exist in database (LocalPT), PoliciesManager must add such
+ * friendly_message_name to the database (LocalPT).
+ * 3. If friendly_message_name does not exist in updated Preloaded PT and
+ * exists in the database (LocalPT), PoliciesManager must leave such
+ * friendly_message_name in the database without changes.
+ *
+ * @param new_pt the policy table loaded from updated preload JSON file.
+ *
+ * @param pt the exists database
+ */
+ void MergeCFM(const policy_table::PolicyTable& new_pt,
+ policy_table::PolicyTable& pt);
+
+ void InitBackupThread();
+
+ /**
+ * @brief Processes the PTU process by distinguishing the policy type.
+ * For the RequestType" array of "<default>" or "<pre_DataConsent>"
+ * rules are applied as described in APPLINK-14698
+ * @param initial_policy_iter Iterator to application policy to use for update
+ */
+ void ProcessUpdate(const policy_table::ApplicationPolicies::const_iterator
+ initial_policy_iter);
+
+ /**
+ * @brief ConsentsSame checks whether external consents contain
+ * same groups+consent combinations as permission groups
+ * @param external_consent_groups External consents
+ * @param permissions Permissions
+ * @return true if all values from permissions have been found in external
+ * consents container
+ */
+ bool ConsentsSame(const policy_table::ConsentGroups& external_consent_groups,
+ const PermissionConsent& permissions) const;
+
+ class BackgroundBackuper : public threads::ThreadDelegate {
+ friend class CacheManager;
+
+ public:
+ BackgroundBackuper(CacheManager* cache_manager);
+ ~BackgroundBackuper();
+ virtual void threadMain();
+ virtual void exitThreadMain();
+ void DoBackup();
+
+ private:
+ void InternalBackup();
+ CacheManager* cache_manager_;
+ sync_primitives::ConditionalVariable backup_notifier_;
+ volatile bool stop_flag_;
+ volatile bool new_data_available_;
+
+ sync_primitives::Lock need_backup_lock_;
+ DISALLOW_COPY_AND_ASSIGN(BackgroundBackuper);
+ };
+ threads::Thread* backup_thread_;
+ sync_primitives::Lock backuper_locker_;
+ BackgroundBackuper* backuper_;
+ const PolicySettings* settings_;
+};
+} // namespace policy
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_CACHE_MANAGER_H_
diff --git a/src/components/policy/policy_external/include/policy/cache_manager_interface.h b/src/components/policy/policy_external/include/policy/cache_manager_interface.h
new file mode 100644
index 0000000000..66631f32cf
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/cache_manager_interface.h
@@ -0,0 +1,794 @@
+/*
+ * Copyright (c) 2016, 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_CACHE_MANAGER_INTERFACE_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_CACHE_MANAGER_INTERFACE_H_
+
+#include <string>
+#include <vector>
+
+#include "utils/shared_ptr.h"
+#include "usage_statistics/counter.h"
+#include "policy/policy_types.h"
+#include "policy/policy_settings.h"
+
+namespace policy_table = rpc::policy_table_interface_base;
+
+namespace policy {
+
+class CacheManagerInterface {
+ public:
+ virtual ~CacheManagerInterface() {}
+
+ /**
+ * @brief GetConsentsPriority provides priorities for group consents
+ * i.e. which consents take priority for group - user consent or external
+ * consent based on timestamps
+ * @param device_id Device id
+ * @param application_id Application id
+ * @return Container with group consents priorities
+ */
+ virtual ConsentPriorityType GetConsentsPriority(
+ const std::string& device_id,
+ const std::string& application_id) const = 0;
+
+ virtual const policy_table::Strings& GetGroups(const PTString& app_id) = 0;
+
+ /**
+ * @brief Check if specified RPC for specified application
+ * has permission to be executed in specified HMI Level
+ * and also its permitted params.
+ * @param app_id Id of application provided during registration
+ * @param hmi_level Current HMI Level of application
+ * @param rpc Name of RPC
+ * @return CheckPermissionResult containing flag if HMI Level is allowed
+ * and list of allowed params.
+ */
+ virtual void CheckPermissions(const PTString& app_id,
+ const PTString& hmi_level,
+ const PTString& rpc,
+ CheckPermissionResult& result) = 0;
+
+ /**
+ * @brief Returns true if Policy Table was not updated yet
+ * from preloaded pt file.
+ */
+ virtual bool IsPTPreloaded() = 0;
+
+ /**
+ * Gets number of ignition cycles before next update policy table
+ * @return number of ignition cycles
+ */
+ virtual int IgnitionCyclesBeforeExchange() = 0;
+
+ /**
+ * Gets value in kilometers before next update policy table
+ * @param current value in kilometers from the odometers
+ * @return value in kilometers
+ */
+ virtual int KilometersBeforeExchange(int current) = 0;
+
+ /**
+ * @brief Sets counter value that passed for recieved successful PT UPdate
+ */
+ virtual bool SetCountersPassedForSuccessfulUpdate(Counters counter,
+ int value) = 0;
+
+ /**
+ * Gets value in days before next update policy table
+ * @param current value in days after epoch
+ * @return value in days
+ */
+ virtual int DaysBeforeExchange(uint16_t current) = 0;
+
+ /**
+ * @brief Increment number of ignition cycles since last exchange by 1
+ */
+ virtual void IncrementIgnitionCycles() = 0;
+
+ /**
+ * @brief Reset number of ignition cycles since last exchange to 0
+ */
+ virtual void ResetIgnitionCycles() = 0;
+
+ /**
+ * @brief Returns timeout to wait for a response of PT update
+ * @return value in seconds
+ */
+ virtual int TimeoutResponse() = 0;
+
+ /**
+ * @brief Returns number of seconds between each try of sending PTS
+ * @param seconds Return value: array of 5 elements
+ * @return bool Success of operation
+ */
+ virtual bool SecondsBetweenRetries(std::vector<int>& seconds) = 0;
+
+ /**
+ * @brief Get information about vehicle
+ */
+ virtual const VehicleInfo GetVehicleInfo() const = 0;
+
+ /**
+ * @brief Allows to update 'vin' field in module_meta table.
+ *
+ * @param new 'vin' value.
+ *
+ * @return true in case when data has been successfully updated,
+ * false otherwise.
+ */
+ virtual bool SetVINValue(const std::string& value) = 0;
+
+ /**
+ * @brief Get message text for displaying/pronouncing for user
+ * dependent on language and context.
+ * @param msg_codes Context of message (Driver distraction, Grant permission
+ * etc)
+ * @param language Language of the message
+ * @return Array of appropriate messages parameters
+ */
+ virtual std::vector<UserFriendlyMessage> GetUserFriendlyMsg(
+ const std::vector<std::string>& msg_codes,
+ const std::string& language,
+ const std::string& active_hmi_language) = 0;
+
+ /**
+ * @brief Get 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) = 0;
+
+ virtual void GetUpdateUrls(const uint32_t service_type,
+ EndpointUrls& out_end_points) = 0;
+
+ /**
+ * @brief GetLockScreenIcon allows to obtain lock screen icon url;
+ *
+ * @return url which point to the resourse where lock screen icon could be
+ *obtained.
+ */
+ virtual std::string GetLockScreenIconUrl() const = 0;
+
+ /**
+ * @brief Get allowed number of notifications
+ * depending on application priority.
+ * @param priority Priority of application
+ */
+ virtual policy_table::NumberOfNotificationsType GetNotificationsNumber(
+ const std::string& priority) = 0;
+
+ /**
+ * @brief Get priority for given application
+ * @param policy_app_id Unique application id
+ * @param priority Priority for application or empty, if value was not set
+ * @return true, if succedeed, otherwise - false
+ */
+ virtual bool GetPriority(const std::string& policy_app_id,
+ std::string& priority) const = 0;
+
+ /**
+ * @brief Initialized Policy Table (load)
+ * @return bool Success of operation
+ */
+ virtual bool Init(const std::string& file_name,
+ const PolicySettings* settings) = 0;
+
+ /**
+ * @brief Get snapshot of Policy Table
+ * including app_policies, functional_groups,
+ * device_info, statistics, excluding user messages
+ * @return Generated structure for obtaining Json string.
+ */
+ virtual utils::SharedPtr<policy_table::Table> GenerateSnapshot() = 0;
+
+ /**
+ * Applies policy table to the current table
+ * @param update_pt policy table
+ * @return true if successfully
+ */
+ virtual bool ApplyUpdate(const policy_table::Table& update_pt) = 0;
+
+ /**
+ * @brief Gets list of appHMIType associated with mobile appID
+ * @param container of appHMIType
+ */
+ virtual void GetHMIAppTypeAfterUpdate(
+ std::map<std::string, StringArray>& app_hmi_types) = 0;
+
+ /**
+ * @brief AppHasHMIType checks whether app has been registered with certain
+ *HMI type.
+ *
+ * @return true in case app contains certain HMI type, false otherwise.
+ */
+ virtual bool AppHasHMIType(const std::string& application_id,
+ policy_table::AppHMIType hmi_type) const = 0;
+
+ /**
+ * Gets flag updateRequired
+ * @return true if update is required
+ */
+ virtual bool UpdateRequired() const = 0;
+
+ /**
+ * @brief Saves flag updateRequired
+ * @param status update status if true then update required.
+ */
+ virtual void SaveUpdateRequired(bool status) = 0;
+
+ /**
+ * @brief GetInitialAppData Retrieves data from app_policies
+ * about app on its registration
+ * @param app_id id of registered app.
+ * All outputs are filled in only if not null
+ * @param nicknames Synonyms for application
+ * @param app_hmi_types app_types Section on HMI where app can
+ * appear (Navigation, Phone etc)
+ * @return true in case initial application data was obtained successfuly.
+ */
+ virtual bool GetInitialAppData(const std::string& app_id,
+ StringArray& nicknames,
+ StringArray& app_hmi_types) = 0;
+
+ /**
+ * Checks if the application is revoked
+ * @param app_id application id
+ * @return true if application is revoked
+ */
+ virtual bool IsApplicationRevoked(const std::string& app_id) const = 0;
+
+ /**
+ * @brief Get functional groupings from DB
+ * @param groups Known functional groupings
+ * @return true, if succeeded, otherwise - false
+ */
+ virtual bool GetFunctionalGroupings(
+ policy_table::FunctionalGroupings& groups) = 0;
+
+ /**
+ * Checks if the application is represented in policy table
+ * @param app_id application id
+ * @return true if application is represented in policy table
+ */
+ virtual bool IsApplicationRepresented(const std::string& app_id) const = 0;
+
+ /**
+ * Checks if the application has default policy
+ * @param app_id application id
+ * @return true if application has default policy
+ */
+ virtual bool IsDefaultPolicy(const std::string& app_id) const = 0;
+
+ /**
+ * @brief SetIsDefault Sets is_default flag for application
+ * @param app_id app specific application
+ * @return true in case opperation was done successfully.
+ */
+ virtual bool SetIsDefault(const std::string& app_id) = 0;
+
+ /**
+ * @brief SetIsPredata Sets is_predata flag for application
+ * @param app_id app specific application
+ * @return true in case opperation was done successfully.
+ */
+ virtual bool SetIsPredata(const std::string& app_id) = 0;
+
+ /**
+ * Checks if the application has pre_data policy
+ * @param app_id application id
+ * @return true if application has pre_data policy
+ */
+ virtual bool IsPredataPolicy(const std::string& app_id) const = 0;
+
+ /**
+ * Sets default policy for application
+ * @param app_id application id
+ * @return true if success
+ */
+ virtual bool SetDefaultPolicy(const std::string& app_id) = 0;
+
+ /**
+ * @brief Is application allowed to send notifications while in
+ * Backgound or limited mode.
+ * @param app_id Application id
+ * @return bool Allowed/disallowed.
+ */
+ virtual bool CanAppKeepContext(const std::string& app_id) const = 0;
+
+ /**
+ * @brief Is application allowed to move foreground at will?
+ * @param app_id Application id
+ * @return bool Allowed/disallowed.
+ */
+ virtual bool CanAppStealFocus(const std::string& app_id) const = 0;
+
+ /**
+ * @brief Get default_hmi for given application
+ * @param policy_app_id Unique application id
+ * @param default_hmi Default HMI level for application or empty, if value was
+ * not set
+ * @return true, if succedeed, otherwise - false
+ */
+ virtual bool GetDefaultHMI(const std::string& app_id,
+ std::string& default_hmi) const = 0;
+
+ /**
+ * Gets HMI types from specific policy
+ * @param app_id ID application
+ * @return list of HMI types
+ */
+ virtual const policy_table::AppHMITypes* GetHMITypes(
+ const std::string& app_id) = 0;
+
+ /**
+ * @brief Resets user consent for device data and applications permissions
+ * @return
+ */
+ virtual bool ResetUserConsent() = 0;
+
+ /**
+ * @brief Gets user permissions for device data usage
+ * @param device_id Generated or obtained id of device
+ * @param consented_groups Groups consented by user
+ * @param disallowed_groups Groups not consented by user
+ * @return true, if query was successfull, otherwise - false
+ */
+ virtual bool GetUserPermissionsForDevice(
+ const std::string& device_id,
+ StringArray& consented_groups,
+ StringArray& disallowed_groups) const = 0;
+
+ /**
+ * @brief Checks if particular mobile device has user consent in cache
+ * @return bool Suceess, if has, otherwise - false
+ */
+ virtual bool IsDeviceConsentCached(const std::string& device_id) const = 0;
+
+ /**
+ * @brief Gets permissions list for device data usage
+ * @param device_id Generated or obtained id of device
+ * @return true, if query was successfull, otherwise - false
+ */
+ virtual bool GetPermissionsList(StringArray& perm_list) const = 0;
+
+ /**
+ * @brief Checks if specified device has specified consent
+ * @return True if consent for device is set, otherwise - false
+ */
+ virtual bool HasDeviceSpecifiedConsent(const std::string& device_id,
+ const bool is_allowed) const = 0;
+
+ /**
+ * @brief Gets user consent for particular mobile device
+ * @return actual consent for device
+ */
+ virtual DeviceConsent GetDeviceConsent(
+ const std::string& device_id) const = 0;
+
+ /**
+ * @brief Sets user consent for particular mobile device
+ */
+ virtual void SetDeviceConsent(const std::string& device_id,
+ const bool is_allowed) = 0;
+
+ /**
+ * @brief Gets list of groups permissions from policy table
+ * @param device_id Unique device id, which hosts specific application
+ * @param policy_app_id Unique application id
+ * @param group_types Group list sorted by permission status
+ * @return true, if query was successfull, otherwise - false
+ */
+ virtual bool GetPermissionsForApp(const std::string& device_id,
+ const std::string& app_id,
+ FunctionalIdType& group_types) = 0;
+
+ /**
+ * @brief Gets device groups and preconsented groups from policies section
+ * @param groups List of groups to be consented for device usage
+ * @param preconsented_groups List of preconsented groups for device usage
+ * @return true, if query was successful, otherwise - false
+ */
+ virtual bool GetDeviceGroupsFromPolicies(
+ rpc::policy_table_interface_base::Strings& groups,
+ rpc::policy_table_interface_base::Strings& preconsented_groups) const = 0;
+
+ /**
+ * @brief Adds information about mobile device in Policy Table.
+ * @param device_id Generated or obtained id of device
+ * @param connection_type device connection type
+ * @return bool Success of operation
+ */
+ virtual bool AddDevice(const std::string& device_id,
+ const std::string& connection_type) = 0;
+
+ /**
+ * @brief Records information about mobile device in Policy Table.
+ * @param device_id Generated or obtained id of device
+ * @return bool Success of operation
+ */
+ virtual bool 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) = 0;
+
+ /**
+ * @brief Sets user consent for particular mobile device,
+ * i.e. to use device for exchanging of Policy Table.
+ * @return bool Success of operation
+ */
+ virtual bool SetUserPermissionsForDevice(
+ const std::string& device_id,
+ const StringArray& consented_groups,
+ const StringArray& disallowed_groups) = 0;
+
+ /**
+ * @brief Update Application Policies as reaction
+ * on User allowing/disallowing device this app is running on.
+ */
+ virtual bool ReactOnUserDevConsentForApp(const std::string& app_id,
+ bool is_device_allowed) = 0;
+
+ /**
+ * @brief Set user consent on functional groups
+ * @param permissions User consent on functional group
+ * @param out_app_permissions_changed Indicates whether the permissions were
+ * changed
+ * @return true, if operation succedeed, otherwise - false
+ */
+ virtual bool SetUserPermissionsForApp(const PermissionConsent& permissions,
+ bool* out_app_permissions_changed) = 0;
+
+ /**
+ * @brief Records information about head unit system to PT
+ * @return bool Success of operation
+ */
+ virtual bool SetMetaInfo(const std::string& ccpu_version,
+ const std::string& wers_country_code,
+ const std::string& language) = 0;
+
+ /**
+ * @brief Checks, if specific head unit is present in PT
+ * @return boot Suceess, if present, otherwise - false
+ */
+ virtual bool IsMetaInfoPresent() const = 0;
+
+ /**
+ * @brief Set current system language
+ * @param language System language
+ * @return true, if succedeed, otherwise - false
+ */
+ virtual bool SetSystemLanguage(const std::string& language) = 0;
+
+ /**
+ * Increments global counter
+ * @param type type of counter
+ */
+ virtual void Increment(usage_statistics::GlobalCounterId type) = 0;
+
+ /**
+ * Increments counter of application
+ * @param app_id id application
+ * @param type type of counter
+ */
+ virtual void Increment(const std::string& app_id,
+ usage_statistics::AppCounterId type) = 0;
+
+ /**
+ * Sets value of application information
+ * @param app_id id application
+ * @param type type of information
+ * @param value value of information
+ */
+ virtual void Set(const std::string& app_id,
+ usage_statistics::AppInfoId type,
+ const std::string& value) = 0;
+
+ /**
+ * Adds value to stopwatch of application
+ * @param app_id id application
+ * @param type type of stopwatch
+ * @param seconds value for adding in seconds
+ */
+ virtual void Add(const std::string& app_id,
+ usage_statistics::AppStopwatchId type,
+ int seconds) = 0;
+
+ /**
+ * @brief CountUnconsentedGroups allows to obtain the count of unconsented
+ * groups for specific application.
+ * @param policy_app_id application id.
+ * @param device_id device id.
+ * @param the count of unconsented groups
+ */
+ virtual int CountUnconsentedGroups(const std::string& policy_app_id,
+ const std::string& device_id) = 0;
+
+ /**
+ * @brief Gets user consent from cache for particular mobile device
+ * @return actual consent for device
+ */
+ virtual DeviceConsent GetCachedDeviceConsent(
+ const std::string& device_id) const = 0;
+
+ /**
+ * @brief Saves user consent to cache for particular mobile device
+ */
+ virtual void SaveDeviceConsentToCache(const std::string& device_id,
+ const bool is_allowed) = 0;
+
+ /**
+ * @brief Gets functional group names and user_consent_prompts, if any
+ * @param Array to be filled with group ids, names and functional prompts
+ * @return true, if succeeded, otherwise - false
+ */
+ virtual bool GetFunctionalGroupNames(FunctionalGroupNames& names) = 0;
+
+ /**
+ * @brief GetAllAppGroups allows to obtain all groups for certain application.
+ * @param app_id specific application id.
+ * @param all_group_ids parameter to fill.
+ */
+ virtual void GetAllAppGroups(const std::string& app_id,
+ FunctionalGroupIDs& all_group_ids) = 0;
+
+ /**
+ * @brief GetPreConsentedGroups allows to obtain all pre-consented groups for
+ * specific application.
+ * @param app_id specific application id.
+ * @param preconsented_groups parameter to fill.
+ */
+ virtual void GetPreConsentedGroups(
+ const std::string& app_id, FunctionalGroupIDs& preconsented_groups) = 0;
+
+ /**
+ * @brief GetConsentedGroups allows to obtain list of allowed and disallowed
+ * groups for specific application on certain device.
+ * @param device_id certain device
+ * @param app_id application id.
+ * @param allowed_groups list of allowed groups
+ * @param disallowed_groups list of disallowed groups
+ */
+ virtual void GetConsentedGroups(const std::string& device_id,
+ const std::string& app_id,
+ FunctionalGroupIDs& allowed_groups,
+ FunctionalGroupIDs& disallowed_groups) = 0;
+
+ /**
+ * @brief GetUnconsentedGroups allows to obtain list of allowed and disallowed
+ * groups for specific application on certain device.
+ * @param device_id certain device
+ * @param policy_app_id application id.
+ * @param unconsented_groups list of unconsented groups.
+ */
+ virtual void GetUnconsentedGroups(const std::string& device_id,
+ const std::string& policy_app_id,
+ FunctionalGroupIDs& unconsented_groups) = 0;
+
+ virtual void RemoveAppConsentForGroup(const std::string& app_id,
+ const std::string& group_name) = 0;
+
+ /**
+ * @brief Set app policy to pre_DataConsented policy
+ * @param app_id Policy ID of application to be changed
+ * @return true, if succeeded, otherwise - false
+ */
+ virtual bool SetPredataPolicy(const std::string& app_id) = 0;
+
+ /**
+ * @brief Removes unpaired devices
+ * @return true if success
+ */
+ virtual bool CleanupUnpairedDevices() = 0;
+
+ /**
+ * Sets flag of unpaired device
+ * @param device_id Unique device id
+ * @param unpaired True, if should be marked as unpaired, otherwise - false
+ * @return true if success
+ */
+ virtual bool SetUnpairedDevice(const std::string& device_id,
+ bool unpaired = true) = 0;
+
+ /**
+ * Resets Policy Table
+ * @param file_name Path to preloaded PT file
+ * @return true if successfully
+ */
+ virtual bool ResetPT(const std::string& file_name) = 0;
+
+ /**
+ * @brief LoadFromBackup allows to load policy into the cache from backup.
+ * @return true in case operation was successful.
+ */
+ virtual bool LoadFromBackup() = 0;
+
+ /**
+ * @brief LoadFromFile allows to load policy cache from preloaded table.
+ * @param file_name preloaded
+ * @param table object which will be filled during file parsing.
+ * @return true in case file was successfuly loaded, false otherwise.
+ */
+ virtual bool LoadFromFile(const std::string& file_name,
+ policy_table::Table& table) = 0;
+
+ /**
+ * @brief Backup allows to save cache onto hard drive.
+ */
+ virtual void Backup() = 0;
+
+ /**
+ * Returns heart beat timeout
+ * @param app_id application id
+ * @return if timeout was set then value in milliseconds greater zero
+ * otherwise heart beat for specific application isn't set
+ */
+ virtual uint32_t HeartBeatTimeout(const std::string& app_id) const = 0;
+
+ /**
+ * @brief Resets all calculated permissions in cache
+ */
+ virtual void ResetCalculatedPermissions() = 0;
+
+ /**
+ * @brief Resets all calculated permissions for specified device in cache
+ */
+ virtual void ResetCalculatedPermissionsForDevice(
+ const std::string& device_id) = 0;
+
+ /**
+ * @brief Adds calculated permissions for specific app on particular device
+ * into cache
+ * @param device_id Device id
+ * @param policy_app_id Application id
+ * @param permissions Calculated permissions
+ */
+ virtual void AddCalculatedPermissions(
+ const std::string& device_id,
+ const std::string& policy_app_id,
+ const policy::Permissions& permissions) = 0;
+
+ /**
+ * @brief Checks if permissions calculated for specific app on particular
+ * device
+ * @param device_id Device id
+ * @param policy_app_id Application id
+ * @param permission Permissions to be filled, in case of presence in cache
+ * @return true if present, otherwise false
+ */
+ virtual bool IsPermissionsCalculated(const std::string& device_id,
+ const std::string& policy_app_id,
+ policy::Permissions& permission) = 0;
+
+ /**
+ * @brief Gets request types for application
+ * @param policy_app_id Unique application id
+ * @param request_types Request types of application
+ */
+ virtual void GetAppRequestTypes(
+ const std::string& policy_app_id,
+ std::vector<std::string>& request_types) const = 0;
+
+ /**
+ * @brief Gets meta information
+ * @return meta information
+ */
+ virtual const MetaInfo GetMetaInfo() const = 0;
+
+ /**
+ * @brief GetCertificate allows to obtain certificate in order to
+ * make secure connection
+ *
+ * @return The certificate in PKCS#7.
+ */
+ virtual std::string GetCertificate() const = 0;
+
+ /**
+ * @brief Sets decrypted certificate in policy table
+ * @param certificate content of certificate
+ */
+ virtual void SetDecryptedCertificate(const std::string& certificate) = 0;
+
+ /**
+ * @brief Saves customer connectivity settings status
+ * @param status external consent status
+ * @return true if succeeded, otherwise - false
+ */
+ virtual bool SetExternalConsentStatus(
+ const ExternalConsentStatus& status) = 0;
+
+ /**
+ * @brief Gets customer connectivity settings status
+ * @return external consent status
+ */
+ virtual ExternalConsentStatus GetExternalConsentStatus() = 0;
+
+ /**
+ * @brief Creates externalConsentStatus data structure from policy table
+ section "externalConsentStatus"
+ * @return ExternalConsentStatus data structure
+ */
+ virtual ExternalConsentStatus GetExternalConsentEntities() = 0;
+
+ /**
+ * @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
+ * @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
+ */
+ virtual GroupsByExternalConsentStatus GetGroupsWithSameEntities(
+ const ExternalConsentStatus& status) = 0;
+
+ /**
+ * @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
+ */
+ virtual std::map<std::string, std::string> GetKnownLinksFromPT() = 0;
+
+ /**
+ * @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
+ */
+ virtual void SetExternalConsentForApp(
+ const PermissionConsent& permissions) = 0;
+
+#ifdef BUILD_TESTS
+ /**
+ * @brief GetPT allows to obtain SharedPtr to PT.
+ * Used ONLY in Unit tests
+ * @return SharedPTR to PT
+ *
+ */
+ virtual utils::SharedPtr<policy_table::Table> GetPT() const = 0;
+#endif
+};
+
+typedef utils::SharedPtr<CacheManagerInterface> CacheManagerInterfaceSPtr;
+
+} // namespace policy
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_CACHE_MANAGER_INTERFACE_H_
diff --git a/src/components/policy/policy_external/include/policy/policy_helper.h b/src/components/policy/policy_external/include/policy/policy_helper.h
new file mode 100644
index 0000000000..10d6908b14
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/policy_helper.h
@@ -0,0 +1,328 @@
+/*
+ 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_HELPER_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_HELPER_H_
+
+#include "policy/policy_table/functions.h"
+#include "utils/shared_ptr.h"
+#include "policy/policy_types.h"
+
+namespace policy {
+class PolicyManagerImpl;
+
+const std::string kAllowedKey = "allowed";
+const std::string kUserDisallowedKey = "userDisallowed";
+const std::string kUndefinedKey = "undefined";
+
+namespace policy_table = rpc::policy_table_interface_base;
+
+typedef policy_table::Strings::const_iterator StringsConstItr;
+typedef policy_table::ApplicationPolicies::const_iterator AppPoliciesConstItr;
+typedef policy_table::HmiLevels::const_iterator HMILevelsConstItr;
+typedef policy_table::Parameters::const_iterator ParametersConstItr;
+typedef policy_table::Rpc::const_iterator RpcConstItr;
+typedef policy_table::FunctionalGroupings::const_iterator FuncGroupConstItr;
+
+typedef policy_table::ApplicationPolicies::value_type AppPoliciesValueType;
+typedef policy_table::Rpc::value_type RpcValueType;
+typedef policy_table::Strings::value_type StringsValueType;
+
+/*
+ * @brief Helper struct to compare functional group names
+ */
+struct CompareGroupName {
+ explicit CompareGroupName(const StringsValueType& group_name);
+ bool operator()(const StringsValueType& group_name_to_compare) const;
+
+ private:
+ const StringsValueType& group_name_;
+};
+
+/*
+ * @brief Used for compare of policies parameters mapped with specific
+ * application ids
+ */
+bool operator!=(const policy_table::ApplicationParams& first,
+ const policy_table::ApplicationParams& second);
+
+/**
+ * @brief Helper struct for checking changes of application policies, which
+ * come with update along with current data snapshot
+ * @param pm Pointer to PolicyManager instance
+ * @param update Shared pointer to policy table update received
+ * @param snapshot Shared pointer to current policy table copy
+ * @param out_results Collection of check result
+ */
+struct CheckAppPolicy {
+ CheckAppPolicy(PolicyManagerImpl* pm,
+ const utils::SharedPtr<policy_table::Table> update,
+ const utils::SharedPtr<policy_table::Table> snapshot,
+ CheckAppPolicyResults& out_results);
+
+ bool operator()(const AppPoliciesValueType& app_policy);
+
+ private:
+ /**
+ * @brief Sets pending values to be notified to the system (depends on HMI
+ * level of application) with SDL.ActivateApp or OnAppPermissionsChanged
+ * notification
+ * @param app_policy Reference to updated application policy
+ * @param result Result of check of updated policy
+ */
+ void SetPendingPermissions(const AppPoliciesValueType& app_policy,
+ PermissionsCheckResult result) const;
+ /**
+ * @brief Analyzes updated application policy whether any changes received. If
+ * yes - provides appropriate result code
+ * @param app_policy Reference to updated application policy
+ * @return Result code according to changes in updated policy
+ */
+ PermissionsCheckResult CheckPermissionsChanges(
+ const AppPoliciesValueType& app_policy) const;
+ /**
+ * @brief Checks whether updated policy has groups revoked, i.e. absent in
+ * compare to current one
+ * @param app_policy Reference to updated policy
+ * @param revoked_groups List of revoked groups if any
+ * @return True if there are revoked groups, otherwise - false
+ */
+ bool HasRevokedGroups(const AppPoliciesValueType& app_policy,
+ policy_table::Strings* revoked_groups = NULL) const;
+ /**
+ * @brief Checks whether updated application policy has new group in compare
+ * to current one
+ * @param app_policy Reference to updated application policy
+ * @param new_groups List of new groups if any
+ * @return True if new groups found, otherwise - false
+ */
+ bool HasNewGroups(const AppPoliciesValueType& app_policy,
+ policy_table::Strings* new_groups = NULL) const;
+ /**
+ * @brief Checks whether updated policy has groups which require user consent
+ * @param app_policy Reference to updated application policy
+ * @return True if has groups requiring user consents, otherwise - false
+ */
+ bool HasConsentNeededGroups(const AppPoliciesValueType& app_policy) const;
+ /**
+ * @brief Gets revoked groups parameters from current policies
+ * @param app_policy Reference to updated application policy
+ * @return List of revoked groups with their parameters
+ */
+ std::vector<FunctionalGroupPermission> GetRevokedGroups(
+ const AppPoliciesValueType& app_policy) const;
+ /**
+ * @brief Removes consents for revoked groups of application
+ * @param app_policy Reference to updated application policy
+ * @param revoked_groups List of revoked groups with parameters to remove
+ * consents if any exists
+ */
+ void RemoveRevokedConsents(
+ const AppPoliciesValueType& app_policy,
+ const std::vector<FunctionalGroupPermission>& revoked_groups) const;
+ /**
+ * @brief Checks whether application is present in current policy table,
+ * since update can be processed only for application known by policy while
+ * it sent update request
+ * @param application_id Application id
+ * @return True if application is known, otherwise - false
+ */
+ bool IsKnownAppication(const std::string& application_id) const;
+ /**
+ * @brief Checks whether application is revoked by backend, i.e. has 'null'
+ * for policies parameters
+ * @param app_policy Reference to updated application policy
+ * @return True if application is revoked, otherwise - false
+ */
+ bool IsAppRevoked(const AppPoliciesValueType& app_policy) const;
+ /**
+ * @brief Checks whether there such application is registered and has correct
+ * nickname
+ * @param app_policy Reference to updated application policy
+ * @return True if there is nickname mismatch, otherwise - false
+ */
+ bool NicknamesMatch(const AppPoliciesValueType& app_policy) const;
+ /**
+ * @brief Adds result of check of current application policy with updated one
+ * @param app_id Application id
+ * @param result Result value
+ */
+ void AddResult(const std::string& app_id, PermissionsCheckResult result);
+ /**
+ * @brief Allows to check if appropriate group requires any consent.
+ * @param group_name the group for which consent will be checked.
+ * @return true if consent is required, false otherwise.
+ */
+ bool IsConsentRequired(const std::string& app_id,
+ const std::string& group_name) const;
+ /**
+ * @brief Checks whether RequestTypes of application have been changed by
+ * udpated
+ * @param app_policy Reference to updated application policy
+ * @return True if changed, otherwise - false
+ */
+ bool IsRequestTypeChanged(const AppPoliciesValueType& app_policy) const;
+
+ private:
+ PolicyManagerImpl* pm_;
+ const utils::SharedPtr<policy_table::Table> update_;
+ const utils::SharedPtr<policy_table::Table> snapshot_;
+ CheckAppPolicyResults& out_results_;
+};
+
+/*
+ * @brief Fill permissions data with merged rpc permissions for hmi levels and
+ * parameters
+ */
+struct FillNotificationData {
+ /**
+ * @brief Constructor
+ * @param data Output structure with filled data
+ * @param group_state Consent of the group processed by instance
+ * @param undefined_group_consent Defines how to treat 'undefined' consent
+ * @param does_require_user_consent Specifies whether processed group requires
+ * user consent
+ */
+ FillNotificationData(Permissions& data,
+ GroupConsent group_state,
+ GroupConsent undefined_group_consent,
+ bool does_require_user_consent);
+ bool operator()(const RpcValueType& rpc);
+ void UpdateHMILevels(const policy_table::HmiLevels& in_hmi,
+ HMIPermissions& out_hmi);
+ void UpdateParameters(const policy_table::Parameters& in_parameters,
+ ParameterPermissions& out_parameter);
+
+ private:
+ void ExcludeSame(RpcPermissions& rpc);
+ void ExcludeSameHMILevels(std::set<HMILevel>& source,
+ const std::set<HMILevel>& target);
+ void ExcludeSameParameters(std::set<Parameter>& source,
+ const std::set<Parameter>& target);
+ void InitRpcKeys(const std::string& rpc_name);
+ bool RpcParametersEmpty(RpcPermissions& rpc);
+ bool IsSectionEmpty(ParameterPermissions& permissions,
+ const std::string& section);
+ std::string current_key_;
+ Permissions& data_;
+ const bool does_require_user_consent_;
+};
+
+/*
+ * @brief Checks for functional group presence and pass it to helper struct,
+ * which fills permissions data according to group consent
+ */
+struct ProcessFunctionalGroup {
+ ProcessFunctionalGroup(
+ const policy_table::FunctionalGroupings& fg,
+ const std::vector<FunctionalGroupPermission>& group_permissions,
+ Permissions& data,
+ GroupConsent undefined_group_consent = GroupConsent::kGroupDisallowed);
+ bool operator()(const StringsValueType& group_name);
+
+ private:
+ GroupConsent GetGroupState(const std::string& group_name);
+ const policy_table::FunctionalGroupings& fg_;
+ const std::vector<FunctionalGroupPermission>& group_permissions_;
+ Permissions& data_;
+ GroupConsent undefined_group_consent_;
+};
+
+struct FunctionalGroupInserter {
+ FunctionalGroupInserter(const policy_table::Strings& preconsented_groups,
+ PermissionsList& list);
+ void operator()(const StringsValueType& group_name);
+
+ private:
+ PermissionsList& list_;
+ const policy_table::Strings& preconsented_;
+};
+
+/**
+ * @brief Fills FunctionalGroupPermissions with provided params
+ * @param ids Functional group ids from DB
+ * @param names Group names and user_consent_prompt
+ * @param state User consent for group
+ * @param permissions Struct to be filled with provided params
+ */
+void FillFunctionalGroupPermissions(
+ FunctionalGroupIDs& ids,
+ FunctionalGroupNames& names,
+ GroupConsent state,
+ std::vector<FunctionalGroupPermission>& permissions);
+
+/**
+ * @brief Checks, if application is predefined, e.g. "default", i.e. which is
+ * must be present in policy table
+ * @param app Application struct
+ * @return true, if app is predefined, otherwise - false
+ */
+bool IsPredefinedApp(const AppPoliciesValueType& app);
+
+/**
+ * @brief Excludes same values
+ * @param from Source, which should be checked
+ * @param what Target, which should be excluded from source
+ * @return Values without excluded
+ */
+FunctionalGroupIDs ExcludeSame(const FunctionalGroupIDs& from,
+ const FunctionalGroupIDs& what);
+
+/**
+ * @brief Merges all values without same values
+ * @param first First source of values
+ * @param second Second source of values
+ * @return Merged values w/o same values
+ */
+FunctionalGroupIDs Merge(const FunctionalGroupIDs& first,
+ const FunctionalGroupIDs& second);
+
+/**
+ * @brief Finds same values
+ * @param first First source of values
+ * @param second Second source of values
+ * @return Same values set, if any found
+ */
+FunctionalGroupIDs FindSame(const FunctionalGroupIDs& first,
+ const FunctionalGroupIDs& second);
+
+/**
+ * @brief Unwrap application policies from predefined values to specific policy
+ * values, i.e. if application has "default", it will be assigned default
+ * policies
+ * @param app_policies Application policies to unwrap
+ * @return true, if succeded, otherwise - false
+ */
+bool UnwrapAppPolicies(policy_table::ApplicationPolicies& app_policies);
+}
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_HELPER_H_
diff --git a/src/components/policy/policy_external/include/policy/policy_manager_impl.h b/src/components/policy/policy_external/include/policy/policy_manager_impl.h
new file mode 100644
index 0000000000..a37d0d66b9
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/policy_manager_impl.h
@@ -0,0 +1,508 @@
+/*
+ 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_MANAGER_IMPL_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_MANAGER_IMPL_H_
+
+#include <list>
+#include "utils/shared_ptr.h"
+#include "utils/lock.h"
+#include "policy/policy_manager.h"
+#include "policy/policy_table.h"
+#include "policy/cache_manager_interface.h"
+#include "policy/update_status_manager.h"
+#include "policy/policy_table/functions.h"
+#include "policy/usage_statistics/statistics_manager.h"
+
+namespace policy_table = rpc::policy_table_interface_base;
+
+namespace policy {
+struct CheckAppPolicy;
+
+class PolicyManagerImpl : public PolicyManager {
+ public:
+ PolicyManagerImpl();
+ explicit PolicyManagerImpl(bool in_memory);
+ virtual void set_listener(PolicyListener* listener);
+ PolicyListener* listener() const {
+ return listener_;
+ }
+ virtual bool InitPT(const std::string& file_name,
+ const PolicySettings* settings);
+ virtual bool LoadPT(const std::string& file, const BinaryMessage& pt_content);
+ virtual bool ResetPT(const std::string& file_name);
+
+ virtual std::string GetUpdateUrl(int service_type);
+ virtual void GetUpdateUrls(const uint32_t service_type,
+ EndpointUrls& out_end_points);
+ virtual void GetUpdateUrls(const std::string& service_type,
+ EndpointUrls& out_end_points);
+ virtual void RequestPTUpdate();
+ virtual void CheckPermissions(const PTString& app_id,
+ const PTString& hmi_level,
+ const PTString& rpc,
+ const RPCParams& rpc_params,
+ CheckPermissionResult& result);
+ virtual bool ResetUserConsent();
+ virtual void KmsChanged(int kilometers);
+ virtual void IncrementIgnitionCycles();
+ virtual std::string ForcePTExchange();
+ virtual std::string ForcePTExchangeAtUserRequest();
+ virtual std::string GetPolicyTableStatus() const;
+ virtual void ResetRetrySequence();
+ virtual int NextRetryTimeout();
+ virtual uint32_t TimeoutExchangeMSec();
+ virtual const std::vector<int> RetrySequenceDelaysSeconds();
+ virtual void OnExceededTimeout();
+ virtual std::string GetLockScreenIconUrl() const OVERRIDE;
+ virtual void OnUpdateStarted();
+ virtual void PTUpdatedAt(Counters counter, int value);
+
+ /**
+ * Refresh data about retry sequence from policy table
+ */
+ virtual void RefreshRetrySequence();
+ virtual DeviceConsent GetUserConsentForDevice(
+ const std::string& device_id) const OVERRIDE;
+ virtual void GetUserConsentForApp(
+ const std::string& device_id,
+ const std::string& policy_app_id,
+ std::vector<FunctionalGroupPermission>& permissions);
+ virtual void SetUserConsentForDevice(const std::string& device_id,
+ const bool is_allowed);
+ virtual bool ReactOnUserDevConsentForApp(const std::string& app_id,
+ const bool is_device_allowed);
+ virtual bool GetInitialAppData(const std::string& application_id,
+ StringArray* nicknames = NULL,
+ StringArray* app_hmi_types = NULL);
+
+ virtual void AddDevice(const std::string& device_id,
+ const std::string& connection_type);
+
+ virtual void SetDeviceInfo(const std::string& device_id,
+ const DeviceInfo& device_info);
+
+ void SetUserConsentForApp(const PermissionConsent& permissions,
+ const NotificationMode mode) OVERRIDE;
+
+ virtual bool GetDefaultHmi(const std::string& policy_app_id,
+ std::string* default_hmi) const;
+
+ virtual bool GetPriority(const std::string& policy_app_id,
+ std::string* priority) const;
+
+ virtual std::vector<UserFriendlyMessage> GetUserFriendlyMessages(
+ const std::vector<std::string>& message_code,
+ const std::string& language,
+ const std::string& active_hmi_language);
+
+ virtual bool IsApplicationRevoked(const std::string& app_id) const;
+
+ virtual void GetPermissionsForApp(
+ const std::string& device_id,
+ const std::string& policy_app_id,
+ std::vector<FunctionalGroupPermission>& permissions);
+
+ virtual std::string& GetCurrentDeviceId(
+ const std::string& policy_app_id) const;
+
+ virtual void SetSystemLanguage(const std::string& language);
+
+ virtual void SetSystemInfo(const std::string& ccpu_version,
+ const std::string& wers_country_code,
+ const std::string& language);
+ virtual void OnSystemReady();
+
+ virtual uint32_t GetNotificationsNumber(
+ const std::string& priority) const OVERRIDE;
+
+ virtual void SetVINValue(const std::string& value);
+
+ // Interface StatisticsManager (begin)
+ virtual void Increment(usage_statistics::GlobalCounterId type);
+ virtual void Increment(const std::string& app_id,
+ usage_statistics::AppCounterId type);
+ virtual void Set(const std::string& app_id,
+ usage_statistics::AppInfoId type,
+ const std::string& value);
+ virtual void Add(const std::string& app_id,
+ usage_statistics::AppStopwatchId type,
+ int32_t timespan_seconds);
+ // Interface StatisticsManager (end)
+
+ AppPermissions GetAppPermissionsChanges(const std::string& policy_app_id);
+ void RemovePendingPermissionChanges(const std::string& app_id);
+
+ void SendNotificationOnPermissionsUpdated(const std::string& application_id);
+
+ bool CleanupUnpairedDevices();
+
+ bool CanAppKeepContext(const std::string& app_id) const;
+ bool CanAppStealFocus(const std::string& app_id) const;
+ void MarkUnpairedDevice(const std::string& device_id);
+
+ StatusNotifier AddApplication(
+ const std::string& application_id,
+ const rpc::policy_table_interface_base::AppHmiTypes& hmi_types);
+
+ virtual void RemoveAppConsentForGroup(const std::string& app_id,
+ const std::string& group_name);
+
+ virtual uint32_t HeartBeatTimeout(const std::string& app_id) const;
+
+ virtual void SaveUpdateStatusRequired(bool is_update_needed);
+
+ virtual bool IsPredataPolicy(const std::string& policy_app_id) const OVERRIDE;
+ void set_cache_manager(CacheManagerInterface* cache_manager);
+
+ virtual void OnAppsSearchStarted();
+
+ virtual void OnAppsSearchCompleted(const bool trigger_ptu);
+
+#ifdef BUILD_TESTS
+ inline CacheManagerInterfaceSPtr GetCache() {
+ return cache_;
+ }
+ inline void SetSendOnUpdateFlags(const bool send_on_update_sent_out,
+ const bool wrong_ptu_update_received) {
+ send_on_update_sent_out_ = send_on_update_sent_out;
+ wrong_ptu_update_received_ = wrong_ptu_update_received;
+ }
+#endif // BUILD_TESTS
+
+ virtual const std::vector<std::string> GetAppRequestTypes(
+ const std::string policy_app_id) const;
+
+ virtual const VehicleInfo GetVehicleInfo() const;
+
+ virtual void OnAppRegisteredOnMobile(const std::string& application_id);
+
+ virtual const MetaInfo GetMetaInfo() const OVERRIDE;
+
+ virtual std::string RetrieveCertificate() const OVERRIDE;
+
+ virtual bool HasCertificate() const OVERRIDE;
+
+ virtual void SetDecryptedCertificate(const std::string& certificate) OVERRIDE;
+
+ const PolicySettings& get_settings() const OVERRIDE;
+
+ AppIdURL GetNextUpdateUrl(const EndpointUrls& urls) OVERRIDE;
+
+ AppIdURL RetrySequenceUrl(const struct RetrySequenceURL& rs,
+ const EndpointUrls& urls) const OVERRIDE;
+
+ /**
+ * @brief Checks, if SDL needs to update it's policy table section
+ "external_consent_status"
+ * @param ExternalConsent status
+ * @return true if such check is needed, false - if not.
+ */
+ bool IsNeedToUpdateExternalConsentStatus(
+ const ExternalConsentStatus& status) const;
+
+ /**
+ * @brief Gets customer connectivity settings status
+ * @return ExternalConsent status
+ */
+ bool SetExternalConsentStatus(const ExternalConsentStatus& status) OVERRIDE;
+ ExternalConsentStatus GetExternalConsentStatus() OVERRIDE;
+
+ protected:
+ virtual utils::SharedPtr<policy_table::Table> Parse(
+ const BinaryMessage& pt_content);
+
+ private:
+ void CheckTriggers();
+
+ /**
+ * @brief Compares current applications policies to the updated one and
+ * returns apporopriate result codes per application, which that are being
+ * processed by sending notification to applications registered and to the
+ * system
+ * @param update Shared pointer to policy table udpate
+ * @param snapshot Shared pointer to current copy of policy table
+ * @return Collection per-application results
+ */
+ CheckAppPolicyResults CheckPermissionsChanges(
+ const utils::SharedPtr<policy_table::Table> update,
+ const utils::SharedPtr<policy_table::Table> snapshot);
+
+ /**
+ * @brief Processes results from policy table update analysis done by
+ * CheckPermissionsChanges() by sending OnPermissionChange and
+ * OnAppPermissionChanged notifications
+ * @param results Collection of per-application results
+ * @param app_policies Reference to updated application policies section as
+ * a data source for generating notifications data
+ */
+ void ProcessAppPolicyCheckResults(
+ const CheckAppPolicyResults& results,
+ const policy_table::ApplicationPolicies& app_policies);
+
+ /**
+ * @brief Fill structure to be sent with OnPermissionsChanged notification
+ *
+ * @param Policy table struct, which contains rpc functional groups data
+ * @param List of rpc functional group names, which should be checked
+ * @param group_permission User permissions for functional groups
+ * @param Notification struct to be filled and sent
+ */
+ void PrepareNotificationData(
+ const policy_table::FunctionalGroupings& groups,
+ const policy_table::Strings& group_names,
+ const std::vector<FunctionalGroupPermission>& group_permission,
+ Permissions& notification_data);
+
+ /**
+ * @brief Validate PermissionConsent structure according to currently
+ * assigned groups
+ * @param permissions PermissionConsent structure that should be validated.
+ * @return PermissonConsent struct, which contains no foreign groups
+ */
+ PermissionConsent EnsureCorrectPermissionConsent(
+ const PermissionConsent& permissions_to_check);
+
+ /**
+ * @brief Allows to process case when added application is not present in
+ * policy db.
+ * @param policy application id.
+ * @param cuuren consent for application's device.
+ */
+ void AddNewApplication(const std::string& application_id,
+ DeviceConsent device_consent);
+
+ /**
+ * @brief Allows to process case when added application is already
+ * in policy db.
+ * @param policy application id.
+ * @param cuuren consent for application's device.
+ */
+ void PromoteExistedApplication(const std::string& application_id,
+ DeviceConsent device_consent);
+
+ /**
+ * @brief Check if certain application already in policy db.
+ * @param policy application id.
+ * @return true if application presents false otherwise.
+ */
+ bool IsNewApplication(const std::string& application_id) const;
+
+ /**
+ * Checks existing and permissions of AppStorageFolder
+ * @return true if AppStorageFolder exists and has permissions read/write
+ */
+ bool CheckAppStorageFolder() const;
+
+ /**
+ * @brief Checks whether need ask the permission of users
+ * @return true if user consent is needed
+ */
+ virtual bool IsConsentNeeded(const std::string& app_id);
+
+ /**
+ * @brief Changes isConsentNeeded for app pending permissions, in case
+ * user set permissions before app activation.
+ * @param Unique app id
+ * @param Current permissions for app
+ */
+ void CheckPendingPermissionsChanges(
+ const std::string& policy_app_id,
+ const std::vector<FunctionalGroupPermission>& current_permissions);
+
+ virtual void StartPTExchange();
+ virtual bool ExceededDays();
+ virtual bool ExceededIgnitionCycles();
+ bool IsPTValid(utils::SharedPtr<policy_table::Table> policy_table,
+ policy_table::PolicyTableType type) const;
+
+ /**
+ * @brief Notify application about its permissions changes by preparing and
+ * sending OnPermissionsChanged notification
+ * @param policy_app_id Application id to send notification to
+ * @param app_group_permissons Current permissions for groups assigned to
+ * application
+ */
+ void NotifyPermissionsChanges(
+ const std::string& policy_app_id,
+ const std::vector<FunctionalGroupPermission>& app_group_permissions);
+
+ /**
+ * @brief Processes updated ExternalConsent status received via
+ * OnAppPermissionConsent
+ * notification by updating user consents and ExternalConsent consents for
+ * registered and
+ * known before by policy table (must have any user consent records)
+ * @param groups_by_status Collection of ExternalConsent entities with their
+ * statuses
+ * @param processing_policy Defines whether consents timestamps must be
+ * considered or external consents take over
+ */
+ void ProcessExternalConsentStatusUpdate(
+ const GroupsByExternalConsentStatus& groups_by_status,
+ const ConsentProcessingPolicy processing_policy);
+
+ /**
+ * @brief Processes ExternalConsent status for application registered
+ * afterward, so its
+ * user consents (if any) and ExternalConsent consents (if any) will be
+ * updated
+ * appropiately to current ExternalConsent status stored by policy table
+ * @param application_id Application id
+ * @param processing_policy Defines whether consents timestamps must be
+ * considered or external consents take over
+ */
+ void ProcessExternalConsentStatusForApp(
+ const std::string& application_id,
+ const ConsentProcessingPolicy processing_policy);
+ /**
+ * @brief Directly updates user consent and ExternalConsent consents (if any)
+ * for
+ * application if it has assigned any of group from allowed or disallowed
+ * lists
+ * @param device_id Device id which is linked to application id
+ * @param application_id Application id
+ * @param allowed_groups List of group names allowed by current
+ * ExternalConsent status
+ * @param disallowed_groups List of group names disallwed by current
+ * ExternalConsent status
+ * @param processing_policy Defines whether consents timestamps have to be
+ * considered or external consents take over
+ */
+ void UpdateAppConsentWithExternalConsent(
+ const std::string& device_id,
+ const std::string& application_id,
+ const GroupsNames& allowed_groups,
+ const GroupsNames& disallowed_groups,
+ const ConsentProcessingPolicy processing_policy);
+
+ typedef policy_table::ApplicationPolicies::value_type AppPoliciesValueType;
+
+ /**
+ * @brief Notifies system by sending OnAppPermissionChanged notification
+ * @param app_policy Reference to application policy
+ */
+ void NotifySystem(const AppPoliciesValueType& app_policy) const;
+
+ /**
+ * @brief Sends OnPermissionChange notification to application if its
+ * currently registered
+ * @param app_policy Reference to application policy
+ */
+ void SendPermissionsToApp(const AppPoliciesValueType& app_policy);
+
+ /**
+ * @brief Gets groups names from collection of groups permissions
+ * @param app_group_permissions Collection of groups permissions
+ * @return Collection of group names
+ */
+ policy_table::Strings GetGroupsNames(
+ const std::vector<FunctionalGroupPermission>& app_group_permissions)
+ const;
+
+ /**
+ * @brief Calculates consents for groups based on mapped ExternalConsent
+ * entities statuses
+ * and groups containers where entities have been found
+ * @param groups_by_external_consent ExternalConsent entities mapped to
+ * functional groups names and
+ * their containters where this entity has been found
+ * @param out_allowed_groups List of groups allowed by ExternalConsent status
+ * @param out_disallowed_groups List of groups disallowed by ExternalConsent
+ * status
+ */
+ void CalculateGroupsConsentFromExternalConsent(
+ const GroupsByExternalConsentStatus& groups_by_external_consent,
+ GroupsNames& out_allowed_groups,
+ GroupsNames& out_disallowed_groups) const;
+
+ PolicyListener* listener_;
+
+ UpdateStatusManager update_status_manager_;
+ CacheManagerInterfaceSPtr cache_;
+ sync_primitives::Lock apps_registration_lock_;
+ sync_primitives::Lock app_permissions_diff_lock_;
+
+ /**
+ * @brief Collection of parameters to be reported to the system with
+ * SDL.ActivateApp response or OnAppPermissionsChanged notification
+ * Being set during policy table update processing
+ */
+ typedef std::map<std::string, AppPermissions> PendingPermissions;
+ PendingPermissions app_permissions_diff_;
+
+ /**
+ * Timeout to wait response with UpdatePT
+ */
+ int retry_sequence_timeout_;
+
+ /**
+ * Seconds between retries to update PT
+ */
+ std::vector<int> retry_sequence_seconds_;
+
+ /**
+ * Current index trying of retry sequence
+ */
+ uint32_t retry_sequence_index_;
+
+ /**
+ * Lock for guarding retry sequence
+ */
+ sync_primitives::Lock retry_sequence_lock_;
+
+ /**
+ * @brief Device id, which is used during PTU handling for specific
+ * application
+ */
+ mutable std::string last_device_id_;
+
+ bool ignition_check;
+
+ const PolicySettings* settings_;
+ friend struct CheckAppPolicy;
+
+ /**
+ * @brief Pair of app index and url index from Endpoints vector
+ * that contains all application URLs
+ */
+ RetrySequenceURL retry_sequence_url_;
+ friend struct ProccessAppGroups;
+
+ bool wrong_ptu_update_received_;
+ bool send_on_update_sent_out_;
+ bool trigger_ptu_;
+};
+
+} // namespace policy
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_MANAGER_IMPL_H_
diff --git a/src/components/policy/policy_external/include/policy/policy_table.h b/src/components/policy/policy_external/include/policy/policy_table.h
new file mode 100644
index 0000000000..ecbd56c2e4
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/policy_table.h
@@ -0,0 +1,62 @@
+/*
+ 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TABLE_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TABLE_H_
+
+#include "utils/shared_ptr.h"
+#include "policy/pt_representation.h"
+#include "policy/pt_ext_representation.h"
+
+namespace policy {
+
+class PolicyTable {
+ public:
+ PolicyTable();
+ explicit PolicyTable(utils::SharedPtr<PTRepresentation> pt_data);
+ virtual ~PolicyTable();
+
+ /**
+ * @brief Returns current implementation of
+ * actual class storing policy table.
+ * @return PTRepresentation* Policy Table Content Handler
+ */
+ utils::SharedPtr<PTRepresentation> pt_data() const {
+ return pt_data_;
+ }
+
+ private:
+ utils::SharedPtr<PTRepresentation> pt_data_;
+};
+} // namespace policy
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TABLE_H_
diff --git a/src/components/policy/policy_external/include/policy/policy_table/enums.h b/src/components/policy/policy_external/include/policy/policy_table/enums.h
new file mode 100644
index 0000000000..45fad03dae
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/policy_table/enums.h
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 2016, 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TABLE_ENUMS_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TABLE_ENUMS_H_
+
+#include <string>
+
+namespace rpc {
+namespace policy_table_interface_base {
+
+enum Priority {
+ P_EMERGENCY,
+ P_NAVIGATION,
+ P_VOICECOM,
+ P_COMMUNICATION,
+ P_NORMAL,
+ P_NONE,
+};
+
+bool IsValidEnum(Priority val);
+const char* EnumToJsonString(Priority val);
+bool EnumFromJsonString(const std::string& literal, Priority* result);
+
+enum HmiLevel {
+ HL_BACKGROUND,
+ HL_FULL,
+ HL_LIMITED,
+ HL_NONE,
+};
+bool IsValidEnum(HmiLevel val);
+const char* EnumToJsonString(HmiLevel val);
+bool EnumFromJsonString(const std::string& literal, HmiLevel* result);
+
+enum Parameter {
+ P_GPS,
+ P_SPEED,
+ P_ENGINETORQUE,
+ P_EXTERNALTEMPERATURE,
+ P_FUELLEVEL,
+ P_FUELLEVEL_STATE,
+ P_HEADLAMPSTATUS,
+ P_INSTANTFUELCONSUMPTION,
+ P_ODOMETER,
+ P_TIREPRESSURE,
+ P_WIPERSTATUS,
+ P_VIN,
+ P_ACCPEDALPOSITION,
+ P_BELTSTATUS,
+ P_DRIVERBRAKING,
+ P_PRNDL,
+ P_RPM,
+ P_STEERINGWHEELANGLE,
+ P_MYKEY,
+ P_AIRBAGSTATUS,
+ P_BODYINFORMATION,
+ P_CLUSTERMODESTATUS,
+ P_DEVICESTATUS,
+ P_EMERGENCYEVENT,
+ P_ECALLINFO,
+ P_ABS_STATE,
+ P_TURN_SIGNAL,
+ P_FUEL_RANGE,
+ P_TIRE_PRESSURE_VALUE,
+ P_TPMS,
+ P_LONGTITUDE_DEGREES,
+ P_LATITUDE_DEGREES,
+ P_LOCATION_NAME,
+ P_LOCATION_DESCRIPTION,
+ P_ADDRESS_LINES,
+ P_PHONE_NUMBER,
+ P_LOCATION_IMAGE,
+ P_DELIVERY_MODE,
+ P_TIMESTAMP,
+ P_ADDRESS,
+ P_EMPTY // Added to allow empty parameters handling
+};
+
+bool IsValidEnum(Parameter val);
+const char* EnumToJsonString(Parameter val);
+bool EnumFromJsonString(const std::string& literal, Parameter* result);
+
+enum AppHMIType {
+ AHT_DEFAULT,
+ AHT_COMMUNICATION,
+ AHT_MEDIA,
+ AHT_MESSAGING,
+ AHT_NAVIGATION,
+ AHT_INFORMATION,
+ AHT_SOCIAL,
+ AHT_BACKGROUND_PROCESS,
+ AHT_TESTING,
+ AHT_SYSTEM
+};
+bool IsValidEnum(AppHMIType val);
+const char* EnumToJsonString(AppHMIType val);
+bool EnumFromJsonString(const std::string& literal, AppHMIType* result);
+
+enum RequestType {
+ RT_HTTP,
+ RT_FILE_RESUME,
+ RT_AUTH_REQUEST,
+ RT_AUTH_CHALLENGE,
+ RT_AUTH_ACK,
+ RT_PROPRIETARY,
+ RT_QUERY_APPS,
+ RT_LAUNCH_APP,
+ RT_LOCK_SCREEN_ICON_URL,
+ RT_TRAFFIC_MESSAGE_CHANNEL,
+ RT_DRIVER_PROFILE,
+ RT_VOICE_SEARCH,
+ RT_NAVIGATION,
+ RT_PHONE,
+ RT_CLIMATE,
+ RT_SETTINGS,
+ RT_VEHICLE_DIAGNOSTICS,
+ RT_EMERGENCY,
+ RT_MEDIA,
+ RT_FOTA
+};
+
+bool IsValidEnum(RequestType val);
+const char* EnumToJsonString(RequestType val);
+bool EnumFromJsonString(const std::string& literal, RequestType* result);
+
+enum Input {
+ I_GUI,
+ I_VUI,
+};
+bool IsValidEnum(Input val);
+const char* EnumToJsonString(Input val);
+bool EnumFromJsonString(const std::string& literal, Input* result);
+
+enum ModuleType {
+ MT_CLIMATE,
+ MT_RADIO,
+};
+bool IsValidEnum(ModuleType val);
+const char* EnumToJsonString(ModuleType val);
+bool EnumFromJsonString(const std::string& literal, ModuleType* result);
+
+extern const std::string kDefaultApp;
+extern const std::string kPreDataConsentApp;
+extern const std::string kDeviceApp;
+
+} // namespace policy_table_interface_base
+} // namespace rpc
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TABLE_ENUMS_H_
diff --git a/src/components/policy/policy_external/include/policy/policy_table/functions.h b/src/components/policy/policy_external/include/policy/policy_table/functions.h
new file mode 100644
index 0000000000..07d4a42a25
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/policy_table/functions.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2016, 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TABLE_FUNCTIONS_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TABLE_FUNCTIONS_H_
+
+#include "policy/policy_table/enums.h"
+#include "policy/policy_table/types.h"
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TABLE_FUNCTIONS_H_
diff --git a/src/components/policy/policy_external/include/policy/policy_table/types.h b/src/components/policy/policy_external/include/policy/policy_table/types.h
new file mode 100644
index 0000000000..774ef3ee59
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/policy_table/types.h
@@ -0,0 +1,583 @@
+/*
+ * Copyright (c) 2016, 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TABLE_TYPES_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TABLE_TYPES_H_
+
+#include <climits>
+#include "utils/macro.h"
+
+#include "policy/policy_table/enums.h"
+#include "rpc_base/rpc_message.h"
+
+namespace Json {
+class Value;
+} // namespace Json
+namespace rpc {
+namespace policy_table_interface_base {
+struct AppLevel;
+struct ApplicationParams;
+struct ConsentRecords;
+struct DeviceParams;
+struct MessageLanguages;
+struct MessageString;
+struct RpcParameters;
+struct Rpcs;
+} // namespace policy_table_interface_base
+} // namespace rpc
+
+namespace rpc {
+namespace policy_table_interface_base {
+
+// According to HMI API
+#define ODO_MAX 17000000
+
+typedef Array<String<1, 255>, 0, 255> Strings;
+
+typedef Array<Enum<AppHMIType>, 0, 255> AppHMITypes;
+
+typedef Array<Enum<HmiLevel>, 0, 4> HmiLevels;
+
+typedef Array<Enum<Parameter>, 0, 100> Parameters;
+
+typedef Map<RpcParameters, 0, 65535> Rpc;
+
+typedef Array<String<10, 65535>, 1, 3> URL;
+
+typedef Map<URL, 1, 255> URLList;
+
+typedef Map<URLList, 1, 255> ServiceEndpoints;
+
+typedef uint8_t NumberOfNotificationsType;
+typedef Map<Integer<NumberOfNotificationsType, 0, 255>, 0, 6>
+ NumberOfNotificationsPerMinute;
+
+typedef Array<Integer<uint16_t, 1, 1000>, 0, 5> SecondsBetweenRetries;
+
+typedef Map<MessageString, 0, 600> Languages;
+
+typedef Map<MessageLanguages, 0, 255> Messages;
+
+typedef Map<AppLevel, 0, 255> AppLevels;
+
+typedef Map<Boolean, 0, 255> ConsentGroups;
+
+typedef Map<ConsentRecords, 0, 1000> UserConsentRecords;
+
+typedef Map<Stringifyable<Nullable<ApplicationParams> >, 1, 1000>
+ ApplicationPolicies;
+
+typedef Map<Rpcs, 1, 255> FunctionalGroupings;
+
+typedef Map<DeviceParams, 0, 255> DeviceData;
+
+typedef Array<Enum<RequestType>, 0, 255> RequestsTypeArray;
+
+typedef AppHMIType AppHmiType;
+typedef std::vector<AppHMIType> AppHmiTypes;
+
+struct RequestTypes : public RequestsTypeArray {
+ RequestTypes();
+ explicit RequestTypes(Json::Value* value);
+ explicit RequestTypes(const Json::Value* value);
+
+ void CleanUp();
+
+ bool is_valid() const OVERRIDE;
+ bool is_omitted() const;
+ bool is_empty() const;
+ bool is_cleaned_up() const;
+
+ private:
+ bool is_cleaned_up_;
+};
+
+struct PolicyBase : CompositeType {
+ public:
+ Strings groups;
+ Optional<Strings> preconsented_groups;
+ Enum<Priority> priority;
+ Enum<HmiLevel> default_hmi;
+ Boolean keep_context;
+ Boolean steal_focus;
+
+ public:
+ PolicyBase();
+ PolicyBase(const Strings& groups,
+ Priority priority,
+ HmiLevel default_hmi,
+ bool keep_context,
+ bool steal_focus);
+ virtual ~PolicyBase();
+ explicit PolicyBase(const Json::Value* value__);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+
+ private:
+ bool Validate() const;
+};
+
+struct DevicePolicy : PolicyBase {
+ public:
+ DevicePolicy();
+ DevicePolicy(const Strings& groups,
+ Priority priority,
+ HmiLevel default_hmi,
+ bool keep_context,
+ bool steal_focus);
+ ~DevicePolicy();
+ explicit DevicePolicy(const Json::Value* value__);
+};
+
+struct ApplicationParams : PolicyBase {
+ public:
+ Optional<Strings> nicknames;
+ Optional<AppHMITypes> AppHMIType;
+ Optional<RequestTypes> RequestType;
+ Optional<Integer<uint16_t, 0, 65225> > memory_kb;
+ Optional<Integer<uint32_t, 0, UINT_MAX> > heart_beat_timeout_ms;
+
+ public:
+ ApplicationParams();
+ ApplicationParams(const Strings& groups,
+ Priority priority,
+ HmiLevel default_hmi,
+ bool keep_context,
+ bool steal_focus);
+ ~ApplicationParams();
+ explicit ApplicationParams(const Json::Value* value__);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+
+ private:
+ bool Validate() const;
+};
+
+struct ApplicationPoliciesSection : CompositeType {
+ public:
+ mutable ApplicationPolicies apps;
+ DevicePolicy device;
+
+ public:
+ ApplicationPoliciesSection();
+ ApplicationPoliciesSection(const ApplicationPolicies& apps,
+ const DevicePolicy& device);
+ ~ApplicationPoliciesSection();
+ explicit ApplicationPoliciesSection(const Json::Value* value__);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+
+ private:
+ bool Validate() const;
+};
+
+struct RpcParameters : CompositeType {
+ public:
+ HmiLevels hmi_levels;
+ Optional<Parameters> parameters;
+
+ public:
+ RpcParameters();
+ explicit RpcParameters(const HmiLevels& hmi_levels);
+ ~RpcParameters();
+ explicit RpcParameters(const Json::Value* value__);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+
+ private:
+ bool Validate() const;
+};
+
+struct ExternalConsentEntity : CompositeType {
+ public:
+ typedef Integer<int32_t, 0, 128> EntityInt;
+ EntityInt entity_type;
+ EntityInt entity_id;
+
+ public:
+ ExternalConsentEntity();
+ explicit ExternalConsentEntity(const Json::Value* value__);
+ ExternalConsentEntity(const int32_t type, const int32_t id);
+ Json::Value ToJsonValue() const;
+ bool operator==(const ExternalConsentEntity& rhs) const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ void SetPolicyTableType(PolicyTableType pt_type) OVERRIDE;
+};
+
+typedef Array<ExternalConsentEntity, 0, 100>
+ DisallowedByExternalConsentEntities;
+
+struct Rpcs : CompositeType {
+ public:
+ Optional<String<1, 255> > user_consent_prompt;
+ Nullable<Rpc> rpcs;
+ Optional<DisallowedByExternalConsentEntities>
+ disallowed_by_external_consent_entities_on;
+ Optional<DisallowedByExternalConsentEntities>
+ disallowed_by_external_consent_entities_off;
+
+ public:
+ Rpcs();
+ explicit Rpcs(const Rpc& rpcs);
+ ~Rpcs();
+ explicit Rpcs(const Json::Value* value__);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+
+ private:
+ bool Validate() const;
+};
+
+struct ModuleConfig : CompositeType {
+ public:
+ Integer<uint8_t, 0, 255> exchange_after_x_ignition_cycles;
+ Integer<int64_t, 0, 4294967296ll> exchange_after_x_kilometers;
+ Integer<uint8_t, 0, 255> exchange_after_x_days;
+ Integer<uint16_t, 0, 65535> timeout_after_x_seconds;
+ SecondsBetweenRetries seconds_between_retries;
+ ServiceEndpoints endpoints;
+ NumberOfNotificationsPerMinute notifications_per_minute_by_priority;
+ Optional<String<0, 100> > vehicle_make;
+ Optional<String<0, 100> > vehicle_model;
+ Optional<String<0, 4> > vehicle_year;
+ Optional<String<0, 10> > preloaded_date;
+ Optional<String<0, 65535> > certificate;
+ Optional<Boolean> preloaded_pt;
+
+ public:
+ ModuleConfig();
+ ModuleConfig(uint8_t exchange_after_x_ignition_cycles,
+ int64_t exchange_after_x_kilometers,
+ uint8_t exchange_after_x_days,
+ uint16_t timeout_after_x_seconds,
+ const SecondsBetweenRetries& seconds_between_retries,
+ const ServiceEndpoints& endpoints,
+ const NumberOfNotificationsPerMinute&
+ notifications_per_minute_by_priority);
+ ~ModuleConfig();
+ explicit ModuleConfig(const Json::Value* value__);
+ void SafeCopyFrom(const ModuleConfig& from);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+
+ private:
+ bool Validate() const;
+};
+
+struct MessageString : CompositeType {
+ public:
+ Optional<String<1, 65535> > line1;
+ Optional<String<1, 65535> > line2;
+ Optional<String<1, 65535> > tts;
+ Optional<String<1, 65535> > label;
+ Optional<String<1, 65535> > textBody;
+
+ public:
+ MessageString();
+ ~MessageString();
+ explicit MessageString(const Json::Value* value__);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+
+ private:
+ bool Validate() const;
+};
+
+struct MessageLanguages : CompositeType {
+ public:
+ Languages languages;
+
+ public:
+ MessageLanguages();
+ explicit MessageLanguages(const Languages& languages);
+ ~MessageLanguages();
+ explicit MessageLanguages(const Json::Value* value__);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+
+ private:
+ bool Validate() const;
+ static const std::string kMandatoryLanguage_;
+};
+
+struct ConsumerFriendlyMessages : CompositeType {
+ public:
+ String<1, 100> version;
+ Optional<Messages> messages;
+
+ public:
+ ConsumerFriendlyMessages();
+ explicit ConsumerFriendlyMessages(const std::string& version);
+ ~ConsumerFriendlyMessages();
+ explicit ConsumerFriendlyMessages(const Json::Value* value__);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+
+ private:
+ bool Validate() const;
+};
+
+struct ModuleMeta : CompositeType {
+ public:
+ Optional<String<0, 250> > ccpu_version;
+ Optional<String<0, 250> > language;
+ Optional<String<0, 250> > wers_country_code;
+ Optional<Integer<uint32_t, 0, ODO_MAX> > pt_exchanged_at_odometer_x;
+ Optional<Integer<uint16_t, 0, 65535> > pt_exchanged_x_days_after_epoch;
+ Optional<Integer<uint16_t, 0, 65535> > ignition_cycles_since_last_exchange;
+ Optional<String<0, 250> > vin;
+
+ public:
+ ModuleMeta();
+ ~ModuleMeta();
+ explicit ModuleMeta(const Json::Value* value__);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+
+ private:
+ bool Validate() const;
+};
+
+struct AppLevel : CompositeType {
+ public:
+ Integer<uint16_t, 0, 65535> minutes_in_hmi_full;
+ String<1, 10> app_registration_language_gui;
+ String<0, 10> app_registration_language_vui;
+ Integer<uint16_t, 0, 65535> minutes_in_hmi_limited;
+ Integer<uint16_t, 0, 65535> minutes_in_hmi_background;
+ Integer<uint16_t, 0, 65535> minutes_in_hmi_none;
+ Integer<uint16_t, 0, 65535> count_of_user_selections;
+ Integer<uint16_t, 0, 65535> count_of_rejections_sync_out_of_memory;
+ Integer<uint16_t, 0, 65535> count_of_rejections_nickname_mismatch;
+ Integer<uint16_t, 0, 65535> count_of_rejections_duplicate_name;
+ Integer<uint16_t, 0, 65535> count_of_rejected_rpc_calls;
+ Integer<uint16_t, 0, 65535> count_of_rpcs_sent_in_hmi_none;
+ Integer<uint16_t, 0, 65535> count_of_removals_for_bad_behavior;
+ Integer<uint16_t, 0, 65535> count_of_tls_errors;
+ Integer<uint16_t, 0, 65535> count_of_run_attempts_while_revoked;
+
+ public:
+ AppLevel();
+ AppLevel(uint16_t minutes_in_hmi_full,
+ const std::string& app_registration_language_gui,
+ const std::string& app_registration_language_vui,
+ uint16_t minutes_in_hmi_limited,
+ uint16_t minutes_in_hmi_background,
+ uint16_t minutes_in_hmi_none,
+ uint16_t count_of_user_selections,
+ uint16_t count_of_rejections_sync_out_of_memory,
+ uint16_t count_of_rejections_nickname_mismatch,
+ uint16_t count_of_rejections_duplicate_name,
+ uint16_t count_of_rejected_rpc_calls,
+ uint16_t count_of_rpcs_sent_in_hmi_none,
+ uint16_t count_of_removals_for_bad_behavior,
+ uint16_t count_of_tls_errors,
+ uint16_t count_of_run_attempts_while_revoked);
+ ~AppLevel();
+ explicit AppLevel(const Json::Value* value__);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+
+ private:
+ bool Validate() const;
+};
+
+struct UsageAndErrorCounts : CompositeType {
+ public:
+ Optional<Integer<uint16_t, 0, 65535> > count_of_iap_buffer_full;
+ Optional<Integer<uint16_t, 0, 65535> > count_sync_out_of_memory;
+ Optional<Integer<uint16_t, 0, 65535> > count_of_sync_reboots;
+ Optional<AppLevels> app_level;
+
+ public:
+ UsageAndErrorCounts();
+ ~UsageAndErrorCounts();
+ explicit UsageAndErrorCounts(const Json::Value* value__);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+
+ private:
+ bool Validate() const;
+};
+
+struct ConsentRecords : CompositeType {
+ public:
+ Optional<ConsentGroups> consent_groups;
+ Optional<ConsentGroups> external_consent_status_groups;
+ Optional<Enum<Input> > input;
+ Optional<String<1, 255> > time_stamp;
+ int64_t consent_last_updated;
+ int64_t ext_consent_last_updated;
+
+ public:
+ ConsentRecords();
+ ~ConsentRecords();
+ explicit ConsentRecords(const Json::Value* value__);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+
+ private:
+ bool Validate() const;
+};
+
+struct DeviceParams : CompositeType {
+ public:
+ Optional<String<0, 255> > hardware;
+ Optional<Nullable<String<0, 255> > > firmware_rev;
+ Optional<String<0, 255> > os;
+ Optional<String<0, 255> > os_version;
+ Optional<Nullable<String<0, 255> > > carrier;
+ Optional<UserConsentRecords> user_consent_records;
+ Optional<Integer<uint8_t, 0, 255> > max_number_rfcom_ports;
+ Optional<String<0, 255> > connection_type;
+
+ public:
+ DeviceParams();
+ ~DeviceParams();
+ explicit DeviceParams(const Json::Value* value__);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+
+ private:
+ bool Validate() const;
+};
+
+struct PolicyTable : CompositeType {
+ public:
+ ApplicationPoliciesSection app_policies_section;
+ FunctionalGroupings functional_groupings;
+ Optional<ConsumerFriendlyMessages> consumer_friendly_messages;
+ ModuleConfig module_config;
+ Optional<ModuleMeta> module_meta;
+ Optional<UsageAndErrorCounts> usage_and_error_counts;
+ Optional<DeviceData> device_data;
+
+ public:
+ PolicyTable();
+ PolicyTable(const ApplicationPoliciesSection& app_policies_section,
+ const FunctionalGroupings& functional_groupings,
+ const ConsumerFriendlyMessages& consumer_friendly_messages,
+ const ModuleConfig& module_config);
+ ~PolicyTable();
+ explicit PolicyTable(const Json::Value* value__);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+
+ private:
+ bool Validate() const;
+};
+
+struct Table : CompositeType {
+ public:
+ PolicyTable policy_table;
+
+ public:
+ Table();
+ explicit Table(const PolicyTable& policy_table);
+ ~Table();
+ explicit Table(const Json::Value* value__);
+ Json::Value ToJsonValue() const;
+ bool is_valid() const;
+ bool is_initialized() const;
+ bool struct_empty() const;
+ void ReportErrors(rpc::ValidationReport* report__) const;
+ virtual void SetPolicyTableType(PolicyTableType pt_type);
+
+ private:
+ bool Validate() const;
+};
+} // namespace policy_table_interface_base
+} // namespace rpc
+
+#endif // SRC_COMPONENTS_POLICY_INCLUDE_POLICY_POLICY_TABLE_TYPES_H_
diff --git a/src/components/policy/policy_external/include/policy/policy_table_interface_ext.xml b/src/components/policy/policy_external/include/policy/policy_table_interface_ext.xml
new file mode 100644
index 0000000000..91518f8f6e
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/policy_table_interface_ext.xml
@@ -0,0 +1,284 @@
+<?xml version="1.0" standalone="no"?>
+<?xml-stylesheet type="text/xml" href="protocol2html.xsl"?>
+
+<interface name="policy table interface base" version="0.0"
+ date="2014-01-23">
+
+ <!-- Common parameters start -->
+ <enum name="Priority">
+ <element name="EMERGENCY" />
+ <element name="NAVIGATION" />
+ <element name="VOICECOM" />
+ <element name="COMMUNICATION" />
+ <element name="NORMAL" />
+ <element name="NONE" />
+ </enum>
+
+ <enum name="HmiLevel">
+ <element name="BACKGROUND" />
+ <element name="FULL" />
+ <element name="LIMITED" />
+ <element name="NONE" />
+ </enum>
+
+ <enum name="Parameter">
+ <element name="gps" />
+ <element name="speed" />
+ <element name="engineTorque" />
+ <element name="externalTemperature" />
+ <element name="fuelLevel" />
+ <element name="fuelLevel_State" />
+ <element name="headLampStatus" />
+ <element name="instantFuelConsumption" />
+ <element name="odometer" />
+ <element name="tirePressure" />
+ <element name="wiperStatus" />
+ <element name="vin" />
+ <element name="accPedalPosition" />
+ <element name="beltStatus" />
+ <element name="driverBraking" />
+ <element name="prndl" />
+ <element name="rpm" />
+ <element name="steeringWheelAngle" />
+ <element name="myKey" />
+ <element name="airbagStatus" />
+ <element name="bodyInformation" />
+ <element name="clusterModeStatus" />
+ <element name="deviceStatus" />
+ <element name="emergencyEvent" />
+ <element name="eCallInfo" />
+ <element name="abs_State" />
+ <element name="turnSignal" />
+ <element name="fuelRange" />
+ <element name="tirePressureValue" />
+ <element name="tpms" />
+ </enum>
+
+ <enum name="AppHMIType">
+ <element name="DEFAULT" />
+ <element name="COMMUNICATION" />
+ <element name="MEDIA" />
+ <element name="MESSAGING" />
+ <element name="NAVIGATION" />
+ <element name="INFORMATION" />
+ <element name="SOCIAL" />
+ <element name="BACKGROUND_PROCESS" />
+ <element name="TESTING" />
+ <element name="SYSTEM" />
+ </enum>
+ <!-- Common parameters end -->
+
+ <!-- app_policies section start -->
+
+ <typedef name="Strings" type="String" maxlength="255" array="true"
+ maxsize="255" />
+
+ <typedef name="AppHMITypes" type="AppHMIType" array="true"
+ maxsize="255" />
+
+ <struct name="ApplicationParams">
+ <param name="groups" type="Strings" />
+ <param name="nicknames" type="Strings" mandatory="false" />
+ <param name="preconsented_groups" type="Strings" mandatory="false" />
+ <param name="AppHMIType" type="AppHMITypes" mandatory="false" />
+ <param name="priority" type="Priority" />
+ <param name="default_hmi" type="HmiLevel" />
+ <param name="keep_context" type="Boolean" />
+ <param name="steal_focus" type="Boolean" />
+ <param name="memory_kb" type="Integer" minvalue="1" maxvalue="65225" mandatory="false"/>
+ <param name="watchdog_timer_ms" type="Integer" minvalue="1"
+ maxvalue="65225" mandatory="false"/>
+ <param name="certificate" type="String" minlength="0" maxlength="255"
+ mandatory="false" />
+ </struct>
+
+ <typedef name="HmiLevels" type="HmiLevel" array="true"
+ maxsize="4" />
+ <typedef name="Parameters" type="Parameter" array="true"
+ maxsize="24" />
+
+ <struct name="RpcParameters">
+ <!-- maxsizes are equal to number of currently known elements of
+ given type -->
+ <param name="hmi_levels" type="HmiLevels" />
+ <param name="parameters" type="Parameters" mandatory="false" />
+ </struct>
+
+ <!-- maxsizes are equal to number of currently known elements of given
+ type -->
+ <typedef name="Rpc" type="RpcParameters" map="true" maxsize="50" null_values_allowed="true" />
+
+ <struct name="Rpcs">
+ <param name="user_consent_prompt" type="String" minlegth="1"
+ maxlength="255" mandatory="false"/>
+ <param name="rpcs" type="Rpc" null_values_allowed="true"/>
+ </struct>
+ <!-- app_policies section end -->
+
+ <!-- module_config section start -->
+ <!-- minlenght="10" since minimum expected is "http://a.b" -->
+ <typedef name="URL" type="String" minlength="10" maxlength="255"
+ array="true" minsize="1" maxsize="255" />
+
+ <typedef name="URLList" type="URL" map="true" minsize="1"
+ maxsize="255" />
+
+ <!-- max number of services is limited to 255 according to protocol specification -->
+ <typedef name="ServiceEndpoints" type="URLList" map="true"
+ minsize="1" maxsize="255" />
+
+ <typedef name="NumberOfNotificationsPerMinute" type="Integer"
+ map="true" maxsize="6" minvalue="0" maxvalue="255" />
+
+ <typedef name="SecondsBetweenRetries" type="Integer" array="true"
+ maxsize="10" minvalue="1" maxvalue="1000" />
+
+ <struct name="ModuleConfig">
+ <param name="device_certificates" type="String" minlength="1" maxlength="100" mandatory="false" map="true" minsize="1" maxsize="255" />
+ <param name="preloaded_pt" type="Boolean" mandatory="false" />
+ <param name="exchange_after_x_ignition_cycles" type="Integer"
+ maxvalue="255" />
+ <param name="exchange_after_x_kilometers" type="Integer"
+ maxvalue="4294967296" />
+ <param name="exchange_after_x_days" type="Integer"
+ maxvalue="255" />
+ <param name="timeout_after_x_seconds" type="Integer"
+ maxvalue="65535" />
+ <param name="seconds_between_retries" type="SecondsBetweenRetries" />
+ <param name="endpoints" type="ServiceEndpoints" />
+ <param name="notifications_per_minute_by_priority" type="NumberOfNotificationsPerMinute" />
+ <param name="vehicle_make" type="String" maxlength="100"
+ mandatory="false" />
+ <param name="vehicle_model" type="String" maxlength="100"
+ mandatory="false" />
+ <param name="vehicle_year" type="String" minlength="4" maxlength="4"
+ mandatory="false" />
+ </struct>
+ <!-- module_config section end -->
+
+ <!-- consumer_friendly_messages section start -->
+ <struct name="MessageString">
+ <param name="line1" type="String" maxlength="255"
+ mandatory="false" />
+ <param name="line2" type="String" maxlength="255"
+ mandatory="false" />
+ <param name="tts" type="String" maxlength="65535" mandatory="false" />
+ <param name="label" type="String" maxlength="255"
+ mandatory="false" />
+ <param name="textBody" type="String" maxlength="500"
+ mandatory="false" />
+ </struct>
+
+ <typedef name="Languages" map="true" type="MessageString"
+ maxsize="500" mandatory="false" />
+
+ <struct name="MessageLanguages">
+ <param name="languages" type="Languages" />
+ </struct>
+
+ <typedef name="Messages" map="true" type="MessageLanguages"
+ maxsize="255" />
+
+ <struct name="ConsumerFriendlyMessages">
+ <param name="version" type="String" maxlength="100" />
+ <param name="messages" type="Messages" mandatory="false" />
+ </struct>
+ <!-- consumer_friendly_messages section end -->
+
+ <!-- module_meta section start -->
+ <struct name="ModuleMeta">
+ <param name="ccpu_version" type="String" maxlength="250" mandatory="false"/>
+ <param name="language" type="String" maxlength="250" mandatory="false"/>
+ <param name="wers_country_code" type="String" maxlength="250" mandatory="false"/>
+ <param name="pt_exchanged_at_odometer_x" type="Integer" minvalue="0" maxvalue="65535" mandatory="false"/>
+ <param name="pt_exchanged_x_days_after_epoch" type="Integer" minvalue="0" maxvalue="65535" mandatory="false"/>
+ <param name="ignition_cycles_since_last_exchange" type="Integer" minvalue="0" maxvalue="65535" mandatory="false"/>
+ <param name="vin" type="String" maxlength="250" mandatory="false"/>
+ </struct>
+ <!-- module_meta section end -->
+
+ <!-- usage_and_error_counts section start -->
+ <struct name="AppLevel">
+ <param name="minutes_in_hmi_full" type="Integer" minvalue="0" maxvalue="65535" />
+ <param name="app_registration_language_gui" type="String" minlength="1" maxlength="10" />
+ <param name="app_registration_language_vui" type="String" minlength="1" maxlength="10" />
+ <param name="count_of_rfcom_limit_reached" type="Integer" minvalue="0" maxvalue="65535" />
+ <param name="minutes_in_hmi_limited" type="Integer" minvalue="0" maxvalue="65535" />
+ <param name="minutes_in_hmi_background" type="Integer" minvalue="0" maxvalue="65535" />
+ <param name="minutes_in_hmi_none" type="Integer" minvalue="0" maxvalue="65535" />
+ <param name="count_of_user_selections" type="Integer" minvalue="0" maxvalue="65535" />
+ <param name="count_of_rejections_sync_out_of_memory" type="Integer" minvalue="0" maxvalue="65535" />
+ <param name="count_of_rejections_nickname_mismatch" type="Integer" minvalue="0" maxvalue="65535" />
+ <param name="count_of_rejections_duplicate_name" type="Integer" minvalue="0" maxvalue="65535" />
+ <param name="count_of_rejected_rpc_calls" type="Integer" minvalue="0" maxvalue="65535" />
+ <param name="count_of_rpcs_sent_in_hmi_none" type="Integer" minvalue="0" maxvalue="65535" />
+ <param name="count_of_removals_for_bad_behavior" type="Integer" minvalue="0" maxvalue="65535" />
+ <param name="count_of_run_attempts_while_revoked" type="Integer" minvalue="0" maxvalue="65535" />
+ </struct>
+
+ <typedef name="AppLevels" type="AppLevel" map="true"
+ maxsize="255" />
+
+ <struct name="UsageAndErrorCounts">
+ <param name="count_of_iap_buffer_full" type="Integer" minvalue="0" maxvalue="65535" mandatory="false" />
+ <param name="count_sync_out_of_memory" type="Integer" minvalue="0" maxvalue="65535" mandatory="false" />
+ <param name="count_of_sync_reboots" type="Integer" minvalue="0" maxvalue="65535" mandatory="false" />
+ <param name="app_level" type="AppLevels" mandatory="false" />
+ </struct>
+ <!-- usage_and_error_counts section end -->
+
+ <!-- device_data section start -->
+ <enum name="Input" scope="internal">
+ <element name="GUI" />
+ <element name="VUI" />
+ </enum>
+
+ <typedef name="ConsentGroups" scope="internal" type="Boolean" map="true" maxsize="255" mandatory="false"/>
+
+ <struct name="ConsentRecords" scope="internal">
+ <param name="consent_groups" type="ConsentGroups" mandatory="false"/>
+ <param name="input" type="Input" mandatory="false" />
+ <param name="time_stamp" type="String" maxlength="255" mandatory="false" />
+ </struct>
+
+ <typedef name="UserConsentRecords" scope="internal" map="true" type="ConsentRecords" minsize="0" maxsize="1000"/>
+
+ <struct name="DeviceParams" scope="internal">
+ <param name="hardware" type="String" maxlength="255" mandatory="false"/>
+ <param name="firmware_rev" type="String" maxlength="255" nullable="true" mandatory="false"/>
+ <param name="os" type="String" maxlength="255" mandatory="false"/>
+ <param name="os_version" type="String" maxlength="255" mandatory="false"/>
+ <param name="carrier" type="String" maxlength="255" nullable="true" mandatory="false"/>
+ <param name="user_consent_records" type="UserConsentRecords" mandatory="false"/>
+ <param name="max_number_rfcom_ports" type="Integer" maxvalue="255" mandatory="false"/>
+ </struct>
+ <!-- device_data section end -->
+
+ <!-- policy_table section start -->
+ <typedef name="ApplicationPolicies" map="true" type="ApplicationParams"
+ null_values_allowed="true" minsize="1" maxsize="1000" />
+
+ <typedef name="FunctionalGroupings" map="true" type="Rpcs"
+ minsize="1" maxsize="255" />
+
+ <typedef name="DeviceData" map="true" type="DeviceParams"
+ maxsize="255" />
+
+ <struct name="PolicyTable">
+ <!-- maxsize for app_policies can be changed, if necessary -->
+ <param name="app_policies" type="ApplicationPolicies" />
+ <param name="functional_groupings" type="FunctionalGroupings" />
+ <param name="consumer_friendly_messages" type="ConsumerFriendlyMessages" />
+ <param name="module_config" type="ModuleConfig" />
+ <param name="module_meta" type="ModuleMeta" mandatory="false"/>
+ <param name="usage_and_error_counts" type="UsageAndErrorCounts" mandatory="false" />
+ <param name="device_data" type="DeviceData" mandatory="false" />
+ </struct>
+ <!-- policy_table section end -->
+
+ <!-- Root element -->
+ <struct name="Table">
+ <param name="policy_table" type="PolicyTable" />
+ </struct>
+
+</interface>
diff --git a/src/components/policy/policy_external/include/policy/policy_types.h b/src/components/policy/policy_external/include/policy/policy_types.h
new file mode 100644
index 0000000000..eff8cfdf7b
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/policy_types.h
@@ -0,0 +1,507 @@
+/*
+ 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TYPES_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TYPES_H_
+
+#include <algorithm>
+#include <string>
+#include <vector>
+#include <map>
+#include <set>
+#include <utility>
+#include "utils/shared_ptr.h"
+#include "utils/helpers.h"
+namespace policy {
+
+// TODO(PV): specify errors
+enum PolicyErrorEnum {};
+
+const std::string kDefaultDeviceMacAddress = "00:00:00:00:00:00";
+const std::string kDefaultDeviceName = "MyDevice";
+const std::string kDefaultDeviceConnectionType = "UNKNOWN";
+
+/**
+ * @brief Constants for special ids in application policies section of
+ * policy table
+ */
+const std::string kPreDataConsentId = "pre_DataConsent";
+const std::string kDefaultId = "default";
+const std::string kDeviceId = "device";
+const std::string kPrimary = "rc_primaryDevice";
+
+/*
+ *@brief Policy Services specifies Users of Updates
+ * received from cloud through mobile device
+ */
+enum PolicyServiceTypes { SERVICE_NONE = 0, IVSU = 0x04, POLICY = 0x07 };
+
+/*
+ * @brief Status of policy table update
+ */
+enum PolicyTableStatus {
+ StatusUpToDate = 0,
+ StatusUpdatePending,
+ StatusUpdateRequired,
+ StatusUnknown
+};
+
+// Code generator uses String class name, so this typedef was renamed to PTSring
+typedef std::string PTString;
+typedef std::vector<uint8_t> BinaryMessage;
+typedef utils::SharedPtr<BinaryMessage> BinaryMessageSptr;
+
+typedef std::string HMILevel;
+typedef std::string Parameter;
+typedef std::string RpcName;
+typedef std::set<std::string> RPCParams;
+
+typedef std::map<std::string, std::set<policy::HMILevel> > HMIPermissions;
+struct ParameterPermissions
+ : std::map<std::string, std::set<policy::Parameter> > {
+ ParameterPermissions()
+ : any_parameter_allowed(false)
+ , any_parameter_disallowed_by_user(false)
+ , any_parameter_disallowed_by_policy(false) {}
+ bool any_parameter_allowed;
+ bool any_parameter_disallowed_by_user;
+ bool any_parameter_disallowed_by_policy;
+};
+
+struct RpcPermissions {
+ HMIPermissions hmi_permissions;
+ ParameterPermissions parameter_permissions;
+};
+
+typedef std::map<RpcName, RpcPermissions> Permissions;
+
+/**
+ * @brief Typedef for use with AllowApp request/notification
+ */
+typedef std::vector<std::string> PermissionsList;
+
+/**
+ * @brief Typedef for getting initial application data, e.g. nickname list
+ */
+typedef std::vector<std::string> StringArray;
+
+enum PermitResult { kRpcAllowed = 0, kRpcDisallowed, kRpcUserDisallowed };
+
+/**
+ * @struct Stores result of check:
+ * if HMI Level was allowed for RPC to work in
+ * and list of parameters allowed for RPC if specified in PT.
+ */
+struct CheckPermissionResult {
+ CheckPermissionResult() : hmi_level_permitted(kRpcDisallowed) {}
+
+ PermitResult hmi_level_permitted;
+ RPCParams list_of_allowed_params;
+ RPCParams list_of_disallowed_params;
+ RPCParams list_of_undefined_params;
+
+ bool HasParameter(const PTString& parameter) {
+ const bool is_allowed =
+ helpers::in_range(list_of_allowed_params, parameter);
+ const bool is_disallowed =
+ helpers::in_range(list_of_disallowed_params, parameter);
+ const bool is_undefined =
+ helpers::in_range(list_of_undefined_params, parameter);
+
+ return is_allowed || is_disallowed || is_undefined;
+ }
+
+ bool DisallowedInclude(const RPCParams& parameters) {
+ if (parameters.empty()) {
+ return false;
+ }
+ return std::includes(list_of_disallowed_params.begin(),
+ list_of_disallowed_params.end(),
+ parameters.begin(),
+ parameters.end());
+ }
+
+ bool IsAnyAllowed(const RPCParams& parameters) {
+ if (parameters.empty()) {
+ return true;
+ }
+ return list_of_allowed_params.end() !=
+ std::find_first_of(list_of_allowed_params.begin(),
+ list_of_allowed_params.end(),
+ parameters.begin(),
+ parameters.end());
+ }
+};
+
+/**
+ @struct Holds Url string and optional policy app id.
+ */
+struct EndpointData {
+ explicit EndpointData(const std::string& url_string = "")
+ : app_id("default") {
+ if (false == url_string.empty()) {
+ url.push_back(url_string);
+ }
+ }
+ std::vector<std::string> url;
+ std::string app_id;
+};
+
+typedef std::vector<EndpointData> EndpointUrls;
+
+/**
+ * @brief Struct contains device data to be used for dialogs, generation of IDs
+ */
+struct DeviceParams {
+ DeviceParams()
+ : device_name(kDefaultDeviceName)
+ , device_mac_address(kDefaultDeviceMacAddress)
+ , device_connection_type(kDefaultDeviceConnectionType)
+ , device_handle(0) {}
+
+ std::string device_name;
+ std::string device_mac_address;
+ std::string device_connection_type;
+ uint32_t device_handle;
+};
+
+/**
+ * @brief User consent for device data usage
+ */
+enum DeviceConsent {
+ kDeviceAllowed = 0,
+ kDeviceDisallowed,
+ kDeviceHasNoConsent
+};
+
+/**
+ * @brief Struct contains parameters, which can be received during application
+ * registration and should be stored in policy table
+ */
+struct DeviceInfo {
+ DeviceInfo() : max_number_rfcom_ports(0) {}
+
+ std::string hardware;
+ std::string firmware_rev;
+ std::string os;
+ std::string os_ver;
+ std::string carrier;
+ uint32_t max_number_rfcom_ports;
+ std::string connection_type;
+
+ void AdoptDeviceType(const std::string& deviceType) {
+ connection_type = "USB_serial_number";
+ using namespace helpers;
+ static const std::string bluetooth("BLUETOOTH");
+ static const std::string wifi("WIFI");
+ if (Compare<std::string, EQ, ONE>(deviceType, bluetooth, wifi)) {
+ connection_type.assign("BTMAC");
+ }
+ }
+};
+
+/**
+ * @brief User consent for functional group
+ */
+enum GroupConsent { kGroupAllowed = 0, kGroupDisallowed, kGroupUndefined };
+
+/**
+ * @brief Contains user permission for RPC functional group with specific name
+ * and id from DB
+ */
+struct FunctionalGroupPermission {
+ FunctionalGroupPermission() : group_id(0), state(kGroupUndefined) {}
+
+ bool operator==(const FunctionalGroupPermission& rhs) {
+ if (this->group_id == rhs.group_id &&
+ this->group_alias == rhs.group_alias &&
+ this->group_name == rhs.group_name) {
+ return true;
+ }
+ return false;
+ }
+
+ std::string group_alias;
+ std::string group_name;
+ int32_t group_id;
+ GroupConsent state;
+};
+
+/**
+ * @brief Stores data to be sent to HMI on application permissions change
+ */
+struct AppPermissions {
+ AppPermissions(const std::string& app_id)
+ : application_id(app_id)
+ , isAppPermissionsRevoked(false)
+ , appRevoked(false)
+ , appPermissionsConsentNeeded(false)
+ , appUnauthorized(false)
+ , requestTypeChanged(false) {}
+
+ std::string application_id;
+ bool isAppPermissionsRevoked;
+ std::vector<policy::FunctionalGroupPermission> appRevokedPermissions;
+ bool appRevoked;
+ bool appPermissionsConsentNeeded;
+ bool appUnauthorized;
+ bool isSDLAllowed;
+ std::string priority;
+ DeviceParams deviceInfo;
+ bool requestTypeChanged;
+ std::vector<std::string> requestType;
+};
+
+/**
+ * @brief Contains parameters for user-defined consent for appication
+ * functional groups on given device
+ */
+struct PermissionConsent {
+ std::string device_id;
+ std::string policy_app_id;
+ std::vector<FunctionalGroupPermission> group_permissions;
+ std::string consent_source;
+};
+
+/**
+ * @brief Contain data for GetUserFriendyMessage response
+ */
+struct UserFriendlyMessage {
+ std::string message_code;
+ std::string tts;
+ std::string label;
+ std::string line1;
+ std::string line2;
+ std::string text_body;
+};
+
+/**
+ * @brief Types of functional groups in policy table
+ */
+enum GroupType {
+ kTypeDefault = 0, // groups assigned to 'default' permissions section
+ kTypeAllowed, // groups allowed by user for specific application
+ kTypeDisallowed, // groups disallowed by user for specific application
+ kTypeUnconsented, // groups disallowed by default but consent may be changed
+ // by user
+ kTypePreconsented, // groups allowed for specific application without
+ // user consent by default (could be changed by user)
+ kTypeGeneral, // groups assigned to specific application
+ kTypePreDataConsented, // groups assigned to 'pre_DataConsent' permissions
+ // section
+ kTypeDevice // groups assigned to 'device' permissions section
+};
+
+/**
+ * @brief Array of functional group id from DB
+ */
+typedef std::vector<int32_t> FunctionalGroupIDs;
+
+/**
+ * @brief Array of functional group ids sorted by types
+ */
+typedef std::map<GroupType, FunctionalGroupIDs> FunctionalIdType;
+
+/**
+ * @brief Array of functional group ids binded to user_consent_prompt (e.g.
+ * VehicleData) and group name (e.g. VehicleData-4)
+ */
+typedef std::map<uint32_t, std::pair<std::string, std::string> >
+ FunctionalGroupNames;
+
+/**
+ * @brief Array of device ids, which are an identifiers in policy table
+ */
+typedef std::vector<std::string> DeviceIds;
+
+/**
+ * @brief Counters that calculated on receiving of succesful update
+ */
+enum Counters { KILOMETERS, DAYS_AFTER_EPOCH };
+
+/**
+ * @struct Vehicle information
+ */
+struct VehicleInfo {
+ std::string vehicle_make;
+ std::string vehicle_model;
+ std::string vehicle_year;
+};
+
+/**
+ * @brief The MetaInfo information
+ */
+struct MetaInfo {
+ std::string ccpu_version;
+ std::string wers_country_code;
+ std::string language;
+};
+
+/**
+ * @brief The index of the application, the index of its URL
+ * and the policy application id from the Endpoints vector
+ * that will be sent on the next OnSystemRequest retry sequence
+ */
+struct RetrySequenceURL {
+ uint32_t app_idx_;
+ uint32_t url_idx_;
+ std::string policy_app_id_;
+ RetrySequenceURL(uint32_t app, uint32_t url, const std::string& app_id)
+ : app_idx_(app), url_idx_(url), policy_app_id_(app_id) {}
+ RetrySequenceURL() : app_idx_(0), url_idx_(0) {}
+};
+
+/**
+ * @brief Index of the application, index of its URL
+ * from the Endpoints vector
+ */
+typedef std::pair<uint32_t, uint32_t> AppIdURL;
+
+enum EntityStatus { kStatusOn, kStatusOff };
+
+enum ReturnValue { kZero, kNonZero };
+
+/**
+ * @brief The ExternalConsentStatusItem struct represents customer connectivity
+ * settings
+ * item
+ */
+struct ExternalConsentStatusItem {
+ ExternalConsentStatusItem(const uint32_t type,
+ const uint32_t id,
+ const EntityStatus status)
+ : entity_type_(type), entity_id_(id), status_(status) {}
+
+ ExternalConsentStatusItem() {}
+
+ ExternalConsentStatusItem operator=(const ExternalConsentStatusItem& rhs) {
+ this->entity_id_ = rhs.entity_id_;
+ this->entity_type_ = rhs.entity_type_;
+ this->status_ = rhs.status_;
+ return *this; // calls copy constructor
+ }
+
+ bool operator==(const ExternalConsentStatusItem& rhs) const {
+ return (entity_type_ == rhs.entity_type_) && (entity_id_ == rhs.entity_id_);
+ }
+
+ bool operator<(const ExternalConsentStatusItem& rhs) const {
+ return (entity_type_ < rhs.entity_type_) || (entity_id_ < rhs.entity_id_);
+ }
+
+ uint32_t entity_type_;
+ uint32_t entity_id_;
+ EntityStatus status_;
+};
+
+struct ExternalConsentStatusItemSorter {
+ bool operator()(const ExternalConsentStatusItem& lhs,
+ const ExternalConsentStatusItem& rhs) const {
+ return (lhs.entity_type_ < rhs.entity_type_) ||
+ (lhs.entity_id_ < rhs.entity_id_);
+ }
+};
+
+/**
+ * @brief Customer connectivity settings status
+ */
+typedef std::set<ExternalConsentStatusItem, ExternalConsentStatusItemSorter>
+ ExternalConsentStatus;
+
+/**
+ * @brief GroupsByExternalConsentStatus represents list of group names, which
+ * has mapped ExternalConsent item (entity type + entity id) in their
+ * disallowed_by_external_consent_ containers. Boolean value represents
+ * whether ExternalConsent item has been found in
+ * disallowed_by_external_consent_ON or in disallowed_by_external_consent_OFF
+ * container
+ */
+typedef std::map<ExternalConsentStatusItem,
+ std::vector<std::pair<std::string, bool> > >
+ GroupsByExternalConsentStatus;
+
+/**
+ * @brief GroupsNames represents groups names from policy table -> functional
+ * groupings groups container
+ */
+typedef std::set<std::string> GroupsNames;
+
+typedef std::string ApplicationId;
+typedef std::string DeviceId;
+
+/**
+ * @brief Link of device to application
+ */
+typedef std::pair<policy::DeviceId, policy::ApplicationId> Link;
+
+/**
+ * @brief Collection of links
+ */
+typedef std::set<Link> ApplicationsLinks;
+
+/**
+ * @brief Represents possible result codes for policy table update check
+ */
+enum PermissionsCheckResult {
+ RESULT_NO_CHANGES,
+ RESULT_APP_REVOKED,
+ RESULT_NICKNAME_MISMATCH,
+ RESULT_PERMISSIONS_REVOKED,
+ RESULT_CONSENT_NEEDED,
+ RESULT_CONSENT_NOT_REQIURED,
+ RESULT_PERMISSIONS_REVOKED_AND_CONSENT_NEEDED,
+ RESULT_REQUEST_TYPE_CHANGED
+};
+
+/**
+ * @brief Per application collection of results done by checking policy table
+ * update
+ */
+typedef std::set<std::pair<std::string, PermissionsCheckResult> >
+ CheckAppPolicyResults;
+
+/**
+ * @brief The ConsentPriorityType enum defined types of priority for group
+ * consents i.e. done by user or by external consents
+ */
+enum ConsentPriorityType { kUserConsentPrio, kExternalConsentPrio };
+
+/**
+ * @brief The ConsentProcessingPolicy enum defines policy for existing consents
+ * update i.e. based on user/external consents timestamps or overriden by
+ * external consents
+ */
+enum ConsentProcessingPolicy { kTimestampBased, kExternalConsentBased };
+
+} // namespace policy
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TYPES_H_
diff --git a/src/components/policy/policy_external/include/policy/pt_ext_representation.h b/src/components/policy/policy_external/include/policy/pt_ext_representation.h
new file mode 100644
index 0000000000..0aa284b707
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/pt_ext_representation.h
@@ -0,0 +1,347 @@
+/*
+ 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_PT_EXT_REPRESENTATION_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_PT_EXT_REPRESENTATION_H_
+
+#include "policy/pt_representation.h"
+
+namespace policy {
+
+enum StatisticsType {
+ S_NONE = 0,
+ S_IAP_BUFFER_FULL,
+ S_SYNC_OUT_OF_MEMORY,
+ S_SYNC_REBOOTS,
+ S_MINS_HMI_FULL,
+ S_MINS_HMI_LIMITED,
+ S_MINS_HMI_BACKGROUND,
+ S_MINS_HMI_NONE,
+ S_RFCOM_LIMIT_REACHED,
+ S_USER_SELECTIONS,
+ S_REJECTIONS_SYNC_OUT_OF_MEMORY,
+ S_REJECTIONS_NICKNAME_MISMATCH,
+ S_REJECTIONS_DUPLICATE_NAME,
+ S_REJECTED_RPC_CALLS,
+ S_RPCS_IN_HMI_NONE,
+ S_REMOVALS_MISBEHAVED,
+ S_RUN_ATTEMPTS_WHILE_REVOKED
+};
+
+enum LanguageType { L_NONE = 0, L_GUI, L_VUI };
+
+class PTExtRepresentation : public virtual PTRepresentation {
+ public:
+ virtual ~PTExtRepresentation() {}
+
+ /**
+ * @brief Is application allowed to send notifications while in
+ * Backgound or limited mode.
+ * @param app_id Application id
+ * @return bool Allowed/disallowed.
+ */
+ virtual bool CanAppKeepContext(const std::string& app_id) = 0;
+
+ /**
+ * @brief Is application allowed to move foreground at will?
+ * @param app_id Application id
+ * @return bool Allowed/disallowed.
+ */
+ virtual bool CanAppStealFocus(const std::string& app_id) = 0;
+
+ /**
+ * @brief Get default_hmi for given application
+ * @param policy_app_id Unique application id
+ * @param default_hmi Default HMI level for application or empty, if value was
+ * not set
+ * @return true, if succedeed, otherwise - false
+ */
+ virtual bool GetDefaultHMI(const std::string& policy_app_id,
+ std::string* default_hmi) = 0;
+
+ /**
+ * @brief Reset user consent for device data and applications permissions
+ * @return
+ */
+ virtual bool ResetUserConsent() = 0;
+
+ /**
+ * @brief Reset user consent for device data
+ * @return
+ */
+ virtual bool ResetDeviceConsents() = 0;
+
+ /**
+ * @brief Reset user consent for applications permissions
+ * @return
+ */
+ virtual bool ResetAppConsents() = 0;
+
+ /**
+ * @brief Get user permissions for device data usage
+ * @param device_id Generated or obtained id of device
+ * @param consented_groups Groups consented by user
+ * @param disallowed_groups Groups not consented by user
+ * @return true, if query was successfull, otherwise - false
+ */
+ virtual bool GetUserPermissionsForDevice(
+ const std::string& device_id,
+ StringArray* consented_groups = NULL,
+ StringArray* disallowed_groups = NULL) = 0;
+
+ /**
+ * @brief Gets list of groups permissions from policy table
+ * @param device_id Unique device id, which hosts specific application
+ * @param policy_app_id Unique application id
+ * @param group_types Group list sorted by permission status
+ * @return true, if query was successfull, otherwise - false
+ */
+ virtual bool GetPermissionsForApp(const std::string& device_id,
+ const std::string& policy_app_id,
+ FunctionalIdType* group_types) = 0;
+
+ /**
+ * @brief Get device groups and preconsented groups from policies section
+ * @param groups List of groups to be consented for device usage
+ * @param preconsented_groups List of preconsented groups for device usage
+ * @return true, if query was successful, otherwise - false
+ */
+ virtual bool GetDeviceGroupsFromPolicies(
+ policy_table::Strings* groups = NULL,
+ policy_table::Strings* preconsented_groups = NULL) = 0;
+
+ /**
+ * @brief Record information about mobile device in Policy Table.
+ * @param device_id Generated or obtained id of device
+ * @return bool Success of operation
+ */
+ virtual bool 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 = 0,
+ const std::string& connection_type = "") = 0;
+
+ /**
+ * @brief Sets user consent for particular mobile device,
+ * i.e. to use device for exchanging of Policy Table.
+ * @return bool Success of operation
+ */
+ virtual bool SetUserPermissionsForDevice(
+ const std::string& device_id,
+ const StringArray& consented_groups = StringArray(),
+ const StringArray& disallowed_gropus = StringArray()) = 0;
+
+ /**
+ * @brief Update Application Policies as reaction
+ * on User allowing/disallowing device this app is running on.
+ */
+ virtual bool ReactOnUserDevConsentForApp(const std::string& app_id,
+ bool is_device_allowed) = 0;
+
+ /**
+ * @brief Set user consent on functional groups
+ * @param permissions User consent on functional group
+ * @return true, if operation succedeed, otherwise - false
+ */
+ virtual bool SetUserPermissionsForApp(
+ const PermissionConsent& permissions) = 0;
+
+ /**
+ * @brief Counter for statistics information: adds 1 to existing number.
+ * @param type Type of statistics (errors, mins in mode etc)
+ * @return bool Success of operation
+ */
+ virtual bool IncreaseStatisticsData(StatisticsType type) = 0;
+
+ /**
+ * @brief Records information about what language
+ * application tried to register with.
+ * @param app_id Id of application
+ * @param type - language for UI/VR
+ * @param language Language
+ * @return bool Success of operation
+ */
+ virtual bool SetAppRegistrationLanguage(const std::string& app_id,
+ LanguageType type,
+ const std::string& language) = 0;
+
+ /**
+ * @brief Records information about head unit system to PT
+ * @return bool Success of operation
+ */
+ virtual bool SetMetaInfo(const std::string& ccpu_version,
+ const std::string& wers_country_code,
+ const std::string& language) = 0;
+
+ /**
+ * @brief Checks, if specific head unit is present in PT
+ * @return boot Suceess, if present, otherwise - false
+ */
+ virtual bool IsMetaInfoPresent() = 0;
+
+ /**
+ * @brief Kms pass since last successfull PT update
+ */
+ virtual int GetKmFromSuccessfulExchange() = 0;
+
+ /**
+ * @brief Days pass since last successfull PT update
+ */
+ virtual int GetDayFromScsExchange() = 0;
+
+ /**
+ * @brief Ignition cycles pass since last successfull PT update
+ */
+ virtual int GetIgnitionsFromScsExchange() = 0;
+
+ /**
+ * @brief Set current system language
+ * @param language System language
+ * @return true, if succedeed, otherwise - false
+ */
+ virtual bool SetSystemLanguage(const std::string& language) = 0;
+
+ /**
+ * Increments global counter
+ * @param type type of counter
+ */
+ virtual void Increment(const std::string& type) const = 0;
+
+ /**
+ * Increments counter of application
+ * @param app_id id application
+ * @param type type of counter
+ */
+ virtual void Increment(const std::string& app_id,
+ const std::string& type) const = 0;
+
+ /**
+ * Sets value of application information
+ * @param app_id id application
+ * @param type type of information
+ * @param value value of information
+ */
+ virtual void Set(const std::string& app_id,
+ const std::string& type,
+ const std::string& value) const = 0;
+
+ /**
+ * Adds value to stopwatch of application
+ * @param app_id id application
+ * @param type type of stopwatch
+ * @param seconds value for adding in seconds
+ */
+ virtual void Add(const std::string& app_id,
+ const std::string& type,
+ int seconds) const = 0;
+
+ virtual bool CountUnconsentedGroups(const std::string& policy_app_id,
+ const std::string& device_id,
+ int* result) const = 0;
+
+ /**
+ * @brief Gets functional group names and user_consent_prompts, if any
+ * @param Array to be filled with group ids, names and functional prompts
+ * @return true, if succeeded, otherwise - false
+ */
+ // TODO(AOleynik): Possibly, we can get rid of this method. Check this.
+ virtual bool GetFunctionalGroupNames(policy::FunctionalGroupNames& names) = 0;
+
+ /**
+ * @brief Set app policy to pre_DataConsented policy
+ * @param app_id Policy ID of application to be changed
+ * @return true, if succeeded, otherwise - false
+ */
+ virtual bool SetPredataPolicy(const std::string& app_id) = 0;
+
+ /**
+ * @brief Updates application policy to either pre_DataConsented or not
+ * @param app_id Policy Id of application to be checked
+ * @param is_pre_data True of False to setting app policy to be
+ * pre_DataConsented
+ * @return true, if succeeded, otherwise - false
+ */
+ virtual bool SetIsPredata(const std::string& app_id, bool is_pre_data) = 0;
+
+ /**
+ * @brief Removes unpaired devices
+ * @return true if success
+ */
+ virtual bool CleanupUnpairedDevices(const DeviceIds& device_ids) const = 0;
+
+ /**
+ * Sets flag of unpaired device
+ * @param device_id Unique device id
+ * @param unpaired True, if unpaired, otherwise - false
+ * @return true if success
+ */
+ virtual bool SetUnpairedDevice(const std::string& device_id,
+ bool unpaired) const = 0;
+
+ /**
+ * Gets list of unpaired devices
+ * @param device_ids output list
+ * @return true if success
+ */
+ virtual bool UnpairedDevicesList(DeviceIds* device_ids) const = 0;
+
+ /**
+ * @brief Remove application consent for particular group
+ * @param policy_app_id Unique application id
+ * @param functional_group_name Functional group name, which consents should
+ * be removed
+ * @return true, in case of success, otherwise - false
+ */
+ virtual bool RemoveAppConsentForGroup(
+ const std::string& policy_app_id,
+ const std::string& functional_group_name) const = 0;
+
+ /**
+ * @brief Saves external user consent settings status
+ * @param status external consent status
+ * @return true if succeeded, otherwise - false
+ */
+ virtual bool SaveExternalConsentStatus(
+ const ExternalConsentStatus& status) const = 0;
+
+ /**
+ * @brief Gets customer connectivity settings status
+ * @return external consent status
+ */
+ virtual ExternalConsentStatus GetExternalConsentStatus() const = 0;
+};
+} // namespace policy
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_PT_EXT_REPRESENTATION_H_
diff --git a/src/components/policy/policy_external/include/policy/pt_representation.h b/src/components/policy/policy_external/include/policy/pt_representation.h
new file mode 100644
index 0000000000..66a9218771
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/pt_representation.h
@@ -0,0 +1,328 @@
+/*
+ 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_PT_REPRESENTATION_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_PT_REPRESENTATION_H_
+
+#include <vector>
+#include <string>
+#include "policy/policy_types.h"
+#include "policy/policy_table/types.h"
+#include "policy/policy_settings.h"
+
+namespace policy_table = rpc::policy_table_interface_base;
+
+namespace policy {
+
+enum InitResult { NONE = 0, EXISTS, SUCCESS, FAIL };
+
+class PTRepresentation {
+ public:
+ virtual ~PTRepresentation() {}
+
+ /**
+ * @brief Check if specified RPC for specified application
+ * has permission to be executed in specified HMI Level
+ * and also its permitted params.
+ * @param app_id Id of application provided during registration
+ * @param hmi_level Current HMI Level of application
+ * @param rpc Name of RPC
+ * @params CheckPermissionResult containing flag if HMI Level is allowed
+ * and list of allowed params.
+ */
+ virtual void CheckPermissions(const PTString& app_id,
+ const PTString& hmi_level,
+ const PTString& rpc,
+ CheckPermissionResult& result) = 0;
+
+ /**
+ * @brief Returns true if Policy Table was not updated yet
+ * from preloaded pt file.
+ */
+ virtual bool IsPTPreloaded() = 0;
+
+ /**
+ * @brief GetLockScreenIcon allows to obtain lock screen icon url;
+ *
+ * @return url which point to the resourse where lock screen icon could be
+ *obtained.
+ */
+ virtual std::string GetLockScreenIconUrl() const = 0;
+
+ /**
+ * @brief Re-creates schema in DB, drops all data
+ * @return true, if succedeed, otherwise - false
+ */
+ virtual bool RefreshDB() = 0;
+ /**
+ * Gets number of ignition cycles before next update policy table
+ * @return number of ignition cycles
+ */
+ virtual int IgnitionCyclesBeforeExchange() = 0;
+
+ /**
+ * Gets value in kilometers before next update policy table
+ * @param current value in kilometers from the odometers
+ * @return value in kilometers
+ */
+ virtual int KilometersBeforeExchange(int current) = 0;
+
+ /**
+ * @brief Sets kilometers and days after epoch, that passed for recieved
+ * successful PT UPdate
+ */
+ virtual bool SetCountersPassedForSuccessfulUpdate(int kilometers,
+ int days_after_epoch) = 0;
+
+ /**
+ * Gets value in days before next update policy table
+ * @param current value in days after epoch
+ * @return value in days
+ */
+ virtual int DaysBeforeExchange(uint16_t current) = 0;
+
+ /**
+ * @brief Increment number of ignition cycles since last exchange by 1
+ */
+ virtual void IncrementIgnitionCycles() = 0;
+
+ /**
+ * @brief Reset number of ignition cycles since last exchange to 0
+ */
+ virtual void ResetIgnitionCycles() = 0;
+
+ /**
+ * @brief Returns timeout to wait for a response of PT update
+ * @return value in seconds
+ */
+ virtual int TimeoutResponse() = 0;
+
+ /**
+ * @brief Returns number of seconds between each try of sending PTS
+ * @param seconds Return value: array of 5 elements
+ * @return bool Success of operation
+ */
+ virtual bool SecondsBetweenRetries(std::vector<int>* seconds) = 0;
+
+ /**
+ * @brief Get information about vehicle
+ */
+ virtual const VehicleInfo GetVehicleInfo() const = 0;
+
+ /**
+ * @brief Allows to update 'vin' field in module_meta table.
+ *
+ * @param new 'vin' value.
+ *
+ * @return true in case when data has been successfully updated,
+ * false otherwise.
+ */
+ virtual bool SetVINValue(const std::string& value) = 0;
+
+ /**
+ * @brief Get message text for displaying/pronouncing for user
+ * dependent on language and context.
+ * @param msg_codes Context of message (Driver distraction, Grant permission
+ * etc)
+ * @param language Language of the message
+ * @return Array of appropriate messages parameters
+ */
+ virtual std::vector<UserFriendlyMessage> GetUserFriendlyMsg(
+ const std::vector<std::string>& msg_codes,
+ const std::string& language) = 0;
+
+ /**
+ * @brief Get list of URL to send PTS to
+ * @param service_type If URLs for specific service are preset,
+ * return them otherwise default URLs.
+ */
+ virtual EndpointUrls GetUpdateUrls(int service_type) = 0;
+
+ /**
+ * @brief Get allowed number of notifications
+ * depending on application priority.
+ * @param priority Priority of application
+ */
+ virtual int GetNotificationsNumber(const std::string& priority) = 0;
+
+ /**
+ * @brief Get priority for given application
+ * @param policy_app_id Unique application id
+ * @param priority Priority for application or empty, if value was not set
+ * @return true, if succedeed, otherwise - false
+ */
+ virtual bool GetPriority(const std::string& policy_app_id,
+ std::string* priority) = 0;
+
+ /**
+ * @brief Initialized Policy Table (load)
+ * @return bool Success of operation
+ */
+ virtual InitResult Init(const PolicySettings* settings) = 0;
+
+ /**
+ * @brief Close policy table
+ * @return bool Success of operation
+ */
+ virtual bool Close() = 0;
+
+ /**
+ * @brief Removes policy table content.
+ * @return bool Success of operation
+ */
+ virtual bool Clear() = 0;
+
+ /**
+ * Drops policy table (schema and content)
+ * @return true if successfully
+ */
+ virtual bool Drop() = 0;
+
+ /**
+ * @brief Get snapshot of Policy Table
+ * including app_policies, functional_groups,
+ * device_info, statistics, excluding user messages
+ * @return Generated structure for obtaining Json string.
+ */
+ virtual utils::SharedPtr<policy_table::Table> GenerateSnapshot() const = 0;
+
+ virtual bool Save(const policy_table::Table& table) = 0;
+
+ /**
+ * Gets flag updateRequired
+ * @return true if update is required
+ */
+ virtual bool UpdateRequired() const = 0;
+
+ /**
+ * Saves flag updateRequired
+ */
+ virtual void SaveUpdateRequired(bool value) = 0;
+
+ /*
+ Retrieves data from app_policies about app on its registration:
+ app_id - id of registered app; all outputs are filled in only if not null
+ output: nicknames Synonyms for application
+ output: app_types Section on HMI where app can appear (Navigation, Phone etc)
+ */
+ virtual bool GetInitialAppData(const std::string& app_id,
+ StringArray* nicknames = NULL,
+ StringArray* app_types = NULL) = 0;
+
+ /**
+ * Checks if the application is revoked
+ * @param app_id application id
+ * @return true if application is revoked
+ */
+ virtual bool IsApplicationRevoked(const std::string& app_id) const = 0;
+
+ /**
+ * @brief Get functional groupings from DB
+ * @param groups Known functional groupings
+ * @return true, if succeeded, otherwise - false
+ */
+ virtual bool GetFunctionalGroupings(
+ policy_table::FunctionalGroupings& groups) = 0;
+
+ /**
+ * Checks if the application is represented in policy table
+ * @param app_id application id
+ * @return true if application is represented in policy table
+ */
+ virtual bool IsApplicationRepresented(const std::string& app_id) const = 0;
+
+ /**
+ * Checks if the application has default policy
+ * @param app_id application id
+ * @return true if application has default policy
+ */
+ virtual bool IsDefaultPolicy(const std::string& app_id) const = 0;
+
+ /**
+ * Checks if the application has pre_data policy
+ * @param app_id application id
+ * @return true if application has pre_data policy
+ */
+ virtual bool IsPredataPolicy(const std::string& app_id) const = 0;
+
+ /**
+ * Sets default policy for application
+ * @param app_id application id
+ * @return true if success
+ */
+ virtual bool SetDefaultPolicy(const std::string& app_id) = 0;
+
+ /**
+ * @brief SaveApplicationCustomData allows to save specific data to database.
+ * This data is only for internal use.
+ * @param app_id the application id for which the data will be saved.
+ * @param is_revoked parameter to save.
+ * @param is_default parameter to save.
+ * @param is_predata parameter to save.
+ */
+ virtual bool SaveApplicationCustomData(const std::string& app_id,
+ bool is_revoked,
+ bool is_default,
+ bool is_predata) = 0;
+
+ virtual void WriteDb() = 0;
+
+ /**
+ * @brief RemoveDB allows to remove the database.
+ * It will either remove or do nothing in case file not exists or any other
+ * troubles are happens during this operation.
+ */
+ virtual void RemoveDB() const = 0;
+
+ /**
+ * @brief Checks if DB version is actual to current schema
+ * @return true if actual, otherwise - false
+ */
+ virtual bool IsDBVersionActual() const = 0;
+
+ /**
+ * @brief Updates DB version according to current schema
+ * @return true if success, otherwise - false
+ */
+ virtual bool UpdateDBVersion() const = 0;
+
+ protected:
+ const PolicySettings& get_settings() const {
+ DCHECK(settings_);
+ return *settings_;
+ }
+ const PolicySettings* settings_;
+};
+
+} // namespace policy
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_PT_REPRESENTATION_H_
diff --git a/src/components/policy/policy_external/include/policy/sql_pt_ext_queries.h b/src/components/policy/policy_external/include/policy/sql_pt_ext_queries.h
new file mode 100644
index 0000000000..b8f85ec7b1
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/sql_pt_ext_queries.h
@@ -0,0 +1,104 @@
+/*
+ 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_SQL_PT_EXT_QUERIES_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_SQL_PT_EXT_QUERIES_H_
+
+#include <string>
+
+namespace policy {
+namespace sql_pt_ext {
+
+extern const std::string kSelectKeepContext;
+extern const std::string kSelectStealFocus;
+extern const std::string kResetDeviceConsents;
+extern const std::string kResetAppConsents;
+extern const std::string kCountDeviceConsentGroup;
+extern const std::string kCountDevice;
+extern const std::string kSelectDeviceConsentedGroup;
+extern const std::string kUpdateDeviceConsentedGroup;
+extern const std::string kUpdateDevice;
+extern const std::string kInsertDeviceConsentedGroup;
+extern const std::string kInsertDevice;
+extern const std::string kSelectDeviceData;
+extern const std::string kSelectConsentGroup;
+extern const std::string kSelectExternalConsentStatusGroup;
+extern const std::string kInsertPreconsentedGroups;
+extern const std::string kSelectPreconsentedGroups;
+extern const std::string kDeletePreconsentedGroups;
+extern const std::string kSelectUsageAndErrorCount;
+extern const std::string kSelectAppLevels;
+extern const std::string kUpdateGlobalCounters;
+extern const std::string kInsertDeviceData;
+extern const std::string kDeleteDeviceData;
+extern const std::string kInsertConsentGroups;
+extern const std::string kInsertExternalConsentStatusGroups;
+extern const std::string kCountUnconsentedGroups;
+extern const std::string kSelectModuleMeta;
+extern const std::string kUpdateMetaParams;
+extern const std::string kUpdateModuleMetaVinParam;
+extern const std::string kSaveModuleMeta;
+extern const std::string kSelectMetaParams;
+extern const std::string kCountAppLevel;
+extern const std::string kUpdateGroupPermissions;
+extern const std::string kSelectDefaultHmi;
+extern const std::string kInsertApplication;
+extern const std::string kSelectFriendlyMsg;
+extern const std::string kCollectFriendlyMsg;
+extern const std::string kSelectAppGroupsId;
+extern const std::string kSelectConsentedGroupsId;
+extern const std::string kCountAppConsents;
+extern const std::string kSelectPreconsentedGroupsId;
+extern const std::string kSelectFunctionalGroupNames;
+extern const std::string kSelectAppPolicies;
+extern const std::string kUpdateMetaLanguage;
+extern const std::string kDeleteDeviceConsent;
+extern const std::string kDeleteAppGroupConsent;
+extern const std::string kSelectGroupId;
+extern const std::string kSelectApplicationIsPreData;
+extern const std::string kUpdateIsPredata;
+extern const std::string kHasAppPreloadedGroups;
+extern const std::string kUpdateUnpairedDevice;
+extern const std::string kSelectUnpairedDevices;
+extern const std::string kHasMsgLanguageCode;
+extern const std::string kDeletePreconsentedGroupsByApplicationId;
+extern const std::string kDeleteAppConsent;
+extern const std::string kSelectExternalConsentStatus;
+extern const std::string kInsertExternalConsentStatus;
+extern const std::string kDeleteExternalConsentEntities;
+extern const std::string kInsertExternalConsentEntity;
+extern const std::string kSelectExternalConsentEntity;
+
+} // namespace sql_pt_ext
+} // namespace policy
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_SQL_PT_EXT_QUERIES_H_
diff --git a/src/components/policy/policy_external/include/policy/sql_pt_ext_representation.h b/src/components/policy/policy_external/include/policy/sql_pt_ext_representation.h
new file mode 100644
index 0000000000..bd2097cfe3
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/sql_pt_ext_representation.h
@@ -0,0 +1,218 @@
+/*
+ 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_SQL_PT_EXT_REPRESENTATION_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_SQL_PT_EXT_REPRESENTATION_H_
+
+#include <string>
+#include "policy/sql_pt_representation.h"
+#include "policy/pt_ext_representation.h"
+
+namespace policy {
+
+class SQLPTExtRepresentation : public SQLPTRepresentation,
+ public PTExtRepresentation {
+ public:
+ SQLPTExtRepresentation();
+ explicit SQLPTExtRepresentation(bool in_memory);
+ bool CanAppKeepContext(const std::string& app_id);
+ bool CanAppStealFocus(const std::string& app_id);
+ bool GetDefaultHMI(const std::string& policy_app_id,
+ std::string* default_hmi);
+ bool ResetUserConsent();
+ bool ResetDeviceConsents();
+ bool ResetAppConsents();
+ bool GetUserPermissionsForDevice(const std::string& device_id,
+ StringArray* consented_groups = NULL,
+ StringArray* disallowed_groups = NULL);
+
+ bool GetPermissionsForApp(const std::string& device_id,
+ const std::string& policy_app_id,
+ FunctionalIdType* group_types);
+
+ bool GetDeviceGroupsFromPolicies(
+ policy_table::Strings* groups = NULL,
+ policy_table::Strings* preconsented_groups = NULL);
+ bool 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 = 0,
+ const std::string& connection_type = "");
+ bool SetUserPermissionsForDevice(
+ const std::string& device_id,
+ const StringArray& consented_groups = StringArray(),
+ const StringArray& disallowed_groups = StringArray());
+
+ bool ReactOnUserDevConsentForApp(const std::string& app_id,
+ bool is_device_allowed);
+
+ bool SetUserPermissionsForApp(const PermissionConsent& permissions);
+
+ std::vector<UserFriendlyMessage> GetUserFriendlyMsg(
+ const std::vector<std::string>& msg_codes, const std::string& language);
+
+ bool IncreaseStatisticsData(StatisticsType type) {
+ return true;
+ }
+ bool SetAppRegistrationLanguage(const std::string& app_id,
+ LanguageType type,
+ const std::string& language) {
+ return true;
+ }
+
+ bool SetMetaInfo(const std::string& ccpu_version,
+ const std::string& wers_country_code,
+ const std::string& language);
+
+ bool IsMetaInfoPresent();
+
+ bool SetSystemLanguage(const std::string& language);
+
+ int GetKmFromSuccessfulExchange() {
+ return true;
+ }
+ int GetDayFromScsExchange() {
+ return true;
+ }
+ int GetIgnitionsFromScsExchange() {
+ return true;
+ }
+
+ bool GetFunctionalGroupNames(FunctionalGroupNames& names);
+ bool CleanupUnpairedDevices(const DeviceIds& device_ids) const;
+
+ void Increment(const std::string& type) const;
+ void Increment(const std::string& app_id, const std::string& type) const;
+ void Set(const std::string& app_id,
+ const std::string& type,
+ const std::string& value) const;
+ void Add(const std::string& app_id,
+ const std::string& type,
+ int seconds) const;
+ bool SetDefaultPolicy(const std::string& app_id);
+ bool SetPredataPolicy(const std::string& app_id);
+ bool SetIsPredata(const std::string& app_id, bool is_pre_data);
+ bool IsPredataPolicy(const std::string& app_id) const;
+ bool SetUnpairedDevice(const std::string& device_id, bool unpaired) const;
+ bool UnpairedDevicesList(DeviceIds* device_ids) const;
+ bool RemoveAppConsentForGroup(const std::string& policy_app_id,
+ const std::string& functional_group_name) const;
+
+ virtual bool SetVINValue(const std::string& value);
+ bool SaveExternalConsentStatus(const ExternalConsentStatus& status) const;
+ ExternalConsentStatus GetExternalConsentStatus() const;
+
+ private:
+ enum ExternalConsentEntitiesType {
+ kExternalConsentEntitiesTypeOn,
+ kExternalConsentEntitiesTypeOff
+ };
+ void GatherModuleMeta(policy_table::ModuleMeta* meta) const;
+ void GatherPreconsentedGroup(const std::string& app_id,
+ policy_table::Strings* groups) const;
+ bool GatherUsageAndErrorCounts(
+ policy_table::UsageAndErrorCounts* counts) const;
+ bool GatherAppLevels(policy_table::AppLevels* apps) const;
+ void GatherDeviceData(policy_table::DeviceData* data) const;
+ void GatherConsentGroup(const std::string& device_id,
+ policy_table::UserConsentRecords* records) const;
+ bool GatherApplicationPoliciesSection(
+ policy_table::ApplicationPoliciesSection* policies) const;
+ bool SaveDeviceData(const policy_table::DeviceData& devices);
+ bool GatherConsumerFriendlyMessages(
+ policy_table::ConsumerFriendlyMessages* messages) const;
+ bool SaveConsentGroup(const std::string& device_id,
+ const policy_table::UserConsentRecords& records);
+ bool SaveApplicationPoliciesSection(
+ const policy_table::ApplicationPoliciesSection& policies);
+ bool SaveSpecificAppPolicy(
+ const policy_table::ApplicationPolicies::value_type& app);
+ bool SaveDevicePolicy(const policy_table::DevicePolicy& device);
+ bool SavePreconsentedGroup(const std::string& app_id,
+ const policy_table::Strings& groups);
+ bool SaveMessageString(const std::string& type,
+ const std::string& lang,
+ const policy_table::MessageString& strings);
+
+ virtual bool SaveUsageAndErrorCounts(
+ const policy_table::UsageAndErrorCounts& counts);
+
+ virtual bool SaveModuleMeta(const policy_table::ModuleMeta& meta);
+
+ bool SaveAppCounters(const policy_table::AppLevels& app_levels);
+
+ bool SaveGlobalCounters(const policy_table::UsageAndErrorCounts& counts);
+
+ bool IsExistAppLevel(const std::string& app_id) const;
+
+ bool GetAllAppGroups(const std::string& policy_app_id,
+ FunctionalGroupIDs& all_groups);
+
+ bool GetConsentedGroups(const std::string& policy_app_id,
+ const std::string& device_id,
+ FunctionalGroupIDs& allowed_groups,
+ FunctionalGroupIDs& disallowed_groups);
+
+ bool GetPreconsentedGroups(const std::string& policy_app_id,
+ FunctionalGroupIDs& preconsented_groups);
+
+ void FillFunctionalGroupPermissions(
+ FunctionalGroupIDs& ids,
+ FunctionalGroupNames& names,
+ GroupConsent state,
+ std::vector<FunctionalGroupPermission>& permissions);
+ bool CountUnconsentedGroups(const std::string& policy_app_id,
+ const std::string& device_id,
+ int* result) const;
+
+ /**
+ * @brief Checks, if there is message present with requested language in PT
+ * @param message Message name
+ * @param language Required message language
+ * @return True, if message with requested language is present, otherwise -
+ * false
+ */
+ bool IsMsgLanguagePresent(const std::string& message,
+ const std::string& language);
+
+ bool SaveExternalConsentEntities(
+ const int64_t group_id,
+ const policy_table::DisallowedByExternalConsentEntities& entities,
+ ExternalConsentEntitiesType type) const;
+};
+
+} // namespace policy
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_SQL_PT_EXT_REPRESENTATION_H_
diff --git a/src/components/policy/policy_external/include/policy/sql_pt_queries.h b/src/components/policy/policy_external/include/policy/sql_pt_queries.h
new file mode 100644
index 0000000000..685c84742f
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/sql_pt_queries.h
@@ -0,0 +1,148 @@
+/*
+ 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_SQL_PT_QUERIES_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_SQL_PT_QUERIES_H_
+
+#include <string>
+
+namespace policy {
+namespace sql_pt {
+
+extern const std::string kSelectPriority;
+extern const std::string kCreateSchema;
+extern const std::string kDropSchema;
+extern const std::string kDeleteData;
+extern const std::string kCheckPgNumber;
+extern const std::string kCheckDBIntegrity;
+extern const std::string kSelectRpc;
+extern const std::string kSelectPreloaded;
+extern const std::string kIsFirstRun;
+extern const std::string kSetNotFirstRun;
+extern const std::string kSelectEndpoint;
+extern const std::string kSelectLockScreenIcon;
+extern const std::string kSelectModuleConfig;
+extern const std::string kSelectEndpoints;
+extern const std::string kSelectNotificationsPerMin;
+extern const std::string kSelectNotificationsPerPriority;
+extern const std::string kSelectAppLevels;
+extern const std::string kSelectDeviceData;
+extern const std::string kSelectFunctionalGroups;
+extern const std::string kSelectAllRpcs;
+extern const std::string kSelectExternalConsentEntities;
+extern const std::string kSelectUserMsgsVersion;
+extern const std::string kSelectAppPolicies;
+extern const std::string kSelectAppGroups;
+extern const std::string kSelectNicknames;
+extern const std::string kSelectAppTypes;
+extern const std::string kSelectRequestTypes;
+extern const std::string kSelectSecondsBetweenRetries;
+extern const std::string kSelectIgnitionCycles;
+extern const std::string kSelectKilometers;
+extern const std::string kSelectDays;
+extern const std::string kSelectTimeoutResponse;
+extern const std::string kInsertFunctionalGroup;
+extern const std::string kInsertRpc;
+extern const std::string kInsertRpcWithParameter;
+extern const std::string kInsertApplication;
+extern const std::string kInsertAppGroup;
+extern const std::string kInsertNickname;
+extern const std::string kInsertAppType;
+extern const std::string kInsertRequestType;
+extern const std::string kInsertMessageType;
+extern const std::string kInsertLanguage;
+extern const std::string kInsertMessageString;
+extern const std::string kUpdateVersion;
+extern const std::string kUpdateModuleConfig;
+extern const std::string kInsertEndpoint;
+extern const std::string kInsertSecondsBetweenRetry;
+extern const std::string kInsertNotificationsByPriority;
+extern const std::string kInsertDeviceData;
+extern const std::string kInsertAppLevel;
+extern const std::string kDeleteSecondsBetweenRetries;
+extern const std::string kDeleteEndpoint;
+extern const std::string kDeleteAppLevel;
+extern const std::string kDeleteMessageString;
+extern const std::string kDeleteFunctionalGroup;
+extern const std::string kDeleteRpc;
+extern const std::string kDeleteExternalConsentEntities;
+extern const std::string kDeleteAppGroup;
+extern const std::string kDeleteApplication;
+extern const std::string kDeleteRequestType;
+extern const std::string kDeleteDevice;
+extern const std::string kIncrementIgnitionCycles;
+extern const std::string kResetIgnitionCycles;
+extern const std::string kUpdateFlagUpdateRequired;
+extern const std::string kSelectFlagUpdateRequired;
+extern const std::string kUpdateCountersSuccessfulUpdate;
+extern const std::string kSelectApplicationRevoked;
+extern const std::string kUpdateApplicationCustomData;
+extern const std::string kSelectApplicationRepresented;
+extern const std::string kSelectApplicationIsDefault;
+extern const std::string kUpdateIsDefault;
+extern const std::string kInsertInitData;
+extern const std::string kDeleteAppGroupByApplicationId;
+extern const std::string kInsertApplicationFull;
+extern const std::string kDeletePreconsentedGroupsByApplicationId;
+extern const std::string kSelectApplicationFull;
+extern const std::string kUpdatePreloaded;
+extern const std::string kUpdateRemoteControlDenied;
+extern const std::string kSelectRemoteControlDenied;
+extern const std::string kDeleteAppGroupPrimaryByApplicationId;
+extern const std::string kDeleteAppGroupNonPrimaryByApplicationId;
+extern const std::string kCollectFriendlyMsg;
+extern const std::string kSelectAppGroupsPrimary;
+extern const std::string kSelectAppGroupsNonPrimary;
+extern const std::string kSelectModuleTypes;
+extern const std::string kInsertAppGroupPrimary;
+extern const std::string kInsertAppGroupNonPrimary;
+extern const std::string kInsertModuleType;
+extern const std::string kInsertInteriorZone;
+extern const std::string kCountInteriorZones;
+extern const std::string kSelectInteriorZones;
+extern const std::string kDeleteInteriorZones;
+extern const std::string kInsertAccessModule;
+extern const std::string kSelectAccessModules;
+extern const std::string kDeleteAccessModules;
+extern const std::string kInsertRemoteRpc;
+extern const std::string kSelectRemoteRpcs;
+extern const std::string kDeleteRemoteRpc;
+extern const std::string kDeleteAppGroupPrimary;
+extern const std::string kDeleteAppGroupNonPrimary;
+extern const std::string kDeleteModuleTypes;
+extern const std::string kDeleteAllDevices;
+extern const std::string kSelectDBVersion;
+extern const std::string kUpdateDBVersion;
+} // namespace sql_pt
+} // namespace policy
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_SQL_PT_QUERIES_H_
diff --git a/src/components/policy/policy_external/include/policy/sql_pt_representation.h b/src/components/policy/policy_external/include/policy/sql_pt_representation.h
new file mode 100644
index 0000000000..b3ce0a69be
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/sql_pt_representation.h
@@ -0,0 +1,211 @@
+/*
+ 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_SQL_PT_REPRESENTATION_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_SQL_PT_REPRESENTATION_H_
+
+#include <string>
+#include <vector>
+#include "policy/pt_representation.h"
+#include "rpc_base/rpc_base.h"
+#include "policy/policy_table/types.h"
+
+namespace policy_table = rpc::policy_table_interface_base;
+
+namespace utils {
+namespace dbms {
+class SQLDatabase;
+} // namespace dbms
+} // namespace utils
+
+namespace policy {
+
+class SQLPTRepresentation : public virtual PTRepresentation {
+ public:
+ SQLPTRepresentation();
+ explicit SQLPTRepresentation(bool in_memory);
+ ~SQLPTRepresentation();
+ virtual void CheckPermissions(const PTString& app_id,
+ const PTString& hmi_level,
+ const PTString& rpc,
+ CheckPermissionResult& result);
+
+ virtual bool IsPTPreloaded();
+ virtual int IgnitionCyclesBeforeExchange();
+ virtual int KilometersBeforeExchange(int current);
+ virtual bool SetCountersPassedForSuccessfulUpdate(int kilometers,
+ int days_after_epoch);
+ virtual int DaysBeforeExchange(uint16_t current);
+ virtual void IncrementIgnitionCycles();
+ virtual void ResetIgnitionCycles();
+ virtual int TimeoutResponse();
+ virtual bool SecondsBetweenRetries(std::vector<int>* seconds);
+ virtual bool RefreshDB();
+ virtual const VehicleInfo GetVehicleInfo() const;
+
+ virtual std::vector<UserFriendlyMessage> GetUserFriendlyMsg(
+ const std::vector<std::string>& msg_codes, const std::string& language);
+
+ virtual EndpointUrls GetUpdateUrls(int service_type);
+
+ virtual int GetNotificationsNumber(const std::string& priority);
+ virtual bool GetPriority(const std::string& policy_app_id,
+ std::string* priority);
+ InitResult Init(const PolicySettings* settings);
+ bool Close();
+ bool Clear();
+ bool Drop();
+ virtual void WriteDb();
+ virtual utils::SharedPtr<policy_table::Table> GenerateSnapshot() const;
+ virtual bool Save(const policy_table::Table& table);
+ bool GetInitialAppData(const std::string& app_id,
+ StringArray* nicknames = NULL,
+ StringArray* app_hmi_types = NULL);
+ bool GetFunctionalGroupings(policy_table::FunctionalGroupings& groups);
+
+#ifdef BUILD_TESTS
+ uint32_t open_counter() {
+ return open_counter_;
+ }
+#endif // BUILD_TESTS
+ protected:
+ virtual void GatherModuleMeta(policy_table::ModuleMeta* meta) const;
+ virtual void GatherModuleConfig(policy_table::ModuleConfig* config) const;
+ virtual bool GatherUsageAndErrorCounts(
+ policy_table::UsageAndErrorCounts* counts) const;
+ virtual void GatherDeviceData(policy_table::DeviceData* data) const;
+ virtual bool GatherFunctionalGroupings(
+ policy_table::FunctionalGroupings* groups) const;
+ virtual bool GatherConsumerFriendlyMessages(
+ policy_table::ConsumerFriendlyMessages* messages) const;
+ virtual bool GatherApplicationPoliciesSection(
+ policy_table::ApplicationPoliciesSection* policies) const;
+
+ bool GatherAppGroup(const std::string& app_id,
+ policy_table::Strings* app_groups) const;
+ bool GatherAppType(const std::string& app_id,
+ policy_table::AppHMITypes* app_types) const;
+ bool GatherRequestType(const std::string& app_id,
+ policy_table::RequestTypes* request_types) const;
+ bool GatherNickName(const std::string& app_id,
+ policy_table::Strings* nicknames) const;
+
+ virtual bool SaveApplicationCustomData(const std::string& app_id,
+ bool is_revoked,
+ bool is_default,
+ bool is_predata);
+
+ virtual bool SaveModuleMeta(const policy_table::ModuleMeta& meta);
+ virtual bool SaveModuleConfig(const policy_table::ModuleConfig& config);
+ virtual bool SaveUsageAndErrorCounts(
+ const policy_table::UsageAndErrorCounts& counts);
+ virtual bool SaveDeviceData(const policy_table::DeviceData& devices);
+ virtual bool SaveFunctionalGroupings(
+ const policy_table::FunctionalGroupings& groups);
+ virtual bool SaveConsumerFriendlyMessages(
+ const policy_table::ConsumerFriendlyMessages& messages);
+ virtual bool SaveApplicationPoliciesSection(
+ const policy_table::ApplicationPoliciesSection& policies);
+ virtual bool SaveSpecificAppPolicy(
+ const policy_table::ApplicationPolicies::value_type& app);
+ virtual bool SaveDevicePolicy(const policy_table::DevicePolicy& device);
+
+ virtual bool SaveMessageString(const std::string& type,
+ const std::string& lang,
+ const policy_table::MessageString& strings);
+
+ bool SaveAppGroup(const std::string& app_id,
+ const policy_table::Strings& app_groups);
+ bool SaveNickname(const std::string& app_id,
+ const policy_table::Strings& nicknames);
+ bool SaveAppType(const std::string& app_id,
+ const policy_table::AppHMITypes& types);
+ bool SaveRequestType(const std::string& app_id,
+ const policy_table::RequestTypes& types);
+
+ public:
+ virtual std::string GetLockScreenIconUrl() const;
+ bool UpdateRequired() const;
+ void SaveUpdateRequired(bool value);
+
+ bool IsApplicationRepresented(const std::string& app_id) const;
+ bool CopyApplication(const std::string& source,
+ const std::string& destination);
+
+ bool IsApplicationRevoked(const std::string& app_id) const;
+ virtual bool IsDefaultPolicy(const std::string& app_id) const;
+ virtual bool IsPredataPolicy(const std::string& app_id) const;
+ virtual bool SetDefaultPolicy(const std::string& app_id);
+ virtual void SetPreloaded(bool value);
+
+ virtual bool SetVINValue(const std::string& value);
+
+ virtual utils::dbms::SQLDatabase* db() const;
+ virtual bool SetIsDefault(const std::string& app_id, bool is_default) const;
+
+ void RemoveDB() const OVERRIDE;
+ virtual bool IsDBVersionActual() const OVERRIDE;
+ virtual bool UpdateDBVersion() const OVERRIDE;
+
+ private:
+ utils::dbms::SQLDatabase* db_;
+
+#ifdef BUILD_TESTS
+ uint32_t open_counter_;
+#endif // BUILD_TESTS
+ enum ExternalConsentEntitiesType {
+ kExternalConsentEntitiesTypeOn,
+ kExternalConsentEntitiesTypeOff
+ };
+ /**
+ * @brief Calculates DB version from current schema
+ * @return version
+ */
+ const int32_t GetDBVersion() const;
+ bool SaveRpcs(int64_t group_id, const policy_table::Rpc& rpcs);
+ bool SaveServiceEndpoints(const policy_table::ServiceEndpoints& endpoints);
+ bool SaveSecondsBetweenRetries(
+ const policy_table::SecondsBetweenRetries& seconds);
+ bool SaveNumberOfNotificationsPerMinute(
+ const policy_table::NumberOfNotificationsPerMinute& notifications);
+ bool SaveMessageType(const std::string& type);
+ bool SaveLanguage(const std::string& code);
+
+ bool is_in_memory;
+ bool SaveExternalConsentEntities(
+ const int64_t group_id,
+ const policy_table::DisallowedByExternalConsentEntities& entities,
+ ExternalConsentEntitiesType type) const;
+};
+} // namespace policy
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_SQL_PT_REPRESENTATION_H_
diff --git a/src/components/policy/policy_external/include/policy/sql_wrapper.h b/src/components/policy/policy_external/include/policy/sql_wrapper.h
new file mode 100644
index 0000000000..87fe1404a7
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/sql_wrapper.h
@@ -0,0 +1,45 @@
+/*
+ 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_SQL_WRAPPER_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_SQL_WRAPPER_H_
+
+#if __QNX__
+#include "utils/qdb_wrapper/sql_database_impl.h"
+#include "utils/qdb_wrapper/sql_query.h"
+#else // __QNX__
+// TODO it can be error root cause AHrytsesevich
+#include "utils/sqlite_wrapper/sql_database.h"
+#include "utils/sqlite_wrapper/sql_query.h"
+#endif // __QNX__
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_SQL_WRAPPER_H_
diff --git a/src/components/policy/policy_external/include/policy/status.h b/src/components/policy/policy_external/include/policy/status.h
new file mode 100644
index 0000000000..53925c599a
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/status.h
@@ -0,0 +1,195 @@
+/*
+ Copyright (c) 2016, 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_STATUS_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_STATUS_H_
+
+#include <string>
+#include "policy/policy_types.h"
+#include "utils/macro.h"
+
+namespace policy {
+
+/**
+ * @brief The UpdateEvent enum defines system events which can change update
+ * status
+ */
+enum UpdateEvent {
+ kOnNewAppRegistered,
+ kOnValidUpdateReceived,
+ kOnWrongUpdateReceived,
+ kOnUpdateSentOut,
+ kOnUpdateTimeout,
+ kOnResetPolicyTableRequireUpdate,
+ kOnResetPolicyTableNoUpdate,
+ kScheduleUpdate,
+ kScheduleManualUpdate,
+ kOnResetRetrySequence
+};
+
+const std::string kUpToDate = "UP_TO_DATE";
+const std::string kUpdateNeeded = "UPDATE_NEEDED";
+const std::string kUpdating = "UPDATING";
+
+class UpdateStatusManager;
+
+/**
+ * @brief The Status class defines base implementation of update status
+ */
+class Status {
+ public:
+ /**
+ * @brief Constructor
+ */
+ Status(const std::string& string_status,
+ const policy::PolicyTableStatus enum_status);
+
+ /**
+ * @brief Destructor
+ */
+ virtual ~Status();
+
+ /**
+ * @brief Process event by setting next status in case event can affect
+ * current status or ignores the event
+ * @param manager Status manager pointer
+ * @param event Event which needs to be processed
+ */
+ virtual void ProcessEvent(UpdateStatusManager* manager,
+ UpdateEvent event) = 0;
+
+ /**
+ * @brief Return current status as string value
+ * @return Status as string
+ */
+ const std::string get_status_string() const;
+
+ /**
+ * @brief Return status as enum value
+ * @return Status as enum value
+ */
+ PolicyTableStatus get_status() const;
+
+ /**
+ * @brief Check whether update is required in terms of status
+ * @return True if update is required, otherwise - false
+ */
+ virtual bool IsUpdateRequired() const;
+
+ /**
+ * @brief Check whether update is pending in terms of status
+ * @return True if update is pending, otherwise - false
+ */
+ virtual bool IsUpdatePending() const;
+
+ private:
+ const std::string string_status_;
+ const PolicyTableStatus enum_status_;
+};
+
+/**
+ * @brief The UpToDateStatus class represents 'up-to-date' status
+ */
+class UpToDateStatus : public Status {
+ public:
+ /**
+ * @brief Constructor
+ */
+ UpToDateStatus();
+
+ /**
+ * @brief Process event by setting next status in case event can affect
+ * current status or ignores the event
+ * @param manager Status manager pointer
+ * @param event Event which needs to be processed
+ */
+ void ProcessEvent(UpdateStatusManager* manager, UpdateEvent event) OVERRIDE;
+};
+
+/**
+ * @brief The UpdateNeededStatus class represents 'update needed' status
+ */
+class UpdateNeededStatus : public Status {
+ public:
+ /**
+ * @brief Constructor
+ */
+ UpdateNeededStatus();
+
+ /**
+ * @brief Process event by setting next status in case event can affect
+ * current status or ignores the event
+ * @param manager Status manager pointer
+ * @param event Event which needs to be processed
+ */
+ void ProcessEvent(UpdateStatusManager* manager, UpdateEvent event) OVERRIDE;
+
+ /**
+ * @brief Check whether update is required in terms of status
+ * @return True if update is required, otherwise - false
+ */
+ bool IsUpdateRequired() const OVERRIDE;
+};
+
+/**
+ * @brief The UpdatingStatus class represents 'updating' status
+ */
+class UpdatingStatus : public Status {
+ public:
+ /**
+ * @brief Constructor
+ */
+ UpdatingStatus();
+
+ /**
+ * @brief Process event by setting next status in case event can affect
+ * current status or ignores the event
+ * @param manager Status manager pointer
+ * @param event Event which needs to be processed
+ */
+ void ProcessEvent(UpdateStatusManager* manager, UpdateEvent event) OVERRIDE;
+
+ /**
+ * @brief Check whether update is required in terms of status
+ * @return True if update is required, otherwise - false
+ */
+ bool IsUpdateRequired() const OVERRIDE;
+
+ /**
+ * @brief Check whether update is pending in terms of status
+ * @return True if update is pending, otherwise - false
+ */
+ bool IsUpdatePending() const OVERRIDE;
+};
+}
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_STATUS_H_
diff --git a/src/components/policy/policy_external/include/policy/update_status_manager.h b/src/components/policy/policy_external/include/policy/update_status_manager.h
new file mode 100644
index 0000000000..b663610a5b
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/update_status_manager.h
@@ -0,0 +1,240 @@
+/*
+ Copyright (c) 2017, 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_UPDATE_STATUS_MANAGER_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_UPDATE_STATUS_MANAGER_H_
+
+#include "policy/policy_types.h"
+#include "utils/lock.h"
+#include "utils/threads/thread.h"
+#include "utils/threads/thread_delegate.h"
+#include "utils/conditional_variable.h"
+#include "utils/lock.h"
+#include "utils/logger.h"
+#include "utils/macro.h"
+#include "policy/status.h"
+
+namespace policy {
+
+class PolicyListener;
+
+class UpdateStatusManager {
+ public:
+ /**
+ * @brief Constructor
+ */
+ UpdateStatusManager();
+
+ ~UpdateStatusManager();
+
+ /**
+ * @brief Process event by current status implementations
+ * @param event Event
+ */
+ void ProcessEvent(UpdateEvent event);
+
+ /**
+ * @brief Set next status during event processing
+ * @param status Status shared pointer
+ */
+ void SetNextStatus(utils::SharedPtr<Status> status);
+
+ /**
+ * @brief Set postponed status (will be set after next status) during event
+ * processing
+ * @param status Status shared pointer
+ */
+ void SetPostponedStatus(utils::SharedPtr<Status> status);
+
+ /**
+ * @brief Sets listener pointer
+ * @param listener Pointer to policy listener implementation
+ */
+ void set_listener(PolicyListener* listener);
+
+ /**
+ * @brief Update status hanlder for PTS sending out
+ * @param update_timeout Timeout for waiting of incoming PTU
+ */
+ void OnUpdateSentOut(uint32_t update_timeout);
+
+ /**
+ * @brief Update status handler for PTU waiting timeout
+ */
+ void OnUpdateTimeoutOccurs();
+
+ /**
+ * @brief Update status handler for valid PTU receiving
+ */
+ void OnValidUpdateReceived();
+
+ /**
+ * @brief Update status handler for wrong PTU receiving
+ */
+ void OnWrongUpdateReceived();
+
+ /**
+ * @brief Update status handler for reset PT to default state
+ * @param is_update_required Update necessity flag
+ */
+ void OnResetDefaultPT(bool is_update_required);
+
+ /**
+ * @brief Update status handler for restarting retry sequence
+ */
+ void OnResetRetrySequence();
+
+ /**
+ * @brief Update status handler on new application registering
+ */
+ void OnNewApplicationAdded(const DeviceConsent consent);
+
+ /**
+ * @brief Update status handler for policy initialization
+ * @param is_update_required Update necessity flag
+ */
+ void OnPolicyInit(bool is_update_required);
+
+ /**
+ * @brief In case application from non-consented device has been registered
+ * before and and no updated happened then triggers status change
+ */
+ void OnDeviceConsented();
+
+ /**
+ * @brief IsUpdateRequired allows to distiguish if update is required
+ *
+ * @return true if update required.
+ */
+ bool IsUpdateRequired() const;
+
+ /**
+ * @brief IsUpdatePending allows to distinguish if update is in pending mode.
+ *
+ * @return true if update is in pending mode.
+ */
+ bool IsUpdatePending() const;
+
+ /**
+ * @brief ScheduleUpdate allows to schedule next update.
+ * It will change state to Update_Needed, that's is.
+ */
+ void ScheduleUpdate();
+
+ /**
+ * @brief ScheduleUpdate allows to schedule next update.
+ * It will change state to Update_Needed, that's is
+ * and will not send any notifications about updating to HMI
+ */
+ void ScheduleManualUpdate();
+
+ /**
+ * @brief StringifiedUpdateStatus allows to obtain update status as a string.
+ *
+ * @return stringified update status.
+ */
+ std::string StringifiedUpdateStatus() const;
+
+ /**
+ * @brief Status handler on applications search started
+ */
+ void OnAppsSearchStarted();
+
+ /**
+ * @brief Status handler on applications search completed
+ */
+ void OnAppsSearchCompleted();
+
+ /**
+ * @brief Returns status is application search in progress
+ * @return true, if in progress, otherwise - false
+ */
+ bool IsAppsSearchInProgress();
+
+#ifdef BUILD_TESTS
+ PolicyTableStatus GetLastUpdateStatus() const {
+ return current_status_->get_status();
+ }
+#endif // BUILD_TESTS
+
+ private:
+ /**
+ * @brief Does statuses transitions after event handling and notifies the
+ * system
+ */
+ void DoTransition();
+
+ private:
+ PolicyListener* listener_;
+
+ /**
+ * @brief Current update status
+ */
+ utils::SharedPtr<Status> current_status_;
+
+ /**
+ * @brief Next status after current to be set
+ */
+ utils::SharedPtr<Status> next_status_;
+
+ /**
+ * @brief Status to be set after 'next' status
+ */
+ utils::SharedPtr<Status> postponed_status_;
+ sync_primitives::Lock status_lock_;
+
+ UpdateEvent last_processed_event_;
+ bool apps_search_in_progress_;
+ bool app_registered_from_non_consented_device_;
+ sync_primitives::Lock apps_search_in_progress_lock_;
+
+ class UpdateThreadDelegate : public threads::ThreadDelegate {
+ public:
+ UpdateThreadDelegate(UpdateStatusManager* update_status_manager);
+ ~UpdateThreadDelegate();
+ virtual void threadMain();
+ virtual void exitThreadMain();
+ void updateTimeOut(const uint32_t timeout_ms);
+
+ volatile uint32_t timeout_;
+ volatile bool stop_flag_;
+ sync_primitives::Lock state_lock_;
+ sync_primitives::ConditionalVariable termination_condition_;
+ UpdateStatusManager* update_status_manager_;
+ };
+
+ UpdateThreadDelegate* update_status_thread_delegate_;
+ threads::Thread* thread_;
+};
+}
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_UPDATE_STATUS_MANAGER_H_
diff --git a/src/components/policy/policy_external/include/policy/usage_statistics/counter.h b/src/components/policy/policy_external/include/policy/usage_statistics/counter.h
new file mode 100644
index 0000000000..adaef0eb28
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/usage_statistics/counter.h
@@ -0,0 +1,108 @@
+/*
+ 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_USAGE_STATISTICS_COUNTER_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_USAGE_STATISTICS_COUNTER_H_
+
+#include <ctime>
+#include "policy/usage_statistics/statistics_manager.h"
+#include "policy/usage_statistics/app_stopwatch.h"
+#include "utils/shared_ptr.h"
+#include "utils/timer.h"
+#include "utils/macro.h"
+
+namespace usage_statistics {
+
+using timer::Timer;
+
+class GlobalCounter {
+ public:
+ GlobalCounter(utils::SharedPtr<StatisticsManager> statistics_manager,
+ GlobalCounterId counter_type);
+ void operator++() const;
+
+ private:
+ GlobalCounterId counter_type_;
+ utils::SharedPtr<StatisticsManager> statistics_manager_;
+};
+
+class AppCounter {
+ public:
+ AppCounter(utils::SharedPtr<StatisticsManager> statistics_manager,
+ const std::string& app_id,
+ AppCounterId counter_type);
+ void operator++() const;
+
+ private:
+ std::string app_id_;
+ AppCounterId counter_type_;
+ utils::SharedPtr<StatisticsManager> statistics_manager_;
+};
+
+class AppInfo {
+ public:
+ AppInfo(utils::SharedPtr<StatisticsManager> statistics_manager,
+ const std::string& app_id,
+ AppInfoId info_type);
+ void Update(const std::string& new_info) const;
+
+ private:
+ std::string app_id_;
+ AppInfoId info_type_;
+ utils::SharedPtr<StatisticsManager> statistics_manager_;
+};
+
+class AppStopwatchImpl : public AppStopwatch {
+ public:
+ AppStopwatchImpl(utils::SharedPtr<StatisticsManager> statistics_manager,
+ const std::string& app_id);
+ AppStopwatchImpl(utils::SharedPtr<StatisticsManager> statistics_manager,
+ const std::string& app_id,
+ std::uint32_t timeout);
+ ~AppStopwatchImpl();
+ void Start(AppStopwatchId stopwatch_type) OVERRIDE;
+ void Switch(AppStopwatchId stopwatch_type) OVERRIDE;
+ void WriteTime() OVERRIDE;
+
+ private:
+ // Fields
+ std::string app_id_;
+ AppStopwatchId stopwatch_type_;
+ utils::SharedPtr<StatisticsManager> statistics_manager_;
+ timer::Timer timer_;
+ const std::uint32_t time_out_;
+ DISALLOW_COPY_AND_ASSIGN(AppStopwatchImpl);
+};
+
+} // namespace usage_statistics
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_USAGE_STATISTICS_COUNTER_H_
diff --git a/src/components/policy/policy_external/include/policy/user_consent_manager.h b/src/components/policy/policy_external/include/policy/user_consent_manager.h
new file mode 100644
index 0000000000..0f242738b6
--- /dev/null
+++ b/src/components/policy/policy_external/include/policy/user_consent_manager.h
@@ -0,0 +1,44 @@
+/*
+ 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.
+ */
+
+#ifndef SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_USER_CONSENT_MANAGER_H_
+#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_USER_CONSENT_MANAGER_H_
+
+namespace policy {
+class UserConsentManager {
+ public:
+ UserConsentManager() {}
+ ~UserConsentManager() {}
+};
+} // namespace policy
+
+#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_USER_CONSENT_MANAGER_H_