pull in new policy updates
[profile/ivi/smartdevicelink.git] / src / components / policy / src / policy / include / policy / policy_manager.h
1 /*
2  Copyright (c) 2013, Ford Motor Company
3  All rights reserved.
4
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7
8  Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10
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
14  distribution.
15
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.
19
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.
31  */
32
33 #ifndef SRC_COMPONENTS_POLICY_INCLUDE_POLICY_POLICY_MANAGER_H_
34 #define SRC_COMPONENTS_POLICY_INCLUDE_POLICY_POLICY_MANAGER_H_
35
36 #include <vector>
37
38 #include "policy/policy_types.h"
39 #include "policy/policy_listener.h"
40 #include "usage_statistics/statistics_manager.h"
41
42 namespace policy {
43
44 class PolicyManager : public usage_statistics::StatisticsManager {
45   public:
46     virtual ~PolicyManager() {
47     }
48
49     virtual void set_listener(PolicyListener* listener) = 0;
50
51     /**
52      * Inits Policy Table
53      * @param file_name Path to preloaded PT file
54      * @return true if successfully
55      */
56     virtual bool InitPT(const std::string& file_name) = 0;
57
58     /**
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
65      */
66     virtual bool LoadPT(const std::string& file, const BinaryMessage& pt_content) = 0;
67
68     /**
69      * Resets Policy Table
70      * @param file_name Path to preloaded PT file
71      * @return true if successfully
72      */
73     virtual bool ResetPT(const std::string& file_name) = 0;
74
75     /**
76      * @brief Gets URL for sending PTS to from PT itself.
77        * @param service_type Service specifies user of URL
78      * @return string URL
79      */
80     virtual std::string GetUpdateUrl(int service_type) = 0;
81
82     /**
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
86      */
87     virtual EndpointUrls GetUpdateUrls(int service_type) = 0;
88
89     /**
90      * @brief PTU is needed, for this PTS has to be formed and sent.
91      * @return BinaryMessage* PTS.
92      */
93     virtual BinaryMessageSptr RequestPTUpdate() = 0;
94
95     /**
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.
104      */
105     virtual CheckPermissionResult CheckPermissions(const PTString& app_id,
106         const PTString& hmi_level,
107         const PTString& rpc) = 0;
108
109     /**
110      * @brief Clear all record of user consents. Used during Factory Reset.
111      * @return bool Success of operation
112      */
113     virtual bool ResetUserConsent() = 0;
114
115     /**
116      * @brief Checks, if policy update is necessary for application
117      * @param Application id assigned by Ford to the application
118      */
119     virtual void CheckAppPolicyState(const std::string& application_id) = 0;
120
121     /**
122      * @brief Returns current status of policy table for HMI
123      * @return Current status of policy table
124      */
125     virtual PolicyTableStatus GetPolicyTableStatus() = 0;
126
127     /**
128      * Checks is PT exceeded IgnitionCycles
129      * @return true if exceeded
130      */
131     virtual bool ExceededIgnitionCycles() = 0;
132
133     /**
134      * Checks is PT exceeded days
135      * @param days current day after epoch
136      * @return true if exceeded
137      */
138     virtual bool ExceededDays(int days) = 0;
139
140     /**
141      * Checks is PT exceeded kilometers
142      * @param kilometers current kilometers at odometer
143      * @return true if exceeded
144      */
145     virtual bool ExceededKilometers(int kilometers) = 0;
146
147     /**
148      * Increments counter of ignition cycles
149      */
150     virtual void IncrementIgnitionCycles() = 0;
151
152     /**
153      * Resets retry sequence
154      */
155     virtual void ResetRetrySequence() = 0;
156
157     /**
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
161      */
162     virtual int NextRetryTimeout() = 0;
163
164     /**
165      * Gets timeout to wait until receive response
166      * @return timeout in seconds
167      */
168     virtual int TimeoutExchange() = 0;
169
170     /**
171      * @brief List of timeouts in seconds between retries
172      *        when attempt to update PT fails
173      * @return List of delays between attempts.
174      */
175     virtual const std::vector<int> RetrySequenceDelaysSeconds() = 0;
176
177     /**
178      * Handler of exceeding timeout of exchanging policy table
179      */
180     virtual void OnExceededTimeout() = 0;
181
182     /**
183      * @brief Check user consent for mobile device data connection
184      * @param device_id Unique device identifier
185      * @return status of device consent
186      */
187     virtual DeviceConsent GetUserConsentForDevice(
188       const std::string& device_id) = 0;
189
190     /**
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
195      */
196     virtual void GetUserConsentForApp(
197       const std::string& device_id, const std::string& policy_app_id,
198       std::vector<FunctionalGroupPermission>& permissions) = 0;
199
200     /**
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
204      */
205     virtual void SetUserConsentForDevice(const std::string& device_id,
206                                          bool is_allowed) = 0;
207
208     /**
209      * @brief Update Application Policies as reaction
210      * on User allowing/disallowing device this app is running on.
211      */
212     virtual bool ReactOnUserDevConsentForApp(const std::string app_id,
213         bool is_device_allowed) = 0;
214     /**
215      * Sets number of kilometers and days after epoch, that passed for
216      * receiving PT UPdate.
217      */
218     virtual void PTUpdatedAt(int kilometers, int days_after_epoch) = 0;
219
220     /**
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
225      */
226     virtual bool GetInitialAppData(const std::string& application_id,
227                                    StringArray* nicknames = NULL,
228                                    StringArray* app_hmi_types = NULL) = 0;
229     /**
230      * @brief Stores device parameters received during application registration
231      * to policy table
232      * @param device_id Device mac address
233      * @param device_info Received device parameters
234      */
235     virtual void SetDeviceInfo(const std::string& device_id,
236                                const DeviceInfo& device_info) = 0;
237
238     /**
239      * @brief Set user consent for application functional groups
240      * @param permissions User-defined application group pemissions
241      */
242     virtual void SetUserConsentForApp(const PermissionConsent& permissions) = 0;
243
244     /**
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
248      * was not set
249      * @return true, if succedeed, otherwise - false
250      */
251     virtual bool GetDefaultHmi(const std::string& policy_app_id,
252                                std::string* default_hmi) = 0;
253
254     /**
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
259      */
260     virtual bool GetPriority(const std::string& policy_app_id,
261                              std::string* priority) = 0;
262
263     /**
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
268      */
269     virtual std::vector<UserFriendlyMessage> GetUserFriendlyMessages(
270       const std::vector<std::string>& message_code,
271       const std::string& language) = 0;
272
273     /**
274      * Checks if the application is revoked
275      * @param app_id application id
276      * @return true if application is revoked
277      */
278     virtual bool IsApplicationRevoked(const std::string& app_id) const = 0;
279
280     /**
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
285      */
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;
292
293     /**
294      * @brief Return device id, which hosts specific application
295      * @param Application id, which is required to update device id
296      */
297     virtual std::string& GetCurrentDeviceId(const std::string& policy_app_id) = 0;
298
299     /**
300      * @brief Set current system language
301      * @param language Language
302      */
303     virtual void SetSystemLanguage(const std::string& language) = 0;
304
305     /**
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
310      */
311     virtual void SetSystemInfo(const std::string& ccpu_version,
312                                const std::string& wers_country_code,
313                                const std::string& language) = 0;
314
315     /**
316      * @brief Send OnPermissionsUpdated for choosen application
317      * @param application_id
318      */
319     virtual void SendNotificationOnPermissionsUpdated(
320       const std::string& application_id) = 0;
321
322     /**
323      * Marks device as upaired
324      * @param device_id id device
325      */
326     virtual void MarkUnpairedDevice(const std::string& device_id) = 0;
327
328     /**
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
332      */
333     virtual bool CleanupUnpairedDevices() = 0;
334
335     /**
336      * @brief Check if app can keep context.
337      */
338     virtual bool CanAppKeepContext(const std::string& app_id) = 0;
339
340     /**
341      * @brief Check if app can steal focus.
342      */
343     virtual bool CanAppStealFocus(const std::string& app_id) = 0;
344 };
345
346 }  // namespace policy
347
348 extern "C" policy::PolicyManager* CreateManager();
349
350 #endif  // SRC_COMPONENTS_POLICY_INCLUDE_POLICY_POLICY_MANAGER_H_