diff options
Diffstat (limited to 'src/components/policy/policy_regular/include')
13 files changed, 756 insertions, 730 deletions
diff --git a/src/components/policy/policy_regular/include/policy/cache_manager.h b/src/components/policy/policy_regular/include/policy/cache_manager.h index 1c28b596c0..00f0adab06 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager.h @@ -142,14 +142,26 @@ class CacheManager : public CacheManagerInterface { virtual bool SecondsBetweenRetries(std::vector<int>& seconds); /** - * @brief Get information about vehicle + * @brief Gets copy of current policy table data + * @return policy_table as json object */ - virtual const VehicleInfo GetVehicleInfo() const; + virtual Json::Value GetPolicyTableData() const OVERRIDE; + + /** + * @brief Gets vehicle data items + * @return Structure with vehicle data items + */ + virtual const std::vector<policy_table::VehicleDataItem> GetVehicleDataItems() + const; + + std::vector<policy_table::VehicleDataItem> GetRemovedVehicleDataItems() + const OVERRIDE; const boost::optional<bool> LockScreenDismissalEnabledState() const OVERRIDE; const boost::optional<std::string> LockScreenDismissalWarningMessage( const std::string& language) const OVERRIDE; + /** * @brief Get a list of enabled cloud applications * @param enabled_apps List filled with the policy app id of each enabled @@ -159,28 +171,14 @@ class CacheManager : public CacheManagerInterface { std::vector<std::string>& enabled_apps) const; /** - * @brief Get cloud app policy information, all fields that aren't set for a - * given app will be filled with empty strings - * @param policy_app_id Unique application id - * @param enabled Whether or not the app is enabled - * @param endpoint Filled with the endpoint used to connect to the cloud - * application - * @param certificate Filled with the certificate used to for creating a - * secure connection to the cloud application - * @param auth_token Filled with the token used for authentication when - * reconnecting to the cloud app - * @param cloud_transport_type Filled with the transport type used by the - * cloud application (ex. "WSS") - * @param hybrid_app_preference Filled with the hybrid app preference for the - * cloud application set by the user - */ - virtual bool GetCloudAppParameters(const std::string& policy_app_id, - bool& enabled, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const; + * @brief Get a list of enabled local applications + * @return enabled_apps List filled with the policy app id of each enabled + * local application + */ + std::vector<std::string> GetEnabledLocalApps() const OVERRIDE; + + bool GetAppProperties(const std::string& policy_app_id, + AppProperties& out_app_properties) const OVERRIDE; /** * Initializes a new cloud application with default policies @@ -279,18 +277,11 @@ class CacheManager : public CacheManagerInterface { * @param service_type If URLs for specific service are preset, * return them otherwise default URLs. */ - virtual void GetUpdateUrls(const std::string& service_type, - EndpointUrls& out_end_points); + void GetUpdateUrls(const std::string& service_type, + EndpointUrls& out_end_points) const OVERRIDE; - virtual void GetUpdateUrls(const uint32_t service_type, - EndpointUrls& out_end_points); - /** - * @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; + void GetUpdateUrls(const uint32_t service_type, + EndpointUrls& out_end_points) const OVERRIDE; /** * @brief Get Icon Url used for showing a cloud apps icon before the intial @@ -396,6 +387,12 @@ class CacheManager : public CacheManagerInterface { bool GetFunctionalGroupings(policy_table::FunctionalGroupings& groups); /** + * @brief Get policy app names from PT + * @return container of strings representing policy application names + */ + const policy_table::Strings GetPolicyAppIDs() const OVERRIDE; + + /** * Checks if the application is represented in policy table * @param app_id application id * @return true if application is represented in policy table @@ -835,6 +832,24 @@ class CacheManager : public CacheManagerInterface { void MergeCFM(const policy_table::PolicyTable& new_pt, policy_table::PolicyTable& pt); + /** + * @brief MergeVD allows to merge VehicleDataItems section by + *definite rules. + * + * The rules are: + * 1. If vehicle_data_items key is not presented in the updated PolicyTable, + * update for VehicleDataItems should be ignored. + * 2. If vehicle_data_items presented in updated PolicyTable, the + * VehicleDataItems in the database (LocalPT) should be overwritten with + * updated data. + * + * @param new_pt the policy table loaded from updated preload JSON file. + * + * @param pt the exists database + */ + void MergeVD(const policy_table::PolicyTable& new_pt, + policy_table::PolicyTable& pt); + const PolicySettings& get_settings() const; std::shared_ptr<policy_table::Table> pt() const { @@ -850,6 +865,24 @@ class CacheManager : public CacheManagerInterface { void OnDeviceSwitching(const std::string& device_id_from, const std::string& device_id_to) OVERRIDE; + EncryptionRequired GetAppEncryptionRequiredFlag( + const std::string& application_policy_name) const OVERRIDE; + + EncryptionRequired GetFunctionalGroupingEncryptionRequiredFlag( + const std::string& functional_group) const OVERRIDE; + + void GetApplicationParams( + const std::string& application_name, + policy_table::ApplicationParams& application_policies) const OVERRIDE; + + /** + * @brief Method for separate RPCSpec vehicle data items from custom + * @param full vehicle data items during PTU + * @return array with only custom vehicle items + */ + static policy_table::VehicleDataItems CollectCustomVDItems( + const policy_table::VehicleDataItems& vd_items); + private: std::string currentDateTime(); struct AppHMITypeToString { @@ -869,6 +902,24 @@ class CacheManager : public CacheManagerInterface { */ void CheckSnapshotInitialization(); + /** + * @brief Calculates difference between two provided custom vehicle data items + * @param items_before list of vehicle data items before PTU was applied + * @param items_after list of vehicle data items after PTU was applied + * @return list with calculated difference or empty list if two input lists + * are equal + */ + policy_table::VehicleDataItems CalculateCustomVdItemsDiff( + const policy_table::VehicleDataItems& items_before, + const policy_table::VehicleDataItems& items_after) const; + + /** + * @brief Sets the custom vehicle data items + * @param removed_items list of vehicle data items to set + */ + void SetRemovedCustomVdItems( + const policy_table::VehicleDataItems& removed_items); + void PersistData(); /** @@ -895,6 +946,7 @@ class CacheManager : public CacheManagerInterface { bool update_required; typedef std::set<std::string> UnpairedDevices; UnpairedDevices is_unpaired_; + policy_table::VehicleDataItems removed_custom_vd_items_; mutable sync_primitives::RecursiveLock cache_lock_; sync_primitives::Lock unpaired_lock_; diff --git a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h index e8f2644bc5..fc1a6337aa 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h @@ -149,9 +149,24 @@ class CacheManagerInterface { virtual bool SecondsBetweenRetries(std::vector<int>& seconds) = 0; /** - * @brief Get information about vehicle + * @brief Gets copy of current policy table data + * @return policy_table as json object */ - virtual const VehicleInfo GetVehicleInfo() const = 0; + virtual Json::Value GetPolicyTableData() const = 0; + + /** + * @brief Gets vehicle data items + * @return Structure with vehicle data items + */ + virtual const std::vector<policy_table::VehicleDataItem> GetVehicleDataItems() + const = 0; + + /** + * @brief Gets vehicle data items removed after the last PTU + * @return List of removed vehicle data items + */ + virtual std::vector<policy_table::VehicleDataItem> + GetRemovedVehicleDataItems() const = 0; /** * @brief Get a list of enabled cloud applications @@ -162,29 +177,21 @@ class CacheManagerInterface { std::vector<std::string>& enabled_apps) const = 0; /** - * @brief Get cloud app policy information, all fields that aren't set for a + * @brief Get a list of enabled local applications + * @return enabled_apps List filled with the policy app id of each enabled + * local application + */ + virtual std::vector<std::string> GetEnabledLocalApps() const = 0; + + /** + * @brief Get app policy information, all fields that aren't set for a * given app will be filled with empty strings - * @param policy_app_id Unique application id - * @param enabled Whether or not the app is enabled - * @param endpoint Filled with the endpoint used to connect to the cloud - * application - * @param certificate Filled with the certificate used to for creating a - * secure connection to the cloud application - * @param auth_token Filled with the token used for authentication when - * reconnecting to the cloud app - * @param cloud_transport_type Filled with the transport type used by the - * cloud application (ex. "WSS") - * @param hybrid_app_preference Filled with the hybrid app preference for the - * cloud application set by the user - */ - virtual bool GetCloudAppParameters( - const std::string& policy_app_id, - bool& enabled, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const = 0; + * @param policy_app_id policy app id + * @param out_app_properties application properties + * @return true if application presents in database, otherwise - false + */ + virtual bool GetAppProperties(const std::string& policy_app_id, + AppProperties& out_app_properties) const = 0; /** * Initializes a new cloud application with default policies @@ -301,17 +308,9 @@ class CacheManagerInterface { * return them otherwise default URLs. */ virtual void GetUpdateUrls(const std::string& service_type, - EndpointUrls& out_end_points) = 0; + EndpointUrls& out_end_points) const = 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; + EndpointUrls& out_end_points) const = 0; /** * @brief Get Icon Url used for showing a cloud apps icon before the intial @@ -419,6 +418,12 @@ class CacheManagerInterface { policy_table::FunctionalGroupings& groups) = 0; /** + * @brief Get policy app names from PT + * @return container of strings representing policy application names + */ + virtual const policy_table::Strings GetPolicyAppIDs() const = 0; + + /** * Checks if the application is represented in policy table * @param app_id application id * @return true if application is represented in policy table @@ -815,6 +820,36 @@ class CacheManagerInterface { */ virtual void OnDeviceSwitching(const std::string& device_id_from, const std::string& device_id_to) = 0; + + /** + * @brief GetAppEncryptionRequiredFlag retrieves encryption required flag for + * given application + * @param application policy application name + * @return optional object containing encryption required flag + */ + virtual rpc::Optional<rpc::Boolean> GetAppEncryptionRequiredFlag( + const std::string& application_policy_name) const = 0; + + /** + * @brief GetFunctionalGroupingEncryptionRequiredFlag retrieves encryption + * required flag + * for + * given functional grouping + * @param functional_group policy functional group name + * @return optional object containing encryption required flag + */ + virtual rpc::Optional<rpc::Boolean> + GetFunctionalGroupingEncryptionRequiredFlag( + const std::string& functional_group) const = 0; + + /** + * @brief retreives application params + * @param application_name policy applicatoin name + * @param application_params application params + */ + virtual void GetApplicationParams( + const std::string& application_name, + policy_table::ApplicationParams& application_params) const = 0; }; typedef std::shared_ptr<CacheManagerInterface> CacheManagerInterfaceSPtr; diff --git a/src/components/policy/policy_regular/include/policy/policy_helper.h b/src/components/policy/policy_regular/include/policy/policy_helper.h index 4c697858f5..d5155cf91b 100644 --- a/src/components/policy/policy_regular/include/policy/policy_helper.h +++ b/src/components/policy/policy_regular/include/policy/policy_helper.h @@ -1,4 +1,4 @@ -/* +/* Copyright (c) 2013, Ford Motor Company All rights reserved. @@ -83,22 +83,11 @@ bool operator!=(const policy_table::ApplicationParams& first, struct CheckAppPolicy { CheckAppPolicy(PolicyManagerImpl* pm, const std::shared_ptr<policy_table::Table> update, - const std::shared_ptr<policy_table::Table> snapshot); + const std::shared_ptr<policy_table::Table> snapshot, + CheckAppPolicyResults& out_results); 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, - RESULT_REQUEST_SUBTYPE_CHANGED - }; - void SetPendingPermissions(const AppPoliciesValueType& app_policy, PermissionsCheckResult result) const; PermissionsCheckResult CheckPermissionsChanges( @@ -107,6 +96,8 @@ struct CheckAppPolicy { policy_table::Strings* revoked_groups = NULL) const; bool HasNewGroups(const AppPoliciesValueType& app_policy, policy_table::Strings* new_groups = NULL) const; + bool HasUpdatedGroups(const policy::AppPoliciesValueType& app_policy, + policy_table::Strings* updated_groups = NULL) const; bool HasConsentNeededGroups(const AppPoliciesValueType& app_policy) const; std::vector<FunctionalGroupPermission> GetRevokedGroups( const AppPoliciesValueType& app_policy) const; @@ -115,10 +106,18 @@ struct CheckAppPolicy { 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 std::string& app_id, - const policy_table::Strings& groups) const; bool IsAppRevoked(const AppPoliciesValueType& app_policy) const; bool NicknamesMatch(const AppPoliciesValueType& app_policy) const; + + /** + * @brief Check of current policy against incoming updated policy is + * performed. + * This function adds result code of this check to container. + * @param app_id Application id + * @param result Result value + */ + void AddResult(const std::string& app_id, PermissionsCheckResult result); + /** * @brief Allows to check if appropriate group requires any consent. * @param group_name the group for which consent will be checked. @@ -129,10 +128,35 @@ struct CheckAppPolicy { bool IsRequestTypeChanged(const AppPoliciesValueType& app_policy) const; bool IsRequestSubTypeChanged(const AppPoliciesValueType& app_policy) const; + bool IsEncryptionRequiredFlagChanged( + const AppPoliciesValueType& app_policy) const; + + bool IsAppPropertiesChanged(const AppPoliciesValueType& app_policy) const; + + bool IsAppPropertiesProvided(const AppPoliciesValueType& app_policy) const; + private: PolicyManagerImpl* pm_; const std::shared_ptr<policy_table::Table> update_; const std::shared_ptr<policy_table::Table> snapshot_; + CheckAppPolicyResults& out_results_; +}; + +/** + * @brief Helper struct for filling actions to be done for processed application + * using CheckAppPolicyResults data as a source + */ +struct FillActionsForAppPolicies { + FillActionsForAppPolicies( + ApplicationsPoliciesActions& actions, + const policy_table::ApplicationPolicies& app_policies) + : actions_(actions), app_policies_(app_policies) {} + + void operator()(const policy::CheckAppPolicyResults::value_type& value); + + private: + ApplicationsPoliciesActions& actions_; + const policy_table::ApplicationPolicies& app_policies_; }; /* @@ -174,6 +198,9 @@ struct ProcessFunctionalGroup { private: GroupConsent GetGroupState(const std::string& group_name); + void FillEncryptionFlagForRpcs( + const policy_table::Rpc& rpcs, + const policy::EncryptionRequired encryption_required); const policy_table::FunctionalGroupings& fg_; const std::vector<FunctionalGroupPermission>& group_permissions_; Permissions& data_; diff --git a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h index 13d19e1a41..aa77019613 100644 --- a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h +++ b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h @@ -37,6 +37,7 @@ #include <list> #include <string> +#include "application_manager/policies/policy_encryption_flag_getter.h" #include "policy/access_remote.h" #include "policy/access_remote_impl.h" #include "policy/cache_manager_interface.h" @@ -57,6 +58,45 @@ struct CheckAppPolicy; class PolicyManagerImpl : public PolicyManager { public: PolicyManagerImpl(); + /* + * \param policy_app_id policy app id + * \return true if the app need encryption + */ + bool AppNeedEncryption(const std::string& policy_app_id) const OVERRIDE; + + /* + * \param policy_app_id policy app id + * \return Optional app need encryption + */ + const rpc::Optional<rpc::Boolean> GetAppEncryptionRequired( + const std::string& policy_app_id) const OVERRIDE; + /* + * \param policy_app_id policy app id + * \return groups that exist for app + */ + const std::vector<std::string> GetFunctionalGroupsForApp( + const std::string& policy_app_id) const OVERRIDE; + + const std::vector<std::string> GetApplicationPolicyIDs() const OVERRIDE; + + /* + * \param policy_group group + * \return true if the group need encryption + */ + bool FunctionGroupNeedEncryption( + const std::string& policy_group) const OVERRIDE; + /* + * \param policy_group group + * \return RPCs that exists in group + */ + const std::vector<std::string> GetRPCsForFunctionGroup( + const std::string& group) const OVERRIDE; + /* + * \param function_id function id + * \return policy function name + */ + const std::string GetPolicyFunctionName( + const uint32_t function_id) const OVERRIDE; /** * @brief set_listener set new policy listener instance @@ -89,8 +129,35 @@ class PolicyManagerImpl : public PolicyManager { * @param pt_content PTU as binary string * @return true if successfully */ - bool LoadPT(const std::string& file, - const BinaryMessage& pt_content) OVERRIDE; + PtProcessingResult LoadPT(const std::string& file, + const BinaryMessage& pt_content) OVERRIDE; + + void OnPTUFinished(const PtProcessingResult ptu_result) OVERRIDE; + + typedef policy_table::ApplicationPolicies::value_type AppPoliciesValueType; + + /** + * @brief Notifies system by sending OnAppPermissionChanged notification + * @param device_id device identifier + * @param app_policy Reference to application policy + */ + void NotifySystem(const std::string& device_id, + const AppPoliciesValueType& app_policy) const; + + /** + * @brief Sends OnPermissionChange notification to application if its + * currently registered + * @param device_id device identifier + * @param app_policy Reference to application policy + */ + void SendPermissionsToApp(const std::string& device_id, + const AppPoliciesValueType& app_policy); + + /** + * @brief Resumes all policy actions for all apps, suspended during + * PTU applying + */ + void ResumePendingAppPolicyActions(); /** * @brief Resets Policy Table @@ -105,16 +172,9 @@ class PolicyManagerImpl : public PolicyManager { * @param out_end_points output vector of urls */ void GetUpdateUrls(const uint32_t service_type, - EndpointUrls& out_end_points) OVERRIDE; + EndpointUrls& out_end_points) const OVERRIDE; void GetUpdateUrls(const std::string& service_type, - EndpointUrls& out_end_points) OVERRIDE; - - /** - * @brief GetLockScreenIcon allows to obtain lock screen icon url; - * @return url which point to the resourse where lock screen icon could be - *obtained. - */ - std::string GetLockScreenIconUrl() const OVERRIDE; + EndpointUrls& out_end_points) const OVERRIDE; /** * @brief Get Icon Url used for showing a cloud apps icon before the intial @@ -128,7 +188,7 @@ class PolicyManagerImpl : public PolicyManager { /** * @brief PTU is needed, for this PTS has to be formed and sent. */ - bool RequestPTUpdate() OVERRIDE; + bool RequestPTUpdate(const PTUIterationType iteration_type) OVERRIDE; /** * @brief Check if specified RPC for specified application @@ -178,6 +238,8 @@ class PolicyManagerImpl : public PolicyManager { */ std::string ForcePTExchange() OVERRIDE; + void StopRetrySequence() OVERRIDE; + /** * @brief Exchange by user request * @return Current status of policy table @@ -192,8 +254,10 @@ class PolicyManagerImpl : public PolicyManager { /** * @brief Resets retry sequence + * @param send_event - if true corresponding event is sent to + * UpdateStatusManager */ - void ResetRetrySequence(); + void ResetRetrySequence(const ResetRetryCountType reset_type) OVERRIDE; /** * @brief Gets timeout to wait before next retry updating PT @@ -265,12 +329,15 @@ class PolicyManagerImpl : public PolicyManager { /** * @brief Update Application Policies as reaction * on User allowing/disallowing device this app is running on. + * @param device_handle device identifier * @param app_id Unique application id * @param is_device_allowed true if user allowing device otherwise false * @return true if operation was successful */ - bool ReactOnUserDevConsentForApp(const std::string app_id, - const bool is_device_allowed) OVERRIDE; + bool ReactOnUserDevConsentForApp( + const transport_manager::DeviceHandle& device_handle, + const std::string app_id, + const bool is_device_allowed) OVERRIDE; /** * @brief Retrieves data from app_policies about app on its registration: @@ -311,12 +378,14 @@ class PolicyManagerImpl : public PolicyManager { /** * @brief Get default HMI level for application + * @param device_id device identifier * @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& policy_app_id, + bool GetDefaultHmi(const std::string& device_id, + const std::string& policy_app_id, std::string* default_hmi) const OVERRIDE; /** @@ -359,9 +428,11 @@ class PolicyManagerImpl : public PolicyManager { /** * @brief Return device id, which hosts specific application + * @param device_handle device identifier * @param policy_app_id Application id, which is required to update device id */ std::string& GetCurrentDeviceId( + const transport_manager::DeviceHandle& device_handle, const std::string& policy_app_id) const OVERRIDE; /** @@ -381,13 +452,6 @@ class PolicyManagerImpl : public PolicyManager { const std::string& language) OVERRIDE; /** - * @brief Runs necessary operations, which is depends on external system - * state, e.g. getting system-specific parameters which are need to be - * filled into policy table - */ - void OnSystemReady() OVERRIDE; - - /** * @brief Get number of notification by priority * @param priority Specified priority * @return notification number @@ -403,11 +467,12 @@ class PolicyManagerImpl : public PolicyManager { /** * @brief Gets specific application permissions changes since last policy * table update + * @param device_id device identifier * @param policy_app_id Unique application id * @return Permissions changes */ AppPermissions GetAppPermissionsChanges( - const std::string& policy_app_id) OVERRIDE; + const std::string& device_id, const std::string& policy_app_id) OVERRIDE; /** * @brief Removes specific application permissions changes @@ -417,10 +482,11 @@ class PolicyManagerImpl : public PolicyManager { /** * @brief Send OnPermissionsUpdated for choosen application + * @param device_id device identifier * @param application_id Unique application id */ void SendNotificationOnPermissionsUpdated( - const std::string& application_id) OVERRIDE; + const std::string& device_id, const std::string& application_id) OVERRIDE; /** * @brief Removes unpaired device records and related records from DB @@ -451,20 +517,24 @@ class PolicyManagerImpl : public PolicyManager { /** * @brief Adds, application to the db or update existed one * run PTU if policy update is necessary for application. + * @param device_id device identifier * @param application_id Unique application id * @param hmi_types application HMI types * @return function that will notify update manager about new application */ StatusNotifier AddApplication( + const std::string& device_id, const std::string& application_id, const rpc::policy_table_interface_base::AppHmiTypes& hmi_types) OVERRIDE; /** * @brief Assigns new HMI types for specified application + * @param device_handle device identifier * @param application_id Unique application id * @param hmi_types new HMI types list */ - void SetDefaultHmiTypes(const std::string& application_id, + void SetDefaultHmiTypes(const transport_manager::DeviceHandle& device_handle, + const std::string& application_id, const std::vector<int>& hmi_types) OVERRIDE; /** @@ -540,6 +610,8 @@ class PolicyManagerImpl : public PolicyManager { */ void OnAppsSearchCompleted(const bool trigger_ptu) OVERRIDE; + void UpdatePTUReadyAppsCount(const uint32_t new_app_count) OVERRIDE; + /** * @brief Get state of request types for given application * @param policy_app_id Unique application id @@ -573,10 +645,20 @@ class PolicyManagerImpl : public PolicyManager { const std::string& policy_app_id) const OVERRIDE; /** - * @brief Get information about vehicle - * @return vehicle information + * @brief Gets vehicle data items + * @return Structure with vehicle data items */ - const VehicleInfo GetVehicleInfo() const OVERRIDE; + const std::vector<policy_table::VehicleDataItem> GetVehicleDataItems() + const OVERRIDE; + + std::vector<policy_table::VehicleDataItem> GetRemovedVehicleDataItems() + const OVERRIDE; + + /** + * @brief Gets copy of current policy table data + * @return policy_table as json object + */ + Json::Value GetPolicyTableData() const OVERRIDE; /** * @brief Get a list of enabled cloud applications @@ -587,28 +669,14 @@ class PolicyManagerImpl : public PolicyManager { std::vector<std::string>& enabled_apps) const OVERRIDE; /** - * @brief Get cloud app policy information, all fields that aren't set for a - * given app will be filled with empty strings - * @param policy_app_id Unique application id - * @param enabled Whether or not the app is enabled - * @param endpoint Filled with the endpoint used to connect to the cloud - * application - * @param certificate Filled with the certificate used to for creating a - * secure connection to the cloud application - * @param auth_token Filled with the token used for authentication when - * reconnecting to the cloud app - * @param cloud_transport_type Filled with the transport type used by the - * cloud application (ex. "WSS") - * @param hybrid_app_preference Filled with the hybrid app preference for the - * cloud application set by the user - */ - bool GetCloudAppParameters(const std::string& policy_app_id, - bool& enabled, - std::string& endpoint, - std::string& certificate, - std::string& auth_token, - std::string& cloud_transport_type, - std::string& hybrid_app_preference) const OVERRIDE; + * @brief Get a list of enabled local applications + * @return enabled_apps List filled with the policy app id of each enabled + * local application + */ + std::vector<std::string> GetEnabledLocalApps() const OVERRIDE; + + bool GetAppProperties(const std::string& policy_app_id, + AppProperties& out_app_properties) const OVERRIDE; /** * @ brief Initialize new cloud app in the policy table @@ -684,10 +752,13 @@ class PolicyManagerImpl : public PolicyManager { /** * @brief OnAppRegisteredOnMobile allows to handle event when application were * succesfully registered on mobile device. - * It will send OnAppPermissionSend notification and will try to start PTU. * + * It will send OnAppPermissionSend notification and will try to start PTU. + * + * @param device_id device identifier * @param application_id registered application. */ - void OnAppRegisteredOnMobile(const std::string& application_id) OVERRIDE; + void OnAppRegisteredOnMobile(const std::string& device_id, + const std::string& application_id) OVERRIDE; void OnDeviceSwitching(const std::string& device_id_from, const std::string& device_id_to) OVERRIDE; @@ -726,6 +797,11 @@ class PolicyManagerImpl : public PolicyManager { AppIdURL RetrySequenceUrl(const struct RetrySequenceURL& rs, const EndpointUrls& urls) const OVERRIDE; + /** + * @brief Trigger a PTU once on startup if it is required + */ + virtual void TriggerPTUOnStartupIfRequired() OVERRIDE; + #ifdef BUILD_TESTS /** * @brief Getter for cache_manager instance @@ -780,6 +856,12 @@ class PolicyManagerImpl : public PolicyManager { int32_t timespan_seconds) OVERRIDE; // Interface StatisticsManager (end) + void OnLocalAppAdded() OVERRIDE; + + bool IsNewApplication(const std::string& application_id) const OVERRIDE; + + void ResetTimeout() OVERRIDE; + protected: #ifdef USE_HMI_PTU_DECRYPTION /** @@ -820,10 +902,19 @@ class PolicyManagerImpl : public PolicyManager { * @param snapshot Shared pointer to current copy of policy table * @return Collection per-application results */ - void CheckPermissionsChanges( + CheckAppPolicyResults CheckPermissionsChanges( const std::shared_ptr<policy_table::Table> update, const std::shared_ptr<policy_table::Table> snapshot); + void ProcessAppPolicyCheckResults( + const CheckAppPolicyResults& results, + const rpc::policy_table_interface_base::ApplicationPolicies& + app_policies); + + void ProcessActionsForAppPolicies( + const ApplicationsPoliciesActions& actions, + const policy_table::ApplicationPolicies& app_policies); + /** * @brief Compares current policies to the updated one. * Trigger actions in case if certain fields after update were changed. @@ -877,13 +968,6 @@ class PolicyManagerImpl : public PolicyManager { 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 */ @@ -891,9 +975,12 @@ class PolicyManagerImpl : public PolicyManager { /** * @brief Checks whether need ask the permission of users + * @param device_id device identifier + * @param app_id policy application id * @return true if user consent is needed */ - virtual bool IsConsentNeeded(const std::string& app_id); + virtual bool IsConsentNeeded(const std::string& device_id, + const std::string& app_id); /** * @brief Changes isConsentNeeded for app pending permissions, in case @@ -936,7 +1023,12 @@ class PolicyManagerImpl : public PolicyManager { /** * @brief Starts new retry sequence */ - void RetrySequence(); + void OnPTUIterationTimeout(); + + /** + * @brief Check that new applications for PTU were registered + */ + bool HasApplicationForPTU() const; private: /** @@ -967,6 +1059,9 @@ class PolicyManagerImpl : public PolicyManager { void SendAppPermissionsChanged(const std::string& device_id, const std::string& application_id) OVERRIDE; + void SendOnAppPropertiesChangeNotification( + const std::string& policy_app_id) const OVERRIDE; + /** * @brief notify listener of updated auth token for a given policy id * @param policy_app_id the app id that has an updated auth token @@ -1036,6 +1131,11 @@ class PolicyManagerImpl : public PolicyManager { uint32_t retry_sequence_index_; /** + * @brief Applications pending count ready for PTU + */ + uint32_t applications_pending_ptu_count_; + + /** * @brief Lock for guarding retry sequence */ sync_primitives::Lock retry_sequence_lock_; @@ -1070,19 +1170,44 @@ class PolicyManagerImpl : public PolicyManager { RetrySequenceURL retry_sequence_url_; /** - * @brief Flag for notifying that invalid PTU was received + * @brief Flag for notifying that PTU was started */ - bool wrong_ptu_update_received_; + bool send_on_update_sent_out_; /** - * @brief Flag for notifying that PTU was started + * @brief List of chnaged application properties */ - bool send_on_update_sent_out_; + std::vector<std::string> app_properties_changed_list_; /** * @brief Flag for notifying that invalid PTU should be triggered */ bool trigger_ptu_; + + /** + * @brief Flag for notifying that PTU was requested + */ + bool ptu_requested_; + + /** + * @brief Last registered application id on mobile + */ + std::string last_registered_policy_app_id_; + + typedef std::list<std::pair<std::string, AppPoliciesValueType> > + PendingAppPolicyActionsList; + + /** + * @brief List containing device_id and pending permissions structure pairs + * which can be processed later on demand + */ + PendingAppPolicyActionsList notify_system_list_; + + /** + * @brief List containing device_id and pending permissions structure pairs + * which can be processed later on demand + */ + PendingAppPolicyActionsList send_permissions_list_; }; } // namespace policy diff --git a/src/components/policy/policy_regular/include/policy/policy_table/enums.h b/src/components/policy/policy_regular/include/policy/policy_table/enums.h index ecb44943aa..05b39a0082 100644 --- a/src/components/policy/policy_regular/include/policy/policy_table/enums.h +++ b/src/components/policy/policy_regular/include/policy/policy_table/enums.h @@ -34,567 +34,12 @@ #define SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_POLICY_TABLE_ENUMS_H_ #include <string> +#include "generated_HMI_API_policy_types.h" +#include "generated_MOBILE_API_policy_types.h" namespace rpc { namespace policy_table_interface_base { -enum Priority { - P_EMERGENCY, - P_NAVIGATION, - P_VOICECOM, - P_COMMUNICATION, - P_NORMAL, - P_PROJECTION, - 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_TURNSIGNAL, - P_FUELLEVEL, - P_FUELLEVEL_STATE, - P_HEADLAMPSTATUS, - P_INSTANTFUELCONSUMPTION, - P_FUELRANGE, - P_ODOMETER, - P_TIREPRESSURE, - P_WIPERSTATUS, - P_VIN, - P_ACCPEDALPOSITION, - P_BELTSTATUS, - P_ELECTRONICPARKBRAKESTATUS, - P_DRIVERBRAKING, - P_PRNDL, - P_RPM, - P_STEERINGWHEELANGLE, - P_ENGINEOILLIFE, - P_MYKEY, - P_CLOUD_APP_VEHICLE_ID, - P_AIRBAGSTATUS, - P_BODYINFORMATION, - P_CLUSTERMODESTATUS, - P_DEVICESTATUS, - P_EMERGENCYEVENT, - P_ECALLINFO, - 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, - AHT_PROJECTION, - AHT_REMOTE_CONTROL -}; -bool IsValidEnum(AppHMIType val); -const char* EnumToJsonString(AppHMIType val); -bool EnumFromJsonString(const std::string& literal, AppHMIType* result); - -enum RequestType { - RT_HTTP, - RT_FILE_RESUME, - RT_AUTH_REQUEST, - RT_AUTH_CHALLENGE, - RT_AUTH_ACK, - RT_PROPRIETARY, - RT_QUERY_APPS, - RT_LAUNCH_APP, - RT_LOCK_SCREEN_ICON_URL, - RT_TRAFFIC_MESSAGE_CHANNEL, - RT_DRIVER_PROFILE, - RT_VOICE_SEARCH, - RT_NAVIGATION, - RT_PHONE, - RT_CLIMATE, - RT_SETTINGS, - RT_VEHICLE_DIAGNOSTICS, - RT_EMERGENCY, - RT_MEDIA, - RT_FOTA, - RT_OEM_SPECIFIC, - RT_EMPTY // Added to allow empty Request Types handling -}; - -bool IsValidEnum(RequestType val); -const char* EnumToJsonString(RequestType val); -bool EnumFromJsonString(const std::string& literal, RequestType* result); - -enum Input { - I_GUI, - I_VUI, -}; -bool IsValidEnum(Input val); -const char* EnumToJsonString(Input val); -bool EnumFromJsonString(const std::string& literal, Input* result); - -enum ModuleType { - MT_CLIMATE, - MT_RADIO, - MT_SEAT, - MT_AUDIO, - MT_LIGHT, - MT_HMI_SETTINGS, - MT_EMPTY -}; -bool IsValidEnum(ModuleType val); -const char* EnumToJsonString(ModuleType val); -bool EnumFromJsonString(const std::string& literal, ModuleType* result); - -enum HybridAppPreference { HAP_MOBILE, HAP_CLOUD, HAP_BOTH }; -bool IsValidEnum(HybridAppPreference val); -const char* EnumToJsonString(HybridAppPreference val); -bool EnumFromJsonString(const std::string& literal, - HybridAppPreference* result); - -/** - * @brief Enumeration FunctionID. - * - * Enumeration linking function names with function IDs in AppLink protocol. - * Assumes enumeration starts at value 0. - */ -enum FunctionID { - /** - * @brief RESERVED. - */ - RESERVED = 0, - - /** - * @brief RegisterAppInterfaceID. - */ - RegisterAppInterfaceID = 1, - - /** - * @brief UnregisterAppInterfaceID. - */ - UnregisterAppInterfaceID = 2, - - /** - * @brief SetGlobalPropertiesID. - */ - SetGlobalPropertiesID = 3, - - /** - * @brief ResetGlobalPropertiesID. - */ - ResetGlobalPropertiesID = 4, - - /** - * @brief AddCommandID. - */ - AddCommandID = 5, - - /** - * @brief DeleteCommandID. - */ - DeleteCommandID = 6, - - /** - * @brief AddSubMenuID. - */ - AddSubMenuID = 7, - - /** - * @brief DeleteSubMenuID. - */ - DeleteSubMenuID = 8, - - /** - * @brief CreateInteractionChoiceSetID. - */ - CreateInteractionChoiceSetID = 9, - - /** - * @brief PerformInteractionID. - */ - PerformInteractionID = 10, - - /** - * @brief DeleteInteractionChoiceSetID. - */ - DeleteInteractionChoiceSetID = 11, - - /** - * @brief AlertID. - */ - AlertID = 12, - - /** - * @brief ShowID. - */ - ShowID = 13, - - /** - * @brief SpeakID. - */ - SpeakID = 14, - - /** - * @brief SetMediaClockTimerID. - */ - SetMediaClockTimerID = 15, - - /** - * @brief PerformAudioPassThruID. - */ - PerformAudioPassThruID = 16, - - /** - * @brief EndAudioPassThruID. - */ - EndAudioPassThruID = 17, - - /** - * @brief SubscribeButtonID. - */ - SubscribeButtonID = 18, - - /** - * @brief UnsubscribeButtonID. - */ - UnsubscribeButtonID = 19, - - /** - * @brief SubscribeVehicleDataID. - */ - SubscribeVehicleDataID = 20, - - /** - * @brief UnsubscribeVehicleDataID. - */ - UnsubscribeVehicleDataID = 21, - - /** - * @brief GetVehicleDataID. - */ - GetVehicleDataID = 22, - - /** - * @brief ReadDIDID. - */ - ReadDIDID = 23, - - /** - * @brief GetDTCsID. - */ - GetDTCsID = 24, - - /** - * @brief ScrollableMessageID. - */ - ScrollableMessageID = 25, - - /** - * @brief SliderID. - */ - SliderID = 26, - - /** - * @brief ShowConstantTBTID. - */ - ShowConstantTBTID = 27, - - /** - * @brief AlertManeuverID. - */ - AlertManeuverID = 28, - - /** - * @brief UpdateTurnListID. - */ - UpdateTurnListID = 29, - - /** - * @brief ChangeRegistrationID. - */ - ChangeRegistrationID = 30, - - /** - * @brief GenericResponseID. - */ - GenericResponseID = 31, - - /** - * @brief PutFileID. - */ - PutFileID = 32, - - /** - * @brief DeleteFileID. - */ - DeleteFileID = 33, - - /** - * @brief ListFilesID. - */ - ListFilesID = 34, - - /** - * @brief SetAppIconID. - */ - SetAppIconID = 35, - - /** - * @brief SetDisplayLayoutID. - */ - SetDisplayLayoutID = 36, - - /** - * @brief DiagnosticMessageID. - */ - DiagnosticMessageID = 37, - - /** - * @brief SystemRequestID. - */ - SystemRequestID = 38, - - /** - * @brief SendLocationID. - */ - SendLocationID = 39, - - /** - * @brief DialNumberID. - */ - DialNumberID = 40, - - /** - * @brief ButtonPressID. - */ - ButtonPressID = 41, - - /** - * @brief GetInteriorVehicleDataID. - */ - GetInteriorVehicleDataID = 43, - - /** - * @brief SetInteriorVehicleDataID. - */ - SetInteriorVehicleDataID = 44, - - /** - * @brief GetWayPointsID. - */ - GetWayPointsID = 45, - - /** - * @brief SubscribeWayPointsID. - */ - SubscribeWayPointsID = 46, - - /** - * @brief UnsubscribeWayPointsID. - */ - UnsubscribeWayPointsID = 47, - - /** - * @brief GetSystemCapabilityID. - */ - GetSystemCapabilityID = 48, - - /** - * @brief SendHapticDataID. - */ - SendHapticDataID = 49, - - /** - * @brief SetCloudAppPropertiesID. - */ - SetCloudAppPropertiesID = 50, - - /** - * @brief GetCloudAppPropertiesID. - */ - GetCloudAppPropertiesID = 51, - - /** - * @brief PublishAppServiceID. - */ - PublishAppServiceID = 52, - - /** - * @brief GetAppServiceDataID. - */ - GetAppServiceDataID = 53, - - /** - * @brief GetFileID - */ - GetFileID = 54, - - /** - * @brief PerformAppServiceInteractionID. - */ - PerformAppServiceInteractionID = 55, - - /** - * @brief UnpublishAppServiceID. - */ - UnpublishAppServiceID = 56, - - /** - * @brief CloseApplicationID. - */ - CloseApplicationID = 58, - - /** - * @brief ShowAppMenuID. - */ - ShowAppMenuID = 59, - - /** - * @brief OnHMIStatusID. - */ - OnHMIStatusID = 32768, - - /** - * @brief OnAppInterfaceUnregisteredID. - */ - OnAppInterfaceUnregisteredID = 32769, - - /** - * @brief OnButtonEventID. - */ - OnButtonEventID = 32770, - - /** - * @brief OnButtonPressID. - */ - OnButtonPressID = 32771, - - /** - * @brief OnVehicleDataID. - */ - OnVehicleDataID = 32772, - - /** - * @brief OnCommandID. - */ - OnCommandID = 32773, - - /** - * @brief OnTBTClientStateID. - */ - OnTBTClientStateID = 32774, - - /** - * @brief OnDriverDistractionID. - */ - OnDriverDistractionID = 32775, - - /** - * @brief OnPermissionsChangeID. - */ - OnPermissionsChangeID = 32776, - - /** - * @brief OnAudioPassThruID. - */ - OnAudioPassThruID = 32777, - - /** - * @brief OnLanguageChangeID. - */ - OnLanguageChangeID = 32778, - - /** - * @brief OnKeyboardInputID. - */ - OnKeyboardInputID = 32779, - - /** - * @brief OnTouchEventID. - */ - OnTouchEventID = 32780, - - /** - * @brief OnSystemRequestID. - */ - OnSystemRequestID = 32781, - - /** - * @brief OnHashChangeID. - */ - OnHashChangeID = 32782, - - /** - * @brief OnInteriorVehicleDataID. - */ - OnInteriorVehicleDataID = 32783, - - /** - * @brief OnWayPointChangeID. - */ - OnWayPointChangeID = 32784, - - /** - * @brief OnRCStatusID. - */ - OnRCStatusID = 32785, - - /** - * @brief OnAppServiceDataID. - */ - OnAppServiceDataID = 32786, - - /** - * @brief OnSystemCapabilityUpdatedID - */ - OnSystemCapabilityUpdatedID = 32787, - - /** - * @brief EncodedSyncPDataID. - */ - EncodedSyncPDataID = 65536, - - /** - * @brief SyncPDataID. - */ - SyncPDataID = 65537, - - /** - * @brief OnEncodedSyncPDataID. - */ - OnEncodedSyncPDataID = 98304, - - /** - * @brief OnSyncPDataID. - */ - OnSyncPDataID = 98305 -}; -bool IsValidEnum(FunctionID val); -const char* EnumToJsonString(FunctionID val); -bool EnumFromJsonString(const std::string& literal, FunctionID* result); - extern const std::string kDefaultApp; extern const std::string kPreDataConsentApp; extern const std::string kDeviceApp; diff --git a/src/components/policy/policy_regular/include/policy/policy_table/policy_enum_schema_factory.h b/src/components/policy/policy_regular/include/policy/policy_table/policy_enum_schema_factory.h new file mode 100644 index 0000000000..2053923cfe --- /dev/null +++ b/src/components/policy/policy_regular/include/policy/policy_table/policy_enum_schema_factory.h @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2017, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_POLICY_TABLE_POLICY_ENUM_SCHEMA_FACTORY_H +#define SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_POLICY_TABLE_POLICY_ENUM_SCHEMA_FACTORY_H +#include <memory> +#include <string> + +#include "smart_objects/smart_schema.h" + +namespace rpc { +namespace policy_table_interface_base { + +class EnumSchemaItemFactory { + public: + /** + * @brief Get enum schema from enum name + * Implementation of this function should be generated from MOBILE_API.xml + * @param enum_name enum name to get schema factory for + * @return shared pointer to schema factory or empty shared pointer if + * enum_name is wrong + */ + static std::shared_ptr<ns_smart_device_link::ns_smart_objects::ISchemaItem> + Get(const std::string& enum_name); + + static bool IsRPCSpecVehicleDataType(const std::string& vd_name); +}; + +} // namespace policy_table_interface_base +} // namespace rpc +#endif // SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_POLICY_TABLE_POLICY_ENUM_SCHEMA_FACTORY_H diff --git a/src/components/policy/policy_regular/include/policy/policy_table/types.h b/src/components/policy/policy_regular/include/policy/policy_table/types.h index c2a8f901ad..2ffbf2e7ec 100644 --- a/src/components/policy/policy_regular/include/policy/policy_table/types.h +++ b/src/components/policy/policy_regular/include/policy/policy_table/types.h @@ -36,7 +36,9 @@ #include <climits> #include "policy/policy_table/enums.h" +#include "policy/policy_table/policy_enum_schema_factory.h" #include "rpc_base/rpc_message.h" +#include "utils/helpers.h" namespace Json { class Value; @@ -46,6 +48,7 @@ namespace policy_table_interface_base { struct AppLevel; struct ApplicationParams; struct DeviceParams; +struct EndpointProperty; struct MessageLanguages; struct MessageString; struct RpcParameters; @@ -67,16 +70,18 @@ typedef Array<Enum<AppHMIType>, 0, 255> AppHMITypes; typedef Array<Enum<HmiLevel>, 0, 4> HmiLevels; -typedef Array<Enum<Parameter>, 0, 255> Parameters; +typedef Array<String<0, 255>, 0, 255> Parameters; typedef Map<RpcParameters, 0, UINT_MAX> Rpc; -typedef Array<String<10, 255>, 1, 3> URL; +typedef Array<String<10, INT_MAX>, 1, 3> URL; typedef Map<URL, 1, 255> URLList; typedef Map<URLList, 1, 255> ServiceEndpoints; +typedef Map<EndpointProperty, 0, 255> ServiceEndpointProperties; + typedef uint8_t NumberOfNotificationsType; typedef Map<Integer<NumberOfNotificationsType, 0, 255>, 0, 7> NumberOfNotificationsPerMinute; @@ -203,6 +208,7 @@ struct ApplicationParams : PolicyBase { // App Service Params Optional<AppServiceParameters> app_service_parameters; Optional<Boolean> allow_unknown_rpc_passthrough; + Optional<Boolean> encryption_required; public: ApplicationParams(); @@ -268,6 +274,7 @@ struct Rpcs : CompositeType { public: Optional<String<1, 255> > user_consent_prompt; Nullable<Rpc> rpcs; + Optional<Boolean> encryption_required; public: Rpcs(); @@ -285,6 +292,24 @@ struct Rpcs : CompositeType { bool Validate() const; }; +struct EndpointProperty : CompositeType { + public: + Optional<String<0, 100> > version; + + EndpointProperty(); + ~EndpointProperty(); + explicit EndpointProperty(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; + void SetPolicyTableType(PolicyTableType pt_type) OVERRIDE; + + private: + bool Validate() const; +}; + struct ModuleConfig : CompositeType { public: Optional<Map<String<0, 100>, 0, 255> > device_certificates; @@ -296,6 +321,7 @@ struct ModuleConfig : CompositeType { Integer<uint16_t, 0, 65535> timeout_after_x_seconds; SecondsBetweenRetries seconds_between_retries; ServiceEndpoints endpoints; + Optional<ServiceEndpointProperties> endpoint_properties; NumberOfNotificationsPerMinute notifications_per_minute_by_priority; Optional<String<1, 100> > vehicle_make; Optional<String<1, 100> > vehicle_model; @@ -304,6 +330,8 @@ struct ModuleConfig : CompositeType { Optional<String<0, 65535> > certificate; Optional<Boolean> lock_screen_dismissal_enabled; + static const std::string kDefaultOemMappingServiceName; + public: ModuleConfig(); ModuleConfig(uint8_t exchange_after_x_ignition_cycles, @@ -312,6 +340,7 @@ struct ModuleConfig : CompositeType { uint16_t timeout_after_x_seconds, const SecondsBetweenRetries& seconds_between_retries, const ServiceEndpoints& endpoints, + const ServiceEndpointProperties& endpoint_properties, const NumberOfNotificationsPerMinute& notifications_per_minute_by_priority); ~ModuleConfig(); @@ -495,6 +524,88 @@ struct DeviceParams : CompositeType { bool Validate() const; }; +struct VehicleDataItem : CompositeType { + public: + static const std::vector<std::string> kPODTypes; + + static const std::string kInteger; + static const std::string kStruct; + static const std::string kString; + static const std::string kFloat; + static const std::string kDouble; + static const std::string kBoolean; + static const std::string kName; + static const std::string kParams; + + String<1, 255> name; + String<0, 255> type; + String<1, 255> key; + Boolean mandatory; + Optional<Array<VehicleDataItem, 0, 255> > params; + + Optional<Boolean> array; + Optional<String<0, 255> > since; + Optional<String<0, 255> > until; + Optional<Boolean> removed; + Optional<Boolean> deprecated; + Optional<Float<-INT32_MAX, INT32_MAX> > minvalue; + Optional<Float<-INT32_MAX, INT32_MAX> > maxvalue; + Optional<Integer<uint32_t, 0, UINT32_MAX> > minsize; + Optional<Integer<uint32_t, 0, UINT32_MAX> > maxsize; + Optional<Integer<uint32_t, 0, UINT32_MAX> > minlength; + Optional<Integer<uint32_t, 0, UINT32_MAX> > maxlength; + + VehicleDataItem(); + VehicleDataItem(const VehicleDataItem& policy_table); + explicit VehicleDataItem(const Json::Value* value__); + + bool operator==(const VehicleDataItem& vd); + + ~VehicleDataItem(); + + Json::Value ToJsonValue() const; + bool is_valid() const; + bool is_initialized() const; + bool struct_not_empty() const; + void ReportErrors(rpc::ValidationReport* report__) const; + virtual void SetPolicyTableType(PolicyTableType pt_type); + + /** + * @brief Validates type of vehicle data item according to + * POD types and generated from API enums. + * @return true if type is valid. + */ + bool ValidateTypes() const; + bool IsPrimitiveType() const; + bool ValidateNaming(std::string str) const; + + private: + bool Validate() const; +}; + +typedef Array<VehicleDataItem, 0, 255> VehicleDataItems; + +struct VehicleData : CompositeType { + public: + Optional<String<0, 100> > schema_version; + Optional<VehicleDataItems> schema_items; + + VehicleData(); + VehicleData(const VehicleData& vehicle_data); + VehicleData(const Json::Value* value__); + ~VehicleData(); + + 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; @@ -504,6 +615,7 @@ struct PolicyTable : CompositeType { Optional<ModuleMeta> module_meta; Optional<UsageAndErrorCounts> usage_and_error_counts; Optional<DeviceData> device_data; + Optional<VehicleData> vehicle_data; public: PolicyTable(); diff --git a/src/components/policy/policy_regular/include/policy/policy_types.h b/src/components/policy/policy_regular/include/policy/policy_types.h index 0be5919126..7f95d9132b 100644 --- a/src/components/policy/policy_regular/include/policy/policy_types.h +++ b/src/components/policy/policy_regular/include/policy/policy_types.h @@ -41,6 +41,7 @@ #include <utility> #include <vector> +#include "policy/policy_table/types.h" #include "transport_manager/common.h" #include "utils/helpers.h" @@ -74,9 +75,16 @@ enum PolicyTableStatus { StatusUpToDate = 0, StatusUpdatePending, StatusUpdateRequired, - StatusUnknown + StatusUnknown, + StatusProcessingSnapshot }; +enum class PTUIterationType { DefaultIteration = 0, RetryIteration }; + +enum class ResetRetryCountType { kResetWithStatusUpdate = 0, kResetInternally }; + +typedef rpc::Optional<rpc::Boolean> EncryptionRequired; + // Code generator uses String class name, so this typedef was renamed to PTSring typedef std::string PTString; typedef std::vector<uint8_t> BinaryMessage; @@ -102,6 +110,7 @@ struct ParameterPermissions struct RpcPermissions { HMIPermissions hmi_permissions; ParameterPermissions parameter_permissions; + EncryptionRequired require_encryption; }; typedef std::map<RpcName, RpcPermissions> Permissions; @@ -225,8 +234,11 @@ struct DeviceInfo { using namespace helpers; static const std::string bluetooth("BLUETOOTH"); static const std::string wifi("WIFI"); + static const std::string webengine("WEBENGINE_WEBSOCKET"); if (Compare<std::string, EQ, ONE>(deviceType, bluetooth, wifi)) { connection_type.assign("BTMAC"); + } else if (Compare<std::string, EQ, ONE>(deviceType, webengine)) { + connection_type.assign(""); } } }; @@ -428,6 +440,30 @@ struct ExternalConsentStatusItemSorter { }; /** + * @brief The ApplicationPolicyActions struct contains actions which should be + * done for some application + */ +struct ApplicationPolicyActions { + ApplicationPolicyActions() + : is_notify_system(false) + , is_send_permissions_to_app(false) + , is_consent_needed(false) + , app_properties_changed(false) {} + + bool is_notify_system; + bool is_send_permissions_to_app; + bool is_consent_needed; + bool app_properties_changed; +}; + +/** + * @brief ApplicationsPoliciesActions map of actions to be done for every + * application + */ +typedef std::map<std::string, ApplicationPolicyActions> + ApplicationsPoliciesActions; + +/** * @brief Customer connectivity settings status */ typedef std::set<ExternalConsentStatusItem, ExternalConsentStatusItemSorter> @@ -473,10 +509,12 @@ enum PermissionsCheckResult { RESULT_NICKNAME_MISMATCH, RESULT_PERMISSIONS_REVOKED, RESULT_CONSENT_NEEDED, - RESULT_CONSENT_NOT_REQIURED, + RESULT_CONSENT_NOT_REQUIRED, RESULT_PERMISSIONS_REVOKED_AND_CONSENT_NEEDED, RESULT_REQUEST_TYPE_CHANGED, - RESULT_REQUEST_SUBTYPE_CHANGED + RESULT_REQUEST_SUBTYPE_CHANGED, + RESULT_ENCRYPTION_REQUIRED_FLAG_CHANGED, + RESULT_APP_PROPERTIES_CHANGED }; /** @@ -492,6 +530,68 @@ typedef std::set<std::pair<std::string, PermissionsCheckResult> > */ typedef std::pair<uint32_t, uint32_t> AppIdURL; +/** + * @brief The AppProperties struct contains application properties + */ +struct AppProperties { + AppProperties() + : endpoint() + , certificate() + , enabled(false) + , auth_token() + , transport_type() + , hybrid_app_preference() {} + + AppProperties(std::string endpoint, + std::string certificate, + bool enabled, + std::string auth_token, + std::string transport_type, + std::string hybrid_app_preference) + : endpoint(endpoint) + , certificate(certificate) + , enabled(enabled) + , auth_token(auth_token) + , transport_type(transport_type) + , hybrid_app_preference(hybrid_app_preference) {} + + /** + * @brief endpoint Filled with the endpoint used to connect to the cloud + * application. + * @note should be absent for local applications + */ + std::string endpoint; + + /** + * @brief certificate Filled with the certificate used for creation + * of a secure connection to the cloud application + */ + std::string certificate; + + /** + * @brief enabled Whether or not the app is enabled + */ + bool enabled; + + /** + * @brief auth_token Filled with the token used for authentication when + * reconnecting to the cloud app + */ + std::string auth_token; + + /** + * @brief transport_type Filled with the transport type used by the + * cloud/local application (ex. "WSS") + */ + std::string transport_type; + + /** + * @brief hybrid_app_preference Filled with the hybrid app preference for the + * application set by the user + */ + std::string hybrid_app_preference; +}; + } // namespace policy #endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_TYPES_H_ diff --git a/src/components/policy/policy_regular/include/policy/pt_representation.h b/src/components/policy/policy_regular/include/policy/pt_representation.h index 0534b27093..467fb4641f 100644 --- a/src/components/policy/policy_regular/include/policy/pt_representation.h +++ b/src/components/policy/policy_regular/include/policy/pt_representation.h @@ -123,11 +123,6 @@ class PTRepresentation { 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. @@ -157,14 +152,6 @@ class PTRepresentation { virtual EndpointUrls GetUpdateUrls(int service_type) = 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 diff --git a/src/components/policy/policy_regular/include/policy/sql_pt_queries.h b/src/components/policy/policy_regular/include/policy/sql_pt_queries.h index bada9a003a..315c30b995 100644 --- a/src/components/policy/policy_regular/include/policy/sql_pt_queries.h +++ b/src/components/policy/policy_regular/include/policy/sql_pt_queries.h @@ -49,7 +49,6 @@ 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; @@ -143,6 +142,19 @@ extern const std::string kSelectDBVersion; extern const std::string kUpdateDBVersion; extern const std::string kSaveModuleMeta; extern const std::string kSelectModuleMeta; +extern const std::string kInsertVehicleDataItem; +extern const std::string kSelectVehicleDataItem; +extern const std::string kDeleteVehicleDataItems; +extern const std::string kInsertVehicleDataItemParams; +extern const std::string kSelectVehicleDataItemParams; +extern const std::string kDeleteVehicleDataItemParams; +extern const std::string kSelectVehicleDataItemWithVersion; +extern const std::string kSelectPrimitiveVehicleDataItems; +extern const std::string kSelectCompositeVehicleDataItemsKey; +extern const std::string kSelectVehicleDataSchemaVersion; +extern const std::string kInsertVehicleDataSchemaVersion; +extern const std::string kSelectEndpointProperties; +extern const std::string kInsertEndpointVersion; } // namespace sql_pt } // namespace policy diff --git a/src/components/policy/policy_regular/include/policy/sql_pt_representation.h b/src/components/policy/policy_regular/include/policy/sql_pt_representation.h index e95620fbc2..1bb74e028c 100644 --- a/src/components/policy/policy_regular/include/policy/sql_pt_representation.h +++ b/src/components/policy/policy_regular/include/policy/sql_pt_representation.h @@ -44,6 +44,7 @@ namespace policy_table = rpc::policy_table_interface_base; namespace utils { namespace dbms { class SQLDatabase; +class SQLQuery; } // namespace dbms } // namespace utils @@ -52,6 +53,7 @@ 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, @@ -69,13 +71,11 @@ class SQLPTRepresentation : public virtual PTRepresentation { 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 std::string GetLockScreenIconUrl() const; virtual int GetNotificationsNumber(const std::string& priority); virtual bool GetPriority(const std::string& policy_app_id, std::string* priority); @@ -123,6 +123,9 @@ class SQLPTRepresentation : public virtual PTRepresentation { policy_table::ConsumerFriendlyMessages* messages) const; virtual bool GatherApplicationPoliciesSection( policy_table::ApplicationPoliciesSection* policies) const; + virtual bool GatherVehicleDataItems( + policy_table::VehicleDataItems* vehicle_data_items) const; + virtual bool GatherVehicleData(policy_table::VehicleData* vehicle_data) const; bool GatherAppGroup(const std::string& app_id, policy_table::Strings* app_groups) const; @@ -159,6 +162,9 @@ class SQLPTRepresentation : public virtual PTRepresentation { virtual bool SaveSpecificAppPolicy( const policy_table::ApplicationPolicies::value_type& app); virtual bool SaveDevicePolicy(const policy_table::DevicePolicy& device); + virtual bool SaveVehicleDataItems( + const policy_table::VehicleDataItems& vehicle_data_items); + virtual bool SaveVehicleData(const policy_table::VehicleData& vehicle_data); virtual bool SaveMessageString(const std::string& type, const std::string& lang, @@ -202,6 +208,26 @@ class SQLPTRepresentation : public virtual PTRepresentation { virtual bool IsDBVersionActual() const OVERRIDE; virtual bool UpdateDBVersion() const OVERRIDE; + policy_table::VehicleDataItems GetVehicleDataItem( + const std::string& name, const std::string& key) const; + bool InsertVehicleDataItem( + const policy_table::VehicleDataItem& vehicle_data_item); + bool VehicleDataItemExists( + const policy_table::VehicleDataItem& vehicle_data_item) const; + + /** + * @brief Retrieves vehicle data items of type Struct (which contains + * params) from the database including these parameters. + * @return Array of composite VehicleDataItems + */ + policy_table::VehicleDataItems SelectCompositeVehicleDataItems() const; + + /** + * @brief Retrieves vehicle data items of non Struct type from the database. + * @return Array of primitive VehicleDataItems + */ + policy_table::VehicleDataItems SelectPrimitiveVehicleDataItems() const; + private: static const std::string kDatabaseName; utils::dbms::SQLDatabase* db_; @@ -217,12 +243,17 @@ class SQLPTRepresentation : public virtual PTRepresentation { const int32_t GetDBVersion() const; bool SaveRpcs(int64_t group_id, const policy_table::Rpc& rpcs); bool SaveServiceEndpoints(const policy_table::ServiceEndpoints& endpoints); + bool SaveServiceEndpointProperties( + const policy_table::ServiceEndpointProperties& endpoint_properties); 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); + policy_table::VehicleDataItem PopulateVDIFromQuery( + const utils::dbms::SQLQuery& query) const; + bool DeleteVehicleDataItems() const; bool is_in_memory; }; diff --git a/src/components/policy/policy_regular/include/policy/status.h b/src/components/policy/policy_regular/include/policy/status.h index 8fd3ff559e..4d8bc47dae 100644 --- a/src/components/policy/policy_regular/include/policy/status.h +++ b/src/components/policy/policy_regular/include/policy/status.h @@ -52,6 +52,7 @@ enum UpdateEvent { kOnResetPolicyTableRequireUpdate, kOnResetPolicyTableNoUpdate, kScheduleUpdate, + kPendingUpdate, kScheduleManualUpdate, kOnResetRetrySequence, kNoEvent @@ -118,6 +119,39 @@ class Status { }; /** + * @brief The UpdatePendingStatus class represents cases when SDL knows that an + * update is required but before the snapshot is sent to the HMI + */ +class UpdatePendingStatus : public Status { + public: + /** + * @brief Constructor + */ + UpdatePendingStatus(); + + /** + * @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(UpdateStatusManagerInterface* manager, + UpdateEvent event) OVERRIDE; + + /** + * @brief Check whether update is required in terms of status + * @return True if update is required, otherwise - false + */ + bool IsUpdateRequired() const OVERRIDE; + + /** + * @brief Check whether update is pending in terms of status + * @return True if update is pending, otherwise - false + */ + bool IsUpdatePending() const OVERRIDE; +}; + +/** * @brief The UpToDateStatus class represents 'up-to-date' status */ class UpToDateStatus : public Status { diff --git a/src/components/policy/policy_regular/include/policy/update_status_manager.h b/src/components/policy/policy_regular/include/policy/update_status_manager.h index 0c79bf0ba4..fb679ac10b 100644 --- a/src/components/policy/policy_regular/include/policy/update_status_manager.h +++ b/src/components/policy/policy_regular/include/policy/update_status_manager.h @@ -149,6 +149,12 @@ class UpdateStatusManager : public UpdateStatusManagerInterface { void ScheduleUpdate(); /** + * @brief PendingUpdate will change state from Update_Needed + * to Update_Pending + */ + void PendingUpdate(); + + /** * @brief ScheduleUpdate allows to schedule next update. * It will change state to Update_Needed, that's is * and will not send any notifications about updating to HMI |