Add support for watch-application to pkgmgr-parser
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_appinfo.c
index cc47899..15383a0 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <string.h>
 #include <ctype.h>
 #include <unistd.h>
 #include "pkgmgrinfo_private.h"
 #include "pkgmgr_parser.h"
 
-#define FILTER_QUERY_COUNT_APP "select count(DISTINCT package_app_info.app_id) " \
-                               "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
-                               "ON package_app_info.app_id=package_app_localized_info.app_id " \
-                               "and package_app_localized_info.app_locale='%s' " \
-                               "LEFT OUTER JOIN package_app_app_svc " \
-                               "ON package_app_info.app_id=package_app_app_svc.app_id " \
-                               "LEFT OUTER JOIN package_app_app_category " \
-                               "ON package_app_info.app_id=package_app_app_category.app_id where "
+static bool _get_bool_value(const char *str)
+{
+       if (str == NULL)
+               return false;
+       else if (!strcasecmp(str, "true"))
+               return true;
+       else
+               return false;
+}
 
 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
 {
        pkgmgr_appinfo_x *info = data;
-       pkgmgr_appinfo_x *tmp;
 
-       while (info != NULL) {
-               tmp = info->next;
+       if (info != NULL) {
                if (info->package)
                        free((void *)info->package);
                if (info->locale)
@@ -37,7 +37,6 @@ static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
 
                pkgmgrinfo_basic_free_application(info->app_info);
                free((void *)info);
-               info = tmp;
        }
        return;
 }
@@ -77,53 +76,138 @@ static char *_get_filtered_query(const char *query_raw,
        return strdup(buf);
 }
 
-static GSList *_appinfo_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 gint _appinfo_get_list(sqlite3 *db, const char *locale,
+               pkgmgrinfo_filter_x *filter, GList **list)
 {
        static const char query_raw[] =
-               "SELECT package_app_info.app_id FROM package_app_info"
+               "SELECT DISTINCT package_app_info.app_id FROM package_app_info"
                " LEFT OUTER JOIN package_app_localized_info"
                "  ON package_app_info.app_id=package_app_localized_info.app_id"
                "  AND package_app_localized_info.app_locale=%Q"
                " LEFT OUTER JOIN package_app_app_category"
                "  ON package_app_info.app_id=package_app_app_category.app_id"
-               " LEFT OUTER JOIN package_app_app_svc"
-               "  ON package_app_info.app_id=package_app_app_svc.app_id ";
+               " LEFT OUTER JOIN package_app_app_control"
+               "  ON package_app_info.app_id=package_app_app_control.app_id"
+               " LEFT OUTER JOIN package_app_app_metadata"
+               "  ON package_app_info.app_id=package_app_app_metadata.app_id ";
        int ret;
        char *query;
        char *query_localized;
        sqlite3_stmt *stmt;
-       GSList *list = NULL;
-       char *appid;
+       char *appid = NULL;
 
        query = _get_filtered_query(query_raw, filter);
        if (query == NULL)
-               return NULL;
+               return PMINFO_R_ERROR;
        query_localized = sqlite3_mprintf(query, locale);
        free(query);
        if (query_localized == NULL)
-               return NULL;
+               return PMINFO_R_ERROR;
 
-       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 PMINFO_R_ERROR;
        }
 
        while (sqlite3_step(stmt) == SQLITE_ROW) {
                _save_column_str(stmt, 0, (const char **)&appid);
-               list = g_slist_append(list, appid);
+               if (appid != NULL)
+                       *list = g_list_insert_sorted(*list, appid,
+                                       __list_strcmp);
        }
 
        sqlite3_finalize(stmt);
 
-       return list;
+       return PMINFO_R_OK;
+}
+
+static int _appinfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid,
+               GList **list)
+{
+       int ret;
+       sqlite3 *db;
+       const char *dbpath;
+       char *locale;
+       GList *tmp;
+       GList *tmp2;
+
+       locale = _get_system_locale();
+       if (locale == NULL)
+               return PMINFO_R_ERROR;
+
+       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 (_appinfo_get_list(db, locale, filter, list)) {
+               free(locale);
+               sqlite3_close_v2(db);
+               return PMINFO_R_ERROR;
+       }
+       sqlite3_close_v2(db);
+
+       if (uid == GLOBAL_USER) {
+               free(locale);
+               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 (_appinfo_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 _appinfo_get_label(const char *appid, const char *locale,
-               label_x **label)
+static int _appinfo_get_label(sqlite3 *db, const char *appid,
+               const char *locale, GList **label)
 {
        static const char query_raw[] =
                "SELECT app_label, app_locale "
@@ -141,11 +225,10 @@ static int _appinfo_get_label(const char *appid, const char *locale,
                return PMINFO_R_ERROR;
        }
 
-       ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
-                       &stmt, NULL);
+       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;
        }
 
@@ -154,21 +237,12 @@ static int _appinfo_get_label(const char *appid, 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);
@@ -176,8 +250,8 @@ static int _appinfo_get_label(const char *appid, const char *locale,
        return PMINFO_R_OK;
 }
 
-static int _appinfo_get_icon(const char *appid, const char *locale,
-               icon_x **icon)
+static int _appinfo_get_icon(sqlite3 *db, const char *appid, const char *locale,
+               GList **icon)
 {
        static const char query_raw[] =
                "SELECT app_icon, app_locale "
@@ -195,11 +269,11 @@ static int _appinfo_get_icon(const char *appid, 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;
        }
 
@@ -208,21 +282,12 @@ static int _appinfo_get_icon(const char *appid, 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);
@@ -230,14 +295,15 @@ static int _appinfo_get_icon(const char *appid, const char *locale,
        return PMINFO_R_OK;
 }
 
-static int _appinfo_get_category(const char *appid, category_x **category)
+static int _appinfo_get_category(sqlite3 *db, const char *appid,
+               GList **category)
 {
        static const char query_raw[] =
                "SELECT category FROM package_app_app_category WHERE app_id=%Q";
        int ret;
        char *query;
        sqlite3_stmt *stmt;
-       category_x *info;
+       const char *val;
 
        query = sqlite3_mprintf(query_raw, appid);
        if (query == NULL) {
@@ -245,32 +311,18 @@ static int _appinfo_get_category(const char *appid, category_x **category)
                return PMINFO_R_ERROR;
        }
 
-       ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
-                       &stmt, NULL);
+       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;
        }
 
        while (sqlite3_step(stmt) == SQLITE_ROW) {
-               info = calloc(1, sizeof(category_x));
-               if (info == NULL) {
-                       LOGE("out of memory");
-                       sqlite3_finalize(stmt);
-                       if (*category) {
-                               LISTHEAD(*category, info);
-                               *category = info;
-                       }
-                       return PMINFO_R_ERROR;
-               }
-               _save_column_str(stmt, 0, &info->name);
-               LISTADD(*category, info);
-       }
-
-       if (*category) {
-               LISTHEAD(*category, info);
-               *category = info;
+               val = NULL;
+               _save_column_str(stmt, 0, &val);
+               if (val)
+                       *category = g_list_append(*category, (gpointer)val);
        }
 
        sqlite3_finalize(stmt);
@@ -278,7 +330,7 @@ static int _appinfo_get_category(const char *appid, category_x **category)
        return PMINFO_R_OK;
 }
 
-static void __parse_appcontrol(appcontrol_x **appcontrol, char *appcontrol_str)
+static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str)
 {
        char *dup;
        char *token;
@@ -304,18 +356,14 @@ static void __parse_appcontrol(appcontrol_x **appcontrol, char *appcontrol_str)
                token = strtok_r(NULL, "|", &ptr);
                if (token && strcmp(token, "NULL"))
                        ac->mime = strdup(token);
-               LISTADD(*appcontrol, ac);
+               *appcontrol = g_list_append(*appcontrol, ac);
        } while ((token = strtok_r(NULL, ";", &ptr)));
 
-       if (*appcontrol) {
-               LISTHEAD(*appcontrol, ac);
-               *appcontrol = ac;
-       }
        free(dup);
 }
 
