Merge "Unregister package from security manager by pkgid" into tizen
[platform/core/appfw/app-installers.git] / src / common / step / pkgmgr / step_recover_application.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 "common/step/pkgmgr/step_recover_application.h"
6
7 #include <boost/filesystem.hpp>
8
9 #include "common/paths.h"
10 #include "common/pkgmgr_registration.h"
11
12 namespace bf = boost::filesystem;
13
14 namespace common_installer {
15 namespace pkgmgr {
16
17 Step::Status StepRecoverApplication::RecoveryNew() {
18   if (!SetXmlPaths())
19     return Status::OK;
20   if (context_->manifest_data.get())
21     UnregisterAppInPkgmgr(context_->manifest_data.get(),
22                           context_->pkgid.get(),
23                           context_->uid.get(),
24                           context_->request_mode.get());
25   else
26     UnregisterAppInPkgmgrForPkgId(context_->pkgid.get(),
27                                   context_->uid.get(),
28                                   context_->request_mode.get());
29   return Status::OK;
30 }
31
32 Step::Status StepRecoverApplication::RecoveryUpdate() {
33   if (!SetXmlPaths()) {
34     LOG(ERROR) << "Some parameters are lacking";
35     return Status::ERROR;
36   }
37   UnregisterAppInPkgmgr(context_->manifest_data.get(),
38                         context_->pkgid.get(),
39                         context_->uid.get(),
40                         context_->request_mode.get());
41   if (!RegisterAppInPkgmgr(context_->manifest_data.get(),
42                            context_->pkgid.get(),
43                            context_->certificate_info.get(),
44                            context_->uid.get(),
45                            context_->request_mode.get())) {
46     LOG(ERROR) << "Unsuccessful app registration";
47     return Status::RECOVERY_ERROR;
48   }
49   return Status::OK;
50 }
51
52 bool StepRecoverApplication::SetXmlPaths() {
53   if (context_->pkgid.get().empty())
54     return false;
55   bf::path xml_path =
56       bf::path(getUserManifestPath(context_->uid.get(),
57           context_->is_readonly_package.get()))
58       / context_->pkgid.get();
59   xml_path += ".xml";
60   context_->xml_path.set(xml_path);
61   context_->backup_xml_path.set(GetBackupPathForManifestFile(xml_path));
62   return true;
63 }
64
65 }  // namespace pkgmgr
66 }  // namespace common_installer