Fix static analysis issue
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_appinfo.c
index 08db1f5..b50e08d 100644 (file)
@@ -52,92 +52,65 @@ static const char join_app_control[] =
 static const char join_metadata[] =
        " LEFT OUTER JOIN package_app_app_metadata"
        "  ON ai.app_id=package_app_app_metadata.app_id ";
-static const char join_appinfo_for_uid[] =
-       " LEFT OUTER JOIN package_app_info_for_uid"
-       " ON ai.app_id=package_app_info_for_uid.app_id ";
+static const char join_privilege[] =
+       " LEFT OUTER JOIN package_privilege_info"
+       " ON ai.package=package_privilege_info.package ";
 
 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
        const char *locale, uid_t uid, char **query, GList **bind_params)
 {
        int joined = 0;
-       size_t len = 0;
        char *condition = NULL;
        char buf[MAX_QUERY_LEN] = { '\0' };
        char tmp_query[MAX_QUERY_LEN] = { '\0' };
-       static const char query_pkg_disable[] = " AND ai.package IN "
-                       "(SELECT package FROM package_info WHERE package_disable='false')";
        GSList *list;
 
-       len += strlen(" WHERE 1=1");
-       strncat(buf, " WHERE 1=1", MAX_QUERY_LEN - len - 1);
-
-       if (filter == NULL) {
-               strncat(buf, query_pkg_disable, MAX_QUERY_LEN - len - 1);
-               *query = strdup(buf);
+       if (!filter)
                return PMINFO_R_OK;
-       }
+       strncat(buf, " WHERE 1=1", sizeof(buf) - strlen(buf) - 1);
 
        for (list = filter->list; list; list = list->next) {
                joined |= __get_filter_condition(list->data, uid, &condition, bind_params);
                if (condition == NULL)
                        continue;
 
-               len += strlen(" AND ");
-               strncat(buf, " AND ", MAX_QUERY_LEN - len - 1);
+               strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1);
 
-               len += strlen(condition);
-               strncat(buf, condition, sizeof(buf) - len - 1);
+               strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
                free(condition);
                condition = NULL;
        }
 
-       if (filter->list_metadata) {
-               len += strlen(" AND (");
-               strncat(buf, " AND (", MAX_QUERY_LEN - len - 1);
-       }
+       if (filter->list_metadata)
+               strncat(buf, " AND (", sizeof(buf) - strlen(buf) - 1);
        for (list = filter->list_metadata; list; list = list->next) {
                joined |= __get_metadata_filter_condition(list->data,
                                &condition, bind_params);
                if (condition == NULL)
                        continue;
-               len += strlen(condition);
-               strncat(buf, condition, sizeof(buf) - len - 1);
+               strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
                free(condition);
                condition = NULL;
 
-               len += strlen(" OR ");
-               strncat(buf, " OR ", MAX_QUERY_LEN - len - 1);
-       }
-       if (filter->list_metadata) {
-               len += strlen("1=0)");
-               strncat(buf, "1=0)", MAX_QUERY_LEN - len - 1);
+               strncat(buf, " OR ", sizeof(buf) - strlen(buf) - 1);
        }
+       if (filter->list_metadata)
+               strncat(buf, "1=0)", sizeof(buf) - strlen(buf) - 1);
 
        if (joined & E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO) {
-               strncat(tmp_query, join_localized_info, MAX_QUERY_LEN - len - 1);
-               len += strlen(join_localized_info);
+               strncat(tmp_query, join_localized_info, sizeof(tmp_query) - strlen(tmp_query) - 1);
                *bind_params = g_list_append(*bind_params, strdup(locale));
        }
-       if (joined & E_PMINFO_APPINFO_JOIN_CATEGORY) {
-               strncat(tmp_query, join_category, MAX_QUERY_LEN - len - 1);
-               len += strlen(join_category);
-       }
-       if (joined & E_PMINFO_APPINFO_JOIN_APP_CONTROL) {
-               strncat(tmp_query, join_app_control, MAX_QUERY_LEN - len - 1);
-               len += strlen(join_app_control);
-       }
-       if (joined & E_PMINFO_APPINFO_JOIN_METADATA) {
-               strncat(tmp_query, join_metadata, MAX_QUERY_LEN - len - 1);
-               len += strlen(join_metadata);
-       }
-       if (joined & E_PMINFO_APPINFO_JOIN_APPINFO_FOR_UID) {
-               strncat(tmp_query, join_appinfo_for_uid, MAX_QUERY_LEN - len - 1);
-               len += strlen(join_appinfo_for_uid);
-       }
-       strncat(tmp_query, buf, MAX_QUERY_LEN - len - 1);
+       if (joined & E_PMINFO_APPINFO_JOIN_CATEGORY)
+               strncat(tmp_query, join_category, sizeof(tmp_query) - strlen(tmp_query) - 1);
+       if (joined & E_PMINFO_APPINFO_JOIN_APP_CONTROL)
+               strncat(tmp_query, join_app_control, sizeof(tmp_query) - strlen(tmp_query) - 1);
+       if (joined & E_PMINFO_APPINFO_JOIN_METADATA)
+               strncat(tmp_query, join_metadata, sizeof(tmp_query) - strlen(tmp_query) - 1);
+       if (joined & E_PMINFO_APPINFO_JOIN_PRIVILEGE)
+               strncat(tmp_query, join_privilege, sizeof(tmp_query) - strlen(tmp_query) - 1);
 
-       len += strlen(buf);
-       strncat(tmp_query, query_pkg_disable, MAX_QUERY_LEN - len - 1);
+       strncat(tmp_query, buf, sizeof(tmp_query) - strlen(tmp_query) - 1);
 
        *query = strdup(tmp_query);
        if (*query == NULL)
@@ -181,7 +154,8 @@ static int _appinfo_get_category(sqlite3 *db, const char *appid,
        return PMINFO_R_OK;
 }
 
-static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str)
+static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str,
+               char *visibility, char *id)
 {
        char *dup;
        char *token;
@@ -192,6 +166,11 @@ static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str)
                return;
 
        dup = strdup(appcontrol_str);
+       if (dup == NULL) {
+               _LOGE("out of memory");
+               return;
+       }
+
        do {
                ac = calloc(1, sizeof(appcontrol_x));
                if (ac == NULL) {
@@ -207,6 +186,8 @@ static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str)
                token = strtok_r(NULL, "|", &ptr);
                if (token && strcmp(token, "NULL"))
                        ac->mime = strdup(token);
+               ac->visibility = strdup(visibility);
+               ac->id = strdup(id);
                *appcontrol = g_list_append(*appcontrol, ac);
        } while ((token = strtok_r(NULL, ";", &ptr)));
 
