Add uid attribute of ThemeInfo 58/235958/2
authorSangyoon Jang <jeremy.jang@samsung.com>
Thu, 11 Jun 2020 09:52:22 +0000 (18:52 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Mon, 15 Jun 2020 07:14:19 +0000 (07:14 +0000)
Change-Id: I2cbc7fac05bcb6915f9fc629703530e85be86e3a
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
CMakeLists.txt
packaging/tizen-theme-manager.spec
src/theme/loader/theme_info.cc
src/theme/loader/theme_info.h
src/theme_plugin/CMakeLists.txt
src/theme_plugin/theme_metadata_plugin.cc
src/theme_plugin/theme_parser.cc
src/theme_plugin/theme_parser.h
test/unit_tests/test_theme_info.cc
test/unit_tests/test_theme_parser.cc

index 202a2ae..3fe9fb0 100644 (file)
@@ -37,6 +37,7 @@ PKG_CHECK_MODULES(GMOCK_DEPS REQUIRED gmock)
 PKG_CHECK_MODULES(JSONCPP_DEPS REQUIRED jsoncpp)
 PKG_CHECK_MODULES(PKGMGR_PARSER_DEPS REQUIRED pkgmgr-parser)
 PKG_CHECK_MODULES(PKGMGR_INFO_DEPS REQUIRED pkgmgr-info)
+PKG_CHECK_MODULES(PKGMGR_INSTALLER_DEPS REQUIRED pkgmgr-installer)
 PKG_CHECK_MODULES(SQLITE_DEPS REQUIRED sqlite3)
 PKG_CHECK_MODULES(GOBJECT_DEPS REQUIRED gobject-2.0)
 
index 3ed76fe..df25d5d 100644 (file)
@@ -15,6 +15,7 @@ BuildRequires:  pkgconfig(gmock)
 BuildRequires:  pkgconfig(jsoncpp)
 BuildRequires:  pkgconfig(pkgmgr-parser)
 BuildRequires:  pkgconfig(pkgmgr-info)
+BuildRequires:  pkgconfig(pkgmgr-installer)
 BuildRequires:  pkgconfig(sqlite3)
 
 %if 0%{?gcov:1}
index 4f7ccb6..3f54a27 100644 (file)
@@ -33,6 +33,11 @@ std::string ThemeInfo::GetPkgid() const {
   return bundle_.GetString("pkgid");
 }
 
+uid_t ThemeInfo::GetUid() const {
+  std::string uid_str = bundle_.GetString("uid");
+  return std::stoi(uid_str);
+}
+
 std::string ThemeInfo::GetVersion() const {
   return bundle_.GetString("version");
 }
index e28323b..cc4ff41 100644 (file)
@@ -18,6 +18,7 @@
 #define THEME_LOADER_THEME_INFO_H_
 
 #include <bundle_cpp.h>
+#include <sys/types.h>
 
 #include <map>
 #include <memory>
@@ -34,6 +35,7 @@ class ThemeInfo {
 
   std::string GetId() const;
   std::string GetPkgid() const;
+  uid_t GetUid() const;
   std::string GetVersion() const;
   std::string GetToolVersion() const;
   std::string GetTitle() const;
index 6e8aa33..fe12d96 100644 (file)
@@ -8,6 +8,7 @@ APPLY_PKG_CONFIG(${TARGET_TIZEN_THEME_PLUGIN} PUBLIC
   GLIB_DEPS
   JSONCPP_DEPS
   PKGMGR_INFO_DEPS
+  PKGMGR_INSTALLER_DEPS
   PKGMGR_PARSER_DEPS
 )
 
index d4ca146..eadf073 100644 (file)
@@ -5,13 +5,16 @@
 #include <glib.h>
 
 #include <dlog.h>
+#include <pkgmgr_installer_info.h>
 #include <pkgmgr_parser.h>
 #include <pkgmgr-info.h>
+#include <sys/types.h>
 
 #include <cstring>
 #include <string>
 
 #include "theme/utils/glist_range.h"
+#include "theme/utils/logging.h"
 #include "theme_plugin/theme_parser.h"
 
 namespace {
@@ -41,9 +44,15 @@ std::string GetThemeFilePath(const char* pkgid) {
 
 bool InstallTheme(const std::string& id, const std::string& pkgid,
     const std::string& path) {
+  uid_t uid;
+  int r = pkgmgr_installer_info_get_target_uid(&uid);
+  if (r < 0) {
+    LOG(ERROR) << "Failed to get target uid";
+    return false;
+  }
   ttm::plugin::ThemeParser parser(path);
   if (!parser.Commit(ttm::plugin::ThemeParser::ThemeOperation::ADD,
-      parser.Inflate(id, pkgid)))
+      parser.Inflate(id, pkgid, uid)))
     return false;
   return true;
 }
@@ -65,9 +74,15 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(
 
 bool UpgradeTheme(const std::string& id, const std::string& pkgid,
     const std::string& path) {
+  uid_t uid;
+  int r = pkgmgr_installer_info_get_target_uid(&uid);
+  if (r < 0) {
+    LOG(ERROR) << "Failed to get target uid";
+    return false;
+  }
   ttm::plugin::ThemeParser parser(path);
   if (!parser.Commit(ttm::plugin::ThemeParser::ThemeOperation::UPDATE,
-      parser.Inflate(id, pkgid)))
+      parser.Inflate(id, pkgid, uid)))
     return false;
   return true;
 }
@@ -89,9 +104,15 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(
 
 bool UninstallTheme(const std::string& id, const std::string& pkgid,
     const std::string& path) {
+  uid_t uid;
+  int r = pkgmgr_installer_info_get_target_uid(&uid);
+  if (r < 0) {
+    LOG(ERROR) << "Failed to get target uid";
+    return false;
+  }
   ttm::plugin::ThemeParser parser(path);
   if (!parser.Commit(ttm::plugin::ThemeParser::ThemeOperation::REMOVE,
-      parser.Inflate(id, pkgid)))
+      parser.Inflate(id, pkgid, uid)))
     return false;
   return true;
 }
