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 <pkgmgr_installer.h>
10 #include <vcore/Certificate.h>
16 #include "common/pkgmgr_registration.h"
17 #include "common/utils/pkgmgr_query.h"
18 #include "common/utils/file_util.h"
20 namespace common_installer {
23 Step::Status StepUnregisterApplication::precheck() {
24 if (context_->pkgid.get().empty()) {
25 LOG(ERROR) << "pkgid attribute is empty";
26 return Status::PACKAGE_NOT_FOUND;
29 if (context_->force_clean_from_db.get())
30 return Step::Status::OK;
32 if (context_->xml_path.get().empty()) {
33 LOG(ERROR) << "xml_path attribute is empty";
34 return Status::MANIFEST_NOT_FOUND;
37 if (!std::filesystem::exists(context_->xml_path.get())) {
38 LOG(ERROR) << "xml_path ("
39 << context_->xml_path.get()
40 << ") path does not exist";
41 return Status::MANIFEST_NOT_FOUND;
44 return Step::Status::OK;
47 bool StepUnregisterApplication::BackupCertInfo() {
48 std::string base64 = QueryCertificateAuthorCertificate(context_->pkgid.get(),
53 CertificateInfo certificate_info;
55 certificate_info.auth_cert.set(ValidationCore::CertificatePtr(
56 new ValidationCore::Certificate(
58 ValidationCore::Certificate::FormType::FORM_BASE64)));
59 } catch (const ValidationCore::Certificate::Exception::Base &e) {
60 LOG(ERROR) << "Exception in cert-svc-vcore Certificate "
61 << "Dump : " << e.DumpToString();
64 context_->certificate_info.set(certificate_info);
69 Step::Status StepUnregisterApplication::process() {
70 // Prepare certificate info for rollback operations
71 if (!BackupCertInfo())
72 LOG(ERROR) << "Failed to backup cert info";
74 if (!UnregisterAppInPkgmgr(context_->manifest_data.get(),
75 context_->pkgid.get(),
77 context_->request_mode.get())) {
78 LOG(ERROR) << "Failed to unregister application from database";
79 return Step::Status::REGISTER_ERROR;
82 LOG(DEBUG) << "Successfully unregister the application";
86 Step::Status StepUnregisterApplication::undo() {
87 if (!RegisterAppInPkgmgr(context_->manifest_data.get(),
88 context_->pkgid.get(),
89 context_->certificate_info.get(),
91 context_->storage.get(),
92 context_->request_mode.get(),
93 context_->tep_path.get())) {
94 LOG(ERROR) << "Failed to restore application registration";
95 return Step::Status::REGISTER_ERROR;
98 LOG(INFO) << "Successfully restored application registration";
102 } // namespace pkgmgr
103 } // namespace common_installer