diff options
Diffstat (limited to 'src/components/include/policy')
-rw-r--r-- | src/components/include/policy/policy_external/policy/policy_listener.h | 140 | ||||
-rw-r--r-- | src/components/include/policy/policy_external/policy/policy_manager.h | 569 | ||||
-rw-r--r-- | src/components/include/policy/policy_external/policy/policy_settings.h (renamed from src/components/include/policy/policy_settings.h) | 6 | ||||
-rw-r--r-- | src/components/include/policy/policy_external/policy/usage_statistics/app_stopwatch.h | 50 | ||||
-rw-r--r-- | src/components/include/policy/policy_external/policy/usage_statistics/statistics_manager.h (renamed from src/components/include/policy/usage_statistics/statistics_manager.h) | 2 | ||||
-rw-r--r-- | src/components/include/policy/policy_regular/policy/policy_manager.h | 521 | ||||
-rw-r--r-- | src/components/include/policy/policy_regular/policy/policy_settings.h | 42 | ||||
-rw-r--r-- | src/components/include/policy/policy_regular/policy/usage_statistics/statistics_manager.h | 86 | ||||
-rw-r--r-- | src/components/include/policy/policy_types.h | 318 |
9 files changed, 1412 insertions, 322 deletions
diff --git a/src/components/include/policy/policy_external/policy/policy_listener.h b/src/components/include/policy/policy_external/policy/policy_listener.h new file mode 100644 index 0000000000..f3388beb95 --- /dev/null +++ b/src/components/include/policy/policy_external/policy/policy_listener.h @@ -0,0 +1,140 @@ +/* + 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_LISTENER_H_ +#define SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_LISTENER_H_ + +#include <queue> + +#include "policy/policy_types.h" +#include "utils/custom_string.h" + +namespace policy { + +namespace custom_str = utils::custom_string; + +class PolicyListener { + public: + virtual ~PolicyListener() {} + virtual void OnPermissionsUpdated(const std::string& policy_app_id, + const Permissions& permissions, + const policy::HMILevel& default_hmi) = 0; + virtual void OnPermissionsUpdated(const std::string& policy_app_id, + const Permissions& permissions) = 0; + virtual void OnPendingPermissionChange(const std::string& policy_app_id) = 0; + virtual void OnUpdateStatusChanged(const std::string&) = 0; + /** + * Gets device ID + * @param policy_app_id + * @return device ID + * @deprecated see std::vector<std::string> GetDevicesIds(const std::string&) + */ + virtual std::string OnCurrentDeviceIdUpdateRequired( + const std::string& policy_app_id) = 0; + virtual void OnSystemInfoUpdateRequired() = 0; + virtual custom_str::CustomString GetAppName( + const std::string& policy_app_id) = 0; + virtual void OnUpdateHMIAppType( + std::map<std::string, StringArray> app_hmi_types) = 0; + + /** + * @brief CanUpdate allows to find active application + * and check whether related device consented. + * + * @return true if there are at least one application has been registered + * with consented device. + */ + virtual bool CanUpdate() = 0; + + /** + * @brief OnSnapshotCreated the notification which will be sent + * when snapshot for PTU has been created. + * + * @param pt_string the snapshot + * + * @param retry_seconds retry sequence timeouts. + * + * @param timeout_exceed timeout. + */ + virtual void OnSnapshotCreated(const BinaryMessage& pt_string, + const std::vector<int>& retry_seconds, + uint32_t timeout_exceed) = 0; + + /** + * @brief Make appropriate changes for related applications permissions and + * notify them, if it possible + * @param device_id Unique device id, which consent had been changed + * @param device_consent Device consent, which is done by user + */ + virtual void OnDeviceConsentChanged(const std::string& device_id, + bool is_allowed) = 0; + + /** + * @brief Sends OnAppPermissionsChanged notification to HMI + * @param permissions contains parameter for OnAppPermisionChanged + * @param policy_app_id contains policy application id + */ + virtual void SendOnAppPermissionsChanged( + const AppPermissions& permissions, + const std::string& policy_app_id) const = 0; + + /** + * @brief GetAvailableApps allows to obtain list of registered applications. + */ + virtual void GetAvailableApps(std::queue<std::string>&) = 0; + + /** + * @brief OnCertificateUpdated the callback which signals if certificate field + * has been updated during PTU + * + * @param certificate_data the value of the updated field. + */ + virtual void OnCertificateUpdated(const std::string& certificate_data) = 0; + + /** + * @brief OnPTUFinishedd the callback which signals PTU has finished + * + * @param ptu_result the result from the PTU - true if successful, + * otherwise false. + */ + virtual void OnPTUFinished(const bool ptu_result) = 0; + + /** + * @brief Collects currently registered applications ids linked to their + * device id + * @return Collection of device_id-to-app_id links + */ + virtual void GetRegisteredLinks( + std::map<std::string, std::string>& out_links) const = 0; +}; +} // namespace policy +#endif // SRC_COMPONENTS_POLICY_POLICY_EXTERNAL_INCLUDE_POLICY_POLICY_LISTENER_H_ diff --git a/src/components/include/policy/policy_external/policy/policy_manager.h b/src/components/include/policy/policy_external/policy/policy_manager.h new file mode 100644 index 0000000000..9201956e2a --- /dev/null +++ b/src/components/include/policy/policy_external/policy/policy_manager.h @@ -0,0 +1,569 @@ +/* + 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_INCLUDE_POLICY_POLICY_MANAGER_H_ +#define SRC_COMPONENTS_INCLUDE_POLICY_POLICY_MANAGER_H_ + +#include <vector> + +#include "utils/callable.h" + +#include "policy/policy_types.h" +#include "policy/policy_table/types.h" +#include "policy/policy_listener.h" +#include "usage_statistics/statistics_manager.h" + +namespace policy { +class PolicySettings; +typedef utils::SharedPtr<utils::Callable> StatusNotifier; + +class PolicyManager : public usage_statistics::StatisticsManager { + public: + /** + * @brief The NotificationMode enum defines whether application will be + * notified about changes done (e.g. after consents were changed) or not + */ + enum NotificationMode { kSilentMode, kNotifyApplicationMode }; + virtual ~PolicyManager() {} + + virtual void set_listener(PolicyListener* listener) = 0; + + /** + * Inits Policy Table + * @param file_name Path to preloaded PT file + * @return true if successfully + */ + virtual bool InitPT(const std::string& file_name, + const PolicySettings* settings) = 0; + + /** + * @brief Updates Policy Table from binary message received from + * mobile device. Saves to Policy Table diff between Policy Table + * sent in snapshot and received Policy Table. + * @param file name of file with update policy table + * @param pt_content PTU as binary string + * @return bool Success of operation + */ + virtual bool LoadPT(const std::string& file, + const BinaryMessage& pt_content) = 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; + + virtual std::string GetUpdateUrl(int service_type) = 0; + + /** + * @brief Gets all URLs for sending PTS to from PT itself. + * @param service_type Service specifies user of URL + * @return vector of urls + */ + + virtual void GetUpdateUrls(const uint32_t service_type, + EndpointUrls& out_end_points) = 0; + virtual void GetUpdateUrls(const std::string& 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 PTU is needed, for this PTS has to be formed and sent. + */ + virtual void RequestPTUpdate() = 0; + + /** + * @brief Check if specified RPC for specified application + * has permission to be executed in specified HMI Level + * and also its permitted params. + * @param app_id Id of application provided during registration + * @param hmi_level Current HMI Level of application + * @param rpc Name of RPC + * @param 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, + const RPCParams& rpc_params, + CheckPermissionResult& result) = 0; + + /** + * @brief Clear all record of user consents. Used during Factory Reset. + * @return bool Success of operation + */ + virtual bool ResetUserConsent() = 0; + + /** + * @brief Returns current status of policy table for HMI + * @return Current status of policy table + */ + virtual std::string GetPolicyTableStatus() const = 0; + + /** + * Checks is PT exceeded kilometers + * @param kilometers current kilometers at odometer + * @return true if exceeded + */ + virtual void KmsChanged(int kilometers) = 0; + + /** + * Increments counter of ignition cycles + */ + virtual void IncrementIgnitionCycles() = 0; + + /** + * @brief Exchange by hmi or mobile request + */ + virtual std::string ForcePTExchange() = 0; + + /** + * @brief ExchangeByUserRequest + */ + virtual std::string ForcePTExchangeAtUserRequest() = 0; + + /** + * Resets retry sequence + */ + virtual void ResetRetrySequence() = 0; + + /** + * Gets timeout to wait before next retry updating PT + * If timeout is less or equal to zero then the retry sequence is not need. + * @return timeout in seconds + */ + virtual int NextRetryTimeout() = 0; + + /** + * Gets timeout to wait until receive response + * @return timeout in seconds + */ + virtual uint32_t TimeoutExchangeMSec() = 0; + + /** + * @brief List of timeouts in seconds between retries + * when attempt to update PT fails + * @return List of delays between attempts. + */ + virtual const std::vector<int> RetrySequenceDelaysSeconds() = 0; + + /** + * Handler of exceeding timeout of exchanging policy table + */ + virtual void OnExceededTimeout() = 0; + + /** + * @brief Handler of PTS sending out + */ + virtual void OnUpdateStarted() = 0; + + /** + * @brief Gets user consent for mobile device data connection + * @param device_id Unique device identifier + * @return status of device consent + */ + virtual DeviceConsent GetUserConsentForDevice( + const std::string& device_id) const = 0; + + /** + * @brief Gets user consent for application + * @param device_id Device id + * @param policy_app_id Unique application id + * @param permissions Array of functional groups permissions + */ + virtual void GetUserConsentForApp( + const std::string& device_id, + const std::string& policy_app_id, + std::vector<FunctionalGroupPermission>& permissions) = 0; + + /** + * @brief Set user consent for mobile device data connection + * @param device_id Unique device identifier + * @param is_allowed User consent for usage device data connection + */ + virtual void SetUserConsentForDevice(const std::string& device_id, + const bool is_allowed) = 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, + const bool is_device_allowed) = 0; + + /** + * Sets counter value that passed for receiving PT UPdate. + */ + virtual void PTUpdatedAt(Counters counter, int value) = 0; + + /** + * @brief Retrieves data from app_policies about app on its registration: + * @param app_id - id of registered app + * @param app_types Section on HMI where app can appear (Navigation, Phone + * etc) + * @param nicknames Synonyms for application + */ + virtual bool GetInitialAppData(const std::string& application_id, + StringArray* nicknames = NULL, + StringArray* app_hmi_types = NULL) = 0; + + /** + * @brief Add's device to policy table + * @param device_id Device mac address + * @param connection_type Device connection type + */ + virtual void AddDevice(const std::string& device_id, + const std::string& connection_type) = 0; + + /** + * @brief Stores device parameters received during application registration + * to policy table + * @param device_id Device mac address + * @param device_info Received device parameters + */ + virtual void SetDeviceInfo(const std::string& device_id, + const DeviceInfo& device_info) = 0; + + /** + * @brief Set user consent for application functional groups + * @param permissions User-defined application group pemissions. + * The permissions is not const reference because it may contains + * valid data as well as invalid. So we will remove all invalid data + * from this structure. + */ + virtual void SetUserConsentForApp(const PermissionConsent& permissions, + const NotificationMode mode) = 0; + + /** + * @brief Get default HMI level for 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) const = 0; + + /** + * @brief Get priority for 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 Get user friendly messages for given RPC messages and language + * @param message_codes RPC message codes + * @param language Language + * @return Array of structs with appropriate message parameters + */ + virtual std::vector<UserFriendlyMessage> GetUserFriendlyMessages( + const std::vector<std::string>& message_code, + const std::string& language, + const std::string& active_hmi_language) = 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 resulting RPCs permissions for application which started on + * specific device + * @param device_id Device id + * @param policy_app_id Unique application id + * @param permissions Array of functional groups permissions + */ + virtual void GetPermissionsForApp( + const std::string& device_id, + const std::string& policy_app_id, + std::vector<FunctionalGroupPermission>& permissions) = 0; + + /** + * @brief Gets specific application permissions changes since last policy + * table update + * @param policy_app_id Unique application id + * @return Permissions changes + */ + virtual AppPermissions GetAppPermissionsChanges( + const std::string& policy_app_id) = 0; + + virtual void RemovePendingPermissionChanges(const std::string& app_id) = 0; + + /** + * @brief Return device id, which hosts specific application + * @param Application id, which is required to update device id + */ + virtual std::string& GetCurrentDeviceId( + const std::string& policy_app_id) const = 0; + + /** + * @brief Set current system language + * @param language Language + */ + virtual void SetSystemLanguage(const std::string& language) = 0; + + /** + * @brief Set data from GetSystemInfo response to policy table + * @param ccpu_version CCPU version + * @param wers_country_code WERS country code + * @param language System language + */ + virtual void SetSystemInfo(const std::string& ccpu_version, + const std::string& wers_country_code, + const std::string& language) = 0; + + /** + * @brief Send OnPermissionsUpdated for choosen application + * @param application_id + */ + virtual void SendNotificationOnPermissionsUpdated( + const std::string& application_id) = 0; + + /** + * Marks device as upaired + * @param device_id id device + */ + virtual void MarkUnpairedDevice(const std::string& device_id) = 0; + + /** + * @brief Adds, application to the db or update existed one + * run PTU if policy update is necessary for application. + * @param Application id assigned by Ford to the application + * @return function that will notify update manager about new application + */ + virtual StatusNotifier AddApplication( + const std::string& application_id, + const rpc::policy_table_interface_base::AppHmiTypes& hmi_types) = 0; + + /** + * @brief Removes unpaired device records and related records from DB + * @param device_ids List of device_id, which should be removed + * @return true, if succedeed, otherwise - false + */ + virtual bool CleanupUnpairedDevices() = 0; + + /** + * @brief Check if app can keep context. + */ + virtual bool CanAppKeepContext(const std::string& app_id) const = 0; + + /** + * @brief Check if app can steal focus. + */ + virtual bool CanAppStealFocus(const std::string& app_id) const = 0; + + /** + * @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 + */ + virtual void OnSystemReady() = 0; + + /** + * @brief GetNotificationNumber + * @param priority + * @return + */ + virtual uint32_t GetNotificationsNumber( + const std::string& priority) const = 0; + + /** + * @brief Allows to update Vehicle Identification Number in policy table. + * @param new value for the parameter. + */ + virtual void SetVINValue(const std::string& value) = 0; + + /** + * @brief Checks, if application has policy assigned w/o data consent + * @param policy_app_id Unique application id + * @return true, if policy assigned w/o data consent, otherwise -false + */ + virtual bool IsPredataPolicy(const std::string& policy_app_id) const = 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 SaveUpdateStatusRequired alows to save update status. + */ + virtual void SaveUpdateStatusRequired(bool is_update_needed) = 0; + + /** + * @brief Handler on applications search started + */ + virtual void OnAppsSearchStarted() = 0; + + /** + * @brief Handler on applications search completed + */ + virtual void OnAppsSearchCompleted(const bool trigger_ptu) = 0; + + /** + * @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. + * + * @param application_id registered application. + */ + virtual void OnAppRegisteredOnMobile(const std::string& application_id) = 0; + + /** + * @brief Gets request types for application + * @param policy_app_id Unique application id + * @return request_types Request types of application + */ + virtual const std::vector<std::string> GetAppRequestTypes( + const std::string policy_app_id) const = 0; + + /** + * @brief Get information about vehicle + */ + virtual const VehicleInfo GetVehicleInfo() const = 0; + + /** + * @brief Gets meta information + * @return meta information + */ + virtual const MetaInfo GetMetaInfo() const = 0; + + /** + * @brief RetrieveCertificate Allows to obtain certificate in order + * to start secure connection. + * + * @return The certificate in PKCS#7 format. + */ + virtual std::string RetrieveCertificate() const = 0; + + /** + * @brief HasCertificate check whether policy table has certificate + * int module_config section. + * + * @return true in case certificate exists, false otherwise + */ + virtual bool HasCertificate() const = 0; + + /** + * @brief Sets decrypted certificate in policy table + * @param certificate content of certificate + */ + virtual void SetDecryptedCertificate(const std::string& certificate) = 0; + + virtual const PolicySettings& get_settings() const = 0; + + /** + * @brief Finds the next URL that must be sent on OnSystemRequest retry + * @param urls vector of vectors that contain urls for each application + * @return Pair of policy application id and application url id from the + * urls vector + */ + virtual AppIdURL GetNextUpdateUrl(const EndpointUrls& urls) = 0; + + /** + * @brief Checks if there is existing URL in the EndpointUrls vector with + * index saved in the policy manager and if not, it moves to the next + * application index + * @param rs contains the application index and url index from the + * urls vector that are to be sent on the next OnSystemRequest + * @param urls vector of vectors that contain urls for each application + * @return Pair of application index and url index + */ + virtual AppIdURL RetrySequenceUrl(const struct RetrySequenceURL& rs, + const EndpointUrls& urls) const = 0; + + /** + * @brief Checks, if SDL needs to update it's policy table "external consent + * status" section + * @param status ExternalConsent status + * @return true if there's such a need, otherwise - false + */ + virtual bool IsNeedToUpdateExternalConsentStatus( + const ExternalConsentStatus& status) const = 0; + + /** + * @brief Saves customer connectivity settings status + * @param status ExternalConsent status + * @return true if succeeded, otherwise - false + */ + virtual bool SetExternalConsentStatus( + const ExternalConsentStatus& status) = 0; + + /** + * @brief Gets customer connectivity settings status + * @return external consent status + */ + virtual ExternalConsentStatus GetExternalConsentStatus() = 0; + + protected: + /** + * Checks is PT exceeded IgnitionCycles + * @return true if exceeded + */ + virtual bool ExceededIgnitionCycles() = 0; + + /** + * Checks is PT exceeded days + * @return true if exceeded + */ + virtual bool ExceededDays() = 0; + + /** + * @brief StartPTExchange allows to start PTU. The function will check + * if one is required and starts the update flow in only case when previous + * condition is true. + */ + virtual void StartPTExchange() = 0; +}; + +} // namespace policy + +extern "C" policy::PolicyManager* CreateManager(); +extern "C" void DeleteManager(policy::PolicyManager*); + +#endif // SRC_COMPONENTS_INCLUDE_POLICY_POLICY_MANAGER_H_ diff --git a/src/components/include/policy/policy_settings.h b/src/components/include/policy/policy_external/policy/policy_settings.h index 7e5b7d6f93..def9fca05a 100644 --- a/src/components/include/policy/policy_settings.h +++ b/src/components/include/policy/policy_external/policy/policy_settings.h @@ -1,5 +1,5 @@ -#ifndef POLICY_HANDLER_SETTINGS_H -#define POLICY_HANDLER_SETTINGS_H +#ifndef SRC_COMPONENTS_INCLUDE_POLICY_POLICY_SETTINGS_H_ +#define SRC_COMPONENTS_INCLUDE_POLICY_POLICY_SETTINGS_H_ #include <string> #include <stdint.h> @@ -39,4 +39,4 @@ class PolicySettings { virtual ~PolicySettings() {} }; } // namespace policy -#endif // POLICY_HANDLER_SETTINGS_H +#endif // SRC_COMPONENTS_INCLUDE_POLICY_POLICY_SETTINGS_H_ diff --git a/src/components/include/policy/policy_external/policy/usage_statistics/app_stopwatch.h b/src/components/include/policy/policy_external/policy/usage_statistics/app_stopwatch.h new file mode 100644 index 0000000000..45883163c4 --- /dev/null +++ b/src/components/include/policy/policy_external/policy/usage_statistics/app_stopwatch.h @@ -0,0 +1,50 @@ +/* + * 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_INCLUDE_POLICY_USAGE_STATISTICS_APP_STOPWATCH_H_ +#define SRC_COMPONENTS_INCLUDE_POLICY_USAGE_STATISTICS_APP_STOPWATCH_H_ + +#include "statistics_manager.h" + +namespace usage_statistics { + +class AppStopwatch { + public: + virtual ~AppStopwatch() {} + virtual void Start(AppStopwatchId stopwatch_type) = 0; + virtual void Switch(AppStopwatchId stopwatch_type) = 0; + virtual void WriteTime() = 0; +}; + +} // namespace usage_statistics + +#endif // SRC_COMPONENTS_INCLUDE_POLICY_USAGE_STATISTICS_APP_STOPWATCH_H_ diff --git a/src/components/include/policy/usage_statistics/statistics_manager.h b/src/components/include/policy/policy_external/policy/usage_statistics/statistics_manager.h index 4a387b8b13..8cf3beaa55 100644 --- a/src/components/include/policy/usage_statistics/statistics_manager.h +++ b/src/components/include/policy/policy_external/policy/usage_statistics/statistics_manager.h @@ -83,4 +83,4 @@ class StatisticsManager { } // namespace usage_statistics -#endif // SRC_COMPONENTS_INCLUDE_POLICY_USAGE_STATISTICS_STATISTICS_MANAGER_H_ +#endif // SRC_COMPONENTS_INCLUDE_POLICY_USAGE_STATISTICS_STATISTICS_MANAGER_H_ diff --git a/src/components/include/policy/policy_regular/policy/policy_manager.h b/src/components/include/policy/policy_regular/policy/policy_manager.h new file mode 100644 index 0000000000..c8074b3528 --- /dev/null +++ b/src/components/include/policy/policy_regular/policy/policy_manager.h @@ -0,0 +1,521 @@ +/* + 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_REGULAR_INCLUDE_POLICY_POLICY_MANAGER_H_ +#define SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_POLICY_MANAGER_H_ + +#include <vector> +#include <cstdint> + +#include "utils/callable.h" +#include "policy/policy_types.h" +#include "policy/policy_table/types.h" +#include "policy/policy_listener.h" +#include "policy/usage_statistics/statistics_manager.h" + +namespace policy { +class PolicySettings; +typedef utils::SharedPtr<utils::Callable> StatusNotifier; + +class PolicyManager : public usage_statistics::StatisticsManager { + public: + virtual ~PolicyManager() {} + + virtual void set_listener(PolicyListener* listener) = 0; + + /** + * Inits Policy Table + * @param file_name Path to preloaded PT file + * @return true if successfully + */ + virtual bool InitPT(const std::string& file_name, + const PolicySettings* settings) = 0; + + /** + * @brief Updates Policy Table from binary message received from + * mobile device. Saves to Policy Table diff between Policy Table + * sent in snapshot and received Policy Table. + * @param file name of file with update policy table + * @param pt_content PTU as binary string + * @return bool Success of operation + */ + virtual bool LoadPT(const std::string& file, + const BinaryMessage& pt_content) = 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 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 Gets all URLs for sending PTS to from PT itself. + * @param service_type Service specifies user of URL + * @return vector of 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 PTU is needed, for this PTS has to be formed and sent. + */ + virtual bool RequestPTUpdate() = 0; + + /** + * @brief Check if specified RPC for specified application + * has permission to be executed in specified HMI Level + * and also its permitted params. + * @param app_id Id of application provided during registration + * @param hmi_level Current HMI Level of application + * @param rpc Name of RPC + * @param CheckPermissionResult containing flag if HMI Level is allowed + * and list of allowed params. + */ + virtual void CheckPermissions(const PTString& device_id, + const PTString& app_id, + const PTString& hmi_level, + const PTString& rpc, + const RPCParams& rpc_params, + CheckPermissionResult& result) = 0; + + virtual void CheckPendingPermissionsChanges( + const std::string& policy_app_id, + const std::vector<FunctionalGroupPermission>& current_permissions) = 0; + + /** + * @brief Clear all record of user consents. Used during Factory Reset. + * @return bool Success of operation + */ + virtual bool ResetUserConsent() = 0; + + /** + * @brief Returns current status of policy table for HMI + * @return Current status of policy table + */ + virtual std::string GetPolicyTableStatus() const = 0; + + /** + * Checks is PT exceeded kilometers + * @param kilometers current kilometers at odometer + * @return true if exceeded + */ + virtual void KmsChanged(int kilometers) = 0; + + /** + * Increments counter of ignition cycles + */ + virtual void IncrementIgnitionCycles() = 0; + + /** + * @brief Exchange by hmi or mobile request + */ + virtual std::string ForcePTExchange() = 0; + + /** + * @brief ExchangeByUserRequest + */ + virtual std::string ForcePTExchangeAtUserRequest() = 0; + + /** + * Gets timeout to wait before next retry updating PT + * If timeout is equal to zero then the retry sequence is not need. + * @return timeout in seconds + */ + virtual uint32_t NextRetryTimeout() = 0; + + /** + * Gets timeout to wait until receive response + * @return timeout in seconds + */ + virtual uint32_t TimeoutExchangeMSec() = 0; + + /** + * @brief List of timeouts in seconds between retries + * when attempt to update PT fails + * @return List of delays between attempts. + */ + virtual const std::vector<int> RetrySequenceDelaysSeconds() = 0; + + /** + * Handler of exceeding timeout of exchanging policy table + */ + virtual void OnExceededTimeout() = 0; + + /** + * @brief Handler of PTS sending out + */ + virtual void OnUpdateStarted() = 0; + + /** + * @brief Check user consent for mobile device data connection + * @param device_id Unique device identifier + * @return status of device consent + */ + virtual DeviceConsent GetUserConsentForDevice( + const std::string& device_id) const = 0; + + /** + * @brief Get user consent for application + * @param device_id Device id + * @param policy_app_id Unique application id + * @param permissions Array of functional groups permissions + */ + virtual void GetUserConsentForApp( + const std::string& device_id, + const std::string& policy_app_id, + std::vector<FunctionalGroupPermission>& permissions) = 0; + + /** + * @brief Set user consent for mobile device data connection + * @param device_id Unique device identifier + * @param is_allowed User consent for usage device data connection + */ + virtual void SetUserConsentForDevice(const std::string& device_id, + bool is_allowed) = 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; + /** + * Sets counter value that passed for receiving PT UPdate. + */ + virtual void PTUpdatedAt(Counters counter, int value) = 0; + + /** + * @brief Retrieves data from app_policies about app on its registration: + * @param app_id - id of registered app + * @param app_types Section on HMI where app can appear (Navigation, Phone + * etc) + * @param nicknames Synonyms for application + */ + virtual bool GetInitialAppData(const std::string& application_id, + StringArray* nicknames = NULL, + StringArray* app_hmi_types = NULL) = 0; + + /** + * @brief Add's device to policy table + * @param device_id Device mac address + * @param connection_type Device connection type + */ + virtual void AddDevice(const std::string& device_id, + const std::string& connection_type) = 0; + + /** + * @brief Stores device parameters received during application registration + * to policy table + * @param device_id Device mac address + * @param device_info Received device parameters + */ + virtual void SetDeviceInfo(const std::string& device_id, + const DeviceInfo& device_info) = 0; + + /** + * @brief Set user consent for application functional groups + * @param permissions User-defined application group pemissions. + * The permissions is not const reference because it may contains + * valid data as well as invalid. So we will remove all invalid data + * from this structure. + */ + virtual void SetUserConsentForApp(const PermissionConsent& permissions) = 0; + + /** + * @brief Get default HMI level for 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) const = 0; + + /** + * @brief Get priority for 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 Get user friendly messages for given RPC messages and language + * @param message_codes RPC message codes + * @param language Language + * @return Array of structs with appropriate message parameters + */ + virtual std::vector<UserFriendlyMessage> GetUserFriendlyMessages( + const std::vector<std::string>& message_code, + const std::string& language) = 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 resulting RPCs permissions for application which started on + * specific device + * @param device_id Device id + * @param policy_app_id Unique application id + * @param permissions Array of functional groups permissions + */ + virtual void GetPermissionsForApp( + const std::string& device_id, + const std::string& policy_app_id, + std::vector<FunctionalGroupPermission>& permissions) = 0; + + /** + * @brief Gets specific application permissions changes since last policy + * table update + * @param policy_app_id Unique application id + * @return Permissions changes + */ + virtual AppPermissions GetAppPermissionsChanges( + const std::string& policy_app_id) = 0; + + virtual void RemovePendingPermissionChanges(const std::string& app_id) = 0; + + /** + * @brief Return device id, which hosts specific application + * @param Application id, which is required to update device id + */ + virtual std::string& GetCurrentDeviceId( + const std::string& policy_app_id) const = 0; + + /** + * @brief Set current system language + * @param language Language + */ + virtual void SetSystemLanguage(const std::string& language) = 0; + + /** + * @brief Set data from GetSystemInfo response to policy table + * @param ccpu_version CCPU version + * @param wers_country_code WERS country code + * @param language System language + */ + virtual void SetSystemInfo(const std::string& ccpu_version, + const std::string& wers_country_code, + const std::string& language) = 0; + + /** + * @brief Send OnPermissionsUpdated for choosen application + * @param application_id + */ + virtual void SendNotificationOnPermissionsUpdated( + const std::string& application_id) = 0; + + /** + * Marks device as upaired + * @param device_id id device + */ + virtual void MarkUnpairedDevice(const std::string& device_id) = 0; + + /** + * @brief Adds, application to the db or update existed one + * run PTU if policy update is necessary for application. + * @param Application id assigned by Ford to the application + * @return function that will notify update manager about new application + */ + virtual StatusNotifier AddApplication( + const std::string& application_id, + const rpc::policy_table_interface_base::AppHmiTypes& hmi_types) = 0; + /** + * @brief Removes unpaired device records and related records from DB + * @param device_ids List of device_id, which should be removed + * @return true, if succedeed, otherwise - false + */ + virtual bool CleanupUnpairedDevices() = 0; + + /** + * @brief Check if app can keep context. + */ + virtual bool CanAppKeepContext(const std::string& app_id) const = 0; + + /** + * @brief Check if app can steal focus. + */ + virtual bool CanAppStealFocus(const std::string& app_id) const = 0; + + /** + * @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 + */ + virtual void OnSystemReady() = 0; + + /** + * @brief GetNotificationNumber + * @param priority + * @return + */ + virtual uint32_t GetNotificationsNumber( + const std::string& priority) const = 0; + + /** + * @brief Allows to update Vehicle Identification Number in policy table. + * @param new value for the parameter. + */ + virtual void SetVINValue(const std::string& value) = 0; + + /** + * @brief Checks, if application has policy assigned w/o data consent + * @param policy_app_id Unique application id + * @return true, if policy assigned w/o data consent, otherwise -false + */ + virtual bool IsPredataPolicy(const std::string& policy_app_id) const = 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 SaveUpdateStatusRequired alows to save update status. + */ + virtual void SaveUpdateStatusRequired(bool is_update_needed) = 0; + + /** + * @brief Handler on applications search started + */ + virtual void OnAppsSearchStarted() = 0; + + /** + * @brief Handler on applications search completed + */ + virtual void OnAppsSearchCompleted(const bool trigger_ptu) = 0; + /** + * @brief Gets request types for application + * @param policy_app_id Unique application id + * @return request_types Request types of application + */ + virtual const std::vector<std::string> GetAppRequestTypes( + const std::string policy_app_id) const = 0; + + /** + * @brief Get information about vehicle + */ + virtual const VehicleInfo GetVehicleInfo() const = 0; + + /** + * @brief OnAppRegisteredOnMobile alows to handle event when application were + * succesfully registered on mobile device. + * It will send OnAppPermissionSend notification and will try to start PTU. + * + * @param application_id registered application. + */ + virtual void OnAppRegisteredOnMobile(const std::string& application_id) = 0; + + /** + * @brief RetrieveCertificate Allows to obtain certificate in order + * to start secure connection. + * + * @return The certificate in PKCS#7 format. + */ + virtual std::string RetrieveCertificate() const = 0; + + /** + * @brief HasCertificate check whether policy table has certificate + * int module_config section. + * + * @return true in case certificate exists, false otherwise + */ + virtual bool HasCertificate() const = 0; + + virtual const PolicySettings& get_settings() const = 0; + + /** + * @brief Finds the next URL that must be sent on OnSystemRequest retry + * @param urls vector of vectors that contain urls for each application + * @return Pair of policy application id and application url id from the + * urls vector + */ + virtual AppIdURL GetNextUpdateUrl(const EndpointUrls& urls) = 0; + + /** + * @brief Checks if there is existing URL in the EndpointUrls vector with + * index saved in the policy manager and if not, it moves to the next + * application index + * @param rs contains the application index and url index from the + * urls vector that are to be sent on the next OnSystemRequest + * @param urls vector of vectors that contain urls for each application + * @return Pair of application index and url index + */ + virtual AppIdURL RetrySequenceUrl(const struct RetrySequenceURL& rs, + const EndpointUrls& urls) const = 0; + + protected: + /** + * Checks is PT exceeded IgnitionCycles + * @return true if exceeded + */ + virtual bool ExceededIgnitionCycles() = 0; + + /** + * Checks is PT exceeded days + * @return true if exceeded + */ + virtual bool ExceededDays() = 0; + + /** + * @brief StartPTExchange allows to start PTU. The function will check + * if one is required and starts the update flow in only case when previous + * condition is true. + */ + virtual void StartPTExchange() = 0; +}; + +} // namespace policy + +extern "C" policy::PolicyManager* CreateManager(); +extern "C" void DeleteManager(policy::PolicyManager*); + +#endif // SRC_COMPONENTS_POLICY_POLICY_REGULAR_INCLUDE_POLICY_POLICY_MANAGER_H_ diff --git a/src/components/include/policy/policy_regular/policy/policy_settings.h b/src/components/include/policy/policy_regular/policy/policy_settings.h new file mode 100644 index 0000000000..def9fca05a --- /dev/null +++ b/src/components/include/policy/policy_regular/policy/policy_settings.h @@ -0,0 +1,42 @@ +#ifndef SRC_COMPONENTS_INCLUDE_POLICY_POLICY_SETTINGS_H_ +#define SRC_COMPONENTS_INCLUDE_POLICY_POLICY_SETTINGS_H_ +#include <string> +#include <stdint.h> + +namespace policy { +class PolicySettings { + public: + /** + * @brief Should Policy be turned off? (Library not loaded) + * @return Flag + */ + virtual bool enable_policy() const = 0; + /* + * @brief Path to preloaded policy file + */ + virtual const std::string& preloaded_pt_file() const = 0; + + /** + * @brief Returns application storage path + */ + virtual const std::string& app_storage_folder() const = 0; + + virtual uint16_t attempts_to_open_policy_db() const = 0; + + virtual uint16_t open_attempt_timeout_ms() const = 0; + + /** + * @brief Path to policies snapshot file + * @return file path + */ + virtual const std::string& policies_snapshot_file_name() const = 0; + + /** + * @brief Returns system files folder path + */ + virtual const std::string& system_files_path() const = 0; + + virtual ~PolicySettings() {} +}; +} // namespace policy +#endif // SRC_COMPONENTS_INCLUDE_POLICY_POLICY_SETTINGS_H_ diff --git a/src/components/include/policy/policy_regular/policy/usage_statistics/statistics_manager.h b/src/components/include/policy/policy_regular/policy/usage_statistics/statistics_manager.h new file mode 100644 index 0000000000..8cf3beaa55 --- /dev/null +++ b/src/components/include/policy/policy_regular/policy/usage_statistics/statistics_manager.h @@ -0,0 +1,86 @@ +/* + * 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_INCLUDE_POLICY_USAGE_STATISTICS_STATISTICS_MANAGER_H_ +#define SRC_COMPONENTS_INCLUDE_POLICY_USAGE_STATISTICS_STATISTICS_MANAGER_H_ + +#include <stdint.h> +#include <string> + +namespace usage_statistics { + +enum GlobalCounterId { + GLOBAL_COUNTER_NONE, + IAP_BUFFER_FULL, + SYNC_OUT_OF_MEMORY, + SYNC_REBOOTS +}; + +enum AppInfoId { APP_INFO_NONE, LANGUAGE_GUI, LANGUAGE_VUI }; + +enum AppStopwatchId { + STOPWATCH_NONE, + SECONDS_HMI_FULL, + SECONDS_HMI_LIMITED, + SECONDS_HMI_BACKGROUND, + SECONDS_HMI_NONE +}; + +enum AppCounterId { + APP_COUNTER_NONE, + USER_SELECTIONS, + REJECTIONS_SYNC_OUT_OF_MEMORY, + REJECTIONS_NICKNAME_MISMATCH, + REJECTIONS_DUPLICATE_NAME, + REJECTED_RPC_CALLS, + RPCS_IN_HMI_NONE, + REMOVALS_MISBEHAVED, + RUN_ATTEMPTS_WHILE_REVOKED, + COUNT_OF_TLS_ERRORS, +}; + +class StatisticsManager { + public: + virtual ~StatisticsManager() {} + virtual void Increment(GlobalCounterId type) = 0; + virtual void Increment(const std::string& app_id, AppCounterId type) = 0; + virtual void Set(const std::string& app_id, + AppInfoId type, + const std::string& value) = 0; + virtual void Add(const std::string& app_id, + AppStopwatchId type, + int32_t timespan_seconds) = 0; +}; + +} // namespace usage_statistics + +#endif // SRC_COMPONENTS_INCLUDE_POLICY_USAGE_STATISTICS_STATISTICS_MANAGER_H_ diff --git a/src/components/include/policy/policy_types.h b/src/components/include/policy/policy_types.h deleted file mode 100644 index f03278619c..0000000000 --- a/src/components/include/policy/policy_types.h +++ /dev/null @@ -1,318 +0,0 @@ -/* - Copyright (c) 2013, Ford Motor Company - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following - disclaimer in the documentation and/or other materials provided with the - distribution. - - Neither the name of the Ford Motor Company nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SRC_COMPONENTS_POLICY_INCLUDE_POLICY_POLICY_TYPES_H_ -#define SRC_COMPONENTS_POLICY_INCLUDE_POLICY_POLICY_TYPES_H_ - -#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 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::vector<std::string> RPCParams; - -typedef std::map<std::string, std::set<policy::HMILevel> > HMIPermissions; -typedef std::map<std::string, std::set<policy::Parameter> > - ParameterPermissions; - -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; - std::vector<PTString> list_of_allowed_params; - std::vector<PTString> list_of_disallowed_params; - std::vector<PTString> list_of_undefined_params; -}; - -/** - @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; -}; - -/** - * @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_INCLUDE_POLICY_POLICY_TYPES_H_ |