Add apis for datacontrol privileges info
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_appinfo.c
index 6d9bc49..e07bf52 100644 (file)
@@ -52,9 +52,6 @@ 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 int _get_filtered_query(pkgmgrinfo_filter_x *filter,
        const char *locale, uid_t uid, char **query, GList **bind_params)
@@ -68,8 +65,8 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
                        "(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);
+       len += strlen(" WHERE 1=1");
 
        if (filter == NULL) {
                strncat(buf, query_pkg_disable, MAX_QUERY_LEN - len - 1);
@@ -82,13 +79,35 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
                if (condition == NULL)
                        continue;
 
-               len += strlen(" AND ");
                strncat(buf, " AND ", MAX_QUERY_LEN - len - 1);
+               len += strlen(" AND ");
 
+               strncat(buf, condition, sizeof(buf) - len - 1);
                len += strlen(condition);
+               free(condition);
+               condition = NULL;
+       }
+
+       if (filter->list_metadata) {
+               strncat(buf, " AND (", MAX_QUERY_LEN - len - 1);
+               len += strlen(" AND (");
+       }
+       for (list = filter->list_metadata; list; list = list->next) {
+               joined |= __get_metadata_filter_condition(list->data,
+                               &condition, bind_params);
+               if (condition == NULL)
+                       continue;
                strncat(buf, condition, sizeof(buf) - len - 1);
+               len += strlen(condition);
                free(condition);
                condition = NULL;
+
+               strncat(buf, " OR ", MAX_QUERY_LEN - len - 1);
+               len += strlen(" OR ");
+       }
+       if (filter->list_metadata) {
+               strncat(buf, "1=0)", MAX_QUERY_LEN - len - 1);
+               len += strlen("1=0)");
        }
 
        if (joined & E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO) {
@@ -108,13 +127,10 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
                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);
 
+       strncat(tmp_query, buf, MAX_QUERY_LEN - len - 1);
        len += strlen(buf);
+
        strncat(tmp_query, query_pkg_disable, MAX_QUERY_LEN - len - 1);
 
        *query = strdup(tmp_query);
@@ -228,50 +244,6 @@ static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
        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);
-       }
-
-       sqlite3_finalize(stmt);
-
-       return PMINFO_R_OK;
-}
-
 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
                GList **metadata)
 {
@@ -404,48 +376,6 @@ 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);
@@ -524,7 +454,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, "
@@ -534,14 +467,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_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=?), "
@@ -551,6 +485,9 @@ 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;
@@ -559,11 +496,13 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
        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)
@@ -579,6 +518,13 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
 
        len = strlen(query_raw);
        snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
+
+       if (flag & PMINFO_APPINFO_GET_BASICINFO) {
+               strncat(query, query_basic, MAX_QUERY_LEN - len - 1);
+               len += strlen(query_basic);
+               strncat(query, query_uid_info, MAX_QUERY_LEN - len - 1);
+               len += strlen(query_uid_info);
+       }
        if (flag & PMINFO_APPINFO_GET_LABEL) {
                strncat(query, query_label, MAX_QUERY_LEN - len - 1);
                len += strlen(query_label);
@@ -590,6 +536,9 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
                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);
@@ -600,6 +549,9 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
        strncat(query, query_from_clause, MAX_QUERY_LEN - len - 1);
        len += strlen(query_from_clause);
 
+       strncat(query, query_uid_info_clause, MAX_QUERY_LEN - len - 1);
+       len += strlen(query_uid_info_clause);
+
        if (constraint)
                strncat(query, constraint, MAX_QUERY_LEN - len - 1);
 
@@ -627,74 +579,83 @@ 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->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);
+               }
 
                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;
+                               }
+                       }
+                       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;
+                               }
                        }
                }
 
-               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);
@@ -729,14 +690,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)) {
@@ -1058,6 +1011,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;
 }
@@ -1325,10 +1280,11 @@ static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
                                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);
@@ -1428,6 +1384,12 @@ API int pkgmgrinfo_appinfo_get_usr_installed_list_full(
                return PMINFO_R_ERROR;
        }
 
+       if (pkgmgrinfo_appinfo_filter_add_bool(filter,
+                       PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false)) {
+               pkgmgrinfo_appinfo_filter_destroy(filter);
+               return PMINFO_R_ERROR;
+       }
+
        ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, flag, app_func,
                        user_data);
 
@@ -1443,20 +1405,6 @@ API int pkgmgrinfo_appinfo_get_installed_list_full(
                        _getuid(), flag, user_data);
 }
 
