change functions for thread-safe
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_pkginfo.c
index 3a970e1..e49ee0d 100644 (file)
  * limitations under the License.
  *
  */
+
 #define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdbool.h>
 #include <unistd.h>
 #include <ctype.h>
 #include <sys/smack.h>
 #include "pkgmgr_parser_db.h"
 #include "pkgmgr_parser_internal.h"
 
-#define FILTER_QUERY_COUNT_PACKAGE     "select count(DISTINCT package_info.package) " \
-                               "from package_info LEFT OUTER JOIN package_localized_info " \
-                               "ON package_info.package=package_localized_info.package " \
-                               "and package_localized_info.package_locale='%s' where "
-
-
-static int _pkginfo_get_pkg(const char *pkgid, const char *locale,
+static int _pkginfo_get_pkginfo(const char *pkgid, uid_t uid,
                pkgmgr_pkginfo_x **pkginfo);
 static char *_get_filtered_query(const char *query_raw,
                pkgmgrinfo_filter_x *filter);
 
+static bool _get_bool_value(const char *str)
+{
+       if (str == NULL)
+               return false;
+       else if (!strcasecmp(str, "true"))
+               return true;
+       else
+               return false;
+}
+
 static gint __compare_func(gconstpointer data1, gconstpointer data2)
 {
        pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
@@ -68,14 +73,6 @@ static gint __compare_func(gconstpointer data1, gconstpointer data2)
                return -1;
 }
 
-static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
-{
-       int *p = (int*)data;
-       *p = atoi(coltxt[0]);
-       _LOGE("count value is %d\n", *p);
-       return 0;
-}
-
 static void __destroy_each_node(gpointer data, gpointer user_data)
 {
        ret_if(data == NULL);
@@ -144,129 +141,208 @@ long long _pkgmgr_calculate_dir_size(char *dirname)
        int q = 0; /*quotient*/
        int r = 0; /*remainder*/
        DIR *dp = NULL;
-       struct dirent *ep = NULL;
+       struct dirent ep, *result;
        struct stat fileinfo;
        char abs_filename[FILENAME_MAX] = { 0, };
        retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
 
        dp = opendir(dirname);
-       if (dp != NULL) {
-               while ((ep = readdir(dp)) != NULL) {
-                       if (!strcmp(ep->d_name, ".") ||
-                               !strcmp(ep->d_name, "..")) {
+       if (dp == NULL) {
+               _LOGE("Couldn't open the directory\n");
+               return -1;
+       }
+
+       for (ret = readdir_r(dp, &ep, &result);
+                       ret == 0 && result != NULL;
+                       ret = readdir_r(dp, &ep, &result)) {
+               if (!strcmp(ep.d_name, ".") ||
+                       !strcmp(ep.d_name, "..")) {
+                       continue;
+               }
+               snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
+                        ep.d_name);
+               if (lstat(abs_filename, &fileinfo) < 0)
+                       perror(abs_filename);
+               else {
+                       if (S_ISDIR(fileinfo.st_mode)) {
+                               total += fileinfo.st_size;
+                               if (strcmp(ep.d_name, ".")
+                                   && strcmp(ep.d_name, "..")) {
+                                       ret = _pkgmgr_calculate_dir_size
+                                           (abs_filename);
+                                       total = total + ret;
+                               }
+                       } else if (S_ISLNK(fileinfo.st_mode)) {
                                continue;
+                       } else {
+                               /*It is a file. Calculate the actual
+                               size occupied (in terms of 4096 blocks)*/
+                       q = (fileinfo.st_size / BLOCK_SIZE);
+                       r = (fileinfo.st_size % BLOCK_SIZE);
+                       if (r) {
+                               q = q + 1;
                        }
-                       snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
-                                ep->d_name);
-                       if (lstat(abs_filename, &fileinfo) < 0)
-                               perror(abs_filename);
-                       else {
-                               if (S_ISDIR(fileinfo.st_mode)) {
-                                       total += fileinfo.st_size;
-                                       if (strcmp(ep->d_name, ".")
-                                           && strcmp(ep->d_name, "..")) {
-                                               ret = _pkgmgr_calculate_dir_size
-                                                   (abs_filename);
-                                               total = total + ret;
-                                       }
-                               } else if (S_ISLNK(fileinfo.st_mode)) {
-                                       continue;
-                               } else {
-                                       /*It is a file. Calculate the actual
-                                       size occupied (in terms of 4096 blocks)*/
-                               q = (fileinfo.st_size / BLOCK_SIZE);
-                               r = (fileinfo.st_size % BLOCK_SIZE);
-                               if (r) {
-                                       q = q + 1;
-                               }
-                               total += q * BLOCK_SIZE;
-                               }
+                       total += q * BLOCK_SIZE;
                        }
                }
-               (void)closedir(dp);
-       } else {
-               _LOGE("Couldn't open the directory\n");
-               return -1;
        }
+       (void)closedir(dp);
        return total;
 
 }
 
-static GSList *_pkginfo_get_filtered_list(const char *locale,
-               pkgmgrinfo_filter_x *filter)
+static gint __list_strcmp(gconstpointer a, gconstpointer b)
+{
+       return strcmp((char *)a, (char *)b);
+}
+
+static int _pkginfo_get_list(sqlite3 *db, const char *locale,
+               pkgmgrinfo_filter_x *filter, GList **list)
 {
        static const char query_raw[] =
                "SELECT DISTINCT package_info.package FROM package_info"
                " LEFT OUTER JOIN package_localized_info"
                "  ON package_info.package=package_localized_info.package"
-               "  AND package_localized_info.package_locale=%Q ";
+               "  AND package_localized_info.package_locale=%Q "
+               " LEFT OUTER JOIN package_privilege_info"
+               "  ON package_info.package=package_privilege_info.package";
        int ret;
        char *query;
        char *query_localized;
        sqlite3_stmt *stmt;
-       GSList *list = NULL;
-       char *pkgid;
+       char *pkgid = NULL;
 
        query = _get_filtered_query(query_raw, filter);
        if (query == NULL)
-               return NULL;
+               return -1;
        query_localized = sqlite3_mprintf(query, locale);
        free(query);
        if (query_localized == NULL)
-               return NULL;
+               return -1;
 
-       ret = sqlite3_prepare_v2(GET_DB(manifest_db), query_localized,
+       ret = sqlite3_prepare_v2(db, query_localized,
                        strlen(query_localized), &stmt, NULL);
        sqlite3_free(query_localized);
        if (ret != SQLITE_OK) {
-               LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
-               return NULL;
+               LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               return -1;
        }
 
        while (sqlite3_step(stmt) == SQLITE_ROW) {
-               _save_column_str(stmt, 0, (const char **)&pkgid);
-               list = g_slist_append(list, pkgid);
+               _save_column_str(stmt, 0, &pkgid);
+               if (pkgid != NULL)
+                       *list = g_list_insert_sorted(*list, pkgid,
+                                       __list_strcmp);
        }
 
        sqlite3_finalize(stmt);
 
-       return list;
+       return 0;
 }
 
-static int _pkginfo_get_filtered_foreach_pkginfo(pkgmgrinfo_filter_x *filter,
-               pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
+static int _pkginfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid,
+               GList **list)
 {
-       pkgmgr_pkginfo_x *info;
-       GSList *list;
-       GSList *tmp;
-       char *pkgid;
+       int ret;
+       sqlite3 *db;
+       const char *dbpath;
        char *locale;
-       int stop = 0;
+       GList *tmp;
+       GList *tmp2;
 
-       if (__open_manifest_db(uid) < 0)
+       locale = _get_system_locale();
+       if (locale == NULL)
                return PMINFO_R_ERROR;
 
-       locale = _get_system_locale();
-       if (locale == NULL) {
-               __close_manifest_db();
+       dbpath = getUserPkgParserDBPathUID(uid);
+       if (dbpath == NULL) {
+               free(locale);
+               return PMINFO_R_ERROR;
+       }
+
+       ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("failed to open db: %d", ret);
+               free(locale);
+               return PMINFO_R_ERROR;
+       }
+
+       if (_pkginfo_get_list(db, locale, filter, list)) {
+               free(locale);
+               sqlite3_close_v2(db);
                return PMINFO_R_ERROR;
        }
+       sqlite3_close_v2(db);
 
-       list = _pkginfo_get_filtered_list(locale, filter);
-       if (list == NULL) {
+       if (uid == GLOBAL_USER) {
                free(locale);
-               __close_manifest_db();
                return PMINFO_R_OK;
        }
 
+       /* search again from global */
+       dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
+       if (dbpath == NULL) {
+               free(locale);
+               return PMINFO_R_ERROR;
+       }
+
+       ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("failed to open db: %d", ret);
+               free(locale);
+               return PMINFO_R_ERROR;
+       }
+
+       if (_pkginfo_get_list(db, locale, filter, list)) {
+               free(locale);
+               sqlite3_close_v2(db);
+               return PMINFO_R_ERROR;
+       }
+       sqlite3_close_v2(db);
+
+       /* remove duplicate element:
+        * since the list is sorted, we can remove duplicates in linear time
+        */
+       for (tmp = *list, tmp2 = g_list_next(tmp); tmp;
+                       tmp = tmp2, tmp2 = g_list_next(tmp)) {
+               if (tmp->prev == NULL || tmp->data == NULL)
+                       continue;
+               if (strcmp((const char *)tmp->prev->data,
+                                       (const char *)tmp->data) == 0)
+                       *list = g_list_delete_link(*list, tmp);
+       }
+
+       free(locale);
+
+       return PMINFO_R_OK;
+}
+
+
+static int _pkginfo_get_filtered_foreach_pkginfo(pkgmgrinfo_filter_x *filter,
+               pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
+{
+       int ret;
+       pkgmgr_pkginfo_x *info;
+       GList *list = NULL;
+       GList *tmp;
+       char *pkgid;
+       int stop = 0;
+
+       ret = _pkginfo_get_filtered_list(filter, uid, &list);
+       if (ret != PMINFO_R_OK)
+               return PMINFO_R_ERROR;
+
        for (tmp = list; tmp; tmp = tmp->next) {
                pkgid = (char *)tmp->data;
                if (stop == 0) {
-                       if (_pkginfo_get_pkg(pkgid, locale, &info)) {
+                       ret = _pkginfo_get_pkginfo(pkgid, uid, &info);
+                       if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
+                               ret = _pkginfo_get_pkginfo(pkgid, GLOBAL_USER,
+                                               &info);
+                       if (ret != PMINFO_R_OK) {
                                free(pkgid);
                                continue;
                        }
-                       info->uid = uid;
                        if (pkg_list_cb(info, user_data) < 0)
                                stop = 1;
                        pkgmgrinfo_pkginfo_destroy_pkginfo(info);
@@ -274,9 +350,7 @@ static int _pkginfo_get_filtered_foreach_pkginfo(pkgmgrinfo_filter_x *filter,
                free(pkgid);
        }
 
-       free(locale);
-       g_slist_free(list);
-       __close_manifest_db();
+       g_list_free(list);
 
        return PMINFO_R_OK;
 }
@@ -298,7 +372,8 @@ API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *us
        return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, GLOBAL_USER);
 }
 
-static int _pkginfo_get_author(const char *pkgid, author_x **author)
+static int _pkginfo_get_author(sqlite3 *db, const char *pkgid,
+               GList **author)
 {
        static const char query_raw[] =
                "SELECT author_name, author_email, author_href "
@@ -315,16 +390,16 @@ static int _pkginfo_get_author(const char *pkgid, author_x **author)
                return PMINFO_R_ERROR;
        }
 
-       ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
+       ret = sqlite3_prepare_v2(db, query, strlen(query),
                        &stmt, NULL);
        sqlite3_free(query);
        if (ret != SQLITE_OK) {
-               LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
+               LOGE("prepare failed: %s", sqlite3_errmsg(db));
                return PMINFO_R_ERROR;
        }
 
        if (sqlite3_step(stmt) == SQLITE_ERROR) {
-               LOGE("step error: %s", sqlite3_errmsg(GET_DB(manifest_db)));
+               LOGE("step error: %s", sqlite3_errmsg(db));
                sqlite3_finalize(stmt);
                return PMINFO_R_ERROR;
        }
@@ -341,15 +416,16 @@ static int _pkginfo_get_author(const char *pkgid, author_x **author)
        _save_column_str(stmt, idx++, &info->email);
        _save_column_str(stmt, idx++, &info->href);
 
-       *author = info;
+       /* TODO: revised */
+       *author = g_list_append(*author, info);
 
        sqlite3_finalize(stmt);
 
        return PMINFO_R_OK;
 }
 
-static int _pkginfo_get_label(const char *pkgid, const char *locale,
-               label_x **label)
+static int _pkginfo_get_label(sqlite3 *db, const char *pkgid,
+               const char *locale, GList **label)
 {
        static const char query_raw[] =
                "SELECT package_label, package_locale "
@@ -367,11 +443,11 @@ static int _pkginfo_get_label(const char *pkgid, const char *locale,
                return PMINFO_R_ERROR;
        }
 
-       ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
+       ret = sqlite3_prepare_v2(db, query, strlen(query),
                        &stmt, NULL);
        sqlite3_free(query);
        if (ret != SQLITE_OK) {
-               LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
+               LOGE("prepare failed: %s", sqlite3_errmsg(db));
                return PMINFO_R_ERROR;
        }
 
@@ -380,21 +456,12 @@ static int _pkginfo_get_label(const char *pkgid, const char *locale,
                if (info == NULL) {
                        LOGE("out of memory");
                        sqlite3_finalize(stmt);
-                       if (*label) {
-                               LISTHEAD(*label, info);
-                               *label = info;
-                       }
                        return PMINFO_R_ERROR;
                }
                idx = 0;
                _save_column_str(stmt, idx++, &info->text);
                _save_column_str(stmt, idx++, &info->lang);
-               LISTADD(*label, info);
-       }
-
-       if (*label) {
-               LISTHEAD(*label, info);
-               *label = info;
+               *label = g_list_append(*label, info);
        }
 
        sqlite3_finalize(stmt);
@@ -402,8 +469,8 @@ static int _pkginfo_get_label(const char *pkgid, const char *locale,
        return PMINFO_R_OK;
 }
 
-static int _pkginfo_get_icon(const char *pkgid, const char *locale,
-               icon_x **icon)
+static int _pkginfo_get_icon(sqlite3 *db, const char *pkgid, const char *locale,
+               GList **icon)
 {
        static const char query_raw[] =
                "SELECT package_icon, package_locale "
@@ -421,11 +488,11 @@ static int _pkginfo_get_icon(const char *pkgid, const char *locale,
                return PMINFO_R_ERROR;
        }
 
-       ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
+       ret = sqlite3_prepare_v2(db, query, strlen(query),
                        &stmt, NULL);
        sqlite3_free(query);
        if (ret != SQLITE_OK) {
-               LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
+               LOGE("prepare failed: %s", sqlite3_errmsg(db));
                return PMINFO_R_ERROR;
        }
 
@@ -434,21 +501,12 @@ static int _pkginfo_get_icon(const char *pkgid, const char *locale,
                if (info == NULL) {
                        LOGE("out of memory");
                        sqlite3_finalize(stmt);
-                       if (*icon) {
-                               LISTHEAD(*icon, info);
-                               *icon = info;
-                       }
                        return PMINFO_R_ERROR;
                }
                idx = 0;
                _save_column_str(stmt, idx++, &info->text);
                _save_column_str(stmt, idx++, &info->lang);
-               LISTADD(*icon, info);
-       }
-
-       if (*icon) {
-               LISTHEAD(*icon, info);
-               *icon = info;
+               *icon = g_list_append(*icon, info);
        }
 
        sqlite3_finalize(stmt);
@@ -456,8 +514,8 @@ static int _pkginfo_get_icon(const char *pkgid, const char *locale,
        return PMINFO_R_OK;
 }
 
-static int _pkginfo_get_description(const char *pkgid, const char *locale,
-               description_x **description)
+static int _pkginfo_get_description(sqlite3 *db, const char *pkgid,
+               const char *locale, GList **description)
 {
        static const char query_raw[] =
                "SELECT package_description, package_locale "
@@ -475,11 +533,11 @@ static int _pkginfo_get_description(const char *pkgid, const char *locale,
                return PMINFO_R_ERROR;
        }
 
-       ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
+       ret = sqlite3_prepare_v2(db, query, strlen(query),
                        &stmt, NULL);
        sqlite3_free(query);
        if (ret != SQLITE_OK) {
-               LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
+               LOGE("prepare failed: %s", sqlite3_errmsg(db));
                return PMINFO_R_ERROR;
        }
 
@@ -488,21 +546,12 @@ static int _pkginfo_get_description(const char *pkgid, const char *locale,
                if (info == NULL) {
                        LOGE("out of memory");
                        sqlite3_finalize(stmt);
-                       if (*description) {
-                               LISTHEAD(*description, info);
-                               *description = info;
-                       }
                        return PMINFO_R_ERROR;
                }
                idx = 0;
                _save_column_str(stmt, idx++, &info->text);
                _save_column_str(stmt, idx++, &info->lang);
-               LISTADD(*description, info);
-       }
-
-       if (*description) {
-               LISTHEAD(*description, info);
-               *description = info;
+               *description = g_list_append(*description, info);
        }
 
        sqlite3_finalize(stmt);
@@ -510,58 +559,36 @@ static int _pkginfo_get_description(const char *pkgid, const char *locale,
        return PMINFO_R_OK;
 }
 
-static int _pkginfo_get_privilege(const char *pkgid, privileges_x **privileges)
+static int _pkginfo_get_privilege(sqlite3 *db, const char *pkgid,
+               GList **privileges)
 {
        static const char query_raw[] =
                "SELECT privilege FROM package_privilege_info WHERE package=%Q";
        int ret;
        char *query;
        sqlite3_stmt *stmt;
-       privileges_x *p;
-       privilege_x *info;
-
-       /* privilege list should stored in privileges_x... */
-       p = calloc(1, sizeof(privileges_x));
-       if (p == NULL) {
-               LOGE("out of memory");
-               return PMINFO_R_ERROR;
-       }
-       *privileges = p;
+       char *privilege;
 
        query = sqlite3_mprintf(query_raw, pkgid);
        if (query == NULL) {
                LOGE("out of memory");
-               free(p);
                return PMINFO_R_ERROR;
        }
 
-       ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
+       ret = sqlite3_prepare_v2(db, query, strlen(query),
                        &stmt, NULL);
        sqlite3_free(query);
        if (ret != SQLITE_OK) {
-               LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
-               free(p);
+               LOGE("prepare failed: %s", sqlite3_errmsg(db));
                return PMINFO_R_ERROR;
        }
 
        while (sqlite3_step(stmt) == SQLITE_ROW) {
-               info = calloc(1, sizeof(privilege_x));
-               if (info == NULL) {
-                       LOGE("out of memory");
-                       sqlite3_finalize(stmt);
-                       if (p->privilege) {
-                               LISTHEAD(p->privilege, info);
-                               p->privilege = info;
-                       }
-                       return PMINFO_R_ERROR;
-               }
-               _save_column_str(stmt, 0, &info->text);
-               LISTADD(p->privilege, info);
-       }
-
-       if (p->privilege) {
-               LISTHEAD(p->privilege, info);
-               p->privilege = info;
+               privilege = NULL;
+               _save_column_str(stmt, 0, &privilege);
+               if (privilege)
+                       *privileges = g_list_append(*privileges,
+                                       (gpointer)privilege);
        }
 
        sqlite3_finalize(stmt);
@@ -604,23 +631,23 @@ static char *_get_filtered_query(const char *query_raw,
        return strdup(buf);
 }
 
-static int _pkginfo_get_pkg(const char *pkgid, const char *locale,
-               pkgmgr_pkginfo_x **pkginfo)
+static int _pkginfo_get_package(sqlite3 *db, const char *pkgid,
+               const char *locale, package_x **package)
 {
        static const char query_raw[] =
-               "SELECT for_all_users, package, package_version, "
+               "SELECT package, package_version, "
                "install_location, package_removable, package_preload, "
                "package_readonly, package_update, package_appsetting, "
                "package_system, package_type, package_size, installed_time, "
                "installed_storage, storeclient_id, mainapp_id, package_url, "
-               "root_path, csc_path, package_nodisplay, package_api_version "
-               "FROM package_info WHERE package=%Q";
+               "root_path, csc_path, package_nodisplay, package_api_version, "
+               "package_support_disable, package_tep_name "
+               "FROM package_info WHERE package=%Q AND package_disable='false'";
        int ret;
        char *query;
        sqlite3_stmt *stmt;
        int idx;
-       pkgmgr_pkginfo_x *info;
-       package_x *pkg;
+       package_x *info;
 
        query = sqlite3_mprintf(query_raw, pkgid);
        if (query == NULL) {
@@ -628,137 +655,162 @@ static int _pkginfo_get_pkg(const char *pkgid, const char *locale,
                return PMINFO_R_ERROR;
        }
 
-       ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
+       ret = sqlite3_prepare_v2(db, query, strlen(query),
                        &stmt, NULL);
        sqlite3_free(query);
        if (ret != SQLITE_OK) {
-               LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
+               LOGE("prepare failed: %s", sqlite3_errmsg(db));
                return PMINFO_R_ERROR;
        }
 
        ret = sqlite3_step(stmt);
        if (ret == SQLITE_DONE) {
-               LOGE("cannot find pkg");
                sqlite3_finalize(stmt);
                return PMINFO_R_ENOENT;
        } else if (ret != SQLITE_ROW) {
-               LOGE("step failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
+               LOGE("step failed: %s", sqlite3_errmsg(db));
                sqlite3_finalize(stmt);
                return PMINFO_R_ERROR;
        }
 
-       pkg = calloc(1, sizeof(package_x));
-       if (pkg == NULL) {
+       info = calloc(1, sizeof(package_x));
+       if (info == NULL) {
                LOGE("out of memory");
                sqlite3_finalize(stmt);
                return PMINFO_R_ERROR;
        }
        idx = 0;
-       _save_column_str(stmt, idx++, &pkg->for_all_users);
-       _save_column_str(stmt, idx++, &pkg->package);
-       _save_column_str(stmt, idx++, &pkg->version);
-       _save_column_str(stmt, idx++, &pkg->installlocation);
-       _save_column_str(stmt, idx++, &pkg->removable);
-       _save_column_str(stmt, idx++, &pkg->preload);
-       _save_column_str(stmt, idx++, &pkg->readonly);
-       _save_column_str(stmt, idx++, &pkg->update);
-       _save_column_str(stmt, idx++, &pkg->appsetting);
-       _save_column_str(stmt, idx++, &pkg->system);
-       _save_column_str(stmt, idx++, &pkg->type);
-       _save_column_str(stmt, idx++, &pkg->package_size);
-       _save_column_str(stmt, idx++, &pkg->installed_time);
-       _save_column_str(stmt, idx++, &pkg->installed_storage);
-       _save_column_str(stmt, idx++, &pkg->storeclient_id);
-       _save_column_str(stmt, idx++, &pkg->mainapp_id);
-       _save_column_str(stmt, idx++, &pkg->package_url);
-       _save_column_str(stmt, idx++, &pkg->root_path);
-       _save_column_str(stmt, idx++, &pkg->csc_path);
-       _save_column_str(stmt, idx++, &pkg->nodisplay_setting);
-       _save_column_str(stmt, idx++, &pkg->api_version);
-
-       if (_pkginfo_get_author(pkg->package, &pkg->author)) {
-               pkgmgrinfo_basic_free_package(pkg);
+       _save_column_str(stmt, idx++, &info->package);
+       _save_column_str(stmt, idx++, &info->version);
+       _save_column_str(stmt, idx++, &info->installlocation);
+       _save_column_str(stmt, idx++, &info->removable);
+       _save_column_str(stmt, idx++, &info->preload);
+       _save_column_str(stmt, idx++, &info->readonly);
+       _save_column_str(stmt, idx++, &info->update);
+       _save_column_str(stmt, idx++, &info->appsetting);
+       _save_column_str(stmt, idx++, &info->system);
+       _save_column_str(stmt, idx++, &info->type);
+       _save_column_str(stmt, idx++, &info->package_size);
+       _save_column_str(stmt, idx++, &info->installed_time);
+       _save_column_str(stmt, idx++, &info->installed_storage);
+       _save_column_str(stmt, idx++, &info->storeclient_id);
+       _save_column_str(stmt, idx++, &info->mainapp_id);
+       _save_column_str(stmt, idx++, &info->package_url);
+       _save_column_str(stmt, idx++, &info->root_path);
+       _save_column_str(stmt, idx++, &info->csc_path);
+       _save_column_str(stmt, idx++, &info->nodisplay_setting);
+       _save_column_str(stmt, idx++, &info->api_version);
+       _save_column_str(stmt, idx++, &info->support_disable);
+       _save_column_str(stmt, idx++, &info->tep_name);
+
+       if (_pkginfo_get_author(db, info->package, &info->author)) {
+               pkgmgrinfo_basic_free_package(info);
                sqlite3_finalize(stmt);
                return PMINFO_R_ERROR;
        }
 
-       if (_pkginfo_get_label(pkg->package, locale, &pkg->label)) {
-               pkgmgrinfo_basic_free_package(pkg);
+       if (_pkginfo_get_label(db, info->package, locale, &info->label)) {
+               pkgmgrinfo_basic_free_package(info);
                sqlite3_finalize(stmt);
                return PMINFO_R_ERROR;
        }
 
-       if (_pkginfo_get_icon(pkg->package, locale, &pkg->icon)) {
-               pkgmgrinfo_basic_free_package(pkg);
+       if (_pkginfo_get_icon(db, info->package, locale, &info->icon)) {
+               pkgmgrinfo_basic_free_package(info);
                sqlite3_finalize(stmt);
                return PMINFO_R_ERROR;
        }
 
-       if (_pkginfo_get_description(pkg->package, locale,
-                               &pkg->description)) {
-               pkgmgrinfo_basic_free_package(pkg);
+       if (_pkginfo_get_description(db, info->package, locale,
+                               &info->description)) {
+               pkgmgrinfo_basic_free_package(info);
                sqlite3_finalize(stmt);
                return PMINFO_R_ERROR;
        }
 
-       if (_pkginfo_get_privilege(pkg->package, &pkg->privileges)) {
-               pkgmgrinfo_basic_free_package(pkg);
-               sqlite3_finalize(stmt);
-                       return PMINFO_R_ERROR;
-       }
-
-       info = calloc(1, sizeof(pkgmgr_pkginfo_x));
-       if (info == NULL) {
-               LOGE("out of memory");
-               pkgmgrinfo_basic_free_package(pkg);
+       if (_pkginfo_get_privilege(db, info->package, &info->privileges)) {
+               pkgmgrinfo_basic_free_package(info);
                sqlite3_finalize(stmt);
                return PMINFO_R_ERROR;
        }
 
-       info->pkg_info = pkg;
-       info->locale = strdup(locale);
-       *pkginfo = info;
-
+       *package = info;
        sqlite3_finalize(stmt);
 
        return PMINFO_R_OK;
 }
 
-API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
-               pkgmgrinfo_pkginfo_h *handle)
+static int _pkginfo_get_pkginfo(const char *pkgid, uid_t uid,
+               pkgmgr_pkginfo_x **pkginfo)
 {
-       pkgmgr_pkginfo_x *pkginfo = NULL;
+       int ret;
+       sqlite3 *db;
+       const char *dbpath;
        char *locale;
+       pkgmgr_pkginfo_x *info;
 
-       if (pkgid == NULL || handle == NULL) {
-               LOGE("invalid parameter");
-               return PMINFO_R_EINVAL;
-       }
-
-       if (__open_manifest_db(uid) < 0)
+       dbpath = getUserPkgParserDBPathUID(uid);
+       if (dbpath == NULL)
                return PMINFO_R_ERROR;
 
-
        locale = _get_system_locale();
-       if (locale == NULL) {
-               __close_manifest_db();
+       if (locale == NULL)
+               return PMINFO_R_ERROR;
+
+       ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("failed to open db: %d", ret);
+               free(locale);
                return PMINFO_R_ERROR;
        }
 
-       if (_pkginfo_get_pkg(pkgid, locale, &pkginfo)) {
-               LOGE("failed to get pkginfo of %s for user %d", pkgid, uid);
+       info = calloc(1, sizeof(pkgmgr_pkginfo_x));
+       if (info == NULL) {
+               _LOGE("out of memory");
                free(locale);
-               __close_manifest_db();
+               sqlite3_close_v2(db);
                return PMINFO_R_ERROR;
        }
 
-       free(locale);
-       pkginfo->uid = uid;
-       *handle = pkginfo;
+       ret = _pkginfo_get_package(db, pkgid, locale, &info->pkg_info);
+       if (ret != PMINFO_R_OK) {
+               free(info);
+               free(locale);
+               sqlite3_close_v2(db);
+               return ret;
+       }
 
-       __close_manifest_db();
+       info->locale = locale;
+       info->uid = uid;
+       info->pkg_info->for_all_users = strdup(
+                       uid != GLOBAL_USER ? "false" : "true");
 
-       return PMINFO_R_OK;
+       *pkginfo = info;
+
+       sqlite3_close_v2(db);
+
+       return ret;
+}
+
+API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid,
+               pkgmgrinfo_pkginfo_h *handle)
+{
+       int ret;
+
+       if (pkgid == NULL || handle == NULL) {
+               LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       ret = _pkginfo_get_pkginfo(pkgid, uid, (pkgmgr_pkginfo_x **)handle);
+       if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
+               ret = _pkginfo_get_pkginfo(pkgid, GLOBAL_USER,
+                               (pkgmgr_pkginfo_x **)handle);
+
+       if (ret != PMINFO_R_OK)
+               _LOGE("failed to get pkginfo of %s for user %d", pkgid, uid);
+
+       return ret;
 }
 
 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
@@ -826,6 +878,39 @@ API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **versi
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_pkginfo_get_api_version(pkgmgrinfo_pkginfo_h handle, char **api_version)
+{
+       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(api_version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+
+       if (info->pkg_info == NULL || info->pkg_info->api_version == NULL)
+               return PMINFO_R_ERROR;
+
+       *api_version = (char *)info->pkg_info->api_version;
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_pkginfo_get_tep_name(pkgmgrinfo_pkginfo_h handle, char **tep_name)
+{
+       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(tep_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+
+       if (info->pkg_info == NULL || info->pkg_info->tep_name == NULL)
+               return PMINFO_R_ERROR;
+
+       if (strlen(info->pkg_info->tep_name) == 0)
+               return PMINFO_R_ERROR;
+
+       *tep_name = (char *)info->pkg_info->tep_name;
+
+       return PMINFO_R_OK;
+}
+
 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
 {
        char *val;
@@ -1023,8 +1108,9 @@ API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
 
 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
 {
-       char *locale;
+       const char *locale;
        icon_x *ptr;
+       GList *tmp;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
 
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
@@ -1033,22 +1119,27 @@ API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
        locale = info->locale;
        retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
 
-       for (ptr = info->pkg_info->icon; ptr != NULL; ptr = ptr->next) {
-               if (ptr->lang == NULL)
+       if (info->pkg_info == NULL)
+               return PMINFO_R_ERROR;
+
+       for (tmp = info->pkg_info->icon; tmp; tmp = tmp->next) {
+               ptr = (icon_x *)tmp->data;
+               if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
+                               !strcasecmp(ptr->text, "(null)") ||
+                               strcmp(ptr->lang, locale))
                        continue;
+               *icon = (char *)ptr->text;
+               return PMINFO_R_OK;
+       }
 
-               if (strcmp(ptr->lang, locale) == 0) {
-                       *icon = (char *)ptr->text;
-                       if (strcasecmp(*icon, "(null)") == 0) {
-                               locale = DEFAULT_LOCALE;
-                               continue;
-                       } else {
-                               return PMINFO_R_OK;
-                       }
-               } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
-                       *icon = (char *)ptr->text;
-                       return PMINFO_R_OK;
-               }
+       locale = DEFAULT_LOCALE;
+       for (tmp = info->pkg_info->icon; tmp; tmp = tmp->next) {
+               ptr = (icon_x *)tmp->data;
+               if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
+                               strcmp(ptr->lang, locale))
+                       continue;
+               *icon = (char *)ptr->text;
+               return PMINFO_R_OK;
        }
 
        return PMINFO_R_ERROR;
@@ -1056,8 +1147,9 @@ API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
 
 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
 {
-       char *locale;
+       const char *locale;
        label_x *ptr;
+       GList *tmp;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
 
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
@@ -1066,22 +1158,23 @@ API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
        locale = info->locale;
        retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
 
-       for (ptr = info->pkg_info->label; ptr != NULL; ptr = ptr->next) {
-               if (ptr->lang == NULL)
+       for (tmp = info->pkg_info->label; tmp != NULL; tmp = tmp->next) {
+               ptr = (label_x *)tmp->data;
+               if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
+                               strcmp(ptr->lang, locale))
                        continue;
+               *label = (char *)ptr->text;
+               return PMINFO_R_OK;
+       }
 
-               if (strcmp(ptr->lang, locale) == 0) {
-                       *label = (char *)ptr->text;
-                       if (strcasecmp(*label, "(null)") == 0) {
-                               locale = DEFAULT_LOCALE;
-                               continue;
-                       } else {
-                               return PMINFO_R_OK;
-                       }
-               } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
-                       *label = (char *)ptr->text;
-                       return PMINFO_R_OK;
-               }
+       locale = DEFAULT_LOCALE;
+       for (tmp = info->pkg_info->label; tmp != NULL; tmp = tmp->next) {
+               ptr = (label_x *)tmp->data;
+               if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
+                               strcmp(ptr->lang, locale))
+                       continue;
+               *label = (char *)ptr->text;
+               return PMINFO_R_OK;
        }
 
        return PMINFO_R_ERROR;
@@ -1089,8 +1182,9 @@ API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
 
 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
 {
-       char *locale;
+       const char *locale;
        description_x *ptr;
+       GList *tmp;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
 
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
@@ -1099,22 +1193,23 @@ API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **d
        locale = info->locale;
        retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
 
-       for (ptr = info->pkg_info->description; ptr != NULL; ptr = ptr->next) {
-               if (ptr->lang == NULL)
+       for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) {
+               ptr = (description_x *)tmp->data;
+               if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
+                               strcmp(ptr->lang, locale))
                        continue;
+               *description = (char *)ptr->text;
+               return PMINFO_R_OK;
+       }
 
-               if (strcmp(ptr->lang, locale) == 0) {
-                       *description = (char *)ptr->text;
-                       if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
-                               locale = DEFAULT_LOCALE;
-                               continue;
-                       } else {
-                               return PMINFO_R_OK;
-                       }
-               } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
-                       *description = (char *)ptr->text;
-                       return PMINFO_R_OK;
-               }
+       locale = DEFAULT_LOCALE;
+       for (tmp = info->pkg_info->description; tmp; tmp = tmp->next) {
+               ptr = (description_x *)tmp->data;
+               if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
+                               strcmp(ptr->lang, locale))
+                       continue;
+               *description = (char *)ptr->text;
+               return PMINFO_R_OK;
        }
 
        return PMINFO_R_ERROR;
@@ -1122,49 +1217,40 @@ API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **d
 
 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
 {
-       char *locale;
-       author_x *ptr;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+       author_x *author;
 
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
        retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
 
-       locale = info->locale;
-       retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
+       if (info->pkg_info == NULL || info->pkg_info->author == NULL)
+               return PMINFO_R_ERROR;
 
-       for (ptr = info->pkg_info->author; ptr != NULL; ptr = ptr->next) {
-               if (ptr->lang == NULL)
-                       continue;
+       author = (author_x *)info->pkg_info->author->data;
+       if (author == NULL || author->text == NULL)
+               return PMINFO_R_ERROR;
 
-               if (strcmp(ptr->lang, locale) == 0) {
-                       *author_name = (char *)ptr->text;
-                       if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
-                               locale = DEFAULT_LOCALE;
-                               continue;
-                       } else {
-                               return PMINFO_R_OK;
-                       }
-               } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
-                       *author_name = (char *)ptr->text;
-                       return PMINFO_R_OK;
-               }
-       }
+       *author_name = (char *)author->text;
 
-       return PMINFO_R_ERROR;
+       return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
 {
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+       author_x *author;
 
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
        retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
 
-       if (info->pkg_info == NULL || info->pkg_info->author == NULL ||
-                       info->pkg_info->author->email == NULL)
+       if (info->pkg_info == NULL || info->pkg_info->author == NULL)
                return PMINFO_R_ERROR;
 
-       *author_email = (char *)info->pkg_info->author->email;
+       author = (author_x *)info->pkg_info->author->data;
+       if (author == NULL || author->email == NULL)
+               return PMINFO_R_ERROR;
+
+       *author_email = (char *)author->email;
 
        return PMINFO_R_OK;
 }
@@ -1172,15 +1258,19 @@ API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **
 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
 {
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+       author_x *author;
 
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
        retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
 
-       if (info->pkg_info == NULL || info->pkg_info->author == NULL ||
-                       info->pkg_info->author->href == NULL)
+       if (info->pkg_info == NULL || info->pkg_info->author == NULL)
+               return PMINFO_R_ERROR;
+
+       author = (author_x *)info->pkg_info->author->data;
+       if (author == NULL || author->href == NULL)
                return PMINFO_R_ERROR;
 
-       *author_href = (char *)info->pkg_info->author->href;
+       *author_href = (char *)author->href;
 
        return PMINFO_R_OK;
 }
@@ -1468,7 +1558,6 @@ API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *acce
 
 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
 {
-       char *val;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
 
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
@@ -1477,13 +1566,7 @@ API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *remov
        if (info->pkg_info == NULL || info->pkg_info->removable == NULL)
                return PMINFO_R_ERROR;
 
-       val = (char *)info->pkg_info->removable;
-       if (strcasecmp(val, "true") == 0)
-               *removable = 1;
-       else if (strcasecmp(val, "false") == 0)
-               *removable = 0;
-       else
-               *removable = 1;
+       *removable = _get_bool_value(info->pkg_info->removable);
 
        return PMINFO_R_OK;
 }
@@ -1512,7 +1595,6 @@ API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable
 
 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
 {
-       char *val;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
 
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
@@ -1521,20 +1603,13 @@ API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload
        if (info->pkg_info == NULL || info->pkg_info->preload == NULL)
                return PMINFO_R_ERROR;
 
-       val = (char *)info->pkg_info->preload;
-       if (strcasecmp(val, "true") == 0)
-               *preload = 1;
-       else if (strcasecmp(val, "false") == 0)
-               *preload = 0;
-       else
-               *preload = 0;
+       *preload = _get_bool_value(info->pkg_info->preload);
 
        return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
 {
-       char *val;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
 
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
@@ -1543,20 +1618,13 @@ API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
        if (info->pkg_info == NULL || info->pkg_info->system == NULL)
                return PMINFO_R_ERROR;
 
-       val = (char *)info->pkg_info->system;
-       if (strcasecmp(val, "true") == 0)
-               *system = 1;
-       else if (strcasecmp(val, "false") == 0)
-               *system = 0;
-       else
-               *system = 0;
+       *system = _get_bool_value(info->pkg_info->system);
 
        return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
 {
-       char *val;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
 
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
@@ -1565,20 +1633,13 @@ API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readon
        if (info->pkg_info == NULL || info->pkg_info->readonly == NULL)
                return PMINFO_R_ERROR;
 
-       val = (char *)info->pkg_info->readonly;
-       if (strcasecmp(val, "true") == 0)
-               *readonly = 1;
-       else if (strcasecmp(val, "false") == 0)
-               *readonly = 0;
-       else
-               *readonly = 0;
+       *readonly = _get_bool_value(info->pkg_info->readonly);
 
        return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
 {
-       char *val;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
 
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
@@ -1587,39 +1648,45 @@ API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
        if (info->pkg_info == NULL || info->pkg_info->update == NULL)
                return PMINFO_R_ERROR;
 
-       val = (char *)info->pkg_info->update;
-       if (strcasecmp(val, "true") == 0)
-               *update = 1;
-       else if (strcasecmp(val, "false") == 0)
-               *update = 0;
-       else
-               *update = 1;
+       *update = _get_bool_value(info->pkg_info->update);
 
        return PMINFO_R_OK;
 }
 
-API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
+API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
+{
+       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
+
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
+       retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+
+       if (info->pkg_info == NULL || info->pkg_info->support_disable == NULL)
+               return PMINFO_R_ERROR;
+
+       *support_disable = _get_bool_value(info->pkg_info->support_disable);
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_pkginfo_is_global(pkgmgrinfo_pkginfo_h handle, bool *global)
 {
-       char *val;
        pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
 
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
-       retvm_if(for_all_users == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
+       retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
 
        if (info->pkg_info == NULL || info->pkg_info->for_all_users == NULL)
                return PMINFO_R_ERROR;
 
-       val = (char *)info->pkg_info->for_all_users;
-       if (strcasecmp(val, "1") == 0)
-               *for_all_users = 1;
-       else if (strcasecmp(val, "0") == 0)
-               *for_all_users = 0;
-       else
-               *for_all_users = 1;
+       *global = _get_bool_value(info->pkg_info->for_all_users);
 
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
+{
+       return pkgmgrinfo_pkginfo_is_global(handle, for_all_users);
+}
 
 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
 {
@@ -1807,72 +1874,23 @@ API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
 
 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
 {
-       retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
-       retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
-       char *locale = NULL;
-       char *condition = NULL;
-       char *error_message = NULL;
-       char query[MAX_QUERY_LEN] = {'\0'};
-       char where[MAX_QUERY_LEN] = {'\0'};
-       GSList *list;
-       int ret = 0;
+       int ret;
+       GList *list = NULL;
 
-       pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
-       filter->uid = uid;
-       /*Get current locale*/
-       locale = _get_system_locale();
-       if (locale == NULL) {
-               _LOGE("manifest locale is NULL\n");
-               return PMINFO_R_ERROR;
+       if (handle == NULL || count == NULL) {
+               _LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
        }
 
-       ret = __open_manifest_db(uid);
-       if (ret == -1) {
-               _LOGE("Fail to open manifest DB\n");
-               free(locale);
+       ret = _pkginfo_get_filtered_list((pkgmgrinfo_filter_x *)handle, uid, &list);
+       if (ret != PMINFO_R_OK)
                return PMINFO_R_ERROR;
-       }
 
-       /*Start constructing query*/
-       snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
+       *count = g_list_length(list);
 
-       /*Get where clause*/
-       for (list = filter->list; list; list = g_slist_next(list)) {
-               __get_filter_condition(list->data, &condition);
-               if (condition) {
-                       strncat(where, condition, sizeof(where) - strlen(where) -1);
-                       where[sizeof(where) - 1] = '\0';
-                       free(condition);
-                       condition = NULL;
-               }
-               if (g_slist_next(list)) {
-                       strncat(where, " and ", sizeof(where) - strlen(where) - 1);
-                       where[sizeof(where) - 1] = '\0';
-               }
-       }
-       if (strlen(where) > 0) {
-               strncat(query, where, sizeof(query) - strlen(query) - 1);
-               query[sizeof(query) - 1] = '\0';
-       }
+       g_list_free_full(list, free);
 
-       /*Execute Query*/
-       if (SQLITE_OK !=
-           sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
-               _LOGE("Don't execute query = %s error message = %s\n", query,
-                      error_message);
-               sqlite3_free(error_message);
-               ret = PMINFO_R_ERROR;
-               *count = 0;
-               goto err;
-       }
-       ret = PMINFO_R_OK;
-err:
-       if (locale) {
-               free(locale);
-               locale = NULL;
-       }
-       __close_manifest_db();
-       return ret;
+       return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
@@ -1904,332 +1922,21 @@ API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
        retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
-       int ret = -1;
-       privilege_x *ptr = NULL;
-       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
-       ptr = info->pkg_info->privileges->privilege;
-       for (; ptr; ptr = ptr->next) {
-               if (ptr->text){
-                       ret = privilege_func(ptr->text, user_data);
-                       if (ret < 0)
-                               break;
-               }
-       }
-       return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
-{
-       retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
-       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
-       char *manifest = NULL;
-       manifest_x *mfx = NULL;
-       *handle = NULL;
-       manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
-       retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
-
-       mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
-       if (manifest) {
-               free(manifest);
-               manifest = NULL;
-       }
-       retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
-
-       *handle = (void *)mfx;
-
-       return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
-{
-       retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
-       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
-       char *manifest = NULL;
-       manifest_x *mfx = NULL;
-       *handle = NULL;
-       manifest = pkgmgr_parser_get_manifest_file(pkgid);
-       retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
-
-       mfx = pkgmgr_parser_process_manifest_xml(manifest);
-       if (manifest) {
-               free(manifest);
-               manifest = NULL;
-       }
-       retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
-
-       *handle = (void *)mfx;
-
-       return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
-{
-       int len;
-       manifest_x *mfx = (manifest_x *)handle;
-
-       retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
-       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
-       len = strlen(type);
-       retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
-
-       if (mfx->type)
-               free((void *)mfx->type);
-
-       mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
-
-       return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
-{
-       int len;
-       manifest_x *mfx = (manifest_x *)handle;
-
-       retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
-       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
-       len = strlen(version);
-       retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
-
-       if (mfx->version)
-               free((void *)mfx->version);
-
-       mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
-       return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
-{
-       manifest_x *mfx = (manifest_x *)handle;
-
-       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-       retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
-
-       if (mfx->installlocation)
-               free((void *)mfx->installlocation);
-
-       if (location == INSTALL_INTERNAL)
-               mfx->installlocation = strdup("internal-only");
-       else if (location == INSTALL_EXTERNAL)
-               mfx->installlocation = strdup("prefer-external");
-
-       return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
-{
-       manifest_x *mfx = (manifest_x *)handle;
-
-       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-       retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
-       if (mfx->package_size)
-               free((void *)mfx->package_size);
-
-       mfx->package_size = strdup(size);
-
-       return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
-{
-       int len;
-       manifest_x *mfx = (manifest_x *)handle;
-       label_x *label;
-
-       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-       retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
-       len = strlen(label_txt);
-       retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
-
-       label = calloc(1, sizeof(label_x));
-       retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
-
-       LISTADD(mfx->label, label);
-       if (locale)
-               mfx->label->lang = strdup(locale);
-       else
-               mfx->label->lang = strdup(DEFAULT_LOCALE);
-       mfx->label->text = strdup(label_txt);
-
-       return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
-{
-       int len;
-       manifest_x *mfx = (manifest_x *)handle;
-       icon_x *icon;
-
-       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-       retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
-       len = strlen(icon_txt);
-       retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
-
-       icon = calloc(1, sizeof(icon_x));
-       retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
-
-       LISTADD(mfx->icon, icon);
-       if (locale)
-               mfx->icon->lang = strdup(locale);
-       else
-               mfx->icon->lang = strdup(DEFAULT_LOCALE);
-       mfx->icon->text = strdup(icon_txt);
-
-       return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
-{
-       int len = strlen(desc_txt);
-       manifest_x *mfx = (manifest_x *)handle;
-       description_x *description;
-
-       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-       retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
-       len = strlen(desc_txt);
-       retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
-
-       description = calloc(1, sizeof(description_x));
-       retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
-
-       LISTADD(mfx->description, description);
-       if (locale)
-               mfx->description->lang = strdup(locale);
-       else
-               mfx->description->lang = strdup(DEFAULT_LOCALE);
-       mfx->description->text = strdup(desc_txt);
-
-       return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
-               const char *author_email, const char *author_href, const char *locale)
-{
-       manifest_x *mfx = (manifest_x *)handle;
-       author_x *author;
-
-       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
-       author = calloc(1, sizeof(author_x));
-       retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
-       LISTADD(mfx->author, author);
-       if (author_name)
-               mfx->author->text = strdup(author_name);
-       if (author_email)
-               mfx->author->email = strdup(author_email);
-       if (author_href)
-               mfx->author->href = strdup(author_href);
-       if (locale)
-               mfx->author->lang = strdup(locale);
-       else
-               mfx->author->lang = strdup(DEFAULT_LOCALE);
-       return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
-{
-       manifest_x *mfx = (manifest_x *)handle;
-
-       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-       retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
-
-       if (mfx->removable)
-               free((void *)mfx->removable);
-
-       if (removable == 0)
-               mfx->removable = strdup("false");
-       else if (removable == 1)
-               mfx->removable = strdup("true");
-
-       return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
-{
-       manifest_x *mfx = (manifest_x *)handle;
-
-       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-       retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
-
-       if (mfx->preload)
-               free((void *)mfx->preload);
-
-       if (preload == 0)
-               mfx->preload = strdup("false");
-       else if (preload == 1)
-               mfx->preload = strdup("true");
-
-       return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
-{
-       manifest_x *mfx = (manifest_x *)handle;
-
-       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-       retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
-
-       if (mfx->installed_storage)
-               free((void *)mfx->installed_storage);
-
-       if (location == INSTALL_INTERNAL)
-               mfx->installed_storage = strdup("installed_internal");
-       else if (location == INSTALL_EXTERNAL)
-               mfx->installed_storage = strdup("installed_external");
-
-       return PMINFO_R_OK;
-}
-
-API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
-{
        int ret;
-       manifest_x *mfx = (manifest_x *)handle;
-       mfx = (manifest_x *)handle;
-
-       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
+       const char *privilege;
+       GList *tmp;
+       pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
 
-       ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
-       if (ret == 0) {
-               _LOGE("Successfully stored info in DB\n");
-               return PMINFO_R_OK;
-       } else {
-               _LOGE("Failed to store info in DB\n");
+       if (info->pkg_info == NULL)
                return PMINFO_R_ERROR;
-       }
-}
-
-API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
-{
-       int ret;
-       manifest_x *mfx = (manifest_x *)handle;
-
-       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
 
-       ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
-       if (ret == 0) {
-               _LOGE("Successfully stored info in DB\n");
-               return PMINFO_R_OK;
-       } else {
-               _LOGE("Failed to store info in DB\n");
-               return PMINFO_R_ERROR;
+       for (tmp = info->pkg_info->privileges; tmp; tmp = tmp->next) {
+               privilege = (const char *)tmp->data;
+               if (privilege == NULL)
+                       continue;
+               ret = privilege_func(privilege, user_data);
+               if (ret < 0)
+                       break;
        }
-}
-
-API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
-{
-       manifest_x *mfx = (manifest_x *)handle;
-
-       retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
-
-       pkgmgrinfo_basic_free_package(mfx);
-
        return PMINFO_R_OK;
 }