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_icons.h>
11 #include <common/step/filesystem/step_create_storage_directories.h>
12 #include <common/step/filesystem/step_delta_patch.h>
13 #include <common/step/filesystem/step_remove_per_user_storage_directories.h>
14 #include <common/step/security/step_privilege_compatibility.h>
15 #include <common/step/security/step_recover_privilege_compatibility.h>
17 #include <wgt_manifest_handlers/widget_config_parser.h>
19 #include "lib/wgt_archive_info.h"
20 #include "wgt/utils/shared_dirs.h"
21 #include "wgt/step/configuration/step_check_rds_manifest.h"
22 #include "wgt/step/configuration/step_check_start_files.h"
23 #include "wgt/step/configuration/step_parse.h"
24 #include "wgt/step/configuration/step_set_old_signature_files_location.h"
25 #include "wgt/step/encryption/step_encrypt_resources.h"
26 #include "wgt/step/encryption/step_remove_encryption_data.h"
27 #include "wgt/step/filesystem/step_copy_preview_icons.h"
28 #include "wgt/step/filesystem/step_create_wgt_symbolic_link.h"
29 #include "wgt/step/filesystem/step_restore_wgt_symbolic_link.h"
30 #include "wgt/step/filesystem/step_wgt_patch_icons.h"
31 #include "wgt/step/filesystem/step_wgt_patch_storage_directories.h"
32 #include "wgt/step/filesystem/step_wgt_prepare_package_directory.h"
33 #include "wgt/step/filesystem/step_wgt_resource_directory.h"
34 #include "wgt/step/filesystem/step_wgt_undo_patch_storage_directories.h"
35 #include "wgt/step/filesystem/step_wgt_update_package_directory.h"
36 #include "wgt/step/pkgmgr/step_generate_xml.h"
37 #include "wgt/step/security/step_add_default_privileges.h"
38 #include "wgt/step/security/step_check_settings_level.h"
39 #include "wgt/step/security/step_check_wgt_background_category.h"
40 #include "wgt/step/security/step_check_wgt_notification_category.h"
41 #include "wgt/step/security/step_check_wgt_ime_privilege.h"
42 #include "wgt/step/security/step_direct_manifest_signature.h"
43 #include "wgt/step/security/step_check_extension_privileges.h"
44 #include "wgt/step/security/step_wgt_recover_signature.h"
46 namespace ci = common_installer;
50 WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr)
51 : AppInstaller("wgt", pkgrmgr) {
52 context_->backend_data.set(new WgtBackendData());
55 std::unique_ptr<ci::ArchiveInfo> WgtInstaller::GetArchiveInfo() {
56 std::unique_ptr<WgtArchiveInfo> archive_info;
57 archive_info.reset(new WgtArchiveInfo(pkgmgr_->GetRequestInfo(GetIndex())));
61 void WgtInstaller::InstallSteps() {
62 AppInstaller::InstallSteps();
63 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
64 wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
65 AddStepAfter<ci::security::StepPrivilegeCompatibility>("Signature",
66 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
67 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
68 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
69 "CheckSettingsLevel");
70 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
71 "CheckWgtBackgroundCategory");
72 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
73 "CheckWgtNotificationCategory");
74 AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
75 AddStepAfter<wgt::filesystem::StepWgtResourceDirectory>("EncryptResources");
76 RemoveStep("CreateIcons");
77 AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>(
79 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
80 "WgtPatchStorageDirectories");
81 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>(
82 "CreateWgtSymbolicLink", true);
83 AddStepAfter<ci::filesystem::StepCreateIcons>("WgtPatchIcons");
84 AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("CreateIcons");
85 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
87 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
88 ReplaceStep<ci::filesystem::StepCreateStorageDirectories>(
89 "CreateStorageDirectories",
90 wgt::filesystem::WgtAdditionalSharedDirs);
93 void WgtInstaller::UpdateSteps() {
94 AppInstaller::UpdateSteps();
95 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
96 wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
97 AddStepAfter<ci::security::StepPrivilegeCompatibility>("CheckOldCertificate",
98 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
99 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
100 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
101 "CheckSettingsLevel");
102 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
103 "CheckWgtBackgroundCategory");
104 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
105 "CheckWgtNotificationCategory");
106 AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
107 AddStepAfter<wgt::filesystem::StepWgtResourceDirectory>("EncryptResources");
108 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
109 AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
110 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>("CopyPreviewIcons");
111 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
112 "CreateWgtSymbolicLink");
113 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
114 AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>(
115 "CopyStorageDirectories");
118 void WgtInstaller::UninstallSteps() {
119 AppInstaller::UninstallSteps();
120 ReplaceStep<ci::filesystem::StepRemovePerUserStorageDirectories>(
121 "RemovePerUserStorageDirectories",
122 wgt::filesystem::WgtAdditionalSharedDirs);
123 AddStepAfter<wgt::filesystem::StepRestoreWgtSymbolicLink>(
124 "RemovePerUserStorageDirectories");
125 AddStepAfter<wgt::encryption::StepRemoveEncryptionData>(
126 "RemovePerUserStorageDirectories");
129 void WgtInstaller::ReinstallSteps() {
130 AppInstaller::ReinstallSteps();
131 AddStepAfter<wgt::configuration::StepCheckRDSManifest>("Configure");
132 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
133 wgt::configuration::StepParse::ConfigLocation::RESOURCE_WGT, false);
134 // Unlike reinstall mode (RDS) of tpk-backend, the RDS package of wgt does not
135 // contain signature files. This may can be changed differently later.
136 RemoveStep("Signature");
137 RemoveStep("CheckOldCertificate");
138 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>("CreateIcons");
141 void WgtInstaller::DeltaSteps() {
142 AppInstaller::DeltaSteps();
143 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
144 wgt::configuration::StepParse::ConfigLocation::PACKAGE, false);
145 AddStepAfter<wgt::filesystem::StepWgtUndoPatchStorageDirectories>(
146 "EnableExternalMount");
147 ReplaceStep<ci::filesystem::StepDeltaPatch>("DeltaPatch", "res/wgt/");
148 AddStepAfter<wgt::configuration::StepCheckStartFiles>("DisableExternalMount");
149 AddStepAfter<ci::security::StepPrivilegeCompatibility>("CheckOldCertificate",
150 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
151 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
152 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
153 "CheckSettingsLevel");
154 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
155 "CheckWgtBackgroundCategory");
156 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
157 "CheckWgtNotificationCategory");
158 AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
159 AddStepAfter<wgt::filesystem::StepWgtResourceDirectory>("EncryptResources");
160 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
161 AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
162 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>("CopyPreviewIcons");
163 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
164 "CreateWgtSymbolicLink");
165 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
166 AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>(
167 "CopyStorageDirectories");
170 void WgtInstaller::RecoverySteps() {
171 AppInstaller::RecoverySteps();
172 AddStepAfter<wgt::security::StepWgtRecoverSignature>("MountRecover");
173 AddStepAfter<ci::security::StepRecoverPrivilegeCompatibility>(
174 "WgtRecoverSignature",
175 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
178 void WgtInstaller::MountInstallSteps() {
179 AppInstaller::MountInstallSteps();
180 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
181 wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
182 AddStepAfter<ci::security::StepPrivilegeCompatibility>("Signature",
183 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
184 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
185 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
186 "CheckSettingsLevel");
187 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
188 "CheckWgtBackgroundCategory");
189 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
190 "CheckWgtNotificationCategory");
191 AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
192 AddStepAfter<wgt::filesystem::StepWgtPreparePackageDirectory>("MountInstall");
193 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
194 AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
195 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
197 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
198 "CreateWgtSymbolicLink");
199 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
200 ReplaceStep<ci::filesystem::StepCreateStorageDirectories>(
201 "CreateStorageDirectories",
202 wgt::filesystem::WgtAdditionalSharedDirs);
203 AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>(
204 "CreateStorageDirectories");
207 void WgtInstaller::MountUpdateSteps() {
208 AppInstaller::MountUpdateSteps();
209 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
210 wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
211 AddStepAfter<ci::security::StepPrivilegeCompatibility>("CheckOldCertificate",
212 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
213 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
214 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
215 "CheckSettingsLevel");
216 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
217 "CheckWgtBackgroundCategory");
218 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
219 "CheckWgtNotificationCategory");
220 AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
221 AddStepAfter<wgt::filesystem::StepWgtUpdatePackageDirectory>("MountUpdate");
222 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
223 AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
224 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
226 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
227 "CreateWgtSymbolicLink");
228 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
229 AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>(
230 "UpdateStorageDirectories");
233 void WgtInstaller::ManifestDirectInstallSteps() {
234 AppInstaller::ManifestDirectInstallSteps();
235 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
236 wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
237 ReplaceStep<wgt::security::StepDirectManifestSignature>("Signature", true);
238 AddStepAfter<ci::security::StepPrivilegeCompatibility>(
239 "DirectManifestSignature",
240 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
241 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
242 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
243 "CheckSettingsLevel");
244 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
245 "CheckWgtBackgroundCategory");
246 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
247 "CheckWgtNotificationCategory");
248 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("RemoveGlobalAppSymlinks",
250 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
252 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CreateWgtSymbolicLink");
253 ReplaceStep<ci::filesystem::StepCreateStorageDirectories>(
254 "CreateStorageDirectories",
255 wgt::filesystem::WgtAdditionalSharedDirs);
258 void WgtInstaller::ManifestDirectUpdateSteps() {
259 AppInstaller::ManifestDirectUpdateSteps();
260 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
261 wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
262 ReplaceStep<wgt::security::StepDirectManifestSignature>("Signature", true);
263 AddStepAfter<ci::security::StepPrivilegeCompatibility>(
264 "CheckOldCertificate",
265 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
266 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
267 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
268 "CheckSettingsLevel");
269 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
270 "CheckWgtBackgroundCategory");
271 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
272 "CheckWgtNotificationCategory");
273 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("RemoveGlobalAppSymlinks",
275 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
277 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CreateWgtSymbolicLink");
280 void WgtInstaller::ReadonlyUpdateInstallSteps() {
281 AppInstaller::ReadonlyUpdateInstallSteps();
282 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
283 wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
284 AddStepAfter<ci::security::StepPrivilegeCompatibility>("CheckOldCertificate",
285 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
286 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
287 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
288 "CheckSettingsLevel");
289 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
290 "CheckWgtBackgroundCategory");
291 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
292 "CheckWgtNotificationCategory");
293 AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
294 AddStepAfter<wgt::filesystem::StepWgtResourceDirectory>("EncryptResources");
295 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
296 AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
297 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
299 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
300 "CreateWgtSymbolicLink");
301 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
302 AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>(
303 "UpdateStorageDirectories");
306 void WgtInstaller::ReadonlyUpdateUninstallSteps() {
307 AppInstaller::ReadonlyUpdateUninstallSteps();
308 AddStepBefore<wgt::configuration::StepSetOldSignatureFilesLocation>(
310 AddStepAfter<ci::security::StepPrivilegeCompatibility>("Signature",
311 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
312 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
313 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
314 "CheckSettingsLevel");
315 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
316 "CheckWgtBackgroundCategory");
317 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
318 "CheckWgtNotificationCategory");
321 void WgtInstaller::ManifestPartialInstallSteps() {
322 AppInstaller::ManifestPartialInstallSteps();
323 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
324 wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
325 ReplaceStep<wgt::security::StepDirectManifestSignature>("Signature", false);
326 AddStepAfter<ci::security::StepPrivilegeCompatibility>(
327 "DirectManifestSignature",
328 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
329 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
330 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
331 "CheckSettingsLevel");
332 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
333 "CheckWgtBackgroundCategory");
334 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
335 "CheckWgtNotificationCategory");
336 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("RemoveGlobalAppSymlinks",
338 ReplaceStep<ci::filesystem::StepCreateStorageDirectories>(
339 "CreateStorageDirectories",
340 wgt::filesystem::WgtAdditionalSharedDirs);
343 void WgtInstaller::ManifestPartialUpdateSteps() {
344 AppInstaller::ManifestPartialUpdateSteps();
345 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
346 wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
347 ReplaceStep<wgt::security::StepDirectManifestSignature>("Signature", false);
348 AddStepAfter<ci::security::StepPrivilegeCompatibility>(
349 "CheckOldCertificate",
350 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
351 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
352 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
353 "CheckSettingsLevel");
354 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
355 "CheckWgtBackgroundCategory");
356 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
357 "CheckWgtNotificationCategory");
358 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("RemoveGlobalAppSymlinks",
362 void WgtInstaller::PartialUninstallSteps() {
363 AppInstaller::PartialUninstallSteps();
364 ReplaceStep<ci::filesystem::StepRemovePerUserStorageDirectories>(
365 "RemovePerUserStorageDirectories",
366 wgt::filesystem::WgtAdditionalSharedDirs);
367 AddStepAfter<wgt::filesystem::StepRestoreWgtSymbolicLink>(
368 "RemovePerUserStorageDirectories");
369 AddStepAfter<wgt::encryption::StepRemoveEncryptionData>(
370 "RemovePerUserStorageDirectories");
373 void WgtInstaller::MoveSteps() {
374 AppInstaller::MoveSteps();
377 void WgtInstaller::EnablePkgSteps() {
378 AppInstaller::EnablePkgSteps();
381 void WgtInstaller::DisablePkgSteps() {
382 AppInstaller::DisablePkgSteps();
385 void WgtInstaller::MigrateExtImgSteps() {
386 AppInstaller::MigrateExtImgSteps();
389 void WgtInstaller::RecoverDBSteps() {
390 AppInstaller::RecoverDBSteps();
391 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
392 wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
393 AddStepAfter<ci::security::StepPrivilegeCompatibility>("GetPrivilegeLevel",
394 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
395 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
396 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
397 "CheckSettingsLevel");
398 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
399 "CheckWgtBackgroundCategory");
400 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
401 "CheckWgtNotificationCategory");