Add pkgid attribute of ThemeInfo 60/235860/2
authorSangyoon Jang <jeremy.jang@samsung.com>
Wed, 10 Jun 2020 09:59:18 +0000 (18:59 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Thu, 11 Jun 2020 09:54:26 +0000 (18:54 +0900)
Change-Id: If3501476cd98f0fd8efafd3039479faf92825415
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/theme/loader/theme_info.cc
src/theme/loader/theme_info.h
src/theme_plugin/theme_metadata_plugin.cc
src/theme_plugin/theme_parser.cc
src/theme_plugin/theme_parser.h
src/theme_provider/db_manager.cc
test/unit_tests/test_theme_info.cc
test/unit_tests/test_theme_parser.cc

index d49b544..4f7ccb6 100644 (file)
@@ -29,6 +29,10 @@ std::string ThemeInfo::GetId() const {
   return bundle_.GetString("id");
 }
 
+std::string ThemeInfo::GetPkgid() const {
+  return bundle_.GetString("pkgid");
+}
+
 std::string ThemeInfo::GetVersion() const {
   return bundle_.GetString("version");
 }
index dfa0662..e28323b 100644 (file)
@@ -33,6 +33,7 @@ class ThemeInfo {
   explicit ThemeInfo(const tizen_base::Bundle& bundle);
 
   std::string GetId() const;
+  std::string GetPkgid() const;
   std::string GetVersion() const;
   std::string GetToolVersion() const;
   std::string GetTitle() const;
index 8ada18a..d4ca146 100644 (file)
@@ -39,10 +39,11 @@ std::string GetThemeFilePath(const char* pkgid) {
 
 }  // namespace
 
-bool InstallTheme(const std::string& id, const std::string& path) {
+bool InstallTheme(const std::string& id, const std::string& pkgid,
+    const std::string& path) {
   ttm::plugin::ThemeParser parser(path);
   if (!parser.Commit(ttm::plugin::ThemeParser::ThemeOperation::ADD,
-      parser.Inflate(id)))
+      parser.Inflate(id, pkgid)))
     return false;
   return true;
 }
@@ -55,17 +56,18 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(
 
   for (__metadata_t* md : GListRange<__metadata_t*>(metadata)) {
     if (!strcmp(md->key, kThemeMetadataKey)) {
-      if (!InstallTheme(appid, (root_path + md->value)))
+      if (!InstallTheme(appid, pkgid, (root_path + md->value)))
         return -1;
     }
   }
   return 0;
 }
 
-bool UpgradeTheme(const std::string& id, const std::string& path) {
+bool UpgradeTheme(const std::string& id, const std::string& pkgid,
+    const std::string& path) {
   ttm::plugin::ThemeParser parser(path);
   if (!parser.Commit(ttm::plugin::ThemeParser::ThemeOperation::UPDATE,
-      parser.Inflate(id)))
+      parser.Inflate(id, pkgid)))
     return false;
   return true;
 }
@@ -78,17 +80,18 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(
 
   for (__metadata_t* md : GListRange<__metadata_t*>(metadata)) {
     if (!strcmp(md->key, kThemeMetadataKey)) {
-      if (!UpgradeTheme(appid, (root_path + md->value)))
+      if (!UpgradeTheme(appid, pkgid, (root_path + md->value)))
         return -1;
     }
   }
   return 0;
 }
 
-bool UninstallTheme(const std::string& id, const std::string& path) {
+bool UninstallTheme(const std::string& id, const std::string& pkgid,
+    const std::string& path) {
   ttm::plugin::ThemeParser parser(path);
   if (!parser.Commit(ttm::plugin::ThemeParser::ThemeOperation::REMOVE,
-      parser.Inflate(id)))
+      parser.Inflate(id, pkgid)))
     return false;
   return true;
 }