index e48cb4f..12c2479 100644 (file)
@@ -5,6 +5,7 @@
 #include "theme_plugin/theme_parser.h"
 
 #include <json/json.h>
+#include <sys/types.h>
 
 #include <fstream>
 #include <streambuf>
@@ -18,7 +19,7 @@ namespace ttm {
 namespace plugin {
 
 loader::ThemeInfo ThemeParser::Inflate(const std::string id,
-    const std::string pkgid) {
+    const std::string pkgid, uid_t uid) {
   Json::CharReaderBuilder rbuilder;
   rbuilder["collectComments"] = false;
 
@@ -34,6 +35,7 @@ loader::ThemeInfo ThemeParser::Inflate(const std::string id,
   // FIXME: this parser should parse more theme information.
   ThemeInfoBuilder builder("testid");
   builder.PutString("pkgid", pkgid).
+      PutString("uid", std::to_string(uid)).
       PutString("version", root["version"].asString()).
       PutString("tool_version", root["tool_version"].asString()).
       PutString("title", root["header"]["title"].asString()).
index 6d08b9b..b6b120b 100644 (file)
@@ -5,6 +5,8 @@
 #ifndef THEME_PLUGIN_THEME_PARSER_H_
 #define THEME_PLUGIN_THEME_PARSER_H_
 
+#include <sys/types.h>
+
 #include <memory>
 #include <string>
 
@@ -22,7 +24,8 @@ class ThemeParser {
   };
 
   explicit ThemeParser(const std::string& path) : path_(path) {}
-  loader::ThemeInfo Inflate(const std::string id, const std::string pkgid);
+  loader::ThemeInfo Inflate(const std::string id, const std::string pkgid,
+      uid_t uid);
   int Commit(ThemeOperation operation, const loader::ThemeInfo& theme);
 
  private:
index dbbbe3e..895e931 100644 (file)
@@ -31,6 +31,7 @@ class ThemeInfoTest : public testing::Test {
   virtual void SetUp() {
     b_.Add("id", "testid");
     b_.Add("pkgid", "testpkgid");
+    b_.Add("uid", "5001");
     b_.Add("version", "1.0");
     b_.Add("tool_version", "1.1");
     b_.Add("title", "Test");
@@ -57,6 +58,12 @@ TEST_F(ThemeInfoTest, ThemeInfo_GetPkgid) {
   EXPECT_EQ(info.GetPkgid(), "testpkgid");
 }
 
+TEST_F(ThemeInfoTest, ThemeInfo_GetUid) {
+  ThemeInfo info(b_);
+
+  EXPECT_EQ(info.GetUid(), 5001);
+}
+
 TEST_F(ThemeInfoTest, ThemeInfo_GetVersion) {
   ThemeInfo info(b_);
 
@@ -99,6 +106,7 @@ TEST_F(ThemeInfoTest, ThemeInfo_Serialize) {
   tizen_base::Bundle b = info.Serialize();
   EXPECT_EQ(b.GetString("id"), "testid");
   EXPECT_EQ(b.GetString("pkgid"), "testpkgid");
+  EXPECT_EQ(b.GetString("uid"), "5001");
   EXPECT_EQ(b.GetString("version"), "1.0");
   EXPECT_EQ(b.GetString("tool_version"), "1.1");
   EXPECT_EQ(b.GetString("title"), "Test");
index 2723413..500bab0 100644 (file)
@@ -32,9 +32,10 @@ class ThemeParserTest : public testing::Test {
 
 TEST_F(ThemeParserTest, Inflate) {
   ttm::plugin::ThemeParser parser("test_samples/test_theme.json");
-  auto info = parser.Inflate("testid", "testpkgid");
+  auto info = parser.Inflate("testid", "testpkgid", 5001);
   EXPECT_EQ(info.GetId(), "testid");
   EXPECT_EQ(info.GetPkgid(), "testpkgid");
+  EXPECT_EQ(info.GetUid(), 5001);
   EXPECT_EQ(info.GetVersion(), "1.0.0");
   EXPECT_EQ(info.GetToolVersion(), "1.00.38.820793");
   EXPECT_EQ(info.GetTitle(), "GOGO Theme");