#include "common/step/pkgmgr/step_recover_application.h"
#include "common/step/pkgmgr/step_recover_parser_plugins.h"
#include "common/step/pkgmgr/step_register_app.h"
+#include "common/step/pkgmgr/step_recover_priv_sharedres.h"
#include "common/step/pkgmgr/step_remove_manifest.h"
+#include "common/step/pkgmgr/step_remove_priv_sharedres.h"
#include "common/step/pkgmgr/step_run_parser_plugins.h"
#include "common/step/pkgmgr/step_unregister_app.h"
#include "common/step/pkgmgr/step_update_app.h"
AddStep<ci::security::StepPrivacyPrivilege>(
ci::security::StepPrivacyPrivilege::ActionType::Uninstall);
AddStep<ci::filesystem::StepRemoveFiles>();
+ AddStep<ci::pkgmgr::StepRemovePrivSharedres>();
AddStep<ci::filesystem::StepRemoveZipImage>();
AddStep<ci::filesystem::StepRemoveIcons>();
AddStep<ci::filesystem::StepRemoveTep>();
AddStep<ci::filesystem::StepRecoverStorageDirectories>();
AddStep<ci::filesystem::StepRecoverGlobalAppSymlinks>();
AddStep<ci::filesystem::StepRecoverFiles>();
+ AddStep<ci::pkgmgr::StepRecoverPrivSharedres>();
AddStep<ci::mount::StepMountRecover>();
AddStep<ci::filesystem::StepRecoverChangeOwner>();
AddStep<ci::pkgmgr::StepRecoverApplication>();
AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
AddStep<ci::filesystem::StepOptionalAcquireExternalStorage>();
AddStep<ci::filesystem::StepRemovePerUserStorageDirectories>();
+ AddStep<ci::pkgmgr::StepRemovePrivSharedres>();
AddStep<ci::pkgmgr::StepUnregisterApplication>();
AddStep<ci::security::StepUnregisterTrustAnchor>();
AddStep<ci::security::StepPrivacyPrivilege>(
AddStep<ci::security::StepPrivacyPrivilege>(
ci::security::StepPrivacyPrivilege::ActionType::Update);
AddStep<ci::filesystem::StepRemoveFiles>();
+ AddStep<ci::pkgmgr::StepRemovePrivSharedres>();
AddStep<ci::filesystem::StepRemoveZipImage>();
AddStep<ci::filesystem::StepRemoveIcons>();
AddStep<ci::filesystem::StepRemoveTep>();
ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
ci::configuration::StepParseManifest::StoreLocation::NORMAL);
AddStep<ci::pkgmgr::StepKillApps>();
+ AddStep<ci::pkgmgr::StepRemovePrivSharedres>();
AddStep<ci::pkgmgr::StepUpdatePkgDisableInfo>(
ci::pkgmgr::StepUpdatePkgDisableInfo::ActionType::Disable);
AddStep<ci::pkgmgr::StepRunParserPlugin>(
--- /dev/null
+// Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/step/pkgmgr/step_recover_priv_sharedres.h"
+
+#include <boost/filesystem.hpp>
+
+#include "common/utils/paths.h"
+#include "common/utils/pkgmgr_query.h"
+#include "common/pkgmgr_registration.h"
+#include "common/step/pkgmgr/step_remove_priv_sharedres.h"
+
+namespace common_installer {
+namespace pkgmgr {
+
+Step::Status StepRecoverPrivSharedres::RecoveryUninstall() {
+ StepRemovePrivSharedres instance(context_);
+ return instance.process();
+}
+
+} // namespace pkgmgr
+} // namespace common_installer
--- /dev/null
+// Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_STEP_PKGMGR_STEP_RECOVER_PRIV_SHAREDRES_H_
+#define COMMON_STEP_PKGMGR_STEP_RECOVER_PRIV_SHAREDRES_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include "common/installer_context.h"
+#include "common/step/recovery/step_recovery.h"
+
+namespace common_installer {
+namespace pkgmgr {
+
+class StepRecoverPrivSharedres : public recovery::StepRecovery {
+ public:
+ using StepRecovery::StepRecovery;
+
+ Status RecoveryNew() override { return Status::OK; }
+ Status RecoveryUpdate() override { return Status::OK; }
+ Status RecoveryUninstall() override;
+
+ STEP_NAME(RecoverPrivSharedres)
+};
+
+} // namespace pkgmgr
+} // namespace common_installer
+
+#endif // COMMON_STEP_PKGMGR_STEP_RECOVER_PRIV_SHAREDRES_H_
--- /dev/null
+// Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/step/pkgmgr/step_remove_priv_sharedres.h"
+
+#include <pkgmgr-info.h>
+#include <tzplatform_config.h>
+
+#include <boost/filesystem.hpp>
+
+#include "common/utils/file_util.h"
+#include "common/utils/user_util.h"
+
+namespace bf = boost::filesystem;
+
+namespace {
+
+bf::path GetRootPathForUid(uid_t uid) {
+ tzplatform_set_user(uid);
+ const char* rootpath = tzplatform_getenv(TZ_USER_HOME);
+ tzplatform_reset_user();
+ return rootpath;
+}
+
+bool RemoveResForUid(const std::string& pkgid, uid_t uid) {
+ bf::path target_path = GetRootPathForUid(uid) / pkgid;
+
+ if (bf::exists(target_path))
+ return true;
+
+ if (!common_installer::RemoveAll(target_path))
+ return false;
+
+ return true;
+}
+
+bool SendUninstallRequest(const std::string& pkgid, uid_t uid) {
+ pkgmgr_client *pc = pkgmgr_client_new(PC_REQUEST);
+
+ int ret = pkgmgr_client_res_usr_uninstall(pc, pkgid.c_str(), uid);
+ pkgmgr_client_free(pc);
+
+ return (ret == PKGMGR_R_OK) ? true : false;
+}
+
+} // namespace
+
+namespace common_installer {
+namespace pkgmgr {
+
+Step::Status StepRemovePrivSharedres::process() {
+ if (context_->installation_mode.get() == InstallationMode::OFFLINE)
+ return OfflineRemove();
+ else
+ return RequestRemove();
+}
+
+Step::Status StepRemovePrivSharedres::OfflineRemove() {
+ if (context_->request_mode.get() == RequestMode::GLOBAL) {
+ common_installer::UserList user_list = common_installer::GetUserList();
+ for (auto l : user_list) {
+ uid_t uid = std::get<0>(l);
+ if (!RemoveResForUid(context_->pkgid.get(), uid))
+ return Status::ERROR;
+ }
+ } else {
+ if (!RemoveResForUid(context_->pkgid.get(), context_->uid.get()))
+ return Status::ERROR;
+ }
+
+ return Status::OK;
+}
+
+Step::Status StepRemovePrivSharedres::RequestRemove() {
+ if (context_->request_mode.get() == RequestMode::GLOBAL) {
+ common_installer::UserList user_list = common_installer::GetUserList();
+ for (auto l : user_list) {
+ uid_t uid = std::get<0>(l);
+ if (!SendUninstallRequest(context_->pkgid.get(), uid)) {
+ LOG(ERROR) << "Failed to remove privileged shared resources";
+ return Status::ERROR;
+ }
+ }
+ } else {
+ if (!SendUninstallRequest(context_->pkgid.get(), context_->uid.get())) {
+ LOG(ERROR) << "Failed to remove privileged shared resources";
+ return Status::ERROR;
+ }
+ }
+ return Status::OK;
+}
+
+} // namespace pkgmgr
+} // namespace common_installer
--- /dev/null
+// Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_STEP_PKGMGR_STEP_REMOVE_PRIV_SHAREDRES_H_
+#define COMMON_STEP_PKGMGR_STEP_REMOVE_PRIV_SHAREDRES_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include "common/installer_context.h"
+#include "common/step/step.h"
+
+namespace common_installer {
+namespace pkgmgr {
+
+class StepRemovePrivSharedres : public Step {
+ public:
+ using Step::Step;
+
+ Status process() override;
+ Status clean() override { return Status::OK; }
+ Status undo() override { return Status::OK; }
+ Status precheck() override { return Status::OK; }
+
+ private:
+ Status OfflineRemove();
+ Status RequestRemove();
+
+ STEP_NAME(RemovePrivSharedres)
+};
+
+} // namespace pkgmgr
+} // namespace common_installer
+
+#endif // COMMON_STEP_PKGMGR_STEP_REMOVE_PRIV_SHAREDRES_H_