@@ -217,12 +198,15 @@ 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 "
-               "WHERE app_id=%Q";
+               "SELECT app_control, visibility, app_control_id "
+               "FROM package_app_app_control WHERE app_id=%Q";
        int ret;
+       int idx;
        char *query;
        sqlite3_stmt *stmt;
        char *str;
+       char *visibility;
+       char *id;
 
        query = sqlite3_mprintf(query_raw, appid);
        if (query == NULL) {
@@ -239,54 +223,17 @@ static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
 
        while (sqlite3_step(stmt) == SQLITE_ROW) {
                str = NULL;
-               _save_column_str(stmt, 0, &str);
+               visibility = NULL;
+               id = NULL;
+               idx = 0;
+               _save_column_str(stmt, idx++, &str);
+               _save_column_str(stmt, idx++, &visibility);
+               _save_column_str(stmt, idx++, &id);
                /* TODO: revise */
-               __parse_appcontrol(appcontrol, str);
+               __parse_appcontrol(appcontrol, str, visibility, id);
                free(str);
-       }
-
-       sqlite3_finalize(stmt);
-
-       return PMINFO_R_OK;
-}
-
-static int _appinfo_get_data_control(sqlite3 *db, const char *appid,
-               GList **datacontrol)
-{
-       static const char query_raw[] =
-               "SELECT providerid, access, type "
-               "FROM package_app_data_control WHERE app_id=%Q";
-       int ret;
-       char *query;
-       sqlite3_stmt *stmt;
-       int idx;
-       datacontrol_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(datacontrol_x));
-               if (info == NULL) {
-                       LOGE("out of memory");
-                       sqlite3_finalize(stmt);
-                       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);
-               *datacontrol = g_list_append(*datacontrol, info);
+               free(visibility);
+               free(id);
        }
 
        sqlite3_finalize(stmt);
@@ -426,71 +373,33 @@ static GList *__get_background_category(const char *value)
 
 }
 
-static int __get_appinfo_for_uid(sqlite3 *db, application_x *info, uid_t uid)
-{
-       static const char query_raw[] =
-               "SELECT is_splash_screen_enabled, is_disabled "
-               "FROM package_app_info_for_uid WHERE app_id='%s' AND uid='%d'";
-       int ret;
-       char *query;
-       char *is_disabled = NULL;
-       sqlite3_stmt *stmt;
-
-       query = sqlite3_mprintf(query_raw, info->appid, uid);
-       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("sqlite3_prepare_v2() failed: %s", sqlite3_errmsg(db));
-               return PMINFO_R_ERROR;
-       }
-
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               if (info->splash_screen_display)
-                       free(info->splash_screen_display);
-               _save_column_str(stmt, 0, &info->splash_screen_display);
-               if (strcasecmp(info->is_disabled, "false") == 0) {
-                       _save_column_str(stmt, 1, &is_disabled);
-                       if (strcasecmp(is_disabled, "true") == 0) {
-                               free(info->is_disabled);
-                               info->is_disabled = is_disabled;
-                       } else {
-                               free(is_disabled);
-                       }
-               }
-       }
-
-       sqlite3_finalize(stmt);
-       return PMINFO_R_OK;
-}
-
 static void __free_applications(gpointer data)
 {
        pkgmgrinfo_basic_free_application((application_x *)data);
 }
 
-static gint __app_disable_chk_func(gconstpointer data1, gconstpointer data2)
+static gint __disable_chk_func(gconstpointer data1, gconstpointer data2)
 {
        pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
+       pkgmgrinfo_appinfo_disable_type value = GPOINTER_TO_INT(data2);
 
-       if (node->prop == E_PMINFO_APPINFO_PROP_APP_DISABLE)
-               return 0;
+       if (value == E_APPINFO_DISABLE_TYPE_PKG)
+               return (node->prop == E_PMINFO_APPINFO_PROP_PKG_DISABLE)
+                               ? 0 : 1;
        else
-               return 1;
+               return (node->prop == E_PMINFO_APPINFO_PROP_APP_DISABLE)
+                               ? 0 : 1;
 }
 
