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>("CopyTep");
78 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
79 "WgtPatchStorageDirectories");
80 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>(
81 "CreateWgtSymbolicLink", true);
82 AddStepAfter<ci::filesystem::StepCreateIcons>("WgtPatchIcons");
83 AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("CreateIcons");
84 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
86 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
87 ReplaceStep<ci::filesystem::StepCreateStorageDirectories>(
88 "CreateStorageDirectories",
89 wgt::filesystem::WgtAdditionalSharedDirs);
92 void WgtInstaller::UpdateSteps() {
93 AppInstaller::UpdateSteps();
94 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
95 wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
96 AddStepAfter<ci::security::StepPrivilegeCompatibility>("CheckOldCertificate",
97 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
98 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
99 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
100 "CheckSettingsLevel");
101 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
102 "CheckWgtBackgroundCategory");
103 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
104 "CheckWgtNotificationCategory");
105 AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
106 AddStepAfter<wgt::filesystem::StepWgtResourceDirectory>("EncryptResources");
107 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
108 AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
109 AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>("UpdateTep");
110 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>("CopyPreviewIcons");
111 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
112 "CreateWgtSymbolicLink");
113 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
116 void WgtInstaller::UninstallSteps() {
117 AppInstaller::UninstallSteps();
118 ReplaceStep<ci::filesystem::StepRemovePerUserStorageDirectories>(
119 "RemovePerUserStorageDirectories",
120 wgt::filesystem::WgtAdditionalSharedDirs);
121 AddStepAfter<wgt::filesystem::StepRestoreWgtSymbolicLink>(
122 "RemovePerUserStorageDirectories");
123 AddStepAfter<wgt::encryption::StepRemoveEncryptionData>(
124 "RemovePerUserStorageDirectories");
127 void WgtInstaller::ReinstallSteps() {
128 AppInstaller::ReinstallSteps();
129 AddStepAfter<wgt::configuration::StepCheckRDSManifest>("Configure");
130 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
131 wgt::configuration::StepParse::ConfigLocation::RESOURCE_WGT, false);
132 // Unlike reinstall mode (RDS) of tpk-backend, the RDS package of wgt does not
133 // contain signature files. This may can be changed differently later.
134 RemoveStep("Signature");
135 RemoveStep("CheckOldCertificate");
136 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>("CreateIcons");
139 void WgtInstaller::DeltaSteps() {
140 AppInstaller::DeltaSteps();
141 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
142 wgt::configuration::StepParse::ConfigLocation::PACKAGE, false);
143 AddStepAfter<wgt::filesystem::StepWgtUndoPatchStorageDirectories>(
144 "EnableExternalMount");
145 ReplaceStep<ci::filesystem::StepDeltaPatch>("DeltaPatch", "res/wgt/");
146 AddStepAfter<wgt::configuration::StepCheckStartFiles>("DisableExternalMount");
147 AddStepAfter<ci::security::StepPrivilegeCompatibility>("CheckOldCertificate",
148 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
149 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
150 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
151 "CheckSettingsLevel");
152 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
153 "CheckWgtBackgroundCategory");
154 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
155 "CheckWgtNotificationCategory");
156 AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
157 AddStepAfter<wgt::filesystem::StepWgtResourceDirectory>("EncryptResources");
158 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
159 AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
160 AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>("UpdateTep");
161 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>("CopyPreviewIcons");
162 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
163 "CreateWgtSymbolicLink");
164 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
167 void WgtInstaller::RecoverySteps() {
168 AppInstaller::RecoverySteps();
169 AddStepAfter<wgt::security::StepWgtRecoverSignature>("MountRecover");
170 AddStepAfter<ci::security::StepRecoverPrivilegeCompatibility>(
171 "WgtRecoverSignature",
172 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
175 void WgtInstaller::MountInstallSteps() {
176 AppInstaller::MountInstallSteps();
177 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
178 wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
179 AddStepAfter<ci::security::StepPrivilegeCompatibility>("Signature",
180 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
181 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
182 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
183 "CheckSettingsLevel");
184 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
185 "CheckWgtBackgroundCategory");
186 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
187 "CheckWgtNotificationCategory");
188 AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
189 AddStepAfter<wgt::filesystem::StepWgtPreparePackageDirectory>("MountInstall");
190 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
191 AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
192 AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>("CopyTep");
193 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
195 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
196 "CreateWgtSymbolicLink");
197 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
198 ReplaceStep<ci::filesystem::StepCreateStorageDirectories>(
199 "CreateStorageDirectories",
200 wgt::filesystem::WgtAdditionalSharedDirs);
203 void WgtInstaller::MountUpdateSteps() {
204 AppInstaller::MountUpdateSteps();
205 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
206 wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
207 AddStepAfter<ci::security::StepPrivilegeCompatibility>("CheckOldCertificate",
208 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
209 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
210 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
211 "CheckSettingsLevel");
212 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
213 "CheckWgtBackgroundCategory");
214 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
215 "CheckWgtNotificationCategory");
216 AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
217 AddStepAfter<wgt::filesystem::StepWgtUpdatePackageDirectory>("MountUpdate");
218 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
219 AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
220 AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>("UpdateTep");
221 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
223 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
224 "CreateWgtSymbolicLink");
225 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
228 void WgtInstaller::ManifestDirectInstallSteps() {
229 AppInstaller::ManifestDirectInstallSteps();
230 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
231 wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
232 ReplaceStep<wgt::security::StepDirectManifestSignature>("Signature", true);
233 AddStepAfter<ci::security::StepPrivilegeCompatibility>(
234 "DirectManifestSignature",
235 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
236 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
237 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
238 "CheckSettingsLevel");
239 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
240 "CheckWgtBackgroundCategory");
241 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
242 "CheckWgtNotificationCategory");
243 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("RemoveGlobalAppSymlinks",
245 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
247 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CreateWgtSymbolicLink");
248 ReplaceStep<ci::filesystem::StepCreateStorageDirectories>(
249 "CreateStorageDirectories",
250 wgt::filesystem::WgtAdditionalSharedDirs);
253 void WgtInstaller::ManifestDirectUpdateSteps() {
254 AppInstaller::ManifestDirectUpdateSteps();
255 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
256 wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
257 ReplaceStep<wgt::security::StepDirectManifestSignature>("Signature", true);
258 AddStepAfter<ci::security::StepPrivilegeCompatibility>(
259 "CheckOldCertificate",
260 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
261 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
262 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
263 "CheckSettingsLevel");
264 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
265 "CheckWgtBackgroundCategory");
266 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
267 "CheckWgtNotificationCategory");
268 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("RemoveGlobalAppSymlinks",
270 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
272 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CreateWgtSymbolicLink");
275 void WgtInstaller::ReadonlyUpdateInstallSteps() {
276 AppInstaller::ReadonlyUpdateInstallSteps();
277 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
278 wgt::configuration::StepParse::ConfigLocation::PACKAGE, true);
279 AddStepAfter<ci::security::StepPrivilegeCompatibility>("CheckOldCertificate",
280 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
281 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
282 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
283 "CheckSettingsLevel");
284 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
285 "CheckWgtBackgroundCategory");
286 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
287 "CheckWgtNotificationCategory");
288 AddStepAfter<wgt::encryption::StepEncryptResources>("CheckWgtImePrivilege");
289 AddStepAfter<wgt::filesystem::StepWgtResourceDirectory>("EncryptResources");
290 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("CreateIcons", true);
291 AddStepAfter<wgt::filesystem::StepCopyPreviewIcons>("WgtPatchIcons");
292 AddStepAfter<wgt::filesystem::StepWgtPatchStorageDirectories>("CopyTep");
293 AddStepAfter<wgt::filesystem::StepCreateWgtSymbolicLink>(
295 AddStepAfter<wgt::security::StepCheckExtensionPrivileges>(
296 "CreateWgtSymbolicLink");
297 AddStepAfter<wgt::pkgmgr::StepGenerateXml>("CheckExtensionPrivileges");
300 void WgtInstaller::ReadonlyUpdateUninstallSteps() {
301 AppInstaller::ReadonlyUpdateUninstallSteps();
302 AddStepBefore<wgt::configuration::StepSetOldSignatureFilesLocation>(
304 AddStepAfter<ci::security::StepPrivilegeCompatibility>("Signature",
305 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
306 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
307 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
308 "CheckSettingsLevel");
309 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
310 "CheckWgtBackgroundCategory");
311 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
312 "CheckWgtNotificationCategory");
315 void WgtInstaller::ManifestPartialInstallSteps() {
316 AppInstaller::ManifestPartialInstallSteps();
317 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
318 wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
319 ReplaceStep<wgt::security::StepDirectManifestSignature>("Signature", false);
320 AddStepAfter<ci::security::StepPrivilegeCompatibility>(
321 "DirectManifestSignature",
322 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
323 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
324 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
325 "CheckSettingsLevel");
326 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
327 "CheckWgtBackgroundCategory");
328 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
329 "CheckWgtNotificationCategory");
330 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("RemoveGlobalAppSymlinks",
332 ReplaceStep<ci::filesystem::StepCreateStorageDirectories>(
333 "CreateStorageDirectories",
334 wgt::filesystem::WgtAdditionalSharedDirs);
337 void WgtInstaller::ManifestPartialUpdateSteps() {
338 AppInstaller::ManifestPartialUpdateSteps();
339 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
340 wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
341 ReplaceStep<wgt::security::StepDirectManifestSignature>("Signature", false);
342 AddStepAfter<ci::security::StepPrivilegeCompatibility>(
343 "CheckOldCertificate",
344 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
345 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
346 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
347 "CheckSettingsLevel");
348 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
349 "CheckWgtBackgroundCategory");
350 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
351 "CheckWgtNotificationCategory");
352 AddStepAfter<wgt::filesystem::StepWgtPatchIcons>("RemoveGlobalAppSymlinks",
356 void WgtInstaller::PartialUninstallSteps() {
357 AppInstaller::PartialUninstallSteps();
358 ReplaceStep<ci::filesystem::StepRemovePerUserStorageDirectories>(
359 "RemovePerUserStorageDirectories",
360 wgt::filesystem::WgtAdditionalSharedDirs);
361 AddStepAfter<wgt::filesystem::StepRestoreWgtSymbolicLink>(
362 "RemovePerUserStorageDirectories");
363 AddStepAfter<wgt::encryption::StepRemoveEncryptionData>(
364 "RemovePerUserStorageDirectories");
367 void WgtInstaller::MoveSteps() {
368 AppInstaller::MoveSteps();
371 void WgtInstaller::EnablePkgSteps() {
372 AppInstaller::EnablePkgSteps();
375 void WgtInstaller::DisablePkgSteps() {
376 AppInstaller::DisablePkgSteps();
379 void WgtInstaller::MigrateExtImgSteps() {
380 AppInstaller::MigrateExtImgSteps();
383 void WgtInstaller::RecoverDBSteps() {
384 AppInstaller::RecoverDBSteps();
385 ReplaceStep<wgt::configuration::StepParse>("ParseManifest",
386 wgt::configuration::StepParse::ConfigLocation::INSTALLED, true);
387 AddStepAfter<ci::security::StepPrivilegeCompatibility>("GetPrivilegeLevel",
388 ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
389 AddStepAfter<wgt::security::StepCheckSettingsLevel>("PrivilegeCompatibility");
390 AddStepAfter<wgt::security::StepCheckWgtBackgroundCategory>(
391 "CheckSettingsLevel");
392 AddStepAfter<wgt::security::StepCheckWgtNotificationCategory>(
393 "CheckWgtBackgroundCategory");
394 AddStepAfter<wgt::security::StepCheckWgtImePrivilege>(
395 "CheckWgtNotificationCategory");