87ff292c11563478786f3300b5d8ffe60f0f5cf3
[platform/core/appfw/wgt-backend.git] / src / wgt / wgt_installer.cc
1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
4
5 #include "wgt/wgt_installer.h"
6
7 #include <common/pkgmgr_interface.h>
8
9 #include <common/privileges.h>
10 #include <common/step/filesystem/step_create_icons.h>
11 #include <common/step/filesystem/step_create_storage_directories.h>
12 #include <common/step/filesystem/step_delta_patch.h>
13 #include <common/step/security/step_privilege_compatibility.h>
14 #include <common/step/security/step_recover_privilege_compatibility.h>
15
16 #include <wgt_manifest_handlers/widget_config_parser.h>
17
18 #include "lib/wgt_archive_info.h"
19 #include "wgt/utils/shared_dirs.h"
20 #include "wgt/step/configuration/step_check_rds_manifest.h"
21 #include "wgt/step/configuration/step_check_start_files.h"
22 #include "wgt/step/configuration/step_parse.h"
23 #include "wgt/step/configuration/step_set_old_signature_files_location.h"
24 #include "wgt/step/encryption/step_encrypt_resources.h"
25 #include "wgt/step/encryption/step_remove_encryption_data.h"
26 #include "wgt/step/filesystem/step_copy_preview_icons.h"
27 #include "wgt/step/filesystem/step_create_wgt_symbolic_link.h"
28 #include "wgt/step/filesystem/step_wgt_patch_icons.h"
29 #include "wgt/step/filesystem/step_wgt_patch_storage_directories.h"
30 #include "wgt/step/filesystem/step_wgt_prepare_package_directory.h"
31 #include "wgt/step/filesystem/step_wgt_resource_directory.h"
32 #include "wgt/step/filesystem/step_wgt_undo_patch_storage_directories.h"
33 #include "wgt/step/filesystem/step_wgt_update_package_directory.h"
34 #include "wgt/step/pkgmgr/step_generate_xml.h"
35 #include "wgt/step/security/step_add_default_privileges.h"
36 #include "wgt/step/security/step_check_settings_level.h"
37 #include "wgt/step/security/step_check_wgt_background_category.h"
38 #include "wgt/step/security/step_check_wgt_notification_category.h"
39 #include "wgt/step/security/step_check_wgt_ime_privilege.h"
40 #include "wgt/step/security/step_direct_manifest_signature.h"
41 #include "wgt/step/security/step_check_extension_privileges.h"
42 #include "wgt/step/security/step_wgt_recover_signature.h"
43
44 namespace ci = common_installer;
45
46 namespace wgt {
47
48 WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr)
49     : AppInstaller("wgt", pkgrmgr) {
50   context_->backend_data.set(new WgtBackendData());
51 }
52
53 std::unique_ptr<ci::ArchiveInfo> WgtInstaller::GetArchiveInfo() {
54   std::unique_ptr<WgtArchiveInfo> archive_info;
55   archive_info.reset(new WgtArchiveInfo(pkgmgr_->GetRequestInfo(GetIndex())));
56   return archive_info;
57 }
58
59 void WgtInstaller::InstallSteps() {
60   AppInstaller::InstallSteps();
61   ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
62       wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
63   AddStepAfter<ci::security::StepPrivilegeCompatibility>("Signature",
64       ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
65   AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
66   AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
67       "CheckSettingsLevel");
68   AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
69       "CheckWgtBackgroundCategory");
70   AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
71       "CheckWgtNotificationCategory");
72   AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
73   AddStepAfter<wgt::filesystem::StepWgtResourceDirectory>("EncryptResources");
74   RemoveStep("CreateIcons");
75   AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>(
76       "CopyTEP");
77   AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
78       "WgtPatchStorageDirectories");
79   AddStepAfter<wgt::filesystem::StepWgtPatchIcons>(
80       "CreateWgtSymbolicLink", true);
81   AddStepAfter<ci::filesystem::StepCreateIcons>("WgtPatchIcons");
82   AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("CreateIcons");
83   AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
84       "CopyPreviewIcons");
85   AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
86   ReplaceStep<ci::filesystem::StepCreateStorageDirectories>(
87       "CreateStorageDirectories",
88       wgt::filesystem::WgtAdditionalSharedDirs);
89 }
90
91 void WgtInstaller::UpdateSteps() {
92   AppInstaller::UpdateSteps();
93   ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
94       wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
95   AddStepAfter<ci::security::StepPrivilegeCompatibility>("CheckOldCertificate",
96       ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
97   AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
98   AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
99       "CheckSettingsLevel");
100   AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
101       "CheckWgtBackgroundCategory");
102   AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
103       "CheckWgtNotificationCategory");
104   AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
105   AddStepAfter<wgt::filesystem::StepWgtResourceDirectory>("EncryptResources");
106   AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
107   AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
108   AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>("CopyPreviewIcons");
109   AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
110       "CreateWgtSymbolicLink");
111   AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
112   AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>(
113       "CopyStorageDirectories");
114 }
115
116 void WgtInstaller::UninstallSteps() {
117   AppInstaller::UninstallSteps();
118   AddStepAfter<wgt::encryption::StepRemoveEncryptionData>(
119       "RemovePerUserStorageDirectories");
120 }
121
122 void WgtInstaller::ReinstallSteps() {
123   AppInstaller::ReinstallSteps();
124   AddStepAfter<wgt::configuration::StepCheckRDSManifest>("Configure");
125   ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
126       wgt::configuration::StepParse::ConfigLocation::RESOURCE_WGT, false);
127   // Unlike reinstall mode (RDS) of tpk-backend, the RDS package of wgt does not
128   // contain signature files. This may can be changed differently later.
129   RemoveStep("Signature");
130   RemoveStep("CheckOldCertificate");
131   AddStepAfter<wgt::security::StepCheckExtensionPrivileges>("CreateIcons");
132 }
133
134 void WgtInstaller::DeltaSteps() {
135   AppInstaller::DeltaSteps();
136   ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
137       wgt::configuration::StepParse::ConfigLocation::PACKAGE, false);
138   AddStepAfter<wgt::filesystem::StepWgtUndoPatchStorageDirectories>(
139       "EnableExternalMount");
140   ReplaceStep<ci::filesystem::StepDeltaPatch>("DeltaPatch", "res/wgt/");
141   AddStepAfter<wgt::configuration::StepCheckStartFiles>("DisableExternalMount");
142   AddStepAfter<ci::security::StepPrivilegeCompatibility>("CheckOldCertificate",
143       ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
144   AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
145   AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
146       "CheckSettingsLevel");
147   AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
148       "CheckWgtBackgroundCategory");
149   AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
150       "CheckWgtNotificationCategory");
151   AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
152   AddStepAfter<wgt::filesystem::StepWgtResourceDirectory>("EncryptResources");
153   AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
154   AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
155   AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>("CopyPreviewIcons");
156   AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
157       "CreateWgtSymbolicLink");
158   AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
159   AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>(
160       "CopyStorageDirectories");
161 }
162
163 void WgtInstaller::RecoverySteps() {
164   AppInstaller::RecoverySteps();
165   AddStepAfter<wgt::security::StepWgtRecoverSignature>("MountRecover");
166   AddStepAfter<ci::security::StepRecoverPrivilegeCompatibility>(
167       "WgtRecoverSignature",
168       ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
169 }
170
171 void WgtInstaller::MountInstallSteps() {
172   AppInstaller::MountInstallSteps();
173   ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
174       wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
175   AddStepAfter<ci::security::StepPrivilegeCompatibility>("Signature",
176       ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
177   AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
178   AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
179       "CheckSettingsLevel");
180   AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
181       "CheckWgtBackgroundCategory");
182   AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
183       "CheckWgtNotificationCategory");
184   AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
185   AddStepAfter<wgt::filesystem::StepWgtPreparePackageDirectory>("MountInstall");
186   AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
187   AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
188   AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
189       "CopyPreviewIcons");
190   AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
191       "CreateWgtSymbolicLink");
192   AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
193   ReplaceStep<ci::filesystem::StepCreateStorageDirectories>(
194       "CreateStorageDirectories",
195       wgt::filesystem::WgtAdditionalSharedDirs);
196   AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>(
197       "CreateStorageDirectories");
198 }
199
200 void WgtInstaller::MountUpdateSteps() {
201   AppInstaller::MountUpdateSteps();
202   ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
203       wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
204   AddStepAfter<ci::security::StepPrivilegeCompatibility>("CheckOldCertificate",
205       ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
206   AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
207   AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
208       "CheckSettingsLevel");
209   AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
210       "CheckWgtBackgroundCategory");
211   AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
212       "CheckWgtNotificationCategory");
213   AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
214   AddStepAfter<wgt::filesystem::StepWgtUpdatePackageDirectory>("MountUpdate");
215   AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
216   AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
217   AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
218       "CopyPreviewIcons");
219   AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
220       "CreateWgtSymbolicLink");
221   AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
222   AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>(
223       "UpdateStorageDirectories");
224 }
225
226 void WgtInstaller::ManifestDirectInstallSteps() {
227   AppInstaller::ManifestDirectInstallSteps();
228   ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
229       wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
230   ReplaceStep<wgt::security::StepDirectManifestSignature>("Signature", true);
231   AddStepAfter<ci::security::StepPrivilegeCompatibility>(
232       "DirectManifestSignature",
233       ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
234   AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
235   AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
236       "CheckSettingsLevel");
237   AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
238       "CheckWgtBackgroundCategory");
239   AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
240       "CheckWgtNotificationCategory");
241   AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("RemoveGlobalAppSymlinks",
242       true);
243   AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
244       "WgtPatchIcons");
245   AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CreateWgtSymbolicLink");
246   ReplaceStep<ci::filesystem::StepCreateStorageDirectories>(
247       "CreateStorageDirectories",
248       wgt::filesystem::WgtAdditionalSharedDirs);
249 }
250
251 void WgtInstaller::ManifestDirectUpdateSteps() {
252   AppInstaller::ManifestDirectUpdateSteps();
253   ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
254       wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
255   ReplaceStep<wgt::security::StepDirectManifestSignature>("Signature", true);
256   AddStepAfter<ci::security::StepPrivilegeCompatibility>(
257       "CheckOldCertificate",
258       ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
259   AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
260   AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
261       "CheckSettingsLevel");
262   AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
263       "CheckWgtBackgroundCategory");
264   AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
265       "CheckWgtNotificationCategory");
266   AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("RemoveGlobalAppSymlinks",
267       true);
268   AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
269       "WgtPatchIcons");
270   AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CreateWgtSymbolicLink");
271 }
272
273 void WgtInstaller::ReadonlyUpdateInstallSteps() {
274   AppInstaller::ReadonlyUpdateInstallSteps();
275   ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
276       wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
277   AddStepAfter<ci::security::StepPrivilegeCompatibility>("CheckOldCertificate",
278       ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
279   AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
280   AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
281       "CheckSettingsLevel");
282   AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
283       "CheckWgtBackgroundCategory");
284   AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
285       "CheckWgtNotificationCategory");
286   AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
287   AddStepAfter<wgt::filesystem::StepWgtResourceDirectory>("EncryptResources");
288   AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
289   AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
290   AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
291       "CopyPreviewIcons");
292   AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
293       "CreateWgtSymbolicLink");
294   AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
295   AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>(
296       "CreateStorageDirectories");
297 }
298
299 void WgtInstaller::ReadonlyUpdateUninstallSteps() {
300   AppInstaller::ReadonlyUpdateUninstallSteps();
301   AddStepBefore<wgt::configuration::StepSetOldSignatureFilesLocation>(
302       "Signature");
303   AddStepAfter<ci::security::StepPrivilegeCompatibility>("Signature",
304       ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
305   AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
306   AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
307       "CheckSettingsLevel");
308   AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
309       "CheckWgtBackgroundCategory");
310   AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
311       "CheckWgtNotificationCategory");
312 }
313
314 void WgtInstaller::ManifestPartialInstallSteps() {
315   AppInstaller::ManifestPartialInstallSteps();
316   ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
317       wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
318   ReplaceStep<wgt::security::StepDirectManifestSignature>("Signature", false);
319   AddStepAfter<ci::security::StepPrivilegeCompatibility>(
320       "DirectManifestSignature",
321       ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
322   AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
323   AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
324       "CheckSettingsLevel");
325   AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
326       "CheckWgtBackgroundCategory");
327   AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
328       "CheckWgtNotificationCategory");
329   AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("RemoveGlobalAppSymlinks",
330       false);
331   ReplaceStep<ci::filesystem::StepCreateStorageDirectories>(
332       "CreateStorageDirectories",
333       wgt::filesystem::WgtAdditionalSharedDirs);
334 }
335
336 void WgtInstaller::ManifestPartialUpdateSteps() {
337   AppInstaller::ManifestPartialUpdateSteps();
338   ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
339       wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
340   ReplaceStep<wgt::security::StepDirectManifestSignature>("Signature", false);
341   AddStepAfter<ci::security::StepPrivilegeCompatibility>(
342       "CheckOldCertificate",
343       ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
344   AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
345   AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
346       "CheckSettingsLevel");
347   AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
348       "CheckWgtBackgroundCategory");
349   AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
350       "CheckWgtNotificationCategory");
351   AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("RemoveGlobalAppSymlinks",
352       false);
353 }
354
355 void WgtInstaller::PartialUninstallSteps() {
356   AppInstaller::PartialUninstallSteps();
357   AddStepAfter<wgt::encryption::StepRemoveEncryptionData>(
358       "RemovePerUserStorageDirectories");
359 }
360
361 void WgtInstaller::MoveSteps() {
362   AppInstaller::MoveSteps();
363 }
364
365 void WgtInstaller::EnablePkgSteps() {
366   AppInstaller::EnablePkgSteps();
367 }
368
369 void WgtInstaller::DisablePkgSteps() {
370   AppInstaller::DisablePkgSteps();
371 }
372
373 void WgtInstaller::MigrateExtImgSteps() {
374   AppInstaller::MigrateExtImgSteps();
375 }
376
377 void WgtInstaller::RecoverDBSteps() {
378   AppInstaller::RecoverDBSteps();
379   ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
380       wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
381   AddStepAfter<ci::security::StepPrivilegeCompatibility>("GetPrivilegeLevel",
382       ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
383   AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
384   AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
385       "CheckSettingsLevel");
386   AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
387       "CheckWgtBackgroundCategory");
388   AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
389       "CheckWgtNotificationCategory");
390 }
391
392 }  // namespace wgt