-static int _appinfo_get_app_control(const char *appid,
-               appcontrol_x **appcontrol)
+static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
+               GList **appcontrol)
 {
        static const char query_raw[] =
                "SELECT app_control FROM package_app_app_control "
@@ -323,7 +371,6 @@ static int _appinfo_get_app_control(const char *appid,
        int ret;
        char *query;
        sqlite3_stmt *stmt;
-       appcontrol_x *info = NULL;
        char *str;
 
        query = sqlite3_mprintf(query_raw, appid);
@@ -332,11 +379,10 @@ static int _appinfo_get_app_control(const char *appid,
                return PMINFO_R_ERROR;
        }
 
-       ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
-                       &stmt, NULL);
+       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;
        }
 
@@ -344,19 +390,17 @@ static int _appinfo_get_app_control(const char *appid,
                str = NULL;
                _save_column_str(stmt, 0, (const char **)&str);
                /* TODO: revise */
-               __parse_appcontrol(&info, str);
+               __parse_appcontrol(appcontrol, str);
                free(str);
        }
 
-       *appcontrol = info;
-
        sqlite3_finalize(stmt);
 
        return PMINFO_R_OK;
 }
 
-static int _appinfo_get_data_control(const char *appid,
-               datacontrol_x **datacontrol)
+static int _appinfo_get_data_control(sqlite3 *db, const char *appid,
+               GList **datacontrol)
 {
        static const char query_raw[] =
                "SELECT providerid, access, type "
@@ -373,11 +417,10 @@ static int _appinfo_get_data_control(const char *appid,
                return PMINFO_R_ERROR;
        }
 
-       ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
-                       &stmt, NULL);
+       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;
        }
 
@@ -386,48 +429,75 @@ static int _appinfo_get_data_control(const char *appid,
                if (info == NULL) {
                        LOGE("out of memory");
                        sqlite3_finalize(stmt);
-                       if (*datacontrol) {
-                               LISTHEAD(*datacontrol, info);
-                               *datacontrol = info;
-                       }
                        return PMINFO_R_ERROR;
                }
                idx = 0;
                _save_column_str(stmt, idx++, &info->providerid);
                _save_column_str(stmt, idx++, &info->access);
                _save_column_str(stmt, idx++, &info->type);
-               LISTADD(*datacontrol, info);
+               *datacontrol = g_list_append(*datacontrol, info);
        }
 
-       if (*datacontrol) {
-               LISTHEAD(*datacontrol, info);
-               *datacontrol = info;
+       sqlite3_finalize(stmt);
+
+       return PMINFO_R_OK;
+}
+
+static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
+               GList **metadata)
+{
+       static const char query_raw[] =
+               "SELECT md_key, md_value "
+               "FROM package_app_app_metadata WHERE app_id=%Q";
+       int ret;
+       char *query;
+       sqlite3_stmt *stmt;
+       int idx;
+       metadata_x *info;
+
+       query = sqlite3_mprintf(query_raw, appid);
+       if (query == NULL) {
+               LOGE("out of memory");
+               return PMINFO_R_ERROR;
+       }
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       sqlite3_free(query);
+       if (ret != SQLITE_OK) {
+               LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               return PMINFO_R_ERROR;
+       }
+
+       while (sqlite3_step(stmt) == SQLITE_ROW) {
+               info = calloc(1, sizeof(metadata_x));
+               if (info == NULL) {
+                       LOGE("out of memory");
+                       sqlite3_finalize(stmt);
+                       return PMINFO_R_ERROR;
+               }
+               idx = 0;
+               _save_column_str(stmt, idx++, &info->key);
+               _save_column_str(stmt, idx++, &info->value);
+               *metadata = g_list_append(*metadata, info);
        }
 
        sqlite3_finalize(stmt);
 
        return PMINFO_R_OK;
+
 }
 
-static int _appinfo_get_app(const char *appid, const char *locale,
-               pkgmgr_appinfo_x **appinfo)
+static int _appinfo_get_splashscreens(sqlite3 *db, const char *appid,
+               GList **splashscreens)
 {
        static const char query_raw[] =
-               "SELECT app_id, app_component, app_exec, app_nodisplay, "
-               "app_type, app_onboot, app_multiple, app_autorestart, "
-               "app_taskmanage, app_enabled, app_hwacceleration, "
-               "app_screenreader, app_mainapp, app_recentimage, "
-               "app_launchcondition, app_indicatordisplay, app_portraitimg, "
-               "app_landscapeimg, app_guestmodevisibility, "
-               "app_permissiontype, app_preload, app_submode, "
-               "app_submode_mainid, app_launch_mode, component_type, package "
-               "FROM package_app_info WHERE app_id=%Q";
+               "SELECT src, type, orientation, indicatordisplay, operation "
+               "FROM package_app_splash_screen WHERE app_id=%Q";
        int ret;
        char *query;
        sqlite3_stmt *stmt;
        int idx;
-       pkgmgr_appinfo_x *info;
-       application_x *app;
+       splashscreen_x *info;
 
        query = sqlite3_mprintf(query_raw, appid);
        if (query == NULL) {
@@ -435,139 +505,309 @@ static int _appinfo_get_app(const char *appid, const char *locale,
                return PMINFO_R_ERROR;
        }
 
-       ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
-                       &stmt, NULL);
+       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;
+       }
+
+       while (sqlite3_step(stmt) == SQLITE_ROW) {
+               info = calloc(1, sizeof(splashscreen_x));
+               if (info == NULL) {
+                       LOGE("out of memory");
+                       sqlite3_finalize(stmt);
+                       return PMINFO_R_ERROR;
+               }
+               idx = 0;
+               _save_column_str(stmt, idx++, &info->src);
+               _save_column_str(stmt, idx++, &info->type);
+               _save_column_str(stmt, idx++, &info->orientation);
+               _save_column_str(stmt, idx++, &info->indicatordisplay);
+               _save_column_str(stmt, idx++, &info->operation);
+               *splashscreens = g_list_append(*splashscreens, info);
+       }
+
+       sqlite3_finalize(stmt);
+
+       return PMINFO_R_OK;
+}
+
+static GList *__get_background_category(char *value)
+{
+       GList *category_list = NULL;
+       int convert_value = 0;
+       if (!value || strlen(value) == 0)
+               return NULL;
+
+       convert_value = atoi(value);
+       if (convert_value < 0)
+               return NULL;
+
+       if (convert_value & APP_BG_CATEGORY_USER_DISABLE_TRUE_VAL)
+               category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_TRUE_STR));
+       else
+               category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_FALSE_STR));
+
+       if (convert_value & APP_BG_CATEGORY_MEDIA_VAL)
+               category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_MEDIA_STR));
+
+       if (convert_value & APP_BG_CATEGORY_DOWNLOAD_VAL)
+               category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_DOWNLOAD_STR));
+
+       if (convert_value & APP_BG_CATEGORY_BGNETWORK_VAL)
+               category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_BGNETWORK_STR));
+
+       if (convert_value & APP_BG_CATEGORY_LOCATION_VAL)
+               category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_LOCATION_STR));
+
+       if (convert_value & APP_BG_CATEGORY_SENSOR_VAL)
+               category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SENSOR_STR));
+
+       if (convert_value & APP_BG_CATEGORY_IOTCOMM_VAL)
+               category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_IOTCOMM_STR));
+
+       if (convert_value & APP_BG_CATEGORY_SYSTEM_VAL)
+               category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SYSTEM));
+
+       return category_list;
+
+}
+
+static int _appinfo_get_application(sqlite3 *db, const char *appid,
+               const char *locale, application_x **application, bool is_disabled)
+{
+       static const char query_raw[] =
+               "SELECT app_id, app_component, app_exec, app_nodisplay, "
+               "app_type, app_onboot, app_multiple, app_autorestart, "
+               "app_taskmanage, app_enabled, app_hwacceleration, "
+               "app_screenreader, app_mainapp, app_recentimage, "
+               "app_launchcondition, app_indicatordisplay, app_portraitimg, "
+               "app_landscapeimg, app_guestmodevisibility, "
+               "app_permissiontype, app_preload, app_submode, "
+               "app_submode_mainid, app_launch_mode, app_ui_gadget, "
+               "app_support_disable, "
+               "component_type, package, app_process_pool, app_installed_storage, "
+               "app_background_category, app_package_type "
+               "FROM package_app_info WHERE app_id='%s' "
+               "AND (app_disable='%s' "
+               "%s app_id %s IN "
+               "(SELECT app_id from package_app_disable_for_user WHERE uid='%d'))";
+       int ret;
+       char query[MAX_QUERY_LEN] = { '\0' };
+       sqlite3_stmt *stmt;
+       int idx;
+       application_x *info;
+       char *bg_category_str = NULL;
+       snprintf(query, MAX_QUERY_LEN - 1, query_raw,
+                       appid,
+                       is_disabled ? "true" : "false",
+                       is_disabled ? "OR" : "AND",
+                       is_disabled ? "" : "NOT",
+                       (int)getuid());
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               LOGE("prepare failed: %s", sqlite3_errmsg(db));
                return PMINFO_R_ERROR;
        }
 
        ret = sqlite3_step(stmt);
        if (ret == SQLITE_DONE) {
-               LOGE("cannot find app");
                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;
        }
 