-static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
+static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter,
+               pkgmgrinfo_appinfo_disable_type type)
 {
        GSList *link;
 
        if (filter == NULL)
                return false;
 
-       link = g_slist_find_custom(filter->list, NULL, __app_disable_chk_func);
+       link = g_slist_find_custom(filter->list, GINT_TO_POINTER(type), __disable_chk_func);
        if (link)
                return true;
 
@@ -546,7 +455,10 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
                GHashTable *applications)
 {
        static const char query_raw[] =
-               "SELECT DISTINCT ai.app_id, ai.app_component, ai.app_exec, "
+               "SELECT DISTINCT ai.app_id, ai.app_installed_storage, "
+               "ai.app_external_path";
+       static const char query_basic[] =
+               ", ai.app_component, ai.app_exec, "
                "ai.app_nodisplay, ai.app_type, ai.app_onboot, "
                "ai.app_multiple, ai.app_autorestart, ai.app_taskmanage, "
                "ai.app_hwacceleration, ai.app_screenreader, "
@@ -556,14 +468,15 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
                "ai.app_permissiontype, ai.app_preload, ai.app_submode, "
                "ai.app_submode_mainid, ai.app_launch_mode, ai.app_ui_gadget, "
                "ai.app_support_disable, ai.app_process_pool, "
-               "ai.app_installed_storage, ai.app_background_category, "
-               "ai.app_package_type, ai.app_root_path, ai.app_api_version, "
-               "ai.app_effective_appid, ai.app_disable, "
-               "ai.app_splash_screen_display, ai.app_tep_name, "
+               "ai.app_background_category, ai.app_package_type, "
+               "ai.app_root_path, ai.app_api_version, ai.app_effective_appid, "
+               "ai.app_disable, ai.app_splash_screen_display, ai.app_tep_name, "
                "ai.app_zip_mount_file, ai.component_type, ai.package, "
-               "ai.app_external_path, ai.app_package_system, ai.app_removable, "
+               "ai.app_package_system, ai.app_removable, "
                "ai.app_package_installed_time, ai.app_support_mode, "
                "ai.app_support_ambient, ai.app_setup_appid";
+       static const char query_uid_info[] =
+               ", ui.is_disabled, ui.is_splash_screen_enabled";
        static const char query_label[] =
                ", COALESCE("
                "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
@@ -573,19 +486,23 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
                "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
                "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))";
        static const char query_from_clause[] = " FROM package_app_info as ai";
+       static const char query_uid_info_clause[] =
+               " LEFT OUTER JOIN package_app_info_for_uid AS ui "
+               "ON (ai.app_id=ui.app_id AND ui.uid=?)";
        int ret = PMINFO_R_ERROR;
        int idx;
-       int len = 0;
        char *dbpath;
        char *bg_category_str = NULL;
        char *constraint = NULL;
        char *tmp_record = NULL;
        char query[MAX_QUERY_LEN] = { '\0' };
+       char buf[BUFSIZE] = { '\0' };
        application_x *info = NULL;
        GList *bind_params = NULL;
        sqlite3 *db = NULL;
        sqlite3_stmt *stmt = NULL;
        bool is_check_storage = true;
+       const uid_t global_user_uid = GLOBAL_USER;
 
        dbpath = getUserPkgParserDBPathUID(db_uid);
        if (dbpath == NULL)
@@ -593,25 +510,30 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
 
        ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
        if (ret != SQLITE_OK) {
-               _LOGE("failed to open db: %d", ret);
+               _LOGE("failed to open db(%s): %d", dbpath, ret);
                free(dbpath);
                return PMINFO_R_ERROR;
        }
        free(dbpath);
 
-       len = strlen(query_raw);
        snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
+
+       if (flag & PMINFO_APPINFO_GET_BASICINFO) {
+               strncat(query, query_basic, sizeof(query) - strlen(query) - 1);
+               strncat(query, query_uid_info, sizeof(query) - strlen(query) - 1);
+       }
        if (flag & PMINFO_APPINFO_GET_LABEL) {
-               strncat(query, query_label, MAX_QUERY_LEN - len - 1);
-               len += strlen(query_label);
+               strncat(query, query_label, sizeof(query) - strlen(query) - 1);
                bind_params = g_list_append(bind_params, strdup(locale));
        }
        if (flag & PMINFO_APPINFO_GET_ICON) {
-               strncat(query, query_icon, MAX_QUERY_LEN - len - 1);
-               len += strlen(query_icon);
+               strncat(query, query_icon, sizeof(query) - strlen(query) - 1);
                bind_params = g_list_append(bind_params, strdup(locale));
        }
 
+       snprintf(buf, MAX_QUERY_LEN - 1, "%d", uid);
+       bind_params = g_list_append(bind_params, strdup(buf));
+
        is_check_storage = __check_app_storage_status(filter);
 
        ret = _get_filtered_query(filter, locale, uid, &constraint, &bind_params);
@@ -619,11 +541,12 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
                LOGE("Failed to get WHERE clause");
                goto catch;
        }
-       strncat(query, query_from_clause, MAX_QUERY_LEN - len - 1);
-       len += strlen(query_from_clause);
+       strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1);
+
+       strncat(query, query_uid_info_clause, sizeof(query) - strlen(query) - 1);
 
        if (constraint)
-               strncat(query, constraint, MAX_QUERY_LEN - len - 1);
+               strncat(query, constraint, sizeof(query) - strlen(query) - 1);
 
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
@@ -649,75 +572,88 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
                }
                idx = 0;
                _save_column_str(stmt, idx++, &info->appid);
-               if (g_hash_table_contains(applications,
-                                       (gconstpointer)info->appid)) {
-                       free(info->appid);
-                       free(info);
-                       info = NULL;
-                       continue;
-               }
-               _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->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->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);
-               _save_column_str(stmt, idx++, &info->root_path);
-               _save_column_str(stmt, idx++, &info->api_version);
-               _save_column_str(stmt, idx++, &info->effective_appid);
-               _save_column_str(stmt, idx++, &info->is_disabled);
-               _save_column_str(stmt, idx++, &info->splash_screen_display);
-               _save_column_str(stmt, idx++, &info->tep_name);
-               _save_column_str(stmt, idx++, &info->zip_mount_file);
-               _save_column_str(stmt, idx++, &info->component_type);
-               _save_column_str(stmt, idx++, &info->package);
-               _save_column_str(stmt, idx++, &info->external_path);
-               _save_column_str(stmt, idx++, &info->package_system);
-               _save_column_str(stmt, idx++, &info->removable);
-               _save_column_str(stmt, idx++, &info->package_installed_time);
-               _save_column_str(stmt, idx++, &info->support_mode);
-               _save_column_str(stmt, idx++, &info->support_ambient);
-               _save_column_str(stmt, idx++, &info->setup_appid);
+               _save_column_str(stmt, idx++ , &info->external_path);
+
+               if (flag & PMINFO_APPINFO_GET_BASICINFO) {
+                       _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->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->process_pool);
+                       _save_column_str(stmt, idx++, &bg_category_str);
+                       _save_column_str(stmt, idx++, &info->package_type);
+                       _save_column_str(stmt, idx++, &info->root_path);
+                       _save_column_str(stmt, idx++, &info->api_version);
+                       _save_column_str(stmt, idx++, &info->effective_appid);
+                       _save_column_str(stmt, idx++, &info->is_disabled);
+                       _save_column_str(stmt, idx++, &info->splash_screen_display);
+                       _save_column_str(stmt, idx++, &info->tep_name);
+                       _save_column_str(stmt, idx++, &info->zip_mount_file);
+                       _save_column_str(stmt, idx++, &info->component_type);
+                       _save_column_str(stmt, idx++, &info->package);
+                       _save_column_str(stmt, idx++, &info->package_system);
+                       _save_column_str(stmt, idx++, &info->removable);
+                       _save_column_str(stmt, idx++, &info->package_installed_time);
+                       _save_column_str(stmt, idx++, &info->support_mode);
+                       _save_column_str(stmt, idx++, &info->support_ambient);
+                       _save_column_str(stmt, idx++, &info->setup_appid);
+                       info->background_category = __get_background_category(
+                                       bg_category_str);
+                       free(bg_category_str);
+                       bg_category_str = NULL;
+               }
 
                info->for_all_users =
