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 "common/step/pkgmgr/step_recover_application.h"
7 #include <boost/filesystem.hpp>
9 #include "common/utils/paths.h"
10 #include "common/utils/pkgmgr_query.h"
11 #include "common/pkgmgr_registration.h"
13 namespace bf = boost::filesystem;
15 namespace common_installer {
18 Step::Status StepRecoverApplication::RecoveryNew() {
21 UnregisterApplication();
25 Step::Status StepRecoverApplication::RecoveryUpdate() {
27 LOG(ERROR) << "Some parameters are lacking";
30 PkgQueryInterface pkg_query(context_->pkgid.get(), context_->uid.get());
31 if (pkg_query.IsPreloadPackage())
32 SetExtAttrForPreloadPackage(pkg_query.IsUpdatedPackage(),
33 pkg_query.IsRemovablePackage());
34 UnregisterApplication();
35 if (!RegisterApplication()) {
36 LOG(ERROR) << "Unsuccessful app registration";
37 return Status::RECOVERY_ERROR;
42 Step::Status StepRecoverApplication::RecoveryReadonlyUpdateInstall() {
44 LOG(ERROR) << "Some parameters are lacking";
47 SetExtAttrForPreloadPackage(false, false);
48 UnregisterApplication();
49 if (!RegisterApplication()) {
50 LOG(ERROR) << "Unsuccessful app registration";
51 return Status::RECOVERY_ERROR;
56 bool StepRecoverApplication::SetXmlPaths() {
57 if (context_->pkgid.get().empty())
60 bf::path(getUserManifestPath(context_->uid.get(),
61 context_->is_readonly_package.get()))
62 / context_->pkgid.get();
64 context_->xml_path.set(xml_path);
65 context_->backup_xml_path.set(GetBackupPathForManifestFile(xml_path));
69 void StepRecoverApplication::SetExtAttrForPreloadPackage(
70 bool is_updated, bool is_removable) {
71 manifest_x* manifest_data = context_->manifest_data.get();
72 free(manifest_data->preload);
73 manifest_data->preload = strdup("true");
74 free(manifest_data->update);
75 manifest_data->update = strdup(is_updated ? "true" : "false");
76 free(manifest_data->system);
77 manifest_data->system = strdup(is_removable ? "false" : "true");
78 free(manifest_data->readonly);
79 manifest_data->readonly = strdup(is_removable ? "false" : "true");
80 free(manifest_data->removable);
81 manifest_data->removable = strdup(is_removable ? "true" : "false");
84 bool StepRecoverApplication::UnregisterApplication() {
85 if (context_->manifest_data.get())
86 return UnregisterAppInPkgmgr(context_->manifest_data.get(),
87 context_->pkgid.get(),
89 context_->request_mode.get());
91 return UnregisterAppInPkgmgrForPkgId(context_->pkgid.get(),
93 context_->request_mode.get());
96 bool StepRecoverApplication::RegisterApplication() {
97 return RegisterAppInPkgmgr(context_->manifest_data.get(),
98 context_->pkgid.get(),
99 context_->certificate_info.get(),
101 context_->storage.get(),
102 context_->request_mode.get(),
103 context_->tep_path.get());
106 } // namespace pkgmgr
107 } // namespace common_installer