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.
5 #include "wgt/wgt_installer.h"
7 #include <common/pkgmgr_interface.h>
9 #include <common/privileges.h>
10 #include <common/step/filesystem/step_create_storage_directories.h>
11 #include <common/step/filesystem/step_delta_patch.h>
12 #include <common/step/security/step_privilege_compatibility.h>
13 #include <common/step/security/step_recover_privilege_compatibility.h>
15 #include <wgt_manifest_handlers/widget_config_parser.h>
17 #include "wgt/shared_dirs.h"
18 #include "wgt/step/configuration/step_check_rds_manifest.h"
19 #include "wgt/step/configuration/step_check_start_files.h"
20 #include "wgt/step/configuration/step_parse.h"
21 #include "wgt/step/configuration/step_set_old_signature_files_location.h"
22 #include "wgt/step/encryption/step_encrypt_resources.h"
23 #include "wgt/step/encryption/step_remove_encryption_data.h"
24 #include "wgt/step/filesystem/step_copy_preview_icons.h"
25 #include "wgt/step/filesystem/step_create_wgt_symbolic_link.h"
26 #include "wgt/step/filesystem/step_wgt_patch_icons.h"
27 #include "wgt/step/filesystem/step_wgt_patch_storage_directories.h"
28 #include "wgt/step/filesystem/step_wgt_prepare_package_directory.h"
29 #include "wgt/step/filesystem/step_wgt_resource_directory.h"
30 #include "wgt/step/filesystem/step_wgt_undo_patch_storage_directories.h"
31 #include "wgt/step/filesystem/step_wgt_update_package_directory.h"
32 #include "wgt/step/pkgmgr/step_generate_xml.h"
33 #include "wgt/step/security/step_add_default_privileges.h"
34 #include "wgt/step/security/step_check_settings_level.h"
35 #include "wgt/step/security/step_check_wgt_background_category.h"
36 #include "wgt/step/security/step_check_wgt_notification_category.h"
37 #include "wgt/step/security/step_check_wgt_ime_privilege.h"
38 #include "wgt/step/security/step_direct_manifest_signature.h"
39 #include "wgt/step/security/step_check_extension_privileges.h"
40 #include "wgt/step/security/step_wgt_recover_signature.h"
42 namespace ci = common_installer;
46 WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr)
47 : AppInstaller("wgt", pkgrmgr) {
48 context_->backend_data.set(new WgtBackendData());
51 void WgtInstaller::InstallSteps() {
52 AppInstaller::InstallSteps();
53 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
54 wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
55 AddStepAfter<ci::security::StepPrivilegeCompatibility>("Signature",
56 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
57 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
58 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
59 "CheckSettingsLevel");
60 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
61 "CheckWgtBackgroundCategory");
62 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
63 "CheckWgtNotificationCategory");
64 AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
65 AddStepAfter<wgt::filesystem::StepWgtResourceDirectory>("EncryptResources");
66 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
67 AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
68 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>("CopyPreviewIcons");
69 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
70 "CreateWgtSymbolicLink");
71 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
72 ReplaceStep<ci::filesystem::StepCreateStorageDirectories>(
73 "CreateStorageDirectories",
74 wgt::filesystem::WgtAdditionalSharedDirs);
75 AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>(
76 "CreateStorageDirectories");
79 void WgtInstaller::UpdateSteps() {
80 AppInstaller::UpdateSteps();
81 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
82 wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
83 AddStepAfter<ci::security::StepPrivilegeCompatibility>("CheckOldCertificate",
84 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
85 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
86 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
87 "CheckSettingsLevel");
88 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
89 "CheckWgtBackgroundCategory");
90 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
91 "CheckWgtNotificationCategory");
92 AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
93 AddStepAfter<wgt::filesystem::StepWgtResourceDirectory>("EncryptResources");
94 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
95 AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
96 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>("CopyPreviewIcons");
97 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
98 "CreateWgtSymbolicLink");
99 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
100 AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>(
101 "CopyStorageDirectories");
104 void WgtInstaller::UninstallSteps() {
105 AppInstaller::UninstallSteps();
106 AddStepAfter<wgt::encryption::StepRemoveEncryptionData>(
107 "RemovePerUserStorageDirectories");
110 void WgtInstaller::ReinstallSteps() {
111 AppInstaller::ReinstallSteps();
112 AddStepAfter<wgt::configuration::StepCheckRDSManifest>("Configure");
113 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
114 wgt::configuration::StepParse::ConfigLocation::RESOURCE_WGT, false);
115 // Unlike reinstall mode (RDS) of tpk-backend, the RDS package of wgt does not
116 // contain signature files. This may can be changed differently later.
117 RemoveStep("Signature");
118 RemoveStep("CheckOldCertificate");
119 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>("CreateIcons");
122 void WgtInstaller::DeltaSteps() {
123 AppInstaller::DeltaSteps();
124 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
125 wgt::configuration::StepParse::ConfigLocation::PACKAGE, false);
126 AddStepAfter<wgt::filesystem::StepWgtUndoPatchStorageDirectories>(
127 "EnableExternalMount");
128 ReplaceStep<ci::filesystem::StepDeltaPatch>("DeltaPatch", "res/wgt/");
129 AddStepAfter<wgt::configuration::StepCheckStartFiles>("DisableExternalMount");
130 AddStepAfter<ci::security::StepPrivilegeCompatibility>("CheckOldCertificate",
131 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
132 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
133 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
134 "CheckSettingsLevel");
135 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
136 "CheckWgtBackgroundCategory");
137 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
138 "CheckWgtNotificationCategory");
139 AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
140 AddStepAfter<wgt::filesystem::StepWgtResourceDirectory>("EncryptResources");
141 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
142 AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
143 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>("CopyPreviewIcons");
144 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
145 "CreateWgtSymbolicLink");
146 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
147 AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>(
148 "CopyStorageDirectories");
151 void WgtInstaller::RecoverySteps() {
152 AppInstaller::RecoverySteps();
153 AddStepAfter<wgt::security::StepWgtRecoverSignature>("MountRecover");
154 AddStepAfter<ci::security::StepRecoverPrivilegeCompatibility>(
155 "WgtRecoverSignature",
156 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
159 void WgtInstaller::MountInstallSteps() {
160 AppInstaller::MountInstallSteps();
161 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
162 wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
163 AddStepAfter<ci::security::StepPrivilegeCompatibility>("Signature",
164 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
165 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
166 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
167 "CheckSettingsLevel");
168 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
169 "CheckWgtBackgroundCategory");
170 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
171 "CheckWgtNotificationCategory");
172 AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
173 AddStepAfter<wgt::filesystem::StepWgtPreparePackageDirectory>("MountInstall");
174 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
175 AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
176 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
178 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
179 "CreateWgtSymbolicLink");
180 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
181 ReplaceStep<ci::filesystem::StepCreateStorageDirectories>(
182 "CreateStorageDirectories",
183 wgt::filesystem::WgtAdditionalSharedDirs);
184 AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>(
185 "CreateStorageDirectories");
188 void WgtInstaller::MountUpdateSteps() {
189 AppInstaller::MountUpdateSteps();
190 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
191 wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
192 AddStepAfter<ci::security::StepPrivilegeCompatibility>("CheckOldCertificate",
193 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
194 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
195 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
196 "CheckSettingsLevel");
197 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
198 "CheckWgtBackgroundCategory");
199 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
200 "CheckWgtNotificationCategory");
201 AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
202 AddStepAfter<wgt::filesystem::StepWgtUpdatePackageDirectory>("MountUpdate");
203 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
204 AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
205 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
207 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
208 "CreateWgtSymbolicLink");
209 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
210 AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>(
211 "UpdateStorageDirectories");
214 void WgtInstaller::ManifestDirectInstallSteps() {
215 AppInstaller::ManifestDirectInstallSteps();
216 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
217 wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
218 ReplaceStep<wgt::security::StepDirectManifestSignature>("Signature", true);
219 AddStepAfter<ci::security::StepPrivilegeCompatibility>(
220 "DirectManifestSignature",
221 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
222 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
223 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
224 "CheckSettingsLevel");
225 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
226 "CheckWgtBackgroundCategory");
227 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
228 "CheckWgtNotificationCategory");
229 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("RemoveGlobalAppSymlinks",
231 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
233 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CreateWgtSymbolicLink");
234 ReplaceStep<ci::filesystem::StepCreateStorageDirectories>(
235 "CreateStorageDirectories",
236 wgt::filesystem::WgtAdditionalSharedDirs);
239 void WgtInstaller::ManifestDirectUpdateSteps() {
240 AppInstaller::ManifestDirectUpdateSteps();
241 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
242 wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
243 ReplaceStep<wgt::security::StepDirectManifestSignature>("Signature", true);
244 AddStepAfter<ci::security::StepPrivilegeCompatibility>(
245 "CheckOldCertificate",
246 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
247 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
248 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
249 "CheckSettingsLevel");
250 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
251 "CheckWgtBackgroundCategory");
252 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
253 "CheckWgtNotificationCategory");
254 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("RemoveGlobalAppSymlinks",
256 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
258 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CreateWgtSymbolicLink");
261 void WgtInstaller::ReadonlyUpdateInstallSteps() {
262 AppInstaller::ReadonlyUpdateInstallSteps();
263 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
264 wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
265 AddStepAfter<ci::security::StepPrivilegeCompatibility>("CheckOldCertificate",
266 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
267 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
268 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
269 "CheckSettingsLevel");
270 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
271 "CheckWgtBackgroundCategory");
272 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
273 "CheckWgtNotificationCategory");
274 AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
275 AddStepAfter<wgt::filesystem::StepWgtResourceDirectory>("EncryptResources");
276 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
277 AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
278 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
280 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
281 "CreateWgtSymbolicLink");
282 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
283 AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>(
284 "CreateStorageDirectories");
287 void WgtInstaller::ReadonlyUpdateUninstallSteps() {
288 AppInstaller::ReadonlyUpdateUninstallSteps();
289 AddStepBefore<wgt::configuration::StepSetOldSignatureFilesLocation>(
291 AddStepAfter<ci::security::StepPrivilegeCompatibility>("Signature",
292 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
293 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
294 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
295 "CheckSettingsLevel");
296 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
297 "CheckWgtBackgroundCategory");
298 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
299 "CheckWgtNotificationCategory");
302 void WgtInstaller::ManifestPartialInstallSteps() {
303 AppInstaller::ManifestPartialInstallSteps();
304 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
305 wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
306 ReplaceStep<wgt::security::StepDirectManifestSignature>("Signature", false);
307 AddStepAfter<ci::security::StepPrivilegeCompatibility>(
308 "DirectManifestSignature",
309 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
310 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
311 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
312 "CheckSettingsLevel");
313 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
314 "CheckWgtBackgroundCategory");
315 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
316 "CheckWgtNotificationCategory");
317 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("RemoveGlobalAppSymlinks",
319 ReplaceStep<ci::filesystem::StepCreateStorageDirectories>(
320 "CreateStorageDirectories",
321 wgt::filesystem::WgtAdditionalSharedDirs);
324 void WgtInstaller::ManifestPartialUpdateSteps() {
325 AppInstaller::ManifestPartialUpdateSteps();
326 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
327 wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
328 ReplaceStep<wgt::security::StepDirectManifestSignature>("Signature", false);
329 AddStepAfter<ci::security::StepPrivilegeCompatibility>(
330 "CheckOldCertificate",
331 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
332 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
333 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
334 "CheckSettingsLevel");
335 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
336 "CheckWgtBackgroundCategory");
337 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
338 "CheckWgtNotificationCategory");
339 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("RemoveGlobalAppSymlinks",
343 void WgtInstaller::PartialUninstallSteps() {
344 AppInstaller::PartialUninstallSteps();
345 AddStepAfter<wgt::encryption::StepRemoveEncryptionData>(
346 "RemovePerUserStorageDirectories");
349 void WgtInstaller::MoveSteps() {
350 AppInstaller::MoveSteps();
353 void WgtInstaller::EnablePkgSteps() {
354 AppInstaller::EnablePkgSteps();
357 void WgtInstaller::DisablePkgSteps() {
358 AppInstaller::DisablePkgSteps();
361 void WgtInstaller::MigrateExtImgSteps() {
362 AppInstaller::MigrateExtImgSteps();
365 void WgtInstaller::RecoverDBSteps() {
366 AppInstaller::RecoverDBSteps();
367 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
368 wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
369 AddStepAfter<ci::security::StepPrivilegeCompatibility>("GetPrivilegeLevel",
370 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
371 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
372 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
373 "CheckSettingsLevel");
374 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
375 "CheckWgtBackgroundCategory");
376 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
377 "CheckWgtNotificationCategory");