-                       strdup((db_uid != GLOBAL_USER) ? "false" : "true");
-
-               if (db_uid == GLOBAL_USER) {
-                       ret = __get_appinfo_for_uid(db, info, uid);
-                       if (ret != PMINFO_R_OK) {
-                               LOGI("Failed to get appinfo for given uid[%d]", (int)uid);
-                               pkgmgrinfo_basic_free_application(info);
-                               info = NULL;
-                               continue;
+                       strdup((db_uid != global_user_uid) ? "false" : "true");
+
+               if (db_uid != global_user_uid) {
+                       idx = idx + 2;
+               } else {
+                       tmp_record = NULL;
+                       _save_column_str(stmt, idx++, &tmp_record);
+                       if (tmp_record != NULL) {
+                               if (strcasecmp(info->is_disabled, "false") == 0 &&
+                                               strcasecmp(tmp_record, "false") == 0) {
+                                       free(info->is_disabled);
+                                       info->is_disabled = tmp_record;
+                               } else {
+                                       free(tmp_record);
+                               }
+                       }
+                       tmp_record = NULL;
+                       _save_column_str(stmt, idx++, &tmp_record);
+                       if (tmp_record != NULL) {
+                               if (strcasecmp(info->splash_screen_display, "false") == 0 &&
+                                               strcasecmp(tmp_record, "false") == 0) {
+                                       free(info->splash_screen_display);
+                                       info->splash_screen_display = tmp_record;
+                               } else {
+                                       free(tmp_record);
+                               }
                        }
                }
 
-               info->background_category = __get_background_category(
-                               bg_category_str);
-               free(bg_category_str);
-
                if (flag & PMINFO_APPINFO_GET_LABEL) {
                        tmp_record = NULL;
                        _save_column_str(stmt, idx++, &tmp_record);
@@ -752,14 +688,6 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
                        }
                }
 
-               if (flag & PMINFO_APPINFO_GET_DATA_CONTROL) {
-                       if (_appinfo_get_data_control(db, info->appid,
-                                               &info->datacontrol)) {
-                               ret = PMINFO_R_ERROR;
-                               goto catch;
-                       }
-               }
-
                if (flag & PMINFO_APPINFO_GET_METADATA) {
                        if (_appinfo_get_metadata(db, info->appid,
                                                &info->metadata)) {
@@ -791,6 +719,9 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
        ret = PMINFO_R_OK;
 
 catch:
+       sqlite3_finalize(stmt);
+       sqlite3_close_v2(db);
+
        if (constraint)
                free(constraint);
 
@@ -798,8 +729,6 @@ catch:
                pkgmgrinfo_basic_free_application(info);
 
        g_list_free_full(bind_params, free);
-       sqlite3_close_v2(db);
-       sqlite3_finalize(stmt);
 
        return ret;
 }
@@ -821,7 +750,8 @@ static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
        if (locale == NULL)
                return PMINFO_R_ERROR;
 
-       list = g_hash_table_new(g_str_hash, g_str_equal);
+       list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+                       __free_applications);
        if (list == NULL) {
                free(locale);
                return PMINFO_R_ERROR;
@@ -833,8 +763,14 @@ static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
                ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, filter,
                                PMINFO_APPINFO_GET_ALL, list);
 
+       if (ret != PMINFO_R_OK) {
+               g_hash_table_destroy(list);
+               free(locale);
+               return ret;
+       }
+
        if (!g_hash_table_size(list)) {
-               _LOGI("appinfo for [%s] is not existed for user [%d]",
+               _LOGD("appinfo for [%s] is not existed for user [%d]",
                                appid, uid);
                g_hash_table_destroy(list);
                free(locale);
@@ -850,10 +786,24 @@ static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
        }
 
        info->app_info = (application_x *)g_hash_table_lookup(list, appid);
+       if (!info->app_info || !info->app_info->package) {
+               _LOGD("appinfo for [%s] is not existed for user [%d]",
+                               appid, uid);
+               g_hash_table_destroy(list);
+               free(locale);
+               return PMINFO_R_ENOENT;
+       }
        info->locale = locale;
        info->package = strdup(info->app_info->package);
+       if (!info->package) {
+               _LOGE("out of memory");
+               g_hash_table_destroy(list);
+               free(locale);
+               return PMINFO_R_ERROR;
+       }
 
        /* just free list only */
+       g_hash_table_steal(list, (gconstpointer)appid);
        g_hash_table_destroy(list);
 
        *handle = info;
@@ -930,6 +880,13 @@ API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
                return PMINFO_R_ERROR;
        }
 
+       ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
+                       PMINFO_APPINFO_PROP_PKG_DISABLE, false);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_appinfo_filter_destroy(filter);
+               return PMINFO_R_ERROR;
+       }
+
        ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
        pkgmgrinfo_appinfo_filter_destroy(filter);
        return ret;
@@ -1081,6 +1038,8 @@ static gpointer __copy_datacontrol(gconstpointer src, gpointer data)
                datacontrol->access = strdup(tmp->access);
        if (tmp->type)
                datacontrol->type = strdup(tmp->type);
+       if (tmp->trusted)
+               datacontrol->trusted = strdup(tmp->trusted);
 
        return datacontrol;
 }
@@ -1343,15 +1302,11 @@ static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
                return PMINFO_R_ERROR;
        }
 
-       if (__check_disable_filter_exist(filter) == false) {
-               pkgmgrinfo_appinfo_filter_add_bool(filter,
-                               PMINFO_APPINFO_PROP_APP_DISABLE, false);
-       }
-
-       ret = _appinfo_get_applications(uid, uid, locale, filter, flag, list);
+       ret = _appinfo_get_applications(uid, uid, locale, filter,
+                       flag | PMINFO_APPINFO_GET_BASICINFO, list);
        if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
                ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
-                               filter, flag, list);
+                               filter, flag | PMINFO_APPINFO_GET_BASICINFO, list);
 
        if (ret != PMINFO_R_OK) {
                g_hash_table_destroy(list);
@@ -1404,6 +1359,12 @@ API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
                return PMINFO_R_ERROR;
        }
 
