Recovery mode for hybrid application
[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/step_check_signature.h>
8 #include <common/step/step_backup_icons.h>
9 #include <common/step/step_backup_manifest.h>
10 #include <common/step/step_configure.h>
11 #include <common/step/step_copy.h>
12 #include <common/step/step_copy_backup.h>
13 #include <common/step/step_copy_storage_directories.h>
14 #include <common/step/step_create_icons.h>
15 #include <common/step/step_create_storage_directories.h>
16 #include <common/step/step_delta_patch.h>
17 #include <common/step/step_fail.h>
18 #include <common/step/step_kill_apps.h>
19 #include <common/step/step_parse_manifest.h>
20 #include <common/step/step_privilege_compatibility.h>
21 #include <common/step/step_register_app.h>
22 #include <common/step/step_register_security.h>
23 #include <common/step/step_remove_files.h>
24 #include <common/step/step_remove_icons.h>
25 #include <common/step/step_revoke_security.h>
26 #include <common/step/step_open_recovery_file.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_temporary_directory.h>
34 #include <common/step/step_rollback_deinstallation_security.h>
35 #include <common/step/step_rollback_installation_security.h>
36 #include <common/step/step_unregister_app.h>
37 #include <common/step/step_unzip.h>
38 #include <common/step/step_update_app.h>
39 #include <common/step/step_update_security.h>
40
41 #include <tpk/step/step_create_symbolic_link.h>
42 #include <tpk/step/step_tpk_patch_icons.h>
43
44 #include "hybrid/hybrid_backend_data.h"
45 #include "hybrid/step/step_encrypt_resources.h"
46 #include "hybrid/step/step_merge_tpk_config.h"
47 #include "hybrid/step/step_stash_tpk_config.h"
48 #include "hybrid/step/step_parse.h"
49 #include "wgt/step/step_check_settings_level.h"
50 #include "wgt/step/step_check_wgt_background_category.h"
51 #include "wgt/step/step_create_symbolic_link.h"
52 #include "wgt/step/step_generate_xml.h"
53 #include "wgt/step/step_parse_recovery.h"
54 #include "wgt/step/step_remove_encryption_data.h"
55 #include "wgt/step/step_wgt_patch_icons.h"
56 #include "wgt/step/step_wgt_patch_storage_directories.h"
57
58 namespace ci = common_installer;
59
60 namespace hybrid {
61
62 HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr)
63     : AppInstaller("wgt", pkgmgr) {
64   context_->backend_data.set(new HybridBackendData());
65
66   switch (pkgmgr_->GetRequestType()) {
67     case ci::RequestType::Install:
68       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
69       AddStep<ci::filesystem::StepUnzip>();
70       AddStep<ci::parse::StepParseManifest>(
71           ci::parse::StepParseManifest::ManifestLocation::PACKAGE,
72           ci::parse::StepParseManifest::StoreLocation::NORMAL);
73       AddStep<hybrid::parse::StepStashTpkConfig>();
74       AddStep<hybrid::parse::StepParse>(true);
75       AddStep<hybrid::parse::StepMergeTpkConfig>();
76       AddStep<ci::security::StepCheckSignature>();
77       AddStep<ci::security::StepPrivilegeCompatibility>();
78       AddStep<wgt::security::StepCheckSettingsLevel>();
79       AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
80       AddStep<hybrid::encrypt::StepEncryptResources>();
81       AddStep<ci::security::StepRollbackInstallationSecurity>();
82       AddStep<ci::filesystem::StepCopy>();
83       AddStep<tpk::filesystem::StepTpkPatchIcons>();
84       AddStep<wgt::filesystem::StepWgtPatchIcons>();
85       AddStep<ci::filesystem::StepCreateIcons>();
86       AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
87       AddStep<ci::filesystem::StepCreateStorageDirectories>();
88       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
89       AddStep<tpk::filesystem::StepCreateSymbolicLink>();
90       AddStep<wgt::pkgmgr::StepGenerateXml>();
91       AddStep<ci::pkgmgr::StepRegisterApplication>();
92       AddStep<ci::security::StepRegisterSecurity>();
93       break;
94     case ci::RequestType::Update:
95       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
96       AddStep<ci::filesystem::StepUnzip>();
97       AddStep<ci::parse::StepParseManifest>(
98           ci::parse::StepParseManifest::ManifestLocation::PACKAGE,
99           ci::parse::StepParseManifest::StoreLocation::NORMAL);
100       AddStep<hybrid::parse::StepStashTpkConfig>();
101       AddStep<hybrid::parse::StepParse>(true);
102       AddStep<hybrid::parse::StepMergeTpkConfig>();
103       AddStep<ci::security::StepCheckSignature>();
104       AddStep<ci::security::StepPrivilegeCompatibility>();
105       AddStep<wgt::security::StepCheckSettingsLevel>();
106       AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
107       AddStep<hybrid::encrypt::StepEncryptResources>();
108       AddStep<ci::security::StepRollbackInstallationSecurity>();
109       AddStep<ci::parse::StepParseManifest>(
110           ci::parse::StepParseManifest::ManifestLocation::INSTALLED,
111           ci::parse::StepParseManifest::StoreLocation::BACKUP);
112       AddStep<ci::pkgmgr::StepKillApps>();
113       AddStep<ci::backup::StepBackupManifest>();
114       AddStep<ci::backup::StepBackupIcons>();
115       AddStep<ci::backup::StepCopyBackup>();
116       AddStep<tpk::filesystem::StepTpkPatchIcons>();
117       AddStep<wgt::filesystem::StepWgtPatchIcons>();
118       AddStep<ci::filesystem::StepCreateIcons>();
119       AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
120       AddStep<ci::filesystem::StepCopyStorageDirectories>();
121       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
122       AddStep<tpk::filesystem::StepCreateSymbolicLink>();
123       AddStep<ci::security::StepUpdateSecurity>();
124       AddStep<wgt::pkgmgr::StepGenerateXml>();
125       AddStep<ci::pkgmgr::StepUpdateApplication>();
126       break;
127     case ci::RequestType::Uninstall:
128       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
129       // TODO(t.iwanek): this parses both configuration files
130       // tpk and wgt, removing pkgmgr-parser should change this code
131       // that it will still support parsing both files
132       AddStep<ci::parse::StepParseManifest>(
133           ci::parse::StepParseManifest::ManifestLocation::INSTALLED,
134           ci::parse::StepParseManifest::StoreLocation::NORMAL);
135       AddStep<ci::pkgmgr::StepKillApps>();
136       AddStep<ci::backup::StepBackupManifest>();
137       AddStep<ci::pkgmgr::StepUnregisterApplication>();
138       AddStep<ci::security::StepRollbackDeinstallationSecurity>();
139       AddStep<ci::filesystem::StepRemoveFiles>();
140       AddStep<ci::filesystem::StepRemoveIcons>();
141       AddStep<wgt::encrypt::StepRemoveEncryptionData>();
142       AddStep<ci::security::StepRevokeSecurity>();
143       break;
144     case ci::RequestType::Reinstall:
145       // RDS is not supported for hybrid apps
146       AddStep<ci::configuration::StepFail>();
147       break;
148     case ci::RequestType::Delta:
149       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
150       AddStep<ci::filesystem::StepUnzip>();
151       AddStep<ci::parse::StepParseManifest>(
152           ci::parse::StepParseManifest::ManifestLocation::PACKAGE,
153           ci::parse::StepParseManifest::StoreLocation::NORMAL);
154       AddStep<hybrid::parse::StepStashTpkConfig>();
155       // TODO(t.iwanek): manifest is parsed twice...
156       AddStep<hybrid::parse::StepParse>(false);
157       AddStep<hybrid::parse::StepMergeTpkConfig>();
158       AddStep<ci::filesystem::StepDeltaPatch>();
159       AddStep<wgt::parse::StepParse>(true);
160       AddStep<ci::security::StepCheckSignature>();
161       AddStep<ci::security::StepPrivilegeCompatibility>();
162       AddStep<wgt::security::StepCheckSettingsLevel>();
163       AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
164       AddStep<hybrid::encrypt::StepEncryptResources>();
165       AddStep<ci::security::StepRollbackInstallationSecurity>();
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<tpk::filesystem::StepTpkPatchIcons>();
174       AddStep<wgt::filesystem::StepWgtPatchIcons>();
175       AddStep<ci::filesystem::StepCreateIcons>();
176       AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
177       AddStep<ci::filesystem::StepCopyStorageDirectories>();
178       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
179       AddStep<tpk::filesystem::StepCreateSymbolicLink>();
180       AddStep<ci::security::StepUpdateSecurity>();
181       AddStep<wgt::pkgmgr::StepGenerateXml>();
182       AddStep<ci::pkgmgr::StepUpdateApplication>();
183       break;
184     case ci::RequestType::Recovery:
185       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
186       AddStep<ci::recovery::StepOpenRecoveryFile>();
187       AddStep<ci::parse::StepParseManifest>(
188           ci::parse::StepParseManifest::ManifestLocation::RECOVERY,
189           ci::parse::StepParseManifest::StoreLocation::NORMAL);
190       AddStep<hybrid::parse::StepStashTpkConfig>();
191       AddStep<wgt::parse::StepParseRecovery>();
192       AddStep<hybrid::parse::StepMergeTpkConfig>();
193       AddStep<ci::pkgmgr::StepRecoverApplication>();
194       AddStep<ci::filesystem::StepRemoveTemporaryDirectory>();
195       AddStep<ci::filesystem::StepRecoverIcons>();
196       AddStep<ci::filesystem::StepRecoverManifest>();
197       AddStep<ci::filesystem::StepRecoverStorageDirectories>();
198       AddStep<ci::filesystem::StepRecoverFiles>();
199       AddStep<ci::security::StepRecoverSecurity>();
200       break;
201     default:
202       AddStep<ci::configuration::StepFail>();
203       break;
204   }
205 }
206
207 }  // namespace hybrid
208