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