+       if (pkgmgrinfo_appinfo_filter_add_bool(filter,
+                       PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
+               pkgmgrinfo_appinfo_filter_destroy(filter);
+               return PMINFO_R_ERROR;
+       }
+
        comp_str = __appcomponent_str(component);
 
        if (comp_str) {
@@ -1446,7 +1407,13 @@ API int pkgmgrinfo_appinfo_get_usr_installed_list_full(
                return PMINFO_R_ERROR;
 
        if (pkgmgrinfo_appinfo_filter_add_bool(filter,
-                               PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
+                       PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
+               pkgmgrinfo_appinfo_filter_destroy(filter);
+               return PMINFO_R_ERROR;
+       }
+
+       if (pkgmgrinfo_appinfo_filter_add_bool(filter,
+                       PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
                pkgmgrinfo_appinfo_filter_destroy(filter);
                return PMINFO_R_ERROR;
        }
@@ -1488,6 +1455,18 @@ API int pkgmgrinfo_appinfo_get_usr_installed_list(
        if (ret != PMINFO_R_OK)
                return ret;
 
+       if (pkgmgrinfo_appinfo_filter_add_bool(filter,
+                       PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
+               pkgmgrinfo_appinfo_filter_destroy(filter);
+               return PMINFO_R_ERROR;
+       }
+
+       if (pkgmgrinfo_appinfo_filter_add_bool(filter,
+                       PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
+               pkgmgrinfo_appinfo_filter_destroy(filter);
+               return PMINFO_R_ERROR;
+       }
+
        ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
                        PMINFO_APPINFO_GET_ALL, app_func, user_data);
 
@@ -1606,21 +1585,42 @@ API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
 {
        label_x *ptr;
        pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+       char *lbl = NULL;
+       const char *locale;
+       GList *tmp;
 
        retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
        retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
 
-       if (info->app_info == NULL || info->app_info->label == NULL)
+       if (info->app_info == NULL)
                return PMINFO_R_ERROR;
 
-       ptr = (label_x *)info->app_info->label->data;
-       if (ptr == NULL)
-               return PMINFO_R_ERROR;
+       locale = info->locale;
+       if (locale == NULL)
+               locale = DEFAULT_LOCALE;
 
-       if (ptr->text == NULL)
-               return PMINFO_R_ERROR;
-       else
-               *label = ptr->text;
+       for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
+               ptr = (label_x *)tmp->data;
+               if (ptr == NULL || strcmp(locale, ptr->lang) != 0)
+                       continue;
+               lbl = ptr->text;
+               break;
+       }
+
+       if (lbl != NULL) {
+               *label = lbl;
+               return PMINFO_R_OK;
+       }
+
+       for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
+               ptr = (label_x *)tmp->data;
+               if (ptr == NULL || strcmp(DEFAULT_LOCALE, ptr->lang) != 0)
+                       continue;
+               lbl = ptr->text;
+               break;
+       }
+
+       *label = lbl ? lbl : "";
 
        return PMINFO_R_OK;
 }
@@ -1739,6 +1739,8 @@ static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
                return PMINFO_WIDGET_APP;
        else if (strcasecmp(comp, "watchapp") == 0)
                return PMINFO_WATCH_APP;
+       else if (strcasecmp(comp, "componentbasedapp") == 0)
+               return PMINFO_COMPONENT_BASED_APP;
        else
                return -1;
 }
@@ -1754,6 +1756,8 @@ static const char *__appcomponent_str(pkgmgrinfo_app_component comp)
                return "widgetapp";
        case PMINFO_WATCH_APP:
                return "watchapp";
+       case PMINFO_COMPONENT_BASED_APP:
+               return "componentbasedapp";
        default:
                return NULL;
        }
@@ -1841,35 +1845,6 @@ API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h  handle,
        return PMINFO_R_OK;
 }
 
-API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
-{
-       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");
-
-       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;
-               if (val && strcmp(val, "setting") == 0) {
-                       *icon = (char *)ptr->text;
-                       return PMINFO_R_OK;
-               }
-       }
-
-       return PMINFO_R_ERROR;
-}
-
-
 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
 {
        char *val;
@@ -2250,128 +2225,460 @@ API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int *
        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)
+static int _appinfo_get_datacontrol_info(sqlite3 *db, const char *providerid,
+               const char *type, char **appid, char **access)
 {
-       retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
-       retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
-       retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
-       retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
-
-       int ret = PMINFO_R_OK;
-       char *query = NULL;
-       sqlite3_stmt *stmt = NULL;
+       static const char query[] =
+               "SELECT app_id, access FROM package_app_data_control "
+               "WHERE providerid=? AND type=?";
+       int ret;
+       sqlite3_stmt *stmt;
 
-       /*open db*/
-       ret = __open_manifest_db(uid, true);
-       retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
+       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;
+       }
 
-       /*Start constructing query*/
-       query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
-       tryvm_if(query == NULL, ret = PMINFO_R_ERROR, "Out of memory");
+       ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
+       if (ret != SQLITE_OK) {
+               LOGE("bind failed: %s", sqlite3_errmsg(db));
+               sqlite3_finalize(stmt);
+               return PMINFO_R_ERROR;
+       }
 
-       /*prepare query*/
-       ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
-       tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
+       ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
+       if (ret != SQLITE_OK) {
+               LOGE("bind failed: %s", sqlite3_errmsg(db));
+               sqlite3_finalize(stmt);
+               return PMINFO_R_ERROR;
+       }
 
-       /*step query*/
        ret = sqlite3_step(stmt);
-       tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
+       if (ret != SQLITE_ROW) {
+               sqlite3_finalize(stmt);
+               if (ret == SQLITE_DONE) {
+                       return PMINFO_R_ENOENT;
+               } else {
+                       LOGE("step error: %s", sqlite3_errmsg(db));
+                       return PMINFO_R_ERROR;
+               }
+       }
 
        *appid = strdup((char *)sqlite3_column_text(stmt, 0));
-       *access = strdup((char *)sqlite3_column_text(stmt, 2));
-
-       ret = PMINFO_R_OK;
+       if (*appid == NULL) {
+               LOGE("out of memory");
+               sqlite3_finalize(stmt);
+               return PMINFO_R_ERROR;
+       }
+       *access = strdup((char *)sqlite3_column_text(stmt, 1));
+       if (*access == NULL) {
+               LOGE("out of memory");
+               free(*appid);
+               sqlite3_finalize(stmt);
+               return PMINFO_R_ERROR;
+       }
 
-catch:
-       sqlite3_free(query);
        sqlite3_finalize(stmt);
-       __close_manifest_db();
-       return ret;
-}
 
-API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
-{
-       return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, _getuid(), appid, access);
+       return PMINFO_R_OK;
 }
 
