70b4f004eccea27fbd80c93f844ae8ec02fd45a8
[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/step/backup/step_backup_icons.h>
10 #include <common/step/backup/step_backup_manifest.h>
11 #include <common/step/backup/step_copy_backup.h>
12 #include <common/step/configuration/step_block_cross_update.h>
13 #include <common/step/configuration/step_configure.h>
14 #include <common/step/configuration/step_fail.h>
15 #include <common/step/configuration/step_parse_manifest.h>
16 #include <common/step/filesystem/step_clear_data.h>
17 #include <common/step/filesystem/step_copy.h>
18 #include <common/step/filesystem/step_copy_storage_directories.h>
19 #include <common/step/filesystem/step_copy_tep.h>
20 #include <common/step/filesystem/step_create_icons.h>
21 #include <common/step/filesystem/step_create_per_user_storage_directories.h>
22 #include <common/step/filesystem/step_create_storage_directories.h>
23 #include <common/step/filesystem/step_delta_patch.h>
24 #include <common/step/filesystem/step_recover_files.h>
25 #include <common/step/filesystem/step_recover_icons.h>
26 #include <common/step/filesystem/step_recover_manifest.h>
27 #include <common/step/filesystem/step_recover_storage_directories.h>
28 #include <common/step/filesystem/step_remove_files.h>
29 #include <common/step/filesystem/step_remove_icons.h>
30 #include <common/step/filesystem/step_remove_per_user_storage_directories.h>
31 #include <common/step/filesystem/step_remove_temporary_directory.h>
32 #include <common/step/filesystem/step_remove_zip_image.h>
33 #include <common/step/filesystem/step_unzip.h>
34 #include <common/step/mount/step_mount_install.h>
35 #include <common/step/mount/step_mount_unpacked.h>
36 #include <common/step/mount/step_mount_update.h>
37 #include <common/step/pkgmgr/step_check_blacklist.h>
38 #include <common/step/pkgmgr/step_check_removable.h>
39 #include <common/step/pkgmgr/step_kill_apps.h>
40 #include <common/step/pkgmgr/step_recover_application.h>
41 #include <common/step/pkgmgr/step_register_app.h>
42 #include <common/step/pkgmgr/step_remove_manifest.h>
43 #include <common/step/pkgmgr/step_run_parser_plugins.h>
44 #include <common/step/pkgmgr/step_unregister_app.h>
45 #include <common/step/pkgmgr/step_update_app.h>
46 #include <common/step/pkgmgr/step_update_tep.h>
47 #include <common/step/recovery/step_open_recovery_file.h>
48 #include <common/step/security/step_check_old_certificate.h>
49 #include <common/step/security/step_check_signature.h>
50 #include <common/step/security/step_privilege_compatibility.h>
51 #include <common/step/security/step_recover_security.h>
52 #include <common/step/security/step_register_security.h>
53 #include <common/step/security/step_revoke_security.h>
54 #include <common/step/security/step_rollback_deinstallation_security.h>
55 #include <common/step/security/step_rollback_installation_security.h>
56 #include <common/step/security/step_update_security.h>
57
58 #include <wgt_manifest_handlers/widget_config_parser.h>
59 #include <common/step/rds/step_rds_modify.h>
60 #include <common/step/rds/step_rds_parse.h>
61
62 #include "wgt/step/configuration/step_parse.h"
63 #include "wgt/step/configuration/step_parse_recovery.h"
64 #include "wgt/step/encryption/step_encrypt_resources.h"
65 #include "wgt/step/encryption/step_remove_encryption_data.h"
66 #include "wgt/step/filesystem/step_create_symbolic_link.h"
67 #include "wgt/step/filesystem/step_wgt_patch_icons.h"
68 #include "wgt/step/filesystem/step_wgt_patch_storage_directories.h"
69 #include "wgt/step/filesystem/step_wgt_prepare_package_directory.h"
70 #include "wgt/step/filesystem/step_wgt_resource_directory.h"
71 #include "wgt/step/filesystem/step_wgt_update_package_directory.h"
72 #include "wgt/step/pkgmgr/step_generate_xml.h"
73 #include "wgt/step/rds/step_wgt_rds_modify.h"
74 #include "wgt/step/security/step_add_default_privileges.h"
75 #include "wgt/step/security/step_check_settings_level.h"
76 #include "wgt/step/security/step_check_wgt_background_category.h"
77 #include "wgt/step/security/step_check_wgt_notification_category.h"
78 #include "wgt/step/security/step_check_wgt_ime_privilege.h"
79 #include "wgt/step/security/step_direct_manifest_check_signature.h"
80
81 namespace ci = common_installer;
82
83 namespace wgt {
84
85 WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr)
86     : AppInstaller("wgt", pkgrmgr) {
87   context_->backend_data.set(new WgtBackendData());
88
89   /* treat the request */
90   switch (pkgmgr_->GetRequestType()) {
91     case ci::RequestType::Install : {
92       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
93       AddStep<ci::filesystem::StepUnzip>();
94       AddStep<wgt::configuration::StepParse>(
95         wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
96       AddStep<ci::pkgmgr::StepCheckBlacklist>();
97       AddStep<ci::security::StepCheckSignature>();
98       AddStep<ci::security::StepPrivilegeCompatibility>();
99       AddStep<wgt::security::StepCheckSettingsLevel>();
100       AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
101       AddStep<wgt::security::StepCheckWgtNotificationCategory>();
102       AddStep<wgt::security::StepCheckWgtImePrivilege>();
103       AddStep<wgt::encryption::StepEncryptResources>();
104       AddStep<wgt::filesystem::StepWgtResourceDirectory>();
105       AddStep<ci::security::StepRollbackInstallationSecurity>();
106       AddStep<ci::filesystem::StepCopy>();
107       AddStep<ci::filesystem::StepCopyTep>();
108       AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
109       AddStep<ci::filesystem::StepCreateStorageDirectories>();
110       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
111       AddStep<wgt::filesystem::StepWgtPatchIcons>();
112       AddStep<ci::filesystem::StepCreateIcons>();
113       AddStep<wgt::pkgmgr::StepGenerateXml>();
114       AddStep<ci::pkgmgr::StepRegisterApplication>();
115       AddStep<ci::pkgmgr::StepRunParserPlugin>(
116           ci::Plugin::ActionType::Install);
117       AddStep<ci::filesystem::StepCreatePerUserStorageDirectories>();
118       AddStep<ci::security::StepRegisterSecurity>();
119       break;
120     }
121     case ci::RequestType::Update: {
122       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
123       AddStep<ci::filesystem::StepUnzip>();
124       AddStep<wgt::configuration::StepParse>(
125           wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
126       AddStep<ci::pkgmgr::StepCheckBlacklist>();
127       AddStep<ci::security::StepCheckSignature>();
128       AddStep<ci::security::StepPrivilegeCompatibility>();
129       AddStep<wgt::security::StepCheckSettingsLevel>();
130       AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
131       AddStep<wgt::security::StepCheckWgtNotificationCategory>();
132       AddStep<wgt::security::StepCheckWgtImePrivilege>();
133       AddStep<ci::security::StepCheckOldCertificate>();
134       AddStep<wgt::encryption::StepEncryptResources>();
135       AddStep<wgt::filesystem::StepWgtResourceDirectory>();
136       AddStep<ci::configuration::StepParseManifest>(
137           ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
138           ci::configuration::StepParseManifest::StoreLocation::BACKUP);
139       AddStep<ci::configuration::StepBlockCrossUpdate>();
140       AddStep<ci::pkgmgr::StepKillApps>();
141       AddStep<ci::backup::StepBackupManifest>();
142       AddStep<ci::backup::StepBackupIcons>();
143       AddStep<ci::backup::StepCopyBackup>();
144       AddStep<ci::filesystem::StepCopyTep>();
145       AddStep<ci::pkgmgr::StepUpdateTep>();
146       AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
147       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
148       AddStep<wgt::filesystem::StepWgtPatchIcons>();
149       AddStep<ci::filesystem::StepCreateIcons>();
150       AddStep<ci::filesystem::StepCopyStorageDirectories>();
151       AddStep<ci::security::StepUpdateSecurity>();
152       AddStep<wgt::pkgmgr::StepGenerateXml>();
153       AddStep<ci::pkgmgr::StepRunParserPlugin>(
154           ci::Plugin::ActionType::Upgrade);
155       AddStep<ci::pkgmgr::StepUpdateApplication>();
156       break;
157     }
158     case ci::RequestType::Uninstall: {
159       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
160       AddStep<ci::pkgmgr::StepCheckRemovable>();
161       AddStep<ci::configuration::StepParseManifest>(
162           ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
163           ci::configuration::StepParseManifest::StoreLocation::NORMAL);
164       AddStep<ci::pkgmgr::StepKillApps>();
165       AddStep<ci::pkgmgr::StepRunParserPlugin>(
166           ci::Plugin::ActionType::Uninstall);
167       AddStep<ci::filesystem::StepRemovePerUserStorageDirectories>();
168       AddStep<ci::pkgmgr::StepUnregisterApplication>();
169       AddStep<ci::security::StepRollbackDeinstallationSecurity>();
170       AddStep<ci::filesystem::StepRemoveFiles>();
171       AddStep<ci::filesystem::StepRemoveZipImage>();
172       AddStep<ci::filesystem::StepRemoveIcons>();
173       AddStep<wgt::encryption::StepRemoveEncryptionData>();
174       AddStep<ci::security::StepRevokeSecurity>();
175       AddStep<ci::pkgmgr::StepRemoveManifest>();
176       break;
177     }
178     case ci::RequestType::Reinstall: {
179       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
180       AddStep<wgt::configuration::StepParse>(
181           wgt::configuration::StepParse::ConfigLocation::PACKAGE, false);
182       AddStep<ci::pkgmgr::StepKillApps>();
183       AddStep<ci::configuration::StepParseManifest>(
184           ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
185           ci::configuration::StepParseManifest::StoreLocation::BACKUP);
186       AddStep<ci::configuration::StepBlockCrossUpdate>();
187       AddStep<ci::pkgmgr::StepCheckBlacklist>();
188       AddStep<ci::rds::StepRDSParse>();
189       AddStep<wgt::rds::StepWgtRDSModify>();
190       AddStep<ci::security::StepUpdateSecurity>();
191       break;
192     }
193     case ci::RequestType::Delta: {
194       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
195       AddStep<ci::filesystem::StepUnzip>();
196       // TODO(t.iwanek): manifest is parsed twice...
197       AddStep<wgt::configuration::StepParse>(
198             wgt::configuration::StepParse::ConfigLocation::PACKAGE, false);
199       // start file may not have changed
200       AddStep<ci::configuration::StepParseManifest>(
201           ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
202           ci::configuration::StepParseManifest::StoreLocation::BACKUP);
203       AddStep<ci::filesystem::StepDeltaPatch>("res/wgt/");
204       AddStep<wgt::configuration::StepParse>(
205           wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
206       AddStep<ci::pkgmgr::StepCheckBlacklist>();
207       AddStep<ci::security::StepCheckSignature>();
208       AddStep<ci::security::StepPrivilegeCompatibility>();
209       AddStep<wgt::security::StepCheckSettingsLevel>();
210       AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
211       AddStep<wgt::security::StepCheckWgtNotificationCategory>();
212       AddStep<wgt::security::StepCheckWgtImePrivilege>();
213       AddStep<ci::security::StepCheckOldCertificate>();
214       AddStep<wgt::encryption::StepEncryptResources>();
215       AddStep<wgt::filesystem::StepWgtResourceDirectory>();
216       AddStep<ci::configuration::StepBlockCrossUpdate>();
217       AddStep<ci::pkgmgr::StepKillApps>();
218       AddStep<ci::backup::StepBackupManifest>();
219       AddStep<ci::backup::StepBackupIcons>();
220       AddStep<ci::backup::StepCopyBackup>();
221       AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
222       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
223       AddStep<wgt::filesystem::StepWgtPatchIcons>();
224       AddStep<ci::filesystem::StepCreateIcons>();
225       AddStep<ci::filesystem::StepCopyStorageDirectories>();
226       AddStep<ci::security::StepUpdateSecurity>();
227       AddStep<wgt::pkgmgr::StepGenerateXml>();
228       AddStep<ci::pkgmgr::StepRunParserPlugin>(
229           ci::Plugin::ActionType::Upgrade);
230       AddStep<ci::pkgmgr::StepUpdateApplication>();
231       break;
232     }
233     case ci::RequestType::Recovery: {
234       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
235       AddStep<ci::recovery::StepOpenRecoveryFile>();
236       AddStep<wgt::configuration::StepParseRecovery>();
237       AddStep<ci::pkgmgr::StepRecoverApplication>();
238       AddStep<ci::filesystem::StepRemoveTemporaryDirectory>();
239       AddStep<ci::filesystem::StepRecoverIcons>();
240       AddStep<ci::filesystem::StepRecoverManifest>();
241       AddStep<ci::filesystem::StepRecoverStorageDirectories>();
242       AddStep<ci::filesystem::StepRecoverFiles>();
243       AddStep<ci::security::StepRecoverSecurity>();
244       break;
245     }
246     case ci::RequestType::Clear: {
247       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
248       AddStep<ci::filesystem::StepClearData>();
249       break;
250     }
251     case ci::RequestType::MountInstall: {
252       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
253       AddStep<ci::mount::StepMountUnpacked>();
254       AddStep<wgt::configuration::StepParse>(
255           wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
256       AddStep<ci::pkgmgr::StepCheckBlacklist>();
257       AddStep<ci::security::StepCheckSignature>();
258       AddStep<ci::security::StepPrivilegeCompatibility>();
259       AddStep<wgt::security::StepCheckSettingsLevel>();
260       AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
261       AddStep<wgt::security::StepCheckWgtNotificationCategory>();
262       AddStep<wgt::security::StepCheckWgtImePrivilege>();
263       AddStep<wgt::encryption::StepEncryptResources>();
264       AddStep<ci::security::StepRollbackInstallationSecurity>();
265       AddStep<ci::mount::StepMountInstall>();
266       AddStep<wgt::filesystem::StepWgtPreparePackageDirectory>();
267       AddStep<ci::filesystem::StepCopyTep>();
268       AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
269       AddStep<ci::filesystem::StepCreateStorageDirectories>();
270       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
271       AddStep<wgt::filesystem::StepWgtPatchIcons>();
272       AddStep<ci::filesystem::StepCreateIcons>();
273       AddStep<wgt::pkgmgr::StepGenerateXml>();
274       AddStep<ci::pkgmgr::StepRegisterApplication>();
275       AddStep<ci::pkgmgr::StepRunParserPlugin>(
276           ci::Plugin::ActionType::Install);
277       AddStep<ci::filesystem::StepCreatePerUserStorageDirectories>();
278       AddStep<ci::security::StepRegisterSecurity>();
279       break;
280     }
281     case ci::RequestType::MountUpdate: {
282       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
283       AddStep<ci::mount::StepMountUnpacked>();
284       AddStep<wgt::configuration::StepParse>(
285           wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
286       AddStep<ci::pkgmgr::StepCheckBlacklist>();
287       AddStep<ci::security::StepCheckSignature>();
288       AddStep<ci::security::StepPrivilegeCompatibility>();
289       AddStep<wgt::security::StepCheckSettingsLevel>();
290       AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
291       AddStep<wgt::security::StepCheckWgtNotificationCategory>();
292       AddStep<wgt::security::StepCheckWgtImePrivilege>();
293       AddStep<ci::security::StepCheckOldCertificate>();
294       AddStep<ci::configuration::StepParseManifest>(
295           ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
296           ci::configuration::StepParseManifest::StoreLocation::BACKUP);
297       AddStep<ci::configuration::StepBlockCrossUpdate>();
298       AddStep<ci::pkgmgr::StepKillApps>();
299       AddStep<ci::backup::StepBackupManifest>();
300       AddStep<ci::backup::StepBackupIcons>();
301       AddStep<ci::mount::StepMountUpdate>();
302       AddStep<wgt::filesystem::StepWgtUpdatePackageDirectory>();
303       AddStep<ci::filesystem::StepCopyTep>();
304       AddStep<ci::pkgmgr::StepUpdateTep>();
305       AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
306       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
307       AddStep<wgt::filesystem::StepWgtPatchIcons>();
308       AddStep<ci::filesystem::StepCreateIcons>();
309       AddStep<ci::security::StepUpdateSecurity>();
310       AddStep<wgt::pkgmgr::StepGenerateXml>();
311       AddStep<ci::pkgmgr::StepRunParserPlugin>(
312           ci::Plugin::ActionType::Upgrade);
313       AddStep<ci::pkgmgr::StepUpdateApplication>();
314       break;
315     }
316     case ci::RequestType::ManifestDirectInstall: {
317       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
318       AddStep<wgt::configuration::StepParse>(
319           wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
320       AddStep<ci::pkgmgr::StepCheckBlacklist>();
321       AddStep<wgt::security::StepDirectManifestCheckSignature>();
322       AddStep<ci::security::StepPrivilegeCompatibility>();
323       AddStep<wgt::security::StepCheckWgtNotificationCategory>();
324       AddStep<wgt::security::StepCheckWgtImePrivilege>();
325       AddStep<wgt::security::StepCheckSettingsLevel>();
326       AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
327       AddStep<ci::security::StepRollbackInstallationSecurity>();
328       AddStep<wgt::pkgmgr::StepGenerateXml>();
329       AddStep<ci::pkgmgr::StepRegisterApplication>();
330       AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Install);
331       AddStep<ci::security::StepRegisterSecurity>();
332       break;
333     }
334     case ci::RequestType::ManifestDirectUpdate: {
335       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
336       AddStep<wgt::configuration::StepParse>(
337           wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
338       AddStep<ci::pkgmgr::StepCheckBlacklist>();
339       AddStep<wgt::security::StepDirectManifestCheckSignature>();
340       AddStep<ci::security::StepPrivilegeCompatibility>();
341       AddStep<wgt::security::StepCheckWgtNotificationCategory>();
342       AddStep<wgt::security::StepCheckWgtImePrivilege>();
343       AddStep<wgt::security::StepCheckSettingsLevel>();
344       AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
345       AddStep<ci::configuration::StepParseManifest>(
346           ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
347           ci::configuration::StepParseManifest::StoreLocation::BACKUP);
348       AddStep<ci::pkgmgr::StepKillApps>();
349       AddStep<ci::filesystem::StepCopyTep>();
350       AddStep<ci::security::StepUpdateSecurity>();
351       AddStep<wgt::pkgmgr::StepGenerateXml>();
352       AddStep<ci::pkgmgr::StepRunParserPlugin>(
353           ci::Plugin::ActionType::Upgrade);
354       AddStep<ci::pkgmgr::StepUpdateApplication>();
355       break;
356     }
357     default: {
358       AddStep<ci::configuration::StepFail>();
359     }
360   }
361 }
362
363 }  // namespace wgt