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