2 Copyright (c) 2013, Ford Motor Company
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
11 Redistributions in binary form must reproduce the above copyright notice,
12 this list of conditions and the following
13 disclaimer in the documentation and/or other materials provided with the
16 Neither the name of the Ford Motor Company nor the names of its contributors
17 may be used to endorse or promote products derived from this software
18 without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
33 #ifndef SRC_COMPONENTS_POLICY_INCLUDE_POLICY_POLICY_MANAGER_H_
34 #define SRC_COMPONENTS_POLICY_INCLUDE_POLICY_POLICY_MANAGER_H_
38 #include "policy/policy_types.h"
39 #include "policy/policy_listener.h"
40 #include "usage_statistics/statistics_manager.h"
44 class PolicyManager : public usage_statistics::StatisticsManager {
46 virtual ~PolicyManager() {
49 virtual void set_listener(PolicyListener* listener) = 0;
53 * @param file_name Path to preloaded PT file
54 * @return true if successfully
56 virtual bool InitPT(const std::string& file_name) = 0;
59 * @brief Updates Policy Table from binary message received from
60 * mobile device. Saves to Policy Table diff between Policy Table
61 * sent in snapshot and received Policy Table.
62 * @param file name of file with update policy table
63 * @param pt_content PTU as binary string
64 * @return bool Success of operation
66 virtual bool LoadPT(const std::string& file, const BinaryMessage& pt_content) = 0;
70 * @param file_name Path to preloaded PT file
71 * @return true if successfully
73 virtual bool ResetPT(const std::string& file_name) = 0;
76 * @brief Gets URL for sending PTS to from PT itself.
77 * @param service_type Service specifies user of URL
80 virtual std::string GetUpdateUrl(int service_type) = 0;
83 * @brief Gets all URLs for sending PTS to from PT itself.
84 * @param service_type Service specifies user of URL
85 * @return vector of urls
87 virtual EndpointUrls GetUpdateUrls(int service_type) = 0;
90 * @brief PTU is needed, for this PTS has to be formed and sent.
91 * @return BinaryMessage* PTS.
93 virtual BinaryMessageSptr RequestPTUpdate() = 0;
96 * @brief Check if specified RPC for specified application
97 * has permission to be executed in specified HMI Level
98 * and also its permitted params.
99 * @param app_id Id of application provided during registration
100 * @param hmi_level Current HMI Level of application
101 * @param rpc Name of RPC
102 * @return CheckPermissionResult containing flag if HMI Level is allowed
103 * and list of allowed params.
105 virtual CheckPermissionResult CheckPermissions(const PTString& app_id,
106 const PTString& hmi_level,
107 const PTString& rpc) = 0;
110 * @brief Clear all record of user consents. Used during Factory Reset.
111 * @return bool Success of operation
113 virtual bool ResetUserConsent() = 0;
116 * @brief Checks, if policy update is necessary for application
117 * @param Application id assigned by Ford to the application
119 virtual void CheckAppPolicyState(const std::string& application_id) = 0;
122 * @brief Returns current status of policy table for HMI
123 * @return Current status of policy table
125 virtual PolicyTableStatus GetPolicyTableStatus() = 0;
128 * Checks is PT exceeded IgnitionCycles
129 * @return true if exceeded
131 virtual bool ExceededIgnitionCycles() = 0;
134 * Checks is PT exceeded days
135 * @param days current day after epoch
136 * @return true if exceeded
138 virtual bool ExceededDays(int days) = 0;
141 * Checks is PT exceeded kilometers
142 * @param kilometers current kilometers at odometer
143 * @return true if exceeded
145 virtual bool ExceededKilometers(int kilometers) = 0;
148 * Increments counter of ignition cycles
150 virtual void IncrementIgnitionCycles() = 0;
153 * Resets retry sequence
155 virtual void ResetRetrySequence() = 0;
158 * Gets timeout to wait before next retry updating PT
159 * If timeout is less or equal to zero then the retry sequence is not need.
160 * @return timeout in seconds
162 virtual int NextRetryTimeout() = 0;
165 * Gets timeout to wait until receive response
166 * @return timeout in seconds
168 virtual int TimeoutExchange() = 0;
171 * @brief List of timeouts in seconds between retries
172 * when attempt to update PT fails
173 * @return List of delays between attempts.
175 virtual const std::vector<int> RetrySequenceDelaysSeconds() = 0;
178 * Handler of exceeding timeout of exchanging policy table
180 virtual void OnExceededTimeout() = 0;
183 * @brief Check user consent for mobile device data connection
184 * @param device_id Unique device identifier
185 * @return status of device consent
187 virtual DeviceConsent GetUserConsentForDevice(
188 const std::string& device_id) = 0;
191 * @brief Get user consent for application
192 * @param device_id Device id
193 * @param policy_app_id Unique application id
194 * @param permissions Array of functional groups permissions
196 virtual void GetUserConsentForApp(
197 const std::string& device_id, const std::string& policy_app_id,
198 std::vector<FunctionalGroupPermission>& permissions) = 0;
201 * @brief Set user consent for mobile device data connection
202 * @param device_id Unique device identifier
203 * @param is_allowed User consent for usage device data connection
205 virtual void SetUserConsentForDevice(const std::string& device_id,
206 bool is_allowed) = 0;
209 * @brief Update Application Policies as reaction
210 * on User allowing/disallowing device this app is running on.
212 virtual bool ReactOnUserDevConsentForApp(const std::string app_id,
213 bool is_device_allowed) = 0;
215 * Sets number of kilometers and days after epoch, that passed for
216 * receiving PT UPdate.
218 virtual void PTUpdatedAt(int kilometers, int days_after_epoch) = 0;
221 * @brief Retrieves data from app_policies about app on its registration:
222 * @param app_id - id of registered app
223 * @param app_types Section on HMI where app can appear (Navigation, Phone etc)
224 * @param nicknames Synonyms for application
226 virtual bool GetInitialAppData(const std::string& application_id,
227 StringArray* nicknames = NULL,
228 StringArray* app_hmi_types = NULL) = 0;
230 * @brief Stores device parameters received during application registration
232 * @param device_id Device mac address
233 * @param device_info Received device parameters
235 virtual void SetDeviceInfo(const std::string& device_id,
236 const DeviceInfo& device_info) = 0;
239 * @brief Set user consent for application functional groups
240 * @param permissions User-defined application group pemissions
242 virtual void SetUserConsentForApp(const PermissionConsent& permissions) = 0;
245 * @brief Get default HMI level for application
246 * @param policy_app_id Unique application id
247 * @param default_hmi Default HMI level for application or empty, if value
249 * @return true, if succedeed, otherwise - false
251 virtual bool GetDefaultHmi(const std::string& policy_app_id,
252 std::string* default_hmi) = 0;
255 * @brief Get priority for application
256 * @param policy_app_id Unique application id
257 * @param priority Priority for application or empty, if value was not set
258 * @return true, if succedeed, otherwise - false
260 virtual bool GetPriority(const std::string& policy_app_id,
261 std::string* priority) = 0;
264 * @brief Get user friendly messages for given RPC messages and language
265 * @param message_codes RPC message codes
266 * @param language Language
267 * @return Array of structs with appropriate message parameters
269 virtual std::vector<UserFriendlyMessage> GetUserFriendlyMessages(
270 const std::vector<std::string>& message_code,
271 const std::string& language) = 0;
274 * Checks if the application is revoked
275 * @param app_id application id
276 * @return true if application is revoked
278 virtual bool IsApplicationRevoked(const std::string& app_id) const = 0;
281 * @brief Get user permissions for application which started on specific device
282 * @param device_id Device id
283 * @param policy_app_id Unique application id
284 * @param permissions Array of functional groups permissions
286 virtual void GetUserPermissionsForApp(
287 const std::string& device_id, const std::string& policy_app_id,
288 std::vector<FunctionalGroupPermission>& permissions) = 0;
289 virtual AppPermissions GetAppPermissionsChanges(
290 const std::string& app_id) = 0;
291 virtual void RemovePendingPermissionChanges(const std::string& app_id) = 0;
294 * @brief Return device id, which hosts specific application
295 * @param Application id, which is required to update device id
297 virtual std::string& GetCurrentDeviceId(const std::string& policy_app_id) = 0;
300 * @brief Set current system language
301 * @param language Language
303 virtual void SetSystemLanguage(const std::string& language) = 0;
306 * @brief Set data from GetSystemInfo response to policy table
307 * @param ccpu_version CCPU version
308 * @param wers_country_code WERS country code
309 * @param language System language
311 virtual void SetSystemInfo(const std::string& ccpu_version,
312 const std::string& wers_country_code,
313 const std::string& language) = 0;
316 * @brief Send OnPermissionsUpdated for choosen application
317 * @param application_id
319 virtual void SendNotificationOnPermissionsUpdated(
320 const std::string& application_id) = 0;
323 * Marks device as upaired
324 * @param device_id id device
326 virtual void MarkUnpairedDevice(const std::string& device_id) = 0;
329 * @brief Removes unpaired device records and related records from DB
330 * @param device_ids List of device_id, which should be removed
331 * @return true, if succedeed, otherwise - false
333 virtual bool CleanupUnpairedDevices() = 0;
336 * @brief Check if app can keep context.
338 virtual bool CanAppKeepContext(const std::string& app_id) = 0;
341 * @brief Check if app can steal focus.
343 virtual bool CanAppStealFocus(const std::string& app_id) = 0;
346 } // namespace policy
348 extern "C" policy::PolicyManager* CreateManager();
350 #endif // SRC_COMPONENTS_POLICY_INCLUDE_POLICY_POLICY_MANAGER_H_