-API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
+static int _pkgmgrinfo_appinfo_get_datacontrol_info(uid_t uid,
+               const char *providerid, const char *type,
+               char **appid, char **access)
 {
-       retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
-       retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
-
-       int ret = PMINFO_R_OK;
-       char *query = NULL;
-       sqlite3_stmt *stmt = NULL;
-
-       /*open db*/
-       ret = __open_manifest_db(uid, true);
-       retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
-
-       /*Start constructing query*/
-       query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
-       tryvm_if(query == NULL, ret = PMINFO_R_ERROR, "Out of memory");
-
-       /*prepare query*/
-       ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
-       tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
+       int ret;
+       char *dbpath;
+       sqlite3 *db;
 
-       /*step query*/
-       ret = sqlite3_step(stmt);
-       tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
+       dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
+       if (dbpath == NULL)
+               return PMINFO_R_ERROR;
 
-       *appid = strdup((char *)sqlite3_column_text(stmt, 0));
+       ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
+       free(dbpath);
+       if (ret != SQLITE_OK) {
+               LOGE("open db failed: %s", sqlite3_errmsg(db));
+               return PMINFO_R_ERROR;
+       }
 
-       ret = PMINFO_R_OK;
+       ret = _appinfo_get_datacontrol_info(db, providerid, type, appid,
+                       access);
+       sqlite3_close_v2(db);
 
-catch:
-       sqlite3_free(query);
-       sqlite3_finalize(stmt);
-       __close_manifest_db();
        return ret;
 }
 
-API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
+API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid,
+               const char *type, uid_t uid, char **appid, char **access)
 {
-       return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
+       int ret;
+
+       if (providerid == NULL || type == NULL || appid == NULL ||
+                       access == NULL) {
+               LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       ret = _pkgmgrinfo_appinfo_get_datacontrol_info(GLOBAL_USER, providerid,
+                       type, appid, access);
+       if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
+               ret = _pkgmgrinfo_appinfo_get_datacontrol_info(uid, providerid,
+                               type, appid, access);
+
+       /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
+        * implementation, return PMINFO_R_ERROR. This should be
+        * modified later...
+        */
+       if (ret == PMINFO_R_ENOENT) {
+               LOGE("no datacontrol info of %s", providerid);
+               ret = PMINFO_R_ERROR;
+       }
+
+       return ret;
 }
 
-API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h  handle, int *support_mode)
+API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid,
+               const char *type, char **appid, char **access)
 {
-       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
-       retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
+       return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid,
+                       type, _getuid(), appid, access);
+}
 
-       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
-       if (info->app_info->support_mode)
-               *support_mode = atoi(info->app_info->support_mode);
-       else
-               *support_mode = 0;
+static int _appinfo_get_datacontrol_appid(sqlite3 *db, const char *providerid,
+               char **appid)
+{
+       static const char query[] =
+               "SELECT app_id FROM package_app_data_control "
+               "WHERE providerid=?";
+       int ret;
+       sqlite3_stmt *stmt;
+
+       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_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
+       if (ret != SQLITE_OK) {
+               LOGE("bind failed: %s", sqlite3_errmsg(db));
+               sqlite3_finalize(stmt);
+               return PMINFO_R_ERROR;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_ROW) {
+               sqlite3_finalize(stmt);
+               if (ret == SQLITE_DONE) {
+                       return PMINFO_R_ENOENT;
+               } else {
+                       LOGE("step error: %s", sqlite3_errmsg(db));
+                       return PMINFO_R_ERROR;
+               }
+       }
+
+       *appid = strdup((char *)sqlite3_column_text(stmt, 0));
+
+       sqlite3_finalize(stmt);
+
+       if (*appid == NULL) {
+               LOGE("out of memory");
+               return PMINFO_R_ERROR;
+       }
 
        return PMINFO_R_OK;
 }
 
