diff options
Diffstat (limited to 'src/components/policy/policy_external/include/policy')
21 files changed, 5547 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..13b7dd88bb --- /dev/null +++ b/src/components/policy/policy_external/include/policy/cache_manager.h @@ -0,0 +1,840 @@ +/* + * 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 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; + + /** + * @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 + * @return true, if operation succedeed, otherwise - false + */ + bool SetUserPermissionsForApp(const PermissionConsent& permissions); + + /** + * @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; + +#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. + */ + void 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); + + 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..fa31290987 --- /dev/null +++ b/src/components/policy/policy_external/include/policy/cache_manager_interface.h @@ -0,0 +1,717 @@ +/* + * 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 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; + + /** + * @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 + * @return true, if operation succedeed, otherwise - false + */ + virtual bool SetUserPermissionsForApp( + const PermissionConsent& permissions) = 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; + +#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..9f8151e29f --- /dev/null +++ b/src/components/policy/policy_external/include/policy/policy_helper.h @@ -0,0 +1,262 @@ +/* + 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 + * In case of policies changed for some application, current data will be + * updated and notification will be sent to application + */ +struct CheckAppPolicy { + CheckAppPolicy(PolicyManagerImpl* pm, + const utils::SharedPtr<policy_table::Table> update, + const utils::SharedPtr<policy_table::Table> snapshot); + bool operator()(const AppPoliciesValueType& app_policy); + + private: + 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 + }; + + void SetPendingPermissions(const AppPoliciesValueType& app_policy, + PermissionsCheckResult result) const; + PermissionsCheckResult CheckPermissionsChanges( + const AppPoliciesValueType& app_policy) const; + bool HasRevokedGroups(const AppPoliciesValueType& app_policy, + policy_table::Strings* revoked_groups = NULL) const; + bool HasNewGroups(const AppPoliciesValueType& app_policy, + policy_table::Strings* new_groups = NULL) const; + bool HasConsentNeededGroups(const AppPoliciesValueType& app_policy) const; + std::vector<FunctionalGroupPermission> GetRevokedGroups( + const AppPoliciesValueType& app_policy) const; + void RemoveRevokedConsents( + const AppPoliciesValueType& app_policy, + const std::vector<FunctionalGroupPermission>& revoked_groups) const; + bool IsKnownAppication(const std::string& application_id) const; + void NotifySystem(const AppPoliciesValueType& app_policy) const; + void SendPermissionsToApp(const AppPoliciesValueType& app_policy) const; + bool IsAppRevoked(const AppPoliciesValueType& app_policy) const; + bool NicknamesMatch(const AppPoliciesValueType& app_policy) const; + /** + * @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; + bool IsRequestTypeChanged(const AppPoliciesValueType& app_policy) const; + + private: + PolicyManagerImpl* pm_; + const utils::SharedPtr<policy_table::Table> update_; + const utils::SharedPtr<policy_table::Table> snapshot_; +}; + +/* + * @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..55b5ab1212 --- /dev/null +++ b/src/components/policy/policy_external/include/policy/policy_manager_impl.h @@ -0,0 +1,342 @@ +/* + 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 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 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); + + virtual void SetUserConsentForApp(const PermissionConsent& permissions); + + 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); + + 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(); + +#ifdef BUILD_TESTS + inline CacheManagerInterfaceSPtr GetCache() { + return cache_; + } +#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; + + protected: + virtual utils::SharedPtr<policy_table::Table> Parse( + const BinaryMessage& pt_content); + + private: + void CheckTriggers(); + /* + * @brief Checks policy table update along with current data for any changes + * in assigned functional group list of application + * + * @param Policy table update struct + */ + void CheckPermissionsChanges( + const utils::SharedPtr<policy_table::Table> update, + const utils::SharedPtr<policy_table::Table> snapshot); + + /** + * @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; + + PolicyListener* listener_; + + UpdateStatusManager update_status_manager_; + CacheManagerInterfaceSPtr cache_; + sync_primitives::Lock apps_registration_lock_; + sync_primitives::Lock app_permissions_diff_lock_; + std::map<std::string, AppPermissions> 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; +}; + +} // 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..9dceeb1c4a --- /dev/null +++ b/src/components/policy/policy_external/include/policy/policy_table/enums.h @@ -0,0 +1,168 @@ +/* + * 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 Input { + I_GUI, + I_VUI, +}; +bool IsValidEnum(Input val); +const char* EnumToJsonString(Input val); +bool EnumFromJsonString(const std::string& literal, Input* 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); + +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..8ca91c310a --- /dev/null +++ b/src/components/policy/policy_external/include/policy/policy_table/types.h @@ -0,0 +1,551 @@ +/* + * 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, 50> 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, 10> 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; + +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 Rpcs : CompositeType { + public: + Optional<String<1, 255> > user_consent_prompt; + Nullable<Rpc> rpcs; + + 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<Enum<Input> > input; + Optional<String<1, 255> > time_stamp; + + 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..e0f7d89ae9 --- /dev/null +++ b/src/components/policy/policy_external/include/policy/policy_types.h @@ -0,0 +1,369 @@ +/* + 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 "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"; + +/* + *@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; +}; + +} // 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..ca3d45e946 --- /dev/null +++ b/src/components/policy/policy_external/include/policy/pt_ext_representation.h @@ -0,0 +1,333 @@ +/* + 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; +}; +} // 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..96406feaf1 --- /dev/null +++ b/src/components/policy/policy_external/include/policy/sql_pt_ext_queries.h @@ -0,0 +1,97 @@ +/* + 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 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 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; + +} // 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..99fe099a59 --- /dev/null +++ b/src/components/policy/policy_external/include/policy/sql_pt_ext_representation.h @@ -0,0 +1,207 @@ +/* + 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); + + private: + 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); +}; + +} // 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..a0ff71ba13 --- /dev/null +++ b/src/components/policy/policy_external/include/policy/sql_pt_queries.h @@ -0,0 +1,121 @@ +/* + 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 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 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 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..a2999b4bf5 --- /dev/null +++ b/src/components/policy/policy_external/include/policy/sql_pt_representation.h @@ -0,0 +1,204 @@ +/* + 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 + + /** + * @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; +}; +} // 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..f578db0311 --- /dev/null +++ b/src/components/policy/policy_external/include/policy/status.h @@ -0,0 +1,194 @@ +/* + 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, + 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) FINAL; +}; + +/** + * @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) FINAL; + + /** + * @brief Check whether update is required in terms of status + * @return True if update is required, otherwise - false + */ + bool IsUpdateRequired() const FINAL; +}; + +/** + * @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) FINAL; + + /** + * @brief Check whether update is required in terms of status + * @return True if update is required, otherwise - false + */ + bool IsUpdateRequired() const FINAL; + + /** + * @brief Check whether update is pending in terms of status + * @return True if update is pending, otherwise - false + */ + bool IsUpdatePending() const FINAL; +}; +} + +#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..91406aef47 --- /dev/null +++ b/src/components/policy/policy_external/include/policy/update_status_manager.h @@ -0,0 +1,232 @@ +/* + 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_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 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_; + + 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_ |