Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / installer_context.h
1 /* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
2 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3 // Use of this source code is governed by a apache 2.0 license that can be
4 // found in the LICENSE file.
5
6 #ifndef COMMON_INSTALLER_CONTEXT_H_
7 #define COMMON_INSTALLER_CONTEXT_H_
8
9 #include <pkgmgr_parser.h>
10
11 #include <unistd.h>
12 #include <sys/types.h>
13 #include <vcore/Certificate.h>
14
15 #include <filesystem>
16 #include <memory>
17 #include <string>
18 #include <utility>
19 #include <vector>
20
21 #include "common/external_mount.h"
22 #include "common/external_storage.h"
23 #include "common/pkgmgr_interface.h"
24 #include "common/recovery_file.h"
25 #include "common/utils/property.h"
26 #include "common/utils/request.h"
27
28 #include "manifest_info/account.h"
29 #include "manifest_info/ime_info.h"
30
31 namespace common_installer {
32
33 struct ShortcutInfo {
34   std::string app_id;
35   std::string extra_data;
36   std::string extra_key;
37   std::string icon;
38   std::vector<std::pair<std::string, std::string>> labels;
39 };
40
41 using ShortcutListInfo = std::vector<ShortcutInfo>;
42
43 /**
44  * \brief Structure, that holds additional data retrieved from manifest
45  * and used during generation of platform manifest (for data that are not
46  * available within manifest_x structure
47  */
48 class ExtraManifestData {
49  public:
50   /** Constructor */
51   ExtraManifestData() {}
52
53   Property<AccountInfo> account_info;
54   Property<ShortcutListInfo> shortcut_info;
55   Property<ImeInfo> ime_info;
56 };
57
58 /**
59  * \brief Base class that is used within specific backends to keep additional
60  *        information regarding package
61  */
62 class BackendData {
63  public:
64   /** virtual destructor */
65   virtual ~BackendData() { }
66 };
67
68 /**
69  * \brief Class represents certificate information
70  */
71 class CertificateInfo {
72  public:
73   /** author_id (using public key from author certificate) */
74   Property<std::string> author_id;
75   /** author_certificate */
76   Property<ValidationCore::CertificatePtr> auth_cert;
77   /** author_intermediate_certificate */
78   Property<ValidationCore::CertificatePtr> auth_im_cert;
79   /** author_root_certificate */
80   Property<ValidationCore::CertificatePtr> auth_root_cert;
81   /** distributor_certificate */
82   Property<ValidationCore::CertificatePtr> dist_cert;
83   /** distributor_intermediate_certificate */
84   Property<ValidationCore::CertificatePtr> dist_im_cert;
85   /** distributor_root_certificate */
86   Property<ValidationCore::CertificatePtr> dist_root_cert;
87   /** distributor2_certificate */
88   Property<ValidationCore::CertificatePtr> dist2_cert;
89   /** distributor2_intermediate_certificate */
90   Property<ValidationCore::CertificatePtr>
91       dist2_im_cert;
92   /** distributor2_root_certificate */
93   Property<ValidationCore::CertificatePtr> dist2_root_cert;
94 };
95
96 /**
97  * \brief Class used for recovery situation.
98  *        It holds pointer to RecoveryFile object.
99  */
100 class RecoveryInfo {
101  public:
102   /** default constructor */
103   RecoveryInfo() : cleanup(false) { }
104
105   /**
106    * Constructor.
107    *
108    * \param rf RecoveryFile object (pointer to object)
109    */
110   explicit RecoveryInfo(std::unique_ptr<recovery::RecoveryFile> rf)
111       : recovery_file(std::move(rf)), cleanup(false) {
112   }
113
114   /**
115    * Constructor.
116    *
117    * \param path path of recovery file to be created
118    * \param recovery_cleanup path of recovery file to be created
119    */
120   explicit RecoveryInfo(const std::filesystem::path& path,
121       bool recovery_cleanup = false)
122       : filepath(path), cleanup(recovery_cleanup) {
123   }
124
125   /** pointer to RecoveryFile */
126   std::unique_ptr<recovery::RecoveryFile> recovery_file;
127
128   /** path of recovery file to be created */
129   std::filesystem::path filepath;
130
131   /** cleanup flag delivered by global recovery file */
132   bool cleanup;
133 };
134
135 /**
136  * Enumeration for Privilege levels
137  */
138 enum class PrivilegeLevel : int {
139   UNTRUSTED  = 0,
140   PUBLIC     = 1,
141   PARTNER    = 2,
142   PLATFORM   = 3
143 };
144
145 /**
146  * Enumeration for Storage types
147  */
148 enum class Storage : int {
149   INTERNAL   = 0,
150   EXTERNAL   = 1,
151   EXTENDED   = 2
152 };
153
154 /**
155  * Enumeration for move types
156  */
157 enum class MoveType : int {
158   NONE = -1,
159   TO_INTERNAL = 0,
160   TO_EXTERNAL = 1,
161   TO_EXTENDED = 2
162 };
163
164 /**
165  * \brief Helper function. Checks (and compares) passed levels
166  *
167  * \param required_level level to compare
168  * \param allowed_level level to compare
169  *
170  * \return true, if required_level <= allowed_level
171  */
172 bool SatifiesPrivilegeLevel(PrivilegeLevel required_level,
173                    PrivilegeLevel allowed_level);
174
175 /**
176  * \brief translates privilege level to string
177  *
178  * \param level privilege level to translate
179  *
180  * \return translated level (to string)
181  */
182 const char* PrivilegeLevelToString(PrivilegeLevel level);
183
184 /**
185  * \brief Holds data generated/used by Steps (e.g. pkgid retrieved from
186  *        manifest parsing, path to unzipped package).
187  *        ContextInstaller is owned by AppInstaller object. Steps holds
188  *        “pointers” to ContextInstaller (pointer is initialized in Step
189  *        constructor).
190  */
191 class InstallerContext {
192  public:
193   /** Constructor */
194   InstallerContext();
195
196   /** Destructor */
197   ~InstallerContext();
198
199   /**
200    * \brief Returns package directory path containing app data
201    */
202   inline std::filesystem::path GetPkgPath() const {
203     return root_application_path.get() / pkgid.get();
204   }
205
206   /**
207    * \brief path to final location of installed package in filesystem
208    */
209   Property<std::string> pkgid;
210
211   /**
212    * \brief package type (string representing name of backend)
213    */
214   Property<std::string> pkg_type;
215
216   /**
217    * \brief In-memory representation of platform xml manifest file
218    *        - contains all information needed by tizen application
219    *        framework to handle package management (pkgid, icon,
220    *        applications, appcontrol, privileges and more)
221    */
222   Property<manifest_x*> manifest_data;
223
224   /** Pkgmgr-parser plugins data */
225   Property<ExtraManifestData> manifest_plugins_data;
226
227   /**
228    * \brief In-memory representation of platform xml manifest file
229    *        - contains all already stored information needed by tizen
230    *        application framework to handle package management (pkgid,
231    *        icon, applications, appcontrol, privileges and more)
232    *        - this field is set only for update installation
233    *        (we need this information for rollback possibility)
234    */
235   Property<manifest_x*> old_manifest_data;
236
237   /**
238    * \brief path to xml platform manifest which was generated according
239    *        to maniest_data content */
240   Property<std::filesystem::path> xml_path;
241
242   /**
243    * \brief path to backup xml platform manifest which was generated
244    *        according to old_maniest_data content (needed for rollback
245    *        operations)
246    */
247   Property<std::filesystem::path> backup_xml_path;
248
249   /**
250    * \brief file path used for installation or reinstallation process
251    */
252   Property<std::filesystem::path> file_path;
253
254   /**
255    * \brief tep file path used for TEP installation process
256    */
257   Property<std::filesystem::path> tep_path;
258
259   /**
260   * \brief boolean property that indicates tep file should be moved or not
261   */
262   Property<bool> is_tep_move;
263
264   /**
265   * \brief boolean property that indicates request is external move or not
266   */
267   Property<bool> is_move_to_external;
268
269   /**
270    * \brief property that indicates move type
271    */
272   Property<MoveType> move_type;
273
274   /**
275    * \brief path to temporary directory when package files are unpacked
276    *        before coping them to final destination
277    */
278   Property<std::filesystem::path> unpacked_dir_path;
279
280   /**
281    * \brief uid of user which installation was triggered for
282    *        (any normal or globaltizenapp)
283    */
284   Property<uid_t> uid;
285
286   /**
287    * \brief root directory of installation of all packages for user
288    *        (${TZ_USER_HOME}/${USER}/apps_rw/) or
289    *        tizenglobalapp user (${TZ_SYS_RO_APP} or ${TZ_SYS_RW_APP})
290    */
291   Property<std::filesystem::path> root_application_path;
292
293   /**
294    * \brief "void*-like" structure to store backend specific
295    *        information about installation process
296    */
297   Property<BackendData*> backend_data;
298
299   /**
300    * \brief privilege/visibility level discovered from signature files
301    *        - restricts package privileges
302    */
303   Property<PrivilegeLevel> privilege_level;
304
305   /**
306    * \brief certificate information
307    */
308   Property<CertificateInfo> certificate_info;
309
310   /**
311    * \brief information for recovery
312    */
313   Property<RecoveryInfo> recovery_info;
314
315   /**
316    * \brief user type of request (GLOBAL/USER)
317    */
318   Property<RequestMode> request_mode;
319
320   /**
321    * \brief request type received from pkgmgr_installer
322    */
323   Property<RequestType> request_type;
324
325   /**
326    * \brief installation mode (ONLINE / OFFLINE)
327    */
328   Property<InstallationMode> installation_mode;
329
330   /**
331    * \brief readonly request received from pkgmgr_installer
332    */
333   Property<bool> is_readonly_package;
334
335   /**
336    * \brief preload-rw request received from pkgmgr_installer
337    */
338   Property<bool> is_preload_rw_package;
339
340   /**
341    * \brief force-remove flag received from pkgmgr_installer
342    */
343   Property<bool> force_remove;
344
345   /**
346    * \brief no-remove flag received from pkgmgr_installer
347    */
348   Property<bool> no_remove;
349
350   /**
351    * \brief keep-rwdata flag received from pkgmgr_installer
352    */
353   Property<bool> keep_rwdata;
354
355   /**
356    * \brief partial-rw flag received from pkgmgr_installer
357    */
358   Property<bool> partial_rw;
359
360   /**
361    * \brief Describes force clean behaviour from db data. It set to ture,
362    *        the uninstallation will be done to the end of steps.
363    */
364   Property<bool> force_clean_from_db;
365
366   /**
367    * \brief Describes behaviour for security manager. It set to true, this will
368    *        force to generates n-to-n rules for package's apps.
369    *        This will be used for hybrid apps.
370    */
371   Property<bool> cross_app_rules;
372
373   /**
374    * \brief boolean property that indicates the request is for debugging or not.
375    */
376   Property<bool> debug_mode;
377
378   /**
379    * \brief boolean property that indicates
380    *        the request is for skip optimization or not.
381    */
382   Property<bool> skip_optimization;
383
384   /**
385   * \brief Property of vector of files to add
386   */
387   Property<std::vector<std::string>> files_to_add;
388
389   /**
390   * \brief Property of vector of files to modify
391   */
392   Property<std::vector<std::string>> files_to_modify;
393
394   /**
395   * \brief Property of vector of files to delete
396   */
397   Property<std::vector<std::string>> files_to_delete;
398
399   /**
400    * @brief External Storage object if installing in external
401    */
402   std::unique_ptr<ExternalStorage> external_storage;
403
404   /**
405    * @brief External package mount object if delta update with external
406    */
407   std::unique_ptr<ExternalMount> external_mount;
408
409   /**
410    * @brief skip-check-reference flag received from pkgmgr_installer
411    */
412   Property<bool> skip_check_reference;
413
414   /**
415    * @brief Storage where package to be installed
416    */
417   Property<Storage> storage;
418
419   /**
420    * @brief Index of current request
421    */
422   Property<int> index;
423 };
424
425 }  // namespace common_installer
426
427 #endif  // COMMON_INSTALLER_CONTEXT_H_