From e65689d562029fced817ff8b430071adfb567629 Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Thu, 31 Mar 2016 11:55:31 +0200 Subject: [PATCH] Implement ManifestDirectInstall and ManifestDirectUpdate request handling To verify, try following to scenarios: 1) wgt-backend -i ${package} wgt-backend -y ${pkgid} # package should be updated from its manifest with success 2) wgt-backend -i ${package} rm /home/$USER/.applications/dbspace/* wgt-backend -y ${pkgid} # package should be installed from its manifest with success Submit together: https://review.tizen.org/gerrit/#/c/64204 Change-Id: I47c2af1e71e8f9b0f022c593762644da88afb8f9 --- src/hybrid/CMakeLists.txt | 1 - src/hybrid/hybrid_installer.cc | 63 +++++++++++++++++++--- src/hybrid/step/configuration/step_parse.cc | 22 -------- src/hybrid/step/configuration/step_parse.h | 33 ------------ src/unit_tests/manifest_test.cc | 4 +- src/wgt/CMakeLists.txt | 1 + src/wgt/step/configuration/step_parse.cc | 27 +++++++++- src/wgt/step/configuration/step_parse.h | 10 +++- src/wgt/step/configuration/step_parse_recovery.cc | 18 ++----- src/wgt/step/configuration/step_parse_recovery.h | 7 --- .../step_direct_manifest_check_signature.cc | 23 ++++++++ .../step_direct_manifest_check_signature.h | 28 ++++++++++ src/wgt/wgt_app_query_interface.cc | 14 +++-- src/wgt/wgt_installer.cc | 63 +++++++++++++++++++--- 14 files changed, 216 insertions(+), 98 deletions(-) delete mode 100644 src/hybrid/step/configuration/step_parse.cc delete mode 100644 src/hybrid/step/configuration/step_parse.h create mode 100644 src/wgt/step/security/step_direct_manifest_check_signature.cc create mode 100644 src/wgt/step/security/step_direct_manifest_check_signature.h diff --git a/src/hybrid/CMakeLists.txt b/src/hybrid/CMakeLists.txt index 0e2418f..72cc3d2 100644 --- a/src/hybrid/CMakeLists.txt +++ b/src/hybrid/CMakeLists.txt @@ -1,6 +1,5 @@ SET(SRCS step/configuration/step_merge_tpk_config.cc - step/configuration/step_parse.cc step/configuration/step_stash_tpk_config.cc step/encryption/step_encrypt_resources.cc hybrid_installer.cc diff --git a/src/hybrid/hybrid_installer.cc b/src/hybrid/hybrid_installer.cc index 2f9c274..26d5593 100644 --- a/src/hybrid/hybrid_installer.cc +++ b/src/hybrid/hybrid_installer.cc @@ -58,9 +58,9 @@ #include "hybrid/hybrid_backend_data.h" #include "hybrid/step/configuration/step_merge_tpk_config.h" -#include "hybrid/step/configuration/step_parse.h" #include "hybrid/step/configuration/step_stash_tpk_config.h" #include "hybrid/step/encryption/step_encrypt_resources.h" +#include "wgt/step/configuration/step_parse.h" #include "wgt/step/configuration/step_parse_recovery.h" #include "wgt/step/encryption/step_remove_encryption_data.h" #include "wgt/step/filesystem/step_create_symbolic_link.h" @@ -88,7 +88,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) ci::configuration::StepParseManifest::ManifestLocation::PACKAGE, ci::configuration::StepParseManifest::StoreLocation::NORMAL); AddStep(); - AddStep(true); + AddStep( + wgt::configuration::StepParse::ConfigLocation::RESOURCE_WGT, true); AddStep(); AddStep(); AddStep(); @@ -121,7 +122,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) ci::configuration::StepParseManifest::ManifestLocation::PACKAGE, ci::configuration::StepParseManifest::StoreLocation::NORMAL); AddStep(); - AddStep(true); + AddStep( + wgt::configuration::StepParse::ConfigLocation::RESOURCE_WGT, true); AddStep(); AddStep(); AddStep(); @@ -185,7 +187,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) ci::configuration::StepParseManifest::StoreLocation::NORMAL); AddStep(); AddStep(); - AddStep(true); + AddStep( + wgt::configuration::StepParse::ConfigLocation::RESOURCE_WGT, true); AddStep(); AddStep(); AddStep(); @@ -244,7 +247,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) ci::configuration::StepParseManifest::ManifestLocation::PACKAGE, ci::configuration::StepParseManifest::StoreLocation::NORMAL); AddStep(); - AddStep(true); + AddStep( + wgt::configuration::StepParse::ConfigLocation::RESOURCE_WGT, true); AddStep(); AddStep(); AddStep(); @@ -278,7 +282,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) ci::configuration::StepParseManifest::ManifestLocation::PACKAGE, ci::configuration::StepParseManifest::StoreLocation::NORMAL); AddStep(); - AddStep(true); + AddStep( + wgt::configuration::StepParse::ConfigLocation::RESOURCE_WGT, true); AddStep(); AddStep(); AddStep(); @@ -311,6 +316,52 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep( ci::Plugin::ActionType::Upgrade); break; + case ci::RequestType::ManifestDirectInstall: + AddStep(pkgmgr_); + AddStep( + ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, + ci::configuration::StepParseManifest::StoreLocation::NORMAL); + AddStep(); + AddStep( + wgt::configuration::StepParse::ConfigLocation::INSTALLED, true); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep( + ci::Plugin::ActionType::Install); + AddStep(); + AddStep(); + AddStep(); + break; + case ci::RequestType::ManifestDirectUpdate: + AddStep(pkgmgr_); + AddStep(); + AddStep( + ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, + ci::configuration::StepParseManifest::StoreLocation::NORMAL); + AddStep(); + AddStep( + wgt::configuration::StepParse::ConfigLocation::INSTALLED, true); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep( + ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, + ci::configuration::StepParseManifest::StoreLocation::BACKUP); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep( + ci::Plugin::ActionType::Upgrade); + break; default: AddStep(); break; diff --git a/src/hybrid/step/configuration/step_parse.cc b/src/hybrid/step/configuration/step_parse.cc deleted file mode 100644 index 1e25fbe..0000000 --- a/src/hybrid/step/configuration/step_parse.cc +++ /dev/null @@ -1,22 +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 "hybrid/step/configuration/step_parse.h" - -namespace { - -const char kResWgtPath[] = "res/wgt"; - -} - -namespace hybrid { -namespace configuration { - -bool StepParse::LocateConfigFile() { - return Check(context_->unpacked_dir_path.get() / kResWgtPath); -} - -} // namespace configuration -} // namespace hybrid - diff --git a/src/hybrid/step/configuration/step_parse.h b/src/hybrid/step/configuration/step_parse.h deleted file mode 100644 index 4c5b339..0000000 --- a/src/hybrid/step/configuration/step_parse.h +++ /dev/null @@ -1,33 +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 HYBRID_STEP_CONFIGURATION_STEP_PARSE_H_ -#define HYBRID_STEP_CONFIGURATION_STEP_PARSE_H_ - -#include - -#include "wgt/step/configuration/step_parse.h" - -namespace hybrid { -namespace configuration { - -/** - * \brief This step parse config.xml configuration file of widget - * - * This subclass overrides location of file and it is used when hybrid package - * is installed. - */ -class StepParse : public wgt::configuration::StepParse { - public: - using wgt::configuration::StepParse::StepParse; - - bool LocateConfigFile() override; - - SCOPE_LOG_TAG(Parse) -}; - -} // namespace configuration -} // namespace hybrid - -#endif // HYBRID_STEP_CONFIGURATION_STEP_PARSE_H_ diff --git a/src/unit_tests/manifest_test.cc b/src/unit_tests/manifest_test.cc index 46d2f8b..b72a9bd 100644 --- a/src/unit_tests/manifest_test.cc +++ b/src/unit_tests/manifest_test.cc @@ -48,7 +48,9 @@ class StepParseRunner { bool Run() { PrepareContext(); - wgt::configuration::StepParse step(context_.get(), !ignore_start_files_); + wgt::configuration::StepParse step(context_.get(), + wgt::configuration::StepParse::ConfigLocation::PACKAGE, + !ignore_start_files_); return step.process() == ci::Step::Status::OK; } diff --git a/src/wgt/CMakeLists.txt b/src/wgt/CMakeLists.txt index 7a63521..1542e28 100644 --- a/src/wgt/CMakeLists.txt +++ b/src/wgt/CMakeLists.txt @@ -18,6 +18,7 @@ SET(SRCS step/security/step_check_wgt_background_category.cc step/security/step_check_wgt_notification_category.cc step/security/step_check_wgt_ime_privilege.cc + step/security/step_direct_manifest_check_signature.cc wgt_app_query_interface.cc wgt_installer.cc ) diff --git a/src/wgt/step/configuration/step_parse.cc b/src/wgt/step/configuration/step_parse.cc index c19e7d9..680ab35 100644 --- a/src/wgt/step/configuration/step_parse.cc +++ b/src/wgt/step/configuration/step_parse.cc @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -51,6 +52,8 @@ const char kCategoryWatchClock[] = "com.samsung.wmanager.WATCH_CLOCK"; const std::string kManifestVersion = "1.0.0"; const char kTizenPackageXmlNamespace[] = "http://tizen.org/ns/packages"; +const char kResWgt[] = "res/wgt"; + GList* GenerateMetadataListX(const wgt::parse::MetaDataInfo& meta_info) { GList* list = nullptr; for (auto& meta : meta_info.metadata()) { @@ -90,8 +93,10 @@ namespace app_keys = wgt::application_widget_keys; namespace sc = std::chrono; StepParse::StepParse(common_installer::InstallerContext* context, + ConfigLocation config_location, bool check_start_file) : Step(context), + config_location_(config_location), check_start_file_(check_start_file) { } @@ -519,7 +524,27 @@ bool StepParse::FillManifestX(manifest_x* manifest) { } bool StepParse::LocateConfigFile() { - return StepParse::Check(context_->unpacked_dir_path.get()); + switch (config_location_) { + case ConfigLocation::PACKAGE: + return StepParse::Check(context_->unpacked_dir_path.get()); + case ConfigLocation::INSTALLED: + return StepParse::Check(context_->pkg_path.get() / kResWgt); + case ConfigLocation::RECOVERY: + if (StepParse::Check(common_installer::GetBackupPathForPackagePath( + context_->root_application_path.get() + / context_->pkgid.get()) / kResWgt)) + return true; + if (StepParse::Check( + context_->root_application_path.get() + / context_->pkgid.get() / kResWgt)) + return true; + return false; + case ConfigLocation::RESOURCE_WGT: + return StepParse::Check(context_->unpacked_dir_path.get() / kResWgt); + default: + LOG(ERROR) << "Unknown config location"; + return false; + } } common_installer::Step::Status StepParse::process() { diff --git a/src/wgt/step/configuration/step_parse.h b/src/wgt/step/configuration/step_parse.h index 93a9328..9bc1b73 100644 --- a/src/wgt/step/configuration/step_parse.h +++ b/src/wgt/step/configuration/step_parse.h @@ -27,8 +27,15 @@ namespace configuration { */ class StepParse : public common_installer::Step { public: + enum class ConfigLocation { + PACKAGE, // parse config file from unpacking diretory + INSTALLED, // parse config file from current package installation + RECOVERY, // parse config file from backup location or package location + RESOURCE_WGT // parse config file from unpacking subdiretory "res/wgt" + }; + explicit StepParse(common_installer::InstallerContext* context, - bool check_start_file); + ConfigLocation config_location, bool check_start_file); Status process() override; Status clean() override { return Status::OK; } @@ -63,6 +70,7 @@ class StepParse : public common_installer::Step { bool FillManifestX(manifest_x* manifest); std::unique_ptr parser_; + ConfigLocation config_location_; bool check_start_file_; SCOPE_LOG_TAG(Parse) diff --git a/src/wgt/step/configuration/step_parse_recovery.cc b/src/wgt/step/configuration/step_parse_recovery.cc index 0d8f3dc..c01cb41 100644 --- a/src/wgt/step/configuration/step_parse_recovery.cc +++ b/src/wgt/step/configuration/step_parse_recovery.cc @@ -18,11 +18,13 @@ namespace configuration { StepParseRecovery::StepParseRecovery( common_installer::InstallerContext* context) - : StepParse(context, false) { + : StepParse(context, StepParse::ConfigLocation::RECOVERY, false) { } common_installer::Step::Status StepParseRecovery::process() { (void) StepParse::process(); + context_->pkg_path.set( + context_->root_application_path.get() / context_->pkgid.get()); return Status::OK; } @@ -38,19 +40,5 @@ common_installer::Step::Status StepParseRecovery::precheck() { return Status::OK; } -bool StepParseRecovery::LocateConfigFile() { - context_->pkg_path.set( - context_->root_application_path.get() / context_->pkgid.get()); - - if (Check(common_installer::GetBackupPathForPackagePath( - context_->pkg_path.get()) / kResWgtPath)) - return true; - - if (Check(context_->pkg_path.get() / kResWgtPath)) - return true; - - return false; -} - } // namespace configuration } // namespace wgt diff --git a/src/wgt/step/configuration/step_parse_recovery.h b/src/wgt/step/configuration/step_parse_recovery.h index ad3015d..bc30019 100644 --- a/src/wgt/step/configuration/step_parse_recovery.h +++ b/src/wgt/step/configuration/step_parse_recovery.h @@ -47,13 +47,6 @@ class StepParseRecovery : public StepParse { */ Status precheck() override; - /** - * \brief Locate config.xml file - * - * \return true if config.xml is found - */ - bool LocateConfigFile() override; - SCOPE_LOG_TAG(ParseRecovery) }; diff --git a/src/wgt/step/security/step_direct_manifest_check_signature.cc b/src/wgt/step/security/step_direct_manifest_check_signature.cc new file mode 100644 index 0000000..469a490 --- /dev/null +++ b/src/wgt/step/security/step_direct_manifest_check_signature.cc @@ -0,0 +1,23 @@ +// 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 "wgt/step/security/step_direct_manifest_check_signature.h" + +namespace bf = boost::filesystem; + +namespace { + +const char kResWgt[] = "res/wgt"; + +} // namespace + +namespace wgt { +namespace security { + +bf::path StepDirectManifestCheckSignature::GetSignatureRoot() const { + return StepCheckSignature::GetSignatureRoot() / kResWgt; +} + +} // namespace security +} // namespace wgt diff --git a/src/wgt/step/security/step_direct_manifest_check_signature.h b/src/wgt/step/security/step_direct_manifest_check_signature.h new file mode 100644 index 0000000..a24d910 --- /dev/null +++ b/src/wgt/step/security/step_direct_manifest_check_signature.h @@ -0,0 +1,28 @@ +// 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 WGT_STEP_SECURITY_STEP_DIRECT_MANIFEST_CHECK_SIGNATURE_H_ +#define WGT_STEP_SECURITY_STEP_DIRECT_MANIFEST_CHECK_SIGNATURE_H_ + +#include +#include + +namespace wgt { +namespace security { + +class StepDirectManifestCheckSignature + : public common_installer::security::StepCheckSignature { + public: + using StepCheckSignature::StepCheckSignature; + + private: + boost::filesystem::path GetSignatureRoot() const override; + + SCOPE_LOG_TAG(StepDirectManifestCheckSignature) +}; + +} // namespace security +} // namespace wgt + +#endif // WGT_STEP_SECURITY_STEP_DIRECT_MANIFEST_CHECK_SIGNATURE_H_ diff --git a/src/wgt/wgt_app_query_interface.cc b/src/wgt/wgt_app_query_interface.cc index 02678ee..e4245cc 100644 --- a/src/wgt/wgt_app_query_interface.cc +++ b/src/wgt/wgt_app_query_interface.cc @@ -41,7 +41,7 @@ std::string GetInstallationRequestInfo(int argc, char** argv) { for (int i = 0; i < argc; ++i) { if (!strcmp(argv[i], "-i") || !strcmp(argv[i], "-r") || !strcmp(argv[i], "-d") || !strcmp(argv[i], "-b") || - !strcmp(argv[i], "-w")) { + !strcmp(argv[i], "-w") || !strcmp(argv[i], "-y")) { if (i + 1 < argc) { path = argv[i + 1]; break; @@ -102,10 +102,16 @@ std::string ReadPkgidFromRecovery(const std::string& recovery_path) { namespace wgt { bool WgtAppQueryInterface::IsAppInstalledByArgv(int argc, char** argv) { - std::string path = GetInstallationRequestInfo(argc, argv); - if (path.empty()) + std::string arg = GetInstallationRequestInfo(argc, argv); + if (arg.empty()) return false; - std::string pkg_id = GetPkgIdFromPath(path); + + // argument from commandline is package id + if (ci::IsPackageInstalled(arg, ci::GetRequestMode())) + return true; + + // argument from commandline is path to file + std::string pkg_id = GetPkgIdFromPath(arg); if (pkg_id.empty()) return false; return ci::IsPackageInstalled(pkg_id, ci::GetRequestMode()); diff --git a/src/wgt/wgt_installer.cc b/src/wgt/wgt_installer.cc index 55c7a53..d56dad9 100644 --- a/src/wgt/wgt_installer.cc +++ b/src/wgt/wgt_installer.cc @@ -76,6 +76,7 @@ #include "wgt/step/security/step_check_wgt_background_category.h" #include "wgt/step/security/step_check_wgt_notification_category.h" #include "wgt/step/security/step_check_wgt_ime_privilege.h" +#include "wgt/step/security/step_direct_manifest_check_signature.h" namespace ci = common_installer; @@ -90,7 +91,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) case ci::RequestType::Install : { AddStep(pkgmgr_); AddStep(); - AddStep(true); + AddStep( + wgt::configuration::StepParse::ConfigLocation::PACKAGE, true); AddStep(); AddStep(); AddStep(); @@ -119,7 +121,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) case ci::RequestType::Update: { AddStep(pkgmgr_); AddStep(); - AddStep(true); + AddStep( + wgt::configuration::StepParse::ConfigLocation::PACKAGE, true); AddStep(); AddStep(); AddStep(); @@ -173,7 +176,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) } case ci::RequestType::Reinstall: { AddStep(pkgmgr_); - AddStep(false); + AddStep( + wgt::configuration::StepParse::ConfigLocation::PACKAGE, false); AddStep(); AddStep( ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, @@ -189,10 +193,12 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(pkgmgr_); AddStep(); // TODO(t.iwanek): manifest is parsed twice... - AddStep(false); + AddStep( + wgt::configuration::StepParse::ConfigLocation::PACKAGE, false); // start file may not have changed AddStep("res/wgt/"); - AddStep(true); + AddStep( + wgt::configuration::StepParse::ConfigLocation::PACKAGE, true); AddStep(); AddStep(); AddStep(); @@ -243,7 +249,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) case ci::RequestType::MountInstall: { AddStep(pkgmgr_); AddStep(); - AddStep(true); + AddStep( + wgt::configuration::StepParse::ConfigLocation::PACKAGE, true); AddStep(); AddStep(); AddStep(); @@ -272,7 +279,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) case ci::RequestType::MountUpdate: { AddStep(pkgmgr_); AddStep(); - AddStep(true); + AddStep( + wgt::configuration::StepParse::ConfigLocation::PACKAGE, true); AddStep(); AddStep(); AddStep(); @@ -303,6 +311,47 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); break; } + case ci::RequestType::ManifestDirectInstall: { + AddStep(pkgmgr_); + AddStep( + wgt::configuration::StepParse::ConfigLocation::INSTALLED, true); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(ci::Plugin::ActionType::Install); + AddStep(); + break; + } + case ci::RequestType::ManifestDirectUpdate: { + AddStep(pkgmgr_); + AddStep( + wgt::configuration::StepParse::ConfigLocation::INSTALLED, true); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep( + ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, + ci::configuration::StepParseManifest::StoreLocation::BACKUP); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep( + ci::Plugin::ActionType::Upgrade); + AddStep(); + break; + } default: { AddStep(); } -- 2.7.4