-API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
-                       pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
+static int _pkgmgrinfo_appinfo_get_datacontrol_appid(uid_t uid,
+               const char *providerid, char **appid)
 {
-       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;
-       GList *tmp;
-       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+       int ret;
+       char *dbpath;
+       sqlite3 *db;
 
-       if (info->app_info == NULL)
+       dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
+       if (dbpath == NULL)
                return PMINFO_R_ERROR;
 
-       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)
-                               break;
+       ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
+       free(dbpath);
+       if (ret != SQLITE_OK) {
+               LOGE("open db failed: %s", sqlite3_errmsg(db));
+               return PMINFO_R_ERROR;
+       }
+
+       ret = _appinfo_get_datacontrol_appid(db, providerid, appid);
+       sqlite3_close_v2(db);
+
+       return ret;
+}
+
+API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid,
+               uid_t uid, char **appid)
+{
+       int ret;
+
+       if (providerid == NULL || appid == NULL) {
+               LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(GLOBAL_USER, providerid,
+                       appid);
+       if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
+               ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(uid, providerid,
+                               appid);
+
+       /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
+        * implementation, return PMINFO_R_ERROR. This should be
+        * modified later...
+        */
+       if (ret == PMINFO_R_ENOENT) {
+               LOGE("no datacontrol appid of %s", providerid);
+               ret = PMINFO_R_ERROR;
+       }
+
+       return ret;
+}
+
+API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
+{
+       return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
+}
+
+static int _appinfo_get_datacontrol_trusted_info(sqlite3 *db,
+               const char *providerid, const char *type, char **appid,
+               bool *is_trusted)
+{
+       static const char query[] =
+               "SELECT app_id, trusted FROM package_app_data_control "
+               "WHERE providerid=? AND type=?";
+       int ret;
+       sqlite3_stmt *stmt;
+
+       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_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
+       if (ret != SQLITE_OK) {
+               LOGE("bind failed: %s", sqlite3_errmsg(db));
+               sqlite3_finalize(stmt);
+               return PMINFO_R_ERROR;
+       }
+
+       ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
+       if (ret != SQLITE_OK) {
+               LOGE("bind failed: %s", sqlite3_errmsg(db));
+               sqlite3_finalize(stmt);
+               return PMINFO_R_ERROR;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_ROW) {
+               sqlite3_finalize(stmt);
+               if (ret == SQLITE_DONE) {
+                       return PMINFO_R_ENOENT;
+               } else {
+                       LOGE("step error: %s", sqlite3_errmsg(db));
+                       return PMINFO_R_ERROR;
                }
        }
+
+       *appid = strdup((char *)sqlite3_column_text(stmt, 0));
+       *is_trusted = _get_bool_value((char *)sqlite3_column_text(stmt, 1));
+
+       sqlite3_finalize(stmt);
+
+       if (*appid == NULL) {
+               LOGE("out of memory");
+               return PMINFO_R_ERROR;
+       }
+
+       return PMINFO_R_OK;
+}
+
+static int _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid_t uid,
+               const char *providerid, const char *type, char **appid,
+               bool *is_trusted)
+{
+       int ret;
+       char *dbpath;
+       sqlite3 *db;
+
+       dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
+       if (dbpath == NULL)
+               return PMINFO_R_ERROR;
+
+       ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
+       free(dbpath);
+       if (ret != SQLITE_OK) {
+               LOGE("open db failed: %s", sqlite3_errmsg(db));
+               return PMINFO_R_ERROR;
+       }
+
+       ret = _appinfo_get_datacontrol_trusted_info(db, providerid, type, appid,
+                       is_trusted);
+       sqlite3_close_v2(db);
+
+       return ret;
+}
+
+API int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(
+               const char *providerid, const char *type, uid_t uid,
+               char **appid, bool *is_trusted)
+{
+       int ret;
+
+       if (providerid == NULL || type == NULL || appid == NULL ||
+                       is_trusted == NULL) {
+               LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(GLOBAL_USER,
+                       providerid, type, appid, is_trusted);
+       if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
+               ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid,
+                               providerid, type, appid, is_trusted);
+
+       /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
+        * implementation, return PMINFO_R_ERROR. This should be
+        * modified later...
+        */
+       if (ret == PMINFO_R_ENOENT) {
+               LOGE("no datacontrol trusted info of %s", providerid);
+               ret = PMINFO_R_ERROR;
+       }
+
+       return ret;
+}
+
+API int pkgmgrinfo_appinfo_get_datacontrol_trsuted_info(const char *providerid,
+               const char *type, char **appid, bool *is_trusted)
+{
+       return pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(providerid,
+                       type, _getuid(), appid, is_trusted);
+}
+
+static int _appinfo_foreach_datacontrol_privileges(sqlite3 *db,
+               const char *providerid, const char *type,
+               pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
+{
+       static const char query[] =
+               "SELECT privilege FROM package_app_data_control_privilege "
+               "WHERE providerid=? AND type=?";
+       int ret;
+       sqlite3_stmt *stmt;
+       int count = 0;
+
+       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_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
+       if (ret != SQLITE_OK) {
+               LOGE("bind failed: %s", sqlite3_errmsg(db));
+               sqlite3_finalize(stmt);
+               return PMINFO_R_ERROR;
+       }
+
+       ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
+       if (ret != SQLITE_OK) {
+               LOGE("bind failed: %s", sqlite3_errmsg(db));
+               sqlite3_finalize(stmt);
+               return PMINFO_R_ERROR;
+       }
+
+       while (sqlite3_step(stmt) == SQLITE_ROW) {
+               count++;
+               ret = callback((const char *)sqlite3_column_text(stmt, 0),
+                               user_data);
+               if (ret < 0)
+                       break;
+       }
+
+       sqlite3_finalize(stmt);
+
+       return count ? PMINFO_R_OK : PMINFO_R_ENOENT;
+}
+
+static int _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid_t uid,
+               const char *providerid, const char *type,
+               pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
+{
+       int ret;
+       char *dbpath;
+       sqlite3 *db;
+
+       dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
+       if (dbpath == NULL)
+               return PMINFO_R_ERROR;
+
+       ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
+       free(dbpath);
+       if (ret != SQLITE_OK) {
+               LOGE("open db failed: %s", sqlite3_errmsg(db));
+               return PMINFO_R_ERROR;
+       }
+
+       ret = _appinfo_foreach_datacontrol_privileges(db, providerid, type,
+                       callback, user_data);
+       sqlite3_close_v2(db);
+
+       return ret;
+}
+
+API int pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
+               const char *providerid, const char *type,
+               pkgmgrinfo_pkg_privilege_list_cb privilege_func,
+               void *user_data, uid_t uid)
+{
+       int ret;
+
+       if (providerid == NULL || type == NULL || privilege_func == NULL) {
+               LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(GLOBAL_USER,
+                       providerid, type, privilege_func, user_data);
+       if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
+               ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid,
+                               providerid, type, privilege_func, user_data);
+
+       if (ret == PMINFO_R_ENOENT)
+               ret = PMINFO_R_OK;
+
+       return ret;
+}
+
+API int pkgmgrinfo_appinfo_foreach_datacontrol_privileges(
+               const char *providerid, const char *type,
+               pkgmgrinfo_pkg_privilege_list_cb privilege_func,
+               void *user_data)
+{
+       return pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
+                       providerid, type, privilege_func, user_data, _getuid());
+}
+
+API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h  handle, int *support_mode)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
+
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+       if (info->app_info->support_mode)
+               *support_mode = atoi(info->app_info->support_mode);
+       else
+               *support_mode = 0;
+
        return PMINFO_R_OK;
 }
 
@@ -2425,6 +2732,121 @@ API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
        return PMINFO_R_OK;
 }
 
