Implement hybrid webapplication installation
[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 <manifest_handlers/widget_config_parser.h>
8
9 #include <common/pkgmgr_interface.h>
10 #include <common/step/step_configure.h>
11 #include <common/step/step_backup_manifest.h>
12 #include <common/step/step_copy.h>
13 #include <common/step/step_copy_backup.h>
14 #include <common/step/step_copy_storage_directories.h>
15 #include <common/step/step_delta_patch.h>
16 #include <common/step/step_fail.h>
17 #include <common/step/step_kill_apps.h>
18 #include <common/step/step_open_recovery_file.h>
19 #include <common/step/step_parse.h>
20 #include <common/step/step_privilege_compatibility.h>
21 #include <common/step/step_register_app.h>
22 #include <common/step/step_recover_application.h>
23 #include <common/step/step_recover_files.h>
24 #include <common/step/step_recover_manifest.h>
25 #include <common/step/step_recover_security.h>
26 #include <common/step/step_recover_storage_directories.h>
27 #include <common/step/step_remove_icons.h>
28 #include <common/step/step_remove_files.h>
29 #include <common/step/step_remove_temporary_directory.h>
30 #include <common/step/step_revoke_security.h>
31 #include <common/step/step_register_security.h>
32 #include <common/step/step_rollback_deinstallation_security.h>
33 #include <common/step/step_rollback_installation_security.h>
34 #include <common/step/step_old_manifest.h>
35 #include <common/step/step_check_signature.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 #include <common/step/step_check_old_certificate.h>
41
42 #include "wgt/step/step_add_default_privileges.h"
43 #include "wgt/step/step_check_settings_level.h"
44 #include "wgt/step/step_check_wgt_background_category.h"
45 #include "wgt/step/step_create_symbolic_link.h"
46 #include "wgt/step/step_encrypt_resources.h"
47 #include "wgt/step/step_generate_xml.h"
48 #include "wgt/step/step_parse.h"
49 #include "wgt/step/step_parse_recovery.h"
50 #include "wgt/step/step_rds_modify.h"
51 #include "wgt/step/step_rds_parse.h"
52 #include "wgt/step/step_remove_encryption_data.h"
53 #include "wgt/step/step_wgt_backup_icons.h"
54 #include "wgt/step/step_wgt_copy_storage_directories.h"
55 #include "wgt/step/step_wgt_create_icons.h"
56 #include "wgt/step/step_wgt_create_storage_directories.h"
57 #include "wgt/step/step_wgt_recover_icons.h"
58 #include "wgt/step/step_wgt_resource_directory.h"
59
60 namespace ci = common_installer;
61
62 namespace wgt {
63
64 WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr)
65     : AppInstaller("wgt", pkgrmgr) {
66   context_->backend_data.set(new WgtBackendData());
67
68   /* treat the request */
69   switch (pkgmgr_->GetRequestType()) {
70     case ci::RequestType::Install : {
71       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
72       AddStep<ci::filesystem::StepUnzip>();
73       AddStep<wgt::parse::StepParse>(true);
74       AddStep<ci::security::StepCheckSignature>();
75       AddStep<ci::security::StepPrivilegeCompatibility>();
76       AddStep<wgt::security::StepCheckSettingsLevel>();
77       AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
78       AddStep<wgt::encrypt::StepEncryptResources>();
79       AddStep<wgt::filesystem::StepWgtResourceDirectory>();
80       AddStep<ci::security::StepRollbackInstallationSecurity>();
81       AddStep<ci::filesystem::StepCopy>();
82       AddStep<wgt::filesystem::StepWgtCreateStorageDirectories>();
83       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
84       AddStep<wgt::filesystem::StepWgtCreateIcons>();
85       AddStep<wgt::pkgmgr::StepGenerateXml>();
86       AddStep<ci::pkgmgr::StepRegisterApplication>();
87       AddStep<ci::security::StepRegisterSecurity>();
88       break;
89     }
90     case ci::RequestType::Update: {
91       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
92       AddStep<ci::filesystem::StepUnzip>();
93       AddStep<wgt::parse::StepParse>(true);
94       AddStep<ci::security::StepCheckSignature>();
95       AddStep<ci::security::StepPrivilegeCompatibility>();
96       AddStep<wgt::security::StepCheckSettingsLevel>();
97       AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
98       AddStep<ci::security::StepCheckOldCertificate>();
99       AddStep<wgt::filesystem::StepWgtResourceDirectory>();
100       AddStep<ci::backup::StepOldManifest>();
101       AddStep<ci::pkgmgr::StepKillApps>();
102       AddStep<ci::backup::StepBackupManifest>();
103       AddStep<wgt::backup::StepWgtBackupIcons>();
104       AddStep<ci::backup::StepCopyBackup>();
105       AddStep<wgt::filesystem::StepWgtCopyStorageDirectories>();
106       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
107       AddStep<wgt::filesystem::StepWgtCreateIcons>();
108       AddStep<ci::security::StepUpdateSecurity>();
109       AddStep<wgt::pkgmgr::StepGenerateXml>();
110       AddStep<ci::pkgmgr::StepUpdateApplication>();
111       break;
112     }
113     case ci::RequestType::Uninstall: {
114       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
115       AddStep<ci::parse::StepParse>();
116       AddStep<ci::pkgmgr::StepKillApps>();
117       AddStep<ci::backup::StepBackupManifest>();
118       AddStep<ci::pkgmgr::StepUnregisterApplication>();
119       AddStep<ci::security::StepRollbackDeinstallationSecurity>();
120       AddStep<ci::filesystem::StepRemoveFiles>();
121       AddStep<ci::filesystem::StepRemoveIcons>();
122       AddStep<wgt::encrypt::StepRemoveEncryptionData>();
123       AddStep<ci::security::StepRevokeSecurity>();
124       break;
125     }
126     case ci::RequestType::Reinstall: {
127       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
128       AddStep<wgt::parse::StepParse>(false);
129       AddStep<ci::pkgmgr::StepKillApps>();
130       AddStep<ci::backup::StepOldManifest>();
131       AddStep<wgt::rds::StepRDSParse>();
132       AddStep<wgt::rds::StepRDSModify>();
133       AddStep<ci::security::StepUpdateSecurity>();
134       break;
135     }
136     case ci::RequestType::Delta: {
137       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
138       AddStep<ci::filesystem::StepUnzip>();
139       // TODO(t.iwanek): manifest is parsed twice...
140       AddStep<wgt::parse::StepParse>(false);  // start file may not have changed
141       AddStep<ci::filesystem::StepDeltaPatch>("res/wgt/");
142       AddStep<wgt::parse::StepParse>(true);
143       AddStep<ci::security::StepCheckSignature>();
144       AddStep<ci::security::StepPrivilegeCompatibility>();
145       AddStep<wgt::security::StepCheckSettingsLevel>();
146       AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
147       AddStep<ci::security::StepCheckOldCertificate>();
148       AddStep<wgt::filesystem::StepWgtResourceDirectory>();
149       AddStep<ci::backup::StepOldManifest>();
150       AddStep<ci::pkgmgr::StepKillApps>();
151       AddStep<ci::backup::StepBackupManifest>();
152       AddStep<wgt::backup::StepWgtBackupIcons>();
153       AddStep<ci::backup::StepCopyBackup>();
154       AddStep<wgt::filesystem::StepWgtCopyStorageDirectories>();
155       AddStep<wgt::filesystem::StepCreateSymbolicLink>();
156       AddStep<wgt::filesystem::StepWgtCreateIcons>();
157       AddStep<ci::security::StepUpdateSecurity>();
158       AddStep<wgt::pkgmgr::StepGenerateXml>();
159       AddStep<ci::pkgmgr::StepUpdateApplication>();
160       break;
161     }
162     case ci::RequestType::Recovery: {
163       AddStep<ci::configuration::StepConfigure>(pkgmgr_);
164       AddStep<ci::recovery::StepOpenRecoveryFile>();
165       AddStep<wgt::parse::StepParseRecovery>();
166       AddStep<ci::pkgmgr::StepRecoverApplication>();
167       AddStep<ci::filesystem::StepRemoveTemporaryDirectory>();
168       AddStep<wgt::filesystem::StepWgtRecoverIcons>();
169       AddStep<ci::filesystem::StepRecoverManifest>();
170       AddStep<ci::filesystem::StepRecoverStorageDirectories>();
171       AddStep<ci::filesystem::StepRecoverFiles>();
172       AddStep<ci::security::StepRecoverSecurity>();
173       break;
174     }
175     default: {
176       AddStep<ci::configuration::StepFail>();
177     }
178   }
179 }
180
181 }  // namespace wgt