ac82ba14eabfe981763f88fed42e0f55a300e5eb
[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 <boost/filesystem/path.hpp>
10
11 #include <pkgmgr_parser.h>
12
13 #include <unistd.h>
14 #include <sys/types.h>
15 #include <vcore/Certificate.h>
16
17 #include <memory>
18 #include <string>
19 #include <utility>
20 #include <vector>
21
22 #include "common/pkgmgr_interface.h"
23 #include "common/recovery_file.h"
24 #include "common/request.h"
25 #include "common/utils/property.h"
26
27 #include "manifest_info/account.h"
28
29 namespace common_installer {
30
31 // TODO(t.iwanek): this structure should be unified for manifest handlers of
32 // wgt and tpk packages
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 // TODO(p.sikorski): if that structure holds extra information not covered
45 // in manifest_x, maybe it should hold manifest_x as well?
46 /**
47  * \brief Structure, that holds additional data retrieved from manifest
48  * and used during generation of platform manifest (for data that are not
49  * available within manifest_x structure
50  */
51 class ExtraManifestData {
52  public:
53   /** Constructor */
54   ExtraManifestData() {}
55
56   Property<AccountInfo> account_info;
57   Property<ShortcutListInfo> shortcut_info;
58 };
59
60 /**
61  * \brief Base class that is used within specific backends to keep additional
62  *        information regarding package
63  */
64 class BackendData {
65  public:
66   /** virtual destructor */
67   virtual ~BackendData() { }
68 };
69
70 /**
71  * \brief Class represents certificate information
72  */
73 class CertificateInfo {
74  public:
75   /** author_id (using public key from author certificate) */
76   Property<std::string> author_id;
77   /** author_certificate */
78   Property<ValidationCore::CertificatePtr> author_certificate;
79   /** author_intermediate_certificate */
80   Property<ValidationCore::CertificatePtr> author_intermediate_certificate;
81   /** author_root_certificate */
82   Property<ValidationCore::CertificatePtr> author_root_certificate;
83   /** distributor_certificate */
84   Property<ValidationCore::CertificatePtr> distributor_certificate;
85   /** distributor_intermediate_certificate */
86   Property<ValidationCore::CertificatePtr> distributor_intermediate_certificate;
87   /** distributor_root_certificate */
88   Property<ValidationCore::CertificatePtr> distributor_root_certificate;
89 };
90
91 /**
92  * \brief Class used for recovery situation.
93  *        It holds pointer to RecoveryFile object.
94  */
95 class RecoveryInfo {
96  public:
97   /** default constructor */
98   RecoveryInfo() { }
99
100   /**
101    * Constructor.
102    *
103    * \param rf RecoveryFile object (pointer to object)
104    */
105   explicit RecoveryInfo(std::unique_ptr<recovery::RecoveryFile> rf)
106       : recovery_file(std::move(rf)) {
107   }
108
109   /** pointer to RecoveryFile */
110   std::unique_ptr<recovery::RecoveryFile> recovery_file;
111 };
112
113 /**
114  * Enumeration for Privilege levels
115  */
116 enum class PrivilegeLevel : int {
117   UNTRUSTED  = 0,
118   PUBLIC     = 1,
119   PARTNER    = 2,
120   PLATFORM   = 3
121 };
122
123 /**
124  * \brief Helper function. Checks (and compares) passed levels
125  *
126  * \param required_level level to compare
127  * \param allowed_level level to compare
128  *
129  * \return true, if required_level <= allowed_level
130  */
131 bool SatifiesPrivilegeLevel(PrivilegeLevel required_level,
132                    PrivilegeLevel allowed_level);
133
134 /**
135  * \brief translates privilege level to string
136  *
137  * \param level privilege level to translate
138  *
139  * \return translated level (to string)
140  */
141 const char* PrivilegeLevelToString(PrivilegeLevel level);
142
143 // TODO(p.sikorski@samsung.com) this class should be divided into:
144 //  Base Context class
145 //  CtxInstall class that inherits from Context
146 //  CtxUninstall class that inherits from Context
147 //  It is because Uninstallation does not need so many fields.
148 //  similarly, installation may not need some of them
149
150 /**
151  * \brief Holds data generated/used by Steps (e.g. pkgid retrieved from
152  *        manifest parsing, path to unzipped package).
153  *        ContextInstaller is owned by AppInstaller object. Steps holds
154  *        “pointers” to ContextInstaller (pointer is initialized in Step
155  *        constructor).
156  */
157 class InstallerContext {
158  public:
159   /** Constructor */
160   InstallerContext();
161
162   /** Destructor */
163   ~InstallerContext();
164
165   /**
166    * \brief package type (string representing name of backend)
167    */
168   Property<std::string> pkg_type;
169
170   /**
171    * \brief In-memory representation of platform xml manifest file
172    *        - contains all information needed by tizen application
173    *        framework to handle package management (pkgid, icon,
174    *        applications, appcontrol, privileges and more)
175    */
176   Property<manifest_x*> manifest_data;
177
178   /** Pkgmgr-parser plugins data */
179   Property<ExtraManifestData> manifest_plugins_data;
180
181   /**
182    * \brief In-memory representation of platform xml manifest file
183    *        - contains all already stored information needed by tizen
184    *        application framework to handle package management (pkgid,
185    *        icon, applications, appcontrol, privileges and more)
186    *        - this field is set only for update installation
187    *        (we need this information for rollback possibility)
188    */
189   Property<manifest_x*> old_manifest_data;
190
191   /**
192    * \brief path to xml platform manifest which was generated according
193    *        to maniest_data content */
194   Property<boost::filesystem::path> xml_path;
195
196   /**
197    * \brief path to backup xml platform manifest which was generated
198    *        according to old_maniest_data content (needed for rollback
199    *        operations)
200    */
201   Property<boost::filesystem::path> backup_xml_path;
202
203   /**
204    * \brief path to final location of installed package in filesystem
205    */
206   Property<std::string> pkgid;
207
208   /**
209    * \brief package directory path containing app data
210    */
211   Property<boost::filesystem::path> pkg_path;
212
213   /**
214    * \brief file path used for installation or reinstallation process
215    */
216   Property<boost::filesystem::path> file_path;
217
218   /**
219    * \brief tep file path used for TEP installation process
220    */
221   Property<boost::filesystem::path> tep_path;
222
223   /**
224   * \brief boolean property that indicates tep file should be moved or not
225   */
226   Property<bool> is_tep_move;
227
228   /**
229    * \brief path to temporary directory when package files are unpacked
230    *        before coping them to final destination
231    */
232   Property<boost::filesystem::path> unpacked_dir_path;
233
234   /**
235    * \brief uid of user which installation was triggered for
236    *        (any normal or globaltizenapp)
237    */
238   Property<uid_t> uid;
239
240   /**
241    * \brief root directory of installation of all packages for user
242    *        (/home/${USER}/apps_rw/) or tizenglobalapp user (/usr/apps/)
243    */
244   Property<boost::filesystem::path> root_application_path;
245
246   /**
247    * \brief "void*-like" structure to store backend specific
248    *        information about installation process
249    */
250   Property<BackendData*> backend_data;
251
252   /**
253    * \brief privilege/visibility level discovered from signature files
254    *        - restricts package privileges
255    */
256   Property<PrivilegeLevel> privilege_level;
257
258   /**
259    * \brief certificate information
260    */
261   Property<CertificateInfo> certificate_info;
262
263   /**
264    * \brief information for recovery
265    */
266   Property<RecoveryInfo> recovery_info;
267
268   /**
269    * \brief user type of request (GLOBAL/USER)
270    */
271   Property<RequestMode> request_mode;
272
273   /**
274    * \brief request type received from pkgmgr_installer
275    */
276   Property<RequestType> request_type;
277
278   /**
279    * \brief installation mode (ONLINE / OFFLINE)
280    */
281   Property<InstallationMode> installation_mode;
282
283   /**
284    * \brief preload request received from pkgmgr_installer
285    */
286   Property<bool> is_preload_request;
287 };
288
289 }  // namespace common_installer
290
291 #endif  // COMMON_INSTALLER_CONTEXT_H_