From: Sangyoon Jang Date: Tue, 24 Oct 2023 08:08:18 +0000 (+0900) Subject: Send pkg upgrade signal X-Git-Tag: accepted/tizen/8.0/unified/20240219.160524~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F00%2F306100%2F1;p=platform%2Fcore%2Fappfw%2Fpkgmgr-tool.git Send pkg upgrade signal Change-Id: I117e850f6e32ea90e83d88fe4b9b889262d30446 Signed-off-by: Sangyoon Jang --- diff --git a/src/pkg_upgrade/CMakeLists.txt b/src/pkg_upgrade/CMakeLists.txt index f5b621f..6353d10 100755 --- a/src/pkg_upgrade/CMakeLists.txt +++ b/src/pkg_upgrade/CMakeLists.txt @@ -8,6 +8,7 @@ ADD_EXECUTABLE(${TARGET_PKG_UPGRADE} ${SRCS}) # Dependency APPLY_PKG_CONFIG(${TARGET_PKG_UPGRADE} PUBLIC PKGMGR_INFO_DEPS + PKGMGR_INSTALLER_DEPS PKGMGR_PARSER_DEPS TIZEN_DATABASE_DEPS TZPLATFORM_DEPS diff --git a/src/pkg_upgrade/include/common_type.hh b/src/pkg_upgrade/include/common_type.hh index 05a7598..40e33b4 100644 --- a/src/pkg_upgrade/include/common_type.hh +++ b/src/pkg_upgrade/include/common_type.hh @@ -50,6 +50,15 @@ enum class PkgVersionCmpResult { UNKNOWN }; +enum class PkgUpgradeResult { + SKIPPED, + INSTALLED, + UNINSTALLED, + UPDATED, + FAILED, + UNKNOWN, +}; + class PkgContext { public: PkgContext(std::string id, std::string version, std::string type, diff --git a/src/pkg_upgrade/include/pkg_upgrader.hh b/src/pkg_upgrade/include/pkg_upgrader.hh index fe96679..94b487f 100644 --- a/src/pkg_upgrade/include/pkg_upgrader.hh +++ b/src/pkg_upgrade/include/pkg_upgrader.hh @@ -37,9 +37,13 @@ class PkgUpgrader { std::string GetVersion() const; const BackendInvoker& GetBackendInvoker() const; PkgVersionCmpResult CompareVersion(const PkgUpgrader& pkg) const; + PkgUpgradeResult GetResult() const; virtual bool Upgrade() = 0; + protected: + PkgUpgradeResult result_; + private: PkgType type_; PkgLocation loc_; diff --git a/src/pkg_upgrade/include/pkgmgr_signal.hh b/src/pkg_upgrade/include/pkgmgr_signal.hh new file mode 100644 index 0000000..6a05c00 --- /dev/null +++ b/src/pkg_upgrade/include/pkgmgr_signal.hh @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PKGMGR_SIGNAL_H_ +#define PKGMGR_SIGNAL_H_ + +#include + +#include + +#include "common_type.hh" + +namespace common_fota { + +class PkgmgrSignal { + public: + PkgmgrSignal(); + virtual ~PkgmgrSignal(); + + void SetTotalPkgs(int total_pkgs); + bool SendSignal(const std::string& pkgid, PkgUpgradeResult result); + bool SendInitialized(); + bool SendFinished(); + bool SendProgress(); + + private: + bool SendSignal(unsigned int progress); + + pkgmgr_installer* pi_; + int count_; + int total_pkgs_; +}; + +} // common_fota + +#endif // PKGMGR_SIGNAL_H_ diff --git a/src/pkg_upgrade/include/upgrader.hh b/src/pkg_upgrade/include/upgrader.hh index 77479c5..7173d0d 100644 --- a/src/pkg_upgrade/include/upgrader.hh +++ b/src/pkg_upgrade/include/upgrader.hh @@ -23,6 +23,7 @@ #include "file_logbackend.hh" #include "pkg_finder.hh" #include "pkg_upgrader.hh" +#include "pkgmgr_signal.hh" namespace common_fota { @@ -56,6 +57,7 @@ class Upgrader { std::list> failure_list_; std::string parser_db_; std::string cert_db_; + PkgmgrSignal signal_; }; } // common_fota diff --git a/src/pkg_upgrade/src/db_upgrader.cc b/src/pkg_upgrade/src/db_upgrader.cc index a756310..ef8c931 100644 --- a/src/pkg_upgrade/src/db_upgrader.cc +++ b/src/pkg_upgrade/src/db_upgrader.cc @@ -47,11 +47,13 @@ bool DbUpgrader::Upgrade() { if (GetLocation() == PkgLocation::RW) { if (!SetRwPkg(pkgid_)) { LOG(ERROR) << "Failed to update pkg " << pkgid_; + result_ = PkgUpgradeResult::FAILED; return false; } LOG(INFO) << "Preloaded files of " << pkgid_ << " has been removed. " << "This package will be non-preload RW package"; } + result_ = PkgUpgradeResult::SKIPPED; return true; } diff --git a/src/pkg_upgrade/src/pkg_upgrader.cc b/src/pkg_upgrade/src/pkg_upgrader.cc index 4442bee..9bc2cbd 100644 --- a/src/pkg_upgrade/src/pkg_upgrader.cc +++ b/src/pkg_upgrade/src/pkg_upgrader.cc @@ -30,9 +30,9 @@ PkgUpgrader::PkgUpgrader(const PkgContext& context, PkgOperation pkg_op) } PkgUpgrader::PkgUpgrader(std::string id, std::string version) - : type_(PkgType::UNKNOWN), loc_(PkgLocation::UNKNOWN), - op_(PkgOperation::COMPLEX), id_(std::move(id)), - version_(std::move(version)) { + : result_(PkgUpgradeResult::UNKNOWN), type_(PkgType::UNKNOWN), + loc_(PkgLocation::UNKNOWN), op_(PkgOperation::COMPLEX), + id_(std::move(id)), version_(std::move(version)) { } PkgType PkgUpgrader::GetType() const { @@ -59,6 +59,10 @@ const BackendInvoker& PkgUpgrader::GetBackendInvoker() const { return backend_; } +PkgUpgradeResult PkgUpgrader::GetResult() const { + return result_; +} + PkgVersionCmpResult PkgUpgrader::CompareVersion( const PkgUpgrader& pkg) const { pkgmgrinfo_version_compare_type compare = PMINFO_VERSION_OLD; diff --git a/src/pkg_upgrade/src/pkgmgr_signal.cc b/src/pkg_upgrade/src/pkgmgr_signal.cc new file mode 100644 index 0000000..aff9458 --- /dev/null +++ b/src/pkg_upgrade/src/pkgmgr_signal.cc @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "pkgmgr_signal.hh" + +#include + +#include + +#include "common_type.hh" +#include "logging.hh" + +namespace { + +const unsigned int kProgressRange = 100; + +} // namespace + +namespace common_fota { + +PkgmgrSignal::PkgmgrSignal() : count_(1), total_pkgs_(0) { + pi_ = pkgmgr_installer_new(); + if (pi_ == nullptr) + LOG(ERROR) << "Failed to create pkgmgr installer"; +} + +PkgmgrSignal::~PkgmgrSignal() { + if (pi_ != nullptr) + pkgmgr_installer_free(pi_); +} + +void PkgmgrSignal::SetTotalPkgs(int total_pkgs) { + total_pkgs_ = total_pkgs; +} + +bool PkgmgrSignal::SendSignal(unsigned int progress) { + if (pi_ == nullptr) { + LOG(ERROR) << "pkgmgr installer is not created"; + return false; + } + + int ret = pkgmgr_installer_send_pkg_upgrade_signal(pi_, progress); + if (ret != 0) { + LOG(ERROR) << "pkgmgr_installer_send_pkg_upgrade_signal failed"; + return false; + } + return true; +} + +bool PkgmgrSignal::SendInitialized() { + LOG(DEBUG) << "Send initialized signal"; + return SendSignal(0); +} + +bool PkgmgrSignal::SendFinished() { + LOG(DEBUG) << "Send finished signal"; + return SendSignal(kProgressRange); +} + +bool PkgmgrSignal::SendProgress() { + if (count_ > total_pkgs_) { + LOG(WARNING) << "count should not be greater than total packages"; + return false; + } + unsigned int progress = count_++ * kProgressRange / total_pkgs_; + LOG(DEBUG) << "Send progress: " << progress; + return SendSignal(progress); +} + +} // namespace common_fota diff --git a/src/pkg_upgrade/src/ro2rw_upgrader.cc b/src/pkg_upgrade/src/ro2rw_upgrader.cc index 7b0bcb0..4e46b74 100644 --- a/src/pkg_upgrade/src/ro2rw_upgrader.cc +++ b/src/pkg_upgrade/src/ro2rw_upgrader.cc @@ -34,6 +34,7 @@ bool Ro2RwUpgrader::Upgrade() { if (old_pkg_.get() != nullptr) { if (!old_pkg_->Upgrade()) { LOG(ERROR) << "Upgrade operation of old RO package failed"; + result_ = PkgUpgradeResult::FAILED; return false; } } @@ -41,9 +42,11 @@ bool Ro2RwUpgrader::Upgrade() { if (new_pkg_.get() != nullptr) { if (!new_pkg_->Upgrade()) { LOG(ERROR) << "Upgrade operation of new RW package failed"; + result_ = PkgUpgradeResult::FAILED; return false; } } + result_ = PkgUpgradeResult::UPDATED; return true; } diff --git a/src/pkg_upgrade/src/ro_upgrader.cc b/src/pkg_upgrade/src/ro_upgrader.cc index 846724a..282c750 100644 --- a/src/pkg_upgrade/src/ro_upgrader.cc +++ b/src/pkg_upgrade/src/ro_upgrader.cc @@ -33,20 +33,24 @@ bool RoUpgrader::Upgrade() { if (result == PkgVersionCmpResult::UNKNOWN) { LOG(ERROR) << "Failed to compare version of package(" << new_pkg_->GetId() << ")"; + result_ = PkgUpgradeResult::FAILED; return false; } if (result == PkgVersionCmpResult::SAME) { LOG(INFO) << new_pkg_->GetId() << " has same version(" << new_pkg_->GetVersion() << "). Nothing to do."; + result_ = PkgUpgradeResult::SKIPPED; return true; } } if (!new_pkg_->Upgrade()) { LOG(ERROR) << "Upgrade operation failed"; + result_ = PkgUpgradeResult::FAILED; return false; } + result_ = PkgUpgradeResult::UPDATED; return true; } diff --git a/src/pkg_upgrade/src/rw2ro_upgrader.cc b/src/pkg_upgrade/src/rw2ro_upgrader.cc index 3cd9911..add08ef 100644 --- a/src/pkg_upgrade/src/rw2ro_upgrader.cc +++ b/src/pkg_upgrade/src/rw2ro_upgrader.cc @@ -34,24 +34,29 @@ bool Rw2RoUpgrader::Upgrade() { if (result == PkgVersionCmpResult::UNKNOWN) { LOG(ERROR) << "Failed to compare version of package(" << new_pkg_->GetId() << ")"; + result_ = PkgUpgradeResult::FAILED; return false; } if (result == PkgVersionCmpResult::LOWER) { LOG(INFO) << old_pkg_->GetId() << " has higher version(" << old_pkg_->GetVersion() << ") already. Nothing to do."; + result_ = PkgUpgradeResult::SKIPPED; return true; } if (!old_pkg_->Upgrade()) { LOG(ERROR) << "Upgrade operation of old RW package failed"; + result_ = PkgUpgradeResult::FAILED; return false; } if (!new_pkg_->Upgrade()) { LOG(ERROR) << "Upgrade operation of new RO package failed"; + result_ = PkgUpgradeResult::FAILED; return false; } + result_ = PkgUpgradeResult::UPDATED; return true; } diff --git a/src/pkg_upgrade/src/rw_upgrader.cc b/src/pkg_upgrade/src/rw_upgrader.cc index e8b3192..479d5e4 100644 --- a/src/pkg_upgrade/src/rw_upgrader.cc +++ b/src/pkg_upgrade/src/rw_upgrader.cc @@ -39,26 +39,32 @@ bool RwUpgrader::Upgrade() { if (result == PkgVersionCmpResult::UNKNOWN) { LOG(ERROR) << "Failed to compare version of package(" << new_pkg_->GetId() << ")"; + result_ = PkgUpgradeResult::FAILED; return false; } if (result == PkgVersionCmpResult::SAME) { LOG(INFO) << new_pkg_->GetId() << " has same version(" << new_pkg_->GetVersion() << "). Nothing to do."; + result_ = PkgUpgradeResult::SKIPPED; return true; } } if (new_pkg_->GetOperation() != PkgOperation::UNINSTALL && new_pkg_->GetOperation() != PkgOperation::UNINSTALL_KEEP_RW_DATA) { - if (!UnzipPkgFromZip(new_pkg_->GetId())) + if (!UnzipPkgFromZip(new_pkg_->GetId())) { + result_ = PkgUpgradeResult::FAILED; return false; + } } if (!new_pkg_->Upgrade()) { LOG(ERROR) << "Upgrade operation failed"; + result_ = PkgUpgradeResult::FAILED; return false; } + result_ = PkgUpgradeResult::UPDATED; return true; } diff --git a/src/pkg_upgrade/src/simple_upgrader.cc b/src/pkg_upgrade/src/simple_upgrader.cc index 60285d3..a8ff9ff 100644 --- a/src/pkg_upgrade/src/simple_upgrader.cc +++ b/src/pkg_upgrade/src/simple_upgrader.cc @@ -24,8 +24,14 @@ SimpleUpgrader::SimpleUpgrader(const PkgContext& context, } bool SimpleUpgrader::Upgrade() { - if (GetBackendInvoker().Run() == 0) + if (GetBackendInvoker().Run() == 0) { + if (GetOperation() == PkgOperation::UNINSTALL) + result_ = PkgUpgradeResult::UNINSTALLED; + else + result_ = PkgUpgradeResult::INSTALLED; return true; + } + result_ = PkgUpgradeResult::FAILED; return false; } diff --git a/src/pkg_upgrade/src/upgrader.cc b/src/pkg_upgrade/src/upgrader.cc index fa4d378..6c4a60e 100644 --- a/src/pkg_upgrade/src/upgrader.cc +++ b/src/pkg_upgrade/src/upgrader.cc @@ -135,12 +135,19 @@ bool Upgrader::Process(PkgFinder* finder) { RemoveBackupDbs(); return false; } + signal_.SetTotalPkgs(list.size()); + LOG(DEBUG) << "Found " << list.size() << " packages to upgrade"; auto priority_list = factory.MakePriorityList(finder, list); + // Send signal after initializing + if (!signal_.SendInitialized()) + LOG(ERROR) << "Failed to send initialized signal"; ProcessList(priority_list); - // send signal at this time? ProcessList(list); + + if (!signal_.SendFinished()) + LOG(ERROR) << "Failed to send finished signal"; RemoveBackupDbs(); logger_->WriteLog(::utils::LogLevel::LOG_INFO, "", "Upgrade Done"); @@ -150,7 +157,10 @@ bool Upgrader::Process(PkgFinder* finder) { void Upgrader::ProcessList(list>& list) { for (auto& pkg : list) { - if (pkg->Upgrade()) { + bool result = pkg->Upgrade(); + if (!signal_.SendProgress()) + LOG(ERROR) << "Failed to send progress signal"; + if (result) { LOG(DEBUG) << "upgrade success (" << pkg->GetId() << ")"; success_list_.push_back(move(pkg)); } else {