From 5276fc398cdec5c422b736548bdd5bb6b13b402c Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Wed, 20 Jul 2016 16:49:32 +0900 Subject: [PATCH] tpk/wgt backend will run as system session Related changes [slp-pkgmgr] https://review.tizen.org/gerrit/#/c/80764/ [pkgmgr-server] https://review.tizen.org/gerrit/#/c/78205/ [app-installers] https://review.tizen.org/gerrit/#/c/78206/ [wgt-backend] https://review.tizen.org/gerrit/#/c/81099/ Change-Id: I8170e2058b97357756847d6dc2cf1e7346345d4b Signed-off-by: Junghyun Yeon --- packaging/tpk-backend.manifest | 2 +- src/tpk/tpk_app_query_interface.cc | 17 ++++++++++++- src/tpk/tpk_installer.cc | 9 +++++++ src/unit_tests/manifest_test.cc | 2 +- src/unit_tests/smoke_test.cc | 49 ++++++++++++++++++++++++++------------ 5 files changed, 61 insertions(+), 18 deletions(-) diff --git a/packaging/tpk-backend.manifest b/packaging/tpk-backend.manifest index d42ffbd..1f49ecb 100644 --- a/packaging/tpk-backend.manifest +++ b/packaging/tpk-backend.manifest @@ -3,6 +3,6 @@ - + diff --git a/src/tpk/tpk_app_query_interface.cc b/src/tpk/tpk_app_query_interface.cc index bdf491a..e910fd0 100644 --- a/src/tpk/tpk_app_query_interface.cc +++ b/src/tpk/tpk_app_query_interface.cc @@ -31,6 +31,20 @@ namespace { const char kManifestFileName[] = "tizen-manifest.xml"; +uid_t GetUid(int argc, char** argv) { + uid_t uid = 0; + for (int i = 0; i < argc; ++i) { + if (!strcmp(argv[i], "-u")) { + if (i + 1 < argc) { + uid = atoi(argv[i + 1]); + break; + } + } + } + + return uid; +} + std::string GetInstallationPackagePath(int argc, char** argv) { std::string path; for (int i = 0; i < argc; ++i) { @@ -102,7 +116,8 @@ bool TpkAppQueryInterface::IsAppInstalledByArgv(int argc, char** argv) { if (pkg_id.empty()) return false; - return ci::QueryIsPackageInstalled(pkg_id, ci::GetRequestMode()); + uid_t uid = GetUid(argc, argv); + return ci::QueryIsPackageInstalled(pkg_id, ci::GetRequestMode(uid), uid); } } // namespace tpk diff --git a/src/tpk/tpk_installer.cc b/src/tpk/tpk_installer.cc index 4337dca..230a019 100644 --- a/src/tpk/tpk_installer.cc +++ b/src/tpk/tpk_installer.cc @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -177,6 +178,7 @@ void TpkInstaller::InstallSteps() { ci::Plugin::ActionType::Install); AddStep(); AddStep(); + AddStep(); } void TpkInstaller::UpdateSteps() { @@ -213,6 +215,7 @@ void TpkInstaller::UpdateSteps() { AddStep(); AddStep(); AddStep(ci::Plugin::ActionType::Upgrade); + AddStep(); } void TpkInstaller::UninstallSteps() { @@ -273,6 +276,7 @@ void TpkInstaller::ReinstallSteps() { AddStep(); AddStep(); AddStep(ci::Plugin::ActionType::Upgrade); + AddStep(); } void TpkInstaller::DeltaSteps() { @@ -309,6 +313,7 @@ void TpkInstaller::DeltaSteps() { AddStep(); AddStep(); AddStep(ci::Plugin::ActionType::Upgrade); + AddStep(); } void TpkInstaller::MoveSteps() { @@ -369,6 +374,7 @@ void TpkInstaller::MountInstallSteps() { ci::Plugin::ActionType::Install); AddStep(); AddStep(); + AddStep(); } void TpkInstaller::MountUpdateSteps() { @@ -404,6 +410,7 @@ void TpkInstaller::MountUpdateSteps() { AddStep(); AddStep(); AddStep(ci::Plugin::ActionType::Upgrade); + AddStep(); } void TpkInstaller::ManifestDirectInstallSteps() { @@ -428,6 +435,7 @@ void TpkInstaller::ManifestDirectInstallSteps() { AddStep(ci::Plugin::ActionType::Install); AddStep(); AddStep(); + AddStep(); } void TpkInstaller::ManifestDirectUpdateSteps() { @@ -450,6 +458,7 @@ void TpkInstaller::ManifestDirectUpdateSteps() { AddStep(); AddStep(); AddStep(ci::Plugin::ActionType::Upgrade); + AddStep(); } void TpkInstaller::ClearSteps() { diff --git a/src/unit_tests/manifest_test.cc b/src/unit_tests/manifest_test.cc index 312cc4f..b373f50 100644 --- a/src/unit_tests/manifest_test.cc +++ b/src/unit_tests/manifest_test.cc @@ -30,7 +30,7 @@ manifest_x* StepParseRunner::GetManifest() const { void StepParseRunner::PrepareContext() { context_.reset(new ci::InstallerContext()); - context_->root_application_path.set(ci::GetRootAppPath(false)); + context_->root_application_path.set(ci::GetRootAppPath(false, getuid())); context_->unpacked_dir_path.set( bf::path(kManifestTestcaseData) / dir_suffix_); diff --git a/src/unit_tests/smoke_test.cc b/src/unit_tests/smoke_test.cc index 6a25027..f63aaf0 100644 --- a/src/unit_tests/smoke_test.cc +++ b/src/unit_tests/smoke_test.cc @@ -55,7 +55,8 @@ enum class RequestResult { class ScopedTzipInterface { public: explicit ScopedTzipInterface(const std::string& pkgid) - : pkg_path_(bf::path(ci::GetRootAppPath(false)) / pkgid), + : pkg_path_(bf::path(ci::GetRootAppPath(false, + tzplatform_getuid(TZ_SYS_DEFAULT_USER))) / pkgid), interface_(ci::GetMountLocation(pkg_path_)) { interface_.MountZip(ci::GetZipPackageLocation(pkg_path_, pkgid)); } @@ -94,7 +95,8 @@ class TestPkgmgrInstaller : public ci::PkgmgrInstallerInterface { }; void RemoveAllRecoveryFiles() { - bf::path root_path = ci::GetRootAppPath(false); + bf::path root_path = ci::GetRootAppPath(false, + tzplatform_getuid(TZ_SYS_DEFAULT_USER)); if (!bf::exists(root_path)) return; for (auto& dir_entry : boost::make_iterator_range( @@ -109,7 +111,8 @@ void RemoveAllRecoveryFiles() { } bf::path FindRecoveryFile() { - bf::path root_path = ci::GetRootAppPath(false); + bf::path root_path = ci::GetRootAppPath(false, + tzplatform_getuid(TZ_SYS_DEFAULT_USER)); for (auto& dir_entry : boost::make_iterator_range( bf::directory_iterator(root_path), bf::directory_iterator())) { if (bf::is_regular_file(dir_entry)) { @@ -124,7 +127,8 @@ bf::path FindRecoveryFile() { bool ValidateFileContentInPackage(const std::string& pkgid, const std::string& relative, const std::string& expected) { - bf::path root_path = ci::GetRootAppPath(false); + bf::path root_path = ci::GetRootAppPath(false, + tzplatform_getuid(TZ_SYS_DEFAULT_USER)); bf::path file_path = root_path / pkgid / relative; if (!bf::exists(file_path)) { LOG(ERROR) << file_path << " doesn't exist"; @@ -145,7 +149,8 @@ bool ValidateFileContentInPackage(const std::string& pkgid, } void ValidatePackageFS(const std::string& pkgid, const std::string& appid) { - bf::path root_path = ci::GetRootAppPath(false); + bf::path root_path = ci::GetRootAppPath(false, + tzplatform_getuid(TZ_SYS_DEFAULT_USER)); bf::path package_path = root_path / pkgid; bf::path binary_path = package_path / "bin" / appid; bf::path data_path = package_path / "data"; @@ -159,7 +164,8 @@ void ValidatePackageFS(const std::string& pkgid, const std::string& appid) { ASSERT_TRUE(bf::exists(cache_path)); bf::path manifest_path = - bf::path(getUserManifestPath(getuid(), false)) / (pkgid + ".xml"); + bf::path(getUserManifestPath( + tzplatform_getuid(TZ_SYS_DEFAULT_USER), false)) / (pkgid + ".xml"); ASSERT_TRUE(bf::exists(manifest_path)); // backups should not exist @@ -170,12 +176,14 @@ void ValidatePackageFS(const std::string& pkgid, const std::string& appid) { } void PackageCheckCleanup(const std::string& pkgid, const std::string&) { - bf::path root_path = ci::GetRootAppPath(false); + bf::path root_path = ci::GetRootAppPath(false, + tzplatform_getuid(TZ_SYS_DEFAULT_USER)); bf::path package_path = root_path / pkgid; ASSERT_FALSE(bf::exists(package_path)); bf::path manifest_path = - bf::path(getUserManifestPath(getuid(), false)) / (pkgid + ".xml"); + bf::path(getUserManifestPath( + tzplatform_getuid(TZ_SYS_DEFAULT_USER), false)) / (pkgid + ".xml"); ASSERT_FALSE(bf::exists(manifest_path)); // backups should not exist @@ -186,13 +194,17 @@ void PackageCheckCleanup(const std::string& pkgid, const std::string&) { } void ValidatePackage(const std::string& pkgid, const std::string& appid) { - ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode())); + ASSERT_TRUE(ci::QueryIsPackageInstalled( + pkgid, ci::GetRequestMode(tzplatform_getuid(TZ_SYS_DEFAULT_USER)), + tzplatform_getuid(TZ_SYS_DEFAULT_USER))); ValidatePackageFS(pkgid, appid); } void CheckPackageNonExistance(const std::string& pkgid, const std::string& appid) { - ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode())); + ASSERT_FALSE(ci::QueryIsPackageInstalled( + pkgid, ci::GetRequestMode(tzplatform_getuid(TZ_SYS_DEFAULT_USER)), + tzplatform_getuid(TZ_SYS_DEFAULT_USER))); PackageCheckCleanup(pkgid, appid); } @@ -391,7 +403,8 @@ TEST_F(SmokeTest, DeltaMode_Tpk) { ValidatePackage(pkgid, appid); // Check delta modifications - bf::path root_path = ci::GetRootAppPath(false); + bf::path root_path = ci::GetRootAppPath(false, + tzplatform_getuid(TZ_SYS_DEFAULT_USER)); ASSERT_FALSE(bf::exists(root_path / pkgid / "DELETED")); ASSERT_TRUE(bf::exists(root_path / pkgid / "ADDED")); ASSERT_TRUE(bf::exists(root_path / pkgid / "bin" / "native")); @@ -408,7 +421,8 @@ TEST_F(SmokeTest, ReinstallMode_Tpk) { ValidatePackage(pkgid, appid); // Check rds modifications - bf::path root_path = ci::GetRootAppPath(false); + bf::path root_path = ci::GetRootAppPath(false, + tzplatform_getuid(TZ_SYS_DEFAULT_USER)); ASSERT_FALSE(bf::exists(root_path / pkgid / "DELETED")); ASSERT_TRUE(bf::exists(root_path / pkgid / "ADDED")); ASSERT_TRUE(bf::exists(root_path / pkgid / "bin" / "native")); @@ -450,7 +464,9 @@ TEST_F(SmokeTest, EnablePkg) { ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK); ASSERT_EQ(DisablePackage(pkgid), ci::AppInstaller::Result::OK); ASSERT_EQ(EnablePackage(pkgid), ci::AppInstaller::Result::OK); - ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode())); + ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode( + tzplatform_getuid(TZ_SYS_DEFAULT_USER)), + tzplatform_getuid(TZ_SYS_DEFAULT_USER))); } TEST_F(SmokeTest, DisablePkg) { @@ -459,7 +475,9 @@ TEST_F(SmokeTest, DisablePkg) { std::string appid = "smokeapp23.DisablePkg"; ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK); ASSERT_EQ(DisablePackage(pkgid), ci::AppInstaller::Result::OK); - ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode())); + ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode( + tzplatform_getuid(TZ_SYS_DEFAULT_USER)), + tzplatform_getuid(TZ_SYS_DEFAULT_USER))); ValidatePackageFS(pkgid, {appid}); } @@ -468,7 +486,8 @@ TEST_F(SmokeTest, ClearMode_Tpk) { std::string pkgid = "smokeapp21"; std::string appid = "smokeapp21.ClearModeTpk"; ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK); - bf::path root_path = ci::GetRootAppPath(false); + bf::path root_path = ci::GetRootAppPath(false, + tzplatform_getuid(TZ_SYS_DEFAULT_USER)); bs::error_code error; bf::create_directory(root_path / pkgid / "data" / "dir", error); ASSERT_FALSE(error); -- 2.7.4