Relocate some utility files 08/237608/2
authorJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 2 Jul 2020 00:43:16 +0000 (09:43 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 3 Jul 2020 01:15:11 +0000 (10:15 +0900)
Relocating some files to reduce modular circular dependency ratio.

Change-Id: I3aeaef2af1b341a0b09b94282d37adc1b8d8e77c
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
100 files changed:
src/common/CMakeLists.txt
src/common/app_installer.cc [deleted file]
src/common/app_installer.h [deleted file]
src/common/app_query_interface.cc
src/common/dependency_checker.cc
src/common/dependency_checker.h
src/common/external_mount.cc
src/common/external_storage.cc
src/common/external_storage.h
src/common/installer/app_installer.cc [new file with mode: 0644]
src/common/installer/app_installer.h [new file with mode: 0644]
src/common/installer_context.h
src/common/installer_runner.cc
src/common/installer_runner.h
src/common/paths.cc [deleted file]
src/common/paths.h [deleted file]
src/common/pkgmgr_dependency.cc
src/common/pkgmgr_dependency.h
src/common/pkgmgr_interface.cc
src/common/pkgmgr_interface.h
src/common/pkgmgr_query.cc [deleted file]
src/common/pkgmgr_query.h [deleted file]
src/common/pkgmgr_signal.cc
src/common/pkgmgr_signal.h
src/common/plugins/category_plugin.cc [new file with mode: 0644]
src/common/plugins/category_plugin.h [new file with mode: 0644]
src/common/plugins/metadata_plugin.cc [new file with mode: 0644]
src/common/plugins/metadata_plugin.h [new file with mode: 0644]
src/common/plugins/plugin_factory.cc
src/common/plugins/plugin_manager.cc
src/common/plugins/plugin_manager.h
src/common/plugins/tag_plugin.cc [new file with mode: 0644]
src/common/plugins/tag_plugin.h [new file with mode: 0644]
src/common/plugins/types/category_plugin.cc [deleted file]
src/common/plugins/types/category_plugin.h [deleted file]
src/common/plugins/types/metadata_plugin.cc [deleted file]
src/common/plugins/types/metadata_plugin.h [deleted file]
src/common/plugins/types/tag_plugin.cc [deleted file]
src/common/plugins/types/tag_plugin.h [deleted file]
src/common/recovery_file.h
src/common/request.cc [deleted file]
src/common/request.h [deleted file]
src/common/security_registration.cc
src/common/shared_dirs.cc
src/common/signature.cc
src/common/step/backup/step_backup_icons.cc
src/common/step/backup/step_backup_manifest.cc
src/common/step/backup/step_copy_backup.cc
src/common/step/configuration/step_block_cross_update.cc
src/common/step/configuration/step_check_install_location.cc
src/common/step/configuration/step_configure.cc
src/common/step/configuration/step_parse_manifest.cc
src/common/step/configuration/step_parse_manifest.h
src/common/step/configuration/step_parse_preload.cc
src/common/step/filesystem/step_acquire_external_storage.cc
src/common/step/filesystem/step_change_ownership_and_permission.cc
src/common/step/filesystem/step_copy_storage_directories.cc
src/common/step/filesystem/step_copy_tep.cc
src/common/step/filesystem/step_create_globalapp_symlinks.cc
src/common/step/filesystem/step_migrate_legacy_external_image.cc
src/common/step/filesystem/step_move_installed_storage.cc
src/common/step/filesystem/step_optional_acquire_external_storage.cc
src/common/step/filesystem/step_recover_change_owner.cc
src/common/step/filesystem/step_recover_files.cc
src/common/step/filesystem/step_recover_icons.cc
src/common/step/filesystem/step_recover_manifest.cc
src/common/step/filesystem/step_recover_storage_directories.cc
src/common/step/filesystem/step_remove_files.cc
src/common/step/filesystem/step_remove_globalapp_symlinks.cc
src/common/step/filesystem/step_remove_zip_image.cc
src/common/step/filesystem/step_update_storage_directories.cc
src/common/step/filesystem/step_update_tep.cc
src/common/step/mount/step_check_mount_path.cc
src/common/step/mount/step_mount_install.cc
src/common/step/mount/step_mount_recover.cc
src/common/step/mount/step_mount_unpacked.cc
src/common/step/mount/step_mount_update.cc
src/common/step/mount/step_unmount.cc
src/common/step/pkgmgr/step_check_force_clean.cc
src/common/step/pkgmgr/step_check_installable.cc
src/common/step/pkgmgr/step_check_removable.cc
src/common/step/pkgmgr/step_check_upgradable.cc
src/common/step/pkgmgr/step_recover_application.cc
src/common/step/pkgmgr/step_unregister_app.cc
src/common/step/pkgmgr/step_update_app.cc
src/common/step/pkgmgr/step_update_pkg_disable_info.h
src/common/step/recovery/step_create_recovery_file.cc
src/common/step/recovery/step_recovery.cc
src/common/step/security/step_check_old_certificate.cc
src/common/utils/file_util.cc
src/common/utils/manifest_util.cc
src/common/utils/paths.cc [new file with mode: 0644]
src/common/utils/paths.h [new file with mode: 0644]
src/common/utils/pkgmgr_query.cc [new file with mode: 0644]
src/common/utils/pkgmgr_query.h [new file with mode: 0644]
src/common/utils/request.cc [new file with mode: 0644]
src/common/utils/request.h [new file with mode: 0644]
src/pkg_recovery/pkg_recovery.cc
src/unit_tests/common/smoke_utils.cc
src/unit_tests/common/smoke_utils.h

index d2c10ba1ee6bb53f43763a5c5636edeb9d777253..0a914102bc980159098a01b0530d7b99fd3826f7 100644 (file)
@@ -11,6 +11,7 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/step/security COMMON_STEP_SECUR
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/plugins COMMON_PLUGINS_SRCS)
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/plugins/types COMMON_PLUGINS_TYPES_SRCS)
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/utils COMMON_UTILS_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/installer COMMON_INSTALLER_SRCS)
 # Target - definition
 ADD_LIBRARY(${TARGET_LIBNAME_COMMON} SHARED
        ${COMMON_SRCS}
@@ -24,7 +25,8 @@ ADD_LIBRARY(${TARGET_LIBNAME_COMMON} SHARED
        ${COMMON_STEP_SECURITY_SRCS}
        ${COMMON_PLUGINS_SRCS}
        ${COMMON_PLUGINS_TYPES_SRCS}
-       ${COMMON_UTILS_SRCS})
+       ${COMMON_UTILS_SRCS}
+       ${COMMON_INSTALLER_SRCS})
 # Target - includes
 TARGET_INCLUDE_DIRECTORIES(${TARGET_LIBNAME_COMMON} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../")
 # Target - deps
@@ -85,3 +87,6 @@ CONFIGURE_FILE(app-installers.pc.in app-installers.pc @ONLY)
 INSTALL(FILES app-installers.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 INSTALL(DIRECTORY ./ DESTINATION ${INCLUDEDIR}/app-installers/common/
         FILES_MATCHING PATTERN "*.h")
+INSTALL(DIRECTORY ./installer/ DESTINATION ${INCLUDEDIR}/app-installers/common/
+        FILES_MATCHING PATTERN "*.h")
+
diff --git a/src/common/app_installer.cc b/src/common/app_installer.cc
deleted file mode 100644 (file)
index 8f1405e..0000000
+++ /dev/null
@@ -1,870 +0,0 @@
-/* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
-// Copyright (c) 2015 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.
-
-#include <unistd.h>
-
-#include <cstdio>
-#include <fstream>
-#include <TTraceWrapper.h>
-
-#include "common/app_installer.h"
-#include "common/installer_context.h"
-#include "common/pkgmgr_interface.h"
-#include "common/pkgmgr_signal.h"
-#include "common/step/configuration/step_fail.h"
-#include "common/utils/file_logbackend.h"
-
-#include "common/step/backup/step_backup_icons.h"
-#include "common/step/backup/step_backup_manifest.h"
-#include "common/step/backup/step_copy_backup.h"
-#include "common/step/configuration/step_block_cross_update.h"
-#include "common/step/configuration/step_check_install_location.h"
-#include "common/step/configuration/step_check_tizen_version.h"
-#include "common/step/configuration/step_configure.h"
-#include "common/step/configuration/step_parse_manifest.h"
-#include "common/step/configuration/step_parse_preload.h"
-#include "common/step/configuration/step_switch_readonly_mode.h"
-#include "common/step/filesystem/step_acquire_external_storage.h"
-#include "common/step/filesystem/step_change_ownership_and_permission.h"
-#include "common/step/filesystem/step_copy.h"
-#include "common/step/filesystem/step_copy_storage_directories.h"
-#include "common/step/filesystem/step_copy_tep.h"
-#include "common/step/filesystem/step_create_globalapp_symlinks.h"
-#include "common/step/filesystem/step_create_icons.h"
-#include "common/step/filesystem/step_create_storage_directories.h"
-#include "common/step/filesystem/step_delta_patch.h"
-#include "common/step/filesystem/step_disable_external_mount.h"
-#include "common/step/filesystem/step_enable_external_mount.h"
-#include "common/step/filesystem/step_migrate_legacy_external_image.h"
-#include "common/step/filesystem/step_move_installed_storage.h"
-#include "common/step/filesystem/step_optional_acquire_external_storage.h"
-#include "common/step/filesystem/step_recover_change_owner.h"
-#include "common/step/filesystem/step_recover_external_storage.h"
-#include "common/step/filesystem/step_recover_files.h"
-#include "common/step/filesystem/step_recover_globalapp_symlinks.h"
-#include "common/step/filesystem/step_recover_icons.h"
-#include "common/step/filesystem/step_recover_manifest.h"
-#include "common/step/filesystem/step_recover_storage_directories.h"
-#include "common/step/filesystem/step_remove_files.h"
-#include "common/step/filesystem/step_remove_icons.h"
-#include "common/step/filesystem/step_remove_globalapp_symlinks.h"
-#include "common/step/filesystem/step_remove_per_user_storage_directories.h"
-#include "common/step/filesystem/step_remove_temporary_directory.h"
-#include "common/step/filesystem/step_remove_tep.h"
-#include "common/step/filesystem/step_remove_user_data.h"
-#include "common/step/filesystem/step_remove_zip_image.h"
-#include "common/step/filesystem/step_unzip.h"
-#include "common/step/filesystem/step_update_storage_directories.h"
-#include "common/step/filesystem/step_update_tep.h"
-#include "common/step/mount/step_check_mount_path.h"
-#include "common/step/mount/step_mount_install.h"
-#include "common/step/mount/step_mount_recover.h"
-#include "common/step/mount/step_mount_unpacked.h"
-#include "common/step/mount/step_mount_update.h"
-#include "common/step/mount/step_unmount.h"
-#include "common/step/pkgmgr/step_check_force_clean.h"
-#include "common/step/pkgmgr/step_check_installable.h"
-#include "common/step/pkgmgr/step_check_removable.h"
-#include "common/step/pkgmgr/step_check_restriction.h"
-#include "common/step/pkgmgr/step_check_upgradable.h"
-#include "common/step/pkgmgr/step_kill_apps.h"
-#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_remove_manifest.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"
-#include "common/step/pkgmgr/step_update_pkg_disable_info.h"
-#include "common/step/rds/step_rds_modify.h"
-#include "common/step/rds/step_rds_parse.h"
-#include "common/step/recovery/step_create_recovery_file.h"
-#include "common/step/recovery/step_open_recovery_file.h"
-#include "common/step/security/step_check_old_certificate.h"
-#include "common/step/security/step_get_privilege_level.h"
-#include "common/step/security/step_privacy_privilege.h"
-#include "common/step/security/step_recover_security.h"
-#include "common/step/security/step_recover_trust_anchor.h"
-#include "common/step/security/step_register_security.h"
-#include "common/step/security/step_register_trust_anchor.h"
-#include "common/step/security/step_revoke_security.h"
-#include "common/step/security/step_revoke_trust_anchor.h"
-#include "common/step/security/step_rollback_installation_security.h"
-#include "common/step/security/step_signature.h"
-#include "common/step/security/step_unregister_trust_anchor.h"
-#include "common/step/security/step_update_security.h"
-
-namespace ci = common_installer;
-
-namespace {
-
-const unsigned kProgressRange = 100;
-const char kLogFileName[] = LOGDIR"/app-installers.log";
-const char kHistoryFileName[] = LOGDIR"/installation-history.log";
-const int kLogRotationSize = 1024 * 256;  // 256KB
-const int kLogMaximumRotation = 3;
-
-}
-
-namespace common_installer {
-
-AppInstaller::AppInstaller(const char* package_type, PkgMgrPtr pkgmgr)
-    : pkgmgr_(pkgmgr), context_(new InstallerContext()),
-      status_(Step::Status::OK), result_(Result::OK), index_(0) {
-  context_->pkg_type.set(package_type);
-  context_->installation_mode.set(pkgmgr->GetInstallationMode());
-
-  // pkgmgr signal should work only for online mode
-  // there is no one to receive it in offline mode
-  if (context_->installation_mode.get() == InstallationMode::ONLINE) {
-    pi_ = pkgmgr->CreatePkgmgrSignal();
-  }
-}
-
-AppInstaller::~AppInstaller() {
-}
-
-void AppInstaller::Init() {
-  // for multi installer
-  context_->index.set(index_);
-  pkgmgr_->SetAppQueryInterface(index_);
-
-  switch (pkgmgr_->GetRequestType(index_)) {
-    case RequestType::Install:
-      InstallSteps();
-      break;
-    case RequestType::Update:
-      UpdateSteps();
-      break;
-    case RequestType::Uninstall:
-      UninstallSteps();
-      break;
-    case RequestType::Reinstall:
-      ReinstallSteps();
-      break;
-    case RequestType::Delta:
-      DeltaSteps();
-      break;
-    case RequestType::Move:
-      MoveSteps();
-      break;
-    case RequestType::Recovery:
-      RecoverySteps();
-      break;
-    case RequestType::MountInstall:
-      MountInstallSteps();
-      break;
-    case RequestType::MountUpdate:
-      MountUpdateSteps();
-      break;
-    case RequestType::ManifestDirectInstall:
-      ManifestDirectInstallSteps();
-      break;
-    case RequestType::ManifestDirectUpdate:
-      ManifestDirectUpdateSteps();
-      break;
-    case RequestType::ManifestPartialInstall:
-      ManifestPartialInstallSteps();
-      break;
-    case RequestType::ManifestPartialUpdate:
-      ManifestPartialUpdateSteps();
-      break;
-    case RequestType::PartialUninstall:
-      PartialUninstallSteps();
-      break;
-    case RequestType::ReadonlyUpdateInstall:
-      ReadonlyUpdateInstallSteps();
-      break;
-    case RequestType::ReadonlyUpdateUninstall:
-      ReadonlyUpdateUninstallSteps();
-      break;
-    case RequestType::EnablePkg:
-      EnablePkgSteps();
-      break;
-    case RequestType::DisablePkg:
-      DisablePkgSteps();
-      break;
-    case RequestType::MigrateExtImg:
-      MigrateExtImgSteps();
-      break;
-    case RequestType::RecoverDB:
-      RecoverDBSteps();
-      break;
-    default:
-      UnknownSteps();
-      break;
-  }
-}
-
-AppInstaller::Result AppInstaller::Run() {
-  Process();
-  if (it_ != steps_.end() && result_ == Result::ERROR) {
-    LOG(ERROR) << "Failure occurs in step: " << (*it_)->name();
-    Undo();
-  } else {
-    Clean();
-  }
-  sync();
-
-  if ((context_->installation_mode.get() == InstallationMode::OFFLINE) &&
-      (result_ == Result::ERROR)) {
-    std::fstream info_file("/tmp/.preload_install_error",
-        std::ios::out | std::ios::app);
-    info_file << context_->pkgid.get() << std::endl;
-    info_file.close();
-  }
-
-  return result_;
-}
-
-void AppInstaller::LogHistory(bool success) {
-  std::shared_ptr<utils::FileLogBackend> history_logger =
-      std::shared_ptr<utils::FileLogBackend>(new utils::FileLogBackend(
-          kHistoryFileName, kLogRotationSize, kLogMaximumRotation));
-  std::string history = "pkgid:" + context_->pkgid.get() + "|mode:" +
-      GetRequestTypeString(context_->request_type.get());
-  if (success)
-    history += "|SUCCESS";
-  else
-    history += "|FAIL";
-  history_logger->WriteLog(::utils::LogLevel::LOG_INFO, "", history);
-  history_logger->WriteLogToFile();
-}
-
-AppInstaller::Result AppInstaller::Process() {
-  Init();
-
-  failure_logger_ =
-      std::shared_ptr<utils::FileLogBackend>(new utils::FileLogBackend(
-            kLogFileName, kLogRotationSize, kLogMaximumRotation));
-  ::utils::LogCore::GetCore().AddLogBackend(failure_logger_);
-
-  unsigned total_steps = steps_.size();
-  unsigned current_step = 1;
-
-  for (it_ = steps_.begin(); it_ != steps_.end(); ++it_, ++current_step) {
-    status_ = SafeExecute(*it_, &Step::precheck, "precheck");
-    if (status_ == Step::Status::OK)
-      status_ = SafeExecute(*it_, &Step::process, "process");
-
-    if (status_ != Step::Status::OK) {
-      if (status_ != Step::Status::RECOVERY_DONE) {
-        LOG(ERROR) << "Error during processing";
-        result_ = Result::ERROR;
-      }
-      break;
-    }
-    SendProgress(current_step * kProgressRange / total_steps);
-  }
-
-  return result_;
-}
-
-AppInstaller::Result AppInstaller::Undo() {
-  do {
-    if (it_ == steps_.end())
-      --it_;
-    if (SafeExecute(*it_, &Step::undo, "undo") != Step::Status::OK) {
-      LOG(ERROR) << "Error during undo operation(" << (*it_)->name()
-                 << "), but continuing...";
-      result_ = Result::UNDO_ERROR;
-    }
-  } while (it_-- != steps_.begin());
-  sync();
-  failure_logger_->WriteLogToFile();
-
-  // Undo will be invoked when other installer fails when multi-install, but the
-  // status of current installer can be ok. We need to change this to proper
-  // error code to notify that entire installation was failed to listener.
-  // TODO(jeremy.jang): Need some other error for multi-install failure?
-  if (status_ == Step::Status::OK)
-    status_ = Step::Status::ERROR;
-  SendFinished(status_);
-
-  LogHistory(false);
-
-  return result_;
-}
-
-AppInstaller::Result AppInstaller::Clean() {
-  const auto& recovery_file =
-    context_->recovery_info.get().recovery_file;
-  if (recovery_file) {
-    recovery_file->set_cleanup(true);
-    recovery_file->WriteAndCommitFileContent();
-  }
-  SendFinished(status_);
-
-  do {
-    if (it_ == steps_.end())
-      --it_;
-    if (SafeExecute(*it_, &Step::clean, "clean") != Step::Status::OK) {
-      LOG(ERROR) << "Error during clean operation(" << (*it_)->name() << ")";
-      result_ = Result::CLEANUP_ERROR;
-      break;
-    }
-  } while (it_-- != steps_.begin());
-  sync();
-
-  LogHistory(true);
-
-  return result_;
-}
-
-void AppInstaller::InstallSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::recovery::StepCreateRecoveryFile>();
-  AddStep<ci::filesystem::StepUnzip>();
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::PACKAGE,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::configuration::StepCheckInstallLocation>();
-  AddStep<ci::pkgmgr::StepCheckInstallable>();
-  AddStep<ci::configuration::StepParsePreload>();
-  AddStep<ci::pkgmgr::StepCheckRestriction>();
-  AddStep<ci::configuration::StepCheckTizenVersion>();
-  AddStep<ci::security::StepSignature>(true);
-  AddStep<ci::security::StepRollbackInstallationSecurity>();
-  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
-  AddStep<ci::filesystem::StepAcquireExternalStorage>(false);
-  AddStep<ci::filesystem::StepCopy>();
-  AddStep<ci::filesystem::StepCopyTep>();
-  AddStep<ci::filesystem::StepCreateIcons>();
-  AddStep<ci::pkgmgr::StepRegisterApplication>();
-  AddStep<ci::security::StepRegisterTrustAnchor>(
-      ci::security::StepRegisterTrustAnchor::RegisterType::INSTALL);
-  AddStep<ci::security::StepPrivacyPrivilege>(
-      ci::security::StepPrivacyPrivilege::ActionType::Install);
-  AddStep<ci::security::StepRegisterSecurity>();
-  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Install);
-  AddStep<ci::filesystem::StepCreateStorageDirectories>();
-  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>();
-  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
-}
-
-void AppInstaller::UpdateSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::recovery::StepCreateRecoveryFile>();
-  AddStep<ci::filesystem::StepUnzip>();
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::PACKAGE,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
-      ci::configuration::StepParseManifest::StoreLocation::BACKUP);
-  AddStep<ci::configuration::StepCheckInstallLocation>();
-  AddStep<ci::pkgmgr::StepCheckUpgradable>();
-  AddStep<ci::configuration::StepParsePreload>();
-  AddStep<ci::configuration::StepCheckTizenVersion>();
-  AddStep<ci::security::StepSignature>(true);
-  AddStep<ci::security::StepCheckOldCertificate>();
-  AddStep<ci::configuration::StepBlockCrossUpdate>();
-  AddStep<ci::pkgmgr::StepKillApps>();
-  AddStep<ci::backup::StepBackupManifest>();
-  AddStep<ci::backup::StepBackupIcons>();
-  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
-  AddStep<ci::filesystem::StepAcquireExternalStorage>(true);
-  AddStep<ci::security::StepRevokeTrustAnchor>();
-  AddStep<ci::backup::StepCopyBackup>();
-  AddStep<ci::filesystem::StepUpdateTep>();
-  AddStep<ci::filesystem::StepCopyStorageDirectories>();
-  AddStep<ci::filesystem::StepCreateIcons>();
-  AddStep<ci::pkgmgr::StepUpdateApplication>();
-  AddStep<ci::security::StepRegisterTrustAnchor>(
-      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
-  AddStep<ci::security::StepPrivacyPrivilege>(
-      ci::security::StepPrivacyPrivilege::ActionType::Update);
-  AddStep<ci::security::StepUpdateSecurity>();
-  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
-  AddStep<ci::filesystem::StepUpdateStorageDirectories>();
-  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>();
-  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
-}
-
-void AppInstaller::UninstallSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::recovery::StepCreateRecoveryFile>();
-  AddStep<ci::pkgmgr::StepCheckRestriction>();
-  AddStep<ci::pkgmgr::StepCheckRemovable>();
-  AddStep<ci::pkgmgr::StepCheckForceClean>();
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::configuration::StepCheckInstallLocation>();
-  AddStep<ci::pkgmgr::StepKillApps>();
-  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Uninstall);
-  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
-  AddStep<ci::filesystem::StepOptionalAcquireExternalStorage>();
-  AddStep<ci::filesystem::StepRemovePerUserStorageDirectories>();
-  AddStep<ci::pkgmgr::StepUnregisterApplication>();
-  AddStep<ci::security::StepUnregisterTrustAnchor>();
-  AddStep<ci::security::StepPrivacyPrivilege>(
-      ci::security::StepPrivacyPrivilege::ActionType::Uninstall);
-  AddStep<ci::filesystem::StepRemoveFiles>();
-  AddStep<ci::filesystem::StepRemoveZipImage>();
-  AddStep<ci::filesystem::StepRemoveIcons>();
-  AddStep<ci::filesystem::StepRemoveTep>();
-  AddStep<ci::security::StepRevokeSecurity>();
-  AddStep<ci::pkgmgr::StepRemoveManifest>();
-  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
-}
-
-void AppInstaller::ReinstallSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::PACKAGE,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
-      ci::configuration::StepParseManifest::StoreLocation::BACKUP);
-  AddStep<ci::configuration::StepCheckInstallLocation>();
-  AddStep<ci::pkgmgr::StepCheckUpgradable>();
-  AddStep<ci::configuration::StepParsePreload>();
-  AddStep<ci::configuration::StepCheckTizenVersion>();
-  AddStep<ci::security::StepSignature>(true);
-  AddStep<ci::security::StepCheckOldCertificate>();
-  AddStep<ci::configuration::StepBlockCrossUpdate>();
-  AddStep<ci::pkgmgr::StepKillApps>();
-  AddStep<ci::backup::StepBackupManifest>();
-  AddStep<ci::backup::StepBackupIcons>();
-  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
-  AddStep<ci::security::StepRevokeTrustAnchor>();
-  AddStep<ci::rds::StepRDSParse>();
-  AddStep<ci::rds::StepRDSModify>();
-  AddStep<ci::filesystem::StepUpdateTep>();
-  AddStep<ci::filesystem::StepCreateIcons>();
-  AddStep<ci::pkgmgr::StepUpdateApplication>();
-  AddStep<ci::security::StepRegisterTrustAnchor>(
-      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
-  AddStep<ci::security::StepPrivacyPrivilege>(
-      ci::security::StepPrivacyPrivilege::ActionType::Update);
-  AddStep<ci::security::StepUpdateSecurity>();
-  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
-  AddStep<ci::filesystem::StepUpdateStorageDirectories>();
-  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>();
-  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
-}
-
-void AppInstaller::DeltaSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::recovery::StepCreateRecoveryFile>();
-  AddStep<ci::filesystem::StepUnzip>();
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::PACKAGE,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
-      ci::configuration::StepParseManifest::StoreLocation::BACKUP);
-  AddStep<ci::configuration::StepCheckInstallLocation>();
-  AddStep<ci::pkgmgr::StepCheckUpgradable>();
-  AddStep<ci::configuration::StepParsePreload>();
-  AddStep<ci::configuration::StepCheckTizenVersion>();
-  AddStep<ci::filesystem::StepEnableExternalMount>();
-  AddStep<ci::filesystem::StepDeltaPatch>();
-  AddStep<ci::filesystem::StepDisableExternalMount>();
-  AddStep<ci::security::StepSignature>(true);
-  AddStep<ci::security::StepCheckOldCertificate>();
-  AddStep<ci::configuration::StepBlockCrossUpdate>();
-  AddStep<ci::pkgmgr::StepKillApps>();
-  AddStep<ci::backup::StepBackupManifest>();
-  AddStep<ci::backup::StepBackupIcons>();
-  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
-  AddStep<ci::filesystem::StepAcquireExternalStorage>(true);
-  AddStep<ci::security::StepRevokeTrustAnchor>();
-  AddStep<ci::backup::StepCopyBackup>();
-  AddStep<ci::filesystem::StepUpdateTep>();
-  AddStep<ci::filesystem::StepCopyStorageDirectories>();
-  AddStep<ci::filesystem::StepCreateIcons>();
-  AddStep<ci::pkgmgr::StepUpdateApplication>();
-  AddStep<ci::security::StepRegisterTrustAnchor>(
-      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
-  AddStep<ci::security::StepPrivacyPrivilege>(
-      ci::security::StepPrivacyPrivilege::ActionType::Update);
-  AddStep<ci::security::StepUpdateSecurity>();
-  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
-  AddStep<ci::filesystem::StepUpdateStorageDirectories>();
-  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>();
-  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
-}
-
-void AppInstaller::MoveSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::pkgmgr::StepCheckRestriction>();
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::configuration::StepCheckInstallLocation>();
-  AddStep<ci::pkgmgr::StepKillApps>();
-  AddStep<ci::filesystem::StepMoveInstalledStorage>();
-  AddStep<ci::security::StepRegisterSecurity>();
-}
-
-void AppInstaller::RecoverySteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::recovery::StepOpenRecoveryFile>();
-  AddStep<ci::filesystem::StepRemoveTemporaryDirectory>();
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::RECOVERY,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::filesystem::StepRecoverIcons>();
-  AddStep<ci::pkgmgr::StepRecoverParserPlugin>();
-  AddStep<ci::filesystem::StepRecoverManifest>();
-  AddStep<ci::filesystem::StepRecoverExternalStorage>();
-  AddStep<ci::filesystem::StepRecoverStorageDirectories>();
-  AddStep<ci::filesystem::StepRecoverGlobalAppSymlinks>();
-  AddStep<ci::filesystem::StepRecoverFiles>();
-  AddStep<ci::mount::StepMountRecover>();
-  AddStep<ci::filesystem::StepRecoverChangeOwner>();
-  AddStep<ci::pkgmgr::StepRecoverApplication>();
-  AddStep<ci::security::StepRecoverTrustAnchor>();
-  AddStep<ci::security::StepRecoverSecurity>();
-}
-
-void AppInstaller::MountInstallSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::recovery::StepCreateRecoveryFile>();
-  AddStep<ci::mount::StepMountUnpacked>();
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::PACKAGE,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::configuration::StepCheckInstallLocation>();
-  AddStep<ci::pkgmgr::StepCheckInstallable>();
-  AddStep<ci::configuration::StepParsePreload>();
-  AddStep<ci::pkgmgr::StepCheckRestriction>();
-  AddStep<ci::configuration::StepCheckTizenVersion>();
-  AddStep<ci::security::StepSignature>(true);
-  AddStep<ci::security::StepRollbackInstallationSecurity>();
-  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
-  AddStep<ci::mount::StepMountInstall>();
-  AddStep<ci::filesystem::StepCopyTep>();
-  AddStep<ci::filesystem::StepCreateIcons>();
-  AddStep<ci::pkgmgr::StepRegisterApplication>();
-  AddStep<ci::security::StepRegisterTrustAnchor>(
-      ci::security::StepRegisterTrustAnchor::RegisterType::INSTALL);
-  AddStep<ci::security::StepPrivacyPrivilege>(
-      ci::security::StepPrivacyPrivilege::ActionType::Install);
-  AddStep<ci::security::StepRegisterSecurity>();
-  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Install);
-  AddStep<ci::mount::StepUnmount>();
-  AddStep<ci::filesystem::StepCreateStorageDirectories>();
-  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>(true);
-  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
-}
-
-void AppInstaller::MountUpdateSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::recovery::StepCreateRecoveryFile>();
-  AddStep<ci::mount::StepMountUnpacked>();
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::PACKAGE,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
-      ci::configuration::StepParseManifest::StoreLocation::BACKUP);
-  AddStep<ci::configuration::StepCheckInstallLocation>();
-  AddStep<ci::pkgmgr::StepCheckUpgradable>();
-  AddStep<ci::configuration::StepParsePreload>();
-  AddStep<ci::configuration::StepCheckTizenVersion>();
-  AddStep<ci::security::StepSignature>(true);
-  AddStep<ci::security::StepCheckOldCertificate>();
-  AddStep<ci::configuration::StepBlockCrossUpdate>();
-  AddStep<ci::security::StepRevokeTrustAnchor>();
-  AddStep<ci::pkgmgr::StepKillApps>();
-  AddStep<ci::backup::StepBackupManifest>();
-  AddStep<ci::backup::StepBackupIcons>();
-  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
-  AddStep<ci::mount::StepMountUpdate>();
-  AddStep<ci::filesystem::StepUpdateTep>();
-  AddStep<ci::filesystem::StepCreateIcons>();
-  AddStep<ci::pkgmgr::StepUpdateApplication>();
-  AddStep<ci::security::StepRegisterTrustAnchor>(
-      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
-  AddStep<ci::security::StepPrivacyPrivilege>(
-      ci::security::StepPrivacyPrivilege::ActionType::Update);
-  AddStep<ci::security::StepUpdateSecurity>();
-  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
-  AddStep<ci::mount::StepUnmount>();
-  AddStep<ci::filesystem::StepUpdateStorageDirectories>();
-  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>(true);
-  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
-}
-
-void AppInstaller::ManifestDirectInstallSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::pkgmgr::StepCheckInstallable>();
-  AddStep<ci::mount::StepCheckMountPath>();
-  AddStep<ci::configuration::StepParsePreload>();
-  AddStep<ci::configuration::StepCheckTizenVersion>();
-  AddStep<ci::security::StepSignature>(true);
-  AddStep<ci::security::StepRollbackInstallationSecurity>();
-  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
-  AddStep<ci::pkgmgr::StepRegisterApplication>();
-  AddStep<ci::security::StepRegisterTrustAnchor>(
-      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
-  AddStep<ci::security::StepPrivacyPrivilege>(
-      ci::security::StepPrivacyPrivilege::ActionType::Install);
-  AddStep<ci::security::StepRegisterSecurity>();
-  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Install);
-  AddStep<ci::filesystem::StepCreateStorageDirectories>();
-  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>();
-  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
-}
-
-void AppInstaller::ManifestDirectUpdateSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::pkgmgr::StepCheckUpgradable>();
-  AddStep<ci::mount::StepCheckMountPath>();
-  AddStep<ci::configuration::StepParsePreload>();
-  AddStep<ci::configuration::StepCheckTizenVersion>();
-  AddStep<ci::security::StepSignature>(true);
-  AddStep<ci::security::StepCheckOldCertificate>();
-  AddStep<ci::pkgmgr::StepKillApps>();
-  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
-  AddStep<ci::pkgmgr::StepUpdateApplication>();
-  AddStep<ci::security::StepRegisterTrustAnchor>(
-      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
-  AddStep<ci::security::StepPrivacyPrivilege>(
-      ci::security::StepPrivacyPrivilege::ActionType::Update);
-  AddStep<ci::security::StepRegisterSecurity>();
-  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
-  AddStep<ci::filesystem::StepUpdateStorageDirectories>();
-  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>();
-  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
-}
-
-void AppInstaller::ManifestPartialInstallSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::configuration::StepParsePreload>();
-  AddStep<ci::security::StepSignature>(false);
-  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
-  AddStep<ci::pkgmgr::StepRegisterApplication>();
-  AddStep<ci::security::StepRegisterTrustAnchor>(
-      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
-  AddStep<ci::security::StepPrivacyPrivilege>(
-      ci::security::StepPrivacyPrivilege::ActionType::Install);
-  AddStep<ci::security::StepRegisterSecurity>();
-  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Install);
-  AddStep<ci::filesystem::StepCreateStorageDirectories>();
-  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
-}
-
-void AppInstaller::ManifestPartialUpdateSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::configuration::StepParsePreload>();
-  AddStep<ci::security::StepSignature>(false);
-  AddStep<ci::security::StepCheckOldCertificate>();
-  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
-  AddStep<ci::pkgmgr::StepKillApps>();
-  AddStep<ci::pkgmgr::StepUpdateApplication>();
-  AddStep<ci::security::StepRegisterTrustAnchor>(
-      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
-  AddStep<ci::security::StepPrivacyPrivilege>(
-      ci::security::StepPrivacyPrivilege::ActionType::Update);
-  AddStep<ci::security::StepRegisterSecurity>();
-  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
-  AddStep<ci::filesystem::StepUpdateStorageDirectories>();
-  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
-}
-
-void AppInstaller::PartialUninstallSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::pkgmgr::StepCheckRemovable>();
-  AddStep<ci::pkgmgr::StepCheckForceClean>();
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::configuration::StepCheckInstallLocation>();
-  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
-  AddStep<ci::filesystem::StepOptionalAcquireExternalStorage>();
-  AddStep<ci::filesystem::StepRemovePerUserStorageDirectories>();
-  AddStep<ci::pkgmgr::StepUnregisterApplication>();
-  AddStep<ci::security::StepUnregisterTrustAnchor>();
-  AddStep<ci::security::StepPrivacyPrivilege>(
-      ci::security::StepPrivacyPrivilege::ActionType::Uninstall);
-  AddStep<ci::security::StepRevokeSecurity>();
-  AddStep<ci::pkgmgr::StepRunParserPlugin>(
-      ci::Plugin::ActionType::Uninstall);
-}
-
-void AppInstaller::ReadonlyUpdateInstallSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::recovery::StepCreateRecoveryFile>();
-  AddStep<ci::filesystem::StepUnzip>();
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::PACKAGE,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::configuration::StepSwitchReadonlyMode>();
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
-      ci::configuration::StepParseManifest::StoreLocation::BACKUP);
-  AddStep<ci::configuration::StepSwitchReadonlyMode>();
-  AddStep<ci::configuration::StepCheckInstallLocation>();
-  AddStep<ci::pkgmgr::StepCheckUpgradable>();
-  AddStep<ci::configuration::StepParsePreload>();
-  AddStep<ci::configuration::StepCheckTizenVersion>();
-  AddStep<ci::security::StepSignature>(true);
-  AddStep<ci::security::StepCheckOldCertificate>();
-  AddStep<ci::configuration::StepBlockCrossUpdate>();
-  AddStep<ci::pkgmgr::StepKillApps>();
-  AddStep<ci::security::StepRevokeTrustAnchor>();
-  AddStep<ci::filesystem::StepCopy>();
-  AddStep<ci::filesystem::StepCopyTep>();
-  AddStep<ci::filesystem::StepCreateIcons>();
-  AddStep<ci::pkgmgr::StepUpdateApplication>();
-  AddStep<ci::security::StepRegisterTrustAnchor>(
-      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
-  AddStep<ci::security::StepPrivacyPrivilege>(
-      ci::security::StepPrivacyPrivilege::ActionType::Update);
-  AddStep<ci::security::StepUpdateSecurity>();
-  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
-  AddStep<ci::filesystem::StepUpdateStorageDirectories>();
-  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>();
-  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
-}
-
-void AppInstaller::ReadonlyUpdateUninstallSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
-      ci::configuration::StepParseManifest::StoreLocation::BACKUP);
-  AddStep<ci::configuration::StepSwitchReadonlyMode>();
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::pkgmgr::StepCheckUpgradable>();
-  AddStep<ci::configuration::StepParsePreload>();
-  AddStep<ci::security::StepSignature>(false);
-  AddStep<ci::configuration::StepSwitchReadonlyMode>();
-  AddStep<ci::pkgmgr::StepKillApps>();
-  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
-  AddStep<ci::security::StepRevokeTrustAnchor>();
-  AddStep<ci::pkgmgr::StepUpdateApplication>();
-  AddStep<ci::security::StepRegisterTrustAnchor>(
-      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
-  AddStep<ci::security::StepPrivacyPrivilege>(
-      ci::security::StepPrivacyPrivilege::ActionType::Update);
-  AddStep<ci::filesystem::StepRemoveFiles>();
-  AddStep<ci::filesystem::StepRemoveZipImage>();
-  AddStep<ci::filesystem::StepRemoveIcons>();
-  AddStep<ci::filesystem::StepRemoveTep>();
-  AddStep<ci::filesystem::StepRemoveUserData>();
-  AddStep<ci::configuration::StepSwitchReadonlyMode>();
-  AddStep<ci::security::StepUpdateSecurity>();
-  AddStep<ci::pkgmgr::StepRemoveManifest>();
-  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
-  AddStep<ci::filesystem::StepUpdateStorageDirectories>();
-}
-
-void AppInstaller::DisablePkgSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::pkgmgr::StepKillApps>();
-  AddStep<ci::pkgmgr::StepUpdatePkgDisableInfo>(
-    ci::pkgmgr::StepUpdatePkgDisableInfo::ActionType::Disable);
-  AddStep<ci::pkgmgr::StepRunParserPlugin>(
-    ci::Plugin::ActionType::Uninstall);
-}
-
-void AppInstaller::EnablePkgSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::pkgmgr::StepUpdatePkgDisableInfo>(
-    ci::pkgmgr::StepUpdatePkgDisableInfo::ActionType::Enable);
-  AddStep<ci::pkgmgr::StepRunParserPlugin>(
-    ci::Plugin::ActionType::Install);
-}
-
-void AppInstaller::MigrateExtImgSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::security::StepMigrateLegacyExtImage>();
-  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>();
-}
-
-void AppInstaller::RecoverDBSteps() {
-  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
-  AddStep<ci::configuration::StepParseManifest>(
-      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
-      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
-  AddStep<ci::pkgmgr::StepCheckInstallable>();
-  AddStep<ci::mount::StepCheckMountPath>();
-  AddStep<ci::configuration::StepParsePreload>();
-  AddStep<ci::security::StepGetPrivilegeLevel>();
-  AddStep<ci::pkgmgr::StepRegisterApplication>();
-}
-
-void AppInstaller::UnknownSteps() {
-  AddStep<configuration::StepFail>();
-}
-
-void AppInstaller::HandleStepError(Step::Status result,
-                                        const std::string& error) {
-  if (pi_)
-    pi_->SendError(result, error, context_->pkg_type.get(),
-                   context_->pkgid.get());
-}
-
-void AppInstaller::SendProgress(int progress) {
-  if (pi_) {
-    // send START signal as soon as possible if not sent
-    if (pi_->state() == PkgmgrSignal::State::NOT_SENT) {
-      if (!context_->pkgid.get().empty()) {
-        // set request type before sending start signal
-        pi_->SetRequestType(context_->request_type.get());
-        pi_->SendStarted(context_->pkg_type.get(), context_->pkgid.get());
-      }
-    }
-
-    // send installation progress
-    pi_->SendProgress(progress,
-        context_->pkg_type.get(), context_->pkgid.get());
-  }
-}
-
-void AppInstaller::SendFinished(Step::Status process_status) {
-  if (pi_) {
-    // send START if pkgid was not parsed
-    if (pi_->state() == PkgmgrSignal::State::NOT_SENT) {
-      // set request type before sending start signal
-      pi_->SetRequestType(context_->request_type.get());
-      pi_->SendStarted(context_->pkg_type.get(), context_->pkgid.get());
-    }
-    pi_->SendFinished(process_status,
-                      context_->pkg_type.get(),
-                      context_->pkgid.get());
-  }
-}
-
-Step::Status AppInstaller::SafeExecute(std::unique_ptr<Step> const& step_ptr,
-                                       Step::Status (Step::*method)(),
-                                       std::string name) {
-  Step::Status process_status = Step::Status::OK;
-  try {
-    TTRACE(TTRACE_TAG_APP, "%s_%s", step_ptr->name(), name.c_str());
-    process_status = ((*step_ptr).*method)();
-  } catch (const std::exception& err) {
-    LOG(ERROR) << "Exception occurred in " << name.c_str() << "(): "
-               << err.what() << " in step: " << step_ptr->name();
-    process_status = Step::Status::ERROR;
-  }
-  return process_status;
-}
-
-}  // namespace common_installer
diff --git a/src/common/app_installer.h b/src/common/app_installer.h
deleted file mode 100644 (file)
index add57c3..0000000
+++ /dev/null
@@ -1,317 +0,0 @@
-/* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
-// Copyright (c) 2015 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_APP_INSTALLER_H_
-#define COMMON_APP_INSTALLER_H_
-
-#include <manifest_parser/utils/logging.h>
-
-#include <boost/bind.hpp>
-
-#include <list>
-#include <memory>
-#include <string>
-#include <utility>
-
-#include "common/archive_info.h"
-#include "common/pkgmgr_interface.h"
-#include "common/pkgmgr_signal.h"
-#include "common/step/step.h"
-#include "common/utils/file_logbackend.h"
-#include "common/utils/macros.h"
-
-namespace common_installer {
-
-/**
- * \brief Includes the main “steps” processing mechanisms. It holds
- *        the lists of steps and runs each of the step in the configured
- *        order.
- */
-class AppInstaller {
- public:
-  /** Enumeration of possible returned Results */
-  enum class Result {
-    OK,
-    ERROR,
-    CLEANUP_ERROR,
-    UNDO_ERROR,
-    UNKNOWN
-  };
-
-  /**
-   * \brief explicit Constructor
-   *
-   * \param package_type package type
-   * \param pkgmgr pointer to PkgMgrInterface object
-   */
-  explicit AppInstaller(const char* package_type, PkgMgrPtr pkgmgr);
-
-  /** virtual desctructor */
-  virtual ~AppInstaller();
-
-  /**
-   * \brief Adds new step to installer by specified type
-   *        Type of template parameter is used to create requested step
-   *        class instance.
-   *        Context of installer is passed to step in this method
-   *        and is not being exposed outside installer.
-   *        Step arguments are deduced and forwarded to constructor.
-   *
-   * \tparam StepT Step object to be added to the step list
-   * \tparam Args constructor arguments for StepT object
-   * \param args argument list
-   */
-  template<class StepT, class... Args>
-  void AddStep(Args&&... args) {
-    std::unique_ptr<Step> step(
-        new StepT(context_.get(), std::forward<Args>(args)...));
-    step->on_error.connect(
-        boost::bind(&AppInstaller::HandleStepError, this, _1, _2));
-    steps_.emplace_back(std::move(step));
-  }
-
-  /**
-   * \brief Removes specific step in steps list.
-   * \param step_name step name to be removed
-   */
-  void RemoveStep(std::string step_name) {
-    auto it = std::find_if(steps_.begin(), steps_.end(),
-        [&](const std::unique_ptr<Step>& s) {
-          return step_name == s->name();
-        });
-    if (steps_.end() == it) {
-      LOG(ERROR) << "Can't find the step : " << step_name;
-      return;
-    }
-    steps_.erase(it);
-  }
-
-  /**
-   * \brief Adds new step to installer by specified type on specyfic place
-   *        in steps list.
-   *        Type of template parameter is used to create requested step
-   *        class instance.
-   *        Context of installer is passed to step in this method
-   *        and is not being exposed outside installer.
-   *        Step arguments are deduced and forwarded to constructor.
-   *
-   * \tparam StepT Step object to be added to the step list
-   * \tparam index index at which the new step is added
-   * \tparam Args constructor arguments for StepT object
-   * \param args argument list
-   */
-  template<class StepT, class... Args>
-  void AddStepAtIndex(unsigned int index, Args&&... args) {
-    std::unique_ptr<Step> step(
-        new StepT(context_.get(), std::forward<Args>(args)...));
-    step->on_error.connect(
-        boost::bind(&AppInstaller::HandleStepError, this, _1, _2));
-    std::list<std::unique_ptr<Step>> tmpList;
-    tmpList.emplace_back(std::move(step));
-    auto it = steps_.begin();
-    std::advance(it, index);
-    steps_.splice(it, tmpList);
-  }
-
-  /**
-   * \brief Replaces new step to installer by specified type
-   *        Type of template parameter is used to create requested step
-   *        class instance.
-   *        Context of installer is passed to step in this method
-   *        and is not being exposed outside installer.
-   *        Step arguments are deduced and forwarded to constructor.
-   * \tparam StepT Step object to be added to the step list
-   * \tparam Args constructor arguments for StepT object
-   * \param step_name step name to replace
-   * \param args argument list
-   */
-  template<class StepT, class... Args>
-  void ReplaceStep(std::string step_name, Args&&... args) {
-    auto it = std::find_if(std::begin(steps_), std::end(steps_),
-        [&](const std::unique_ptr<Step>& s) {
-          return step_name == s->name();
-        });
-
-    if (steps_.end() == it) {
-      LOG(ERROR) << "Can't find the step : " << step_name;
-      return;
-    }
-
-    std::unique_ptr<Step> step(
-        new StepT(context_.get(), std::forward<Args>(args)...));
-    step->on_error.connect(
-        boost::bind(&AppInstaller::HandleStepError, this, _1, _2));
-    *it = std::move(step);
-  }
-
-  /**
-   * \brief Adds new step before specified step
-   *        Type of template parameter is used to create requested step
-   *        class instance.
-   *        Context of installer is passed to step in this method
-   *        and is not being exposed outside installer.
-   *        Step arguments are deduced and forwarded to constructor.
-   * \tparam StepT Step object to be added to the step list
-   * \tparam Args constructor arguments for StepT object
-   * \param step_name step name to find and add
-   * \param args argument list
-   */
-  template<class StepT, class... Args>
-  void AddStepBefore(std::string step_name, Args&&... args) {
-    auto it = std::find_if(std::begin(steps_), std::end(steps_),
-        [&](const std::unique_ptr<Step>& s) {
-          return step_name == s->name();
-        });
-
-    if (steps_.end() == it) {
-      LOG(ERROR) << "Can't find the step : " << step_name;
-      return;
-    }
-
-    std::unique_ptr<Step> step(
-        new StepT(context_.get(), std::forward<Args>(args)...));
-    step->on_error.connect(
-        boost::bind(&AppInstaller::HandleStepError, this, _1, _2));
-    steps_.insert(it, std::move(step));
-  }
-
-  /**
-   * \brief Adds new step after specified step
-   *        Type of template parameter is used to create requested step
-   *        class instance.
-   *        Context of installer is passed to step in this method
-   *        and is not being exposed outside installer.
-   *        Step arguments are deduced and forwarded to constructor.
-   * \tparam StepT Step object to be added to the step list
-   * \tparam Args constructor arguments for StepT object
-   * \param step_name step name to find and add
-   * \param args argument list
-   */
-  template<class StepT, class... Args>
-  void AddStepAfter(std::string step_name, Args&&... args) {
-    auto it = std::find_if(std::begin(steps_), std::end(steps_),
-        [&](const std::unique_ptr<Step>& s) {
-          return step_name == s->name();
-        });
-
-    if (steps_.end() == it) {
-      LOG(ERROR) << "Can't find the step : " << step_name;
-      return;
-    }
-
-    std::unique_ptr<Step> step(
-        new StepT(context_.get(), std::forward<Args>(args)...));
-    step->on_error.connect(
-        boost::bind(&AppInstaller::HandleStepError, this, _1, _2));
-    steps_.insert(++it, std::move(step));
-  }
-
-  /**
-   * \brief runs the steps in the specific sequence
-   *
-   * \return Result of the run (eg Result:OK)
-   */
-  Result Run();
-
-  /**
-   * \brief runs the process operations of steps
-   *
-   * \return Result of the run (eg Result:OK)
-   */
-  Result Process();
-
-  /**
-   * \brief runs the undo operations of steps
-   *
-   * \return Result of the run (eg Result:OK)
-   */
-  Result Undo();
-
-  /**
-   * \brief runs the clean operations of steps
-   *
-   * \return Result of the run (eg Result:OK)
-   */
-  Result Clean();
-
-  /**
-   * \brief This method can be used to check
-   *        the number of the registered steps.
-   *
-   * \return number of steps registered in app-installer
-   */
-  unsigned int StepCount() {
-    return steps_.size();
-  }
-
-  void SetIndex(int index) {
-    index_ = index;
-  }
-
-  int GetIndex() {
-    return index_;
-  }
-
-  virtual std::unique_ptr<ArchiveInfo> GetArchiveInfo() = 0;
-
- protected:
-  PkgMgrPtr pkgmgr_;
-  std::unique_ptr<InstallerContext> context_;
-
-  virtual void InstallSteps();
-  virtual void UpdateSteps();
-  virtual void UninstallSteps();
-  virtual void ReinstallSteps();
-  virtual void DeltaSteps();
-  virtual void MoveSteps();
-  virtual void RecoverySteps();
-  virtual void MountInstallSteps();
-  virtual void MountUpdateSteps();
-  virtual void ManifestDirectInstallSteps();
-  virtual void ManifestDirectUpdateSteps();
-  virtual void ManifestPartialInstallSteps();
-  virtual void ManifestPartialUpdateSteps();
-  virtual void PartialUninstallSteps();
-  virtual void ReadonlyUpdateInstallSteps();
-  virtual void ReadonlyUpdateUninstallSteps();
-  virtual void DisablePkgSteps();
-  virtual void EnablePkgSteps();
-  virtual void MigrateExtImgSteps();
-  virtual void RecoverDBSteps();
-  virtual void UnknownSteps();
-
- private:
-  void Init();
-
-  std::list<std::unique_ptr<Step>> steps_;
-  std::list<std::unique_ptr<Step>>::iterator it_;
-
-  // data used to send signal
-  std::unique_ptr<PkgmgrSignal> pi_;
-
-  void SendProgress(int progress);
-  void SendFinished(Step::Status status);
-  Step::Status SafeExecute(std::unique_ptr<Step> const& step_ptr,
-                           Step::Status (Step::*method)(),
-                           std::string name);
-  void HandleStepError(Step::Status result, const std::string& error);
-
-  std::shared_ptr<utils::FileLogBackend> failure_logger_;
-  Step::Status status_;
-  Result result_;
-  void LogHistory(bool success);
-
-  int index_;
-
-  friend class InstallerRunner;
-
-  SCOPE_LOG_TAG(AppInstaller)
-
-  DISALLOW_COPY_AND_ASSIGN(AppInstaller);
-};
-
-}  // namespace common_installer
-
-#endif  // COMMON_APP_INSTALLER_H_
index 0d10067fc91f675d6b8dc6bfca9524209f176005..3d578943f357d8c9933cc4fa2f578c91ba794098 100644 (file)
@@ -3,7 +3,7 @@
 // found in the LICENSE file.
 
 #include "common/app_query_interface.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/utils/file_util.h"
 
 namespace bf = boost::filesystem;
index b02664a7c25348b37744052f430b79488d58130c..b9be5e165e3551786a53a0c82ef860afbba31c88 100644 (file)
@@ -15,7 +15,7 @@
 #include <utility>
 
 #include "common/archive_info.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 
 using Dependency = std::tuple<std::string, std::string, std::string>;
 
index b42cd6d4b280c91bb5c71d29a4711f844c06684b..7d86518f442ebf9df22535020a2d0ba671d79798 100644 (file)
@@ -13,7 +13,7 @@
 #include <tuple>
 #include <vector>
 
-#include "common/app_installer.h"
+#include "common/installer/app_installer.h"
 #include "common/pkgmgr_interface.h"
 
 namespace common_installer {
index ebd0a26bc28bb745c2908f541ed6d4f88d17ff81..525bbc480f6f88fed7ca87a81c7bcd6b947c10e6 100644 (file)
@@ -10,8 +10,8 @@
 #include <boost/filesystem/operations.hpp>
 #include <boost/filesystem/path.hpp>
 
-#include "common/paths.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
+#include "common/utils/paths.h"
 
 namespace bf = boost::filesystem;
 
index 68be0112819eb488c59b4d5567783cd4649f3cef..a70c101e609c31b359faadd40e67da3cf424ae72 100644 (file)
@@ -8,9 +8,9 @@
 
 #include <manifest_parser/utils/logging.h>
 
-#include "common/request.h"
 #include "common/utils/byte_size_literals.h"
 #include "common/utils/file_util.h"
+#include "common/utils/request.h"
 
 namespace bf = boost::filesystem;
 
index 31ca0d614b6601e927b8a673003bde9e81014d9c..f9a70b339e336c35190b49a8d3ac2d71065d6034 100644 (file)
@@ -14,8 +14,8 @@
 #include <string>
 #include <vector>
 
-#include "common/request.h"
 #include "common/app2ext_dynamic_service.h"
+#include "common/utils/request.h"
 
 namespace common_installer {
 
diff --git a/src/common/installer/app_installer.cc b/src/common/installer/app_installer.cc
new file mode 100644 (file)
index 0000000..5c1b468
--- /dev/null
@@ -0,0 +1,870 @@
+/* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
+// Copyright (c) 2015 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.
+
+#include <unistd.h>
+
+#include <cstdio>
+#include <fstream>
+#include <TTraceWrapper.h>
+
+#include "common/installer/app_installer.h"
+#include "common/installer_context.h"
+#include "common/pkgmgr_interface.h"
+#include "common/pkgmgr_signal.h"
+#include "common/step/configuration/step_fail.h"
+#include "common/utils/file_logbackend.h"
+
+#include "common/step/backup/step_backup_icons.h"
+#include "common/step/backup/step_backup_manifest.h"
+#include "common/step/backup/step_copy_backup.h"
+#include "common/step/configuration/step_block_cross_update.h"
+#include "common/step/configuration/step_check_install_location.h"
+#include "common/step/configuration/step_check_tizen_version.h"
+#include "common/step/configuration/step_configure.h"
+#include "common/step/configuration/step_parse_manifest.h"
+#include "common/step/configuration/step_parse_preload.h"
+#include "common/step/configuration/step_switch_readonly_mode.h"
+#include "common/step/filesystem/step_acquire_external_storage.h"
+#include "common/step/filesystem/step_change_ownership_and_permission.h"
+#include "common/step/filesystem/step_copy.h"
+#include "common/step/filesystem/step_copy_storage_directories.h"
+#include "common/step/filesystem/step_copy_tep.h"
+#include "common/step/filesystem/step_create_globalapp_symlinks.h"
+#include "common/step/filesystem/step_create_icons.h"
+#include "common/step/filesystem/step_create_storage_directories.h"
+#include "common/step/filesystem/step_delta_patch.h"
+#include "common/step/filesystem/step_disable_external_mount.h"
+#include "common/step/filesystem/step_enable_external_mount.h"
+#include "common/step/filesystem/step_migrate_legacy_external_image.h"
+#include "common/step/filesystem/step_move_installed_storage.h"
+#include "common/step/filesystem/step_optional_acquire_external_storage.h"
+#include "common/step/filesystem/step_recover_change_owner.h"
+#include "common/step/filesystem/step_recover_external_storage.h"
+#include "common/step/filesystem/step_recover_files.h"
+#include "common/step/filesystem/step_recover_globalapp_symlinks.h"
+#include "common/step/filesystem/step_recover_icons.h"
+#include "common/step/filesystem/step_recover_manifest.h"
+#include "common/step/filesystem/step_recover_storage_directories.h"
+#include "common/step/filesystem/step_remove_files.h"
+#include "common/step/filesystem/step_remove_icons.h"
+#include "common/step/filesystem/step_remove_globalapp_symlinks.h"
+#include "common/step/filesystem/step_remove_per_user_storage_directories.h"
+#include "common/step/filesystem/step_remove_temporary_directory.h"
+#include "common/step/filesystem/step_remove_tep.h"
+#include "common/step/filesystem/step_remove_user_data.h"
+#include "common/step/filesystem/step_remove_zip_image.h"
+#include "common/step/filesystem/step_unzip.h"
+#include "common/step/filesystem/step_update_storage_directories.h"
+#include "common/step/filesystem/step_update_tep.h"
+#include "common/step/mount/step_check_mount_path.h"
+#include "common/step/mount/step_mount_install.h"
+#include "common/step/mount/step_mount_recover.h"
+#include "common/step/mount/step_mount_unpacked.h"
+#include "common/step/mount/step_mount_update.h"
+#include "common/step/mount/step_unmount.h"
+#include "common/step/pkgmgr/step_check_force_clean.h"
+#include "common/step/pkgmgr/step_check_installable.h"
+#include "common/step/pkgmgr/step_check_removable.h"
+#include "common/step/pkgmgr/step_check_restriction.h"
+#include "common/step/pkgmgr/step_check_upgradable.h"
+#include "common/step/pkgmgr/step_kill_apps.h"
+#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_remove_manifest.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"
+#include "common/step/pkgmgr/step_update_pkg_disable_info.h"
+#include "common/step/rds/step_rds_modify.h"
+#include "common/step/rds/step_rds_parse.h"
+#include "common/step/recovery/step_create_recovery_file.h"
+#include "common/step/recovery/step_open_recovery_file.h"
+#include "common/step/security/step_check_old_certificate.h"
+#include "common/step/security/step_get_privilege_level.h"
+#include "common/step/security/step_privacy_privilege.h"
+#include "common/step/security/step_recover_security.h"
+#include "common/step/security/step_recover_trust_anchor.h"
+#include "common/step/security/step_register_security.h"
+#include "common/step/security/step_register_trust_anchor.h"
+#include "common/step/security/step_revoke_security.h"
+#include "common/step/security/step_revoke_trust_anchor.h"
+#include "common/step/security/step_rollback_installation_security.h"
+#include "common/step/security/step_signature.h"
+#include "common/step/security/step_unregister_trust_anchor.h"
+#include "common/step/security/step_update_security.h"
+
+namespace ci = common_installer;
+
+namespace {
+
+const unsigned kProgressRange = 100;
+const char kLogFileName[] = LOGDIR"/app-installers.log";
+const char kHistoryFileName[] = LOGDIR"/installation-history.log";
+const int kLogRotationSize = 1024 * 256;  // 256KB
+const int kLogMaximumRotation = 3;
+
+}
+
+namespace common_installer {
+
+AppInstaller::AppInstaller(const char* package_type, PkgMgrPtr pkgmgr)
+    : pkgmgr_(pkgmgr), context_(new InstallerContext()),
+      status_(Step::Status::OK), result_(Result::OK), index_(0) {
+  context_->pkg_type.set(package_type);
+  context_->installation_mode.set(pkgmgr->GetInstallationMode());
+
+  // pkgmgr signal should work only for online mode
+  // there is no one to receive it in offline mode
+  if (context_->installation_mode.get() == InstallationMode::ONLINE) {
+    pi_ = pkgmgr->CreatePkgmgrSignal();
+  }
+}
+
+AppInstaller::~AppInstaller() {
+}
+
+void AppInstaller::Init() {
+  // for multi installer
+  context_->index.set(index_);
+  pkgmgr_->SetAppQueryInterface(index_);
+
+  switch (pkgmgr_->GetRequestType(index_)) {
+    case RequestType::Install:
+      InstallSteps();
+      break;
+    case RequestType::Update:
+      UpdateSteps();
+      break;
+    case RequestType::Uninstall:
+      UninstallSteps();
+      break;
+    case RequestType::Reinstall:
+      ReinstallSteps();
+      break;
+    case RequestType::Delta:
+      DeltaSteps();
+      break;
+    case RequestType::Move:
+      MoveSteps();
+      break;
+    case RequestType::Recovery:
+      RecoverySteps();
+      break;
+    case RequestType::MountInstall:
+      MountInstallSteps();
+      break;
+    case RequestType::MountUpdate:
+      MountUpdateSteps();
+      break;
+    case RequestType::ManifestDirectInstall:
+      ManifestDirectInstallSteps();
+      break;
+    case RequestType::ManifestDirectUpdate:
+      ManifestDirectUpdateSteps();
+      break;
+    case RequestType::ManifestPartialInstall:
+      ManifestPartialInstallSteps();
+      break;
+    case RequestType::ManifestPartialUpdate:
+      ManifestPartialUpdateSteps();
+      break;
+    case RequestType::PartialUninstall:
+      PartialUninstallSteps();
+      break;
+    case RequestType::ReadonlyUpdateInstall:
+      ReadonlyUpdateInstallSteps();
+      break;
+    case RequestType::ReadonlyUpdateUninstall:
+      ReadonlyUpdateUninstallSteps();
+      break;
+    case RequestType::EnablePkg:
+      EnablePkgSteps();
+      break;
+    case RequestType::DisablePkg:
+      DisablePkgSteps();
+      break;
+    case RequestType::MigrateExtImg:
+      MigrateExtImgSteps();
+      break;
+    case RequestType::RecoverDB:
+      RecoverDBSteps();
+      break;
+    default:
+      UnknownSteps();
+      break;
+  }
+}
+
+AppInstaller::Result AppInstaller::Run() {
+  Process();
+  if (it_ != steps_.end() && result_ == Result::ERROR) {
+    LOG(ERROR) << "Failure occurs in step: " << (*it_)->name();
+    Undo();
+  } else {
+    Clean();
+  }
+  sync();
+
+  if ((context_->installation_mode.get() == InstallationMode::OFFLINE) &&
+      (result_ == Result::ERROR)) {
+    std::fstream info_file("/tmp/.preload_install_error",
+        std::ios::out | std::ios::app);
+    info_file << context_->pkgid.get() << std::endl;
+    info_file.close();
+  }
+
+  return result_;
+}
+
+void AppInstaller::LogHistory(bool success) {
+  std::shared_ptr<utils::FileLogBackend> history_logger =
+      std::shared_ptr<utils::FileLogBackend>(new utils::FileLogBackend(
+          kHistoryFileName, kLogRotationSize, kLogMaximumRotation));
+  std::string history = "pkgid:" + context_->pkgid.get() + "|mode:" +
+      GetRequestTypeString(context_->request_type.get());
+  if (success)
+    history += "|SUCCESS";
+  else
+    history += "|FAIL";
+  history_logger->WriteLog(::utils::LogLevel::LOG_INFO, "", history);
+  history_logger->WriteLogToFile();
+}
+
+AppInstaller::Result AppInstaller::Process() {
+  Init();
+
+  failure_logger_ =
+      std::shared_ptr<utils::FileLogBackend>(new utils::FileLogBackend(
+            kLogFileName, kLogRotationSize, kLogMaximumRotation));
+  ::utils::LogCore::GetCore().AddLogBackend(failure_logger_);
+
+  unsigned total_steps = steps_.size();
+  unsigned current_step = 1;
+
+  for (it_ = steps_.begin(); it_ != steps_.end(); ++it_, ++current_step) {
+    status_ = SafeExecute(*it_, &Step::precheck, "precheck");
+    if (status_ == Step::Status::OK)
+      status_ = SafeExecute(*it_, &Step::process, "process");
+
+    if (status_ != Step::Status::OK) {
+      if (status_ != Step::Status::RECOVERY_DONE) {
+        LOG(ERROR) << "Error during processing";
+        result_ = Result::ERROR;
+      }
+      break;
+    }
+    SendProgress(current_step * kProgressRange / total_steps);
+  }
+
+  return result_;
+}
+
+AppInstaller::Result AppInstaller::Undo() {
+  do {
+    if (it_ == steps_.end())
+      --it_;
+    if (SafeExecute(*it_, &Step::undo, "undo") != Step::Status::OK) {
+      LOG(ERROR) << "Error during undo operation(" << (*it_)->name()
+                 << "), but continuing...";
+      result_ = Result::UNDO_ERROR;
+    }
+  } while (it_-- != steps_.begin());
+  sync();
+  failure_logger_->WriteLogToFile();
+
+  // Undo will be invoked when other installer fails when multi-install, but the
+  // status of current installer can be ok. We need to change this to proper
+  // error code to notify that entire installation was failed to listener.
+  // TODO(jeremy.jang): Need some other error for multi-install failure?
+  if (status_ == Step::Status::OK)
+    status_ = Step::Status::ERROR;
+  SendFinished(status_);
+
+  LogHistory(false);
+
+  return result_;
+}
+
+AppInstaller::Result AppInstaller::Clean() {
+  const auto& recovery_file =
+    context_->recovery_info.get().recovery_file;
+  if (recovery_file) {
+    recovery_file->set_cleanup(true);
+    recovery_file->WriteAndCommitFileContent();
+  }
+  SendFinished(status_);
+
+  do {
+    if (it_ == steps_.end())
+      --it_;
+    if (SafeExecute(*it_, &Step::clean, "clean") != Step::Status::OK) {
+      LOG(ERROR) << "Error during clean operation(" << (*it_)->name() << ")";
+      result_ = Result::CLEANUP_ERROR;
+      break;
+    }
+  } while (it_-- != steps_.begin());
+  sync();
+
+  LogHistory(true);
+
+  return result_;
+}
+
+void AppInstaller::InstallSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::recovery::StepCreateRecoveryFile>();
+  AddStep<ci::filesystem::StepUnzip>();
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::PACKAGE,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::configuration::StepCheckInstallLocation>();
+  AddStep<ci::pkgmgr::StepCheckInstallable>();
+  AddStep<ci::configuration::StepParsePreload>();
+  AddStep<ci::pkgmgr::StepCheckRestriction>();
+  AddStep<ci::configuration::StepCheckTizenVersion>();
+  AddStep<ci::security::StepSignature>(true);
+  AddStep<ci::security::StepRollbackInstallationSecurity>();
+  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
+  AddStep<ci::filesystem::StepAcquireExternalStorage>(false);
+  AddStep<ci::filesystem::StepCopy>();
+  AddStep<ci::filesystem::StepCopyTep>();
+  AddStep<ci::filesystem::StepCreateIcons>();
+  AddStep<ci::pkgmgr::StepRegisterApplication>();
+  AddStep<ci::security::StepRegisterTrustAnchor>(
+      ci::security::StepRegisterTrustAnchor::RegisterType::INSTALL);
+  AddStep<ci::security::StepPrivacyPrivilege>(
+      ci::security::StepPrivacyPrivilege::ActionType::Install);
+  AddStep<ci::security::StepRegisterSecurity>();
+  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Install);
+  AddStep<ci::filesystem::StepCreateStorageDirectories>();
+  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>();
+  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
+}
+
+void AppInstaller::UpdateSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::recovery::StepCreateRecoveryFile>();
+  AddStep<ci::filesystem::StepUnzip>();
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::PACKAGE,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
+      ci::configuration::StepParseManifest::StoreLocation::BACKUP);
+  AddStep<ci::configuration::StepCheckInstallLocation>();
+  AddStep<ci::pkgmgr::StepCheckUpgradable>();
+  AddStep<ci::configuration::StepParsePreload>();
+  AddStep<ci::configuration::StepCheckTizenVersion>();
+  AddStep<ci::security::StepSignature>(true);
+  AddStep<ci::security::StepCheckOldCertificate>();
+  AddStep<ci::configuration::StepBlockCrossUpdate>();
+  AddStep<ci::pkgmgr::StepKillApps>();
+  AddStep<ci::backup::StepBackupManifest>();
+  AddStep<ci::backup::StepBackupIcons>();
+  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
+  AddStep<ci::filesystem::StepAcquireExternalStorage>(true);
+  AddStep<ci::security::StepRevokeTrustAnchor>();
+  AddStep<ci::backup::StepCopyBackup>();
+  AddStep<ci::filesystem::StepUpdateTep>();
+  AddStep<ci::filesystem::StepCopyStorageDirectories>();
+  AddStep<ci::filesystem::StepCreateIcons>();
+  AddStep<ci::pkgmgr::StepUpdateApplication>();
+  AddStep<ci::security::StepRegisterTrustAnchor>(
+      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
+  AddStep<ci::security::StepPrivacyPrivilege>(
+      ci::security::StepPrivacyPrivilege::ActionType::Update);
+  AddStep<ci::security::StepUpdateSecurity>();
+  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
+  AddStep<ci::filesystem::StepUpdateStorageDirectories>();
+  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>();
+  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
+}
+
+void AppInstaller::UninstallSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::recovery::StepCreateRecoveryFile>();
+  AddStep<ci::pkgmgr::StepCheckRestriction>();
+  AddStep<ci::pkgmgr::StepCheckRemovable>();
+  AddStep<ci::pkgmgr::StepCheckForceClean>();
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::configuration::StepCheckInstallLocation>();
+  AddStep<ci::pkgmgr::StepKillApps>();
+  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Uninstall);
+  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
+  AddStep<ci::filesystem::StepOptionalAcquireExternalStorage>();
+  AddStep<ci::filesystem::StepRemovePerUserStorageDirectories>();
+  AddStep<ci::pkgmgr::StepUnregisterApplication>();
+  AddStep<ci::security::StepUnregisterTrustAnchor>();
+  AddStep<ci::security::StepPrivacyPrivilege>(
+      ci::security::StepPrivacyPrivilege::ActionType::Uninstall);
+  AddStep<ci::filesystem::StepRemoveFiles>();
+  AddStep<ci::filesystem::StepRemoveZipImage>();
+  AddStep<ci::filesystem::StepRemoveIcons>();
+  AddStep<ci::filesystem::StepRemoveTep>();
+  AddStep<ci::security::StepRevokeSecurity>();
+  AddStep<ci::pkgmgr::StepRemoveManifest>();
+  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
+}
+
+void AppInstaller::ReinstallSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::PACKAGE,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
+      ci::configuration::StepParseManifest::StoreLocation::BACKUP);
+  AddStep<ci::configuration::StepCheckInstallLocation>();
+  AddStep<ci::pkgmgr::StepCheckUpgradable>();
+  AddStep<ci::configuration::StepParsePreload>();
+  AddStep<ci::configuration::StepCheckTizenVersion>();
+  AddStep<ci::security::StepSignature>(true);
+  AddStep<ci::security::StepCheckOldCertificate>();
+  AddStep<ci::configuration::StepBlockCrossUpdate>();
+  AddStep<ci::pkgmgr::StepKillApps>();
+  AddStep<ci::backup::StepBackupManifest>();
+  AddStep<ci::backup::StepBackupIcons>();
+  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
+  AddStep<ci::security::StepRevokeTrustAnchor>();
+  AddStep<ci::rds::StepRDSParse>();
+  AddStep<ci::rds::StepRDSModify>();
+  AddStep<ci::filesystem::StepUpdateTep>();
+  AddStep<ci::filesystem::StepCreateIcons>();
+  AddStep<ci::pkgmgr::StepUpdateApplication>();
+  AddStep<ci::security::StepRegisterTrustAnchor>(
+      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
+  AddStep<ci::security::StepPrivacyPrivilege>(
+      ci::security::StepPrivacyPrivilege::ActionType::Update);
+  AddStep<ci::security::StepUpdateSecurity>();
+  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
+  AddStep<ci::filesystem::StepUpdateStorageDirectories>();
+  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>();
+  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
+}
+
+void AppInstaller::DeltaSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::recovery::StepCreateRecoveryFile>();
+  AddStep<ci::filesystem::StepUnzip>();
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::PACKAGE,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
+      ci::configuration::StepParseManifest::StoreLocation::BACKUP);
+  AddStep<ci::configuration::StepCheckInstallLocation>();
+  AddStep<ci::pkgmgr::StepCheckUpgradable>();
+  AddStep<ci::configuration::StepParsePreload>();
+  AddStep<ci::configuration::StepCheckTizenVersion>();
+  AddStep<ci::filesystem::StepEnableExternalMount>();
+  AddStep<ci::filesystem::StepDeltaPatch>();
+  AddStep<ci::filesystem::StepDisableExternalMount>();
+  AddStep<ci::security::StepSignature>(true);
+  AddStep<ci::security::StepCheckOldCertificate>();
+  AddStep<ci::configuration::StepBlockCrossUpdate>();
+  AddStep<ci::pkgmgr::StepKillApps>();
+  AddStep<ci::backup::StepBackupManifest>();
+  AddStep<ci::backup::StepBackupIcons>();
+  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
+  AddStep<ci::filesystem::StepAcquireExternalStorage>(true);
+  AddStep<ci::security::StepRevokeTrustAnchor>();
+  AddStep<ci::backup::StepCopyBackup>();
+  AddStep<ci::filesystem::StepUpdateTep>();
+  AddStep<ci::filesystem::StepCopyStorageDirectories>();
+  AddStep<ci::filesystem::StepCreateIcons>();
+  AddStep<ci::pkgmgr::StepUpdateApplication>();
+  AddStep<ci::security::StepRegisterTrustAnchor>(
+      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
+  AddStep<ci::security::StepPrivacyPrivilege>(
+      ci::security::StepPrivacyPrivilege::ActionType::Update);
+  AddStep<ci::security::StepUpdateSecurity>();
+  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
+  AddStep<ci::filesystem::StepUpdateStorageDirectories>();
+  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>();
+  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
+}
+
+void AppInstaller::MoveSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::pkgmgr::StepCheckRestriction>();
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::configuration::StepCheckInstallLocation>();
+  AddStep<ci::pkgmgr::StepKillApps>();
+  AddStep<ci::filesystem::StepMoveInstalledStorage>();
+  AddStep<ci::security::StepRegisterSecurity>();
+}
+
+void AppInstaller::RecoverySteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::recovery::StepOpenRecoveryFile>();
+  AddStep<ci::filesystem::StepRemoveTemporaryDirectory>();
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::RECOVERY,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::filesystem::StepRecoverIcons>();
+  AddStep<ci::pkgmgr::StepRecoverParserPlugin>();
+  AddStep<ci::filesystem::StepRecoverManifest>();
+  AddStep<ci::filesystem::StepRecoverExternalStorage>();
+  AddStep<ci::filesystem::StepRecoverStorageDirectories>();
+  AddStep<ci::filesystem::StepRecoverGlobalAppSymlinks>();
+  AddStep<ci::filesystem::StepRecoverFiles>();
+  AddStep<ci::mount::StepMountRecover>();
+  AddStep<ci::filesystem::StepRecoverChangeOwner>();
+  AddStep<ci::pkgmgr::StepRecoverApplication>();
+  AddStep<ci::security::StepRecoverTrustAnchor>();
+  AddStep<ci::security::StepRecoverSecurity>();
+}
+
+void AppInstaller::MountInstallSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::recovery::StepCreateRecoveryFile>();
+  AddStep<ci::mount::StepMountUnpacked>();
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::PACKAGE,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::configuration::StepCheckInstallLocation>();
+  AddStep<ci::pkgmgr::StepCheckInstallable>();
+  AddStep<ci::configuration::StepParsePreload>();
+  AddStep<ci::pkgmgr::StepCheckRestriction>();
+  AddStep<ci::configuration::StepCheckTizenVersion>();
+  AddStep<ci::security::StepSignature>(true);
+  AddStep<ci::security::StepRollbackInstallationSecurity>();
+  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
+  AddStep<ci::mount::StepMountInstall>();
+  AddStep<ci::filesystem::StepCopyTep>();
+  AddStep<ci::filesystem::StepCreateIcons>();
+  AddStep<ci::pkgmgr::StepRegisterApplication>();
+  AddStep<ci::security::StepRegisterTrustAnchor>(
+      ci::security::StepRegisterTrustAnchor::RegisterType::INSTALL);
+  AddStep<ci::security::StepPrivacyPrivilege>(
+      ci::security::StepPrivacyPrivilege::ActionType::Install);
+  AddStep<ci::security::StepRegisterSecurity>();
+  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Install);
+  AddStep<ci::mount::StepUnmount>();
+  AddStep<ci::filesystem::StepCreateStorageDirectories>();
+  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>(true);
+  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
+}
+
+void AppInstaller::MountUpdateSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::recovery::StepCreateRecoveryFile>();
+  AddStep<ci::mount::StepMountUnpacked>();
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::PACKAGE,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
+      ci::configuration::StepParseManifest::StoreLocation::BACKUP);
+  AddStep<ci::configuration::StepCheckInstallLocation>();
+  AddStep<ci::pkgmgr::StepCheckUpgradable>();
+  AddStep<ci::configuration::StepParsePreload>();
+  AddStep<ci::configuration::StepCheckTizenVersion>();
+  AddStep<ci::security::StepSignature>(true);
+  AddStep<ci::security::StepCheckOldCertificate>();
+  AddStep<ci::configuration::StepBlockCrossUpdate>();
+  AddStep<ci::security::StepRevokeTrustAnchor>();
+  AddStep<ci::pkgmgr::StepKillApps>();
+  AddStep<ci::backup::StepBackupManifest>();
+  AddStep<ci::backup::StepBackupIcons>();
+  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
+  AddStep<ci::mount::StepMountUpdate>();
+  AddStep<ci::filesystem::StepUpdateTep>();
+  AddStep<ci::filesystem::StepCreateIcons>();
+  AddStep<ci::pkgmgr::StepUpdateApplication>();
+  AddStep<ci::security::StepRegisterTrustAnchor>(
+      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
+  AddStep<ci::security::StepPrivacyPrivilege>(
+      ci::security::StepPrivacyPrivilege::ActionType::Update);
+  AddStep<ci::security::StepUpdateSecurity>();
+  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
+  AddStep<ci::mount::StepUnmount>();
+  AddStep<ci::filesystem::StepUpdateStorageDirectories>();
+  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>(true);
+  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
+}
+
+void AppInstaller::ManifestDirectInstallSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::pkgmgr::StepCheckInstallable>();
+  AddStep<ci::mount::StepCheckMountPath>();
+  AddStep<ci::configuration::StepParsePreload>();
+  AddStep<ci::configuration::StepCheckTizenVersion>();
+  AddStep<ci::security::StepSignature>(true);
+  AddStep<ci::security::StepRollbackInstallationSecurity>();
+  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
+  AddStep<ci::pkgmgr::StepRegisterApplication>();
+  AddStep<ci::security::StepRegisterTrustAnchor>(
+      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
+  AddStep<ci::security::StepPrivacyPrivilege>(
+      ci::security::StepPrivacyPrivilege::ActionType::Install);
+  AddStep<ci::security::StepRegisterSecurity>();
+  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Install);
+  AddStep<ci::filesystem::StepCreateStorageDirectories>();
+  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>();
+  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
+}
+
+void AppInstaller::ManifestDirectUpdateSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::pkgmgr::StepCheckUpgradable>();
+  AddStep<ci::mount::StepCheckMountPath>();
+  AddStep<ci::configuration::StepParsePreload>();
+  AddStep<ci::configuration::StepCheckTizenVersion>();
+  AddStep<ci::security::StepSignature>(true);
+  AddStep<ci::security::StepCheckOldCertificate>();
+  AddStep<ci::pkgmgr::StepKillApps>();
+  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
+  AddStep<ci::pkgmgr::StepUpdateApplication>();
+  AddStep<ci::security::StepRegisterTrustAnchor>(
+      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
+  AddStep<ci::security::StepPrivacyPrivilege>(
+      ci::security::StepPrivacyPrivilege::ActionType::Update);
+  AddStep<ci::security::StepRegisterSecurity>();
+  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
+  AddStep<ci::filesystem::StepUpdateStorageDirectories>();
+  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>();
+  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
+}
+
+void AppInstaller::ManifestPartialInstallSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::configuration::StepParsePreload>();
+  AddStep<ci::security::StepSignature>(false);
+  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
+  AddStep<ci::pkgmgr::StepRegisterApplication>();
+  AddStep<ci::security::StepRegisterTrustAnchor>(
+      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
+  AddStep<ci::security::StepPrivacyPrivilege>(
+      ci::security::StepPrivacyPrivilege::ActionType::Install);
+  AddStep<ci::security::StepRegisterSecurity>();
+  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Install);
+  AddStep<ci::filesystem::StepCreateStorageDirectories>();
+  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
+}
+
+void AppInstaller::ManifestPartialUpdateSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::configuration::StepParsePreload>();
+  AddStep<ci::security::StepSignature>(false);
+  AddStep<ci::security::StepCheckOldCertificate>();
+  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
+  AddStep<ci::pkgmgr::StepKillApps>();
+  AddStep<ci::pkgmgr::StepUpdateApplication>();
+  AddStep<ci::security::StepRegisterTrustAnchor>(
+      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
+  AddStep<ci::security::StepPrivacyPrivilege>(
+      ci::security::StepPrivacyPrivilege::ActionType::Update);
+  AddStep<ci::security::StepRegisterSecurity>();
+  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
+  AddStep<ci::filesystem::StepUpdateStorageDirectories>();
+  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
+}
+
+void AppInstaller::PartialUninstallSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::pkgmgr::StepCheckRemovable>();
+  AddStep<ci::pkgmgr::StepCheckForceClean>();
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::configuration::StepCheckInstallLocation>();
+  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
+  AddStep<ci::filesystem::StepOptionalAcquireExternalStorage>();
+  AddStep<ci::filesystem::StepRemovePerUserStorageDirectories>();
+  AddStep<ci::pkgmgr::StepUnregisterApplication>();
+  AddStep<ci::security::StepUnregisterTrustAnchor>();
+  AddStep<ci::security::StepPrivacyPrivilege>(
+      ci::security::StepPrivacyPrivilege::ActionType::Uninstall);
+  AddStep<ci::security::StepRevokeSecurity>();
+  AddStep<ci::pkgmgr::StepRunParserPlugin>(
+      ci::Plugin::ActionType::Uninstall);
+}
+
+void AppInstaller::ReadonlyUpdateInstallSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::recovery::StepCreateRecoveryFile>();
+  AddStep<ci::filesystem::StepUnzip>();
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::PACKAGE,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::configuration::StepSwitchReadonlyMode>();
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
+      ci::configuration::StepParseManifest::StoreLocation::BACKUP);
+  AddStep<ci::configuration::StepSwitchReadonlyMode>();
+  AddStep<ci::configuration::StepCheckInstallLocation>();
+  AddStep<ci::pkgmgr::StepCheckUpgradable>();
+  AddStep<ci::configuration::StepParsePreload>();
+  AddStep<ci::configuration::StepCheckTizenVersion>();
+  AddStep<ci::security::StepSignature>(true);
+  AddStep<ci::security::StepCheckOldCertificate>();
+  AddStep<ci::configuration::StepBlockCrossUpdate>();
+  AddStep<ci::pkgmgr::StepKillApps>();
+  AddStep<ci::security::StepRevokeTrustAnchor>();
+  AddStep<ci::filesystem::StepCopy>();
+  AddStep<ci::filesystem::StepCopyTep>();
+  AddStep<ci::filesystem::StepCreateIcons>();
+  AddStep<ci::pkgmgr::StepUpdateApplication>();
+  AddStep<ci::security::StepRegisterTrustAnchor>(
+      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
+  AddStep<ci::security::StepPrivacyPrivilege>(
+      ci::security::StepPrivacyPrivilege::ActionType::Update);
+  AddStep<ci::security::StepUpdateSecurity>();
+  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
+  AddStep<ci::filesystem::StepUpdateStorageDirectories>();
+  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>();
+  AddStep<ci::filesystem::StepCreateGlobalAppSymlinks>();
+}
+
+void AppInstaller::ReadonlyUpdateUninstallSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
+      ci::configuration::StepParseManifest::StoreLocation::BACKUP);
+  AddStep<ci::configuration::StepSwitchReadonlyMode>();
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::pkgmgr::StepCheckUpgradable>();
+  AddStep<ci::configuration::StepParsePreload>();
+  AddStep<ci::security::StepSignature>(false);
+  AddStep<ci::configuration::StepSwitchReadonlyMode>();
+  AddStep<ci::pkgmgr::StepKillApps>();
+  AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
+  AddStep<ci::security::StepRevokeTrustAnchor>();
+  AddStep<ci::pkgmgr::StepUpdateApplication>();
+  AddStep<ci::security::StepRegisterTrustAnchor>(
+      ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
+  AddStep<ci::security::StepPrivacyPrivilege>(
+      ci::security::StepPrivacyPrivilege::ActionType::Update);
+  AddStep<ci::filesystem::StepRemoveFiles>();
+  AddStep<ci::filesystem::StepRemoveZipImage>();
+  AddStep<ci::filesystem::StepRemoveIcons>();
+  AddStep<ci::filesystem::StepRemoveTep>();
+  AddStep<ci::filesystem::StepRemoveUserData>();
+  AddStep<ci::configuration::StepSwitchReadonlyMode>();
+  AddStep<ci::security::StepUpdateSecurity>();
+  AddStep<ci::pkgmgr::StepRemoveManifest>();
+  AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
+  AddStep<ci::filesystem::StepUpdateStorageDirectories>();
+}
+
+void AppInstaller::DisablePkgSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::pkgmgr::StepKillApps>();
+  AddStep<ci::pkgmgr::StepUpdatePkgDisableInfo>(
+    ci::pkgmgr::StepUpdatePkgDisableInfo::ActionType::Disable);
+  AddStep<ci::pkgmgr::StepRunParserPlugin>(
+    ci::Plugin::ActionType::Uninstall);
+}
+
+void AppInstaller::EnablePkgSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::pkgmgr::StepUpdatePkgDisableInfo>(
+    ci::pkgmgr::StepUpdatePkgDisableInfo::ActionType::Enable);
+  AddStep<ci::pkgmgr::StepRunParserPlugin>(
+    ci::Plugin::ActionType::Install);
+}
+
+void AppInstaller::MigrateExtImgSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::security::StepMigrateLegacyExtImage>();
+  AddStep<ci::filesystem::StepChangeOwnershipAndPermission>();
+}
+
+void AppInstaller::RecoverDBSteps() {
+  AddStep<ci::configuration::StepConfigure>(pkgmgr_);
+  AddStep<ci::configuration::StepParseManifest>(
+      ci::configuration::StepParseManifest::ManifestLocation::INSTALLED,
+      ci::configuration::StepParseManifest::StoreLocation::NORMAL);
+  AddStep<ci::pkgmgr::StepCheckInstallable>();
+  AddStep<ci::mount::StepCheckMountPath>();
+  AddStep<ci::configuration::StepParsePreload>();
+  AddStep<ci::security::StepGetPrivilegeLevel>();
+  AddStep<ci::pkgmgr::StepRegisterApplication>();
+}
+
+void AppInstaller::UnknownSteps() {
+  AddStep<configuration::StepFail>();
+}
+
+void AppInstaller::HandleStepError(Step::Status result,
+                                        const std::string& error) {
+  if (pi_)
+    pi_->SendError(result, error, context_->pkg_type.get(),
+                   context_->pkgid.get());
+}
+
+void AppInstaller::SendProgress(int progress) {
+  if (pi_) {
+    // send START signal as soon as possible if not sent
+    if (pi_->state() == PkgmgrSignal::State::NOT_SENT) {
+      if (!context_->pkgid.get().empty()) {
+        // set request type before sending start signal
+        pi_->SetRequestType(context_->request_type.get());
+        pi_->SendStarted(context_->pkg_type.get(), context_->pkgid.get());
+      }
+    }
+
+    // send installation progress
+    pi_->SendProgress(progress,
+        context_->pkg_type.get(), context_->pkgid.get());
+  }
+}
+
+void AppInstaller::SendFinished(Step::Status process_status) {
+  if (pi_) {
+    // send START if pkgid was not parsed
+    if (pi_->state() == PkgmgrSignal::State::NOT_SENT) {
+      // set request type before sending start signal
+      pi_->SetRequestType(context_->request_type.get());
+      pi_->SendStarted(context_->pkg_type.get(), context_->pkgid.get());
+    }
+    pi_->SendFinished(process_status,
+                      context_->pkg_type.get(),
+                      context_->pkgid.get());
+  }
+}
+
+Step::Status AppInstaller::SafeExecute(std::unique_ptr<Step> const& step_ptr,
+                                       Step::Status (Step::*method)(),
+                                       std::string name) {
+  Step::Status process_status = Step::Status::OK;
+  try {
+    TTRACE(TTRACE_TAG_APP, "%s_%s", step_ptr->name(), name.c_str());
+    process_status = ((*step_ptr).*method)();
+  } catch (const std::exception& err) {
+    LOG(ERROR) << "Exception occurred in " << name.c_str() << "(): "
+               << err.what() << " in step: " << step_ptr->name();
+    process_status = Step::Status::ERROR;
+  }
+  return process_status;
+}
+
+}  // namespace common_installer
diff --git a/src/common/installer/app_installer.h b/src/common/installer/app_installer.h
new file mode 100644 (file)
index 0000000..ad2b8ea
--- /dev/null
@@ -0,0 +1,317 @@
+/* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
+// Copyright (c) 2015 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_INSTALLER_APP_INSTALLER_H_
+#define COMMON_INSTALLER_APP_INSTALLER_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include <boost/bind.hpp>
+
+#include <list>
+#include <memory>
+#include <string>
+#include <utility>
+
+#include "common/archive_info.h"
+#include "common/pkgmgr_interface.h"
+#include "common/pkgmgr_signal.h"
+#include "common/step/step.h"
+#include "common/utils/file_logbackend.h"
+#include "common/utils/macros.h"
+
+namespace common_installer {
+
+/**
+ * \brief Includes the main “steps” processing mechanisms. It holds
+ *        the lists of steps and runs each of the step in the configured
+ *        order.
+ */
+class AppInstaller {
+ public:
+  /** Enumeration of possible returned Results */
+  enum class Result {
+    OK,
+    ERROR,
+    CLEANUP_ERROR,
+    UNDO_ERROR,
+    UNKNOWN
+  };
+
+  /**
+   * \brief explicit Constructor
+   *
+   * \param package_type package type
+   * \param pkgmgr pointer to PkgMgrInterface object
+   */
+  explicit AppInstaller(const char* package_type, PkgMgrPtr pkgmgr);
+
+  /** virtual desctructor */
+  virtual ~AppInstaller();
+
+  /**
+   * \brief Adds new step to installer by specified type
+   *        Type of template parameter is used to create requested step
+   *        class instance.
+   *        Context of installer is passed to step in this method
+   *        and is not being exposed outside installer.
+   *        Step arguments are deduced and forwarded to constructor.
+   *
+   * \tparam StepT Step object to be added to the step list
+   * \tparam Args constructor arguments for StepT object
+   * \param args argument list
+   */
+  template<class StepT, class... Args>
+  void AddStep(Args&&... args) {
+    std::unique_ptr<Step> step(
+        new StepT(context_.get(), std::forward<Args>(args)...));
+    step->on_error.connect(
+        boost::bind(&AppInstaller::HandleStepError, this, _1, _2));
+    steps_.emplace_back(std::move(step));
+  }
+
+  /**
+   * \brief Removes specific step in steps list.
+   * \param step_name step name to be removed
+   */
+  void RemoveStep(std::string step_name) {
+    auto it = std::find_if(steps_.begin(), steps_.end(),
+        [&](const std::unique_ptr<Step>& s) {
+          return step_name == s->name();
+        });
+    if (steps_.end() == it) {
+      LOG(ERROR) << "Can't find the step : " << step_name;
+      return;
+    }
+    steps_.erase(it);
+  }
+
+  /**
+   * \brief Adds new step to installer by specified type on specyfic place
+   *        in steps list.
+   *        Type of template parameter is used to create requested step
+   *        class instance.
+   *        Context of installer is passed to step in this method
+   *        and is not being exposed outside installer.
+   *        Step arguments are deduced and forwarded to constructor.
+   *
+   * \tparam StepT Step object to be added to the step list
+   * \tparam index index at which the new step is added
+   * \tparam Args constructor arguments for StepT object
+   * \param args argument list
+   */
+  template<class StepT, class... Args>
+  void AddStepAtIndex(unsigned int index, Args&&... args) {
+    std::unique_ptr<Step> step(
+        new StepT(context_.get(), std::forward<Args>(args)...));
+    step->on_error.connect(
+        boost::bind(&AppInstaller::HandleStepError, this, _1, _2));
+    std::list<std::unique_ptr<Step>> tmpList;
+    tmpList.emplace_back(std::move(step));
+    auto it = steps_.begin();
+    std::advance(it, index);
+    steps_.splice(it, tmpList);
+  }
+
+  /**
+   * \brief Replaces new step to installer by specified type
+   *        Type of template parameter is used to create requested step
+   *        class instance.
+   *        Context of installer is passed to step in this method
+   *        and is not being exposed outside installer.
+   *        Step arguments are deduced and forwarded to constructor.
+   * \tparam StepT Step object to be added to the step list
+   * \tparam Args constructor arguments for StepT object
+   * \param step_name step name to replace
+   * \param args argument list
+   */
+  template<class StepT, class... Args>
+  void ReplaceStep(std::string step_name, Args&&... args) {
+    auto it = std::find_if(std::begin(steps_), std::end(steps_),
+        [&](const std::unique_ptr<Step>& s) {
+          return step_name == s->name();
+        });
+
+    if (steps_.end() == it) {
+      LOG(ERROR) << "Can't find the step : " << step_name;
+      return;
+    }
+
+    std::unique_ptr<Step> step(
+        new StepT(context_.get(), std::forward<Args>(args)...));
+    step->on_error.connect(
+        boost::bind(&AppInstaller::HandleStepError, this, _1, _2));
+    *it = std::move(step);
+  }
+
+  /**
+   * \brief Adds new step before specified step
+   *        Type of template parameter is used to create requested step
+   *        class instance.
+   *        Context of installer is passed to step in this method
+   *        and is not being exposed outside installer.
+   *        Step arguments are deduced and forwarded to constructor.
+   * \tparam StepT Step object to be added to the step list
+   * \tparam Args constructor arguments for StepT object
+   * \param step_name step name to find and add
+   * \param args argument list
+   */
+  template<class StepT, class... Args>
+  void AddStepBefore(std::string step_name, Args&&... args) {
+    auto it = std::find_if(std::begin(steps_), std::end(steps_),
+        [&](const std::unique_ptr<Step>& s) {
+          return step_name == s->name();
+        });
+
+    if (steps_.end() == it) {
+      LOG(ERROR) << "Can't find the step : " << step_name;
+      return;
+    }
+
+    std::unique_ptr<Step> step(
+        new StepT(context_.get(), std::forward<Args>(args)...));
+    step->on_error.connect(
+        boost::bind(&AppInstaller::HandleStepError, this, _1, _2));
+    steps_.insert(it, std::move(step));
+  }
+
+  /**
+   * \brief Adds new step after specified step
+   *        Type of template parameter is used to create requested step
+   *        class instance.
+   *        Context of installer is passed to step in this method
+   *        and is not being exposed outside installer.
+   *        Step arguments are deduced and forwarded to constructor.
+   * \tparam StepT Step object to be added to the step list
+   * \tparam Args constructor arguments for StepT object
+   * \param step_name step name to find and add
+   * \param args argument list
+   */
+  template<class StepT, class... Args>
+  void AddStepAfter(std::string step_name, Args&&... args) {
+    auto it = std::find_if(std::begin(steps_), std::end(steps_),
+        [&](const std::unique_ptr<Step>& s) {
+          return step_name == s->name();
+        });
+
+    if (steps_.end() == it) {
+      LOG(ERROR) << "Can't find the step : " << step_name;
+      return;
+    }
+
+    std::unique_ptr<Step> step(
+        new StepT(context_.get(), std::forward<Args>(args)...));
+    step->on_error.connect(
+        boost::bind(&AppInstaller::HandleStepError, this, _1, _2));
+    steps_.insert(++it, std::move(step));
+  }
+
+  /**
+   * \brief runs the steps in the specific sequence
+   *
+   * \return Result of the run (eg Result:OK)
+   */
+  Result Run();
+
+  /**
+   * \brief runs the process operations of steps
+   *
+   * \return Result of the run (eg Result:OK)
+   */
+  Result Process();
+
+  /**
+   * \brief runs the undo operations of steps
+   *
+   * \return Result of the run (eg Result:OK)
+   */
+  Result Undo();
+
+  /**
+   * \brief runs the clean operations of steps
+   *
+   * \return Result of the run (eg Result:OK)
+   */
+  Result Clean();
+
+  /**
+   * \brief This method can be used to check
+   *        the number of the registered steps.
+   *
+   * \return number of steps registered in app-installer
+   */
+  unsigned int StepCount() {
+    return steps_.size();
+  }
+
+  void SetIndex(int index) {
+    index_ = index;
+  }
+
+  int GetIndex() {
+    return index_;
+  }
+
+  virtual std::unique_ptr<ArchiveInfo> GetArchiveInfo() = 0;
+
+ protected:
+  PkgMgrPtr pkgmgr_;
+  std::unique_ptr<InstallerContext> context_;
+
+  virtual void InstallSteps();
+  virtual void UpdateSteps();
+  virtual void UninstallSteps();
+  virtual void ReinstallSteps();
+  virtual void DeltaSteps();
+  virtual void MoveSteps();
+  virtual void RecoverySteps();
+  virtual void MountInstallSteps();
+  virtual void MountUpdateSteps();
+  virtual void ManifestDirectInstallSteps();
+  virtual void ManifestDirectUpdateSteps();
+  virtual void ManifestPartialInstallSteps();
+  virtual void ManifestPartialUpdateSteps();
+  virtual void PartialUninstallSteps();
+  virtual void ReadonlyUpdateInstallSteps();
+  virtual void ReadonlyUpdateUninstallSteps();
+  virtual void DisablePkgSteps();
+  virtual void EnablePkgSteps();
+  virtual void MigrateExtImgSteps();
+  virtual void RecoverDBSteps();
+  virtual void UnknownSteps();
+
+ private:
+  void Init();
+
+  std::list<std::unique_ptr<Step>> steps_;
+  std::list<std::unique_ptr<Step>>::iterator it_;
+
+  // data used to send signal
+  std::unique_ptr<PkgmgrSignal> pi_;
+
+  void SendProgress(int progress);
+  void SendFinished(Step::Status status);
+  Step::Status SafeExecute(std::unique_ptr<Step> const& step_ptr,
+                           Step::Status (Step::*method)(),
+                           std::string name);
+  void HandleStepError(Step::Status result, const std::string& error);
+
+  std::shared_ptr<utils::FileLogBackend> failure_logger_;
+  Step::Status status_;
+  Result result_;
+  void LogHistory(bool success);
+
+  int index_;
+
+  friend class InstallerRunner;
+
+  SCOPE_LOG_TAG(AppInstaller)
+
+  DISALLOW_COPY_AND_ASSIGN(AppInstaller);
+};
+
+}  // namespace common_installer
+
+#endif  // COMMON_INSTALLER_APP_INSTALLER_H_
index 42b45dd945c28405c7245e944f853d184333b8cb..c8c1ab148b3a6778344f0b03f8162fc6212da791 100644 (file)
@@ -23,8 +23,8 @@
 #include "common/external_storage.h"
 #include "common/pkgmgr_interface.h"
 #include "common/recovery_file.h"
-#include "common/request.h"
 #include "common/utils/property.h"
+#include "common/utils/request.h"
 
 #include "manifest_info/account.h"
 #include "manifest_info/ime_info.h"
index f4f3d046630893bc50ab98a3475ee6d3435bd2fc..68e9747108f21e8fb1394a99d7bb77ee4f92c9d4 100644 (file)
@@ -10,7 +10,7 @@
 #include <string>
 #include <utility>
 
-#include "common/app_installer.h"
+#include "common/installer/app_installer.h"
 #include "common/installer_context.h"
 #include "common/installer_factory.h"
 #include "common/pkgmgr_interface.h"
index df404ae8731d86adfa2f1e6214d8018f22c2809c..25361fc875e13dd61c42db189daafdbe0070142f 100644 (file)
@@ -8,7 +8,7 @@
 #include <list>
 #include <memory>
 
-#include "common/app_installer.h"
+#include "common/installer/app_installer.h"
 #include "common/dependency_checker.h"
 #include "common/global_recovery_file.h"
 #include "common/pkgmgr_interface.h"
diff --git a/src/common/paths.cc b/src/common/paths.cc
deleted file mode 100644 (file)
index 71ce838..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-// Copyright (c) 2015 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/paths.h"
-
-#include <manifest_parser/utils/logging.h>
-
-#include <boost/filesystem/operations.hpp>
-
-#include <pwd.h>
-#include <tzplatform_config.h>
-#include <storage-internal.h>
-
-#include <vector>
-
-#include "common/utils/user_util.h"
-
-namespace bf = boost::filesystem;
-namespace ci = common_installer;
-
-namespace {
-
-const char kImageDir[] = ".image";
-const char kBckExtension[] = ".bck";
-
-boost::filesystem::path GetBackupPath(const boost::filesystem::path& pkg_path) {
-  bf::path backup_path = pkg_path;
-  backup_path += kBckExtension;
-  return backup_path;
-}
-
-}  // namespace
-
-namespace common_installer {
-
-boost::filesystem::path GetBackupPathForPackagePath(
-    const boost::filesystem::path& pkg_path) {
-  return GetBackupPath(pkg_path);
-}
-
-boost::filesystem::path GetBackupPathForManifestFile(
-    const boost::filesystem::path& manifest_path) {
-  return GetBackupPath(manifest_path);
-}
-
-boost::filesystem::path GetBackupPathForIconFile(
-    const boost::filesystem::path& icon_path) {
-  return GetBackupPath(icon_path);
-}
-
-std::string GetIconFileBackupExtension() {
-  return kBckExtension;
-}
-
-boost::filesystem::path GetBackupPathForZipFile(const bf::path& zip_path) {
-  return GetBackupPath(zip_path);
-}
-
-boost::filesystem::path GetMountLocation(const bf::path& pkg_path) {
-  return pkg_path / ".pkg";
-}
-
-boost::filesystem::path GetZipPackageLocation(
-    const boost::filesystem::path& pkg_path,
-    const std::string& pkgid) {
-  return pkg_path / kImageDir / pkgid;
-}
-
-boost::filesystem::path GetExternalCardPath() {
-  char* sdpath = nullptr;
-  int storage_id = 0;
-  int ret;
-
-  ret = storage_get_primary_sdcard(&storage_id, &sdpath);
-  if (ret != STORAGE_ERROR_NONE) {
-    free(sdpath);
-    return bf::path();
-  }
-
-  if (sdpath) {
-    std::string mount_path(sdpath);
-    free(sdpath);
-    return bf::path(mount_path);
-  }
-
-  return bf::path();
-}
-
-boost::filesystem::path GetExternalTepPath(RequestMode request_mode,
-                                           uid_t uid) {
-  bf::path result;
-  bf::path ext_mount_path = GetExternalCardPath();
-  if (bf::is_empty(ext_mount_path))
-    return result;
-  result = ext_mount_path / "tep";
-  if (request_mode == RequestMode::USER)
-    result /= ci::GetUsernameByUid(uid);
-  return result;
-}
-
-boost::filesystem::path GetInternalTepPath(
-    const boost::filesystem::path& pkg_path) {
-  return pkg_path / "tep";
-}
-
-boost::filesystem::path GetIconPath(const bf::path& base_path,
-                      const std::string& pkgid,
-                      const bf::path& icon_filename,
-                      const bf::path& root_path) {
-  std::vector<bf::path> paths;
-  bf::path system_path = base_path / icon_filename;
-  bf::path small_system_path = base_path / "default" / "small" / icon_filename;
-  bf::path res_path = root_path / pkgid / "res" / "icons" / icon_filename;
-
-  paths.push_back(system_path);
-  paths.push_back(small_system_path);
-  paths.push_back(res_path);
-
-  for (auto& path : paths) {
-    if (bf::exists(path))
-      return path;
-  }
-
-  return {};
-}
-
-bool IsExtendedStorageAvailable() {
-  bool is_available = false;
-  int ret = storage_foreach_device_supported(
-      [](int, storage_type_e type, storage_state_e state,
-          const char* path, void* user_data) -> bool {
-        if (type != STORAGE_TYPE_EXTENDED_INTERNAL)
-          return true;
-        if (state != STORAGE_STATE_MOUNTED)
-          return true;
-        bool* is_available = static_cast<bool*>(user_data);
-        if (bf::exists(path))
-          *is_available = true;
-        // Stop iteration
-        return false;
-      },
-      &is_available);
-  if (ret != STORAGE_ERROR_NONE) {
-    LOG(ERROR) << "Failed to call storage_foreach_device_supported()";
-    return false;
-  }
-  return is_available;
-}
-
-}  // namespace common_installer
diff --git a/src/common/paths.h b/src/common/paths.h
deleted file mode 100644 (file)
index 65f2b49..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-// Copyright (c) 2015 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_PATHS_H_
-#define COMMON_PATHS_H_
-
-#include <boost/filesystem/path.hpp>
-#include <boost/filesystem/operations.hpp>
-#include <unistd.h>
-
-#include <string>
-
-#include "common/request.h"
-
-namespace common_installer {
-
-/**
- * \brief Helper function for getting backup path (used for recovery)
- *        based on package path
- *
- * \param pkg_path package path
- *
- * \return backup path
- */
-boost::filesystem::path GetBackupPathForPackagePath(
-    const boost::filesystem::path& pkg_path);
-
-/**
- * \brief Helper function for getting backup path (used for recovery)
- *        based on manifest file path
- *
- * \param manifest_path path to manifest file
- *
- * \return backup path
- */
-boost::filesystem::path GetBackupPathForManifestFile(
-    const boost::filesystem::path& manifest_path);
-
-/**
- * \brief Helper function for getting backup path (used for recovery)
- *        based on icon path
- *
- * \param icon_path path to icon file
- *
- * \return backup path
- */
-boost::filesystem::path GetBackupPathForIconFile(
-    const boost::filesystem::path& icon_path);
-
-/**
- * @brief GetIconFileBackupExtension
- * @return extension for backup icon files
- */
-std::string GetIconFileBackupExtension();
-
-/**
- * \brief Helper function for getting backup path of zip (used for recovery)
- *        based on zip path
- *
- * \param zip_path path to zip file
- *
- * \return backup path of zip
- */
-boost::filesystem::path GetBackupPathForZipFile(
-    const boost::filesystem::path& zip_path);
-
-/**
- * @brief GetZipPackageLocation
- *        Returns location where zip package file must be copied during package
- *        installation.
- *
- * @param pkg_path package path
- * @param pkgid package id
- *
- * @return full path of zip package location
- */
-boost::filesystem::path GetZipPackageLocation(
-    const boost::filesystem::path& pkg_path,
-    const std::string& pkgid);
-
-/**
- * @brief GetMountLocation
- *        Returns the mount point of zip package. This location is used to
- *        mount package.
- *
- * @param pkg_path package path for which zip mount location is being obtained
- *
- * @return full path of package mount point
- */
-boost::filesystem::path GetMountLocation(
-    const boost::filesystem::path& pkg_path);
-
-/**
- * @brief GetExternalCardPath
- *        Returns full path to mounted filesystem of sd card
- *
- * @return path
- */
-boost::filesystem::path GetExternalCardPath();
-
-/**
- * @brief GetExternalTepPath
- *        Returns external installation location for tep package
- * @param request_mode request type
- * @param uid user id of request
- *
- * @return full directory path
- */
-boost::filesystem::path GetExternalTepPath(RequestMode request_mode, uid_t uid);
-
-/**
- * @brief GetInternalTepPath
- *        Returns internal installation location for tep package
- * @param pkg_path path of installation request
- *
- * @return full directory path
- */
-boost::filesystem::path GetInternalTepPath(
-    const boost::filesystem::path& pkg_path);
-
-/**
- * @brief GetIconPath
- *        Returns internal location for preinstalled global app icon
- * @param base_path path of icon in application
- * @param pkgid package id
- * @param icon_filename filename of icon
- * @param root_path root path of application
- *
- * @return full icon path
- */
-boost::filesystem::path GetIconPath(const boost::filesystem::path& base_path,
-                      const std::string& pkgid,
-                      const boost::filesystem::path& icon_filename,
-                      const boost::filesystem::path& root_path);
-
-/**
- * @brief IsExtendedStorageAvailable
- *        Returns true if the extended storage is available
- *
- * @return true is the extended storage is available, otherwise false
- */
-bool IsExtendedStorageAvailable();
-
-}  // namespace common_installer
-
-#endif  // COMMON_PATHS_H_
index 7ee1d8b3ff7f79d307c9cd5669e4eac214ee8d09..86bf3fb15bc44336dc34ed0684def53bb625bf28 100644 (file)
@@ -6,8 +6,8 @@
 
 #include <manifest_parser/utils/version_number.h>
 
-#include "common/request.h"
 #include "common/utils/glist_range.h"
+#include "common/utils/request.h"
 
 namespace {
 
index 27d103abaf16885dcb983f134e0dbdd207e6637c..4af4af69bc8326292177e65a8c93528cf14c9878 100644 (file)
@@ -11,7 +11,7 @@
 #include <vector>
 
 #include "common/installer_context.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 
 namespace common_installer {
 
index 1afbb673bfb0a2b884a45624e672dcf0a25d5dc4..0267569ee454a2480af7b1b2add61da751d5af68 100644 (file)
@@ -14,7 +14,7 @@
 #include <fstream>
 
 #include "common/app_query_interface.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/pkgmgr_signal.h"
 #include "common/pkgmgr_registration.h"
 #include "common/utils/file_util.h"
index a090c34c44c9db4425e28bbc990744098c2800eb..2c7f205fa4d0a9ece10b81cb1fa5de59124df508 100644 (file)
@@ -16,8 +16,8 @@
 #include <string>
 
 #include "common/app_query_interface.h"
-#include "common/request.h"
 #include "common/utils/macros.h"
+#include "common/utils/request.h"
 
 namespace common_installer {
 
diff --git a/src/common/pkgmgr_query.cc b/src/common/pkgmgr_query.cc
deleted file mode 100644 (file)
index e628d8f..0000000
+++ /dev/null
@@ -1,391 +0,0 @@
-// Copyright (c) 2016 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/pkgmgr_query.h"
-
-#include <sys/types.h>
-#include <manifest_parser/utils/logging.h>
-#include <pkgmgr_installer.h>
-#include <pkgmgr_parser.h>
-#include <tzplatform_config.h>
-
-#include <cstring>
-#include <utility>
-
-namespace ci = common_installer;
-
-namespace {
-
-const uid_t kGlobalUserUid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
-
-int PkgmgrForeachPluginCallback(const char* pkgid, const char* appid,
-    const char* plugin_type, const char* plugin_name, void* user_data) {
-  auto* data_list =
-      static_cast<std::vector<ci::PkgQueryInterface::PluginInfo>*>(user_data);
-  data_list->emplace_back(pkgid, appid ? appid : "", plugin_type, plugin_name);
-  return PMINFO_R_OK;
-}
-
-}  // namespace
-
-namespace common_installer {
-
-std::shared_ptr<PkgHandle> PkgQueryInterface::PkgQuery::GetResult(
-    const std::string& pkgid, uid_t uid, bool refresh) {
-  const auto& it = query_results_.find(std::make_pair(pkgid, uid));
-  if (it != query_results_.end()) {
-    if (refresh)
-      query_results_.erase(it);
-    else
-      return it->second;
-  }
-
-  pkgmgrinfo_pkginfo_h handle;
-  int error_ = pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid.c_str(), uid,
-      &handle);
-  if (error_ != PMINFO_R_OK) {
-    if (error_ != PMINFO_R_ENOENT)
-      LOG(ERROR) << "Failed to call pkgmgrinfo_pkginfo_get_usr_pkginfo";
-    return nullptr;
-  }
-  auto res = query_results_.emplace(std::make_pair(pkgid, uid),
-      std::make_shared<PkgHandle>(handle));
-  return res.first->second;
-}
-
-PkgQueryInterface::PkgQueryInterface(const std::string& pkgid, uid_t uid,
-    bool refresh)
-    : error_(0), pkgid_(pkgid), uid_(uid) {
-  handle_ = PkgQuery::Instance().GetResult(pkgid_, uid, refresh);
-}
-
-PkgQueryInterface::~PkgQueryInterface() {
-}
-
-bool PkgQueryInterface::IsValid() {
-  return handle_ != nullptr;
-}
-
-int PkgQueryInterface::GetLastOperationError() {
-  return error_;
-}
-
-std::string PkgQueryInterface::Version() {
-  if (!IsValid())
-    return {};
-  char* version = nullptr;
-  error_ = pkgmgrinfo_pkginfo_get_version(handle_->handle, &version);
-  if (error_ != PMINFO_R_OK) {
-    LOG(DEBUG) << "pkgmgrinfo_pkginfo_get_version failed with error: "
-               << error_;
-    return {};
-  }
-  std::string version_value;
-  if (version)
-    version_value = version;
-  return version_value;
-}
-
-std::string PkgQueryInterface::TepPath() {
-  if (!IsValid())
-    return {};
-  char* tep_name = nullptr;
-  error_ = pkgmgrinfo_pkginfo_get_tep_name(handle_->handle, &tep_name);
-  if (error_ != PMINFO_R_OK) {
-    LOG(DEBUG) << "pkgmgrinfo_pkginfo_get_tep_name failed with error: "
-               << error_;
-    return {};
-  }
-  std::string tep_name_value;
-  if (tep_name)
-    tep_name_value = tep_name;
-  return tep_name_value;
-}
-
-std::string PkgQueryInterface::ZipMountFile() {
-  if (!IsValid())
-    return {};
-  char* zip_mount_file = nullptr;
-  error_ = pkgmgrinfo_pkginfo_get_zip_mount_file(handle_->handle,
-          &zip_mount_file);
-  if (error_ != PMINFO_R_OK) {
-    LOG(DEBUG) << "pkgmgrinfo_pkginfo_get_zip_mount_file failed with error: "
-               << error_;
-    return {};
-  }
-  std::string zip_mount_file_value;
-  if (zip_mount_file)
-    zip_mount_file_value = zip_mount_file;
-  return zip_mount_file_value;
-}
-
-std::string PkgQueryInterface::StorageForPkgId() {
-  if (!IsValid())
-    return {};
-  // initial & default : internal
-  std::string installed_location = "installed_internal";
-
-  pkgmgrinfo_installed_storage storage;
-  error_ = pkgmgrinfo_pkginfo_get_installed_storage(handle_->handle, &storage);
-
-  if (error_ != PMINFO_R_OK)
-    return "";
-
-  if (storage == PMINFO_EXTERNAL_STORAGE)
-    installed_location = "installed_external";
-  else if (storage == PMINFO_EXTENDED_STORAGE)
-    installed_location = "installed_extended";
-
-  return installed_location;
-}
-
-std::string PkgQueryInterface::Type() {
-  if (!IsValid())
-    return {};
-  char* type = nullptr;
-  error_ = pkgmgrinfo_pkginfo_get_type(handle_->handle, &type);
-  if (error_ != PMINFO_R_OK) {
-    LOG(DEBUG) << "pkgmgrinfo_pkginfo_get_type failed with error: "
-               << error_;
-    return {};
-  }
-  std::string type_value;
-  if (type)
-    type_value = type;
-  return type_value;
-}
-
-bool PkgQueryInterface::IsPackageInstalled() {
-  if (!IsValid())
-    return false;
-  bool is_global = false;
-  if (pkgmgrinfo_pkginfo_is_for_all_users(handle_->handle, &is_global) !=
-      PMINFO_R_OK) {
-    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_for_all_users failed";
-    return false;
-  }
-
-  if (uid_ == kGlobalUserUid && is_global)
-    return true;
-  if (uid_ != kGlobalUserUid && is_global)
-    return false;
-  return true;
-}
-
-bool PkgQueryInterface::IsPackageInstalled(RequestMode mode) {
-  if (!IsValid())
-    return false;
-  bool is_global = false;
-  error_ = pkgmgrinfo_pkginfo_is_for_all_users(handle_->handle, &is_global);
-  if (error_ != PMINFO_R_OK) {
-    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_for_all_users failed";
-    return false;
-  }
-
-  if (mode == RequestMode::GLOBAL && !is_global)
-    return false;
-  if (mode == RequestMode::USER && is_global)
-    return false;
-
-  return true;
-}
-
-bool PkgQueryInterface::IsGlobalPackage() {
-  if (!IsValid())
-    return false;
-  bool is_global = false;
-  error_ = pkgmgrinfo_pkginfo_is_for_all_users(handle_->handle, &is_global);
-  if (error_ != PMINFO_R_OK) {
-    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_for_all_users failed";
-    return false;
-  }
-  return is_global;
-}
-
-bool PkgQueryInterface::IsReadonlyPackage() {
-  if (!IsValid())
-    return false;
-  bool is_readonly = false;
-  error_ = pkgmgrinfo_pkginfo_is_readonly(handle_->handle, &is_readonly);
-  if (error_ != PMINFO_R_OK) {
-    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_readonly failed";
-    return false;
-  }
-  return is_readonly;
-}
-
-bool PkgQueryInterface::IsUpdatedPackage() {
-  if (!IsValid())
-    return false;
-  bool is_update = false;
-  error_ = pkgmgrinfo_pkginfo_is_update(handle_->handle, &is_update);
-  if (error_ != PMINFO_R_OK) {
-    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_update failed";
-    return false;
-  }
-  return is_update;
-}
-
-bool PkgQueryInterface::IsPreloadPackage() {
-  if (!IsValid())
-    return false;
-  bool is_preload = false;
-  error_ = pkgmgrinfo_pkginfo_is_preload(handle_->handle, &is_preload);
-  if (error_ != PMINFO_R_OK) {
-    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_preload failed";
-    return false;
-  }
-  return is_preload;
-}
-
-bool PkgQueryInterface::IsSystemPackage() {
-  if (!IsValid())
-    return false;
-  bool is_system = false;
-  error_ = pkgmgrinfo_pkginfo_is_system(handle_->handle, &is_system);
-  if (error_ != PMINFO_R_OK) {
-    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_system failed";
-    return false;
-  }
-  return is_system;
-}
-
-bool PkgQueryInterface::IsRemovablePackage() {
-  if (!IsValid())
-    return false;
-  bool is_removable = false;
-  error_ = pkgmgrinfo_pkginfo_is_removable(handle_->handle, &is_removable);
-  if (error_ != PMINFO_R_OK) {
-    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_removable failed";
-    return false;
-  }
-  return is_removable;
-}
-
-bool PkgQueryInterface::AppidsForPkgId(std::vector<std::string>* result) {
-  if (!IsValid())
-    return false;
-  error_ = pkgmgrinfo_appinfo_get_usr_list(handle_->handle, PMINFO_ALL_APP,
-      [](const pkgmgrinfo_appinfo_h handle, void* user_data) -> int {
-        auto* data = static_cast<std::vector<std::string>*>(user_data);
-        char* app_id = nullptr;
-        if (pkgmgrinfo_appinfo_get_appid(handle, &app_id) != PMINFO_R_OK)
-          return PMINFO_R_ERROR;
-        data->emplace_back(app_id);
-        return PMINFO_R_OK;
-      },
-      result, uid_);
-  return error_ == PMINFO_R_OK;
-}
-
-bool PkgQueryInterface::PrivilegesForPkgId(std::vector<std::string>* result) {
-  if (!IsValid())
-    return false;
-  error_ = pkgmgrinfo_pkginfo_foreach_privilege(handle_->handle,
-      [](const char* privilege_name, void* user_data) -> int {
-        auto* data = static_cast<std::vector<std::string>*>(user_data);
-        data->emplace_back(privilege_name);
-        return PMINFO_R_OK;
-      },
-      result);
-  return error_ == PMINFO_R_OK;
-}
-
-bool PkgQueryInterface::PackagesDependsOn(
-    std::vector<DependencyInfo>* result) {
-  if (!IsValid())
-    return false;
-  error_ = pkgmgrinfo_pkginfo_foreach_depends_on(handle_->handle,
-      [](const char* from, const char* to, const char* type,
-          const char* version, void* user_data) -> int {
-        auto* data =
-            static_cast<std::vector<ci::PkgQueryInterface::DependencyInfo>*>(
-                user_data);
-        data->emplace_back(from, to, type, version ? version : "");
-        return PMINFO_R_OK;
-      },
-      result);
-  return error_ == PMINFO_R_OK;
-}
-
-bool PkgQueryInterface::IsPluginExecuted(const std::string& plugin_type,
-                                         const std::string& plugin_name) {
-  if (!IsValid())
-    return false;
-  std::vector<PluginInfo> plugin_list;
-  error_ = pkgmgrinfo_pkginfo_foreach_plugin(handle_->handle,
-      &PkgmgrForeachPluginCallback, &plugin_list);
-  if (error_ != PMINFO_R_OK) {
-    LOG(ERROR) << "Failed to get plugin info";
-    return false;
-  }
-
-  for (const auto& plugin : plugin_list) {
-    if (plugin_type.compare(std::get<2>(plugin)) == 0 &&
-        plugin_name.compare(std::get<3>(plugin)) == 0) {
-      return true;
-    }
-  }
-  return false;
-}
-
-bool PkgQueryInterface::PluginExecutionInfo(
-    std::vector<PluginInfo>* plugin_list) {
-  if (!IsValid())
-    return false;
-
-  error_ = pkgmgrinfo_pkginfo_foreach_plugin(handle_->handle,
-      &PkgmgrForeachPluginCallback, plugin_list);
-  return error_ == PMINFO_R_OK;
-}
-
-std::string QueryCertificateAuthorCertificate(const std::string& pkgid,
-                                              uid_t uid) {
-  pkgmgrinfo_certinfo_h handle;
-  int ret = pkgmgrinfo_pkginfo_create_certinfo(&handle);
-  if (ret != PMINFO_R_OK) {
-    LOG(DEBUG) << "pkgmgrinfo_pkginfo_create_certinfo failed with error: "
-               << ret;
-    return {};
-  }
-  ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid.c_str(), handle, uid);
-  if (ret != PMINFO_R_OK) {
-    if (ret != PMINFO_R_ENOENT)
-      LOG(DEBUG) << "pkgmgrinfo_pkginfo_load_certinfo failed with error: "
-                 << ret;
-    pkgmgrinfo_pkginfo_destroy_certinfo(handle);
-    return {};
-  }
-  const char* author_cert = nullptr;
-  ret = pkgmgrinfo_pkginfo_get_cert_value(handle, PMINFO_AUTHOR_SIGNER_CERT,
-                                          &author_cert);
-  if (ret != PMINFO_R_OK) {
-    LOG(DEBUG) << "pkgmgrinfo_pkginfo_get_cert_value failed with error: "
-               << ret;
-    pkgmgrinfo_pkginfo_destroy_certinfo(handle);
-    return {};
-  }
-  std::string old_author_certificate;
-  if (author_cert)
-    old_author_certificate = author_cert;
-  pkgmgrinfo_pkginfo_destroy_certinfo(handle);
-  return old_author_certificate;
-}
-
-bool QueryIsDisabledPackage(const std::string& pkg_id, uid_t uid) {
-  pkgmgrinfo_pkginfo_h handle;
-  int ret = pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkg_id.c_str(),
-              uid, &handle);
-  if (ret != PMINFO_R_OK) {
-    if (ret != PMINFO_R_ENOENT)
-      LOG(ERROR) <<
-          "Failed to call pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo";
-    return false;
-  }
-
-  pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-  return true;
-}
-
-}  // namespace common_installer
diff --git a/src/common/pkgmgr_query.h b/src/common/pkgmgr_query.h
deleted file mode 100644 (file)
index 5059fbe..0000000
+++ /dev/null
@@ -1,232 +0,0 @@
-// Copyright (c) 2016 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_PKGMGR_QUERY_H_
-#define COMMON_PKGMGR_QUERY_H_
-
-#include <unistd.h>
-#include <pkgmgr-info.h>
-#include <sys/types.h>
-
-#include <map>
-#include <memory>
-#include <string>
-#include <tuple>
-#include <utility>
-#include <vector>
-
-#include "common/request.h"
-#include "common/utils/singleton.h"
-
-namespace common_installer {
-
-struct PkgHandle {
-  pkgmgrinfo_pkginfo_h handle;
-  explicit PkgHandle(pkgmgrinfo_pkginfo_h pkginfo_handle) {
-    handle = pkginfo_handle;
-  }
-  ~PkgHandle() {
-    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-  }
-};
-
-/**
- * \brief Adapter interface for external PkgMgr module.
- */
-class PkgQueryInterface {
- public:
-  using PluginInfo =
-      std::tuple<std::string, std::string, std::string, std::string>;
-  using DependencyInfo =
-      std::tuple<std::string, std::string, std::string, std::string>;
-  PkgQueryInterface(const std::string& pkgid, uid_t uid, bool refresh = false);
-  ~PkgQueryInterface();
-
-  bool IsValid();
-  int GetLastOperationError();
-
-  /**
-   * \brief Returns package version for given package.
-   *
-   * @return version or empty
-   */
-  std::string Version();
-
-  /**
-   * \brief Returns tizen extension package path for given package.
-   *
-   * @return path or empty
-   */
-  std::string TepPath();
-
-  /**
-   * \brief Returns zip mount path for given package.
-   *
-   * @return path or empty
-   */
-  std::string ZipMountFile();
-
-  /**
-   * \brief Returns storage for given package.
-   *
-   * @return path or empty
-   */
-  std::string StorageForPkgId();
-
-  /**
-   * \brief Returns type for given package.
-   *
-   * @return type or empty
-   */
-  std::string Type();
-
-  /**
-   * \brief Checks if given package is installed/registered.
-   *
-   * \return true if package is installed
-   */
-  bool IsPackageInstalled();
-
-  /**
-   * \brief Checks if given package is installed/registered as request mode.
-   *
-   * \param mode request mode
-   *
-   * \return true if package is installed
-   */
-  bool IsPackageInstalled(RequestMode mode);
-
-  /**
-   * \brief Checks if given package is global package.
-   *
-   * \return true if package is global package
-   */
-  bool IsGlobalPackage();
-
-  /**
-   * \brief Checks if given package is readonly package.
-   *
-   * \return true if package is readonly
-   */
-  bool IsReadonlyPackage();
-
-  /**
-   * \brief Checks if given package is updated package.
-   *
-   * \return true if package is updated
-   */
-  bool IsUpdatedPackage();
-
-  /**
-   * \brief Checks if given package is preloaded package.
-   *
-   * \return true if package is preloaded
-   */
-  bool IsPreloadPackage();
-
-  /**
-   * \brief Checks if given package is system package.
-   *
-   * \return true if package is system package
-   */
-  bool IsSystemPackage();
-
-  /**
-   * \brief Checks if given package is removable package.
-   *
-   * \return true if package is removable package
-   */
-  bool IsRemovablePackage();
-
-  /**
-   * \brief Returns list of appids for given package.
-   *
-   * \param result[out] Output
-   *
-   * \return true if success
-   */
-  bool AppidsForPkgId(std::vector<std::string>* result);
-  /**
-   * \brief Returns list of privileges for given package
-   *
-   * \param result result - privileges
-   *
-   * \return true if success
-   */
-  bool PrivilegesForPkgId(std::vector<std::string>* result);
-
-  /**
-   * \brief Returns whether plugin has executed for given package
-   *
-   * \param plugin_type plugin type
-   * \param plugin_name plugin name
-   *
-   * \return true if success
-   */
-  bool IsPluginExecuted(const std::string& plugin_type,
-                        const std::string& plugin_name);
-
-  /**
-   * \brief Returns list of plugins executed with given package
-   *
-   * \param plugin_list[out] plugin list
-   *
-   * \return true if success
-   */
-  bool PluginExecutionInfo(std::vector<PluginInfo>* plugin_list);
-
-
-  /**
-   * \brief Returns list of packages depends on given package
-   *
-   * \param result[out] Output
-   *
-   * \return true if success
-   */
-  bool PackagesDependsOn(std::vector<DependencyInfo>* result);
-
- private:
-  class PkgQuery : public Singleton<PkgQuery> {
-    CRTP_DECLARE_DEFAULT_CONSTRUCTOR_CLASS(PkgQuery)
-   public:
-    std::shared_ptr<PkgHandle> GetResult(const std::string& pkgid, uid_t uid,
-        bool refresh);
-
-   private:
-    std::map<std::pair<std::string, uid_t>, std::shared_ptr<PkgHandle>>
-        query_results_;
-  };
-
-  int error_;
-  std::string pkgid_;
-  uid_t uid_;
-  std::shared_ptr<PkgHandle> handle_;
-};
-
-/**
- * \brief Adapter interface for external PkgMgr module used for getting
- *        certificate information for given package
- *
- * \param pkgid package pkgid
- * \param uid user id
- *
- * \return returns certificate information
- */
-std::string QueryCertificateAuthorCertificate(const std::string& pkgid,
-                                              uid_t uid);
-
-/**
- * \brief Adapter interface for external PkgMgr module used for checking
- *        if given package is disabled package
- *
- * \param pkg_id package id
- * \param uid user id
- *
- * \return true if package is disable.
- */
-bool QueryIsDisabledPackage(const std::string& pkg_id, uid_t uid);
-
-}  // namespace common_installer
-
-#endif  // COMMON_PKGMGR_QUERY_H_
index 44f3eb16dd92cd906bf5256a49ab3ea0f841cb65..2c90ecc97b4ce3fb339d258436b3140981c039d2 100644 (file)
@@ -15,7 +15,7 @@
 #include <map>
 #include <vector>
 
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 
 namespace {
 
index 095155e447cf87c9509ad66d8c9cd1d9aa70b637..073232a89dca1100257dc0c37d8f89389e91182c 100644 (file)
@@ -12,9 +12,9 @@
 #include <utility>
 #include <vector>
 
-#include "common/request.h"
 #include "common/step/step.h"
 #include "common/utils/macros.h"
+#include "common/utils/request.h"
 
 namespace common_installer {
 
diff --git a/src/common/plugins/category_plugin.cc b/src/common/plugins/category_plugin.cc
new file mode 100644 (file)
index 0000000..10b9834
--- /dev/null
@@ -0,0 +1,181 @@
+// Copyright (c) 2015 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/plugins/category_plugin.h"
+
+#include <pkgmgr-info.h>
+#include <pkgmgr_parser.h>
+
+#include <algorithm>
+#include <map>
+#include <vector>
+
+#include "common/utils/glist_range.h"
+
+namespace {
+
+std::string GetCategoryName(const std::string& url) {
+  return url.substr(url.find_last_of('/') + 1);
+}
+
+void ClearCategoryDetail(gpointer data) {
+  __category_t* category = reinterpret_cast<__category_t*>(data);
+  free(const_cast<char*>(category->name));
+  free(category);
+}
+
+}  // namespace
+
+namespace common_installer {
+
+const char CategoryPlugin::kType[] = "category";
+
+std::unique_ptr<CategoryPlugin> CategoryPlugin::Create(
+    const PluginInfo& plugin_info) {
+  std::unique_ptr<CategoryPlugin> plugin(new CategoryPlugin(plugin_info));
+  if (!plugin->Load())
+    return nullptr;
+  return plugin;
+}
+
+bool CategoryPlugin::AddPluginInfo(manifest_x* manifest, const char* appid) {
+  plugin_x* plugin = static_cast<plugin_x*>(calloc(1, sizeof(plugin_x)));
+  if (!plugin) {
+    LOG(ERROR) << "out of memory";
+    return false;
+  }
+  plugin->pkgid = strdup(manifest->package);
+  plugin->appid = strdup(appid);
+  plugin->plugin_type = strdup(plugin_info_.type().c_str());
+  plugin->plugin_name = strdup(plugin_info_.name().c_str());
+  manifest->plugin = g_list_append(manifest->plugin, plugin);
+  return true;
+}
+
+std::string CategoryPlugin::GetFunctionName(ActionType action) const {
+  static std::map<ActionType, std::string> names {
+    {ActionType::Install,  "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL"},
+    {ActionType::Upgrade,  "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE"},
+    {ActionType::Uninstall,  "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL"},
+    {ActionType::RecoverInstall, "PKGMGR_CATEGORY_PARSER_PLUGIN_RECOVERINSTALL"},   // NOLINT
+    {ActionType::RecoverUpgrade, "PKGMGR_CATEGORY_PARSER_PLUGIN_RECOVERUPGRADE"},   // NOLINT
+    {ActionType::RecoverUninstall, "PKGMGR_CATEGORY_PARSER_PLUGIN_RECOVERUNINSTALL"},   // NOLINT
+    {ActionType::Clean, "PKGMGR_CATEGORY_PARSER_PLUGIN_CLEAN"},
+    {ActionType::Undo, "PKGMGR_CATEGORY_PARSER_PLUGIN_UNDO"},
+    {ActionType::Removed, "PKGMGR_CATEGORY_PARSER_PLUGIN_REMOVED"},
+  };
+
+  auto pos = names.find(action);
+  if (pos == names.end()) {
+    LOG(INFO) << "Function name not defined";
+    return "";
+  }
+  return pos->second;
+}
+
+bool CategoryPlugin::Run(xmlDocPtr /*doc_ptr*/, manifest_x* manifest,
+         ActionType action_type) {
+  std::string name;
+  std::string tag = GetCategoryName(plugin_info_.name());
+  if (tag.empty())
+    return false;
+
+  std::vector<std::string> appid_list;
+  if (action_type == ActionType::Upgrade) {
+    if (pkgmgrinfo_plugininfo_foreach_plugininfo(manifest->package,
+        CategoryPlugin::kType,
+        plugin_info_.name().c_str(),
+        [](const char*, const char* appid, const char*,
+            const char*, void* user_data) -> int {
+          auto* appid_list =
+              static_cast<std::vector<std::string>*>(user_data);
+          appid_list->emplace_back(std::string(appid));
+          return PMINFO_R_OK;
+        },
+        &appid_list) != PMINFO_R_OK) {
+      LOG(ERROR) << "Failed to get previous execution info";
+      return false;
+    }
+    std::sort(appid_list.begin(), appid_list.end());
+  }
+
+  for (application_x* app : GListRange<application_x*>(manifest->application)) {
+    // pack all categories starting with key to list that will
+    // be sent to the plugin.
+    // e.g. all http://tizen.org/category/antivirus/*
+    //   will be packed for http://tizen.org/category/antivirus
+    GList* category_list = nullptr;
+    for (const char* category : GListRange<char*>(app->category)) {
+      const std::string& sub_key_prefix = plugin_info_.name();
+      if (std::string(category).find(sub_key_prefix) == 0) {
+        __category_t* c = reinterpret_cast<__category_t*>(
+            calloc(1, sizeof(__category_t)));
+        if (!c) {
+          LOG(ERROR) << "Out of memory";
+          g_list_free_full(category_list, &ClearCategoryDetail);
+          return false;
+        }
+        c->name = strdup(category);
+        if (!c->name) {
+          LOG(ERROR) << "Out of memory";
+          free(c);
+          g_list_free_full(category_list, &ClearCategoryDetail);
+          return false;
+        }
+        category_list = g_list_append(category_list, c);
+      }
+    }
+
+    // skip application if it has no given category
+    if (!category_list) {
+      if (action_type != ActionType::Upgrade)
+        continue;
+      auto iter = std::lower_bound(appid_list.begin(), appid_list.end(),
+                                     app->appid);
+      if (iter != appid_list.end() && *iter == app->appid) {
+        name = GetFunctionName(ActionType::Removed);
+        iter = appid_list.erase(iter);
+        category_list = nullptr;
+      } else {
+        continue;
+      }
+    } else {
+      name = GetFunctionName(action_type);
+      if (!AddPluginInfo(manifest, app->appid)) {
+        g_list_free_full(category_list, &ClearCategoryDetail);
+        return false;
+      }
+      auto iter = std::lower_bound(appid_list.begin(), appid_list.end(),
+                                     app->appid);
+      if (iter != appid_list.end() && *iter == app->appid)
+        appid_list.erase(iter);
+    }
+    int result = 0;
+    Exec(name, &result, manifest->package, app->appid, category_list);
+    if (result) {
+      LOG(ERROR) << "Function: " << name << " of plugin "
+                 << plugin_info_.path() << " failed";
+      g_list_free_full(category_list, &ClearCategoryDetail);
+      return false;
+    }
+    g_list_free_full(category_list, &ClearCategoryDetail);
+  }
+
+  if (action_type != ActionType::Upgrade)
+    return true;
+
+  name = GetFunctionName(ActionType::Removed);
+  for (auto appid : appid_list) {
+    int result = 0;
+    Exec(name, &result, manifest->package, appid, nullptr);
+    if (result) {
+      LOG(ERROR) << "Function: " << name << " of plugin "
+                << plugin_info_.path() << " failed";
+      return false;
+    }
+  }
+  return true;
+}
+
+}  // namespace common_installer
diff --git a/src/common/plugins/category_plugin.h b/src/common/plugins/category_plugin.h
new file mode 100644 (file)
index 0000000..883d4a9
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright (c) 2015 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_PLUGINS_CATEGORY_PLUGIN_H_
+#define COMMON_PLUGINS_CATEGORY_PLUGIN_H_
+
+#include <memory>
+#include <string>
+
+#include "common/plugins/plugin.h"
+
+namespace common_installer {
+
+class CategoryPlugin : public Plugin {
+ public:
+  static const char kType[];
+
+  static std::unique_ptr<CategoryPlugin> Create(const PluginInfo& plugin_info);
+  bool Run(xmlDocPtr doc_ptr, manifest_x* manifest,
+           ActionType action_type) override;
+
+ private:
+  bool AddPluginInfo(manifest_x* manifest, const char* appid);
+  std::string GetFunctionName(ActionType action) const;
+
+  using Plugin::Plugin;
+
+  SCOPE_LOG_TAG(CategoryPlugin)
+};
+
+}  // namespace common_installer
+
+#endif  // COMMON_PLUGINS_CATEGORY_PLUGIN_H_
diff --git a/src/common/plugins/metadata_plugin.cc b/src/common/plugins/metadata_plugin.cc
new file mode 100644 (file)
index 0000000..4de70fe
--- /dev/null
@@ -0,0 +1,192 @@
+// Copyright (c) 2015 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/plugins/metadata_plugin.h"
+
+#include <pkgmgr-info.h>
+#include <pkgmgr_parser.h>
+
+#include <algorithm>
+#include <map>
+#include <vector>
+
+#include "common/utils/glist_range.h"
+
+namespace {
+
+std::string GetMetadataTag(const std::string& url) {
+  return url.substr(url.find_last_of('/') + 1);
+}
+
+void ClearMetadataDetail(gpointer data) {
+  __metadata_t* meta = reinterpret_cast<__metadata_t*>(data);
+  if (meta->key)
+    free(const_cast<char*>(meta->key));
+  if (meta->value)
+    free(const_cast<char*>(meta->value));
+  free(meta);
+}
+
+}  // namespace
+
+namespace common_installer {
+
+const char MetadataPlugin::kType[] = "metadata";
+
+std::unique_ptr<MetadataPlugin> MetadataPlugin::Create(
+    const PluginInfo& plugin_info) {
+  std::unique_ptr<MetadataPlugin> plugin(new MetadataPlugin(plugin_info));
+  if (!plugin->Load())
+    return nullptr;
+  return plugin;
+}
+
+bool MetadataPlugin::AddPluginInfo(manifest_x* manifest, const char* appid) {
+  plugin_x* plugin = static_cast<plugin_x*>(calloc(1, sizeof(plugin_x)));
+  if (!plugin) {
+    LOG(ERROR) << "out of memory";
+    return false;
+  }
+  plugin->pkgid = strdup(manifest->package);
+  plugin->appid = strdup(appid);
+  plugin->plugin_type = strdup(plugin_info_.type().c_str());
+  plugin->plugin_name = strdup(plugin_info_.name().c_str());
+  if (!plugin->pkgid || !plugin->appid |
+      !plugin->plugin_type || !plugin->plugin_name) {
+    LOG(ERROR) << "out of memory";
+    free(plugin->pkgid);
+    free(plugin->appid);
+    free(plugin->plugin_type);
+    free(plugin->plugin_name);
+    free(plugin);
+    return false;
+  }
+  manifest->plugin = g_list_append(manifest->plugin, plugin);
+  return true;
+}
+
+std::string MetadataPlugin::GetFunctionName(ActionType action) const {
+  static std::map<ActionType, std::string> names {
+    {ActionType::Install,  "PKGMGR_MDPARSER_PLUGIN_INSTALL"},
+    {ActionType::Upgrade,  "PKGMGR_MDPARSER_PLUGIN_UPGRADE"},
+    {ActionType::Uninstall,  "PKGMGR_MDPARSER_PLUGIN_UNINSTALL"},
+    {ActionType::RecoverInstall,  "PKGMGR_MDPARSER_PLUGIN_RECOVERINSTALL"},
+    {ActionType::RecoverUpgrade,  "PKGMGR_MDPARSER_PLUGIN_RECOVERUPGRADE"},
+    {ActionType::RecoverUninstall,  "PKGMGR_MDPARSER_PLUGIN_RECOVERUNINSTALL"},
+    {ActionType::Clean, "PKGMGR_MDPARSER_PLUGIN_CLEAN"},
+    {ActionType::Undo, "PKGMGR_MDPARSER_PLUGIN_UNDO"},
+    {ActionType::Removed, "PKGMGR_MDPARSER_PLUGIN_REMOVED"},
+  };
+
+  auto pos = names.find(action);
+  if (pos == names.end()) {
+    LOG(INFO) << "Function name not defined";
+    return "";
+  }
+  return pos->second;
+}
+
+bool MetadataPlugin::Run(xmlDocPtr /*doc_ptr*/, manifest_x* manifest,
+                         ActionType action_type) {
+  std::string name;
+  std::string tag = GetMetadataTag(plugin_info_.name());
+  if (tag.empty())
+    return false;
+
+  if (action_type == ActionType::Upgrade) {
+    if (pkgmgrinfo_plugininfo_foreach_plugininfo(manifest->package,
+        MetadataPlugin::kType,
+        plugin_info_.name().c_str(),
+        [](const char*, const char* appid, const char*,
+            const char*, void* user_data) -> int {
+          auto* appid_list =
+              static_cast<std::vector<std::string>*>(user_data);
+          appid_list->emplace_back(std::string(appid));
+          return PMINFO_R_OK;
+        },
+        &appid_list_) != PMINFO_R_OK) {
+      LOG(ERROR) << "Failed to get previous execution info";
+      return false;
+    }
+    std::sort(appid_list_.begin(), appid_list_.end());
+  }
+
+  for (application_x* app : GListRange<application_x*>(manifest->application)) {
+    // pack all metadata starting with key to list that will
+    // be sent to the plugin.
+    // e.g. all http://developer.samsung.com/tizen/metadata/profile/*
+    //   will be packed for http://developer.samsung.com/tizen/metadata/profile
+    GList* md_list = nullptr;
+    for (metadata_x* meta : GListRange<metadata_x*>(app->metadata)) {
+      const std::string& sub_key_prefix = plugin_info_.name();
+      if (meta->key && meta->value &&
+          std::string(meta->key).find(sub_key_prefix) == 0) {
+        __metadata_t* md = reinterpret_cast<__metadata_t*>(
+            calloc(1, sizeof(__metadata_t)));
+        if (!md) {
+          LOG(ERROR) << "Out of memory";
+          g_list_free_full(md_list, &ClearMetadataDetail);
+          return false;
+        }
+        md->key = strdup(meta->key);
+        if (!md->key) {
+          LOG(ERROR) << "Out of memory";
+          free(md);
+          g_list_free_full(md_list, &ClearMetadataDetail);
+          return false;
+        }
+        md->value = strdup(meta->value);
+        if (!md->value) {
+          LOG(ERROR) << "Out of memory";
+          ClearMetadataDetail(md);
+          g_list_free_full(md_list, &ClearMetadataDetail);
+          return false;
+        }
+        md_list = g_list_append(md_list, md);
+      }
+    }
+
+    // skip application if it has no given metadata
+    if (!md_list) {
+      continue;
+    } else {
+      name = GetFunctionName(action_type);
+      if (!AddPluginInfo(manifest, app->appid)) {
+        g_list_free_full(md_list, &ClearMetadataDetail);
+        return false;
+      }
+      auto iter = std::lower_bound(appid_list_.begin(), appid_list_.end(),
+                                     app->appid);
+      if (iter != appid_list_.end() && *iter == app->appid)
+        appid_list_.erase(iter);
+    }
+    int result = 0;
+    Exec(name, &result, manifest->package, app->appid, md_list);
+    if (result) {
+      LOG(ERROR) << "Function: " << name << " of plugin "
+                 << plugin_info_.path() << " failed";
+      g_list_free_full(md_list, &ClearMetadataDetail);
+      return false;
+    }
+    g_list_free_full(md_list, &ClearMetadataDetail);
+  }
+
+  if (action_type == ActionType::Clean ||
+      action_type == ActionType::Undo)
+    name = GetFunctionName(action_type);
+  else
+    name = GetFunctionName(ActionType::Removed);
+  for (auto appid : appid_list_) {
+    int result = 0;
+    Exec(name, &result, manifest->package, appid.c_str(), nullptr);
+    if (result) {
+      LOG(ERROR) << "Function: " << name << " of plugin "
+                << plugin_info_.path() << " failed";
+      return false;
+    }
+  }
+  return true;
+}
+
+}  // namespace common_installer
diff --git a/src/common/plugins/metadata_plugin.h b/src/common/plugins/metadata_plugin.h
new file mode 100644 (file)
index 0000000..492a3e4
--- /dev/null
@@ -0,0 +1,36 @@
+// Copyright (c) 2015 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_PLUGINS_METADATA_PLUGIN_H_
+#define COMMON_PLUGINS_METADATA_PLUGIN_H_
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "common/plugins/plugin.h"
+
+namespace common_installer {
+
+class MetadataPlugin : public Plugin {
+ public:
+  static const char kType[];
+
+  static std::unique_ptr<MetadataPlugin> Create(const PluginInfo& plugin_info);
+  bool Run(xmlDocPtr doc_ptr, manifest_x* manifest,
+           ActionType action_type) override;
+
+ private:
+  bool AddPluginInfo(manifest_x* manifest, const char* appid);
+  std::string GetFunctionName(ActionType action) const;
+
+  using Plugin::Plugin;
+
+  std::vector<std::string> appid_list_;
+  SCOPE_LOG_TAG(MetadataPlugin)
+};
+
+}  // namespace common_installer
+
+#endif  // COMMON_PLUGINS_METADATA_PLUGIN_H_
index f5d220d6b6f0e5a0195cb914d051769c2cc9e98d..e13cd2b72215d59aa62b16f142e33037b7890ea4 100644 (file)
@@ -6,9 +6,9 @@
 
 #include <manifest_parser/utils/logging.h>
 
-#include "common/plugins/types/category_plugin.h"
-#include "common/plugins/types/metadata_plugin.h"
-#include "common/plugins/types/tag_plugin.h"
+#include "common/plugins/category_plugin.h"
+#include "common/plugins/metadata_plugin.h"
+#include "common/plugins/tag_plugin.h"
 
 namespace common_installer {
 
index e6848fc431305276cae2f77543bb8ce71919c3d3..f914ca4edcbd1bbc0cb53586fe6076adc4f3801e 100644 (file)
@@ -16,9 +16,9 @@
 #include "common/plugins/plugin_factory.h"
 #include "common/plugins/plugin_list_parser.h"
 #include "common/plugins/plugin_xml_parser.h"
-#include "common/plugins/types/category_plugin.h"
-#include "common/plugins/types/metadata_plugin.h"
-#include "common/plugins/types/tag_plugin.h"
+#include "common/plugins/category_plugin.h"
+#include "common/plugins/metadata_plugin.h"
+#include "common/plugins/tag_plugin.h"
 #include "common/utils/glist_range.h"
 
 namespace {
index d1a946d2d0cf413a059d02272670e7a48bcec238..5f6c47ce42de29bc73e2892d10ae7ff4479ed46a 100644 (file)
@@ -13,7 +13,7 @@
 #include <string>
 #include <vector>
 
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/plugins/plugin.h"
 #include "common/plugins/plugin_list_parser.h"
 #include "common/plugins/plugin_xml_parser.h"
diff --git a/src/common/plugins/tag_plugin.cc b/src/common/plugins/tag_plugin.cc
new file mode 100644 (file)
index 0000000..7e9b5c4
--- /dev/null
@@ -0,0 +1,138 @@
+// Copyright (c) 2015 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/plugins/tag_plugin.h"
+
+#include <map>
+#include <utility>
+
+namespace common_installer {
+
+const char TagPlugin::kType[] = "tag";
+
+std::unique_ptr<TagPlugin> TagPlugin::Create(
+    const PluginInfo& plugin_info, Plugin::ActionType action_type) {
+  std::unique_ptr<TagPlugin> plugin(new TagPlugin(plugin_info, action_type));
+  if (!plugin->Load())
+    return nullptr;
+  return plugin;
+}
+
+std::string TagPlugin::GetFunctionName(ProcessType process,
+                                       ActionType action) const {
+  static std::map<std::pair<ActionType, ProcessType>, std::string> names {
+    {{ActionType::Install,   ProcessType::Pre},  "PKGMGR_PARSER_PLUGIN_PRE_INSTALL"},   // NOLINT
+    {{ActionType::Upgrade,   ProcessType::Pre},  "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE"},   // NOLINT
+    {{ActionType::Uninstall, ProcessType::Pre},  "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL"}, // NOLINT
+    {{ActionType::RecoverInstall, ProcessType::Pre},  "PKGMGR_PARSER_PLUGIN_PRE_RECOVERINSTALL"}, // NOLINT
+    {{ActionType::RecoverUpgrade, ProcessType::Pre},  "PKGMGR_PARSER_PLUGIN_PRE_RECOVERUPGRADE"}, // NOLINT
+    {{ActionType::RecoverUninstall, ProcessType::Pre},  "PKGMGR_PARSER_PLUGIN_PRE_RECOVERUNINSTALL"}, // NOLINT
+    {{ActionType::Install,   ProcessType::Main}, "PKGMGR_PARSER_PLUGIN_INSTALL"},       // NOLINT
+    {{ActionType::Upgrade,   ProcessType::Main}, "PKGMGR_PARSER_PLUGIN_UPGRADE"},       // NOLINT
+    {{ActionType::Uninstall, ProcessType::Main}, "PKGMGR_PARSER_PLUGIN_UNINSTALL"},     // NOLINT
+    {{ActionType::Removed, ProcessType::Main}, "PKGMGR_PARSER_PLUGIN_REMOVED"},     // NOLINT
+    {{ActionType::RecoverInstall, ProcessType::Main},  "PKGMGR_PARSER_PLUGIN_RECOVERINSTALL"}, // NOLINT
+    {{ActionType::RecoverUpgrade, ProcessType::Main},  "PKGMGR_PARSER_PLUGIN_RECOVERUPGRADE"}, // NOLINT
+    {{ActionType::RecoverUninstall, ProcessType::Main},  "PKGMGR_PARSER_PLUGIN_RECOVERUNINSTALL"}, // NOLINT
+    {{ActionType::Clean, ProcessType::Main},  "PKGMGR_PARSER_PLUGIN_CLEAN"}, // NOLINT
+    {{ActionType::Undo, ProcessType::Main},  "PKGMGR_PARSER_PLUGIN_UNDO"}, // NOLINT
+    {{ActionType::Install,   ProcessType::Post}, "PKGMGR_PARSER_PLUGIN_POST_INSTALL"},  // NOLINT
+    {{ActionType::Upgrade,   ProcessType::Post}, "PKGMGR_PARSER_PLUGIN_POST_UPGRADE"},  // NOLINT
+    {{ActionType::Uninstall, ProcessType::Post}, "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL"}, // NOLINT
+    {{ActionType::RecoverInstall, ProcessType::Post},  "PKGMGR_PARSER_PLUGIN_POST_RECOVERINSTALL"}, // NOLINT
+    {{ActionType::RecoverUpgrade, ProcessType::Post},  "PKGMGR_PARSER_PLUGIN_POST_RECOVERUPGRADE"}, // NOLINT
+    {{ActionType::RecoverUninstall, ProcessType::Post},  "PKGMGR_PARSER_PLUGIN_POST_RECOVERUNINSTALL"}, // NOLINT
+  };
+
+  auto pos = names.find(std::make_pair(action, process));
+  if (pos == names.end()) {
+    LOG(INFO) << "Function name not defined";
+    return "";
+  }
+  return pos->second;
+}
+
+xmlNodePtr MakePluginNode(xmlNodePtr node, const std::string& tag_name) {
+    xmlNodePtr ret_node = nullptr;
+    if (tag_name == reinterpret_cast<const char*>(node->name)) {
+        ret_node = xmlCopyNode(node, 1);
+        return ret_node;
+    }
+
+    for (xmlNodePtr child = xmlFirstElementChild(node);
+        child != nullptr; child = xmlNextElementSibling(child)) {
+      xmlNodePtr child_node = MakePluginNode(child, tag_name);
+      if (!child_node)
+        continue;
+      if (!ret_node)
+        ret_node = xmlCopyNode(node, 0);
+      xmlAddChild(ret_node, child_node);
+    }
+    return ret_node;
+}
+
+xmlDocPtr TagPlugin::CreateDocPtrForPlugin(xmlDocPtr doc_ptr,
+    const std::string& tag_name) const {
+  // Make copy of document and root node
+  xmlNodePtr root_node = xmlDocGetRootElement(doc_ptr);
+  if (!root_node) {
+    LOG(ERROR) << "Original document is empty. Cannot create copy for plugin";
+    return nullptr;
+  }
+  xmlDocPtr plugin_doc_ptr = xmlCopyDoc(doc_ptr, 0);
+  xmlNodePtr plugin_root_node = MakePluginNode(root_node, tag_name);
+  if (!plugin_root_node) {
+    LOG(ERROR) << "make plugin node fail";
+    return nullptr;
+  }
+  xmlDocSetRootElement(plugin_doc_ptr, plugin_root_node);
+  xmlSetTreeDoc(plugin_root_node, plugin_doc_ptr);
+  return plugin_doc_ptr;
+}
+
+bool TagPlugin::Run(xmlDocPtr doc_ptr, manifest_x* manifest,
+         ActionType action_type) {
+  xmlDocPtr plugin_doc_ptr = CreateDocPtrForPlugin(doc_ptr,
+                                                   plugin_info_.name());
+  if (!plugin_doc_ptr)
+    return false;
+
+  int result = 0;
+  ActionType type =
+      (action_type_ != ActionType::Unknown &&
+       action_type != ActionType::Undo &&
+       action_type != ActionType::Clean) ? action_type_ : action_type;
+  std::string pre_function = GetFunctionName(ProcessType::Pre, type);
+  Exec(pre_function, &result, manifest->package);
+  if (result) {
+    LOG(ERROR) << "Function: " << pre_function << " of plugin "
+               << plugin_info_.path() << " failed";
+    xmlFreeDoc(plugin_doc_ptr);
+    return false;
+  }
+
+  std::string main_function = GetFunctionName(ProcessType::Main, type);
+  Exec(main_function, &result, plugin_doc_ptr, manifest->package);
+  if (result) {
+    LOG(ERROR) << "Function: " << main_function << " of plugin "
+               << plugin_info_.path() << " failed";
+    xmlFreeDoc(plugin_doc_ptr);
+    return false;
+  }
+
+  std::string post_function = GetFunctionName(ProcessType::Post, type);
+  Exec(post_function, &result, manifest->package);
+  if (result) {
+    LOG(ERROR) << "Function: " << post_function << " of plugin "
+               << plugin_info_.path() << " failed";
+    xmlFreeDoc(plugin_doc_ptr);
+    return false;
+  }
+
+  xmlFreeDoc(plugin_doc_ptr);
+  return true;
+}
+
+
+}  // namespace common_installer
diff --git a/src/common/plugins/tag_plugin.h b/src/common/plugins/tag_plugin.h
new file mode 100644 (file)
index 0000000..b5df9ef
--- /dev/null
@@ -0,0 +1,53 @@
+// Copyright (c) 2015 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_PLUGINS_TAG_PLUGIN_H_
+#define COMMON_PLUGINS_TAG_PLUGIN_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include <memory>
+#include <string>
+
+#include "common/plugins/plugin.h"
+#include "common/plugins/plugin_list_parser.h"
+
+namespace common_installer {
+
+class TagPlugin : public Plugin {
+ public:
+  static const char kType[];
+
+  static std::unique_ptr<TagPlugin> Create(const PluginInfo& plugin_info,
+      Plugin::ActionType action_type = Plugin::ActionType::Unknown);
+
+  bool Run(xmlDocPtr doc_ptr, manifest_x* manifest,
+           ActionType action_type) override;
+
+ private:
+  using Plugin::Plugin;
+
+  TagPlugin(const PluginInfo& plugin_info, Plugin::ActionType action_type)
+      : Plugin(plugin_info), action_type_(action_type) {}
+
+  std::string GetFunctionName(ProcessType process, ActionType action) const;
+
+  /**
+   * @brief CreateDocPtrForPlugin
+   *        Create copy of xml document with nodes only matching requested
+   *        tag_name
+   * @param doc_ptr original doc ptr of document
+   * @param tag_name name of required node/nodes
+   * @return requested copy
+   */
+  xmlDocPtr CreateDocPtrForPlugin(xmlDocPtr doc_ptr,
+                                  const std::string& tag_name) const;
+
+  Plugin::ActionType action_type_;
+  SCOPE_LOG_TAG(TagPlugin)
+};
+
+}  // namespace common_installer
+
+#endif  // COMMON_PLUGINS_TAG_PLUGIN_H_
diff --git a/src/common/plugins/types/category_plugin.cc b/src/common/plugins/types/category_plugin.cc
deleted file mode 100644 (file)
index e3dd2c8..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-// Copyright (c) 2015 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/plugins/types/category_plugin.h"
-
-#include <pkgmgr-info.h>
-#include <pkgmgr_parser.h>
-
-#include <algorithm>
-#include <map>
-#include <vector>
-
-#include "common/utils/glist_range.h"
-
-namespace {
-
-std::string GetCategoryName(const std::string& url) {
-  return url.substr(url.find_last_of('/') + 1);
-}
-
-void ClearCategoryDetail(gpointer data) {
-  __category_t* category = reinterpret_cast<__category_t*>(data);
-  free(const_cast<char*>(category->name));
-  free(category);
-}
-
-}  // namespace
-
-namespace common_installer {
-
-const char CategoryPlugin::kType[] = "category";
-
-std::unique_ptr<CategoryPlugin> CategoryPlugin::Create(
-    const PluginInfo& plugin_info) {
-  std::unique_ptr<CategoryPlugin> plugin(new CategoryPlugin(plugin_info));
-  if (!plugin->Load())
-    return nullptr;
-  return plugin;
-}
-
-bool CategoryPlugin::AddPluginInfo(manifest_x* manifest, const char* appid) {
-  plugin_x* plugin = static_cast<plugin_x*>(calloc(1, sizeof(plugin_x)));
-  if (!plugin) {
-    LOG(ERROR) << "out of memory";
-    return false;
-  }
-  plugin->pkgid = strdup(manifest->package);
-  plugin->appid = strdup(appid);
-  plugin->plugin_type = strdup(plugin_info_.type().c_str());
-  plugin->plugin_name = strdup(plugin_info_.name().c_str());
-  manifest->plugin = g_list_append(manifest->plugin, plugin);
-  return true;
-}
-
-std::string CategoryPlugin::GetFunctionName(ActionType action) const {
-  static std::map<ActionType, std::string> names {
-    {ActionType::Install,  "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL"},
-    {ActionType::Upgrade,  "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE"},
-    {ActionType::Uninstall,  "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL"},
-    {ActionType::RecoverInstall, "PKGMGR_CATEGORY_PARSER_PLUGIN_RECOVERINSTALL"},   // NOLINT
-    {ActionType::RecoverUpgrade, "PKGMGR_CATEGORY_PARSER_PLUGIN_RECOVERUPGRADE"},   // NOLINT
-    {ActionType::RecoverUninstall, "PKGMGR_CATEGORY_PARSER_PLUGIN_RECOVERUNINSTALL"},   // NOLINT
-    {ActionType::Clean, "PKGMGR_CATEGORY_PARSER_PLUGIN_CLEAN"},
-    {ActionType::Undo, "PKGMGR_CATEGORY_PARSER_PLUGIN_UNDO"},
-    {ActionType::Removed, "PKGMGR_CATEGORY_PARSER_PLUGIN_REMOVED"},
-  };
-
-  auto pos = names.find(action);
-  if (pos == names.end()) {
-    LOG(INFO) << "Function name not defined";
-    return "";
-  }
-  return pos->second;
-}
-
-bool CategoryPlugin::Run(xmlDocPtr /*doc_ptr*/, manifest_x* manifest,
-         ActionType action_type) {
-  std::string name;
-  std::string tag = GetCategoryName(plugin_info_.name());
-  if (tag.empty())
-    return false;
-
-  std::vector<std::string> appid_list;
-  if (action_type == ActionType::Upgrade) {
-    if (pkgmgrinfo_plugininfo_foreach_plugininfo(manifest->package,
-        CategoryPlugin::kType,
-        plugin_info_.name().c_str(),
-        [](const char*, const char* appid, const char*,
-            const char*, void* user_data) -> int {
-          auto* appid_list =
-              static_cast<std::vector<std::string>*>(user_data);
-          appid_list->emplace_back(std::string(appid));
-          return PMINFO_R_OK;
-        },
-        &appid_list) != PMINFO_R_OK) {
-      LOG(ERROR) << "Failed to get previous execution info";
-      return false;
-    }
-    std::sort(appid_list.begin(), appid_list.end());
-  }
-
-  for (application_x* app : GListRange<application_x*>(manifest->application)) {
-    // pack all categories starting with key to list that will
-    // be sent to the plugin.
-    // e.g. all http://tizen.org/category/antivirus/*
-    //   will be packed for http://tizen.org/category/antivirus
-    GList* category_list = nullptr;
-    for (const char* category : GListRange<char*>(app->category)) {
-      const std::string& sub_key_prefix = plugin_info_.name();
-      if (std::string(category).find(sub_key_prefix) == 0) {
-        __category_t* c = reinterpret_cast<__category_t*>(
-            calloc(1, sizeof(__category_t)));
-        if (!c) {
-          LOG(ERROR) << "Out of memory";
-          g_list_free_full(category_list, &ClearCategoryDetail);
-          return false;
-        }
-        c->name = strdup(category);
-        if (!c->name) {
-          LOG(ERROR) << "Out of memory";
-          free(c);
-          g_list_free_full(category_list, &ClearCategoryDetail);
-          return false;
-        }
-        category_list = g_list_append(category_list, c);
-      }
-    }
-
-    // skip application if it has no given category
-    if (!category_list) {
-      if (action_type != ActionType::Upgrade)
-        continue;
-      auto iter = std::lower_bound(appid_list.begin(), appid_list.end(),
-                                     app->appid);
-      if (iter != appid_list.end() && *iter == app->appid) {
-        name = GetFunctionName(ActionType::Removed);
-        iter = appid_list.erase(iter);
-        category_list = nullptr;
-      } else {
-        continue;
-      }
-    } else {
-      name = GetFunctionName(action_type);
-      if (!AddPluginInfo(manifest, app->appid)) {
-        g_list_free_full(category_list, &ClearCategoryDetail);
-        return false;
-      }
-      auto iter = std::lower_bound(appid_list.begin(), appid_list.end(),
-                                     app->appid);
-      if (iter != appid_list.end() && *iter == app->appid)
-        appid_list.erase(iter);
-    }
-    int result = 0;
-    Exec(name, &result, manifest->package, app->appid, category_list);
-    if (result) {
-      LOG(ERROR) << "Function: " << name << " of plugin "
-                 << plugin_info_.path() << " failed";
-      g_list_free_full(category_list, &ClearCategoryDetail);
-      return false;
-    }
-    g_list_free_full(category_list, &ClearCategoryDetail);
-  }
-
-  if (action_type != ActionType::Upgrade)
-    return true;
-
-  name = GetFunctionName(ActionType::Removed);
-  for (auto appid : appid_list) {
-    int result = 0;
-    Exec(name, &result, manifest->package, appid, nullptr);
-    if (result) {
-      LOG(ERROR) << "Function: " << name << " of plugin "
-                << plugin_info_.path() << " failed";
-      return false;
-    }
-  }
-  return true;
-}
-
-}  // namespace common_installer
diff --git a/src/common/plugins/types/category_plugin.h b/src/common/plugins/types/category_plugin.h
deleted file mode 100644 (file)
index 34b5b98..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (c) 2015 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_PLUGINS_TYPES_CATEGORY_PLUGIN_H_
-#define COMMON_PLUGINS_TYPES_CATEGORY_PLUGIN_H_
-
-#include <memory>
-#include <string>
-
-#include "common/plugins/plugin.h"
-
-namespace common_installer {
-
-class CategoryPlugin : public Plugin {
- public:
-  static const char kType[];
-
-  static std::unique_ptr<CategoryPlugin> Create(const PluginInfo& plugin_info);
-  bool Run(xmlDocPtr doc_ptr, manifest_x* manifest,
-           ActionType action_type) override;
-
- private:
-  bool AddPluginInfo(manifest_x* manifest, const char* appid);
-  std::string GetFunctionName(ActionType action) const;
-
-  using Plugin::Plugin;
-
-  SCOPE_LOG_TAG(CategoryPlugin)
-};
-
-}  // namespace common_installer
-
-#endif  // COMMON_PLUGINS_TYPES_CATEGORY_PLUGIN_H_
diff --git a/src/common/plugins/types/metadata_plugin.cc b/src/common/plugins/types/metadata_plugin.cc
deleted file mode 100644 (file)
index fefb5f7..0000000
+++ /dev/null
@@ -1,192 +0,0 @@
-// Copyright (c) 2015 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/plugins/types/metadata_plugin.h"
-
-#include <pkgmgr-info.h>
-#include <pkgmgr_parser.h>
-
-#include <algorithm>
-#include <map>
-#include <vector>
-
-#include "common/utils/glist_range.h"
-
-namespace {
-
-std::string GetMetadataTag(const std::string& url) {
-  return url.substr(url.find_last_of('/') + 1);
-}
-
-void ClearMetadataDetail(gpointer data) {
-  __metadata_t* meta = reinterpret_cast<__metadata_t*>(data);
-  if (meta->key)
-    free(const_cast<char*>(meta->key));
-  if (meta->value)
-    free(const_cast<char*>(meta->value));
-  free(meta);
-}
-
-}  // namespace
-
-namespace common_installer {
-
-const char MetadataPlugin::kType[] = "metadata";
-
-std::unique_ptr<MetadataPlugin> MetadataPlugin::Create(
-    const PluginInfo& plugin_info) {
-  std::unique_ptr<MetadataPlugin> plugin(new MetadataPlugin(plugin_info));
-  if (!plugin->Load())
-    return nullptr;
-  return plugin;
-}
-
-bool MetadataPlugin::AddPluginInfo(manifest_x* manifest, const char* appid) {
-  plugin_x* plugin = static_cast<plugin_x*>(calloc(1, sizeof(plugin_x)));
-  if (!plugin) {
-    LOG(ERROR) << "out of memory";
-    return false;
-  }
-  plugin->pkgid = strdup(manifest->package);
-  plugin->appid = strdup(appid);
-  plugin->plugin_type = strdup(plugin_info_.type().c_str());
-  plugin->plugin_name = strdup(plugin_info_.name().c_str());
-  if (!plugin->pkgid || !plugin->appid |
-      !plugin->plugin_type || !plugin->plugin_name) {
-    LOG(ERROR) << "out of memory";
-    free(plugin->pkgid);
-    free(plugin->appid);
-    free(plugin->plugin_type);
-    free(plugin->plugin_name);
-    free(plugin);
-    return false;
-  }
-  manifest->plugin = g_list_append(manifest->plugin, plugin);
-  return true;
-}
-
-std::string MetadataPlugin::GetFunctionName(ActionType action) const {
-  static std::map<ActionType, std::string> names {
-    {ActionType::Install,  "PKGMGR_MDPARSER_PLUGIN_INSTALL"},
-    {ActionType::Upgrade,  "PKGMGR_MDPARSER_PLUGIN_UPGRADE"},
-    {ActionType::Uninstall,  "PKGMGR_MDPARSER_PLUGIN_UNINSTALL"},
-    {ActionType::RecoverInstall,  "PKGMGR_MDPARSER_PLUGIN_RECOVERINSTALL"},
-    {ActionType::RecoverUpgrade,  "PKGMGR_MDPARSER_PLUGIN_RECOVERUPGRADE"},
-    {ActionType::RecoverUninstall,  "PKGMGR_MDPARSER_PLUGIN_RECOVERUNINSTALL"},
-    {ActionType::Clean, "PKGMGR_MDPARSER_PLUGIN_CLEAN"},
-    {ActionType::Undo, "PKGMGR_MDPARSER_PLUGIN_UNDO"},
-    {ActionType::Removed, "PKGMGR_MDPARSER_PLUGIN_REMOVED"},
-  };
-
-  auto pos = names.find(action);
-  if (pos == names.end()) {
-    LOG(INFO) << "Function name not defined";
-    return "";
-  }
-  return pos->second;
-}
-
-bool MetadataPlugin::Run(xmlDocPtr /*doc_ptr*/, manifest_x* manifest,
-                         ActionType action_type) {
-  std::string name;
-  std::string tag = GetMetadataTag(plugin_info_.name());
-  if (tag.empty())
-    return false;
-
-  if (action_type == ActionType::Upgrade) {
-    if (pkgmgrinfo_plugininfo_foreach_plugininfo(manifest->package,
-        MetadataPlugin::kType,
-        plugin_info_.name().c_str(),
-        [](const char*, const char* appid, const char*,
-            const char*, void* user_data) -> int {
-          auto* appid_list =
-              static_cast<std::vector<std::string>*>(user_data);
-          appid_list->emplace_back(std::string(appid));
-          return PMINFO_R_OK;
-        },
-        &appid_list_) != PMINFO_R_OK) {
-      LOG(ERROR) << "Failed to get previous execution info";
-      return false;
-    }
-    std::sort(appid_list_.begin(), appid_list_.end());
-  }
-
-  for (application_x* app : GListRange<application_x*>(manifest->application)) {
-    // pack all metadata starting with key to list that will
-    // be sent to the plugin.
-    // e.g. all http://developer.samsung.com/tizen/metadata/profile/*
-    //   will be packed for http://developer.samsung.com/tizen/metadata/profile
-    GList* md_list = nullptr;
-    for (metadata_x* meta : GListRange<metadata_x*>(app->metadata)) {
-      const std::string& sub_key_prefix = plugin_info_.name();
-      if (meta->key && meta->value &&
-          std::string(meta->key).find(sub_key_prefix) == 0) {
-        __metadata_t* md = reinterpret_cast<__metadata_t*>(
-            calloc(1, sizeof(__metadata_t)));
-        if (!md) {
-          LOG(ERROR) << "Out of memory";
-          g_list_free_full(md_list, &ClearMetadataDetail);
-          return false;
-        }
-        md->key = strdup(meta->key);
-        if (!md->key) {
-          LOG(ERROR) << "Out of memory";
-          free(md);
-          g_list_free_full(md_list, &ClearMetadataDetail);
-          return false;
-        }
-        md->value = strdup(meta->value);
-        if (!md->value) {
-          LOG(ERROR) << "Out of memory";
-          ClearMetadataDetail(md);
-          g_list_free_full(md_list, &ClearMetadataDetail);
-          return false;
-        }
-        md_list = g_list_append(md_list, md);
-      }
-    }
-
-    // skip application if it has no given metadata
-    if (!md_list) {
-      continue;
-    } else {
-      name = GetFunctionName(action_type);
-      if (!AddPluginInfo(manifest, app->appid)) {
-        g_list_free_full(md_list, &ClearMetadataDetail);
-        return false;
-      }
-      auto iter = std::lower_bound(appid_list_.begin(), appid_list_.end(),
-                                     app->appid);
-      if (iter != appid_list_.end() && *iter == app->appid)
-        appid_list_.erase(iter);
-    }
-    int result = 0;
-    Exec(name, &result, manifest->package, app->appid, md_list);
-    if (result) {
-      LOG(ERROR) << "Function: " << name << " of plugin "
-                 << plugin_info_.path() << " failed";
-      g_list_free_full(md_list, &ClearMetadataDetail);
-      return false;
-    }
-    g_list_free_full(md_list, &ClearMetadataDetail);
-  }
-
-  if (action_type == ActionType::Clean ||
-      action_type == ActionType::Undo)
-    name = GetFunctionName(action_type);
-  else
-    name = GetFunctionName(ActionType::Removed);
-  for (auto appid : appid_list_) {
-    int result = 0;
-    Exec(name, &result, manifest->package, appid.c_str(), nullptr);
-    if (result) {
-      LOG(ERROR) << "Function: " << name << " of plugin "
-                << plugin_info_.path() << " failed";
-      return false;
-    }
-  }
-  return true;
-}
-
-}  // namespace common_installer
diff --git a/src/common/plugins/types/metadata_plugin.h b/src/common/plugins/types/metadata_plugin.h
deleted file mode 100644 (file)
index 9e95d55..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (c) 2015 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_PLUGINS_TYPES_METADATA_PLUGIN_H_
-#define COMMON_PLUGINS_TYPES_METADATA_PLUGIN_H_
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "common/plugins/plugin.h"
-
-namespace common_installer {
-
-class MetadataPlugin : public Plugin {
- public:
-  static const char kType[];
-
-  static std::unique_ptr<MetadataPlugin> Create(const PluginInfo& plugin_info);
-  bool Run(xmlDocPtr doc_ptr, manifest_x* manifest,
-           ActionType action_type) override;
-
- private:
-  bool AddPluginInfo(manifest_x* manifest, const char* appid);
-  std::string GetFunctionName(ActionType action) const;
-
-  using Plugin::Plugin;
-
-  std::vector<std::string> appid_list_;
-  SCOPE_LOG_TAG(MetadataPlugin)
-};
-
-}  // namespace common_installer
-
-#endif  // COMMON_PLUGINS_TYPES_METADATA_PLUGIN_H_
diff --git a/src/common/plugins/types/tag_plugin.cc b/src/common/plugins/types/tag_plugin.cc
deleted file mode 100644 (file)
index 4c6f0b3..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-// Copyright (c) 2015 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/plugins/types/tag_plugin.h"
-
-#include <map>
-#include <utility>
-
-namespace common_installer {
-
-const char TagPlugin::kType[] = "tag";
-
-std::unique_ptr<TagPlugin> TagPlugin::Create(
-    const PluginInfo& plugin_info, Plugin::ActionType action_type) {
-  std::unique_ptr<TagPlugin> plugin(new TagPlugin(plugin_info, action_type));
-  if (!plugin->Load())
-    return nullptr;
-  return plugin;
-}
-
-std::string TagPlugin::GetFunctionName(ProcessType process,
-                                       ActionType action) const {
-  static std::map<std::pair<ActionType, ProcessType>, std::string> names {
-    {{ActionType::Install,   ProcessType::Pre},  "PKGMGR_PARSER_PLUGIN_PRE_INSTALL"},   // NOLINT
-    {{ActionType::Upgrade,   ProcessType::Pre},  "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE"},   // NOLINT
-    {{ActionType::Uninstall, ProcessType::Pre},  "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL"}, // NOLINT
-    {{ActionType::RecoverInstall, ProcessType::Pre},  "PKGMGR_PARSER_PLUGIN_PRE_RECOVERINSTALL"}, // NOLINT
-    {{ActionType::RecoverUpgrade, ProcessType::Pre},  "PKGMGR_PARSER_PLUGIN_PRE_RECOVERUPGRADE"}, // NOLINT
-    {{ActionType::RecoverUninstall, ProcessType::Pre},  "PKGMGR_PARSER_PLUGIN_PRE_RECOVERUNINSTALL"}, // NOLINT
-    {{ActionType::Install,   ProcessType::Main}, "PKGMGR_PARSER_PLUGIN_INSTALL"},       // NOLINT
-    {{ActionType::Upgrade,   ProcessType::Main}, "PKGMGR_PARSER_PLUGIN_UPGRADE"},       // NOLINT
-    {{ActionType::Uninstall, ProcessType::Main}, "PKGMGR_PARSER_PLUGIN_UNINSTALL"},     // NOLINT
-    {{ActionType::Removed, ProcessType::Main}, "PKGMGR_PARSER_PLUGIN_REMOVED"},     // NOLINT
-    {{ActionType::RecoverInstall, ProcessType::Main},  "PKGMGR_PARSER_PLUGIN_RECOVERINSTALL"}, // NOLINT
-    {{ActionType::RecoverUpgrade, ProcessType::Main},  "PKGMGR_PARSER_PLUGIN_RECOVERUPGRADE"}, // NOLINT
-    {{ActionType::RecoverUninstall, ProcessType::Main},  "PKGMGR_PARSER_PLUGIN_RECOVERUNINSTALL"}, // NOLINT
-    {{ActionType::Clean, ProcessType::Main},  "PKGMGR_PARSER_PLUGIN_CLEAN"}, // NOLINT
-    {{ActionType::Undo, ProcessType::Main},  "PKGMGR_PARSER_PLUGIN_UNDO"}, // NOLINT
-    {{ActionType::Install,   ProcessType::Post}, "PKGMGR_PARSER_PLUGIN_POST_INSTALL"},  // NOLINT
-    {{ActionType::Upgrade,   ProcessType::Post}, "PKGMGR_PARSER_PLUGIN_POST_UPGRADE"},  // NOLINT
-    {{ActionType::Uninstall, ProcessType::Post}, "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL"}, // NOLINT
-    {{ActionType::RecoverInstall, ProcessType::Post},  "PKGMGR_PARSER_PLUGIN_POST_RECOVERINSTALL"}, // NOLINT
-    {{ActionType::RecoverUpgrade, ProcessType::Post},  "PKGMGR_PARSER_PLUGIN_POST_RECOVERUPGRADE"}, // NOLINT
-    {{ActionType::RecoverUninstall, ProcessType::Post},  "PKGMGR_PARSER_PLUGIN_POST_RECOVERUNINSTALL"}, // NOLINT
-  };
-
-  auto pos = names.find(std::make_pair(action, process));
-  if (pos == names.end()) {
-    LOG(INFO) << "Function name not defined";
-    return "";
-  }
-  return pos->second;
-}
-
-xmlNodePtr MakePluginNode(xmlNodePtr node, const std::string& tag_name) {
-    xmlNodePtr ret_node = nullptr;
-    if (tag_name == reinterpret_cast<const char*>(node->name)) {
-        ret_node = xmlCopyNode(node, 1);
-        return ret_node;
-    }
-
-    for (xmlNodePtr child = xmlFirstElementChild(node);
-        child != nullptr; child = xmlNextElementSibling(child)) {
-      xmlNodePtr child_node = MakePluginNode(child, tag_name);
-      if (!child_node)
-        continue;
-      if (!ret_node)
-        ret_node = xmlCopyNode(node, 0);
-      xmlAddChild(ret_node, child_node);
-    }
-    return ret_node;
-}
-
-xmlDocPtr TagPlugin::CreateDocPtrForPlugin(xmlDocPtr doc_ptr,
-    const std::string& tag_name) const {
-  // Make copy of document and root node
-  xmlNodePtr root_node = xmlDocGetRootElement(doc_ptr);
-  if (!root_node) {
-    LOG(ERROR) << "Original document is empty. Cannot create copy for plugin";
-    return nullptr;
-  }
-  xmlDocPtr plugin_doc_ptr = xmlCopyDoc(doc_ptr, 0);
-  xmlNodePtr plugin_root_node = MakePluginNode(root_node, tag_name);
-  if (!plugin_root_node) {
-    LOG(ERROR) << "make plugin node fail";
-    return nullptr;
-  }
-  xmlDocSetRootElement(plugin_doc_ptr, plugin_root_node);
-  xmlSetTreeDoc(plugin_root_node, plugin_doc_ptr);
-  return plugin_doc_ptr;
-}
-
-bool TagPlugin::Run(xmlDocPtr doc_ptr, manifest_x* manifest,
-         ActionType action_type) {
-  xmlDocPtr plugin_doc_ptr = CreateDocPtrForPlugin(doc_ptr,
-                                                   plugin_info_.name());
-  if (!plugin_doc_ptr)
-    return false;
-
-  int result = 0;
-  ActionType type =
-      (action_type_ != ActionType::Unknown &&
-       action_type != ActionType::Undo &&
-       action_type != ActionType::Clean) ? action_type_ : action_type;
-  std::string pre_function = GetFunctionName(ProcessType::Pre, type);
-  Exec(pre_function, &result, manifest->package);
-  if (result) {
-    LOG(ERROR) << "Function: " << pre_function << " of plugin "
-               << plugin_info_.path() << " failed";
-    xmlFreeDoc(plugin_doc_ptr);
-    return false;
-  }
-
-  std::string main_function = GetFunctionName(ProcessType::Main, type);
-  Exec(main_function, &result, plugin_doc_ptr, manifest->package);
-  if (result) {
-    LOG(ERROR) << "Function: " << main_function << " of plugin "
-               << plugin_info_.path() << " failed";
-    xmlFreeDoc(plugin_doc_ptr);
-    return false;
-  }
-
-  std::string post_function = GetFunctionName(ProcessType::Post, type);
-  Exec(post_function, &result, manifest->package);
-  if (result) {
-    LOG(ERROR) << "Function: " << post_function << " of plugin "
-               << plugin_info_.path() << " failed";
-    xmlFreeDoc(plugin_doc_ptr);
-    return false;
-  }
-
-  xmlFreeDoc(plugin_doc_ptr);
-  return true;
-}
-
-
-}  // namespace common_installer
diff --git a/src/common/plugins/types/tag_plugin.h b/src/common/plugins/types/tag_plugin.h
deleted file mode 100644 (file)
index 3b5713a..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (c) 2015 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_PLUGINS_TYPES_TAG_PLUGIN_H_
-#define COMMON_PLUGINS_TYPES_TAG_PLUGIN_H_
-
-#include <manifest_parser/utils/logging.h>
-
-#include <memory>
-#include <string>
-
-#include "common/plugins/plugin.h"
-#include "common/plugins/plugin_list_parser.h"
-
-namespace common_installer {
-
-class TagPlugin : public Plugin {
- public:
-  static const char kType[];
-
-  static std::unique_ptr<TagPlugin> Create(const PluginInfo& plugin_info,
-      Plugin::ActionType action_type = Plugin::ActionType::Unknown);
-
-  bool Run(xmlDocPtr doc_ptr, manifest_x* manifest,
-           ActionType action_type) override;
-
- private:
-  using Plugin::Plugin;
-
-  TagPlugin(const PluginInfo& plugin_info, Plugin::ActionType action_type)
-      : Plugin(plugin_info), action_type_(action_type) {}
-
-  std::string GetFunctionName(ProcessType process, ActionType action) const;
-
-  /**
-   * @brief CreateDocPtrForPlugin
-   *        Create copy of xml document with nodes only matching requested
-   *        tag_name
-   * @param doc_ptr original doc ptr of document
-   * @param tag_name name of required node/nodes
-   * @return requested copy
-   */
-  xmlDocPtr CreateDocPtrForPlugin(xmlDocPtr doc_ptr,
-                                  const std::string& tag_name) const;
-
-  Plugin::ActionType action_type_;
-  SCOPE_LOG_TAG(TagPlugin)
-};
-
-}  // namespace common_installer
-
-#endif  // COMMON_PLUGINS_TYPES_TAG_PLUGIN_H_
index 93adc3f45323eebcea8ba9ad662e6f3856ae8440..6aaffb2e312a2c4926f71093e4cd29a63b6e2a26 100644 (file)
@@ -11,7 +11,7 @@
 #include <memory>
 #include <string>
 
-#include "common/request.h"
+#include "common/utils/request.h"
 
 namespace common_installer {
 
diff --git a/src/common/request.cc b/src/common/request.cc
deleted file mode 100644 (file)
index ff444e0..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright (c) 2015 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/request.h"
-
-#include <tzplatform_config.h>
-#include <unistd.h>
-
-#include <map>
-#include <string>
-
-#include "common/utils/user_util.h"
-
-namespace bf = boost::filesystem;
-
-namespace common_installer {
-
-const std::map<RequestType, const char*> kRequestTypeStringMap = {
-  {RequestType::Unknown, "Unknown"},
-  {RequestType::Install, "Install"},
-  {RequestType::Update, "Update"},
-  {RequestType::Uninstall, "Uninstall"},
-  {RequestType::Reinstall, "Reinstall"},
-  {RequestType::Delta, "Delta"},
-  {RequestType::Move, "Move"},
-  {RequestType::Recovery, "Recovery"},
-  {RequestType::RecoveryUpdate, "RecoveryUpdate"},
-  {RequestType::MountInstall, "MountInstall"},
-  {RequestType::MountUpdate, "MountUpdate"},
-  {RequestType::ManifestDirectInstall, "ManifestDirectInstall"},
-  {RequestType::ManifestDirectUpdate, "ManifestDirectUpdate"},
-  {RequestType::ManifestPartialInstall, "ManifestPartialInstall"},
-  {RequestType::ManifestPartialUpdate, "ManifestPartialUpdate"},
-  {RequestType::PartialUninstall, "PartialUninstall"},
-  {RequestType::ReadonlyUpdateInstall, "ReadonlyUpdateInstall"},
-  {RequestType::ReadonlyUpdateUninstall, "ReadonlyUpdateUninstall"},
-  {RequestType::DisablePkg, "DisablePkg"},
-  {RequestType::EnablePkg, "EnablePkg"},
-  {RequestType::MigrateExtImg, "MigrateExtImg"},
-  {RequestType::RecoverDB, "RecoverDB"},
-};
-
-std::string GetRequestTypeString(RequestType request_type) {
-  const auto& it = kRequestTypeStringMap.find(request_type);
-  if (it == kRequestTypeStringMap.end())
-    return "Unknown";
-  else
-    return it->second;
-}
-
-RequestMode GetRequestMode(uid_t uid) {
-  return (uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) ?
-      RequestMode::GLOBAL : RequestMode::USER;
-}
-
-// Now, readonly app is always installed RO location.
-const char* GetRootAppPath(bool is_readonly, uid_t uid) {
-  if (GetRequestMode(uid) == RequestMode::GLOBAL) {
-    return is_readonly ?
-        tzplatform_getenv(TZ_SYS_RO_APP) : tzplatform_getenv(TZ_SYS_RW_APP);
-  } else {
-    tzplatform_set_user(uid);
-    const char* rootpath = tzplatform_getenv(TZ_USER_APP);
-    tzplatform_reset_user();
-    return rootpath;
-  }
-}
-
-const char* GetExtendedRootAppPath(uid_t uid) {
-  if (GetRequestMode(uid) == RequestMode::GLOBAL) {
-    return tzplatform_getenv(TZ_SYS_EXTENDEDSD_APP);
-  } else {
-    tzplatform_set_user(uid);
-    const char* rootpath = tzplatform_getenv(TZ_USER_EXTENDEDSD_APP);
-    tzplatform_reset_user();
-    return rootpath;
-  }
-}
-
-}  // namespace common_installer
diff --git a/src/common/request.h b/src/common/request.h
deleted file mode 100644 (file)
index db1bab6..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright (c) 2015 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_REQUEST_H_
-#define COMMON_REQUEST_H_
-
-#include <boost/filesystem/path.hpp>
-
-#include <string>
-
-namespace common_installer {
-
-/** Request type received from pkgmgr_installer */
-enum class RequestType : int {
-  Unknown = 0,
-  Install,
-  Update,
-  Uninstall,
-  Reinstall,
-  Delta,
-  Move,
-  Recovery,
-  RecoveryUpdate,
-  MountInstall,
-  MountUpdate,
-  ManifestDirectInstall,
-  ManifestDirectUpdate,
-  ManifestPartialInstall,
-  ManifestPartialUpdate,
-  PartialUninstall,
-  ReadonlyUpdateInstall,
-  ReadonlyUpdateUninstall,
-  DisablePkg,
-  EnablePkg,
-  MigrateExtImg,
-  RecoverDB
-};
-
-/** Request mode (USER vs GLOBAL) */
-enum class RequestMode : int {
-  USER,
-  GLOBAL
-};
-
-/**
- * Get string of given request type
- *
- * \return request mode
- */
-std::string GetRequestTypeString(RequestType request_type);
-
-/**
- * Get mode for current request (GLOBAL/USER)
- *
- * \return request mode
- */
-RequestMode GetRequestMode(uid_t uid);
-
-/**
- * Get apps root path for current request (GLOBAL/USER)
- *
- * \return root application path (eg. $HOME/apps_rw/)
- */
-const char* GetRootAppPath(bool is_readonly, uid_t uid);
-
-/**
- * Get appt root path at exteded storage for current request (GLOBAL/USER)
- *
- * \return root application path at extended path
- *         (eg. $TZ_SYS_MEDIA/extended/globalapps)
- */
-const char* GetExtendedRootAppPath(uid_t uid);
-
-}  // namespace common_installer
-
-#endif  // COMMON_REQUEST_H_
-
index 35d6b2613ddaa6546babceb5b897c34278ff5e6d..91b93da4109b70e35f3b0d87aa25ef70a1b77465 100644 (file)
@@ -18,7 +18,7 @@
 #include <algorithm>
 #include <functional>
 
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/privileges.h"
 #include "common/utils/file_util.h"
 #include "common/utils/glist_range.h"
index 64f87e8b4758334a71a6b5accbbe3393c75151b6..3621d2441192ee9353699771d48e471cf1eb6a0c 100644 (file)
@@ -34,9 +34,9 @@
 #include <vector>
 #include <tuple>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/security_registration.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/utils/base64.h"
 #include "common/utils/file_util.h"
 #include "common/utils/user_util.h"
index 78e7ac147f2cd7036286bbcb43613160e4cf228f..eb3c2ea101cca27364dfe7f984ae855b9fcb3c29 100644 (file)
 #include <regex>
 
 #include "common/certificate_validation.h"
-#include "common/pkgmgr_query.h"
-#include "common/request.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/utils/glist_range.h"
 #include "common/utils/file_util.h"
+#include "common/utils/request.h"
 
 namespace bf = boost::filesystem;
 namespace bi = boost::iostreams;
index 6b0b13e86f6f108c5ffa10fadc4ab0133f2714c0..6e664d22e0e70eebbb628f3d0a723560b8ac6777 100644 (file)
@@ -11,7 +11,7 @@
 
 #include <string>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/utils/file_util.h"
 #include "common/utils/glist_range.h"
 
index 59c8ef1953bb6b1df7fe7e5b2b40012bd308205c..bc1fa54af87368fc93468281bbd0126ad58c4831 100644 (file)
@@ -14,7 +14,7 @@
 #include <algorithm>
 #include <string>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/utils/file_util.h"
 
 namespace bf = boost::filesystem;
index fd81df46baa67fc72a3b23bbcafc59dc90ce8e4a..e2b27a6bc21c726d23416fcd29b00255258d4096 100644 (file)
@@ -14,7 +14,7 @@
 #include <cstdint>
 #include <string>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/shared_dirs.h"
 #include "common/utils/file_util.h"
 #include "common/utils/user_util.h"
index 7b1538f5a1bfdaf5244d71a87d85b80fd5080b38..72332fbc7a26a674093ccb23f75773cf1002cfe4 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <boost/filesystem/operations.hpp>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 
 namespace bf = boost::filesystem;
 
index 2fe5c07e89d8da74fe3d73474f3f903ee8abf636..bba263aaa26490ae3adde1c034d1a5bdc28b9bb1 100644 (file)
@@ -12,8 +12,8 @@
 #include <string>
 
 #include "common/installer_context.h"
-#include "common/paths.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/paths.h"
+#include "common/utils/pkgmgr_query.h"
 
 namespace {
 
index 2961426dbf1bf6668e641287fc53d3d1cb93f66f..9fc033972c1a55439cbe32e823c60e1f7d3340e3 100644 (file)
 #include <string>
 #include <utility>
 
-#include "common/pkgmgr_query.h"
-#include "common/request.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/utils/file_util.h"
 #include "common/utils/user_util.h"
+#include "common/utils/request.h"
 
 namespace bf = boost::filesystem;
 
index abfb3b1220a7825054bea081d9cda26ca21d29f1..3bcd3df53f0eadc25d9be0f06d3704be1e7dc05f 100644 (file)
 
 #include "common/feature_validator.h"
 #include "common/installer_context.h"
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/privileges.h"
 #include "common/pkgmgr_registration.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/step/step.h"
 #include "common/utils/glist_range.h"
 
index fe22b7d6cc6ba1274c83a67d406609e8ece312b8..eadea724ee2c38c8a35d07f3273400b223f1a4dc 100644 (file)
@@ -7,7 +7,7 @@
 
 #include <boost/filesystem.hpp>
 
-#include <common/app_installer.h>
+#include <common/installer/app_installer.h>
 #include <common/installer_context.h>
 #include <common/step/step.h>
 
index bc1636772c7239c3192028ed8b38c43d8fca76bf..6e26f7fcf1c00719006a22f54314798883bedbff 100644 (file)
@@ -14,7 +14,7 @@
 #include <string>
 
 #include "common/pkgmgr_interface.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/utils/file_util.h"
 
 namespace bf = boost::filesystem;
index 3aa4f2b3ee7e509b6634db9844f5cec81bb2d4d2..57a7b901590772a5258f0d8aeec42019a42db3f4 100644 (file)
@@ -11,7 +11,7 @@
 #include <string>
 
 #include "common/external_storage.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 
 namespace {
 
index e9dab43118bcca47ab913b5eccbde7b90592ca93..772b0781471ec33642cf5862228eea13bb14fc31 100644 (file)
 #include <string>
 #include <vector>
 
-#include "common/paths.h"
-#include "common/request.h"
+#include "common/utils/paths.h"
 #include "common/shared_dirs.h"
 #include "common/utils/file_util.h"
 #include "common/utils/glist_range.h"
 #include "common/utils/user_util.h"
+#include "common/utils/request.h"
 
 namespace bf = boost::filesystem;
 namespace ci = common_installer;
index 37b2903576aaa4412c51576c17987d7d32ed9f8f..b4ffb01c4e4fefbd6981c2c6350f85d2b970f28b 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <string>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "utils/file_util.h"
 
 namespace bf = boost::filesystem;
index e6cce4659255f9c69ee3ca9ce29a80f89ab9ffe5..b79b3fb75154cd97cfd5f17d6267c169feef4ee0 100644 (file)
@@ -9,7 +9,7 @@
 #include <cstring>
 #include <string>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/utils/file_util.h"
 
 namespace common_installer {
index 046e8777073906fba89d4a96cd0ec35dfb2b2485..9672b45f8f037b44682bfc906a6e09f3e682cc78 100644 (file)
@@ -10,7 +10,7 @@
 #include <string>
 
 #include "common/shared_dirs.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 
 namespace {
 
index 17970ffe8bfdacf32871b954e2a4d39e0a85dc4c..07e30022b1be525ce94a8142e24f716915ffe7f6 100644 (file)
@@ -11,7 +11,7 @@
 #include <string>
 
 #include "common/security_registration.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 
 namespace bf = boost::filesystem;
 
index db1bce11dfd3587102add62dae8da59813b9b879..62e3dd0cbcaeb2c2bd042434e1fd99419b7a9a32 100644 (file)
@@ -14,9 +14,9 @@
 #include "common/external_storage.h"
 #include "common/shared_dirs.h"
 #include "common/utils/file_util.h"
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/pkgmgr_registration.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 
 namespace bf = boost::filesystem;
 namespace bs = boost::system;
index 1b47b65581cb4823aece88bb0f4a6e10aff836a1..fb5127e4984fcb736c7578bf08f470c51af8f71b 100644 (file)
@@ -11,7 +11,7 @@
 #include <string>
 
 #include "common/external_storage.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 
 namespace {
 
index a4a3c29f4d078b721d180df24fe948220885c3f7..854888a54818a9985ee528e2628e4847ef02ca3c 100644 (file)
@@ -18,7 +18,7 @@
 #include <string>
 #include <vector>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/shared_dirs.h"
 #include "common/utils/file_util.h"
 #include "common/utils/glist_range.h"
index 616de93b427bc1085f3f5629ea2e4721caa1b718..5f2f6ca12d110be18915b04ffeac2e2280dc7bb2 100644 (file)
@@ -8,10 +8,10 @@
 #include <boost/filesystem/path.hpp>
 #include <boost/system/error_code.hpp>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/recovery_file.h"
-#include "common/request.h"
 #include "common/utils/file_util.h"
+#include "common/utils/request.h"
 
 namespace bf = boost::filesystem;
 namespace bs = boost::system;
index 656b1e23640099b1bbaaa8e096304be1e91a8516..bf648ee6e66904f857ee076cd658890620324ef3 100644 (file)
@@ -8,7 +8,7 @@
 #include <boost/system/error_code.hpp>
 #include <pkgmgr-info.h>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/utils/file_util.h"
 #include "common/utils/glist_range.h"
 
index e2cb0646fe451f43780b1786c48a4fe45e07b67d..0b2be0b7f83c53fab528c8f826dc4f7d3979d1fc 100644 (file)
@@ -9,7 +9,7 @@
 #include <boost/system/error_code.hpp>
 #include <pkgmgr-info.h>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/utils/file_util.h"
 
 namespace bf = boost::filesystem;
index fdd324a9772d61aab83fde55e578abfb847c99f2..0bb69994291865e5f9395e2d90ebdfa5b161b2dc 100644 (file)
@@ -10,7 +10,7 @@
 
 #include <pkgmgrinfo_basic.h>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/privileges.h"
 #include "common/shared_dirs.h"
 #include "common/utils/file_util.h"
index 12c843ed77d5011bc1e28b449e4eca2db4bea24e..a6057411f3fada55e7f09473954d0ffa244f2a53 100644 (file)
@@ -14,7 +14,7 @@
 #include <string>
 #include <vector>
 
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/utils/file_util.h"
 #include "common/shared_dirs.h"
 
index 98c4ab7c4fdba939e8784a54673172cbf193c9c8..644f20c737d8047efb0f48b947a3567dba15f95f 100644 (file)
@@ -10,7 +10,7 @@
 #include <string>
 
 #include "common/installer_context.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/shared_dirs.h"
 
 namespace {
index c09330abb7d2cfcfac90ed5efd4534db79d31136..e6b020d2c230b6cf30072f524ba33bba3dbb8f4c 100644 (file)
@@ -11,9 +11,9 @@
 #include <string>
 #include <vector>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/pkgmgr_registration.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/utils/file_util.h"
 
 namespace bs = boost::system;
index fc8333ee2c33f0f22fade6cb6f6be2accf555a35..d8d2abc0c9fb88bb81e2f7c15a7bc9998c689c16 100644 (file)
@@ -11,7 +11,7 @@
 #include <string>
 #include <vector>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/privileges.h"
 #include "common/security_registration.h"
 #include "common/shared_dirs.h"
index 9221fcfeb389b995f92befa0e36d206cc274edb8..d8ad9cf3642d6c9313e7868a2c216f876a4640e0 100644 (file)
@@ -11,7 +11,7 @@
 #include <cstring>
 #include <string>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/pkgmgr_registration.h"
 #include "common/utils/file_util.h"
 
index 661f7632f1e864103aaca8a2bc2c2d3f1c404523..5339bcc7ecef13f31470a4f4093c79a4d6d32ec4 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <string>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 
 namespace bf = boost::filesystem;
 namespace bs = boost::system;
index 74d48ffe4799cd20c943ce24c91fb4290c19c1b1..1aa4e482c2aac7e8a902bad86a12ff512495ca2d 100644 (file)
@@ -9,11 +9,11 @@
 
 #include <string>
 
-#include "common/paths.h"
-#include "common/request.h"
+#include "common/utils/paths.h"
 #include "common/tzip_interface.h"
 #include "common/zip_interface.h"
 #include "common/utils/file_util.h"
+#include "common/utils/request.h"
 
 namespace bf = boost::filesystem;
 namespace bs = boost::system;
index a753b69ff61505bd71eb5146d98d20061b5881fe..e922b0cb0921ea05308007f85cf70a0785dc7c7f 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <pkgmgrinfo_basic.h>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/tzip_interface.h"
 #include "common/zip_interface.h"
 
index 445a42bdcf9f144779ac6b3d5adc0c119c354388..e0fe999def62a8681b6628c2e75e4a817ec5910a 100644 (file)
@@ -10,7 +10,7 @@
 
 #include <string>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/utils/file_util.h"
 #include "common/tzip_interface.h"
 #include "common/zip_interface.h"
index 61e74e6baec6affe4b8617e13929bea9081e948e..449414ac464ebb0fe5c373a5f2b18b227667ade3 100644 (file)
@@ -9,11 +9,11 @@
 
 #include <string>
 
-#include "common/paths.h"
-#include "common/request.h"
+#include "common/utils/paths.h"
 #include "common/tzip_interface.h"
 #include "common/zip_interface.h"
 #include "common/utils/file_util.h"
+#include "common/utils/request.h"
 
 namespace bf = boost::filesystem;
 namespace bs = boost::system;
index 31ee91f3576ea0436ee05fa68dd2cc89dec9a9f3..ad547ca0f2dd7b8b40730bc6b2d4cb883679d144 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <string>
 
-#include "common/paths.h"
+#include "common/utils/paths.h"
 #include "common/tzip_interface.h"
 
 namespace bf = boost::filesystem;
index c688753a2f816f04a69c8da1eb27c969cca8005b..de31a6981f7ba5e244052c1188b45bbeef35f0b7 100644 (file)
@@ -11,7 +11,7 @@
 #include <boost/filesystem.hpp>
 #include <boost/filesystem/path.hpp>
 
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/installer_context.h"
 #include "common/utils/manifest_util.h"
 
index ce70c5e7b741ced720260a64a64cfadd837a5338..6faf760d2a3d534b49265d722768de16bda4e3cc 100644 (file)
@@ -14,7 +14,7 @@
 #include <vector>
 
 #include "common/pkgmgr_dependency.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/utils/glist_range.h"
 #include "common/utils/user_util.h"
 
index 9a3e4f0c0085885f90c89478a170f7469cbad63a..2ab1e2f1dbeed2646301c7562716e559d2b4cc19 100644 (file)
@@ -10,9 +10,9 @@
 #include <string>
 #include <vector>
 
-#include "common/app_installer.h"
+#include "common/installer/app_installer.h"
 #include "common/pkgmgr_dependency.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 
 namespace common_installer {
 namespace pkgmgr {
index ce7b9b006f19015c8be41cf542fcc3ad51b674d0..2107488ee6a578b0620cb810dda932cdff8a86a1 100644 (file)
@@ -13,7 +13,7 @@
 #include <vector>
 
 #include "common/pkgmgr_dependency.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 
 namespace common_installer {
 namespace pkgmgr {
index 526048acca3a1faad4ccff78c4b641e37267e1e8..ff51359446e440adc333012b0ccafca55fd519ce 100644 (file)
@@ -6,8 +6,8 @@
 
 #include <boost/filesystem.hpp>
 
-#include "common/paths.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/paths.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/pkgmgr_registration.h"
 
 namespace bf = boost::filesystem;
index a665b7d5757f8ba9f55d66b70e7ff0985a8cfedf..964f357e276d9aa3da8170f29ee9f7eeb663215d 100644 (file)
@@ -15,7 +15,7 @@
 #include <string>
 
 #include "common/pkgmgr_registration.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/utils/file_util.h"
 
 namespace common_installer {
index 5c55b11dc56fc7f74488026fcfd25cc85887fae3..313447753410dd5c9d4c25ff58f47658c1d3a1eb 100644 (file)
@@ -17,7 +17,7 @@
 #include <string>
 
 #include "common/pkgmgr_registration.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/utils/file_util.h"
 
 namespace bf = boost::filesystem;
index 24844f28b6a92033f4c7efb498555c241e998aad..2d39f6352b94e3e41e655e347f9d173b80c5c9bb 100644 (file)
@@ -5,7 +5,7 @@
 #ifndef COMMON_STEP_PKGMGR_STEP_UPDATE_PKG_DISABLE_INFO_H_
 #define COMMON_STEP_PKGMGR_STEP_UPDATE_PKG_DISABLE_INFO_H_
 
-#include <common/app_installer.h>
+#include <common/installer/app_installer.h>
 #include <common/installer_context.h>
 #include <common/step/step.h>
 
index c5d1236536de8a1d91f9a47b74ab248ee42682c4..ee515b09a48250b64a079b3f17948512caf040a4 100644 (file)
 #include <string>
 #include <utility>
 
-#include "common/pkgmgr_query.h"
-#include "common/request.h"
+#include "common/utils/pkgmgr_query.h"
 #include "common/utils/file_util.h"
 #include "common/utils/user_util.h"
+#include "common/utils/request.h"
 #include "common/recovery_file.h"
 
 namespace bf = boost::filesystem;
index c3cef830ece49d4570ca4ca5c82f2cd45c79cb88..1e4dc39dddfcd43872ca4efc7091bec25d85615c 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <manifest_parser/utils/logging.h>
 
-#include "common/request.h"
+#include "common/utils/request.h"
 
 namespace common_installer {
 namespace recovery {
index fa8d33aa905d689cbdfee3c918c5afe8904f5892..81ed7bee5d451600d6375d02d48be06af6af18bf 100644 (file)
@@ -12,7 +12,7 @@
 #include <string>
 
 #include "common/certificate_validation.h"
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 
 namespace common_installer {
 namespace security {
index 65952564a25b2af8cfe0c0688d49dfba95ac27a8..dfe7aefbef6abfbe67f00a52c5208adcce495c10 100644 (file)
@@ -20,8 +20,8 @@
 #include <string>
 #include <vector>
 
-#include "common/paths.h"
 #include "common/utils/byte_size_literals.h"
+#include "common/utils/paths.h"
 
 namespace ba = boost::algorithm;
 namespace bs = boost::system;
index 218888030d2e4da1ea06893b2e415842f1c85022..23b81e58b24272055bd588307ca35a7b6573889b 100644 (file)
@@ -12,7 +12,7 @@
 #include <boost/filesystem/path.hpp>
 #include <string>
 
-#include "common/pkgmgr_query.h"
+#include "common/utils/pkgmgr_query.h"
 
 namespace bf = boost::filesystem;
 
diff --git a/src/common/utils/paths.cc b/src/common/utils/paths.cc
new file mode 100644 (file)
index 0000000..54f8706
--- /dev/null
@@ -0,0 +1,151 @@
+// Copyright (c) 2015 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/utils/paths.h"
+
+#include <manifest_parser/utils/logging.h>
+
+#include <boost/filesystem/operations.hpp>
+
+#include <pwd.h>
+#include <tzplatform_config.h>
+#include <storage-internal.h>
+
+#include <vector>
+
+#include "common/utils/user_util.h"
+
+namespace bf = boost::filesystem;
+namespace ci = common_installer;
+
+namespace {
+
+const char kImageDir[] = ".image";
+const char kBckExtension[] = ".bck";
+
+boost::filesystem::path GetBackupPath(const boost::filesystem::path& pkg_path) {
+  bf::path backup_path = pkg_path;
+  backup_path += kBckExtension;
+  return backup_path;
+}
+
+}  // namespace
+
+namespace common_installer {
+
+boost::filesystem::path GetBackupPathForPackagePath(
+    const boost::filesystem::path& pkg_path) {
+  return GetBackupPath(pkg_path);
+}
+
+boost::filesystem::path GetBackupPathForManifestFile(
+    const boost::filesystem::path& manifest_path) {
+  return GetBackupPath(manifest_path);
+}
+
+boost::filesystem::path GetBackupPathForIconFile(
+    const boost::filesystem::path& icon_path) {
+  return GetBackupPath(icon_path);
+}
+
+std::string GetIconFileBackupExtension() {
+  return kBckExtension;
+}
+
+boost::filesystem::path GetBackupPathForZipFile(const bf::path& zip_path) {
+  return GetBackupPath(zip_path);
+}
+
+boost::filesystem::path GetMountLocation(const bf::path& pkg_path) {
+  return pkg_path / ".pkg";
+}
+
+boost::filesystem::path GetZipPackageLocation(
+    const boost::filesystem::path& pkg_path,
+    const std::string& pkgid) {
+  return pkg_path / kImageDir / pkgid;
+}
+
+boost::filesystem::path GetExternalCardPath() {
+  char* sdpath = nullptr;
+  int storage_id = 0;
+  int ret;
+
+  ret = storage_get_primary_sdcard(&storage_id, &sdpath);
+  if (ret != STORAGE_ERROR_NONE) {
+    free(sdpath);
+    return bf::path();
+  }
+
+  if (sdpath) {
+    std::string mount_path(sdpath);
+    free(sdpath);
+    return bf::path(mount_path);
+  }
+
+  return bf::path();
+}
+
+boost::filesystem::path GetExternalTepPath(RequestMode request_mode,
+                                           uid_t uid) {
+  bf::path result;
+  bf::path ext_mount_path = GetExternalCardPath();
+  if (bf::is_empty(ext_mount_path))
+    return result;
+  result = ext_mount_path / "tep";
+  if (request_mode == RequestMode::USER)
+    result /= ci::GetUsernameByUid(uid);
+  return result;
+}
+
+boost::filesystem::path GetInternalTepPath(
+    const boost::filesystem::path& pkg_path) {
+  return pkg_path / "tep";
+}
+
+boost::filesystem::path GetIconPath(const bf::path& base_path,
+                      const std::string& pkgid,
+                      const bf::path& icon_filename,
+                      const bf::path& root_path) {
+  std::vector<bf::path> paths;
+  bf::path system_path = base_path / icon_filename;
+  bf::path small_system_path = base_path / "default" / "small" / icon_filename;
+  bf::path res_path = root_path / pkgid / "res" / "icons" / icon_filename;
+
+  paths.push_back(system_path);
+  paths.push_back(small_system_path);
+  paths.push_back(res_path);
+
+  for (auto& path : paths) {
+    if (bf::exists(path))
+      return path;
+  }
+
+  return {};
+}
+
+bool IsExtendedStorageAvailable() {
+  bool is_available = false;
+  int ret = storage_foreach_device_supported(
+      [](int, storage_type_e type, storage_state_e state,
+          const char* path, void* user_data) -> bool {
+        if (type != STORAGE_TYPE_EXTENDED_INTERNAL)
+          return true;
+        if (state != STORAGE_STATE_MOUNTED)
+          return true;
+        bool* is_available = static_cast<bool*>(user_data);
+        if (bf::exists(path))
+          *is_available = true;
+        // Stop iteration
+        return false;
+      },
+      &is_available);
+  if (ret != STORAGE_ERROR_NONE) {
+    LOG(ERROR) << "Failed to call storage_foreach_device_supported()";
+    return false;
+  }
+  return is_available;
+}
+
+}  // namespace common_installer
diff --git a/src/common/utils/paths.h b/src/common/utils/paths.h
new file mode 100644 (file)
index 0000000..996b6a9
--- /dev/null
@@ -0,0 +1,147 @@
+// Copyright (c) 2015 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_UTILS_PATHS_H_
+#define COMMON_UTILS_PATHS_H_
+
+#include <boost/filesystem/path.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <unistd.h>
+
+#include <string>
+
+#include "common/utils/request.h"
+
+namespace common_installer {
+
+/**
+ * \brief Helper function for getting backup path (used for recovery)
+ *        based on package path
+ *
+ * \param pkg_path package path
+ *
+ * \return backup path
+ */
+boost::filesystem::path GetBackupPathForPackagePath(
+    const boost::filesystem::path& pkg_path);
+
+/**
+ * \brief Helper function for getting backup path (used for recovery)
+ *        based on manifest file path
+ *
+ * \param manifest_path path to manifest file
+ *
+ * \return backup path
+ */
+boost::filesystem::path GetBackupPathForManifestFile(
+    const boost::filesystem::path& manifest_path);
+
+/**
+ * \brief Helper function for getting backup path (used for recovery)
+ *        based on icon path
+ *
+ * \param icon_path path to icon file
+ *
+ * \return backup path
+ */
+boost::filesystem::path GetBackupPathForIconFile(
+    const boost::filesystem::path& icon_path);
+
+/**
+ * @brief GetIconFileBackupExtension
+ * @return extension for backup icon files
+ */
+std::string GetIconFileBackupExtension();
+
+/**
+ * \brief Helper function for getting backup path of zip (used for recovery)
+ *        based on zip path
+ *
+ * \param zip_path path to zip file
+ *
+ * \return backup path of zip
+ */
+boost::filesystem::path GetBackupPathForZipFile(
+    const boost::filesystem::path& zip_path);
+
+/**
+ * @brief GetZipPackageLocation
+ *        Returns location where zip package file must be copied during package
+ *        installation.
+ *
+ * @param pkg_path package path
+ * @param pkgid package id
+ *
+ * @return full path of zip package location
+ */
+boost::filesystem::path GetZipPackageLocation(
+    const boost::filesystem::path& pkg_path,
+    const std::string& pkgid);
+
+/**
+ * @brief GetMountLocation
+ *        Returns the mount point of zip package. This location is used to
+ *        mount package.
+ *
+ * @param pkg_path package path for which zip mount location is being obtained
+ *
+ * @return full path of package mount point
+ */
+boost::filesystem::path GetMountLocation(
+    const boost::filesystem::path& pkg_path);
+
+/**
+ * @brief GetExternalCardPath
+ *        Returns full path to mounted filesystem of sd card
+ *
+ * @return path
+ */
+boost::filesystem::path GetExternalCardPath();
+
+/**
+ * @brief GetExternalTepPath
+ *        Returns external installation location for tep package
+ * @param request_mode request type
+ * @param uid user id of request
+ *
+ * @return full directory path
+ */
+boost::filesystem::path GetExternalTepPath(RequestMode request_mode, uid_t uid);
+
+/**
+ * @brief GetInternalTepPath
+ *        Returns internal installation location for tep package
+ * @param pkg_path path of installation request
+ *
+ * @return full directory path
+ */
+boost::filesystem::path GetInternalTepPath(
+    const boost::filesystem::path& pkg_path);
+
+/**
+ * @brief GetIconPath
+ *        Returns internal location for preinstalled global app icon
+ * @param base_path path of icon in application
+ * @param pkgid package id
+ * @param icon_filename filename of icon
+ * @param root_path root path of application
+ *
+ * @return full icon path
+ */
+boost::filesystem::path GetIconPath(const boost::filesystem::path& base_path,
+                      const std::string& pkgid,
+                      const boost::filesystem::path& icon_filename,
+                      const boost::filesystem::path& root_path);
+
+/**
+ * @brief IsExtendedStorageAvailable
+ *        Returns true if the extended storage is available
+ *
+ * @return true is the extended storage is available, otherwise false
+ */
+bool IsExtendedStorageAvailable();
+
+}  // namespace common_installer
+
+#endif  // COMMON_UTILS_PATHS_H_
diff --git a/src/common/utils/pkgmgr_query.cc b/src/common/utils/pkgmgr_query.cc
new file mode 100644 (file)
index 0000000..cd2f947
--- /dev/null
@@ -0,0 +1,391 @@
+// Copyright (c) 2016 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/utils/pkgmgr_query.h"
+
+#include <sys/types.h>
+#include <manifest_parser/utils/logging.h>
+#include <pkgmgr_installer.h>
+#include <pkgmgr_parser.h>
+#include <tzplatform_config.h>
+
+#include <cstring>
+#include <utility>
+
+namespace ci = common_installer;
+
+namespace {
+
+const uid_t kGlobalUserUid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+
+int PkgmgrForeachPluginCallback(const char* pkgid, const char* appid,
+    const char* plugin_type, const char* plugin_name, void* user_data) {
+  auto* data_list =
+      static_cast<std::vector<ci::PkgQueryInterface::PluginInfo>*>(user_data);
+  data_list->emplace_back(pkgid, appid ? appid : "", plugin_type, plugin_name);
+  return PMINFO_R_OK;
+}
+
+}  // namespace
+
+namespace common_installer {
+
+std::shared_ptr<PkgHandle> PkgQueryInterface::PkgQuery::GetResult(
+    const std::string& pkgid, uid_t uid, bool refresh) {
+  const auto& it = query_results_.find(std::make_pair(pkgid, uid));
+  if (it != query_results_.end()) {
+    if (refresh)
+      query_results_.erase(it);
+    else
+      return it->second;
+  }
+
+  pkgmgrinfo_pkginfo_h handle;
+  int error_ = pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid.c_str(), uid,
+      &handle);
+  if (error_ != PMINFO_R_OK) {
+    if (error_ != PMINFO_R_ENOENT)
+      LOG(ERROR) << "Failed to call pkgmgrinfo_pkginfo_get_usr_pkginfo";
+    return nullptr;
+  }
+  auto res = query_results_.emplace(std::make_pair(pkgid, uid),
+      std::make_shared<PkgHandle>(handle));
+  return res.first->second;
+}
+
+PkgQueryInterface::PkgQueryInterface(const std::string& pkgid, uid_t uid,
+    bool refresh)
+    : error_(0), pkgid_(pkgid), uid_(uid) {
+  handle_ = PkgQuery::Instance().GetResult(pkgid_, uid, refresh);
+}
+
+PkgQueryInterface::~PkgQueryInterface() {
+}
+
+bool PkgQueryInterface::IsValid() {
+  return handle_ != nullptr;
+}
+
+int PkgQueryInterface::GetLastOperationError() {
+  return error_;
+}
+
+std::string PkgQueryInterface::Version() {
+  if (!IsValid())
+    return {};
+  char* version = nullptr;
+  error_ = pkgmgrinfo_pkginfo_get_version(handle_->handle, &version);
+  if (error_ != PMINFO_R_OK) {
+    LOG(DEBUG) << "pkgmgrinfo_pkginfo_get_version failed with error: "
+               << error_;
+    return {};
+  }
+  std::string version_value;
+  if (version)
+    version_value = version;
+  return version_value;
+}
+
+std::string PkgQueryInterface::TepPath() {
+  if (!IsValid())
+    return {};
+  char* tep_name = nullptr;
+  error_ = pkgmgrinfo_pkginfo_get_tep_name(handle_->handle, &tep_name);
+  if (error_ != PMINFO_R_OK) {
+    LOG(DEBUG) << "pkgmgrinfo_pkginfo_get_tep_name failed with error: "
+               << error_;
+    return {};
+  }
+  std::string tep_name_value;
+  if (tep_name)
+    tep_name_value = tep_name;
+  return tep_name_value;
+}
+
+std::string PkgQueryInterface::ZipMountFile() {
+  if (!IsValid())
+    return {};
+  char* zip_mount_file = nullptr;
+  error_ = pkgmgrinfo_pkginfo_get_zip_mount_file(handle_->handle,
+          &zip_mount_file);
+  if (error_ != PMINFO_R_OK) {
+    LOG(DEBUG) << "pkgmgrinfo_pkginfo_get_zip_mount_file failed with error: "
+               << error_;
+    return {};
+  }
+  std::string zip_mount_file_value;
+  if (zip_mount_file)
+    zip_mount_file_value = zip_mount_file;
+  return zip_mount_file_value;
+}
+
+std::string PkgQueryInterface::StorageForPkgId() {
+  if (!IsValid())
+    return {};
+  // initial & default : internal
+  std::string installed_location = "installed_internal";
+
+  pkgmgrinfo_installed_storage storage;
+  error_ = pkgmgrinfo_pkginfo_get_installed_storage(handle_->handle, &storage);
+
+  if (error_ != PMINFO_R_OK)
+    return "";
+
+  if (storage == PMINFO_EXTERNAL_STORAGE)
+    installed_location = "installed_external";
+  else if (storage == PMINFO_EXTENDED_STORAGE)
+    installed_location = "installed_extended";
+
+  return installed_location;
+}
+
+std::string PkgQueryInterface::Type() {
+  if (!IsValid())
+    return {};
+  char* type = nullptr;
+  error_ = pkgmgrinfo_pkginfo_get_type(handle_->handle, &type);
+  if (error_ != PMINFO_R_OK) {
+    LOG(DEBUG) << "pkgmgrinfo_pkginfo_get_type failed with error: "
+               << error_;
+    return {};
+  }
+  std::string type_value;
+  if (type)
+    type_value = type;
+  return type_value;
+}
+
+bool PkgQueryInterface::IsPackageInstalled() {
+  if (!IsValid())
+    return false;
+  bool is_global = false;
+  if (pkgmgrinfo_pkginfo_is_for_all_users(handle_->handle, &is_global) !=
+      PMINFO_R_OK) {
+    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_for_all_users failed";
+    return false;
+  }
+
+  if (uid_ == kGlobalUserUid && is_global)
+    return true;
+  if (uid_ != kGlobalUserUid && is_global)
+    return false;
+  return true;
+}
+
+bool PkgQueryInterface::IsPackageInstalled(RequestMode mode) {
+  if (!IsValid())
+    return false;
+  bool is_global = false;
+  error_ = pkgmgrinfo_pkginfo_is_for_all_users(handle_->handle, &is_global);
+  if (error_ != PMINFO_R_OK) {
+    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_for_all_users failed";
+    return false;
+  }
+
+  if (mode == RequestMode::GLOBAL && !is_global)
+    return false;
+  if (mode == RequestMode::USER && is_global)
+    return false;
+
+  return true;
+}
+
+bool PkgQueryInterface::IsGlobalPackage() {
+  if (!IsValid())
+    return false;
+  bool is_global = false;
+  error_ = pkgmgrinfo_pkginfo_is_for_all_users(handle_->handle, &is_global);
+  if (error_ != PMINFO_R_OK) {
+    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_for_all_users failed";
+    return false;
+  }
+  return is_global;
+}
+
+bool PkgQueryInterface::IsReadonlyPackage() {
+  if (!IsValid())
+    return false;
+  bool is_readonly = false;
+  error_ = pkgmgrinfo_pkginfo_is_readonly(handle_->handle, &is_readonly);
+  if (error_ != PMINFO_R_OK) {
+    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_readonly failed";
+    return false;
+  }
+  return is_readonly;
+}
+
+bool PkgQueryInterface::IsUpdatedPackage() {
+  if (!IsValid())
+    return false;
+  bool is_update = false;
+  error_ = pkgmgrinfo_pkginfo_is_update(handle_->handle, &is_update);
+  if (error_ != PMINFO_R_OK) {
+    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_update failed";
+    return false;
+  }
+  return is_update;
+}
+
+bool PkgQueryInterface::IsPreloadPackage() {
+  if (!IsValid())
+    return false;
+  bool is_preload = false;
+  error_ = pkgmgrinfo_pkginfo_is_preload(handle_->handle, &is_preload);
+  if (error_ != PMINFO_R_OK) {
+    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_preload failed";
+    return false;
+  }
+  return is_preload;
+}
+
+bool PkgQueryInterface::IsSystemPackage() {
+  if (!IsValid())
+    return false;
+  bool is_system = false;
+  error_ = pkgmgrinfo_pkginfo_is_system(handle_->handle, &is_system);
+  if (error_ != PMINFO_R_OK) {
+    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_system failed";
+    return false;
+  }
+  return is_system;
+}
+
+bool PkgQueryInterface::IsRemovablePackage() {
+  if (!IsValid())
+    return false;
+  bool is_removable = false;
+  error_ = pkgmgrinfo_pkginfo_is_removable(handle_->handle, &is_removable);
+  if (error_ != PMINFO_R_OK) {
+    LOG(ERROR) << "pkgmgrinfo_pkginfo_is_removable failed";
+    return false;
+  }
+  return is_removable;
+}
+
+bool PkgQueryInterface::AppidsForPkgId(std::vector<std::string>* result) {
+  if (!IsValid())
+    return false;
+  error_ = pkgmgrinfo_appinfo_get_usr_list(handle_->handle, PMINFO_ALL_APP,
+      [](const pkgmgrinfo_appinfo_h handle, void* user_data) -> int {
+        auto* data = static_cast<std::vector<std::string>*>(user_data);
+        char* app_id = nullptr;
+        if (pkgmgrinfo_appinfo_get_appid(handle, &app_id) != PMINFO_R_OK)
+          return PMINFO_R_ERROR;
+        data->emplace_back(app_id);
+        return PMINFO_R_OK;
+      },
+      result, uid_);
+  return error_ == PMINFO_R_OK;
+}
+
+bool PkgQueryInterface::PrivilegesForPkgId(std::vector<std::string>* result) {
+  if (!IsValid())
+    return false;
+  error_ = pkgmgrinfo_pkginfo_foreach_privilege(handle_->handle,
+      [](const char* privilege_name, void* user_data) -> int {
+        auto* data = static_cast<std::vector<std::string>*>(user_data);
+        data->emplace_back(privilege_name);
+        return PMINFO_R_OK;
+      },
+      result);
+  return error_ == PMINFO_R_OK;
+}
+
+bool PkgQueryInterface::PackagesDependsOn(
+    std::vector<DependencyInfo>* result) {
+  if (!IsValid())
+    return false;
+  error_ = pkgmgrinfo_pkginfo_foreach_depends_on(handle_->handle,
+      [](const char* from, const char* to, const char* type,
+          const char* version, void* user_data) -> int {
+        auto* data =
+            static_cast<std::vector<ci::PkgQueryInterface::DependencyInfo>*>(
+                user_data);
+        data->emplace_back(from, to, type, version ? version : "");
+        return PMINFO_R_OK;
+      },
+      result);
+  return error_ == PMINFO_R_OK;
+}
+
+bool PkgQueryInterface::IsPluginExecuted(const std::string& plugin_type,
+                                         const std::string& plugin_name) {
+  if (!IsValid())
+    return false;
+  std::vector<PluginInfo> plugin_list;
+  error_ = pkgmgrinfo_pkginfo_foreach_plugin(handle_->handle,
+      &PkgmgrForeachPluginCallback, &plugin_list);
+  if (error_ != PMINFO_R_OK) {
+    LOG(ERROR) << "Failed to get plugin info";
+    return false;
+  }
+
+  for (const auto& plugin : plugin_list) {
+    if (plugin_type.compare(std::get<2>(plugin)) == 0 &&
+        plugin_name.compare(std::get<3>(plugin)) == 0) {
+      return true;
+    }
+  }
+  return false;
+}
+
+bool PkgQueryInterface::PluginExecutionInfo(
+    std::vector<PluginInfo>* plugin_list) {
+  if (!IsValid())
+    return false;
+
+  error_ = pkgmgrinfo_pkginfo_foreach_plugin(handle_->handle,
+      &PkgmgrForeachPluginCallback, plugin_list);
+  return error_ == PMINFO_R_OK;
+}
+
+std::string QueryCertificateAuthorCertificate(const std::string& pkgid,
+                                              uid_t uid) {
+  pkgmgrinfo_certinfo_h handle;
+  int ret = pkgmgrinfo_pkginfo_create_certinfo(&handle);
+  if (ret != PMINFO_R_OK) {
+    LOG(DEBUG) << "pkgmgrinfo_pkginfo_create_certinfo failed with error: "
+               << ret;
+    return {};
+  }
+  ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid.c_str(), handle, uid);
+  if (ret != PMINFO_R_OK) {
+    if (ret != PMINFO_R_ENOENT)
+      LOG(DEBUG) << "pkgmgrinfo_pkginfo_load_certinfo failed with error: "
+                 << ret;
+    pkgmgrinfo_pkginfo_destroy_certinfo(handle);
+    return {};
+  }
+  const char* author_cert = nullptr;
+  ret = pkgmgrinfo_pkginfo_get_cert_value(handle, PMINFO_AUTHOR_SIGNER_CERT,
+                                          &author_cert);
+  if (ret != PMINFO_R_OK) {
+    LOG(DEBUG) << "pkgmgrinfo_pkginfo_get_cert_value failed with error: "
+               << ret;
+    pkgmgrinfo_pkginfo_destroy_certinfo(handle);
+    return {};
+  }
+  std::string old_author_certificate;
+  if (author_cert)
+    old_author_certificate = author_cert;
+  pkgmgrinfo_pkginfo_destroy_certinfo(handle);
+  return old_author_certificate;
+}
+
+bool QueryIsDisabledPackage(const std::string& pkg_id, uid_t uid) {
+  pkgmgrinfo_pkginfo_h handle;
+  int ret = pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo(pkg_id.c_str(),
+              uid, &handle);
+  if (ret != PMINFO_R_OK) {
+    if (ret != PMINFO_R_ENOENT)
+      LOG(ERROR) <<
+          "Failed to call pkgmgrinfo_pkginfo_get_usr_disabled_pkginfo";
+    return false;
+  }
+
+  pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+  return true;
+}
+
+}  // namespace common_installer
diff --git a/src/common/utils/pkgmgr_query.h b/src/common/utils/pkgmgr_query.h
new file mode 100644 (file)
index 0000000..2b9cf78
--- /dev/null
@@ -0,0 +1,232 @@
+// Copyright (c) 2016 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_UTILS_PKGMGR_QUERY_H_
+#define COMMON_UTILS_PKGMGR_QUERY_H_
+
+#include <unistd.h>
+#include <pkgmgr-info.h>
+#include <sys/types.h>
+
+#include <map>
+#include <memory>
+#include <string>
+#include <tuple>
+#include <utility>
+#include <vector>
+
+#include "common/utils/singleton.h"
+#include "common/utils/request.h"
+
+namespace common_installer {
+
+struct PkgHandle {
+  pkgmgrinfo_pkginfo_h handle;
+  explicit PkgHandle(pkgmgrinfo_pkginfo_h pkginfo_handle) {
+    handle = pkginfo_handle;
+  }
+  ~PkgHandle() {
+    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+  }
+};
+
+/**
+ * \brief Adapter interface for external PkgMgr module.
+ */
+class PkgQueryInterface {
+ public:
+  using PluginInfo =
+      std::tuple<std::string, std::string, std::string, std::string>;
+  using DependencyInfo =
+      std::tuple<std::string, std::string, std::string, std::string>;
+  PkgQueryInterface(const std::string& pkgid, uid_t uid, bool refresh = false);
+  ~PkgQueryInterface();
+
+  bool IsValid();
+  int GetLastOperationError();
+
+  /**
+   * \brief Returns package version for given package.
+   *
+   * @return version or empty
+   */
+  std::string Version();
+
+  /**
+   * \brief Returns tizen extension package path for given package.
+   *
+   * @return path or empty
+   */
+  std::string TepPath();
+
+  /**
+   * \brief Returns zip mount path for given package.
+   *
+   * @return path or empty
+   */
+  std::string ZipMountFile();
+
+  /**
+   * \brief Returns storage for given package.
+   *
+   * @return path or empty
+   */
+  std::string StorageForPkgId();
+
+  /**
+   * \brief Returns type for given package.
+   *
+   * @return type or empty
+   */
+  std::string Type();
+
+  /**
+   * \brief Checks if given package is installed/registered.
+   *
+   * \return true if package is installed
+   */
+  bool IsPackageInstalled();
+
+  /**
+   * \brief Checks if given package is installed/registered as request mode.
+   *
+   * \param mode request mode
+   *
+   * \return true if package is installed
+   */
+  bool IsPackageInstalled(RequestMode mode);
+
+  /**
+   * \brief Checks if given package is global package.
+   *
+   * \return true if package is global package
+   */
+  bool IsGlobalPackage();
+
+  /**
+   * \brief Checks if given package is readonly package.
+   *
+   * \return true if package is readonly
+   */
+  bool IsReadonlyPackage();
+
+  /**
+   * \brief Checks if given package is updated package.
+   *
+   * \return true if package is updated
+   */
+  bool IsUpdatedPackage();
+
+  /**
+   * \brief Checks if given package is preloaded package.
+   *
+   * \return true if package is preloaded
+   */
+  bool IsPreloadPackage();
+
+  /**
+   * \brief Checks if given package is system package.
+   *
+   * \return true if package is system package
+   */
+  bool IsSystemPackage();
+
+  /**
+   * \brief Checks if given package is removable package.
+   *
+   * \return true if package is removable package
+   */
+  bool IsRemovablePackage();
+
+  /**
+   * \brief Returns list of appids for given package.
+   *
+   * \param result[out] Output
+   *
+   * \return true if success
+   */
+  bool AppidsForPkgId(std::vector<std::string>* result);
+  /**
+   * \brief Returns list of privileges for given package
+   *
+   * \param result result - privileges
+   *
+   * \return true if success
+   */
+  bool PrivilegesForPkgId(std::vector<std::string>* result);
+
+  /**
+   * \brief Returns whether plugin has executed for given package
+   *
+   * \param plugin_type plugin type
+   * \param plugin_name plugin name
+   *
+   * \return true if success
+   */
+  bool IsPluginExecuted(const std::string& plugin_type,
+                        const std::string& plugin_name);
+
+  /**
+   * \brief Returns list of plugins executed with given package
+   *
+   * \param plugin_list[out] plugin list
+   *
+   * \return true if success
+   */
+  bool PluginExecutionInfo(std::vector<PluginInfo>* plugin_list);
+
+
+  /**
+   * \brief Returns list of packages depends on given package
+   *
+   * \param result[out] Output
+   *
+   * \return true if success
+   */
+  bool PackagesDependsOn(std::vector<DependencyInfo>* result);
+
+ private:
+  class PkgQuery : public Singleton<PkgQuery> {
+    CRTP_DECLARE_DEFAULT_CONSTRUCTOR_CLASS(PkgQuery)
+   public:
+    std::shared_ptr<PkgHandle> GetResult(const std::string& pkgid, uid_t uid,
+        bool refresh);
+
+   private:
+    std::map<std::pair<std::string, uid_t>, std::shared_ptr<PkgHandle>>
+        query_results_;
+  };
+
+  int error_;
+  std::string pkgid_;
+  uid_t uid_;
+  std::shared_ptr<PkgHandle> handle_;
+};
+
+/**
+ * \brief Adapter interface for external PkgMgr module used for getting
+ *        certificate information for given package
+ *
+ * \param pkgid package pkgid
+ * \param uid user id
+ *
+ * \return returns certificate information
+ */
+std::string QueryCertificateAuthorCertificate(const std::string& pkgid,
+                                              uid_t uid);
+
+/**
+ * \brief Adapter interface for external PkgMgr module used for checking
+ *        if given package is disabled package
+ *
+ * \param pkg_id package id
+ * \param uid user id
+ *
+ * \return true if package is disable.
+ */
+bool QueryIsDisabledPackage(const std::string& pkg_id, uid_t uid);
+
+}  // namespace common_installer
+
+#endif  // COMMON_UTILS_PKGMGR_QUERY_H_
diff --git a/src/common/utils/request.cc b/src/common/utils/request.cc
new file mode 100644 (file)
index 0000000..f109908
--- /dev/null
@@ -0,0 +1,81 @@
+// Copyright (c) 2015 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/utils/request.h"
+
+#include <tzplatform_config.h>
+#include <unistd.h>
+
+#include <map>
+#include <string>
+
+#include "common/utils/user_util.h"
+
+namespace bf = boost::filesystem;
+
+namespace common_installer {
+
+const std::map<RequestType, const char*> kRequestTypeStringMap = {
+  {RequestType::Unknown, "Unknown"},
+  {RequestType::Install, "Install"},
+  {RequestType::Update, "Update"},
+  {RequestType::Uninstall, "Uninstall"},
+  {RequestType::Reinstall, "Reinstall"},
+  {RequestType::Delta, "Delta"},
+  {RequestType::Move, "Move"},
+  {RequestType::Recovery, "Recovery"},
+  {RequestType::RecoveryUpdate, "RecoveryUpdate"},
+  {RequestType::MountInstall, "MountInstall"},
+  {RequestType::MountUpdate, "MountUpdate"},
+  {RequestType::ManifestDirectInstall, "ManifestDirectInstall"},
+  {RequestType::ManifestDirectUpdate, "ManifestDirectUpdate"},
+  {RequestType::ManifestPartialInstall, "ManifestPartialInstall"},
+  {RequestType::ManifestPartialUpdate, "ManifestPartialUpdate"},
+  {RequestType::PartialUninstall, "PartialUninstall"},
+  {RequestType::ReadonlyUpdateInstall, "ReadonlyUpdateInstall"},
+  {RequestType::ReadonlyUpdateUninstall, "ReadonlyUpdateUninstall"},
+  {RequestType::DisablePkg, "DisablePkg"},
+  {RequestType::EnablePkg, "EnablePkg"},
+  {RequestType::MigrateExtImg, "MigrateExtImg"},
+  {RequestType::RecoverDB, "RecoverDB"},
+};
+
+std::string GetRequestTypeString(RequestType request_type) {
+  const auto& it = kRequestTypeStringMap.find(request_type);
+  if (it == kRequestTypeStringMap.end())
+    return "Unknown";
+  else
+    return it->second;
+}
+
+RequestMode GetRequestMode(uid_t uid) {
+  return (uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) ?
+      RequestMode::GLOBAL : RequestMode::USER;
+}
+
+// Now, readonly app is always installed RO location.
+const char* GetRootAppPath(bool is_readonly, uid_t uid) {
+  if (GetRequestMode(uid) == RequestMode::GLOBAL) {
+    return is_readonly ?
+        tzplatform_getenv(TZ_SYS_RO_APP) : tzplatform_getenv(TZ_SYS_RW_APP);
+  } else {
+    tzplatform_set_user(uid);
+    const char* rootpath = tzplatform_getenv(TZ_USER_APP);
+    tzplatform_reset_user();
+    return rootpath;
+  }
+}
+
+const char* GetExtendedRootAppPath(uid_t uid) {
+  if (GetRequestMode(uid) == RequestMode::GLOBAL) {
+    return tzplatform_getenv(TZ_SYS_EXTENDEDSD_APP);
+  } else {
+    tzplatform_set_user(uid);
+    const char* rootpath = tzplatform_getenv(TZ_USER_EXTENDEDSD_APP);
+    tzplatform_reset_user();
+    return rootpath;
+  }
+}
+
+}  // namespace common_installer
diff --git a/src/common/utils/request.h b/src/common/utils/request.h
new file mode 100644 (file)
index 0000000..b9df0e2
--- /dev/null
@@ -0,0 +1,77 @@
+// Copyright (c) 2015 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_UTILS_REQUEST_H_
+#define COMMON_UTILS_REQUEST_H_
+
+#include <boost/filesystem/path.hpp>
+
+#include <string>
+
+namespace common_installer {
+
+/** Request type received from pkgmgr_installer */
+enum class RequestType : int {
+  Unknown = 0,
+  Install,
+  Update,
+  Uninstall,
+  Reinstall,
+  Delta,
+  Move,
+  Recovery,
+  RecoveryUpdate,
+  MountInstall,
+  MountUpdate,
+  ManifestDirectInstall,
+  ManifestDirectUpdate,
+  ManifestPartialInstall,
+  ManifestPartialUpdate,
+  PartialUninstall,
+  ReadonlyUpdateInstall,
+  ReadonlyUpdateUninstall,
+  DisablePkg,
+  EnablePkg,
+  MigrateExtImg,
+  RecoverDB
+};
+
+/** Request mode (USER vs GLOBAL) */
+enum class RequestMode : int {
+  USER,
+  GLOBAL
+};
+
+/**
+ * Get string of given request type
+ *
+ * \return request mode
+ */
+std::string GetRequestTypeString(RequestType request_type);
+
+/**
+ * Get mode for current request (GLOBAL/USER)
+ *
+ * \return request mode
+ */
+RequestMode GetRequestMode(uid_t uid);
+
+/**
+ * Get apps root path for current request (GLOBAL/USER)
+ *
+ * \return root application path (eg. $HOME/apps_rw/)
+ */
+const char* GetRootAppPath(bool is_readonly, uid_t uid);
+
+/**
+ * Get appt root path at exteded storage for current request (GLOBAL/USER)
+ *
+ * \return root application path at extended path
+ *         (eg. $TZ_SYS_MEDIA/extended/globalapps)
+ */
+const char* GetExtendedRootAppPath(uid_t uid);
+
+}  // namespace common_installer
+
+#endif  // COMMON_UTILS_REQUEST_H_
index a2a187b5f4d7a9ade69e611cda8b7c9644a5b021..4a908d6702d490d86323a1cb5d9bf5da4f6550d6 100644 (file)
@@ -7,8 +7,8 @@
 #include <boost/filesystem/path.hpp>
 
 #include <glib.h>
-#include <common/request.h>
 #include <common/utils/file_util.h>
+#include <common/utils/request.h>
 #include <common/utils/subprocess.h>
 #include <common/utils/user_util.h>
 #include <manifest_parser/utils/logging.h>
index 73f8398f652ae2055dac477c1e0666e64d6e6f19..76588e5e775d8b03803d14131a19847f2a6e4f04 100644 (file)
 #include <boost/filesystem/path.hpp>
 #include <gtest/gtest.h>
 
-#include <common/app_installer.h>
-#include <common/paths.h>
+#include <common/installer/app_installer.h>
+#include <common/utils/paths.h>
 #include <common/pkgmgr_interface.h>
-#include <common/pkgmgr_query.h>
+#include <common/utils/pkgmgr_query.h>
 #include <common/tzip_interface.h>
 
 #include <list>
index d9469efbc09131dd2ba9e9ccab8090a47debd0c5..57afe29951fbc363f8b642af4d8d936b92efe277 100644 (file)
 #include <common/utils/subprocess.h>
 #include <common/utils/user_util.h>
 #include <common/utils/file_util.h>
-#include <common/request.h>
+#include <common/utils/request.h>
 #include <common/tzip_interface.h>
-#include <common/app_installer.h>
-#include <common/paths.h>
-#include <common/pkgmgr_query.h>
+#include <common/installer/app_installer.h>
+#include <common/utils/paths.h>
+#include <common/utils/pkgmgr_query.h>
 #include <common/recovery_file.h>
 
 #include <array>