@@ -101,7 +104,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(
 
   for (__metadata_t* md : GListRange<__metadata_t*>(metadata)) {
     if (!strcmp(md->key, kThemeMetadataKey)) {
-      if (!UninstallTheme(appid, (root_path + md->value)))
+      if (!UninstallTheme(appid, pkgid, (root_path + md->value)))
         return -1;
     }
   }
index 6c43d69..e48cb4f 100644 (file)
@@ -17,7 +17,8 @@
 namespace ttm {
 namespace plugin {
 
-loader::ThemeInfo ThemeParser::Inflate(const std::string id) {
+loader::ThemeInfo ThemeParser::Inflate(const std::string id,
+    const std::string pkgid) {
   Json::CharReaderBuilder rbuilder;
   rbuilder["collectComments"] = false;
 
@@ -32,7 +33,8 @@ loader::ThemeInfo ThemeParser::Inflate(const std::string id) {
 
   // FIXME: this parser should parse more theme information.
   ThemeInfoBuilder builder("testid");
-  builder.PutString("version", root["version"].asString()).
+  builder.PutString("pkgid", pkgid).
+      PutString("version", root["version"].asString()).
       PutString("tool_version", root["tool_version"].asString()).
       PutString("title", root["header"]["title"].asString()).
       PutString("description", root["header"]["description"].asString());
index b580aef..6d08b9b 100644 (file)
@@ -22,7 +22,7 @@ class ThemeParser {
   };
 
   explicit ThemeParser(const std::string& path) : path_(path) {}
-  loader::ThemeInfo Inflate(const std::string id);
+  loader::ThemeInfo Inflate(const std::string id, const std::string pkgid);
   int Commit(ThemeOperation operation, const loader::ThemeInfo& theme);
 
  private:
index fa4afec..45e860e 100644 (file)
@@ -17,6 +17,7 @@ namespace {
 const char kCreateThemeTableQuery[] =
     "CREATE TABLE IF NOT EXISTS theme (\n"
     "  id           TEXT,\n"
+    "  pkgid        TEXT,\n"
     "  version      TEXT,\n"
     "  tool_version TEXT,\n"
     "  title        TEXT,\n"
@@ -26,9 +27,9 @@ const char kCreateThemeTableQuery[] =
     "  details      BLOB,\n"
     "  PRIMARY KEY (id))";
 const char kInsertQuery[] =
-    "INSERT INTO theme (id, version, tool_version, title, description,"
+    "INSERT INTO theme (id, pkgid, version, tool_version, title, description,"
     "  preview, resolution, details) "
-    "VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
+    "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
 const char kUpdateQuery[] =
     "UPDATE theme SET version = ?, tool_version = ?, title = ?,"
     "  description = ?, preview = ?, resolution = ?, details = ? "
@@ -36,8 +37,8 @@ const char kUpdateQuery[] =
 const char kDeleteQuery[] =
     "DELETE FROM theme WHERE id = ?";
 const char kSelectQuery[] =
-    "SELECT id, version, tool_version, title, description, preview, resolution,"
-    "  details FROM theme WHERE id = ?";
+    "SELECT id, pkgid, version, tool_version, title, description, preview, "
+    "  resolution, details FROM theme WHERE id = ?";
 const char kSelectIdsQuery[] = "SELECT id FROM theme";
 const char kCreateThemeSettingTableQuery[] =
     "CREATE TABLE IF NOT EXISTS theme_setting (\n"
@@ -73,6 +74,8 @@ bool DbManager::Insert(const std::string& id, const tizen_base::Bundle& info) {
   int idx = 1;
   if (!stmt->BindString(idx++, info.GetString("id")))
     return false;
+  if (!stmt->BindString(idx++, info.GetString("pkgid")))
+    return false;
   if (!stmt->BindString(idx++, info.GetString("version")))
     return false;
   if (!stmt->BindString(idx++, info.GetString("tool_version")))
@@ -168,6 +171,7 @@ tizen_base::Bundle DbManager::Select(const std::string& id) {
   int idx = 0;
   tizen_base::Bundle b = tizen_base::Bundle();
   b.Add("id", stmt->GetColumnString(idx++));
+  b.Add("pkgid", stmt->GetColumnString(idx++));
   b.Add("version", stmt->GetColumnString(idx++));
   b.Add("tool_version", stmt->GetColumnString(idx++));
   b.Add("title", stmt->GetColumnString(idx++));
index 984fb5d..dbbbe3e 100644 (file)
@@ -30,6 +30,7 @@ class ThemeInfoTest : public testing::Test {
 
   virtual void SetUp() {
     b_.Add("id", "testid");
+    b_.Add("pkgid", "testpkgid");
     b_.Add("version", "1.0");
     b_.Add("tool_version", "1.1");
     b_.Add("title", "Test");
@@ -50,6 +51,12 @@ TEST_F(ThemeInfoTest, ThemeInfo_GetId) {
   EXPECT_EQ(info.GetId(), "testid");
 }
 
+TEST_F(ThemeInfoTest, ThemeInfo_GetPkgid) {
+  ThemeInfo info(b_);
+
+  EXPECT_EQ(info.GetPkgid(), "testpkgid");
+}
+
 TEST_F(ThemeInfoTest, ThemeInfo_GetVersion) {
   ThemeInfo info(b_);
 
@@ -91,6 +98,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("version"), "1.0");
   EXPECT_EQ(b.GetString("tool_version"), "1.1");
   EXPECT_EQ(b.GetString("title"), "Test");
index 7ec17e0..2723413 100644 (file)
@@ -32,8 +32,9 @@ class ThemeParserTest : public testing::Test {
 
 TEST_F(ThemeParserTest, Inflate) {
   ttm::plugin::ThemeParser parser("test_samples/test_theme.json");
-  auto info = parser.Inflate("testid");
+  auto info = parser.Inflate("testid", "testpkgid");
   EXPECT_EQ(info.GetId(), "testid");
+  EXPECT_EQ(info.GetPkgid(), "testpkgid");
   EXPECT_EQ(info.GetVersion(), "1.0.0");
   EXPECT_EQ(info.GetToolVersion(), "1.00.38.820793");
   EXPECT_EQ(info.GetTitle(), "GOGO Theme");