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