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