-       app = calloc(1, sizeof(application_x));
-       if (app == NULL) {
+       info = calloc(1, sizeof(application_x));
+       if (info == NULL) {
                LOGE("out of memory");
                sqlite3_finalize(stmt);
                return PMINFO_R_ERROR;
        }
        idx = 0;
-       _save_column_str(stmt, idx++, &app->appid);
-       _save_column_str(stmt, idx++, &app->component);
-       _save_column_str(stmt, idx++, &app->exec);
-       _save_column_str(stmt, idx++, &app->nodisplay);
-       _save_column_str(stmt, idx++, &app->type);
-       _save_column_str(stmt, idx++, &app->onboot);
-       _save_column_str(stmt, idx++, &app->multiple);
-       _save_column_str(stmt, idx++, &app->autorestart);
-       _save_column_str(stmt, idx++, &app->taskmanage);
-       _save_column_str(stmt, idx++, &app->enabled);
-       _save_column_str(stmt, idx++, &app->hwacceleration);
-       _save_column_str(stmt, idx++, &app->screenreader);
-       _save_column_str(stmt, idx++, &app->mainapp);
-       _save_column_str(stmt, idx++, &app->recentimage);
-       _save_column_str(stmt, idx++, &app->launchcondition);
-       _save_column_str(stmt, idx++, &app->indicatordisplay);
-       _save_column_str(stmt, idx++, &app->portraitimg);
-       _save_column_str(stmt, idx++, &app->landscapeimg);
-       _save_column_str(stmt, idx++, &app->guestmode_visibility);
-       _save_column_str(stmt, idx++, &app->permission_type);
-       _save_column_str(stmt, idx++, &app->preload);
-       _save_column_str(stmt, idx++, &app->submode);
-       _save_column_str(stmt, idx++, &app->submode_mainid);
-       _save_column_str(stmt, idx++, &app->launch_mode);
-       _save_column_str(stmt, idx++, &app->component_type);
-       _save_column_str(stmt, idx++, &app->package);
-
-       if (_appinfo_get_label(app->appid, locale, &app->label)) {
-               pkgmgrinfo_basic_free_application(app);
+       _save_column_str(stmt, idx++, &info->appid);
+       _save_column_str(stmt, idx++, &info->component);
+       _save_column_str(stmt, idx++, &info->exec);
+       _save_column_str(stmt, idx++, &info->nodisplay);
+       _save_column_str(stmt, idx++, &info->type);
+       _save_column_str(stmt, idx++, &info->onboot);
+       _save_column_str(stmt, idx++, &info->multiple);
+       _save_column_str(stmt, idx++, &info->autorestart);
+       _save_column_str(stmt, idx++, &info->taskmanage);
+       _save_column_str(stmt, idx++, &info->enabled);
+       _save_column_str(stmt, idx++, &info->hwacceleration);
+       _save_column_str(stmt, idx++, &info->screenreader);
+       _save_column_str(stmt, idx++, &info->mainapp);
+       _save_column_str(stmt, idx++, &info->recentimage);
+       _save_column_str(stmt, idx++, &info->launchcondition);
+       _save_column_str(stmt, idx++, &info->indicatordisplay);
+       _save_column_str(stmt, idx++, &info->portraitimg);
+       _save_column_str(stmt, idx++, &info->landscapeimg);
+       _save_column_str(stmt, idx++, &info->guestmode_visibility);
+       _save_column_str(stmt, idx++, &info->permission_type);
+       _save_column_str(stmt, idx++, &info->preload);
+       _save_column_str(stmt, idx++, &info->submode);
+       _save_column_str(stmt, idx++, &info->submode_mainid);
+       _save_column_str(stmt, idx++, &info->launch_mode);
+       _save_column_str(stmt, idx++, &info->ui_gadget);
+       _save_column_str(stmt, idx++, &info->support_disable);
+       _save_column_str(stmt, idx++, &info->component_type);
+       _save_column_str(stmt, idx++, &info->package);
+       _save_column_str(stmt, idx++, &info->process_pool);
+       _save_column_str(stmt, idx++, &info->installed_storage);
+       _save_column_str(stmt, idx++, &bg_category_str);
+       _save_column_str(stmt, idx++, &info->package_type);
+
+       info->background_category = __get_background_category(bg_category_str);
+
+       if (_appinfo_get_label(db, info->appid, locale, &info->label)) {
+               pkgmgrinfo_basic_free_application(info);
                sqlite3_finalize(stmt);
                return PMINFO_R_ERROR;
        }
 
-       if (_appinfo_get_icon(app->appid, locale, &app->icon)) {
-               pkgmgrinfo_basic_free_application(app);
+       if (_appinfo_get_icon(db, info->appid, locale, &info->icon)) {
+               pkgmgrinfo_basic_free_application(info);
                sqlite3_finalize(stmt);
                return PMINFO_R_ERROR;
        }
 
-       if (_appinfo_get_category(app->appid, &app->category)) {
-               pkgmgrinfo_basic_free_application(app);
+       if (_appinfo_get_category(db, info->appid, &info->category)) {
+               pkgmgrinfo_basic_free_application(info);
                sqlite3_finalize(stmt);
                return PMINFO_R_ERROR;
        }
 
-       if (_appinfo_get_app_control(app->appid, &app->appcontrol)) {
-               pkgmgrinfo_basic_free_application(app);
+       if (_appinfo_get_app_control(db, info->appid, &info->appcontrol)) {
+               pkgmgrinfo_basic_free_application(info);
                sqlite3_finalize(stmt);
                return PMINFO_R_ERROR;
        }
 
-       if (_appinfo_get_data_control(app->appid, &app->datacontrol)) {
-               pkgmgrinfo_basic_free_application(app);
+       if (_appinfo_get_data_control(db, info->appid, &info->datacontrol)) {
+               pkgmgrinfo_basic_free_application(info);
                sqlite3_finalize(stmt);
                return PMINFO_R_ERROR;
        }
 
-       info = calloc(1, sizeof(pkgmgr_appinfo_x));
-       if (info == NULL) {
-               LOGE("out of memory");
-               pkgmgrinfo_basic_free_application(app);
+       if (_appinfo_get_metadata(db, info->appid, &info->metadata)) {
+               pkgmgrinfo_basic_free_application(info);
                sqlite3_finalize(stmt);
                return PMINFO_R_ERROR;
        }
 
-       info->package = strdup(app->package);
-       info->app_info = app;
-       info->locale = strdup(locale);
-       *appinfo = info;
+       if (_appinfo_get_splashscreens(db, info->appid, &info->splashscreens)) {
+               pkgmgrinfo_basic_free_application(info);
+               sqlite3_finalize(stmt);
+               return PMINFO_R_ERROR;
+       }
+
+       *application = info;
 
        sqlite3_finalize(stmt);
 
        return PMINFO_R_OK;
 }
 
-API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
-               pkgmgrinfo_appinfo_h *handle)
+static int _appinfo_get_appinfo(const char *appid, uid_t uid,
+               pkgmgr_appinfo_x **appinfo, bool is_disabled)
 {
-       pkgmgr_appinfo_x *appinfo = NULL;
+       int ret;
+       sqlite3 *db;
+       const char *dbpath;
        char *locale;
+       pkgmgr_appinfo_x *info;
 
-       if (appid == 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 (_appinfo_get_app(appid, locale, &appinfo)) {
+       info = calloc(1, sizeof(pkgmgr_appinfo_x));
+       if (info == NULL) {
+               _LOGE("out of memory");
                free(locale);
-               __close_manifest_db();
+               sqlite3_close_v2(db);
                return PMINFO_R_ERROR;
        }
 
-       *handle = appinfo;
+       ret = _appinfo_get_application(db, appid, locale, &info->app_info, is_disabled);
+       if (ret != PMINFO_R_OK) {
+               free(info);
+               free(locale);
+               sqlite3_close_v2(db);
+               return ret;
+       }
+
+       info->locale = locale;
+       info->package = strdup(info->app_info->package);
 
-       free(locale);
-       __close_manifest_db();
+       *appinfo = info;
 
-       return PMINFO_R_OK;
+       sqlite3_close_v2(db);
+
+       return ret;
+}
+
+API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid,
+               pkgmgrinfo_appinfo_h *handle)
+{
+       int ret;
+
+       if (appid == NULL || handle == NULL) {
+               LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle, true);
+       if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
+               ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
+                               (pkgmgr_appinfo_x **)handle, true);
+
+       if (ret != PMINFO_R_OK)
+               _LOGE("failed to get appinfo of %s for user %d", appid, uid);
+
+       return ret;
+}
+
+API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
+{
+       return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, GLOBAL_USER, handle);
+}
+
+API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
+               pkgmgrinfo_appinfo_h *handle)
+{
+       int ret;
+
+       if (appid == NULL || handle == NULL) {
+               LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle, false);
+       if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
+               ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
+                               (pkgmgr_appinfo_x **)handle, false);
+
+       if (ret != PMINFO_R_OK)
+               _LOGE("failed to get appinfo of %s for user %d", appid, uid);
+
+       return ret;
 }
 
 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
@@ -575,37 +815,365 @@ API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *
        return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
 }
 
+static gpointer __copy_str(gconstpointer src, gpointer data)
+{
+       const char *tmp = (const char *)src;
+       const char *buffer;
+
+       buffer = strdup(tmp);
+       if (buffer == NULL) {
+               LOGE("memory alloc failed");
+               *(int *)data = -1;
+               return NULL;
+       }
+
+       return buffer;
+}
+
+static gpointer __copy_label(gconstpointer src, gpointer data)
+{
+       label_x *tmp = (label_x *)src;
+       label_x *label;
+
+       label = calloc(1, sizeof(label_x));
+       if (label == NULL) {
+               LOGE("memory alloc failed");
+               *(int *)data = -1;
+               return NULL;
+       }
+
+       if (tmp->name)
+               label->name = strdup(tmp->name);
+       if (tmp->text)
+               label->text = strdup(tmp->text);
+       if (tmp->lang)
+               label->lang = strdup(tmp->lang);
+
+       return label;
+}
+
+static gpointer __copy_icon(gconstpointer src, gpointer data)
+{
+       icon_x *tmp = (icon_x *)src;
+       icon_x *icon;
+
+       icon = calloc(1, sizeof(icon_x));
+       if (icon== NULL) {
+               LOGE("memory alloc failed");
+               *(int *)data = -1;
+               return NULL;
+       }
+
+       if (tmp->text)
+               icon->text = strdup(tmp->text);
+       if (tmp->lang)
+               icon->lang = strdup(tmp->lang);
+       if (tmp->section)
+               icon->section = strdup(tmp->section);
+       if (tmp->size)
+               icon->size = strdup(tmp->size);
+       if (tmp->resolution)
+               icon->resolution = strdup(tmp->resolution);
+
+       return icon;
+}
+
+static gpointer __copy_metadata(gconstpointer src, gpointer data)
+{
+       metadata_x *tmp = (metadata_x *)src;
+       metadata_x *metadata;
+
+       metadata = calloc(1, sizeof(metadata_x));
+       if (metadata == NULL) {
+               LOGE("memory alloc failed");
+               *(int *)data = -1;
+               return NULL;
+       }
+
+       if (tmp->key)
+               metadata->key = strdup(tmp->key);
+       if (tmp->value)
+               metadata->value = strdup(tmp->value);
+
+       return metadata;
+}
+
+static gpointer __copy_datacontrol(gconstpointer src, gpointer data)
+{
+       datacontrol_x *tmp = (datacontrol_x *)src;
+       datacontrol_x *datacontrol;
+
+       datacontrol = calloc(1, sizeof(datacontrol_x));
+       if (datacontrol == NULL) {
+               LOGE("memory alloc failed");
+               *(int *)data = -1;
+               return NULL;
+       }
+
+       if (tmp->providerid)
+               datacontrol->providerid = strdup(tmp->providerid);
+       if (tmp->access)
+               datacontrol->access = strdup(tmp->access);
+       if (tmp->type)
+               datacontrol->type = strdup(tmp->type);
+
+       return datacontrol;
+}
+
+static gpointer __copy_appcontrol(gconstpointer src, gpointer data)
+{
+       appcontrol_x *tmp = (appcontrol_x *)src;
+       appcontrol_x *appcontrol;
+
+       appcontrol = calloc(1, sizeof(appcontrol_x));
+       if (appcontrol ==NULL) {
+               LOGE("memory alloc failed");
+               *(int *)data = -1;
+               return NULL;
+       }
+
+       if (tmp->operation)
+               appcontrol->operation = strdup(tmp->operation);
+       if (tmp->uri)
+               appcontrol->uri = strdup(tmp->uri);
+       if (tmp->mime)
+               appcontrol->mime = strdup(tmp->mime);
+
+       return appcontrol;
+}
+
+static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
+{
+       splashscreen_x *tmp = (splashscreen_x *)src;
+       splashscreen_x *splashscreen;
+
+       splashscreen = (splashscreen_x *)calloc(1, sizeof(splashscreen_x));
+       if (splashscreen == NULL) {
+               LOGE("memory alloc failed");
+               *(int *)data = -1;
+               return NULL;
+       }
+
+       if (tmp->src)
+               splashscreen->src = strdup(tmp->src);
+       if (tmp->type)
+               splashscreen->type = strdup(tmp->type);
+       if (tmp->orientation)
+               splashscreen->orientation = strdup(tmp->orientation);
+       if (tmp->indicatordisplay)
+               splashscreen->indicatordisplay = strdup(tmp->indicatordisplay);
+       if (tmp->operation)
+               splashscreen->operation = strdup(tmp->operation);
+
+       return splashscreen;
+}
+
+static int _appinfo_copy_appinfo(application_x **application, application_x *data)
+{
+       application_x *app_info;
+       int ret;
+
+       app_info = calloc(1, sizeof(application_x));
+       if (app_info == NULL) {
+               LOGE("memory alloc failed");
+               return PMINFO_R_ERROR;
+       }
+
+       if (data->appid != NULL)
+               app_info->appid = strdup(data->appid);
+       if (data->exec != NULL)
+               app_info->exec = strdup(data->exec);
+       if (data->nodisplay != NULL)
+               app_info->nodisplay = strdup(data->nodisplay);
+       if (data->multiple != NULL)
+               app_info->multiple = strdup(data->multiple);
+       if (data->taskmanage != NULL)
+               app_info->taskmanage = strdup(data->taskmanage);
+       if (data->enabled != NULL)
+               app_info->enabled = strdup(data->enabled);
+       if (data->type != NULL)
+               app_info->type = strdup(data->type);
+       if (data->categories != NULL)
+               app_info->categories = strdup(data->categories);
+       if (data->hwacceleration != NULL)
+               app_info->hwacceleration = strdup(data->hwacceleration);
+       if (data->screenreader != NULL)
+               app_info->screenreader = strdup(data->screenreader);
+       if (data->mainapp != NULL)
+               app_info->mainapp = strdup(data->mainapp);
+       if (data->package != NULL)
+               app_info->package = strdup(data->package);
+       if (data->recentimage != NULL)
+               app_info->recentimage = strdup(data->recentimage);
+       if (data->launchcondition != NULL)
+               app_info->launchcondition = strdup(data->launchcondition);
+       if (data->indicatordisplay != NULL)
+               app_info->indicatordisplay = strdup(data->indicatordisplay);
+       if (data->portraitimg != NULL)
+               app_info->portraitimg = strdup(data->portraitimg);
+       if (data->landscapeimg != NULL)
+               app_info->landscapeimg = strdup(data->landscapeimg);
+       if (data->guestmode_visibility != NULL)
+               app_info->guestmode_visibility = strdup(data->guestmode_visibility);
+       if (data->component != NULL)
+               app_info->component = strdup(data->component);
+       if (data->permission_type != NULL)
+               app_info->permission_type = strdup(data->permission_type);
+       if (data->component_type != NULL)
+               app_info->component_type = strdup(data->component_type);
+       if (data->preload != NULL)
+               app_info->preload = strdup(data->preload);
+       if (data->submode != NULL)
+               app_info->submode = strdup(data->submode);
+       if (data->submode_mainid != NULL)
+               app_info->submode_mainid = strdup(data->submode_mainid);
+       if (data->process_pool != NULL)
+               app_info->process_pool = strdup(data->process_pool);
+       if (data->installed_storage != NULL)
+               app_info->installed_storage = strdup(data->installed_storage);
+       if (data->autorestart != NULL)
+               app_info->autorestart = strdup(data->autorestart);
+       if (data->onboot != NULL)
+               app_info->onboot = strdup(data->onboot);
+       if (data->support_disable != NULL)
+               app_info->support_disable = strdup(data->support_disable);
+       if (data->ui_gadget != NULL)
+               app_info->ui_gadget = strdup(data->ui_gadget);
+       if (data->launch_mode != NULL)
+               app_info->launch_mode = strdup(data->launch_mode);
+       if (data->package_type != NULL)
+               app_info->package_type = strdup(data->package_type);
+
+       /* GList */
+       ret = 0;
+       app_info->label = g_list_copy_deep(data->label, __copy_label, &ret);
+       if (ret < 0) {
+               LOGE("memory alloc failed");
+               pkgmgrinfo_basic_free_application(app_info);
+               return PMINFO_R_ERROR;
+       }
+
+       ret = 0;
+       app_info->icon = g_list_copy_deep(data->icon, __copy_icon, &ret);
+       if (ret < 0) {
+               LOGE("memory alloc failed");
+               pkgmgrinfo_basic_free_application(app_info);
+               return PMINFO_R_ERROR;
+       }
+
+       ret = 0;
+       app_info->category = g_list_copy_deep(data->category, __copy_str, &ret);
+       if (ret < 0) {
+               LOGE("memory alloc failed");
+               pkgmgrinfo_basic_free_application(app_info);
+               return PMINFO_R_ERROR;
+       }
+
+       ret = 0;
+       app_info->metadata = g_list_copy_deep(data->metadata, __copy_metadata, &ret);
+       if (ret < 0) {
+               LOGE("memory alloc failed");
+               pkgmgrinfo_basic_free_application(app_info);
+               return PMINFO_R_ERROR;
+       }
+
+       ret = 0;
+       app_info->datacontrol = g_list_copy_deep(data->datacontrol, __copy_datacontrol, &ret);
+       if (ret < 0) {
+               LOGE("memory alloc failed");
+               pkgmgrinfo_basic_free_application(app_info);
+               return PMINFO_R_ERROR;
+       }
+
+       ret = 0;
+       app_info->appcontrol = g_list_copy_deep(data->appcontrol, __copy_appcontrol, &ret);
+       if (ret < 0) {
+               LOGE("memory alloc failed");
+               pkgmgrinfo_basic_free_application(app_info);
+               return PMINFO_R_ERROR;
+       }
+
+       ret = 0;
+       app_info->background_category = g_list_copy_deep(data->background_category, __copy_str, &ret);
+       if (ret < 0) {
+               LOGE("memory alloc failed");
+               pkgmgrinfo_basic_free_application(app_info);
+               return PMINFO_R_ERROR;
+       }
+
+       ret = 0;
+       app_info->splashscreens = g_list_copy_deep(data->splashscreens, __copy_splashscreens, &ret);
+       if (ret < 0) {
+               LOGE("memory alloc failed");
+               pkgmgrinfo_basic_free_application(app_info);
+               return PMINFO_R_ERROR;
+       }
+
+       *application = app_info;
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h handle,
+               pkgmgrinfo_appinfo_h *clone)
+{
+       pkgmgr_appinfo_x *info;
+       pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
+
+       if (handle == NULL)
+               return PMINFO_R_EINVAL;
+
+       info = calloc(1, sizeof(pkgmgr_appinfo_x));
+       if (info == NULL) {
+               LOGE("memory alloc failed");
+               return PMINFO_R_ERROR;
+       }
+
+       if (temp->package != NULL)
+               info->package = strdup(temp->package);
+       if (temp->locale != NULL)
+               info->locale = strdup(temp->locale);
+
+       info->app_component = temp->app_component;
+
+       if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
+               LOGE("appinfo copy failed");
+               if (info->package)
+                       free((void *)info->package);
+               if (info->locale)
+                       free(info->locale);
+               free(info);
+               return PMINFO_R_ERROR;
+       }
+
+       *clone = info;
+
+       return PMINFO_R_OK;
+}
+
 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
                pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
                void *user_data)
 {
+       int ret;
        pkgmgr_appinfo_x *info;
-       GSList *list;
-       GSList *tmp;
+       GList *list = NULL;
+       GList *tmp;
        char *appid;
-       char *locale;
        int stop = 0;
 
-       if (__open_manifest_db(uid) < 0)
+       ret = _appinfo_get_filtered_list(filter, uid, &list);
+       if (ret != PMINFO_R_OK)
                return PMINFO_R_ERROR;
 
-       locale = _get_system_locale();
-       if (locale == NULL) {
-               __close_manifest_db();
-               return PMINFO_R_ERROR;
-       }
-
-       list = _appinfo_get_filtered_list(locale, filter);
-       if (list == NULL) {
-               free(locale);
-               __close_manifest_db();
-               return PMINFO_R_OK;
-       }
-
        for (tmp = list; tmp; tmp = tmp->next) {
                appid = (char *)tmp->data;
                if (stop == 0) {
-                       if (_appinfo_get_app(appid, locale, &info)) {
+                       ret = _appinfo_get_appinfo(appid, uid, &info, false);
+                       if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
+                               ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
+                                               &info, false);
+                       if (ret != PMINFO_R_OK) {
                                free(appid);
                                continue;
                        }
@@ -616,9 +1184,7 @@ static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
                free(appid);
        }
 
-       free(locale);
-       g_slist_free(list);
-       __close_manifest_db();
+       g_list_free(list);
 
        return PMINFO_R_OK;
 }
@@ -633,7 +1199,7 @@ API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
        const char *comp_str = NULL;
 
        if (handle == NULL || app_func == NULL) {
-               LOGE("invalied parameter");
+               LOGE("invalid parameter");
                return PMINFO_R_EINVAL;
        }
 
@@ -651,6 +1217,13 @@ API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
                return PMINFO_R_ERROR;
        }
 
