Rework step/ directory structure
[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_configure.h>
13 #include <common/step/configuration/step_fail.h>
14 #include <common/step/configuration/step_parse_manifest.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_create_icons.h>
19 #include <common/step/filesystem/step_create_per_user_storage_directories.h>
20 #include <common/step/filesystem/step_create_storage_directories.h>
21 #include <common/step/filesystem/step_delta_patch.h>
22 #include <common/step/filesystem/step_recover_files.h>
23 #include <common/step/filesystem/step_recover_icons.h>
24 #include <common/step/filesystem/step_recover_manifest.h>
25 #include <common/step/filesystem/step_recover_storage_directories.h>
26 #include <common/step/filesystem/step_remove_files.h>
27 #include <common/step/filesystem/step_remove_icons.h>
28 #include <common/step/filesystem/step_remove_per_user_storage_directories.h>
29 #include <common/step/filesystem/step_remove_temporary_directory.h>
30 #include <common/step/filesystem/step_unzip.h>
31 #include <common/step/pkgmgr/step_check_blacklist.h>
32 #include <common/step/pkgmgr/step_check_removable.h>
33 #include <common/step/pkgmgr/step_kill_apps.h>
34 #include <common/step/pkgmgr/step_recover_application.h>
35 #include <common/step/pkgmgr/step_register_app.h>
36 #include <common/step/pkgmgr/step_remove_manifest.h>
37 #include <common/step/pkgmgr/step_run_parser_plugins.h>
38 #include <common/step/pkgmgr/step_unregister_app.h>
39 #include <common/step/pkgmgr/step_update_app.h>
40 #include <common/step/recovery/step_open_recovery_file.h>
41 #include <common/step/security/step_check_old_certificate.h>
42 #include <common/step/security/step_check_signature.h>
43 #include <common/step/security/step_privilege_compatibility.h>
44 #include <common/step/security/step_recover_security.h>
45 #include <common/step/security/step_register_security.h>
46 #include <common/step/security/step_revoke_security.h>
47 #include <common/step/security/step_rollback_deinstallation_security.h>
48 #include <common/step/security/step_rollback_installation_security.h>
49 #include <common/step/security/step_update_security.h>
50
51 #include <wgt_manifest_handlers/widget_config_parser.h>
52
53 #include "wgt/step/configuration/step_parse.h"
54 #include "wgt/step/configuration/step_parse_recovery.h"
55 #include "wgt/step/encryption/step_encrypt_resources.h"
56 #include "wgt/step/encryption/step_remove_encryption_data.h"
57 #include "wgt/step/filesystem/step_create_symbolic_link.h"
58 #include "wgt/step/filesystem/step_wgt_patch_icons.h"
59 #include "wgt/step/filesystem/step_wgt_patch_storage_directories.h"
60 #include "wgt/step/filesystem/step_wgt_resource_directory.h"
61 #include "wgt/step/pkgmgr/step_generate_xml.h"
62 #include "wgt/step/rds/step_rds_modify.h"
63 #include "wgt/step/rds/step_rds_parse.h"
64 #include "wgt/step/security/step_add_default_privileges.h"
65 #include "wgt/step/security/step_check_settings_level.h"
66 #include "wgt/step/security/step_check_wgt_background_category.h"
67
68 namespace ci = common_installer;
69
70 namespace wgt {
71
72 WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr)
73     : AppInstaller("wgt", pkgrmgr) {
74   context_->backend_data.set(new WgtBackendData());
75
76   /* treat the request */
77   switch (pkgmgr_->GetRequestType()) {
78     case ci::RequestType::Install : {
79       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
80       AddStep<ci::filesystem::StepUnzip>();
81       AddStep<wgt::configuration::StepParse>(true);
82       AddStep<ci::pkgmgr::StepCheckBlacklist>();
83       AddStep<ci::security::StepCheckSignature>();
84       AddStep<ci::security::StepPrivilegeCompatibility>();
85       AddStep<wgt::security::StepCheckSettingsLevel>();
86       AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
87       AddStep<wgt::encryption::StepEncryptResources>();
88       AddStep<wgt::filesystem::StepWgtResourceDirectory>();
89       AddStep<ci::security::StepRollbackInstallationSecurity>();
90       AddStep<ci::filesystem::StepCopy>();
91       AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
92       AddStep<ci::filesystem::StepCreateStorageDirectories>();
93       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
94       AddStep<wgt::filesystem::StepWgtPatchIcons>();
95       AddStep<ci::filesystem::StepCreateIcons>();
96       AddStep<wgt::pkgmgr::StepGenerateXml>();
97       AddStep<ci::pkgmgr::StepRegisterApplication>();
98       AddStep<ci::pkgmgr::StepRunParserPlugin>(
99           ci::Plugin::ActionType::Install);
100       AddStep<ci::filesystem::StepCreatePerUserStorageDirectories>();
101       AddStep<ci::security::StepRegisterSecurity>();
102       break;
103     }
104     case ci::RequestType::Update: {
105       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
106       AddStep<ci::filesystem::StepUnzip>();
107       AddStep<wgt::configuration::StepParse>(true);
108       AddStep<ci::pkgmgr::StepCheckBlacklist>();
109       AddStep<ci::security::StepCheckSignature>();
110       AddStep<ci::security::StepPrivilegeCompatibility>();
111       AddStep<wgt::security::StepCheckSettingsLevel>();
112       AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
113       AddStep<ci::security::StepCheckOldCertificate>();
114       AddStep<wgt::filesystem::StepWgtResourceDirectory>();
115       AddStep<ci::configuration::StepParseManifest>(
116           ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
117           ci::configuration::StepParseManifest::StoreLocation::BACKUP);
118       AddStep<ci::pkgmgr::StepKillApps>();
119       AddStep<ci::backup::StepBackupManifest>();
120       AddStep<ci::backup::StepBackupIcons>();
121       AddStep<ci::backup::StepCopyBackup>();
122       AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
123       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
124       AddStep<wgt::filesystem::StepWgtPatchIcons>();
125       AddStep<ci::filesystem::StepCreateIcons>();
126       AddStep<ci::filesystem::StepCopyStorageDirectories>();
127       AddStep<ci::security::StepUpdateSecurity>();
128       AddStep<wgt::pkgmgr::StepGenerateXml>();
129       AddStep<ci::pkgmgr::StepRunParserPlugin>(
130           ci::Plugin::ActionType::Upgrade);
131       AddStep<ci::pkgmgr::StepUpdateApplication>();
132       break;
133     }
134     case ci::RequestType::Uninstall: {
135       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
136       AddStep<ci::pkgmgr::StepCheckRemovable>();
137       AddStep<ci::configuration::StepParseManifest>(
138           ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
139           ci::configuration::StepParseManifest::StoreLocation::NORMAL);
140       AddStep<ci::pkgmgr::StepKillApps>();
141       AddStep<ci::pkgmgr::StepRunParserPlugin>(
142           ci::Plugin::ActionType::Uninstall);
143       AddStep<ci::filesystem::StepRemovePerUserStorageDirectories>();
144       AddStep<ci::pkgmgr::StepUnregisterApplication>();
145       AddStep<ci::security::StepRollbackDeinstallationSecurity>();
146       AddStep<ci::filesystem::StepRemoveFiles>();
147       AddStep<ci::filesystem::StepRemoveIcons>();
148       AddStep<wgt::encryption::StepRemoveEncryptionData>();
149       AddStep<ci::security::StepRevokeSecurity>();
150       AddStep<ci::pkgmgr::StepRemoveManifest>();
151       break;
152     }
153     case ci::RequestType::Reinstall: {
154       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
155       AddStep<wgt::configuration::StepParse>(false);
156       AddStep<ci::pkgmgr::StepKillApps>();
157       AddStep<ci::configuration::StepParseManifest>(
158           ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
159           ci::configuration::StepParseManifest::StoreLocation::BACKUP);
160       AddStep<ci::pkgmgr::StepCheckBlacklist>();
161       AddStep<wgt::rds::StepRDSParse>();
162       AddStep<wgt::rds::StepRDSModify>();
163       AddStep<ci::security::StepUpdateSecurity>();
164       break;
165     }
166     case ci::RequestType::Delta: {
167       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
168       AddStep<ci::filesystem::StepUnzip>();
169       // TODO(t.iwanek): manifest is parsed twice...
170       AddStep<wgt::configuration::StepParse>(false);
171       // start file may not have changed
172       AddStep<ci::filesystem::StepDeltaPatch>("res/wgt/");
173       AddStep<wgt::configuration::StepParse>(true);
174       AddStep<ci::pkgmgr::StepCheckBlacklist>();
175       AddStep<ci::security::StepCheckSignature>();
176       AddStep<ci::security::StepPrivilegeCompatibility>();
177       AddStep<wgt::security::StepCheckSettingsLevel>();
178       AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
179       AddStep<ci::security::StepCheckOldCertificate>();
180       AddStep<wgt::filesystem::StepWgtResourceDirectory>();
181       AddStep<ci::configuration::StepParseManifest>(
182           ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
183           ci::configuration::StepParseManifest::StoreLocation::BACKUP);
184       AddStep<ci::pkgmgr::StepKillApps>();
185       AddStep<ci::backup::StepBackupManifest>();
186       AddStep<ci::backup::StepBackupIcons>();
187       AddStep<ci::backup::StepCopyBackup>();
188       AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
189       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
190       AddStep<wgt::filesystem::StepWgtPatchIcons>();
191       AddStep<ci::filesystem::StepCreateIcons>();
192       AddStep<ci::filesystem::StepCopyStorageDirectories>();
193       AddStep<ci::security::StepUpdateSecurity>();
194       AddStep<wgt::pkgmgr::StepGenerateXml>();
195       AddStep<ci::pkgmgr::StepRunParserPlugin>(
196           ci::Plugin::ActionType::Upgrade);
197       AddStep<ci::pkgmgr::StepUpdateApplication>();
198       break;
199     }
200     case ci::RequestType::Recovery: {
201       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
202       AddStep<ci::recovery::StepOpenRecoveryFile>();
203       AddStep<wgt::configuration::StepParseRecovery>();
204       AddStep<ci::pkgmgr::StepRecoverApplication>();
205       AddStep<ci::filesystem::StepRemoveTemporaryDirectory>();
206       AddStep<ci::filesystem::StepRecoverIcons>();
207       AddStep<ci::filesystem::StepRecoverManifest>();
208       AddStep<ci::filesystem::StepRecoverStorageDirectories>();
209       AddStep<ci::filesystem::StepRecoverFiles>();
210       AddStep<ci::security::StepRecoverSecurity>();
211       break;
212     }
213     case ci::RequestType::Clear: {
214       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
215       AddStep<ci::filesystem::StepClearData>();
216       break;
217     }
218     default: {
219       AddStep<ci::configuration::StepFail>();
220     }
221   }
222 }
223
224 }  // namespace wgt