-API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func,
-               uid_t uid, void *user_data)
-{
-       return pkgmgrinfo_appinfo_get_usr_installed_list_full(app_func,
-                       uid, PMINFO_APPINFO_GET_ALL, user_data);
-}
-
-API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func,
-               void *user_data)
-{
-       return pkgmgrinfo_appinfo_get_usr_installed_list_full(app_func,
-                       _getuid(), PMINFO_APPINFO_GET_ALL, user_data);
-}
-
 API int pkgmgrinfo_appinfo_get_usr_installed_list(
                pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
 {
@@ -2235,7 +2183,8 @@ 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)
+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");
        retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
@@ -2274,9 +2223,11 @@ catch:
        return ret;
 }
 
-API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
+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 pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid,
+                       type, _getuid(), appid, access);
 }
 
 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
@@ -2320,6 +2271,98 @@ API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **
        return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
 }
 
+API int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(const char *providerid,
+               const char *type, uid_t uid, char **appid, bool *is_trusted)
+{
+       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 app_id, trusted FROM package_app_data_control WHERE providerid=%Q AND type=%Q", providerid, type);
+       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);
+
+       /*step query*/
+       ret = sqlite3_step(stmt);
+       tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
+
+       _save_column_str(stmt, 0, appid);
+       *is_trusted = _get_bool_value((char *)sqlite3_column_text(stmt, 1));
+
+       ret = PMINFO_R_OK;
+
+catch:
+       sqlite3_free(query);
+       sqlite3_finalize(stmt);
+       __close_manifest_db();
+       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);
+}
+
+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)
+{
+       retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
+       retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
+
+       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 privilege FROM package_app_data_control_privilege "
+                       "WHERE providerid=%Q AND type=%Q", providerid, type);
+       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);
+
+       while (sqlite3_step(stmt) == SQLITE_ROW) {
+               char *privilege;
+               privilege = (char *)sqlite3_column_text(stmt, 0);
+               ret = privilege_func(privilege, user_data);
+               if (ret < 0)
+                       break;
+       }
+
+       ret = PMINFO_R_OK;
+
+catch:
+       sqlite3_free(query);
+       sqlite3_finalize(stmt);
+       __close_manifest_db();
+       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");
@@ -2785,6 +2828,22 @@ API int pkgmgrinfo_appinfo_get_splash_screen_display(pkgmgrinfo_appinfo_h handle
        return PMINFO_R_OK;
 }
 
+API int pkgmgrinfo_appinfo_get_setup_appid(pkgmgrinfo_appinfo_h handle, char **setup_appid)
+{
+       pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
+
+       if (info == NULL || setup_appid == NULL) {
+               _LOGE("Invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
+       if (info->app_info == NULL || info->app_info->setup_appid == NULL)
+               return PMINFO_R_ERROR;
+
+       *setup_appid = info->app_info->setup_appid;
+       return PMINFO_R_OK;
+}
+
 API int pkgmgrinfo_appinfo_is_support_ambient(pkgmgrinfo_appinfo_h handle,
                bool *support_ambient)
 {
@@ -3067,23 +3126,30 @@ API int pkgmgrinfo_appinfo_metadata_filter_add(
                pkgmgrinfo_appinfo_metadata_filter_h handle,
                const char *key, const char *value)
 {
-       int ret;
-
-       ret = pkgmgrinfo_appinfo_filter_add_string(handle,
-                       PMINFO_APPINFO_PROP_APP_METADATA_KEY, key);
-       if (ret != PMINFO_R_OK)
-               return ret;
+       pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
+       pkgmgrinfo_metadata_node_x *node;
 
        /* value can be NULL.
         * In that case all apps with specified key should be displayed
         */
-       if (value && strlen(value)) {
-               ret = pkgmgrinfo_appinfo_filter_add_string(handle,
-                               PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value);
-               if (ret != PMINFO_R_OK)
-                       return ret;
+       if (key == NULL) {
+               LOGE("invalid parameter");
+               return PMINFO_R_EINVAL;
        }
 
+       node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x));
+       if (node == NULL) {
+               LOGE("out of memory");
+               return PMINFO_R_ERROR;
+       }
+
+       node->key = strdup(key);
+       if (value && strlen(value))
+               node->value = strdup(value);
+
+       filter->list_metadata = g_slist_append(filter->list_metadata,
+                       (gpointer)node);
+
        return PMINFO_R_OK;
 }