tpk/wgt backend will run as system session 87/80787/15 accepted/tizen/common/20160812.140734 accepted/tizen/ivi/20160815.233243 accepted/tizen/mobile/20160815.233110 accepted/tizen/tv/20160815.233201 accepted/tizen/wearable/20160815.233221 submit/tizen/20160811.013634 submit/tizen/20160811.062803 submit/tizen/20160812.053402
authorJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 20 Jul 2016 07:49:32 +0000 (16:49 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 11 Aug 2016 04:24:56 +0000 (13:24 +0900)
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 <jungh.yeon@samsung.com>
packaging/tpk-backend.manifest
src/tpk/tpk_app_query_interface.cc
src/tpk/tpk_installer.cc
src/unit_tests/manifest_test.cc
src/unit_tests/smoke_test.cc

index d42ffbd..1f49ecb 100644 (file)
@@ -3,6 +3,6 @@
                 <domain name="_" />
         </request>
         <assign>
-                <filesystem path="/usr/bin/tpk-backend" label="System" exec_label="User" />
+                <filesystem path="/usr/bin/tpk-backend" label="System" exec_label="none" />
         </assign>
 </manifest>
index bdf491a..e910fd0 100644 (file)
@@ -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
index 4337dca..230a019 100644 (file)
@@ -12,6 +12,7 @@
 #include <common/step/configuration/step_parse_manifest.h>
 #include <common/step/configuration/step_parse_preload.h>
 #include <common/step/filesystem/step_acquire_external_storage.h>
+#include <common/step/filesystem/step_change_owner.h>
 #include <common/step/filesystem/step_clear_data.h>
 #include <common/step/filesystem/step_copy.h>
 #include <common/step/filesystem/step_copy_storage_directories.h>
@@ -177,6 +178,7 @@ void TpkInstaller::InstallSteps() {
       ci::Plugin::ActionType::Install);
   AddStep<ci::filesystem::StepCreatePerUserStorageDirectories>();
   AddStep<ci::filesystem::StepCreateLegacyDirectories>();
+  AddStep<ci::filesystem::StepChangeOwner>();
 }
 
 void TpkInstaller::UpdateSteps() {
@@ -213,6 +215,7 @@ void TpkInstaller::UpdateSteps() {
   AddStep<tpk::pkgmgr::StepManifestAdjustment>();
   AddStep<ci::pkgmgr::StepUpdateApplication>();
   AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
+  AddStep<ci::filesystem::StepChangeOwner>();
 }
 
 void TpkInstaller::UninstallSteps() {
@@ -273,6 +276,7 @@ void TpkInstaller::ReinstallSteps() {
   AddStep<tpk::pkgmgr::StepManifestAdjustment>();
   AddStep<ci::pkgmgr::StepUpdateApplication>();
   AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
+  AddStep<ci::filesystem::StepChangeOwner>();
 }
 
 void TpkInstaller::DeltaSteps() {
@@ -309,6 +313,7 @@ void TpkInstaller::DeltaSteps() {
   AddStep<tpk::pkgmgr::StepConvertXml>();
   AddStep<ci::pkgmgr::StepUpdateApplication>();
   AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
+  AddStep<ci::filesystem::StepChangeOwner>();
 }
 
 void TpkInstaller::MoveSteps() {
@@ -369,6 +374,7 @@ void TpkInstaller::MountInstallSteps() {
       ci::Plugin::ActionType::Install);
   AddStep<ci::filesystem::StepCreatePerUserStorageDirectories>();
   AddStep<ci::filesystem::StepCreateLegacyDirectories>();
+  AddStep<ci::filesystem::StepChangeOwner>();
 }
 
 void TpkInstaller::MountUpdateSteps() {
@@ -404,6 +410,7 @@ void TpkInstaller::MountUpdateSteps() {
   AddStep<ci::pkgmgr::StepUpdateApplication>();
   AddStep<tpk::filesystem::StepTpkGrantPermission>();
   AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
+  AddStep<ci::filesystem::StepChangeOwner>();
 }
 
 void TpkInstaller::ManifestDirectInstallSteps() {
@@ -428,6 +435,7 @@ void TpkInstaller::ManifestDirectInstallSteps() {
   AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Install);
   AddStep<ci::filesystem::StepCreatePerUserStorageDirectories>();
   AddStep<ci::filesystem::StepCreateLegacyDirectories>();
+  AddStep<ci::filesystem::StepChangeOwner>();
 }
 
 void TpkInstaller::ManifestDirectUpdateSteps() {
@@ -450,6 +458,7 @@ void TpkInstaller::ManifestDirectUpdateSteps() {
   AddStep<ci::pkgmgr::StepUpdateApplication>();
   AddStep<tpk::filesystem::StepTpkGrantPermission>();
   AddStep<ci::pkgmgr::StepRunParserPlugin>(ci::Plugin::ActionType::Upgrade);
+  AddStep<ci::filesystem::StepChangeOwner>();
 }
 
 void TpkInstaller::ClearSteps() {
index 312cc4f..b373f50 100644 (file)
@@ -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_);
 
index 6a25027..f63aaf0 100644 (file)
@@ -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);