#include <sys/types.h>
#include <unistd.h>
+#include <pkgmgrinfo_type.h>
#include <vcore/Certificate.h>
#include <cassert>
#include <string>
#include "common/pkgmgr_registration.h"
+#include "common/privileges.h"
#include "common/utils/pkgmgr_query.h"
#include "common/utils/file_util.h"
namespace common_installer {
namespace pkgmgr {
+bool StepUpdateApplication::BackupPrivileges() {
+ PkgQueryInterface pkg_query(context_->pkgid.get(), context_->uid.get());
+ if (!pkg_query.IsValid()) {
+ LOG(ERROR) << "This package is not installed";
+ return false;
+ }
+
+ std::vector<std::tuple<int, std::string, std::string>> result;
+ if (!pkg_query.PrivilegesForPkgId(&result)) {
+ LOG(ERROR) << "Failed to get package's privileges";
+ return false;
+ }
+
+ manifest_x* manifest = context_->old_manifest_data.get();
+ if (!manifest) {
+ LOG(ERROR) << "manifest data null";
+ return false;
+ }
+ g_list_free_full(manifest->privileges, common_installer::FreePrivilegeX);
+ manifest->privileges = nullptr;
+ for (const auto& it : result) {
+ if (std::get<0>(it) != static_cast<int>(PMINFO_PRIVILEGE_NORMAL))
+ continue;
+
+ privilege_x* privilege =
+ reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x)));
+ if (!privilege) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
+ privilege->value = strdup(std::get<1>(it).c_str());
+ privilege->type = strdup(std::get<2>(it).c_str());
+ manifest->privileges = g_list_append(manifest->privileges, privilege);
+ }
+
+ return true;
+}
+
Step::Status StepUpdateApplication::process() {
+ if (!BackupPrivileges())
+ LOG(ERROR) << "can't backup privilege";
+
if (!UpgradeAppInPkgmgr(context_->manifest_data.get(),
context_->pkgid.get(),
context_->certificate_info.get(),