Fix getting icon path 83/45783/4
authorSangyoon Jang <s89.jang@samsung.com>
Tue, 11 Aug 2015 07:45:39 +0000 (16:45 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Thu, 13 Aug 2015 11:30:15 +0000 (20:30 +0900)
try to get icon path from various paths

Change-Id: I7400cc427758a0a4fe4bb2dfdc107fe788b4798a
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
parser/pkgmgr_parser.c

index 9b53af1..e0bb926 100644 (file)
@@ -1494,61 +1494,68 @@ static int __ps_process_datashare(xmlTextReaderPtr reader, datashare_x *datashar
        return ret;
 }
 
-static char *__get_icon_with_path(const char * icon, uid_t uid)
+static char *__get_icon_with_path(const char *icon, uid_t uid)
 {
-       char *theme;
-       char *icon_with_path;
-       char *confirmed_icon;
+       char icon_with_path[BUFSIZE];
        const char *app_path;
-       int len;
 
        if (!icon || !package)
                return NULL;
 
-       if (index(icon, '/') == NULL) {
-/* "db/setting/theme" is not exist */
-#if 0
-               theme = vconf_get_str("db/setting/theme");
-               if (!theme) {
-                       theme = strdup("default");
-                       if(!theme) {
-                               return NULL;
-                       }
-               }
-#else
-               theme = strdup("default");
-#endif
+       /* just use absolute path */
+       if (index(icon, '/'))
+               return strdup(icon);
 
-               len = (0x01 << 7) + strlen(icon) + strlen(package) + strlen(theme);
-               icon_with_path = malloc(len);
-               if(icon_with_path == NULL) {
-                       _LOGD("(icon_with_path == NULL) return\n");
-                       free(theme);
-                       return NULL;
-               }
+       do {
+               snprintf(icon_with_path, sizeof(icon_with_path), "%s%s",
+                               getIconPath(uid), icon);
+               if (access(icon_with_path, F_OK) == 0)
+                       break;
 
-               memset(icon_with_path, 0, len);
-               if (uid != GLOBAL_USER && uid != OWNER_ROOT)
-                       snprintf(icon_with_path, len, "%s%s", getIconPath(uid), icon);
-               else {
-                       snprintf(icon_with_path, len, "%s%s/small/%s", getIconPath(GLOBAL_USER), theme, icon);
-                       if (access (icon_with_path, F_OK)) { //If doesn't exist in case of Global app, try to get icon directly into app's directory
-                               app_path = tzplatform_getenv(TZ_SYS_RW_APP);
-                               if (app_path)
-                                       snprintf(icon_with_path, len, "%s/%s/res/icons/%s/small/%s", app_path, package, theme, icon);
-                               if (access(icon_with_path, F_OK))
-                                       _LOGE("Cannot find icon path");
-                       }
+               /* for backward compatibility (.../default/small/...)
+                * this should be removed
+                */
+               snprintf(icon_with_path, sizeof(icon_with_path),
+                               "%sdefault/small/%s",
+                               getIconPath(uid), icon);
+               if (access(icon_with_path, F_OK) == 0)
+                       break;
+
+               if (uid == GLOBAL_USER || uid == OWNER_ROOT) {
+                       app_path = tzplatform_getenv(TZ_SYS_RW_APP);
+               } else {
+                       tzplatform_set_user(uid);
+                       app_path = tzplatform_getenv(TZ_USER_APP);
+                       tzplatform_reset_user();
                }
-               free(theme);
-               _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
-               return icon_with_path;
-       } else {
-               confirmed_icon = strdup(icon);
-               if (!confirmed_icon)
-                       return NULL;
-               return confirmed_icon;
-       }
+
+               /* If doesn't exist in case of Global app,
+                * try to get icon directly into app's directory
+                */
+               snprintf(icon_with_path, sizeof(icon_with_path),
+                               "%s/%s/%s", app_path, package, icon);
+               if (access(icon_with_path, F_OK) == 0)
+                       break;
+
+               /* some preload package has icons at below path */
+               snprintf(icon_with_path, sizeof(icon_with_path),
+                               "%s/%s/res/icons/%s", app_path, package, icon);
+               if (access(icon_with_path, F_OK) == 0)
+                       break;
+
+               /* since 2.3 tpk package */
+               snprintf(icon_with_path, sizeof(icon_with_path),
+                               "%s/%s/shared/res/%s", app_path, package, icon);
+               if (access(icon_with_path, F_OK) == 0)
+                       break;
+
+               _LOGE("cannot find icon path for [%s]", icon);
+               return NULL;
+       } while (0);
+
+       _LOGD("Icon path : %s ---> %s", icon, icon_with_path);
+
+       return strdup(icon_with_path);
 }
 
 static void __ps_process_tag(manifest_x * mfx, char *const tagv[])