+static int _appinfo_foreach_appcontrol_privileges(sqlite3 *db,
+               const char *appid, const char *operation,
+               pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
+{
+       static const char query[] =
+               "SELECT app_control, privilege FROM package_app_app_control_privilege "
+               "WHERE app_id=?";
+       int ret;
+       sqlite3_stmt *stmt;
+       const char *app_control;
+       char *dup_app_control;
+       char *token;
+       char *saveptr = NULL;
+       const char *privilege;
+       int count = 0;
+
+       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_bind_text(stmt, 1, appid, -1, SQLITE_STATIC);
+       if (ret != SQLITE_OK) {
+               LOGE("bind failed: %s", sqlite3_errmsg(db));
+               sqlite3_finalize(stmt);
+               return PMINFO_R_ERROR;
+       }
+
+       while (sqlite3_step(stmt) == SQLITE_ROW) {
+               app_control = (const char *)sqlite3_column_text(stmt, 0);
+               if (!app_control)
+                       continue;
+
+               dup_app_control = strdup(app_control);
+               if (!dup_app_control)
+                       continue;
+
+               token = strtok_r(dup_app_control, "|", &saveptr);
+               if (token && !strcmp(token, operation)) {
+                       count++;
+                       privilege = (const char *)sqlite3_column_text(stmt, 1);
+                       ret = callback(privilege, user_data);
+                       if (ret < 0) {
+                               free(dup_app_control);
+                               break;
+                       }
+               }
+               free(dup_app_control);
+       }
+
+       sqlite3_finalize(stmt);
+
+       return count ? PMINFO_R_OK : PMINFO_R_ENOENT;
+}
+
+static int _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid_t uid,
+               const char *appid, const char *operation,
+               pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
+{
+       int ret;
+       char *dbpath;
+       sqlite3 *db;
+
+       dbpath = getUserPkgParserDBPathUID(uid);
+       if (dbpath == NULL)
+               return PMINFO_R_ERROR;
+
+       ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
+       free(dbpath);
+       if (ret != SQLITE_OK) {
+               LOGE("open db failed: %s", sqlite3_errmsg(db));
+               return PMINFO_R_ERROR;
+       }
+
+       ret = _appinfo_foreach_appcontrol_privileges(db, appid, operation,
+                       callback, user_data);
+       sqlite3_close_v2(db);
+
+       return ret;
+}
+
+API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid,
+               const char *operation,
+               pkgmgrinfo_pkg_privilege_list_cb privilege_func,
+               void *user_data, uid_t uid)
+{
+       int ret;
+
+       if (appid == NULL || operation == NULL || privilege_func == NULL) {
+               LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(GLOBAL_USER,
+                       appid, operation, privilege_func, user_data);
+       if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
+               ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid,
+                               appid, operation, privilege_func, user_data);
+
+       if (ret == PMINFO_R_ENOENT)
+               ret = PMINFO_R_OK;
+
+       return ret;
+}
+
+API int pkgmgrinfo_appinfo_foreach_appcontrol_privileges(const char *appid,
+               const char *operation,
+               pkgmgrinfo_pkg_privilege_list_cb privilege_func,
+               void *user_data)
+{
+       return pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(appid,
+                       operation, privilege_func, user_data, _getuid());
+}
+
 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
                        pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
 {
@@ -2440,7 +2862,32 @@ API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
 
        for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
                appcontrol = (appcontrol_x *)tmp->data;
-               if (appcontrol == NULL)
+               if (appcontrol == NULL || !strcasecmp(appcontrol->visibility, "remote-only"))
+                       continue;
+               ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
+               if (ret < 0)
+                       break;
+       }
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_foreach_remote_appcontrol(pkgmgrinfo_appinfo_h handle,
+                       pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
+       int ret;
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+       appcontrol_x *appcontrol;
+       GList *tmp;
+
+       if (info->app_info == NULL)
+               return PMINFO_R_ERROR;
+
+       for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
+               appcontrol = (appcontrol_x *)tmp->data;
+               if (appcontrol == NULL || !strcasecmp(appcontrol->visibility, "local-only"))
                        continue;
                ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
                if (ret < 0)
@@ -3042,6 +3489,26 @@ API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle,
                return PMINFO_R_ERROR;
        }
 
+       if (__check_disable_filter_exist(
+                       handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
+               if (pkgmgrinfo_appinfo_filter_add_bool(handle,
+                               PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
+                       g_hash_table_destroy(list);
+                       free(locale);
+                       return PMINFO_R_ERROR;
+               }
+       }
+
+       if (__check_disable_filter_exist(
+                       handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
+               if (pkgmgrinfo_appinfo_filter_add_bool(handle,
+                               PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
+                       g_hash_table_destroy(list);
+                       free(locale);
+                       return PMINFO_R_ERROR;
+               }
+       }
+
        ret = _appinfo_get_applications(uid, uid, locale, handle, 0, list);
        if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
                ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
@@ -3074,6 +3541,20 @@ API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
                return PMINFO_R_EINVAL;
        }
 
+       if (__check_disable_filter_exist(
+                       handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
+               if (pkgmgrinfo_appinfo_filter_add_bool(handle,
+                               PMINFO_APPINFO_PROP_APP_DISABLE, false))
+                       return PMINFO_R_ERROR;
+       }
+
+       if (__check_disable_filter_exist(
+                       handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
+               if (pkgmgrinfo_appinfo_filter_add_bool(handle,
+                               PMINFO_APPINFO_PROP_PKG_DISABLE, false))
+                       return PMINFO_R_ERROR;
+       }
+
        return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
                        user_data);
 }
@@ -3134,6 +3615,15 @@ API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
                return PMINFO_R_EINVAL;
        }
 
+       pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
+       if (pkgmgrinfo_appinfo_filter_add_bool(filter,
+                       PMINFO_APPINFO_PROP_APP_DISABLE, false))
+               return PMINFO_R_ERROR;
+
+       if (pkgmgrinfo_appinfo_filter_add_bool(filter,
+                       PMINFO_APPINFO_PROP_PKG_DISABLE, false))
+               return PMINFO_R_ERROR;
+
        return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
                        user_data);
 }
@@ -3158,3 +3648,60 @@ API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle,
        *status = _get_bool_value(val);
        return PMINFO_R_OK;
 }
+
+API int pkgmgrinfo_appinfo_foreach_appcontrol_v2(pkgmgrinfo_appinfo_h handle,
+               pkgmgrinfo_app_control_list_cb_v2 appcontrol_func,
+               void *user_data)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
+       int ret;
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+       appcontrol_x *appcontrol;
+       GList *tmp;
+
+       if (info->app_info == NULL)
+               return PMINFO_R_ERROR;
+
+       for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
+               appcontrol = (appcontrol_x *)tmp->data;
+               if (appcontrol == NULL ||
+                               !strcasecmp(appcontrol->visibility, "remote-only"))
+                       continue;
+               ret = appcontrol_func(appcontrol->operation, appcontrol->uri,
+                               appcontrol->mime, appcontrol->id, user_data);
+               if (ret < 0)
+                       break;
+       }
+
+       return PMINFO_R_OK;
+}
+
+API int pkgmgrinfo_appinfo_foreach_remote_appcontrol_v2(
+               pkgmgrinfo_appinfo_h handle,
+               pkgmgrinfo_app_control_list_cb_v2 appcontrol_func,
+               void *user_data)
+{
+       retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
+       retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
+       int ret;
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+       appcontrol_x *appcontrol;
+       GList *tmp;
+
+       if (info->app_info == NULL)
+               return PMINFO_R_ERROR;
+
+       for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
+               appcontrol = (appcontrol_x *)tmp->data;
+               if (appcontrol == NULL ||
+                               !strcasecmp(appcontrol->visibility, "local-only"))
+                       continue;
+               ret = appcontrol_func(appcontrol->operation, appcontrol->uri,
+                               appcontrol->mime, appcontrol->id, user_data);
+               if (ret < 0)
+                       break;
+       }
+
+       return PMINFO_R_OK;
+}