Remove setuid bit
[platform/core/appfw/ail.git] / src / ail_desktop.c
index 3bd7eda..15e4fa4 100755 (executable)
@@ -22,6 +22,7 @@
 
 
 #define _GNU_SOURCE
+#include <errno.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <time.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <tzplatform_config.h>
 #include <xdgmime.h>
 
-#include <vconf.h>
 #include <glib.h>
+#include <grp.h>
+#include <pwd.h>
 
 #include "ail_private.h"
 #include "ail_db.h"
 #include "ail_sql.h"
 #include "ail.h"
+#include "ail_vconf.h"
+#include "ail_convert.h"
 
-#define OPT_DESKTOP_DIRECTORY "/opt/share/applications"
-#define USR_DESKTOP_DIRECTORY "/usr/share/applications"
-#define BUFSZE 4096
+#define BUFSIZE 4096
+#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
 
 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
 #define argsdelimiter  " \t"
 
+#define SQL_INSERT_LOCALNAME_STR "insert into localname (package, locale, name) values "
+#define SQL_INSERT_LOCALNAME_STR_LEN (sizeof(SQL_INSERT_LOCALNAME_STR)-1)
+
+#define SQL_INSERT_LOCALNAME_INIT_STR  SQL_INSERT_LOCALNAME_STR"( ?, ?, ?) "
+
+#define SQL_LOCALNAME_TRIPLET_STR  ", ( ?, ?, ?)"
+#define SQL_LOCALNAME_TRIPLET_STR_LEN (sizeof(SQL_LOCALNAME_TRIPLET_STR) - 1)
+
 typedef enum {
        NOTI_ADD,
        NOTI_UPDATE,
@@ -55,26 +67,27 @@ typedef enum {
 
 struct entry_parser {
        const char *field;
-       ail_error_e (*value_cb)(void *data, char *tag, char *value);
+       ail_error_e (*value_cb)(void *data, char *tag, char *value, uid_t uid);
 };
 
-inline static char *_ltrim(char *str)
+static inline char *_ltrim(char *str)
 {
-       if (!str) return NULL;
+       if (!str)
+               return NULL;
 
-       while (*str == ' ' || *str == '\t' || *str == '\n') str ++;
+       while (*str == ' ' || *str == '\t' || *str == '\n')
+               str++;
 
        return str;
 }
 
-
-
-inline static int _rtrim(char *str)
+static inline int _rtrim(char *str)
 {
        int len;
 
        len = strlen(str);
-       while (--len >= 0 && (str[len] == ' ' || str[len] == '\n' || str[len] == '\t')) str[len] = '\0';
+       while (--len >= 0 && (str[len] == ' ' || str[len] == '\n' || str[len] == '\t'))
+               str[len] = '\0';
 
        return len;
 }
@@ -103,6 +116,8 @@ typedef struct {
        char*           x_slp_appid;
        char*           x_slp_pkgid;
        char*           x_slp_domain;
+       char*           x_slp_submodemainid;
+       char*           x_slp_installedstorage;
        int             x_slp_baselayoutwidth;
        int             x_slp_installedtime;
        int             nodisplay;
@@ -111,13 +126,12 @@ typedef struct {
        int             x_slp_removable;
        int             x_slp_ishorizontalscale;
        int             x_slp_enabled;
+       int             x_slp_submode;
        char*           desktop;
        GSList*         localname;
 } desktop_info_s;
 
-
-
-static ail_error_e _read_exec(void *data, char *tag, char *value)
+static ail_error_e _read_exec(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
        char *token_exe_path;
@@ -131,7 +145,7 @@ static ail_error_e _read_exec(void *data, char *tag, char *value)
        retv_if(!info->exec, AIL_ERROR_OUT_OF_MEMORY);
 
        temp_exec = strdup(value);
-       if(!temp_exec) {
+       if (!temp_exec) {
                free(info->exec);
                return AIL_ERROR_OUT_OF_MEMORY;
        }
@@ -139,7 +153,7 @@ static ail_error_e _read_exec(void *data, char *tag, char *value)
        token_exe_path = strtok_r(temp_exec, argsdelimiter, &save_ptr);
 
        info->x_slp_exe_path = strdup(token_exe_path);
-       if(!info->x_slp_exe_path) {
+       if (!info->x_slp_exe_path) {
                free(info->exec);
                info->exec = NULL;
                free(temp_exec);
@@ -151,9 +165,7 @@ static ail_error_e _read_exec(void *data, char *tag, char *value)
        return AIL_ERROR_OK;
 }
 
-
-
-static ail_error_e _read_name(void *data, char *tag, char *value)
+static ail_error_e _read_name(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
@@ -164,17 +176,17 @@ static ail_error_e _read_name(void *data, char *tag, char *value)
        if (tag && strlen(tag) > 0) {
                struct name_item *item;
                item = (struct name_item *)calloc(1, sizeof(struct name_item));
-               retv_if (NULL == item, AIL_ERROR_OUT_OF_MEMORY);
+               retv_if(NULL == item, AIL_ERROR_OUT_OF_MEMORY);
 
                SAFE_FREE_AND_STRDUP(tag, item->locale);
-               if(NULL == item->locale) {
+               if (item->locale == NULL) {
                        _E("(NULL == item->locale) return\n");
                        free(item);
                        return AIL_ERROR_OUT_OF_MEMORY;
                }
 
                SAFE_FREE_AND_STRDUP(value, item->name);
-               if(NULL == item->name) {
+               if (item->name == NULL) {
                        _E("(NULL == item->name) return\n");
                        free(item->locale);
                        free(item);
@@ -186,15 +198,13 @@ static ail_error_e _read_name(void *data, char *tag, char *value)
                return AIL_ERROR_OK;
        } else {
                SAFE_FREE_AND_STRDUP(value, info->name);
-               retv_if (!info->name, AIL_ERROR_OUT_OF_MEMORY);
+               retv_if(!info->name, AIL_ERROR_OUT_OF_MEMORY);
 
                return AIL_ERROR_OK;
        }
 }
 
-
-
-static ail_error_e _read_type(void *data, char *tag, char *value)
+static ail_error_e _read_type(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
@@ -202,35 +212,31 @@ static ail_error_e _read_type(void *data, char *tag, char *value)
        retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
 
        SAFE_FREE_AND_STRDUP(value, info->type);
-       retv_if (!info->type, AIL_ERROR_OUT_OF_MEMORY);
+       retv_if(!info->type, AIL_ERROR_OUT_OF_MEMORY);
 
        return AIL_ERROR_OK;
 }
 
-
-static char*
-_get_package_from_icon(char* icon)
+static char *_get_package_from_icon(char* icon)
 {
-       charpackage;
-       charextension;
+       char *package;
+       char *extension;
 
        retv_if(!icon, NULL);
 
        package = strdup(icon);
        retv_if(!package, NULL);
        extension = rindex(package, '.');
-       if (extension) {
+       if (extension)
                *extension = '\0';
-       } else {
+       else
                _E("cannot extract from icon [%s] to package.", icon);
-       }
 
        return package;
 }
 
-
 static char*
-_get_icon_with_path(char* icon)
+_get_icon_with_path(char* icon, uid_t uid)
 {
        retv_if(!icon, NULL);
 
@@ -239,23 +245,23 @@ _get_icon_with_path(char* icon)
                char* theme = NULL;
                char* icon_with_path = NULL;
                int len;
+               const char *app_path = NULL;
 
                package = _get_package_from_icon(icon);
                retv_if(!package, NULL);
 
-               theme = vconf_get_str("db/setting/theme");
-               if (!theme) {
-                       theme = strdup("default");
-                       if(!theme) {
-                               free(package);
-                               return NULL;
-                       }
+               /* "db/setting/theme" is not exist */
+               theme = strdup("default");
+               if (theme == NULL) {
+                       _E("out of memory");
+                       free(package);
+                       return NULL;
                }
 
                len = (0x01 << 7) + strlen(icon) + strlen(package) + strlen(theme);
                icon_with_path = malloc(len);
-               if(icon_with_path == NULL) {
-                       _E("(icon_with_path == NULL) return\n");
+               if (icon_with_path == NULL) {
+                       _E("icon_with_path == NULL\n");
                        free(package);
                        free(theme);
                        return NULL;
@@ -263,36 +269,21 @@ _get_icon_with_path(char* icon)
 
                memset(icon_with_path, 0, len);
 
-               sqlite3_snprintf( len, icon_with_path,"/opt/share/icons/%q/small/%q", theme, icon);
-               do {
-                       if (access(icon_with_path, R_OK) == 0) break;
-                       sqlite3_snprintf( len, icon_with_path,"/usr/share/icons/%q/small/%q", theme, icon);
-                       if (access(icon_with_path, R_OK) == 0) break;
-                       _D("cannot find icon %s", icon_with_path);
-                       sqlite3_snprintf( len, icon_with_path, "/opt/share/icons/default/small/%q", icon);
-                       if (access(icon_with_path, R_OK) == 0) break;
-                       sqlite3_snprintf( len, icon_with_path, "/usr/share/icons/default/small/%q", icon);
-                       if (access(icon_with_path, R_OK) == 0) break;
-
-                       #if 1 /* this will be remove when finish the work for moving icon path */
-                       _E("icon file must be moved to %s", icon_with_path);
-                       sqlite3_snprintf( len, icon_with_path,  "/opt/apps/%q/res/icons/%q/small/%q", package, theme, icon);
-                       if (access(icon_with_path, R_OK) == 0) break;
-                       sqlite3_snprintf( len, icon_with_path, "/usr/apps/%q/res/icons/%q/small/%q", package, theme, icon);
-                       if (access(icon_with_path, R_OK) == 0) break;
-                       _D("cannot find icon %s", icon_with_path);
-                       sqlite3_snprintf( len, icon_with_path, "/opt/apps/%q/res/icons/default/small/%q", package, icon);
-                       if (access(icon_with_path, R_OK) == 0) break;
-                       sqlite3_snprintf( len, icon_with_path, "/usr/apps/%q/res/icons/default/small/%q", package, icon);
-                       if (access(icon_with_path, R_OK) == 0) break;
-                       #endif
-               } while (0);
-
+               if (uid != GLOBAL_USER)
+                       sqlite3_snprintf(len, icon_with_path, "%s%q", ail_get_icon_path(uid), icon);
+               else
+                       sqlite3_snprintf(len, icon_with_path, "%s/%q/small/%q", ail_get_icon_path(GLOBAL_USER), theme, icon);
+
+               if (access(icon_with_path, F_OK)) {
+                       app_path = tzplatform_getenv(TZ_SYS_RW_APP);
+                       if (app_path)
+                               sqlite3_snprintf(len, icon_with_path, "%s/%q/res/icons/%q/small/%q", app_path, package, theme, icon);
+                       if (access(icon_with_path, F_OK))
+                               _E("Cannot find icon path");
+               }
                free(theme);
                free(package);
-
-               _D("Icon path : %s ---> %s", icon, icon_with_path);
-
+               _D("Icon path : %s", icon_with_path);
                return icon_with_path;
        } else {
                char* confirmed_icon = NULL;
@@ -303,24 +294,21 @@ _get_icon_with_path(char* icon)
        }
 }
 
-
-static ail_error_e _read_icon(void *data, char *tag, char *value)
+static ail_error_e _read_icon(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
        retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
        retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
 
-       info->icon = _get_icon_with_path(value);
+       info->icon = _get_icon_with_path(value, uid);
 
-       retv_if (!info->icon, AIL_ERROR_OUT_OF_MEMORY);
+       retv_if(!info->icon, AIL_ERROR_OUT_OF_MEMORY);
 
        return AIL_ERROR_OK;
 }
 
-
-
-static ail_error_e _read_categories(void *data, char *tag, char *value)
+static ail_error_e _read_categories(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
@@ -328,14 +316,12 @@ static ail_error_e _read_categories(void *data, char *tag, char *value)
        retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
 
        SAFE_FREE_AND_STRDUP(value, info->categories);
-       retv_if (!info->categories, AIL_ERROR_OUT_OF_MEMORY);
+       retv_if(!info->categories, AIL_ERROR_OUT_OF_MEMORY);
 
        return AIL_ERROR_OK;
 }
 
-
-
-static ail_error_e _read_version(void *data, char *tag, char *value)
+static ail_error_e _read_version(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
@@ -343,14 +329,12 @@ static ail_error_e _read_version(void *data, char *tag, char *value)
        retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
 
        SAFE_FREE_AND_STRDUP(value, info->version);
-       retv_if (!info->version, AIL_ERROR_OUT_OF_MEMORY);
+       retv_if(!info->version, AIL_ERROR_OUT_OF_MEMORY);
 
        return AIL_ERROR_OK;
 }
 
-
-
-static ail_error_e _read_mimetype(void *data, char *tag, char *value)
+static ail_error_e _read_mimetype(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
        int size, total_len = 0;
@@ -365,7 +349,7 @@ static ail_error_e _read_mimetype(void *data, char *tag, char *value)
 
        size = getpagesize();
        mimes_changed = calloc(1, size);
-       if(mimes_changed == NULL) {
+       if (mimes_changed == NULL) {
                _E("(mimes_changed == NULL) return\n");
                free(mimes_origin);
                return AIL_ERROR_OUT_OF_MEMORY;
@@ -388,7 +372,7 @@ static ail_error_e _read_mimetype(void *data, char *tag, char *value)
                        char *tmp;
                        size *= 2;
                        tmp = realloc(mimes_changed, size);
-                       if(!tmp) {
+                       if (!tmp) {
                                free(mimes_changed);
                                return AIL_ERROR_OUT_OF_MEMORY;
                        }
@@ -399,9 +383,8 @@ static ail_error_e _read_mimetype(void *data, char *tag, char *value)
                total_len += token_len;
 
                token_unalias = strtok_r(NULL, ";", &save_ptr);
-               if (token_unalias) {
+               if (token_unalias)
                        strncat(mimes_changed, ";", size-strlen(mimes_changed)-1);
-               }
        }
 
        SAFE_FREE(info->mimetype);
@@ -410,9 +393,7 @@ static ail_error_e _read_mimetype(void *data, char *tag, char *value)
        return AIL_ERROR_OK;
 }
 
-
-
-static ail_error_e _read_nodisplay(void *data, char *tag, char *value)
+static ail_error_e _read_nodisplay(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s* info = data;
 
@@ -426,7 +407,7 @@ static ail_error_e _read_nodisplay(void *data, char *tag, char *value)
 
 
 
-static ail_error_e _read_x_slp_service(void *data, char *tag, char *value)
+static ail_error_e _read_x_slp_service(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
@@ -441,7 +422,7 @@ static ail_error_e _read_x_slp_service(void *data, char *tag, char *value)
 
 
 
-static ail_error_e _read_x_slp_packagetype(void *data, char *tag, char *value)
+static ail_error_e _read_x_slp_packagetype(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
@@ -456,7 +437,7 @@ static ail_error_e _read_x_slp_packagetype(void *data, char *tag, char *value)
 
 
 
-static ail_error_e _read_x_slp_packagecategories(void *data, char *tag, char *value)
+static ail_error_e _read_x_slp_packagecategories(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
@@ -471,7 +452,7 @@ static ail_error_e _read_x_slp_packagecategories(void *data, char *tag, char *va
 
 
 
-static ail_error_e _read_x_slp_packageid(void *data, char *tag, char *value)
+static ail_error_e _read_x_slp_packageid(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
@@ -484,9 +465,33 @@ static ail_error_e _read_x_slp_packageid(void *data, char *tag, char *value)
        return AIL_ERROR_OK;
 }
 
+static ail_error_e _read_x_slp_submodemainid(void *data, char *tag, char *value, uid_t uid)
+{
+       desktop_info_s *info = data;
+
+       retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
+       retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
+
+       SAFE_FREE_AND_STRDUP(value, info->x_slp_submodemainid);
+       retv_if(!info->x_slp_submodemainid, AIL_ERROR_OUT_OF_MEMORY);
+
+       return AIL_ERROR_OK;
+}
+
+static ail_error_e _read_x_slp_installedstorage(void *data, char *tag, char *value, uid_t uid)
+{
+       desktop_info_s *info = data;
+
+       retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
+       retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
+
+       SAFE_FREE_AND_STRDUP(value, info->x_slp_installedstorage);
+       retv_if(!info->x_slp_installedstorage, AIL_ERROR_OUT_OF_MEMORY);
 
+       return AIL_ERROR_OK;
+}
 
-static ail_error_e _read_x_slp_uri(void *data, char *tag, char *value)
+static ail_error_e _read_x_slp_uri(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
@@ -501,7 +506,7 @@ static ail_error_e _read_x_slp_uri(void *data, char *tag, char *value)
 
 
 
-static ail_error_e _read_x_slp_svc(void *data, char *tag, char *value)
+static ail_error_e _read_x_slp_svc(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
@@ -516,7 +521,7 @@ static ail_error_e _read_x_slp_svc(void *data, char *tag, char *value)
 
 
 
-static ail_error_e _read_x_slp_taskmanage(void *data, char *tag, char *value)
+static ail_error_e _read_x_slp_taskmanage(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
@@ -530,7 +535,7 @@ static ail_error_e _read_x_slp_taskmanage(void *data, char *tag, char *value)
 
 
 
-static ail_error_e _read_x_slp_multiple(void *data, char *tag, char *value)
+static ail_error_e _read_x_slp_multiple(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
@@ -544,7 +549,7 @@ static ail_error_e _read_x_slp_multiple(void *data, char *tag, char *value)
 
 
 
-static ail_error_e _read_x_slp_removable(void *data, char *tag, char *value)
+static ail_error_e _read_x_slp_removable(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
@@ -557,7 +562,19 @@ static ail_error_e _read_x_slp_removable(void *data, char *tag, char *value)
 }
 
 
-static ail_error_e _read_x_slp_appid(void *data, char *tag, char *value)
+static ail_error_e _read_x_slp_submode(void *data, char *tag, char *value, uid_t uid)
+{
+       desktop_info_s *info = data;
+
+       retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
+       retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
+
+       info->x_slp_submode = !strcasecmp(value, "true");
+
+       return AIL_ERROR_OK;
+}
+
+static ail_error_e _read_x_slp_appid(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
@@ -571,7 +588,7 @@ static ail_error_e _read_x_slp_appid(void *data, char *tag, char *value)
 }
 
 
-static ail_error_e _read_x_slp_pkgid(void *data, char *tag, char *value)
+static ail_error_e _read_x_slp_pkgid(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
@@ -585,7 +602,7 @@ static ail_error_e _read_x_slp_pkgid(void *data, char *tag, char *value)
 }
 
 
-static ail_error_e _read_x_slp_domain(void *data, char *tag, char *value)
+static ail_error_e _read_x_slp_domain(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
@@ -599,7 +616,7 @@ static ail_error_e _read_x_slp_domain(void *data, char *tag, char *value)
 }
 
 
-static ail_error_e _read_x_slp_enabled(void *data, char *tag, char *value)
+static ail_error_e _read_x_slp_enabled(void *data, char *tag, char *value, uid_t uid)
 {
        desktop_info_s *info = data;
 
@@ -658,6 +675,14 @@ static struct entry_parser entry_parsers[] = {
                .value_cb = _read_x_slp_packageid,
        },
        {
+               .field = "x-tizen-submodemainid",
+               .value_cb = _read_x_slp_submodemainid,
+       },
+       {
+               .field = "x-tizen-installedstorage",
+               .value_cb = _read_x_slp_installedstorage,
+       },
+       {
                .field = "x-tizen-uri",
                .value_cb = _read_x_slp_uri,
        },
@@ -678,6 +703,10 @@ static struct entry_parser entry_parsers[] = {
                .value_cb = _read_x_slp_enabled,
        },
        {
+               .field = "x-tizen-submode",
+               .value_cb = _read_x_slp_submode,
+       },
+       {
                .field = "x-tizen-multiple",
                .value_cb = _read_x_slp_multiple,
        },
@@ -707,49 +736,136 @@ static struct entry_parser entry_parsers[] = {
        },
 };
 
+char *_pkgname_to_desktop(const char *package, uid_t uid)
+{
+       char *desktop;
+       char *desktop_path;
+       int size;
 
+       retv_if(!package, NULL);
 
-/* Utility functions */
-static int _count_all(void)
-{
-       ail_error_e ret;
-       int count;
+       desktop_path = ail_get_desktop_path(uid);
+       if (desktop_path == NULL) {
+               _E("Failed to get desktop path");
+               return NULL;
+       }
 
-       ret = ail_filter_count_appinfo(NULL, &count);
-       if(ret != AIL_ERROR_OK) {
-               _E("cannot count appinfo");
-               count = -1;
+       size = strlen(desktop_path) + strlen(package) + 10;
+       desktop = malloc(size);
+       if (desktop == NULL) {
+               _E("out of memory");
+               free(desktop_path);
+               return NULL;
        }
 
-       retv_if(ret != AIL_ERROR_OK, -1);
+       snprintf(desktop, size, "%s/%s.desktop", desktop_path, package);
+       _D("uid: %d / desktop: [%s]\n",  uid, desktop);
 
-       return count;
+       free(desktop_path);
+
+       return desktop;
 }
 
+static inline int _bind_local_info(desktop_info_s* info, sqlite3_stmt * stmt)
+{
+       unsigned long i = 0;
+       struct name_item *item;
+       GSList* localname;
+
+       retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
+       retv_if(!info->localname, AIL_ERROR_INVALID_PARAMETER);
+       retv_if(!stmt, AIL_ERROR_INVALID_PARAMETER);
+
+       localname = info->localname;
+       while (localname) {
+               item = (struct name_item *)     localname->data;
+               if (item && item->locale && item->name) {
+                       /* Bind values for a triplet : package, locale, name */
+                       retv_if(db_bind_text(stmt, i+1, info->package) != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
+                       retv_if(db_bind_text(stmt, i+2, item->locale) != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
+                       retv_if(db_bind_text(stmt, i+3, item->name) != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
+                       i += 3;
+               }
+               localname = g_slist_next(localname);
+       }
 
+       return AIL_ERROR_OK;
+}
 
-char *_pkgname_to_desktop(const char *package)
+static inline int _len_local_info(desktop_info_s* info)
 {
-       char *desktop;
-       int size;
+       int len = 0;
+       struct name_item *item;
+       GSList* localname;
+       retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
+       if (info->localname) {
+               localname = info->localname;
+               while (localname) {
+                       item = (struct name_item *)     localname->data;
+                       if (item && item->locale && item->name)
+                               len++;
+                       localname = g_slist_next(localname);
+               }
+       }
+       return len;
+}
 
-       retv_if(!package, NULL);
+static inline int _insert_local_info(desktop_info_s* info, uid_t uid)
+{
+       int len_query = SQL_INSERT_LOCALNAME_STR_LEN;
+       int nb_locale_args;
+       char *query;
+       int ret = AIL_ERROR_OK;
+       sqlite3_stmt *stmt = NULL;
+       int i = 0;
 
-       size = strlen(OPT_DESKTOP_DIRECTORY) + strlen(package) + 10;
-       desktop = malloc(size);
-       retv_if(!desktop, NULL);
+       retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
+       retv_if(!info->localname, AIL_ERROR_INVALID_PARAMETER);
 
-       snprintf(desktop, size, OPT_DESKTOP_DIRECTORY"/%s.desktop", package);
+       nb_locale_args = _len_local_info(info);
+       retv_if(!nb_locale_args, AIL_ERROR_INVALID_PARAMETER);
 
-       if (access(desktop, R_OK) == 0)
-               return desktop;
+       len_query += SQL_LOCALNAME_TRIPLET_STR_LEN*nb_locale_args + 1;
 
-       snprintf(desktop, size, USR_DESKTOP_DIRECTORY"/%s.desktop", package);
+       query = (char *)malloc(len_query);
+       retv_if(!query, AIL_ERROR_OUT_OF_MEMORY);
 
-       return desktop;
-}
+       stpncpy(query, SQL_INSERT_LOCALNAME_INIT_STR, len_query);
+       for (i = 0; i < nb_locale_args - 1; i++)
+               strncat(query, SQL_LOCALNAME_TRIPLET_STR, len_query - strlen(query) - 1);
 
+       do {
+               if (uid != GLOBAL_USER)
+                       ret = db_prepare_rw(query, &stmt);
+               else
+                       ret = db_prepare_globalrw(query, &stmt);
+
+               if (ret < 0)
+                       break;
 
+               ret = _bind_local_info(info, stmt);
+               if (ret < 0) {
+                       _E("Can't bind locale information to this query - %s. ", query);
+                       db_finalize(stmt);
+                       break;
+               }
+
+               ret = db_step(stmt);
+               if (ret != AIL_ERROR_NO_DATA) {
+                       /* Insert Request doesn't return any data.
+                        * db_step should returns AIL_ERROR_NO_DATA in this case. */
+                       _E("Can't execute this query - %s. ", query);
+                       db_finalize(stmt);
+                       break;
+               }
+
+               ret = db_finalize(stmt);
+       } while (0);
+
+       free(query);
+
+       return ret;
+}
 
 static inline int _strlen_desktop_info(desktop_info_s* info)
 {
@@ -774,27 +890,28 @@ static inline int _strlen_desktop_info(desktop_info_s* info)
        if (info->x_slp_exe_path) len += strlen(info->x_slp_exe_path);
        if (info->x_slp_appid) len += strlen(info->x_slp_appid);
        if (info->desktop) len += strlen(info->desktop);
+       if (info->x_slp_submodemainid) len += strlen(info->x_slp_submodemainid);
+       if (info->x_slp_installedstorage) len += strlen(info->x_slp_installedstorage);
 
        return len;
 }
 
-
 int __is_ail_initdb(void)
 {
-       if( getenv("AIL_INITDB") || getenv("INITDB") )
+       if (getenv("AIL_INITDB") || getenv("INITDB"))
                return 1;
        else
                return 0;
 }
 
-
-
 /* Manipulating desktop_info functions */
-static ail_error_e _init_desktop_info(desktop_info_s *info, const char *package)
+static ail_error_e _init_desktop_info(desktop_info_s *info, const char *package, uid_t uid)
 {
        static int is_initdb = -1;
 
-       if(is_initdb == -1)
+       _D("package - [%s].", package);
+
+       if (is_initdb == -1)
                is_initdb = __is_ail_initdb();
 
        retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
@@ -805,8 +922,9 @@ static ail_error_e _init_desktop_info(desktop_info_s *info, const char *package)
 
        info->x_slp_taskmanage = 1;
        info->x_slp_removable = 1;
+       info->x_slp_submode = 0;
 
-       if(is_initdb)
+       if (is_initdb)
                info->x_slp_installedtime = 0;
        else
                info->x_slp_installedtime = time(NULL);
@@ -820,20 +938,21 @@ static ail_error_e _init_desktop_info(desktop_info_s *info, const char *package)
 
        info->x_slp_packageid = strdup(package);
        retv_if(!info->x_slp_packageid, AIL_ERROR_OUT_OF_MEMORY);
+
        info->x_slp_appid = strdup(package);
        retv_if(!info->x_slp_appid, AIL_ERROR_OUT_OF_MEMORY);
 
        info->x_slp_enabled = 1;
 
-       info->desktop = _pkgname_to_desktop(package);
+       info->desktop = _pkgname_to_desktop(package, uid);
        retv_if(!info->desktop, AIL_ERROR_FAIL);
 
+       _D("desktop - [%s].", info->desktop);
+
        return AIL_ERROR_OK;
 }
 
-
-
-static ail_error_e _read_desktop_info(desktop_info_s* info)
+static ail_error_e _read_desktop_info(desktop_info_s *info, uid_t uid)
 {
        char *line = NULL;
        FILE *fp;
@@ -850,9 +969,12 @@ static ail_error_e _read_desktop_info(desktop_info_s* info)
                char *tmp, *field, *field_name, *tag, *value;
 
                tmp = _ltrim(line);
-               if(tmp == NULL) continue;
-               if (*tmp == '#') continue;
-               if (_rtrim(tmp) <= 0) continue;
+               if (tmp == NULL)
+                       continue;
+               if (*tmp == '#')
+                       continue;
+               if (_rtrim(tmp) <= 0)
+                       continue;
 
                len = strlen(line) + 1;
                field = calloc(1, len);
@@ -860,9 +982,8 @@ static ail_error_e _read_desktop_info(desktop_info_s* info)
                tag = calloc(1, len);
                value = calloc(1, len);
 
-               if (!field || !field_name || !tag || !value) {
+               if (!field || !field_name || !tag || !value)
                        goto NEXT;
-               }
 
                sscanf(tmp, "%[^=]=%[^\n]", field, value);
                _rtrim(field);
@@ -870,15 +991,13 @@ static ail_error_e _read_desktop_info(desktop_info_s* info)
 
                sscanf(field, "%[^[][%[^]]]", field_name, tag);
 
-               if (!field_name || !strlen(field_name)){
+               if (!field_name || !strlen(field_name))
                        goto NEXT;
-               }
 
-               for (idx = 0; entry_parsers[idx].field; idx ++) {
+               for (idx = 0; entry_parsers[idx].field; idx++) {
                        if (!g_ascii_strcasecmp(entry_parsers[idx].field, field_name) && entry_parsers[idx].value_cb) {
-                               if (entry_parsers[idx].value_cb(info, tag, tmp) != AIL_ERROR_OK) {
+                               if (entry_parsers[idx].value_cb(info, tag, tmp, uid) != AIL_ERROR_OK)
                                        _E("field - [%s] is wrong.", field_name);
-                               }
                                break;
                        }
                }
@@ -941,6 +1060,8 @@ static ail_error_e _retrieve_all_column_to_desktop_info(desktop_info_s* info, sq
        SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_APPID_STR], info->x_slp_appid);
        SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_PKGID_STR], info->x_slp_pkgid);
        SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_DOMAIN_STR], info->x_slp_domain);
+       SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_SUBMODEMAINID_STR], info->x_slp_submodemainid);
+       SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR], info->x_slp_installedstorage);
 
        info->x_slp_installedtime = atoi(values[E_AIL_PROP_X_SLP_INSTALLEDTIME_INT]);
 
@@ -950,6 +1071,7 @@ static ail_error_e _retrieve_all_column_to_desktop_info(desktop_info_s* info, sq
        info->x_slp_removable = atoi(values[E_AIL_PROP_X_SLP_REMOVABLE_BOOL]);
        info->x_slp_ishorizontalscale = atoi(values[E_AIL_PROP_X_SLP_ISHORIZONTALSCALE_BOOL]);
        info->x_slp_enabled = atoi(values[E_AIL_PROP_X_SLP_ENABLED_BOOL]);
+       info->x_slp_submode = atoi(values[E_AIL_PROP_X_SLP_SUBMODE_BOOL]);
 
        err = AIL_ERROR_OK;
 
@@ -964,25 +1086,35 @@ NEXT:
 }
 
 
-static ail_error_e _load_desktop_info(desktop_info_s* info)
+static ail_error_e _load_desktop_info(desktop_info_s* info, uid_t uid)
 {
        ail_error_e ret;
        char query[AIL_SQL_QUERY_MAX_LEN];
        sqlite3_stmt *stmt = NULL;
        char w[AIL_SQL_QUERY_MAX_LEN];
+       const char *filter;
 
        retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
 
-       snprintf(w, sizeof(w), sql_get_filter(E_AIL_PROP_X_SLP_APPID_STR), info->package);
+       filter = sql_get_filter(E_AIL_PROP_X_SLP_APPID_STR);
+       if (filter == NULL)
+               return AIL_ERROR_FAIL;
 
-       snprintf(query, sizeof(query), "SELECT %s FROM %s WHERE %s",SQL_FLD_APP_INFO, SQL_TBL_APP_INFO, w);
+       snprintf(w, sizeof(w), filter, info->package);
+       snprintf(query, sizeof(query), "SELECT %s FROM %s WHERE %s", SQL_FLD_APP_INFO, SQL_TBL_APP_INFO, w);
 
        do {
-               ret = db_open(DB_OPEN_RO);
-               if (ret < 0) break;
+               ret = db_open(DB_OPEN_RO, uid);
+               if (ret < 0)
+                       break;
+
+               if (uid != GLOBAL_USER)
+                       ret = db_prepare(query, &stmt);
+               else
+                       ret = db_prepare_globalro(query, &stmt);
 
-               ret = db_prepare(query, &stmt);
-               if (ret < 0) break;
+               if (ret < 0)
+                       break;
 
                ret = db_step(stmt);
                if (ret < 0) {
@@ -997,10 +1129,11 @@ static ail_error_e _load_desktop_info(desktop_info_s* info)
                }
 
                ret = db_finalize(stmt);
-               if (ret < 0) break;
+               if (ret < 0)
+                       break;
 
                return AIL_ERROR_OK;
-       } while(0);
+       } while (0);
 
        return ret;
 }
@@ -1010,7 +1143,6 @@ static ail_error_e _modify_desktop_info_bool(desktop_info_s* info,
                                                  bool value)
 {
        ail_prop_bool_e prop;
-       int val;
 
        retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
        retv_if(!property, AIL_ERROR_INVALID_PARAMETER);
@@ -1021,11 +1153,11 @@ static ail_error_e _modify_desktop_info_bool(desktop_info_s* info,
                return AIL_ERROR_INVALID_PARAMETER;
 
        switch (prop) {
-               case E_AIL_PROP_X_SLP_ENABLED_BOOL:
-                       info->x_slp_enabled = (int)value;
-                       break;
-               default:
-                       return AIL_ERROR_FAIL;
+       case E_AIL_PROP_X_SLP_ENABLED_BOOL:
+               info->x_slp_enabled = (int)value;
+               break;
+       default:
+               return AIL_ERROR_FAIL;
        }
 
        return AIL_ERROR_OK;
@@ -1036,8 +1168,7 @@ static ail_error_e _modify_desktop_info_str(desktop_info_s* info,
                                                  const char *property,
                                                  const char *value)
 {
-       ail_prop_bool_e prop;
-       int val;
+       int prop;
 
        retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
        retv_if(!property, AIL_ERROR_INVALID_PARAMETER);
@@ -1048,86 +1179,47 @@ static ail_error_e _modify_desktop_info_str(desktop_info_s* info,
                return AIL_ERROR_INVALID_PARAMETER;
 
        switch (prop) {
-               case E_AIL_PROP_NAME_STR:
-                       SAFE_FREE_AND_STRDUP(value, info->name);
-                       retv_if (!info->name, AIL_ERROR_OUT_OF_MEMORY);
-                       break;
-               default:
-                       return AIL_ERROR_FAIL;
-       }
-
-       return AIL_ERROR_OK;
-}
-
-
-
-
-static ail_error_e _create_table(void)
-{
-       int i;
-       ail_error_e ret;
-       const char *tbls[3] = {
-               "CREATE TABLE app_info "
-               "(package TEXT PRIMARY KEY, "
-               "exec TEXT DEFAULT 'No Exec', "
-               "name TEXT DEFAULT 'No Name', "
-               "type TEXT DEFAULT 'Application', "
-               "icon TEXT DEFAULT 'No Icon', "
-               "categories TEXT, "
-               "version TEXT, "
-               "mimetype TEXT, "
-               "x_slp_service TEXT, "
-               "x_slp_packagetype TEXT, "
-               "x_slp_packagecategories TEXT, "
-               "x_slp_packageid TEXT, "
-               "x_slp_uri TEXT, "
-               "x_slp_svc TEXT, "
-               "x_slp_exe_path TEXT, "
-               "x_slp_appid TEXT, "
-               "x_slp_pkgid TEXT, "
-               "x_slp_domain TEXT, "
-               "x_slp_baselayoutwidth INTEGER DEFAULT 0, "
-               "x_slp_installedtime INTEGER DEFAULT 0, "
-               "nodisplay INTEGER DEFAULT 0, "
-               "x_slp_taskmanage INTEGER DEFAULT 1, "
-               "x_slp_multiple INTEGER DEFAULT 0, "
-               "x_slp_removable INTEGER DEFAULT 1, "
-               "x_slp_ishorizontalscale INTEGER DEFAULT 0, "
-               "x_slp_enabled INTEGER DEFAULT 1, "
-               "desktop TEXT UNIQUE NOT NULL);",
-               "CREATE TABLE localname (package TEXT NOT NULL, "
-               "locale TEXT NOT NULL, "
-               "name TEXT NOT NULL, PRIMARY KEY (package, locale));",
-               NULL
-       };
-
-       ret = db_open(DB_OPEN_RW);
-       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
-
-       for (i = 0; tbls[i] != NULL; i++) {
-               ret = db_exec(tbls[i]);
-               retv_if(ret != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
+       case E_AIL_PROP_NAME_STR:
+               SAFE_FREE_AND_STRDUP(value, info->name);
+               retv_if(!info->name, AIL_ERROR_OUT_OF_MEMORY);
+               break;
+       case E_AIL_PROP_X_SLP_SVC_STR:
+               SAFE_FREE_AND_STRDUP(value, info->x_slp_svc);
+               retv_if(!info->x_slp_svc, AIL_ERROR_OUT_OF_MEMORY);
+               break;
+       case E_AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR:
+               SAFE_FREE_AND_STRDUP(value, info->x_slp_installedstorage);
+               retv_if(!info->x_slp_installedstorage, AIL_ERROR_OUT_OF_MEMORY);
+               break;
+       default:
+               _E("prop[%d] is not defined\n", prop);
+               return AIL_ERROR_FAIL;
        }
 
        return AIL_ERROR_OK;
 }
 
 
-static inline void _insert_localname(gpointer data, gpointer user_data)
+static inline void _insert_localname(gpointer data, gpointer user_data, uid_t uid)
 {
        char query[512];
 
        struct name_item *item = (struct name_item *)data;
        desktop_info_s *info = (desktop_info_s *)user_data;
 
-       snprintf(query, sizeof(query), "insert into localname (package, locale, name) "
-                       "values ('%s', '%s', '%s');", 
-                       info->package, item->locale, item->name);
-       if (db_exec(query) < 0)
-               _E("Failed to insert local name of package[%s]",info->package);
+       sqlite3_snprintf(sizeof(query), query, "insert into localname (package, locale, name, x_slp_pkgid) "
+                       "values ('%q', '%q', '%q', '%q');",
+                       info->package, item->locale, item->name, info->x_slp_pkgid);
+       if (uid != GLOBAL_USER) {
+               if (db_exec_usr_rw(query) < 0)
+                       _E("Failed to insert local name of package[%s]", info->package);
+       } else {
+               if (db_exec_glo_rw(query) < 0)
+                       _E("Failed to insert local name of package[%s]", info->package);
+       }
 }
 
-static ail_error_e _insert_desktop_info(desktop_info_s *info)
+static ail_error_e _insert_desktop_info(desktop_info_s *info, uid_t uid)
 {
        char *query;
        int len;
@@ -1155,6 +1247,8 @@ static ail_error_e _insert_desktop_info(desktop_info_s *info)
                "x_slp_appid, "
                "x_slp_pkgid, "
                "x_slp_domain, "
+               "x_slp_submodemainid, "
+               "x_slp_installedstorage, "
                "x_slp_baselayoutwidth, "
                "x_slp_installedtime, "
                "nodisplay, "
@@ -1163,13 +1257,14 @@ static ail_error_e _insert_desktop_info(desktop_info_s *info)
                "x_slp_removable, "
                "x_slp_ishorizontalscale, "
                "x_slp_enabled, "
+               "x_slp_submode, "
                "desktop) "
                "values "
                "('%q', '%q', '%q', '%q', '%q', "
                "'%q', '%q', '%q', '%q', '%q', "
                "'%q', '%q', '%q', '%q', '%q', "
-               "'%q', '%q', '%q', "
-               "%d, %d, %d, %d, %d, %d, "
+               "'%q', '%q', '%q', '%q', '%q', "
+               "%d, %d, %d, %d, %d, %d, %d,"
                "%d, %d, "
                "'%q');",
                info->package,
@@ -1190,6 +1285,8 @@ static ail_error_e _insert_desktop_info(desktop_info_s *info)
                info->x_slp_appid,
                info->x_slp_pkgid,
                info->x_slp_domain,
+               info->x_slp_submodemainid,
+               info->x_slp_installedstorage,
                info->x_slp_baselayoutwidth,
                info->x_slp_installedtime,
                info->nodisplay,
@@ -1198,45 +1295,47 @@ static ail_error_e _insert_desktop_info(desktop_info_s *info)
                info->x_slp_removable,
                info->x_slp_ishorizontalscale,
                info->x_slp_enabled,
+               info->x_slp_submode,
                info->desktop
                );
 
-       ret = db_open(DB_OPEN_RW);
-       if(ret != AIL_ERROR_OK) {
+       ret = db_open(DB_OPEN_RW, uid);
+       if (ret != AIL_ERROR_OK) {
                _E("(tmp == NULL) return\n");
                free(query);
                return AIL_ERROR_DB_FAILED;
        }
+       if (uid != GLOBAL_USER)
+               ret = db_exec_usr_rw(query);
+       else
+               ret = db_exec_glo_rw(query);
+
+       _D("Add (%s).", query);
+       free(query);
 
-       ret = db_exec(query);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
 
        if (info->localname)
-               g_slist_foreach(info->localname, _insert_localname, info);
-
-       _D("Add (%s).", info->package);
+               _insert_local_info(info, uid);
 
        return AIL_ERROR_OK;
 }
 
-
-
-static ail_error_e _update_desktop_info(desktop_info_s *info)
+static ail_error_e _update_desktop_info(desktop_info_s *info, uid_t uid)
 {
        char *query;
        int len;
 
-       retv_if (NULL == info, AIL_ERROR_INVALID_PARAMETER);
+       retv_if(NULL == info, AIL_ERROR_INVALID_PARAMETER);
 
-       if (db_open(DB_OPEN_RW) < 0) {
+       if (db_open(DB_OPEN_RW, uid) < 0)
                return AIL_ERROR_DB_FAILED;
-       }
 
        len = _strlen_desktop_info(info) + (0x01 << 10);
        query = calloc(1, len);
        retv_if(!query, AIL_ERROR_OUT_OF_MEMORY);
 
-       sqlite3_snprintf ( len, query, "update app_info set "
+       sqlite3_snprintf(len, query, "update app_info set "
                "exec='%q', "
                "name='%q', "
                "type='%q', "
@@ -1254,6 +1353,8 @@ static ail_error_e _update_desktop_info(desktop_info_s *info)
                "x_slp_appid='%q', "
                "x_slp_pkgid='%q', "
                "x_slp_domain='%q', "
+               "x_slp_submodemainid='%q', "
+               "x_slp_installedstorage='%q', "
                "x_slp_baselayoutwidth=%d, "
                "x_slp_installedtime=%d, "
                "nodisplay=%d, "
@@ -1262,6 +1363,7 @@ static ail_error_e _update_desktop_info(desktop_info_s *info)
                "x_slp_removable=%d, "
                "x_slp_ishorizontalscale=%d, "
                "x_slp_enabled=%d, "
+               "x_slp_submode=%d, "
                "desktop='%q'"
                "where package='%q'",
                info->exec,
@@ -1281,6 +1383,8 @@ static ail_error_e _update_desktop_info(desktop_info_s *info)
                info->x_slp_appid,
                info->x_slp_pkgid,
                info->x_slp_domain,
+               info->x_slp_submodemainid,
+               info->x_slp_installedstorage,
                info->x_slp_baselayoutwidth,
                info->x_slp_installedtime,
                info->nodisplay,
@@ -1289,23 +1393,35 @@ static ail_error_e _update_desktop_info(desktop_info_s *info)
                info->x_slp_removable,
                info->x_slp_ishorizontalscale,
                info->x_slp_enabled,
+               info->x_slp_submode,
                info->desktop,
                info->package);
 
-       if (db_exec(query) < 0) {
-               free (query);
-               return AIL_ERROR_DB_FAILED;
+       if (uid != GLOBAL_USER) {
+               if (db_exec_usr_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
+       } else {
+               if (db_exec_glo_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
        }
-
        snprintf(query, len, "delete from localname where package = '%s'", info->package);
-
-       if (db_exec(query) < 0) {
-               free (query);
-               return AIL_ERROR_DB_FAILED;
+       if (uid != GLOBAL_USER) {
+               if (db_exec_usr_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
+       } else {
+               if (db_exec_glo_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
        }
-
        if (info->localname)
-               g_slist_foreach(info->localname, _insert_localname, info);
+               _insert_local_info(info, uid);
 
        _D("Update (%s).", info->package);
 
@@ -1316,16 +1432,15 @@ static ail_error_e _update_desktop_info(desktop_info_s *info)
 
 
 
-static ail_error_e _remove_package(const char* package)
+static ail_error_e _remove_package(const char* package, uid_t uid)
 {
        char *query;
        int size;
 
        retv_if(!package, AIL_ERROR_INVALID_PARAMETER);
 
-       if (db_open(DB_OPEN_RW) < 0) {
+       if (db_open(DB_OPEN_RW, uid) < 0)
                return AIL_ERROR_DB_FAILED;
-       }
 
        size = strlen(package) + (0x01 << 10);
        query = calloc(1, size);
@@ -1333,26 +1448,83 @@ static ail_error_e _remove_package(const char* package)
 
        snprintf(query, size, "delete from app_info where package = '%s'", package);
 
-       if (db_exec(query) < 0) {
-               free(query);
-               return AIL_ERROR_DB_FAILED;
+       if (uid != GLOBAL_USER) {
+               if (db_exec_usr_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
+       } else {
+               if (db_exec_glo_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
        }
-
        snprintf(query, size, "delete from localname where package = '%s'", package);
-       _D("query=%s",query);
+       _D("query=%s", query);
 
-       if (db_exec(query) < 0) {
-               free(query);
-               return AIL_ERROR_DB_FAILED;
+       if (uid != GLOBAL_USER) {
+               if (db_exec_usr_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
+       } else {
+               if (db_exec_glo_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
        }
-
        _D("Remove (%s).", package);
        free(query);
 
        return AIL_ERROR_OK;
 }
 
+static ail_error_e _clean_pkgid_data(const char* pkgid, uid_t uid)
+{
+       char *query;
+       int size;
+
+       retv_if(!pkgid, AIL_ERROR_INVALID_PARAMETER);
 
+       if (db_open(DB_OPEN_RW, uid))
+               return AIL_ERROR_DB_FAILED;
+
+       size = strlen(pkgid) + (0x01 << 10);
+       query = calloc(1, size);
+       retv_if(!query, AIL_ERROR_OUT_OF_MEMORY);
+
+       snprintf(query, size, "delete from app_info where x_slp_pkgid = '%s'", pkgid);
+
+       if (uid != GLOBAL_USER) {
+               if (db_exec_usr_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
+       } else {
+               if (db_exec_glo_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
+       }
+       snprintf(query, size, "delete from localname where x_slp_pkgid = '%s'", pkgid);
+       _D("query=%s", query);
+
+       if (uid != GLOBAL_USER) {
+               if (db_exec_usr_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
+       } else {
+               if (db_exec_glo_rw(query) < 0) {
+                       free(query);
+                       return AIL_ERROR_DB_FAILED;
+               }
+       }
+       _D("Clean pkgid data (%s).", pkgid);
+       free(query);
+
+       return AIL_ERROR_OK;
+}
 
 static ail_error_e _send_db_done_noti(noti_type type, const char *package)
 {
@@ -1362,26 +1534,24 @@ static ail_error_e _send_db_done_noti(noti_type type, const char *package)
        retv_if(!package, AIL_ERROR_INVALID_PARAMETER);
 
        switch (type) {
-               case NOTI_ADD:
-                       type_string = "create";
-                       break;
-               case NOTI_UPDATE:
-                       type_string = "update";
-                       break;
-               case NOTI_REMOVE:
-                       type_string = "delete";
-                       break;
-               default:
-                       return AIL_ERROR_FAIL;
+       case NOTI_ADD:
+               type_string = "create";
+               break;
+       case NOTI_UPDATE:
+               type_string = "update";
+               break;
+       case NOTI_REMOVE:
+               type_string = "delete";
+               break;
+       default:
+               return AIL_ERROR_FAIL;
        }
 
-       size = strlen(package) + 8;
-       noti_string = calloc(1, size);
+       size = snprintf(NULL, 0, "%s:%s:%u", type_string, package, getuid());
+       noti_string = (char*) calloc(size + 1, sizeof(char));
        retv_if(!noti_string, AIL_ERROR_OUT_OF_MEMORY);
 
-       snprintf(noti_string, size, "%s:%s", type_string, package);
-       vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
-       vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
+       snprintf(noti_string, size + 1, "%s:%s:%u", type_string, package, getuid());
        _D("Noti : %s", noti_string);
 
        free(noti_string);
@@ -1389,11 +1559,10 @@ static ail_error_e _send_db_done_noti(noti_type type, const char *package)
        return AIL_ERROR_OK;
 }
 
-
-static void inline _name_item_free_func(gpointer data)
+static inline void _name_item_free_func(gpointer data)
 {
        struct name_item *item = (struct name_item *)data;
-       if (item){
+       if (item) {
                SAFE_FREE(item->locale);
                item->locale = NULL;
                SAFE_FREE(item->name);
@@ -1421,6 +1590,8 @@ static void _fini_desktop_info(desktop_info_s *info)
        SAFE_FREE(info->x_slp_appid);
        SAFE_FREE(info->x_slp_pkgid);
        SAFE_FREE(info->x_slp_domain);
+       SAFE_FREE(info->x_slp_submodemainid);
+       SAFE_FREE(info->x_slp_installedstorage);
        SAFE_FREE(info->desktop);
        if (info->localname) {
                g_slist_free_full(info->localname, _name_item_free_func);
@@ -1430,97 +1601,78 @@ static void _fini_desktop_info(desktop_info_s *info)
        return;
 }
 
-static int __is_authorized()
-{
-       uid_t uid = getuid();
-       if ((uid_t) 0 == uid )
-               return 1;
-       else
-               return 0;
-}
-
-
 /* Public functions */
-EXPORT_API ail_error_e ail_desktop_add(const char *appid)
+EXPORT_API ail_error_e ail_usr_desktop_add(const char *appid, uid_t uid)
 {
        desktop_info_s info = {0,};
        ail_error_e ret;
-       int count;
 
        retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
-       if (!__is_authorized()) {
-               _E("You are not an authorized user on adding!\n");
-               return -1;
-       }
 
-       count = _count_all();
-       if (count <= 0) {
-               ret = _create_table();
-               if (ret != AIL_ERROR_OK) {
-                       _D("Cannot create a table. Maybe there is already a table.");
-               }
-       }
+       ret = _init_desktop_info(&info, appid, uid);
+       if (ret != AIL_ERROR_OK)
+               goto end;
 
-       ret = _init_desktop_info(&info, appid);
-       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
+       ret = _read_desktop_info(&info, uid);
+       if (ret != AIL_ERROR_OK)
+               goto end;
 
-       ret = _read_desktop_info(&info);
-       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
-
-       ret = _insert_desktop_info(&info);
-       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
+       ret = _insert_desktop_info(&info, uid);
+       if (ret != AIL_ERROR_OK)
+               goto end;
 
        ret = _send_db_done_noti(NOTI_ADD, appid);
-       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
+end:
        _fini_desktop_info(&info);
 
-       return AIL_ERROR_OK;
+       return ret;
 }
 
+EXPORT_API ail_error_e ail_desktop_add(const char *appid)
+{
+       return ail_usr_desktop_add(appid, GLOBAL_USER);
+}
 
-
-EXPORT_API ail_error_e ail_desktop_update(const char *appid)
+EXPORT_API ail_error_e ail_usr_desktop_update(const char *appid, uid_t uid)
 {
        desktop_info_s info = {0,};
        ail_error_e ret;
 
        retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
-       if (!__is_authorized()) {
-               _E("You are not an authorized user on updating!\n");
-               return -1;
-       }
 
-       ret = _init_desktop_info(&info, appid);
-       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
+       ret = _init_desktop_info(&info, appid, uid);
+       if (ret != AIL_ERROR_OK)
+               goto end;
 
-       ret = _read_desktop_info(&info);
-       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
+       ret = _read_desktop_info(&info, uid);
+       if (ret != AIL_ERROR_OK)
+               goto end;
 
-       ret = _update_desktop_info(&info);
-       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
+       ret = _update_desktop_info(&info, uid);
+       if (ret != AIL_ERROR_OK)
+               goto end;
 
        ret = _send_db_done_noti(NOTI_UPDATE, appid);
-       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
+end:
        _fini_desktop_info(&info);
 
-       return AIL_ERROR_OK;
+       return ret;
 }
 
+EXPORT_API ail_error_e ail_desktop_update(const char *appid)
+{
+       return ail_usr_desktop_update(appid, GLOBAL_USER);
+}
 
-
-EXPORT_API ail_error_e ail_desktop_remove(const char *appid)
+EXPORT_API ail_error_e ail_usr_desktop_remove(const char *appid, uid_t uid)
 {
        ail_error_e ret;
 
        retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
-       if (!__is_authorized()) {
-               _E("You are not an authorized user on removing!\n");
-               return -1;
-       }
 
-       ret = _remove_package(appid);
+       ret = _remove_package(appid, uid);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
        ret = _send_db_done_noti(NOTI_REMOVE, appid);
@@ -1529,11 +1681,62 @@ EXPORT_API ail_error_e ail_desktop_remove(const char *appid)
        return AIL_ERROR_OK;
 }
 
+EXPORT_API ail_error_e ail_desktop_remove(const char *appid)
+{
+       return ail_usr_desktop_remove(appid, GLOBAL_USER);
+}
 
-EXPORT_API ail_error_e ail_desktop_appinfo_modify_bool(const char *appid,
-                                                            const char *property,
-                                                            bool value,
-                                                            bool broadcast)
+
+EXPORT_API ail_error_e ail_usr_desktop_clean(const char *pkgid, uid_t uid)
+{
+       ail_error_e ret;
+
+       retv_if(!pkgid, AIL_ERROR_INVALID_PARAMETER);
+
+       _D("ail_desktop_clean=%s", pkgid);
+
+       ret = _clean_pkgid_data(pkgid, uid);
+       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
+
+       return AIL_ERROR_OK;
+}
+
+EXPORT_API ail_error_e ail_desktop_clean(const char *pkgid)
+{
+       return ail_usr_desktop_clean(pkgid, GLOBAL_USER);
+}
+
+EXPORT_API ail_error_e ail_usr_desktop_fota(const char *appid, uid_t uid)
+{
+       desktop_info_s info = {0,};
+       ail_error_e ret;
+
+       retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
+
+       ret = _init_desktop_info(&info, appid, uid);
+       if (ret != AIL_ERROR_OK)
+               goto end;
+
+       ret = _read_desktop_info(&info, uid);
+       if (ret != AIL_ERROR_OK)
+               goto end;
+
+       ret = _insert_desktop_info(&info, uid);
+
+end:
+       _fini_desktop_info(&info);
+
+       return ret;
+}
+
+EXPORT_API ail_error_e ail_desktop_fota(const char *appid)
+{
+       return ail_usr_desktop_fota(appid, GLOBAL_USER);
+}
+
+
+EXPORT_API ail_error_e ail_desktop_appinfo_modify_usr_bool(const char *appid,
+               const char *property, bool value, bool broadcast, uid_t uid)
 {
        desktop_info_s info = {0,};
        ail_error_e ret;
@@ -1541,66 +1744,80 @@ EXPORT_API ail_error_e ail_desktop_appinfo_modify_bool(const char *appid,
        retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
 
        retv_if(strcmp(property, AIL_PROP_X_SLP_ENABLED_BOOL),
-               AIL_ERROR_INVALID_PARAMETER);
+                               AIL_ERROR_INVALID_PARAMETER);
 
-       ret = _init_desktop_info(&info, appid);
-       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
+       ret = _init_desktop_info(&info, appid, uid);
+       if (ret != AIL_ERROR_OK)
+               goto end;
 
-       ret = _load_desktop_info(&info);
-       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
+       ret = _load_desktop_info(&info, uid);
+       if (ret != AIL_ERROR_OK)
+               goto end;
 
        ret = _modify_desktop_info_bool(&info, property, value);
-       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
+       if (ret != AIL_ERROR_OK)
+               goto end;
 
-       ret = _update_desktop_info(&info);
-       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
+       ret = _update_desktop_info(&info, uid);
+       if (ret != AIL_ERROR_OK)
+               goto end;
 
-       if (broadcast) {
+       if (broadcast)
                ret = _send_db_done_noti(NOTI_UPDATE, appid);
-               retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
-       }
 
+end:
        _fini_desktop_info(&info);
 
-       return AIL_ERROR_OK;
+       return ret;
+}
+
+EXPORT_API ail_error_e ail_desktop_appinfo_modify_bool(const char *appid,
+                       const char *property, bool value, bool broadcast)
+{
+       return ail_desktop_appinfo_modify_usr_bool(appid, property, value,
+                                               broadcast, GLOBAL_USER);
 }
 
 
-EXPORT_API ail_error_e ail_desktop_appinfo_modify_str(const char *appid,
-                                                            const char *property,
-                                                            const char *value,
-                                                            bool broadcast)
+EXPORT_API ail_error_e ail_desktop_appinfo_modify_usr_str(const char *appid,
+       uid_t uid, const char *property, const char *value, bool broadcast)
 {
        desktop_info_s info = {0,};
        ail_error_e ret;
 
        retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
 
-       retv_if(strcmp(property, AIL_PROP_NAME_STR),
-               AIL_ERROR_INVALID_PARAMETER);
+       ret = _init_desktop_info(&info, appid, uid);
+       if (ret != AIL_ERROR_OK)
+               goto end;
 
-       ret = _init_desktop_info(&info, appid);
-       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
-
-       ret = _load_desktop_info(&info);
-       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
+       ret = _load_desktop_info(&info, uid);
+       if (ret != AIL_ERROR_OK)
+               goto end;
 
        _D("info.name [%s], value [%s]", info.name, value);
        ret = _modify_desktop_info_str(&info, property, value);
-       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
+       if (ret != AIL_ERROR_OK)
+               goto end;
+
        _D("info.name [%s], value [%s]", info.name, value);
 
-       ret = _update_desktop_info(&info);
-       retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
+       ret = _update_desktop_info(&info, uid);
+       if (ret != AIL_ERROR_OK)
+               goto end;
 
-       if (broadcast) {
+       if (broadcast)
                ret = _send_db_done_noti(NOTI_UPDATE, appid);
-               retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
-       }
 
+end:
        _fini_desktop_info(&info);
 
-       return AIL_ERROR_OK;
+       return ret;
 }
 
-// End of File
+EXPORT_API ail_error_e ail_desktop_appinfo_modify_str(const char *appid,
+                       const char *property, const char *value, bool broadcast)
+{
+       return ail_desktop_appinfo_modify_usr_str(appid, GLOBAL_USER, property,
+                                               value, broadcast);
+}