1 // Copyright (c) 2014 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_unregister_app.h"
9 #include <boost/filesystem.hpp>
10 #include <boost/system/error_code.hpp>
11 #include <pkgmgr_installer.h>
12 #include <vcore/Certificate.h>
17 #include "common/pkgmgr_registration.h"
18 #include "common/pkgmgr_query.h"
19 #include "common/utils/file_util.h"
21 namespace common_installer {
24 namespace bs = boost::system;
25 namespace bf = boost::filesystem;
27 Step::Status StepUnregisterApplication::precheck() {
28 if (context_->pkgid.get().empty()) {
29 LOG(ERROR) << "pkgid attribute is empty";
30 return Status::PACKAGE_NOT_FOUND;
32 if (context_->xml_path.get().empty()) {
33 LOG(ERROR) << "xml_path attribute is empty";
34 return Status::MANIFEST_NOT_FOUND;
36 if (!boost::filesystem::exists(context_->xml_path.get())) {
37 LOG(ERROR) << "xml_path ("
38 << context_->xml_path.get()
39 << ") path does not exist";
40 return Status::MANIFEST_NOT_FOUND;
43 return Step::Status::OK;
46 bool StepUnregisterApplication::BackupCertInfo() {
47 std::string base64 = QueryCertificateAuthorCertificate(context_->pkgid.get(),
49 if (!base64.empty()) {
50 CertificateInfo certificate_info;
52 certificate_info.author_certificate.set(ValidationCore::CertificatePtr(
53 new ValidationCore::Certificate(
55 ValidationCore::Certificate::FormType::FORM_BASE64)));
56 } catch (const ValidationCore::Certificate::Exception::Base &e) {
57 LOG(ERROR) << "Exception in cert-svc-vcore Certificate "
58 << "Dump : " << e.DumpToString();
61 context_->certificate_info.set(certificate_info);
67 Step::Status StepUnregisterApplication::process() {
68 // Prepare certificate info for rollback operations
69 if (!BackupCertInfo()) {
70 LOG(ERROR) << "Failed to backup cert info";
73 if (!UnregisterAppInPkgmgr(context_->manifest_data.get(),
74 context_->pkgid.get(),
76 context_->request_mode.get())) {
77 LOG(ERROR) << "Failed to unregister package into database";
80 // remove manifest file
82 bf::remove(context_->xml_path.get(), error);
84 LOG(DEBUG) << "Successfully unregister the application";
89 Step::Status StepUnregisterApplication::undo() {
90 if (!RegisterAppInPkgmgr(context_->manifest_data.get(),
91 context_->pkgid.get(),
92 context_->certificate_info.get(),
94 context_->request_mode.get())) {
95 LOG(ERROR) << "Failed to restore the app registration in pkgmgr";
96 return Step::Status::REGISTER_ERROR;
99 LOG(INFO) << "Successfully restored the app registration in pkgmgr";
103 } // namespace pkgmgr
104 } // namespace common_installer