Fix widget plugin parser 26/86026/2 accepted/tizen/common/20160830.150339 accepted/tizen/ivi/20160831.124238 accepted/tizen/mobile/20160831.124149 accepted/tizen/tv/20160831.124202 accepted/tizen/wearable/20160831.124220 submit/tizen/20160830.074519
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 30 Aug 2016 07:20:54 +0000 (16:20 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 30 Aug 2016 07:35:04 +0000 (16:35 +0900)
- Use pkgmgr API to get app root path

Change-Id: I5dae1335a88e31c87f1627a090d7c7c9b214acc7
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
parser/widget_plugin_parser_db.c

index 2173b64..e186711 100644 (file)
 
 #include <dlog.h>
 #include <tzplatform_config.h>
+#include <pkgmgr-info.h>
 #include <pkgmgr_installer_info.h>
 
 #include "widget_plugin_parser_internal.h"
 
 static int target_uid_initialized;
 static uid_t target_uid;
+static int root_path_initialized;
+static char root_path[PATH_MAX];
 
 static uid_t __get_target_uid(void)
 {
@@ -55,20 +58,32 @@ static int _bind_text(sqlite3_stmt *stmt, int idx, const char *text)
 
 static const char *_get_root_path(const char *pkgid)
 {
-       const char *path;
+       pkgmgrinfo_pkginfo_h pkginfo;
+       char *path = NULL;
        uid_t uid = __get_target_uid();
+       int ret;
+
+       if (root_path_initialized)
+               return root_path;
+
+       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &pkginfo);
+       if (ret != PMINFO_R_OK) {
+               LOGE("Failed to get pkginfo - %d(%s)", ret, pkgid);
+               return NULL;
+       }
 
-       if (uid == 0) {
-               path = tzplatform_mkpath(TZ_SYS_RO_APP, pkgid);
-       } else if (uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) {
-               path = tzplatform_mkpath(TZ_SYS_RW_APP, pkgid);
-       } else {
-               tzplatform_set_user(uid);
-               path = tzplatform_mkpath(TZ_USER_APP, pkgid);
-               tzplatform_reset_user();
+       ret = pkgmgrinfo_pkginfo_get_root_path(pkginfo, &path);
+       if (ret != PMINFO_R_OK) {
+               LOGE("Failed to get root path - %d(%s)", ret, pkgid);
+               pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
+               return NULL;
        }
 
-       return path;
+       snprintf(root_path, sizeof(root_path), "%s", path);
+       pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
+       root_path_initialized = 1;
+
+       return root_path;
 }
 
 static int _insert_support_size(sqlite3 *db, const char *pkgid,
@@ -97,12 +112,13 @@ static int _insert_support_size(sqlite3 *db, const char *pkgid,
                _bind_text(stmt, idx++, classid);
                /* adjust preview image path */
                if (size->preview != NULL) {
-                       if (size->preview[0] == '/')
+                       if (size->preview[0] == '/') {
                                snprintf(buf, sizeof(buf), "%s", size->preview);
-                       else
+                       } else {
                                snprintf(buf, sizeof(buf), "%s/shared/res/%s",
                                                _get_root_path(pkgid),
                                                size->preview);
+                       }
                        _bind_text(stmt, idx++, buf);
                } else {
                        _bind_text(stmt, idx++, NULL);
@@ -194,11 +210,12 @@ static int _insert_icon(sqlite3 *db, const char *pkgid,
                _bind_text(stmt, idx++, classid);
                _bind_text(stmt, idx++, icon->lang);
                /* adjust icon path */
-               if (icon->icon[0] == '/')
+               if (icon->icon[0] == '/') {
                        snprintf(buf, sizeof(buf), "%s", icon->icon);
-               else
+               } else {
                        snprintf(buf, sizeof(buf), "%s/shared/res/%s",
                                        _get_root_path(pkgid), icon->icon);
+               }
                _bind_text(stmt, idx++, buf);
 
                ret = sqlite3_step(stmt);