Fix plugin to identify theme json file 84/235184/3
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 2 Jun 2020 11:07:14 +0000 (20:07 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 3 Jun 2020 04:55:30 +0000 (04:55 +0000)
Manifest only contains filename. Absolute path will be
detemined during install so Plugin should construct absolute filepath itself.

Change-Id: I8227fdaaa5ab10dcd63ea5827f9591e9056a3bad
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/theme_plugin/theme_metadata_plugin.cc

index e64b5f4..0236eb7 100644 (file)
@@ -3,7 +3,10 @@
 // found in the LICENSE file.
 
 #include <glib.h>
+
+#include <dlog.h>
 #include <pkgmgr_parser.h>
+#include <pkgmgr-info.h>
 
 #include <cstring>
 #include <string>
@@ -15,6 +18,25 @@ namespace {
 
 const char kThemeMetadataKey[] = "http://tizen.org/metadata/theme";
 
+std::string GetThemeFilePath(const char* pkgid) {
+  pkgmgrinfo_pkginfo_h handle;
+  int ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+  if (ret != PMINFO_R_OK)
+    return {};
+
+  char *root_path;
+  ret = pkgmgrinfo_pkginfo_get_root_path(handle, &root_path);
+  if (ret != PMINFO_R_OK) {
+    pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+    return {};
+  }
+  std::string path(root_path);
+  path += "/res/";
+  pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+  return path;
+}
+
 }  // namespace
 
 bool InstallTheme(const std::string& id, const std::string& path) {
@@ -27,9 +49,13 @@ bool InstallTheme(const std::string& id, const std::string& path) {
 
 extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(
     const char* pkgid, const char* appid, GList* metadata) {
+  std::string root_path = GetThemeFilePath(pkgid);
+  if (root_path.empty())
+    return -1;
+
   for (__metadata_t* md : GListRange<__metadata_t*>(metadata)) {
     if (!strcmp(md->key, kThemeMetadataKey)) {
-      InstallTheme(appid, md->value);
+      InstallTheme(appid, (root_path + md->value));
     }
   }
   return 0;
@@ -45,9 +71,13 @@ bool UpgradeTheme(const std::string& id, const std::string& path) {
 
 extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(
     const char* pkgid, const char* appid, GList* metadata) {
+  std::string root_path = GetThemeFilePath(pkgid);
+  if (root_path.empty())
+    return -1;
+
   for (__metadata_t* md : GListRange<__metadata_t*>(metadata)) {
     if (!strcmp(md->key, kThemeMetadataKey)) {
-      UpgradeTheme(appid, md->value);
+      UpgradeTheme(appid, (root_path + md->value));
     }
   }
   return 0;
@@ -63,9 +93,13 @@ bool UninstallTheme(const std::string& id, const std::string& path) {
 
 extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(
     const char* pkgid, const char* appid, GList* metadata) {
+  std::string root_path = GetThemeFilePath(pkgid);
+  if (root_path.empty())
+    return -1;
+
   for (__metadata_t* md : GListRange<__metadata_t*>(metadata)) {
     if (!strcmp(md->key, kThemeMetadataKey)) {
-      UninstallTheme(appid, md->value);
+      UninstallTheme(appid, (root_path + md->value));
     }
   }
   return 0;