+       if (uid == GLOBAL_USER) {
+               if (pkgmgrinfo_appinfo_filter_add_int(filter,
+                                       PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER, (int)getuid())) {
+                       pkgmgrinfo_appinfo_filter_destroy(filter);
+                       return PMINFO_R_ERROR;
+               }
+       }
 
        switch (component) {
        case PMINFO_UI_APP:
@@ -762,6 +1335,17 @@ API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h  handle, char **pkgtype)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+
+       *pkgtype = (char *)info->app_info->package_type;
+
+       return PMINFO_R_OK;
+}
+
 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
 {
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
@@ -779,9 +1363,9 @@ API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
 
 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
 {
-        char *locale;
+        const char *locale;
         icon_x *ptr;
-        icon_x *start;
+        GList *tmp;
         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
@@ -790,23 +1374,27 @@ API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
        locale = info->locale;
        retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
 
-       start = info->app_info->icon;
-       for (ptr = start; ptr != NULL; ptr = ptr->next) {
-               if (ptr->lang == NULL)
+       if (info->app_info == NULL)
+               return PMINFO_R_ERROR;
+
+       for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
+               ptr = (icon_x *)tmp->data;
+               if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
+                               !strcasecmp(ptr->text, "") ||
+                               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->app_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;
@@ -815,9 +1403,9 @@ API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
 
 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
 {
-       char *locale;
+       const char *locale;
        label_x *ptr;
-       label_x *start;
+       GList *tmp;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
@@ -826,23 +1414,26 @@ API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
        locale = info->locale;
        retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
 
-       start = info->app_info->label;
-       for (ptr = start; ptr != NULL; ptr = ptr->next) {
-               if (ptr->lang == NULL)
+       if (info->app_info == NULL)
+               return PMINFO_R_ERROR;
+
+       for (tmp = info->app_info->label; tmp; 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->app_info->label; tmp; 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;
@@ -918,10 +1509,14 @@ API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *loca
 
 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
 {
-       if ( strcasecmp(comp, "uiapp") == 0)
+       if (strcasecmp(comp, "uiapp") == 0)
                return PMINFO_UI_APP;
-       else if ( strcasecmp(comp, "svcapp") == 0)
+       else if (strcasecmp(comp, "svcapp") == 0)
                return PMINFO_SVC_APP;
+       else if (strcasecmp(comp, "widgetapp") == 0)
+               return PMINFO_WIDGET_APP;
+       else if (strcasecmp(comp, "watchapp") == 0)
+               return PMINFO_WATCH_APP;
        else
                return -1;
 }
@@ -1012,13 +1607,18 @@ API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **
 {
        char *val;
        icon_x *ptr;
+       GList *tmp;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
        retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
 
-       for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
-               if (ptr->section == NULL)
+       if (info->app_info == NULL)
+               return PMINFO_R_ERROR;
+
+       for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
+               ptr = (icon_x *)tmp->data;
+               if (ptr == NULL || ptr->section == NULL)
                        continue;
 
                val = (char *)ptr->section;
@@ -1036,13 +1636,18 @@ API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, ch
 {
        char *val;
        icon_x *ptr;
+       GList *tmp;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
        retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
 
-       for (ptr = info->app_info->icon; ptr != NULL; ptr = ptr->next) {
-               if (ptr->section == NULL)
+       if (info->app_info == NULL)
+               return PMINFO_R_ERROR;
+
+       for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
+               ptr = (icon_x *)tmp->data;
+               if (ptr == NULL || ptr->section == NULL)
                        continue;
 
                val = (char *)ptr->section;
@@ -1081,13 +1686,18 @@ API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char *
 {
        char *val;
        image_x *ptr;
+       GList *tmp;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
        retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
 
-       for (ptr = info->app_info->image; ptr != NULL; ptr = ptr->next) {
-               if (ptr->section == NULL)
+       if (info->app_info == NULL)
+               return PMINFO_R_ERROR;
+
+       for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
+               ptr = (image_x *)tmp->data;
+               if (ptr == NULL || ptr->section == NULL)
                        continue;
 
                val = (char *)ptr->section;
@@ -1189,8 +1799,8 @@ API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **p
        retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
        retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
 
-       if (info->app_info == NULL || info->app_info->portraitimg ||
-                       info->app_info->landscapeimg == NULL)
+       if (info->app_info == NULL || (info->app_info->portraitimg == NULL
+                       && info->app_info->landscapeimg == NULL))
                return PMINFO_R_ERROR;
 
        *portrait_img = (char *)info->app_info->portraitimg;
@@ -1199,6 +1809,23 @@ API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **p
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
+{
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+
+       if (handle == NULL || effectimage_type == NULL) {
+               LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
+               return PMINFO_R_ERROR;
+
+       *effectimage_type = (char *)info->app_info->effectimage_type;
+
+       return PMINFO_R_OK;
+}
+
 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h  handle, char **submode_mainid)
 {
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
@@ -1214,6 +1841,24 @@ API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h  handle, char
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+
+       if (info->app_info && info->app_info->installed_storage){
+                if (strcmp(info->app_info->installed_storage,"installed_internal") == 0)
+                       *storage = PMINFO_INTERNAL_STORAGE;
+                else if (strcmp(info->app_info->installed_storage,"installed_external") == 0)
+                        *storage = PMINFO_EXTERNAL_STORAGE;
+                else
+                        return PMINFO_R_ERROR;
+       }else
+               return PMINFO_R_ERROR;
+
+       return PMINFO_R_OK;
+}
+
 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
 {
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
@@ -1229,6 +1874,40 @@ API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **m
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
+{
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+
+       if (handle == NULL || alias_appid == NULL) {
+               LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       if (info->app_info == NULL || info->app_info->alias_appid == NULL)
+               return PMINFO_R_ERROR;
+
+       *alias_appid = (char *)info->app_info->alias_appid;
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
+{
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+
+       if (handle == NULL || effective_appid == NULL) {
+               LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       if (info->app_info == NULL || info->app_info->effective_appid == NULL)
+               return PMINFO_R_ERROR;
+
+       *effective_appid = (char *)info->app_info->effective_appid;
+
+       return PMINFO_R_OK;
+}
+
 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
 {
        retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
@@ -1241,7 +1920,7 @@ API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, cons
        sqlite3_stmt *stmt = NULL;
 
        /*open db*/
-       ret = __open_manifest_db(uid);
+       ret = __open_manifest_db(uid, true);
        retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
 
        /*Start constructing query*/
@@ -1282,7 +1961,7 @@ API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid
        sqlite3_stmt *stmt = NULL;
 
        /*open db*/
-       ret = __open_manifest_db(uid);
+       ret = __open_manifest_db(uid, true);
        retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
 
        /*Start constructing query*/
@@ -1318,13 +1997,17 @@ API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
        retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
        int ret = -1;
-       permission_x *ptr = NULL;
+       permission_x *ptr;
+       GList *tmp;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
        if (info->app_info == NULL)
                return PMINFO_R_ERROR;
 
-       for (ptr = info->app_info->permission; ptr; ptr = ptr->next) {
+       for (tmp = info->app_info->permission; tmp; tmp = tmp->next) {
+               ptr = (permission_x *)tmp->data;
+               if (ptr == NULL)
+                       continue;
                if (ptr->value) {
                        ret = permission_func(ptr->value, user_data);
                        if (ret < 0)
@@ -1340,15 +2023,17 @@ API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
        retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
        int ret = -1;
-       category_x *ptr = NULL;
+       const char *category;
+       GList *tmp;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
        if (info->app_info == NULL)
                return PMINFO_R_ERROR;
 
-       for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
-               if (ptr->name) {
-                       ret = category_func(ptr->name, user_data);
+       for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
+               category = (const char *)tmp->data;
+               if (category) {
+                       ret = category_func(category, user_data);
                        if (ret < 0)
                                break;
                }
@@ -1362,13 +2047,17 @@ API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
        retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
        int ret = -1;
-       metadata_x *ptr = NULL;
+       metadata_x *ptr;
+       GList *tmp;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
        if (info->app_info == NULL)
                return PMINFO_R_ERROR;
 
-       for (ptr = info->app_info->metadata; ptr; ptr = ptr->next) {
+       for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
+               ptr = (metadata_x *)tmp->data;
+               if (ptr == NULL)
+                       continue;
                if (ptr->key) {
                        ret = metadata_func(ptr->key, ptr->value, user_data);
                        if (ret < 0)
@@ -1386,11 +2075,15 @@ API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
        int ret;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
        appcontrol_x *appcontrol;
+       GList *tmp;
 
-       if (info->uiapp_info == NULL)
+       if (info->app_info == NULL)
                return PMINFO_R_ERROR;
 
-       for (appcontrol = info->app_info->appcontrol; appcontrol; appcontrol = appcontrol->next) {
+       for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
+               appcontrol = (appcontrol_x *)tmp->data;
+               if (appcontrol == NULL)
+                       continue;
                ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
                if (ret < 0)
                        break;
@@ -1399,25 +2092,75 @@ API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_appinfo_foreach_background_category(
+               pkgmgrinfo_appinfo_h handle,
+               pkgmgrinfo_app_background_category_list_cb category_func,
+               void *user_data)
+{
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+       GList *tmp;
+       char *category;
+
+       if (handle == NULL || category_func == NULL || info->app_info == NULL) {
+               LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
+               category = (char *)tmp->data;
+               if (category == NULL)
+                       continue;
+
+               if (category_func(category, user_data) < 0)
+                       break;
+       }
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
+               pkgmgrinfo_app_splash_screen_list_cb splash_screen_func,
+               void *user_data)
+{
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+       splashscreen_x *splashscreen;
+       GList *tmp;
+       int ret;
+
+       if (info == NULL || info->app_info == NULL
+                       || splash_screen_func == NULL) {
+               LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) {
+               splashscreen = (splashscreen_x *)tmp->data;
+               if (splashscreen == NULL)
+                       continue;
+               ret = splash_screen_func(splashscreen->src,
+                               splashscreen->type,
+                               splashscreen->orientation,
+                               splashscreen->indicatordisplay,
+                               splashscreen->operation,
+                               user_data);
+               if (ret < 0)
+                       break;
+       }
+
+       return PMINFO_R_OK;
+}
+
 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
        retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
-       char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
-       if (info->app_info == NULL)
+       if (info->app_info == NULL || info->app_info->nodisplay == NULL)
                return PMINFO_R_ERROR;
 
-       val = (char *)info->app_info->nodisplay;
-       if (val) {
-               if (strcasecmp(val, "true") == 0)
-                       *nodisplay = 1;
-               else if (strcasecmp(val, "false") == 0)
-                       *nodisplay = 0;
-               else
-                       *nodisplay = 0;
-       }
+       *nodisplay = _get_bool_value(info->app_info->nodisplay);
+
        return PMINFO_R_OK;
 }
 
@@ -1425,21 +2168,13 @@ API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multip
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
        retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
-       char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
-       if (info->app_info == NULL)
+       if (info->app_info == NULL || info->app_info->multiple == NULL)
                return PMINFO_R_ERROR;
 
-       val = (char *)info->app_info->multiple;
-       if (val) {
-               if (strcasecmp(val, "true") == 0)
-                       *multiple = 1;
-               else if (strcasecmp(val, "false") == 0)
-                       *multiple = 0;
-               else
-                       *multiple = 0;
-       }
+       *multiple = _get_bool_value(info->app_info->multiple);
+
        return PMINFO_R_OK;
 }
 
@@ -1447,22 +2182,13 @@ API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h han
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
        retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
-       char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
-       if (info->app_info == NULL)
+       if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
                return PMINFO_R_ERROR;
 
-       val = (char *)info->app_info->indicatordisplay;
-       if (val) {
-               if (strcasecmp(val, "true") == 0){
-                       *indicator_disp = 1;
-               }else if (strcasecmp(val, "false") == 0){
-                       *indicator_disp = 0;
-               }else{
-                       *indicator_disp = 0;
-               }
-       }
+       *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
+
        return PMINFO_R_OK;
 }
 
@@ -1470,21 +2196,13 @@ API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h  handle, bool *tas
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
        retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
-       char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
-       if (info->app_info == NULL)
+       if (info->app_info == NULL || info->app_info->taskmanage == NULL)
                return PMINFO_R_ERROR;
 
-       val = (char *)info->app_info->taskmanage;
-       if (val) {
-               if (strcasecmp(val, "true") == 0)
-                       *taskmanage = 1;
-               else if (strcasecmp(val, "false") == 0)
-                       *taskmanage = 0;
-               else
-                       *taskmanage = 0;
-       }
+       *taskmanage = _get_bool_value(info->app_info->taskmanage);
+
        return PMINFO_R_OK;
 }
 
@@ -1492,44 +2210,27 @@ API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h  handle, bool *enable
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
        retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
-       char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
-       if (info->app_info == NULL)
+       if (info->app_info == NULL || info->app_info->enabled == NULL)
                return PMINFO_R_ERROR;
 
-       val = (char *)info->app_info->enabled;
-       if (val) {
-               if (strcasecmp(val, "true") == 0)
-                       *enabled = 1;
-               else if (strcasecmp(val, "false") == 0)
-                       *enabled = 0;
-               else
-                       *enabled = 1;
-       }
-       return PMINFO_R_OK;
+       *enabled = _get_bool_value(info->app_info->enabled);
 
+       return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h  handle, bool *onboot)
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
        retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
-       char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
-       if (info->app_info == NULL)
+       if (info->app_info == NULL || info->app_info->onboot == NULL)
                return PMINFO_R_ERROR;
 
-       val = (char *)info->app_info->onboot;
-       if (val) {
-               if (strcasecmp(val, "true") == 0)
-                       *onboot = 1;
-               else if (strcasecmp(val, "false") == 0)
-                       *onboot = 0;
-               else
-                       *onboot = 0;
-       }
+       *onboot = _get_bool_value(info->app_info->onboot);
+
        return PMINFO_R_OK;
 }
 
@@ -1537,21 +2238,13 @@ API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h  handle, bool *au
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
        retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
-       char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
-       if (info->app_info == NULL)
+       if (info->app_info == NULL || info->app_info->autorestart == NULL)
                return PMINFO_R_ERROR;
 
-       val = (char *)info->app_info->autorestart;
-       if (val) {
-               if (strcasecmp(val, "true") == 0)
-                       *autorestart = 1;
-               else if (strcasecmp(val, "false") == 0)
-                       *autorestart = 0;
-               else
-                       *autorestart = 0;
-       }
+       *autorestart = _get_bool_value(info->app_info->autorestart);
+
        return PMINFO_R_OK;
 }
 
@@ -1559,21 +2252,13 @@ API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h  handle, bool *mainap
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
        retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
-       char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
-       if (info->app_info == NULL)
+       if (info->app_info == NULL || info->app_info->mainapp == NULL)
                return PMINFO_R_ERROR;
 
-       val = (char *)info->app_info->mainapp;
-       if (val) {
-               if (strcasecmp(val, "true") == 0)
-                       *mainapp = 1;
-               else if (strcasecmp(val, "false") == 0)
-                       *mainapp = 0;
-               else
-                       *mainapp = 0;
-       }
+       *mainapp = _get_bool_value(info->app_info->mainapp);
+
        return PMINFO_R_OK;
 }
 
@@ -1581,21 +2266,13 @@ API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
        retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
-       char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
-       if (info->app_info == NULL)
+       if (info->app_info == NULL || info->app_info->preload == NULL)
                return PMINFO_R_ERROR;
 
-       val = (char *)info->app_info->preload;
-       if (val) {
-               if (strcasecmp(val, "true") == 0)
-                       *preload = 1;
-               else if (strcasecmp(val, "false") == 0)
-                       *preload = 0;
-               else
-                       *preload = 0;
-       }
+       *preload = _get_bool_value(info->app_info->preload);
+
        return PMINFO_R_OK;
 }
 
@@ -1603,21 +2280,30 @@ API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
        retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
-       char *val = NULL;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
-       if (info->app_info == NULL)
+       if (info->app_info == NULL || info->app_info->submode == NULL)
                return PMINFO_R_ERROR;
 
-       val = (char *)info->app_info->submode;
-       if (val) {
-               if (strcasecmp(val, "true") == 0)
-                       *submode = 1;
-               else if (strcasecmp(val, "false") == 0)
-                       *submode = 0;
-               else
-                       *submode = 0;
+       *submode = _get_bool_value(info->app_info->submode);
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
+{
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+
+       if (handle == NULL || process_pool == NULL) {
+               LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
        }
+
+       if (info->app_info == NULL)
+               return PMINFO_R_ERROR;
+
+       *process_pool = _get_bool_value(info->app_info->process_pool);
+
        return PMINFO_R_OK;
 }
 
@@ -1627,26 +2313,58 @@ API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const
        retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
        retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
 
-       category_x *ptr = NULL;
+       const char *val;
+       GList *tmp;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
 
        if (info->app_info == NULL)
                return PMINFO_R_ERROR;
 
        *exist = 0;
-       for (ptr = info->app_info->category; ptr; ptr = ptr->next) {
-               if (ptr->name) {
-                       if (strcasecmp(ptr->name, category) == 0) {
-                               *exist = 1;
-                               break;
-                       }
+       for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
+               val = (const char *)tmp->data;
+               if (val == NULL)
+                       continue;
+               if (strcasecmp(val, category) == 0) {
+                       *exist = 1;
+                       break;
                }
        }
 
        return PMINFO_R_OK;
 }
 
-API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h  handle)
+API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
+               bool *ui_gadget)
+{
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+
+       if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
+               _LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
+               bool *support_disable)
+{
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+
+       if (info == NULL || info->app_info == NULL || support_disable == NULL) {
+               _LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       *support_disable = _get_bool_value(info->app_info->support_disable);
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
 {
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
@@ -1839,81 +2557,25 @@ API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
        return PMINFO_R_OK;
 }
 
-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;
-}
-
 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_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;
-       /*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 = _appinfo_get_filtered_list(handle, uid, &list);
+       if (ret != PMINFO_R_OK)
                return PMINFO_R_ERROR;
-       }
 
-       /*Start constructing query*/
-       snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, 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_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
@@ -1950,183 +2612,49 @@ API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_f
        return (pkgmgrinfo_pkginfo_filter_destroy(handle));
 }
 
-API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
+API int pkgmgrinfo_appinfo_metadata_filter_add(
+               pkgmgrinfo_appinfo_metadata_filter_h handle,
                const char *key, const char *value)
 {
-       retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
-       retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
-       /*value can be NULL. In that case all apps with specified key should be displayed*/
-       int ret = 0;
-       char *k = NULL;
-       char *v = NULL;
-       pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
-       pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
-       retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
-       k = strdup(key);
-       tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
-       node->key = k;
-       if (value) {
-               v = strdup(value);
-               tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
-       }
-       node->value = v;
-       /*If API is called multiple times, we should OR all conditions.*/
-       filter->list = g_slist_append(filter->list, (gpointer)node);
-       /*All memory will be freed in destroy API*/
-       return PMINFO_R_OK;
-catch:
-       if (node) {
-               if (node->key) {
-                       free(node->key);
-                       node->key = NULL;
-               }
-               if (node->value) {
-                       free(node->value);
-                       node->value = NULL;
-               }
-               free(node);
-               node = NULL;
-       }
-       return ret;
-}
-
-static void __get_metadata_filter_condition(gpointer data, char **condition)
-{
-       pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
-       char key[MAX_QUERY_LEN] = {'\0'};
-       char value[MAX_QUERY_LEN] = {'\0'};
-       if (node->key) {
-               snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
-       }
-       if (node->value) {
-               snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
-               strcat(key, value);
-       } else {
-               strcat(key, ")");
-       }
-       *condition = strdup(key);
-       return;
-}
-
-static char *_get_metadata_filtered_query(const char *query_raw,
-               pkgmgrinfo_filter_x *filter)
-{
-       char buf[MAX_QUERY_LEN] = { 0, };
-       char *condition;
-       size_t len;
-       GSList *list;
-       GSList *head = NULL;
-
-       if (filter)
-               head = filter->list;
-
-       strncat(buf, query_raw, MAX_QUERY_LEN - 1);
-       len = strlen(buf);
-       for (list = head; list; list = list->next) {
-               /* TODO: revise condition getter function */
-               __get_metadata_filter_condition(list->data, &condition);
-               if (condition == NULL)
-                       continue;
-               if (buf[strlen(query_raw)] == '\0') {
-                       len += strlen(" WHERE ");
-                       strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1);
-               } else {
-                       len += strlen(" AND ");
-                       strncat(buf, " AND ", MAX_QUERY_LEN -len - 1);
-               }
-               len += strlen(condition);
-               strncat(buf, condition, sizeof(buf) - len - 1);
-               free(condition);
-               condition = NULL;
-       }
-
-       return strdup(buf);
-}
-
-static GSList *_appinfo_get_metadata_filtered_list(pkgmgrinfo_filter_x *filter)
-{
-       static const char query_raw[] =
-               "SELECT app_id FROM package_app_app_metadata";
        int ret;
-       char *query;
-       sqlite3_stmt *stmt;
-       GSList *list = NULL;
-       char *appid;
-
-       query = _get_metadata_filtered_query(query_raw, filter);
-       if (query == NULL) {
-               LOGE("out of memory");
-               return NULL;
-       }
 
-       ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query),
-                       &stmt, NULL);
-       free(query);
-       if (ret != SQLITE_OK) {
-               LOGE("prepare failed: %s", sqlite3_errmsg(GET_DB(manifest_db)));
-               return NULL;
-       }
+       ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+                       PMINFO_APPINFO_PROP_APP_METADATA_KEY, key);
+       if (ret != PMINFO_R_OK)
+               return ret;
 
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               _save_column_str(stmt, 0, (const char **)&appid);
-               list = g_slist_append(list, appid);
+       /* value can be NULL.
+        * In that case all apps with specified key should be displayed
+        */
+       if (value) {
+               ret = pkgmgrinfo_appinfo_filter_add_string(handle,
+                               PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value);
+               if (ret != PMINFO_R_OK)
+                       return ret;
        }
 
-       sqlite3_finalize(stmt);
-
-       return list;
+       return PMINFO_R_OK;
 }
 
 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
                pkgmgrinfo_appinfo_metadata_filter_h handle,
                pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
 {
-       GSList *list;
-       GSList *tmp;
-       char *appid;
-       pkgmgrinfo_appinfo_h info;
-       int stop = 0;
-
        if (handle == NULL || app_cb == NULL) {
                LOGE("invalid parameter");
                return PMINFO_R_EINVAL;
        }
 
-       if (__open_manifest_db(uid) < 0)
-               return PMINFO_R_ERROR;
-
-       list = _appinfo_get_metadata_filtered_list(handle);
-       if (list == NULL) {
-               LOGE("no result");
-               __close_manifest_db();
-               return PMINFO_R_OK;
-       }
-
-       for (tmp = list; tmp; tmp = tmp->next) {
-               appid = (char *)tmp->data;
-               if (stop == 0) {
-                       if (pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid,
-                                               &info)) {
-                               free(appid);
-                               continue;
-                       }
-                       if (app_cb(info, user_data) < 0)
-                               stop = 1;
-                       pkgmgrinfo_appinfo_destroy_appinfo(info);
-               }
-               free(appid);
-       }
-
-       g_slist_free(list);
-       __close_manifest_db();
-
-       return PMINFO_R_OK;
+       return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
+                       user_data);
 }
 
-API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
+API int pkgmgrinfo_appinfo_metadata_filter_foreach(
+               pkgmgrinfo_appinfo_metadata_filter_h handle,
                pkgmgrinfo_app_list_cb app_cb, void *user_data)
 {
-       return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
+       return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
+                       user_data, GLOBAL_USER);
 }
 
 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
@@ -2137,15 +2665,7 @@ API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle,
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
        retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
 
-       val = info->uiapp_info->guestmode_visibility;
-       if (val) {
-               if (strcasecmp(val, "true") == 0){
-                       *status = 1;
-               }else if (strcasecmp(val, "false") == 0){
-                       *status = 0;
-               }else{
-                       *status = 1;
-               }
-       }
+       val = info->app_info->guestmode_visibility;
+       *status = _get_bool_value(val);
        return PMINFO_R_OK;
 }