Fix memory leak
[platform/core/appfw/pkgmgr-info.git] / src / appinfo_internal.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdbool.h>
4 #include <string.h>
5 #include <ctype.h>
6 #include <unistd.h>
7 #include <sys/types.h>
8 #include <dlfcn.h>
9
10 #include <sqlite3.h>
11 #include <glib.h>
12
13 #include "pkgmgr-info.h"
14 #include "pkgmgrinfo_debug.h"
15 #include "pkgmgrinfo_private.h"
16 #include "pkgmgr_parser.h"
17 #include "pkgmgrinfo_internal.h"
18
19 static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str,
20                                char *visibility, char *id) {
21   char *dup;
22   char *token;
23   char *ptr = NULL;
24   appcontrol_x *ac;
25
26   if (appcontrol_str == NULL) return;
27
28   dup = strdup(appcontrol_str);
29   if (dup == NULL) {
30     _LOGE("out of memory");
31     return;
32   }
33
34   do {
35     ac = calloc(1, sizeof(appcontrol_x));
36     if (ac == NULL) {
37       _LOGE("out of memory");
38       break;
39     }
40     token = strtok_r(dup, "|", &ptr);
41     if (token && strcmp(token, "NULL")) ac->operation = strdup(token);
42     token = strtok_r(NULL, "|", &ptr);
43     if (token && strcmp(token, "NULL")) ac->uri = strdup(token);
44     token = strtok_r(NULL, "|", &ptr);
45     if (token && strcmp(token, "NULL")) ac->mime = strdup(token);
46     ac->visibility = strdup(visibility);
47     ac->id = strdup(id);
48     *appcontrol = g_list_prepend(*appcontrol, ac);
49   } while ((token = strtok_r(NULL, ";", &ptr)));
50
51   free(dup);
52 }
53
54 static int _appinfo_get_splashscreens(sqlite3 *db, const char *appid,
55                                       GList **splashscreens) {
56   static const char query_raw[] =
57       "SELECT src, type, orientation, indicatordisplay, operation, color_depth "
58       "FROM package_app_splash_screen WHERE app_id=%Q";
59   int ret;
60   char *query;
61   sqlite3_stmt *stmt;
62   int idx;
63   splashscreen_x *info;
64
65   query = sqlite3_mprintf(query_raw, appid);
66   if (query == NULL) {
67     LOGE("out of memory");
68     return PMINFO_R_ERROR;
69   }
70
71   ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
72   sqlite3_free(query);
73   if (ret != SQLITE_OK) {
74     LOGE("prepare failed: %s", sqlite3_errmsg(db));
75     return PMINFO_R_ERROR;
76   }
77
78   while (sqlite3_step(stmt) == SQLITE_ROW) {
79     info = calloc(1, sizeof(splashscreen_x));
80     if (info == NULL) {
81       LOGE("out of memory");
82       sqlite3_finalize(stmt);
83       return PMINFO_R_ERROR;
84     }
85     idx = 0;
86     _save_column_str(stmt, idx++, &info->src);
87     _save_column_str(stmt, idx++, &info->type);
88     _save_column_str(stmt, idx++, &info->orientation);
89     _save_column_str(stmt, idx++, &info->indicatordisplay);
90     _save_column_str(stmt, idx++, &info->operation);
91     _save_column_str(stmt, idx++, &info->color_depth);
92     *splashscreens = g_list_prepend(*splashscreens, info);
93   }
94
95   sqlite3_finalize(stmt);
96
97   return PMINFO_R_OK;
98 }
99
100 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
101                                  GList **metadata) {
102   static const char query_raw[] =
103       "SELECT md_key, md_value "
104       "FROM package_app_app_metadata WHERE app_id=%Q";
105   int ret;
106   char *query;
107   sqlite3_stmt *stmt;
108   int idx;
109   metadata_x *info;
110
111   query = sqlite3_mprintf(query_raw, appid);
112   if (query == NULL) {
113     LOGE("out of memory");
114     return PMINFO_R_ERROR;
115   }
116
117   ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
118   sqlite3_free(query);
119   if (ret != SQLITE_OK) {
120     LOGE("prepare failed: %s", sqlite3_errmsg(db));
121     return PMINFO_R_ERROR;
122   }
123
124   while (sqlite3_step(stmt) == SQLITE_ROW) {
125     info = calloc(1, sizeof(metadata_x));
126     if (info == NULL) {
127       LOGE("out of memory");
128       sqlite3_finalize(stmt);
129       return PMINFO_R_ERROR;
130     }
131     idx = 0;
132     _save_column_str(stmt, idx++, &info->key);
133     _save_column_str(stmt, idx++, &info->value);
134     *metadata = g_list_prepend(*metadata, info);
135   }
136
137   sqlite3_finalize(stmt);
138
139   return PMINFO_R_OK;
140 }
141
142 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
143                                     GList **appcontrol) {
144   static const char query_raw[] =
145       "SELECT app_control, visibility, app_control_id "
146       "FROM package_app_app_control WHERE app_id=%Q";
147   int ret;
148   int idx;
149   char *query;
150   sqlite3_stmt *stmt;
151   char *str;
152   char *visibility;
153   char *id;
154
155   query = sqlite3_mprintf(query_raw, appid);
156   if (query == NULL) {
157     LOGE("out of memory");
158     return PMINFO_R_ERROR;
159   }
160
161   ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
162   sqlite3_free(query);
163   if (ret != SQLITE_OK) {
164     LOGE("prepare failed: %s", sqlite3_errmsg(db));
165     return PMINFO_R_ERROR;
166   }
167
168   while (sqlite3_step(stmt) == SQLITE_ROW) {
169     str = NULL;
170     visibility = NULL;
171     id = NULL;
172     idx = 0;
173     _save_column_str(stmt, idx++, &str);
174     _save_column_str(stmt, idx++, &visibility);
175     _save_column_str(stmt, idx++, &id);
176     /* TODO: revise */
177     __parse_appcontrol(appcontrol, str, visibility, id);
178     free(str);
179     free(visibility);
180     free(id);
181   }
182
183   sqlite3_finalize(stmt);
184
185   return PMINFO_R_OK;
186 }
187
188 static int _appinfo_get_category(sqlite3 *db, const char *appid,
189                                  GList **category) {
190   static const char query_raw[] =
191       "SELECT category FROM package_app_app_category WHERE app_id=%Q";
192   int ret;
193   char *query;
194   sqlite3_stmt *stmt;
195   char *val;
196
197   query = sqlite3_mprintf(query_raw, appid);
198   if (query == NULL) {
199     LOGE("out of memory");
200     return PMINFO_R_ERROR;
201   }
202
203   ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
204   sqlite3_free(query);
205   if (ret != SQLITE_OK) {
206     LOGE("prepare failed: %s", sqlite3_errmsg(db));
207     return PMINFO_R_ERROR;
208   }
209
210   while (sqlite3_step(stmt) == SQLITE_ROW) {
211     val = NULL;
212     _save_column_str(stmt, 0, &val);
213     if (val) *category = g_list_prepend(*category, (gpointer)val);
214   }
215
216   sqlite3_finalize(stmt);
217
218   return PMINFO_R_OK;
219 }
220
221 static GList *__get_background_category(const char *value) {
222   GList *category_list = NULL;
223   int convert_value = 0;
224   if (!value || strlen(value) == 0) return NULL;
225
226   convert_value = atoi(value);
227   if (convert_value < 0) return NULL;
228
229   if (convert_value & APP_BG_CATEGORY_USER_DISABLE_TRUE_VAL)
230     category_list = g_list_prepend(
231         category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_TRUE_STR));
232   else
233     category_list = g_list_prepend(
234         category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_FALSE_STR));
235
236   if (convert_value & APP_BG_CATEGORY_MEDIA_VAL)
237     category_list =
238         g_list_prepend(category_list, strdup(APP_BG_CATEGORY_MEDIA_STR));
239
240   if (convert_value & APP_BG_CATEGORY_DOWNLOAD_VAL)
241     category_list =
242         g_list_prepend(category_list, strdup(APP_BG_CATEGORY_DOWNLOAD_STR));
243
244   if (convert_value & APP_BG_CATEGORY_BGNETWORK_VAL)
245     category_list =
246         g_list_prepend(category_list, strdup(APP_BG_CATEGORY_BGNETWORK_STR));
247
248   if (convert_value & APP_BG_CATEGORY_LOCATION_VAL)
249     category_list =
250         g_list_prepend(category_list, strdup(APP_BG_CATEGORY_LOCATION_STR));
251
252   if (convert_value & APP_BG_CATEGORY_SENSOR_VAL)
253     category_list =
254         g_list_prepend(category_list, strdup(APP_BG_CATEGORY_SENSOR_STR));
255
256   if (convert_value & APP_BG_CATEGORY_IOTCOMM_VAL)
257     category_list =
258         g_list_prepend(category_list, strdup(APP_BG_CATEGORY_IOTCOMM_STR));
259
260   if (convert_value & APP_BG_CATEGORY_SYSTEM_VAL)
261     category_list =
262         g_list_prepend(category_list, strdup(APP_BG_CATEGORY_SYSTEM));
263
264   return category_list;
265 }
266
267 static int __bind_params(sqlite3_stmt *stmt, GList *params) {
268   GList *tmp_list = NULL;
269   int idx = 0;
270   int ret;
271
272   if (stmt == NULL || params == NULL) return PMINFO_R_EINVAL;
273
274   tmp_list = params;
275   while (tmp_list) {
276     ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1,
277                             SQLITE_STATIC);
278     if (ret != SQLITE_OK) return PMINFO_R_ERROR;
279     tmp_list = tmp_list->next;
280   }
281
282   return PMINFO_R_OK;
283 }
284
285 static const char join_localized_info[] =
286     " LEFT OUTER JOIN package_app_localized_info"
287     "  ON ai.app_id=package_app_localized_info.app_id"
288     "  AND package_app_localized_info.app_locale=?";
289 static const char join_category[] =
290     " LEFT OUTER JOIN package_app_app_category"
291     " ON ai.app_id=package_app_app_category.app_id";
292 static const char join_app_control[] =
293     " LEFT OUTER JOIN package_app_app_control"
294     "  ON ai.app_id=package_app_app_control.app_id";
295 static const char join_metadata[] =
296     " LEFT OUTER JOIN package_app_app_metadata"
297     "  ON ai.app_id=package_app_app_metadata.app_id ";
298 static const char join_privilege[] =
299     " LEFT OUTER JOIN package_privilege_info"
300     " ON ai.package=package_privilege_info.package ";
301
302 static int _get_filtered_query(pkgmgrinfo_filter_x *filter, const char *locale,
303                                uid_t uid, char **query, GList **bind_params) {
304   int joined = 0;
305   int size;
306   char *condition = NULL;
307   char buf[MAX_QUERY_LEN] = {'\0'};
308   char tmp_query[MAX_QUERY_LEN] = {'\0'};
309   GSList *list;
310
311   if (!filter) return PMINFO_R_OK;
312   strncat(buf, " WHERE 1=1", sizeof(buf) - strlen(buf) - 1);
313
314   for (list = filter->list; list; list = list->next) {
315     joined |= __get_filter_condition(list->data, uid, &condition, bind_params);
316     if (condition == NULL) continue;
317
318     strncat(buf, " AND ", sizeof(buf) - strlen(buf) - 1);
319
320     strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
321     free(condition);
322     condition = NULL;
323   }
324
325   if (filter->list_metadata)
326     strncat(buf, " AND (", sizeof(buf) - strlen(buf) - 1);
327   for (list = filter->list_metadata; list; list = list->next) {
328     joined |=
329         __get_metadata_filter_condition(list->data, &condition, bind_params);
330     if (condition == NULL) continue;
331     strncat(buf, condition, sizeof(buf) - strlen(buf) - 1);
332     free(condition);
333     condition = NULL;
334
335     strncat(buf, " OR ", sizeof(buf) - strlen(buf) - 1);
336   }
337   if (filter->list_metadata)
338     strncat(buf, "1=0)", sizeof(buf) - strlen(buf) - 1);
339
340   if (joined & E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO) {
341     strncat(tmp_query, join_localized_info,
342             sizeof(tmp_query) - strlen(tmp_query) - 1);
343     *bind_params = g_list_append(*bind_params, strdup(locale));
344   }
345   if (joined & E_PMINFO_APPINFO_JOIN_CATEGORY)
346     strncat(tmp_query, join_category,
347             sizeof(tmp_query) - strlen(tmp_query) - 1);
348   if (joined & E_PMINFO_APPINFO_JOIN_APP_CONTROL)
349     strncat(tmp_query, join_app_control,
350             sizeof(tmp_query) - strlen(tmp_query) - 1);
351   if (joined & E_PMINFO_APPINFO_JOIN_METADATA)
352     strncat(tmp_query, join_metadata,
353             sizeof(tmp_query) - strlen(tmp_query) - 1);
354   if (joined & E_PMINFO_APPINFO_JOIN_PRIVILEGE)
355     strncat(tmp_query, join_privilege,
356             sizeof(tmp_query) - strlen(tmp_query) - 1);
357
358   size = strlen(tmp_query) + strlen(buf) + 1;
359   *query = (char *)calloc(1, size);
360   if (*query == NULL) return PMINFO_R_ERROR;
361   snprintf(*query, size, "%s%s", tmp_query, buf);
362
363   return PMINFO_R_OK;
364 }
365
366 static bool __check_app_storage_status(pkgmgrinfo_filter_x *tmp_filter) {
367   GSList *tmp_list = NULL;
368   pkgmgrinfo_node_x *tmp_node = NULL;
369   int property = -1;
370
371   if (tmp_filter == NULL) return true;
372
373   property = _pminfo_appinfo_convert_to_prop_bool(
374       PMINFO_APPINFO_PROP_APP_CHECK_STORAGE);
375   for (tmp_list = tmp_filter->list; tmp_list != NULL;
376        tmp_list = g_slist_next(tmp_list)) {
377     tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
378     if (property == tmp_node->prop) {
379       if (strcmp(tmp_node->value, "true") == 0)
380         return true;
381       else
382         return false;
383     }
384   }
385
386   return true;
387 }
388
389 static int _appinfo_get_applications(sqlite3 *db, uid_t db_uid, uid_t uid,
390                                      const char *locale,
391                                      pkgmgrinfo_filter_x *filter, int flag,
392                                      GHashTable *applications) {
393   static const char query_raw[] =
394       "SELECT DISTINCT ai.app_id, ai.app_installed_storage, "
395       "ai.app_external_path";
396   static const char query_basic[] =
397       ", ai.app_component, ai.app_exec, "
398       "ai.app_nodisplay, ai.app_type, ai.app_onboot, "
399       "ai.app_multiple, ai.app_autorestart, ai.app_taskmanage, "
400       "ai.app_hwacceleration, ai.app_screenreader, "
401       "ai.app_mainapp, ai.app_recentimage, ai.app_launchcondition, "
402       "ai.app_indicatordisplay, ai.app_portraitimg, "
403       "ai.app_landscapeimg, ai.app_guestmodevisibility, "
404       "ai.app_permissiontype, ai.app_preload, ai.app_submode, "
405       "ai.app_submode_mainid, ai.app_launch_mode, ai.app_ui_gadget, "
406       "ai.app_support_disable, ai.app_process_pool, "
407       "ai.app_background_category, ai.app_package_type, "
408       "ai.app_root_path, ai.app_api_version, ai.app_effective_appid, "
409       "ai.app_disable, ai.app_splash_screen_display, ai.app_tep_name, "
410       "ai.app_zip_mount_file, ai.component_type, ai.package, "
411       "ai.app_package_system, ai.app_removable, "
412       "ai.app_package_installed_time, ai.app_support_mode, "
413       "ai.app_support_ambient, ai.app_setup_appid";
414   static const char query_uid_info[] =
415       ", ui.is_disabled, ui.is_splash_screen_enabled";
416   static const char query_label[] =
417       ", COALESCE("
418       "(SELECT app_label FROM package_app_localized_info WHERE "
419       "ai.app_id=app_id AND app_locale=?), "
420       "(SELECT app_label FROM package_app_localized_info WHERE "
421       "ai.app_id=app_id AND app_locale='No Locale'))";
422   static const char query_icon[] =
423       ", COALESCE("
424       "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id "
425       "AND app_locale=?), "
426       "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id "
427       "AND app_locale='No Locale'))";
428   static const char query_from_clause[] = " FROM package_app_info as ai";
429   static const char query_uid_info_clause[] =
430       " LEFT OUTER JOIN package_app_info_for_uid AS ui "
431       "ON (ai.app_id=ui.app_id AND ui.uid=?)";
432   int ret = PMINFO_R_ERROR;
433   int idx;
434   char *bg_category_str = NULL;
435   char *constraint = NULL;
436   char *tmp_record = NULL;
437   char query[MAX_QUERY_LEN] = {'\0'};
438   char buf[BUFSIZE] = {'\0'};
439   application_x *info = NULL;
440   GList *bind_params = NULL;
441   sqlite3_stmt *stmt = NULL;
442   bool is_check_storage = true;
443   const uid_t global_user_uid = GLOBAL_USER;
444
445   snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
446
447   if (flag & PMINFO_APPINFO_GET_BASICINFO) {
448     strncat(query, query_basic, sizeof(query) - strlen(query) - 1);
449     strncat(query, query_uid_info, sizeof(query) - strlen(query) - 1);
450   }
451   if (flag & PMINFO_APPINFO_GET_LABEL) {
452     strncat(query, query_label, sizeof(query) - strlen(query) - 1);
453     bind_params = g_list_append(bind_params, strdup(locale));
454   }
455   if (flag & PMINFO_APPINFO_GET_ICON) {
456     strncat(query, query_icon, sizeof(query) - strlen(query) - 1);
457     bind_params = g_list_append(bind_params, strdup(locale));
458   }
459
460   snprintf(buf, MAX_QUERY_LEN - 1, "%d", uid);
461   bind_params = g_list_append(bind_params, strdup(buf));
462
463   is_check_storage = __check_app_storage_status(filter);
464
465   ret = _get_filtered_query(filter, locale, uid, &constraint, &bind_params);
466   if (ret != PMINFO_R_OK) {
467     LOGE("Failed to get WHERE clause");
468     goto catch;
469   }
470   strncat(query, query_from_clause, sizeof(query) - strlen(query) - 1);
471
472   strncat(query, query_uid_info_clause, sizeof(query) - strlen(query) - 1);
473
474   if (constraint) strncat(query, constraint, sizeof(query) - strlen(query) - 1);
475
476   ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
477   if (ret != SQLITE_OK) {
478     LOGE("prepare failed: %s", sqlite3_errmsg(db));
479     ret = PMINFO_R_ERROR;
480     goto catch;
481   }
482
483   if (g_list_length(bind_params) != 0) {
484     ret = __bind_params(stmt, bind_params);
485     if (ret != SQLITE_OK) {
486       LOGE("Failed to bind parameters");
487       goto catch;
488     }
489   }
490
491   while (sqlite3_step(stmt) == SQLITE_ROW) {
492     info = calloc(1, sizeof(application_x));
493     if (info == NULL) {
494       LOGE("out of memory");
495       ret = PMINFO_R_ERROR;
496       goto catch;
497     }
498     info->locale = strdup(locale);
499     if (info->locale == NULL) {
500       LOGE("Out of memory");
501       ret = PMINFO_R_ERROR;
502       goto catch;
503     }
504
505     idx = 0;
506     _save_column_str(stmt, idx++, &info->appid);
507     _save_column_str(stmt, idx++, &info->installed_storage);
508     _save_column_str(stmt, idx++, &info->external_path);
509
510     if (flag & PMINFO_APPINFO_GET_BASICINFO) {
511       _save_column_str(stmt, idx++, &info->component);
512       _save_column_str(stmt, idx++, &info->exec);
513       _save_column_str(stmt, idx++, &info->nodisplay);
514       _save_column_str(stmt, idx++, &info->type);
515       _save_column_str(stmt, idx++, &info->onboot);
516       _save_column_str(stmt, idx++, &info->multiple);
517       _save_column_str(stmt, idx++, &info->autorestart);
518       _save_column_str(stmt, idx++, &info->taskmanage);
519       _save_column_str(stmt, idx++, &info->hwacceleration);
520       _save_column_str(stmt, idx++, &info->screenreader);
521       _save_column_str(stmt, idx++, &info->mainapp);
522       _save_column_str(stmt, idx++, &info->recentimage);
523       _save_column_str(stmt, idx++, &info->launchcondition);
524       _save_column_str(stmt, idx++, &info->indicatordisplay);
525       _save_column_str(stmt, idx++, &info->portraitimg);
526       _save_column_str(stmt, idx++, &info->landscapeimg);
527       _save_column_str(stmt, idx++, &info->guestmode_visibility);
528       _save_column_str(stmt, idx++, &info->permission_type);
529       _save_column_str(stmt, idx++, &info->preload);
530       _save_column_str(stmt, idx++, &info->submode);
531       _save_column_str(stmt, idx++, &info->submode_mainid);
532       _save_column_str(stmt, idx++, &info->launch_mode);
533       _save_column_str(stmt, idx++, &info->ui_gadget);
534       _save_column_str(stmt, idx++, &info->support_disable);
535       _save_column_str(stmt, idx++, &info->process_pool);
536       _save_column_str(stmt, idx++, &bg_category_str);
537       _save_column_str(stmt, idx++, &info->package_type);
538       _save_column_str(stmt, idx++, &info->root_path);
539       _save_column_str(stmt, idx++, &info->api_version);
540       _save_column_str(stmt, idx++, &info->effective_appid);
541       _save_column_str(stmt, idx++, &info->is_disabled);
542       _save_column_str(stmt, idx++, &info->splash_screen_display);
543       _save_column_str(stmt, idx++, &info->tep_name);
544       _save_column_str(stmt, idx++, &info->zip_mount_file);
545       _save_column_str(stmt, idx++, &info->component_type);
546       _save_column_str(stmt, idx++, &info->package);
547       _save_column_str(stmt, idx++, &info->package_system);
548       _save_column_str(stmt, idx++, &info->removable);
549       _save_column_str(stmt, idx++, &info->package_installed_time);
550       _save_column_str(stmt, idx++, &info->support_mode);
551       _save_column_str(stmt, idx++, &info->support_ambient);
552       _save_column_str(stmt, idx++, &info->setup_appid);
553       info->background_category = __get_background_category(bg_category_str);
554       free(bg_category_str);
555       bg_category_str = NULL;
556     }
557
558     info->for_all_users =
559         strdup((db_uid != global_user_uid) ? "false" : "true");
560
561     if (db_uid != global_user_uid) {
562       idx = idx + 2;
563     } else {
564       tmp_record = NULL;
565       _save_column_str(stmt, idx++, &tmp_record);
566       if (tmp_record != NULL) {
567         if (strcasecmp(info->is_disabled, "false") == 0 &&
568             strcasecmp(tmp_record, "false") == 0) {
569           free(info->is_disabled);
570           info->is_disabled = tmp_record;
571         } else {
572           free(tmp_record);
573         }
574       }
575       tmp_record = NULL;
576       _save_column_str(stmt, idx++, &tmp_record);
577       if (tmp_record != NULL) {
578         if (strcasecmp(info->splash_screen_display, "false") == 0 &&
579             strcasecmp(tmp_record, "false") == 0) {
580           free(info->splash_screen_display);
581           info->splash_screen_display = tmp_record;
582         } else {
583           free(tmp_record);
584         }
585       }
586     }
587
588     if (flag & PMINFO_APPINFO_GET_LABEL) {
589       tmp_record = NULL;
590       _save_column_str(stmt, idx++, &tmp_record);
591       if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
592         ret = PMINFO_R_ERROR;
593         goto catch;
594       }
595     }
596
597     if (flag & PMINFO_APPINFO_GET_ICON) {
598       tmp_record = NULL;
599       _save_column_str(stmt, idx++, &tmp_record);
600       if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
601         ret = PMINFO_R_ERROR;
602         goto catch;
603       }
604     }
605
606     if (flag & PMINFO_APPINFO_GET_CATEGORY) {
607       if (_appinfo_get_category(db, info->appid, &info->category)) {
608         ret = PMINFO_R_ERROR;
609         goto catch;
610       }
611     }
612
613     if (flag & PMINFO_APPINFO_GET_APP_CONTROL) {
614       if (_appinfo_get_app_control(db, info->appid, &info->appcontrol)) {
615         ret = PMINFO_R_ERROR;
616         goto catch;
617       }
618     }
619
620     if (flag & PMINFO_APPINFO_GET_METADATA) {
621       if (_appinfo_get_metadata(db, info->appid, &info->metadata)) {
622         ret = PMINFO_R_ERROR;
623         goto catch;
624       }
625     }
626
627     if (flag & PMINFO_APPINFO_GET_SPLASH_SCREEN) {
628       if (_appinfo_get_splashscreens(db, info->appid, &info->splashscreens)) {
629         ret = PMINFO_R_ERROR;
630         goto catch;
631       }
632     }
633
634     if (is_check_storage &&
635         __appinfo_check_installed_storage(info) != PMINFO_R_OK) {
636       ret = PMINFO_R_ERROR;
637       pkgmgrinfo_basic_free_application(info);
638       info = NULL;
639       continue;
640     }
641
642     g_hash_table_insert(applications, (gpointer)info->appid, (gpointer)info);
643   }
644
645   ret = PMINFO_R_OK;
646
647   catch : sqlite3_finalize(stmt);
648
649   if (constraint) free(constraint);
650
651   if (ret != PMINFO_R_OK && info != NULL)
652     pkgmgrinfo_basic_free_application(info);
653
654   g_list_free_full(bind_params, free);
655
656   return ret;
657 }
658
659 API int appinfo_internal_filter_get_list(sqlite3 *db,
660                                          pkgmgrinfo_appinfo_filter_h filter,
661                                          uid_t uid, const char *locale,
662                                          GHashTable *appinfo_list) {
663   int ret;
664
665   if (db == NULL || filter == NULL || appinfo_list == NULL) {
666     LOGE("Invalid argument");
667     return PMINFO_R_EINVAL;
668   }
669
670   ret = _appinfo_get_applications(db, uid, uid, locale, filter,
671                                   PMINFO_APPINFO_GET_ALL, appinfo_list);
672   return ret;
673 }