diff options
Diffstat (limited to 'src/components/application_manager/include/application_manager/policies/policy_handler.h')
-rw-r--r-- | src/components/application_manager/include/application_manager/policies/policy_handler.h | 246 |
1 files changed, 186 insertions, 60 deletions
diff --git a/src/components/application_manager/include/application_manager/policies/policy_handler.h b/src/components/application_manager/include/application_manager/policies/policy_handler.h index 6f36408444..e2c4d73f5c 100644 --- a/src/components/application_manager/include/application_manager/policies/policy_handler.h +++ b/src/components/application_manager/include/application_manager/policies/policy_handler.h @@ -30,8 +30,8 @@ POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_POLICY_HANDLER_H_ -#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_POLICY_HANDLER_H_ +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_POLICIES_POLICY_HANDLER_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_POLICIES_POLICY_HANDLER_H_ #include <string> #include <map> @@ -41,6 +41,7 @@ #include <stdint.h> #include "policy/policy_manager.h" +#include "application_manager/application.h" #include "application_manager/policies/policy_handler_interface.h" #include "application_manager/policies/policy_event_observer.h" #include "application_manager/policies/delegates/statistics_delegate.h" @@ -64,6 +65,7 @@ class ApplicationManager; } namespace policy { + typedef std::vector<uint32_t> AppIds; typedef std::vector<uint32_t> DeviceHandles; namespace custom_str = utils::custom_string; @@ -92,15 +94,20 @@ class PolicyHandler : public PolicyHandlerInterface, virtual void OnPermissionsUpdated(const std::string& policy_app_id, const Permissions& permissions) OVERRIDE; - virtual void OnSnapshotCreated(const BinaryMessage& pt_string) OVERRIDE; - +#ifdef EXTERNAL_PROPRIETARY_MODE + void OnSnapshotCreated(const BinaryMessage& pt_string, + const std::vector<int>& retry_delay_seconds, + uint32_t timeout_exchange) OVERRIDE; +#else // EXTERNAL_PROPRIETARY_MODE + void OnSnapshotCreated(const BinaryMessage& pt_string) OVERRIDE; +#endif // EXTERNAL_PROPRIETARY_MODE virtual bool GetPriority(const std::string& policy_app_id, std::string* priority) const OVERRIDE; - void CheckPermissions(const PTString& app_id, - const PTString& hmi_level, - const PTString& rpc, - const RPCParams& rpc_params, - CheckPermissionResult& result) OVERRIDE; + virtual void CheckPermissions( + const application_manager::ApplicationSharedPtr app, + const PTString& rpc, + const RPCParams& rpc_params, + CheckPermissionResult& result) OVERRIDE; uint32_t GetNotificationsNumber(const std::string& priority) const OVERRIDE; virtual DeviceConsent GetUserConsentForDevice( @@ -110,12 +117,14 @@ class PolicyHandler : public PolicyHandlerInterface, bool GetInitialAppData(const std::string& application_id, StringArray* nicknames = NULL, StringArray* app_hmi_types = NULL) OVERRIDE; - void GetServiceUrls(const std::string& service_type, - EndpointUrls& end_points) OVERRIDE; + void GetUpdateUrls(const std::string& service_type, + EndpointUrls& out_end_points) OVERRIDE; + void GetUpdateUrls(const uint32_t service_type, + EndpointUrls& out_end_points) OVERRIDE; virtual std::string GetLockScreenIconUrl() const OVERRIDE; - void ResetRetrySequence() OVERRIDE; uint32_t NextRetryTimeout() OVERRIDE; - int TimeoutExchange() OVERRIDE; + uint32_t TimeoutExchangeSec() OVERRIDE; + uint32_t TimeoutExchangeMSec() OVERRIDE; void OnExceededTimeout() OVERRIDE; void OnSystemReady() OVERRIDE; void PTUpdatedAt(Counters counter, int value) OVERRIDE; @@ -150,11 +159,11 @@ class PolicyHandler : public PolicyHandlerInterface, /** * @brief Process user consent on mobile data connection access - * @param Device id or empty string, if concern to all SDL functionality - * @param User consent from response + * @param is_allowed - user consent from response + * @param device_mac - mac adress of device */ void OnAllowSDLFunctionalityNotification( - bool is_allowed, const std::string& device_id) OVERRIDE; + bool is_allowed, const std::string& device_mac) OVERRIDE; /** * @brief Increment counter for ignition cycles @@ -185,14 +194,32 @@ class PolicyHandler : public PolicyHandlerInterface, void SetDeviceInfo(const std::string& device_id, const DeviceInfo& device_info) OVERRIDE; - /** - * @brief Store user-changed permissions consent to DB - * @param connection_key Connection key of application or 0, if permissions - * should be applied to all applications - * @param permissions User-changed group permissions consent - */ +/** + * @brief Store user-changed permissions consent to DB + * @param connection_key Connection key of application or 0, if permissions + * should be applied to all applications + * @param permissions User-changed group permissions consent + */ + +/** + * @brief Processes permissions changes received from system via + * OnAppPermissionConsent notification + * @param connection_key Connection key of application, 0 if no key has been + * provided by notification + * @param permissions Structure containing group permissions changes + * @param external_consent_status Structure containig customer connectivity + * settings + * changes + */ +#ifdef EXTERNAL_PROPRIETARY_MODE + void OnAppPermissionConsent( + const uint32_t connection_key, + const PermissionConsent& permissions, + const ExternalConsentStatus& external_consent_status) OVERRIDE; +#else void OnAppPermissionConsent(const uint32_t connection_key, const PermissionConsent& permissions) OVERRIDE; +#endif /** * @brief Get appropriate message parameters and send them with response @@ -287,8 +314,9 @@ class PolicyHandler : public PolicyHandlerInterface, void OnSystemError(int code) OVERRIDE; /** - * @brief Choose application id to be used for snapshot sending - * @return Application id or 0, if there are no applications registered + * @brief Chooses random application id to be used for snapshot sending + * considering HMI level + * @return Application id or 0, if there are no suitable applications */ uint32_t GetAppIdForSending() const OVERRIDE; @@ -300,7 +328,9 @@ class PolicyHandler : public PolicyHandlerInterface, virtual void OnCertificateUpdated( const std::string& certificate_data) OVERRIDE; - +#ifdef EXTERNAL_PROPRIETARY_MODE + void OnCertificateDecrypted(bool is_succeeded) OVERRIDE; +#endif // EXTERNAL_PROPRIETARY_MODE virtual bool CanUpdate() OVERRIDE; virtual void OnDeviceConsentChanged(const std::string& device_id, @@ -318,8 +348,11 @@ class PolicyHandler : public PolicyHandlerInterface, * @brief Allows to add new or update existed application during * registration process * @param application_id The policy aplication id. + ** @return function that will notify update manager about new application */ - void AddApplication(const std::string& application_id) OVERRIDE; + StatusNotifier AddApplication( + const std::string& application_id, + const rpc::policy_table_interface_base::AppHmiTypes& hmi_types) OVERRIDE; /** * Checks whether application is revoked @@ -354,7 +387,16 @@ class PolicyHandler : public PolicyHandlerInterface, /** * @brief Handler on applications search completed */ - void OnAppsSearchCompleted() OVERRIDE; + void OnAppsSearchCompleted(const bool trigger_ptu) OVERRIDE; + + /** + * @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. + */ + void OnAppRegisteredOnMobile(const std::string& application_id) OVERRIDE; /** * @brief Checks if certain request type is allowed for application @@ -380,30 +422,33 @@ class PolicyHandler : public PolicyHandlerInterface, */ const VehicleInfo GetVehicleInfo() const OVERRIDE; +#ifdef EXTERNAL_PROPRIETARY_MODE /** - * @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. + * @brief Gets meta information + * @return meta information */ - void OnAppRegisteredOnMobile(const std::string& application_id) OVERRIDE; + const policy::MetaInfo GetMetaInfo() const OVERRIDE; +#endif // EXTERNAL_PROPRIETARY_MODE // TODO(AKutsan) REMOVE THIS UGLY HOTFIX - virtual void Increment(usage_statistics::GlobalCounterId type) OVERRIDE; - virtual void Increment(const std::string& app_id, - usage_statistics::AppCounterId type) OVERRIDE; - virtual void Set(const std::string& app_id, - usage_statistics::AppInfoId type, - const std::string& value) OVERRIDE; - virtual void Add(const std::string& app_id, - usage_statistics::AppStopwatchId type, - int32_t timespan_seconds) OVERRIDE; + void Increment(usage_statistics::GlobalCounterId type) OVERRIDE; + void Increment(const std::string& app_id, + usage_statistics::AppCounterId type) OVERRIDE; + void Set(const std::string& app_id, + usage_statistics::AppInfoId type, + const std::string& value) OVERRIDE; + void Add(const std::string& app_id, + usage_statistics::AppStopwatchId type, + int32_t timespan_seconds) OVERRIDE; #ifdef BUILD_TESTS void SetPolicyManager(utils::SharedPtr<PolicyManager> pm) { policy_manager_ = pm; } + + AppIds& last_used_app_ids() { + return last_used_app_ids_; + } #endif // BUILD_TESTS #ifdef ENABLE_SECURITY @@ -412,6 +457,8 @@ class PolicyHandler : public PolicyHandlerInterface, const PolicySettings& get_settings() const OVERRIDE; + virtual void OnPTUFinished(const bool ptu_result) OVERRIDE; + protected: /** * Starts next retry exchange policy table @@ -439,21 +486,58 @@ class PolicyHandler : public PolicyHandlerInterface, */ bool CheckStealFocus(const std::string& policy_app_id) const; - /** - * @brief OnAppPermissionConsentInternal reacts on permission changing - * - * @param connection_key connection key - * - * @param permissions new permissions. - */ - void OnAppPermissionConsentInternal(const uint32_t connection_key, - PermissionConsent& permissions) OVERRIDE; +/** + * @brief Processes data received via OnAppPermissionChanged notification + * from. Being started asyncronously from AppPermissionDelegate class. + * Sets updated permissions and ExternalConsent for registered applications + * and + * applications which already have appropriate group assigned which related to + * devices already known by policy + * @param connection_key Connection key of application, 0 if no key has been + * provided within notification + * @param external_consent_status Customer connectivity settings changes to + * process + * @param permissions Permissions changes to process + */ +#ifdef EXTERNAL_PROPRIETARY_MODE + void OnAppPermissionConsentInternal( + const uint32_t connection_key, + const ExternalConsentStatus& external_consent_status, + PermissionConsent& out_permissions) OVERRIDE; +#else + void OnAppPermissionConsentInternal( + const uint32_t connection_key, + PermissionConsent& out_permissions) OVERRIDE; +#endif /** * @brief Sets days after epoch on successful policy update */ void SetDaysAfterEpoch(); + /** + * @brief Link all currently registered applications + */ + void LinkAppsToDevice(); + + typedef std::vector<application_manager::ApplicationSharedPtr> Applications; + + /** + * @brief Checks application registration status (SDL4.0) and device consent + * to find out whether application is suitable + * @param value Item from applications collection + * @return true if application is suitable, otherwise - false + */ + bool IsAppSuitableForPolicyUpdate(const Applications::value_type value) const; + + /** + * @brief Chooses random application from list using + * IsAppSuitableForPolicyUpdate + * @param app_list Application collection + * @return Application id if suitable is found, otherwise - zero + */ + uint32_t ChooseRandomAppForPolicyUpdate(Applications& app_list) const; + private: class StatisticManagerImpl : public usage_statistics::StatisticsManager { public: @@ -462,26 +546,26 @@ class PolicyHandler : public PolicyHandlerInterface, DCHECK(policy_handler_); } // TODO(AKutsan) REMOVE THIS UGLY HOTFIX - virtual void Increment(usage_statistics::GlobalCounterId type) { + void Increment(usage_statistics::GlobalCounterId type) OVERRIDE { policy_handler_->AsyncRun(new StatisticsDelegate(*policy_handler_, type)); } void Increment(const std::string& app_id, - usage_statistics::AppCounterId type) { + usage_statistics::AppCounterId type) OVERRIDE { policy_handler_->AsyncRun( new StatisticsDelegate(*policy_handler_, app_id, type)); } void Set(const std::string& app_id, usage_statistics::AppInfoId type, - const std::string& value) { + const std::string& value) OVERRIDE { policy_handler_->AsyncRun( new StatisticsDelegate(*policy_handler_, app_id, type, value)); } void Add(const std::string& app_id, usage_statistics::AppStopwatchId type, - int32_t timespan_seconds) { + int32_t timespan_seconds) OVERRIDE { policy_handler_->AsyncRun(new StatisticsDelegate( *policy_handler_, app_id, type, timespan_seconds)); } @@ -489,9 +573,39 @@ class PolicyHandler : public PolicyHandlerInterface, private: PolicyHandler* policy_handler_; }; - +#ifdef EXTERNAL_PROPRIETARY_MODE + void OnEmptyCertificateArrived() const; +#endif // EXTERNAL_PROPRIETARY_MODE bool SaveSnapshot(const BinaryMessage& pt_string, std::string& snap_path); + + /** + * @brief Collects permissions for all currently registered applications on + * all devices + * @return consolidated permissions list or empty list if no + * applications/devices currently present + */ + std::vector<FunctionalGroupPermission> CollectRegisteredAppsPermissions(); + + /** + * @brief Collects permissions for application with certain connection key + * @param connection_key Connection key of application to look for + * @return list of application permissions or empty list if no such + * application found + */ + std::vector<FunctionalGroupPermission> CollectAppPermissions( + const uint32_t connection_key); + + private: static const std::string kLibrary; + + /** + * @brief Collects currently registered applications ids linked to their + * device id + * @param out_links Collection of device_id-to-app_id links + */ + void GetRegisteredLinks(std::map<std::string, std::string>& out_links) const; + + private: mutable sync_primitives::RWLock policy_manager_lock_; utils::SharedPtr<PolicyManager> policy_manager_; void* dl_handle_; @@ -508,11 +622,12 @@ class PolicyHandler : public PolicyHandlerInterface, typedef std::list<PolicyHandlerObserver*> HandlersCollection; HandlersCollection listeners_; - sync_primitives::Lock listeners_lock_; + mutable sync_primitives::Lock listeners_lock_; /** - * @brief Application-to-device map is used for getting/setting user consents - * for all apps + * @brief Application-to-device links are used for collecting their current + * consents to provide for HMI request and process response with possible + * changes done by user */ std::map<std::string, std::string> app_to_device_link_; @@ -524,9 +639,20 @@ class PolicyHandler : public PolicyHandlerInterface, application_manager::ApplicationManager& application_manager_; friend class AppPermissionDelegate; + /** + * @brief Checks if the application with the given policy + * application id is registered or it is default id + * @param app_idx Application idx from EndpointUrls vector + * @param urls EndpointUrls vector + * @return TRUE if the vector with URLs with given idx is not empty + * and is related to a registered application or these are default URLs, + * otherwise FALSE + */ + bool IsUrlAppIdValid(const uint32_t app_idx, const EndpointUrls& urls) const; + DISALLOW_COPY_AND_ASSIGN(PolicyHandler); }; } // namespace policy -#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_POLICY_HANDLER_H_ +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_POLICIES_POLICY_HANDLER_H_ |