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