Fix wrong size calculation of using strncat
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_appinfo.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
18 static bool _get_bool_value(const char *str)
19 {
20         if (str && !strcmp(str, "true"))
21                 return true;
22         else
23                 return false;
24 }
25
26 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
27 {
28         pkgmgr_appinfo_x *info = data;
29
30         if (info != NULL) {
31                 if (info->package)
32                         free((void *)info->package);
33                 if (info->locale)
34                         free((void *)info->locale);
35
36                 pkgmgrinfo_basic_free_application(info->app_info);
37                 free((void *)info);
38         }
39         return;
40 }
41
42 static const char join_localized_info[] =
43         " LEFT OUTER JOIN package_app_localized_info"
44         "  ON ai.app_id=package_app_localized_info.app_id"
45         "  AND package_app_localized_info.app_locale=?";
46 static const char join_category[] =
47         " LEFT OUTER JOIN package_app_app_category"
48         " ON ai.app_id=package_app_app_category.app_id";
49 static const char join_app_control[] =
50         " LEFT OUTER JOIN package_app_app_control"
51         "  ON ai.app_id=package_app_app_control.app_id";
52 static const char join_metadata[] =
53         " LEFT OUTER JOIN package_app_app_metadata"
54         "  ON ai.app_id=package_app_app_metadata.app_id ";
55 static const char join_appinfo_for_uid[] =
56         " LEFT OUTER JOIN package_app_info_for_uid"
57         " ON ai.app_id=package_app_info_for_uid.app_id ";
58
59 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
60         const char *locale, uid_t uid, char **query, GList **bind_params)
61 {
62         int joined = 0;
63         size_t len = 0;
64         char *condition = NULL;
65         char buf[MAX_QUERY_LEN] = { '\0' };
66         char tmp_query[MAX_QUERY_LEN] = { '\0' };
67         static const char query_pkg_disable[] = " AND ai.package IN "
68                         "(SELECT package FROM package_info WHERE package_disable='false')";
69         GSList *list;
70
71         strncat(buf, " WHERE 1=1", MAX_QUERY_LEN - len - 1);
72         len += strlen(" WHERE 1=1");
73
74         if (filter == NULL) {
75                 strncat(buf, query_pkg_disable, MAX_QUERY_LEN - len - 1);
76                 *query = strdup(buf);
77                 return PMINFO_R_OK;
78         }
79
80         for (list = filter->list; list; list = list->next) {
81                 joined |= __get_filter_condition(list->data, uid, &condition, bind_params);
82                 if (condition == NULL)
83                         continue;
84
85                 strncat(buf, " AND ", MAX_QUERY_LEN - len - 1);
86                 len += strlen(" AND ");
87
88                 strncat(buf, condition, sizeof(buf) - len - 1);
89                 len += strlen(condition);
90                 free(condition);
91                 condition = NULL;
92         }
93
94         if (filter->list_metadata) {
95                 strncat(buf, " AND (", MAX_QUERY_LEN - len - 1);
96                 len += strlen(" AND (");
97         }
98         for (list = filter->list_metadata; list; list = list->next) {
99                 joined |= __get_metadata_filter_condition(list->data,
100                                 &condition, bind_params);
101                 if (condition == NULL)
102                         continue;
103                 strncat(buf, condition, sizeof(buf) - len - 1);
104                 len += strlen(condition);
105                 free(condition);
106                 condition = NULL;
107
108                 strncat(buf, " OR ", MAX_QUERY_LEN - len - 1);
109                 len += strlen(" OR ");
110         }
111         if (filter->list_metadata) {
112                 strncat(buf, "1=0)", MAX_QUERY_LEN - len - 1);
113                 len += strlen("1=0)");
114         }
115
116         if (joined & E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO) {
117                 strncat(tmp_query, join_localized_info, MAX_QUERY_LEN - len - 1);
118                 len += strlen(join_localized_info);
119                 *bind_params = g_list_append(*bind_params, strdup(locale));
120         }
121         if (joined & E_PMINFO_APPINFO_JOIN_CATEGORY) {
122                 strncat(tmp_query, join_category, MAX_QUERY_LEN - len - 1);
123                 len += strlen(join_category);
124         }
125         if (joined & E_PMINFO_APPINFO_JOIN_APP_CONTROL) {
126                 strncat(tmp_query, join_app_control, MAX_QUERY_LEN - len - 1);
127                 len += strlen(join_app_control);
128         }
129         if (joined & E_PMINFO_APPINFO_JOIN_METADATA) {
130                 strncat(tmp_query, join_metadata, MAX_QUERY_LEN - len - 1);
131                 len += strlen(join_metadata);
132         }
133         if (joined & E_PMINFO_APPINFO_JOIN_APPINFO_FOR_UID) {
134                 strncat(tmp_query, join_appinfo_for_uid, MAX_QUERY_LEN - len - 1);
135                 len += strlen(join_appinfo_for_uid);
136         }
137         strncat(tmp_query, buf, MAX_QUERY_LEN - len - 1);
138         len += strlen(buf);
139
140         strncat(tmp_query, query_pkg_disable, MAX_QUERY_LEN - len - 1);
141
142         *query = strdup(tmp_query);
143         if (*query == NULL)
144                 return PMINFO_R_ERROR;
145
146         return PMINFO_R_OK;
147 }
148
149 static int _appinfo_get_category(sqlite3 *db, const char *appid,
150                 GList **category)
151 {
152         static const char query_raw[] =
153                 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
154         int ret;
155         char *query;
156         sqlite3_stmt *stmt;
157         char *val;
158
159         query = sqlite3_mprintf(query_raw, appid);
160         if (query == NULL) {
161                 LOGE("out of memory");
162                 return PMINFO_R_ERROR;
163         }
164
165         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
166         sqlite3_free(query);
167         if (ret != SQLITE_OK) {
168                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
169                 return PMINFO_R_ERROR;
170         }
171
172         while (sqlite3_step(stmt) == SQLITE_ROW) {
173                 val = NULL;
174                 _save_column_str(stmt, 0, &val);
175                 if (val)
176                         *category = g_list_append(*category, (gpointer)val);
177         }
178
179         sqlite3_finalize(stmt);
180
181         return PMINFO_R_OK;
182 }
183
184 static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str)
185 {
186         char *dup;
187         char *token;
188         char *ptr = NULL;
189         appcontrol_x *ac;
190
191         if (appcontrol_str == NULL)
192                 return;
193
194         dup = strdup(appcontrol_str);
195         do {
196                 ac = calloc(1, sizeof(appcontrol_x));
197                 if (ac == NULL) {
198                         _LOGE("out of memory");
199                         break;
200                 }
201                 token = strtok_r(dup, "|", &ptr);
202                 if (token && strcmp(token, "NULL"))
203                         ac->operation = strdup(token);
204                 token = strtok_r(NULL, "|", &ptr);
205                 if (token && strcmp(token, "NULL"))
206                         ac->uri = strdup(token);
207                 token = strtok_r(NULL, "|", &ptr);
208                 if (token && strcmp(token, "NULL"))
209                         ac->mime = strdup(token);
210                 *appcontrol = g_list_append(*appcontrol, ac);
211         } while ((token = strtok_r(NULL, ";", &ptr)));
212
213         free(dup);
214 }
215
216 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
217                 GList **appcontrol)
218 {
219         static const char query_raw[] =
220                 "SELECT app_control FROM package_app_app_control "
221                 "WHERE app_id=%Q";
222         int ret;
223         char *query;
224         sqlite3_stmt *stmt;
225         char *str;
226
227         query = sqlite3_mprintf(query_raw, appid);
228         if (query == NULL) {
229                 LOGE("out of memory");
230                 return PMINFO_R_ERROR;
231         }
232
233         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
234         sqlite3_free(query);
235         if (ret != SQLITE_OK) {
236                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
237                 return PMINFO_R_ERROR;
238         }
239
240         while (sqlite3_step(stmt) == SQLITE_ROW) {
241                 str = NULL;
242                 _save_column_str(stmt, 0, &str);
243                 /* TODO: revise */
244                 __parse_appcontrol(appcontrol, str);
245                 free(str);
246         }
247
248         sqlite3_finalize(stmt);
249
250         return PMINFO_R_OK;
251 }
252
253 static int _appinfo_get_data_control(sqlite3 *db, const char *appid,
254                 GList **datacontrol)
255 {
256         static const char query_raw[] =
257                 "SELECT providerid, access, type "
258                 "FROM package_app_data_control WHERE app_id=%Q";
259         int ret;
260         char *query;
261         sqlite3_stmt *stmt;
262         int idx;
263         datacontrol_x *info;
264
265         query = sqlite3_mprintf(query_raw, appid);
266         if (query == NULL) {
267                 LOGE("out of memory");
268                 return PMINFO_R_ERROR;
269         }
270
271         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
272         sqlite3_free(query);
273         if (ret != SQLITE_OK) {
274                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
275                 return PMINFO_R_ERROR;
276         }
277
278         while (sqlite3_step(stmt) == SQLITE_ROW) {
279                 info = calloc(1, sizeof(datacontrol_x));
280                 if (info == NULL) {
281                         LOGE("out of memory");
282                         sqlite3_finalize(stmt);
283                         return PMINFO_R_ERROR;
284                 }
285                 idx = 0;
286                 _save_column_str(stmt, idx++, &info->providerid);
287                 _save_column_str(stmt, idx++, &info->access);
288                 _save_column_str(stmt, idx++, &info->type);
289                 *datacontrol = g_list_append(*datacontrol, info);
290         }
291
292         sqlite3_finalize(stmt);
293
294         return PMINFO_R_OK;
295 }
296
297 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
298                 GList **metadata)
299 {
300         static const char query_raw[] =
301                 "SELECT md_key, md_value "
302                 "FROM package_app_app_metadata WHERE app_id=%Q";
303         int ret;
304         char *query;
305         sqlite3_stmt *stmt;
306         int idx;
307         metadata_x *info;
308
309         query = sqlite3_mprintf(query_raw, appid);
310         if (query == NULL) {
311                 LOGE("out of memory");
312                 return PMINFO_R_ERROR;
313         }
314
315         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
316         sqlite3_free(query);
317         if (ret != SQLITE_OK) {
318                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
319                 return PMINFO_R_ERROR;
320         }
321
322         while (sqlite3_step(stmt) == SQLITE_ROW) {
323                 info = calloc(1, sizeof(metadata_x));
324                 if (info == NULL) {
325                         LOGE("out of memory");
326                         sqlite3_finalize(stmt);
327                         return PMINFO_R_ERROR;
328                 }
329                 idx = 0;
330                 _save_column_str(stmt, idx++, &info->key);
331                 _save_column_str(stmt, idx++, &info->value);
332                 *metadata = g_list_append(*metadata, info);
333         }
334
335         sqlite3_finalize(stmt);
336
337         return PMINFO_R_OK;
338
339 }
340
341 static int _appinfo_get_splashscreens(sqlite3 *db, const char *appid,
342                 GList **splashscreens)
343 {
344         static const char query_raw[] =
345                 "SELECT src, type, orientation, indicatordisplay, operation, color_depth "
346                 "FROM package_app_splash_screen WHERE app_id=%Q";
347         int ret;
348         char *query;
349         sqlite3_stmt *stmt;
350         int idx;
351         splashscreen_x *info;
352
353         query = sqlite3_mprintf(query_raw, appid);
354         if (query == NULL) {
355                 LOGE("out of memory");
356                 return PMINFO_R_ERROR;
357         }
358
359         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
360         sqlite3_free(query);
361         if (ret != SQLITE_OK) {
362                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
363                 return PMINFO_R_ERROR;
364         }
365
366         while (sqlite3_step(stmt) == SQLITE_ROW) {
367                 info = calloc(1, sizeof(splashscreen_x));
368                 if (info == NULL) {
369                         LOGE("out of memory");
370                         sqlite3_finalize(stmt);
371                         return PMINFO_R_ERROR;
372                 }
373                 idx = 0;
374                 _save_column_str(stmt, idx++, &info->src);
375                 _save_column_str(stmt, idx++, &info->type);
376                 _save_column_str(stmt, idx++, &info->orientation);
377                 _save_column_str(stmt, idx++, &info->indicatordisplay);
378                 _save_column_str(stmt, idx++, &info->operation);
379                 _save_column_str(stmt, idx++, &info->color_depth);
380                 *splashscreens = g_list_append(*splashscreens, info);
381         }
382
383         sqlite3_finalize(stmt);
384
385         return PMINFO_R_OK;
386 }
387
388 static GList *__get_background_category(const char *value)
389 {
390         GList *category_list = NULL;
391         int convert_value = 0;
392         if (!value || strlen(value) == 0)
393                 return NULL;
394
395         convert_value = atoi(value);
396         if (convert_value < 0)
397                 return NULL;
398
399         if (convert_value & APP_BG_CATEGORY_USER_DISABLE_TRUE_VAL)
400                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_TRUE_STR));
401         else
402                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_FALSE_STR));
403
404         if (convert_value & APP_BG_CATEGORY_MEDIA_VAL)
405                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_MEDIA_STR));
406
407         if (convert_value & APP_BG_CATEGORY_DOWNLOAD_VAL)
408                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_DOWNLOAD_STR));
409
410         if (convert_value & APP_BG_CATEGORY_BGNETWORK_VAL)
411                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_BGNETWORK_STR));
412
413         if (convert_value & APP_BG_CATEGORY_LOCATION_VAL)
414                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_LOCATION_STR));
415
416         if (convert_value & APP_BG_CATEGORY_SENSOR_VAL)
417                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SENSOR_STR));
418
419         if (convert_value & APP_BG_CATEGORY_IOTCOMM_VAL)
420                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_IOTCOMM_STR));
421
422         if (convert_value & APP_BG_CATEGORY_SYSTEM_VAL)
423                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SYSTEM));
424
425         return category_list;
426
427 }
428
429 static int __get_appinfo_for_uid(sqlite3 *db, application_x *info, uid_t uid)
430 {
431         static const char query_raw[] =
432                 "SELECT is_splash_screen_enabled, is_disabled "
433                 "FROM package_app_info_for_uid WHERE app_id='%s' AND uid='%d'";
434         int ret;
435         char *query;
436         char *is_disabled = NULL;
437         sqlite3_stmt *stmt;
438
439         query = sqlite3_mprintf(query_raw, info->appid, uid);
440         if (query == NULL) {
441                 LOGE("out of memory");
442                 return PMINFO_R_ERROR;
443         }
444
445         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
446         sqlite3_free(query);
447         if (ret != SQLITE_OK) {
448                 LOGE("sqlite3_prepare_v2() failed: %s", sqlite3_errmsg(db));
449                 return PMINFO_R_ERROR;
450         }
451
452         while (sqlite3_step(stmt) == SQLITE_ROW) {
453                 if (info->splash_screen_display)
454                         free(info->splash_screen_display);
455                 _save_column_str(stmt, 0, &info->splash_screen_display);
456                 if (strcasecmp(info->is_disabled, "false") == 0) {
457                         _save_column_str(stmt, 1, &is_disabled);
458                         if (strcasecmp(is_disabled, "true") == 0) {
459                                 free(info->is_disabled);
460                                 info->is_disabled = is_disabled;
461                         } else {
462                                 free(is_disabled);
463                         }
464                 }
465         }
466
467         sqlite3_finalize(stmt);
468         return PMINFO_R_OK;
469 }
470
471 static void __free_applications(gpointer data)
472 {
473         pkgmgrinfo_basic_free_application((application_x *)data);
474 }
475
476 static gint __app_disable_chk_func(gconstpointer data1, gconstpointer data2)
477 {
478         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data1;
479
480         if (node->prop == E_PMINFO_APPINFO_PROP_APP_DISABLE)
481                 return 0;
482         else
483                 return 1;
484 }
485
486 static bool __check_disable_filter_exist(pkgmgrinfo_filter_x *filter)
487 {
488         GSList *link;
489
490         if (filter == NULL)
491                 return false;
492
493         link = g_slist_find_custom(filter->list, NULL, __app_disable_chk_func);
494         if (link)
495                 return true;
496
497         return false;
498 }
499
500 static int __bind_params(sqlite3_stmt *stmt, GList *params)
501 {
502         GList *tmp_list = NULL;
503         int idx = 0;
504         int ret;
505
506         if (stmt == NULL || params == NULL)
507                 return PMINFO_R_EINVAL;
508
509         tmp_list = params;
510         while (tmp_list) {
511                 ret = sqlite3_bind_text(stmt, ++idx, (char *)tmp_list->data, -1, SQLITE_STATIC);
512                 if (ret != SQLITE_OK)
513                         return PMINFO_R_ERROR;
514                 tmp_list = tmp_list->next;
515         }
516
517         return PMINFO_R_OK;
518 }
519
520 static bool __check_app_storage_status(pkgmgrinfo_filter_x *tmp_filter)
521 {
522         GSList *tmp_list = NULL;
523         pkgmgrinfo_node_x *tmp_node = NULL;
524         int property = -1;
525
526         if (tmp_filter == NULL)
527                 return true;
528
529         property = _pminfo_appinfo_convert_to_prop_bool(PMINFO_APPINFO_PROP_APP_CHECK_STORAGE);
530         for (tmp_list = tmp_filter->list; tmp_list != NULL;
531                         tmp_list = g_slist_next(tmp_list)) {
532                 tmp_node = (pkgmgrinfo_node_x *)tmp_list->data;
533                 if (property == tmp_node->prop) {
534                         if (strcmp(tmp_node->value, "true") == 0)
535                                 return true;
536                         else
537                                 return false;
538                 }
539         }
540
541         return true;
542 }
543
544 static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
545                 const char *locale, pkgmgrinfo_filter_x *filter, int flag,
546                 GHashTable *applications)
547 {
548         static const char query_raw[] =
549                 "SELECT DISTINCT ai.app_id, ai.app_component, ai.app_exec, "
550                 "ai.app_nodisplay, ai.app_type, ai.app_onboot, "
551                 "ai.app_multiple, ai.app_autorestart, ai.app_taskmanage, "
552                 "ai.app_hwacceleration, ai.app_screenreader, "
553                 "ai.app_mainapp, ai.app_recentimage, ai.app_launchcondition, "
554                 "ai.app_indicatordisplay, ai.app_portraitimg, "
555                 "ai.app_landscapeimg, ai.app_guestmodevisibility, "
556                 "ai.app_permissiontype, ai.app_preload, ai.app_submode, "
557                 "ai.app_submode_mainid, ai.app_launch_mode, ai.app_ui_gadget, "
558                 "ai.app_support_disable, ai.app_process_pool, "
559                 "ai.app_installed_storage, ai.app_background_category, "
560                 "ai.app_package_type, ai.app_root_path, ai.app_api_version, "
561                 "ai.app_effective_appid, ai.app_disable, "
562                 "ai.app_splash_screen_display, ai.app_tep_name, "
563                 "ai.app_zip_mount_file, ai.component_type, ai.package, "
564                 "ai.app_external_path, ai.app_package_system, ai.app_removable, "
565                 "ai.app_package_installed_time, ai.app_support_mode, "
566                 "ai.app_support_ambient, ai.app_setup_appid";
567         static const char query_label[] =
568                 ", COALESCE("
569                 "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
570                 "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))";
571         static const char query_icon[] =
572                 ", COALESCE("
573                 "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
574                 "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))";
575         static const char query_from_clause[] = " FROM package_app_info as ai";
576         int ret = PMINFO_R_ERROR;
577         int idx;
578         int len = 0;
579         char *dbpath;
580         char *bg_category_str = NULL;
581         char *constraint = NULL;
582         char *tmp_record = NULL;
583         char query[MAX_QUERY_LEN] = { '\0' };
584         application_x *info = NULL;
585         GList *bind_params = NULL;
586         sqlite3 *db = NULL;
587         sqlite3_stmt *stmt = NULL;
588         bool is_check_storage = true;
589
590         dbpath = getUserPkgParserDBPathUID(db_uid);
591         if (dbpath == NULL)
592                 return PMINFO_R_ERROR;
593
594         ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
595         if (ret != SQLITE_OK) {
596                 _LOGE("failed to open db: %d", ret);
597                 free(dbpath);
598                 return PMINFO_R_ERROR;
599         }
600         free(dbpath);
601
602         len = strlen(query_raw);
603         snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
604         if (flag & PMINFO_APPINFO_GET_LABEL) {
605                 strncat(query, query_label, MAX_QUERY_LEN - len - 1);
606                 len += strlen(query_label);
607                 bind_params = g_list_append(bind_params, strdup(locale));
608         }
609         if (flag & PMINFO_APPINFO_GET_ICON) {
610                 strncat(query, query_icon, MAX_QUERY_LEN - len - 1);
611                 len += strlen(query_icon);
612                 bind_params = g_list_append(bind_params, strdup(locale));
613         }
614
615         is_check_storage = __check_app_storage_status(filter);
616
617         ret = _get_filtered_query(filter, locale, uid, &constraint, &bind_params);
618         if (ret != PMINFO_R_OK) {
619                 LOGE("Failed to get WHERE clause");
620                 goto catch;
621         }
622         strncat(query, query_from_clause, MAX_QUERY_LEN - len - 1);
623         len += strlen(query_from_clause);
624
625         if (constraint)
626                 strncat(query, constraint, MAX_QUERY_LEN - len - 1);
627
628         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
629         if (ret != SQLITE_OK) {
630                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
631                 ret = PMINFO_R_ERROR;
632                 goto catch;
633         }
634
635         if (g_list_length(bind_params) != 0) {
636                 ret = __bind_params(stmt, bind_params);
637                 if (ret != SQLITE_OK) {
638                         LOGE("Failed to bind parameters");
639                         goto catch;
640                 }
641         }
642
643         while (sqlite3_step(stmt) == SQLITE_ROW) {
644                 info = calloc(1, sizeof(application_x));
645                 if (info == NULL) {
646                         LOGE("out of memory");
647                         ret = PMINFO_R_ERROR;
648                         goto catch;
649                 }
650                 idx = 0;
651                 _save_column_str(stmt, idx++, &info->appid);
652                 if (g_hash_table_contains(applications,
653                                         (gconstpointer)info->appid)) {
654                         free(info->appid);
655                         free(info);
656                         info = NULL;
657                         continue;
658                 }
659                 _save_column_str(stmt, idx++, &info->component);
660                 _save_column_str(stmt, idx++, &info->exec);
661                 _save_column_str(stmt, idx++, &info->nodisplay);
662                 _save_column_str(stmt, idx++, &info->type);
663                 _save_column_str(stmt, idx++, &info->onboot);
664                 _save_column_str(stmt, idx++, &info->multiple);
665                 _save_column_str(stmt, idx++, &info->autorestart);
666                 _save_column_str(stmt, idx++, &info->taskmanage);
667                 _save_column_str(stmt, idx++, &info->hwacceleration);
668                 _save_column_str(stmt, idx++, &info->screenreader);
669                 _save_column_str(stmt, idx++, &info->mainapp);
670                 _save_column_str(stmt, idx++, &info->recentimage);
671                 _save_column_str(stmt, idx++, &info->launchcondition);
672                 _save_column_str(stmt, idx++, &info->indicatordisplay);
673                 _save_column_str(stmt, idx++, &info->portraitimg);
674                 _save_column_str(stmt, idx++, &info->landscapeimg);
675                 _save_column_str(stmt, idx++, &info->guestmode_visibility);
676                 _save_column_str(stmt, idx++, &info->permission_type);
677                 _save_column_str(stmt, idx++, &info->preload);
678                 _save_column_str(stmt, idx++, &info->submode);
679                 _save_column_str(stmt, idx++, &info->submode_mainid);
680                 _save_column_str(stmt, idx++, &info->launch_mode);
681                 _save_column_str(stmt, idx++, &info->ui_gadget);
682                 _save_column_str(stmt, idx++, &info->support_disable);
683                 _save_column_str(stmt, idx++, &info->process_pool);
684                 _save_column_str(stmt, idx++, &info->installed_storage);
685                 _save_column_str(stmt, idx++, &bg_category_str);
686                 _save_column_str(stmt, idx++, &info->package_type);
687                 _save_column_str(stmt, idx++, &info->root_path);
688                 _save_column_str(stmt, idx++, &info->api_version);
689                 _save_column_str(stmt, idx++, &info->effective_appid);
690                 _save_column_str(stmt, idx++, &info->is_disabled);
691                 _save_column_str(stmt, idx++, &info->splash_screen_display);
692                 _save_column_str(stmt, idx++, &info->tep_name);
693                 _save_column_str(stmt, idx++, &info->zip_mount_file);
694                 _save_column_str(stmt, idx++, &info->component_type);
695                 _save_column_str(stmt, idx++, &info->package);
696                 _save_column_str(stmt, idx++, &info->external_path);
697                 _save_column_str(stmt, idx++, &info->package_system);
698                 _save_column_str(stmt, idx++, &info->removable);
699                 _save_column_str(stmt, idx++, &info->package_installed_time);
700                 _save_column_str(stmt, idx++, &info->support_mode);
701                 _save_column_str(stmt, idx++, &info->support_ambient);
702                 _save_column_str(stmt, idx++, &info->setup_appid);
703
704                 info->for_all_users =
705                         strdup((db_uid != GLOBAL_USER) ? "false" : "true");
706
707                 if (db_uid == GLOBAL_USER) {
708                         ret = __get_appinfo_for_uid(db, info, uid);
709                         if (ret != PMINFO_R_OK) {
710                                 LOGI("Failed to get appinfo for given uid[%d]", (int)uid);
711                                 pkgmgrinfo_basic_free_application(info);
712                                 info = NULL;
713                                 continue;
714                         }
715                 }
716
717                 info->background_category = __get_background_category(
718                                 bg_category_str);
719                 free(bg_category_str);
720
721                 if (flag & PMINFO_APPINFO_GET_LABEL) {
722                         tmp_record = NULL;
723                         _save_column_str(stmt, idx++, &tmp_record);
724                         if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
725                                 ret = PMINFO_R_ERROR;
726                                 goto catch;
727                         }
728                 }
729
730                 if (flag & PMINFO_APPINFO_GET_ICON) {
731                         tmp_record = NULL;
732                         _save_column_str(stmt, idx++, &tmp_record);
733                         if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
734                                 ret = PMINFO_R_ERROR;
735                                 goto catch;
736                         }
737                 }
738
739                 if (flag & PMINFO_APPINFO_GET_CATEGORY) {
740                         if (_appinfo_get_category(db, info->appid,
741                                                 &info->category)) {
742                                 ret = PMINFO_R_ERROR;
743                                 goto catch;
744                         }
745                 }
746
747                 if (flag & PMINFO_APPINFO_GET_APP_CONTROL) {
748                         if (_appinfo_get_app_control(db, info->appid,
749                                                 &info->appcontrol)) {
750                                 ret = PMINFO_R_ERROR;
751                                 goto catch;
752                         }
753                 }
754
755                 if (flag & PMINFO_APPINFO_GET_DATA_CONTROL) {
756                         if (_appinfo_get_data_control(db, info->appid,
757                                                 &info->datacontrol)) {
758                                 ret = PMINFO_R_ERROR;
759                                 goto catch;
760                         }
761                 }
762
763                 if (flag & PMINFO_APPINFO_GET_METADATA) {
764                         if (_appinfo_get_metadata(db, info->appid,
765                                                 &info->metadata)) {
766                                 ret = PMINFO_R_ERROR;
767                                 goto catch;
768                         }
769                 }
770
771                 if (flag & PMINFO_APPINFO_GET_SPLASH_SCREEN) {
772                         if (_appinfo_get_splashscreens(db, info->appid,
773                                                 &info->splashscreens)) {
774                                 ret = PMINFO_R_ERROR;
775                                 goto catch;
776                         }
777                 }
778
779                 if (is_check_storage &&
780                                 __appinfo_check_installed_storage(info) != PMINFO_R_OK) {
781                         ret = PMINFO_R_ERROR;
782                         pkgmgrinfo_basic_free_application(info);
783                         info = NULL;
784                         continue;
785                 }
786
787                 g_hash_table_insert(applications, (gpointer)info->appid,
788                                 (gpointer)info);
789         }
790
791         ret = PMINFO_R_OK;
792
793 catch:
794         if (constraint)
795                 free(constraint);
796
797         if (ret != PMINFO_R_OK && info != NULL)
798                 pkgmgrinfo_basic_free_application(info);
799
800         g_list_free_full(bind_params, free);
801         sqlite3_close_v2(db);
802         sqlite3_finalize(stmt);
803
804         return ret;
805 }
806
807 static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
808         pkgmgrinfo_appinfo_filter_h filter, pkgmgrinfo_appinfo_h *handle)
809 {
810         int ret;
811         char *locale;
812         GHashTable *list;
813         pkgmgr_appinfo_x *info;
814
815         if (appid == NULL || filter == NULL || handle == NULL) {
816                         LOGE("invalid parameter");
817                         return PMINFO_R_EINVAL;
818         }
819
820         locale = _get_system_locale();
821         if (locale == NULL)
822                 return PMINFO_R_ERROR;
823
824         list = g_hash_table_new(g_str_hash, g_str_equal);
825         if (list == NULL) {
826                 free(locale);
827                 return PMINFO_R_ERROR;
828         }
829
830         ret = _appinfo_get_applications(uid, uid, locale, filter,
831                         PMINFO_APPINFO_GET_ALL, list);
832         if (!g_hash_table_size(list) && uid != GLOBAL_USER)
833                 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, filter,
834                                 PMINFO_APPINFO_GET_ALL, list);
835
836         if (!g_hash_table_size(list)) {
837                 _LOGI("appinfo for [%s] is not existed for user [%d]",
838                                 appid, uid);
839                 g_hash_table_destroy(list);
840                 free(locale);
841                 return PMINFO_R_ENOENT;
842         }
843
844         info = calloc(1, sizeof(pkgmgr_appinfo_x));
845         if (info == NULL) {
846                 _LOGE("out of memory");
847                 g_hash_table_destroy(list);
848                 free(locale);
849                 return PMINFO_R_ERROR;
850         }
851
852         info->app_info = (application_x *)g_hash_table_lookup(list, appid);
853         info->locale = locale;
854         info->package = strdup(info->app_info->package);
855
856         /* just free list only */
857         g_hash_table_destroy(list);
858
859         *handle = info;
860
861         return ret;
862 }
863
864 API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid,
865                 pkgmgrinfo_appinfo_h *handle)
866 {
867         int ret;
868         pkgmgrinfo_appinfo_filter_h filter;
869
870         if (appid == NULL || handle == NULL) {
871                 LOGE("invalid parameter");
872                 return PMINFO_R_EINVAL;
873         }
874
875         ret = pkgmgrinfo_appinfo_filter_create(&filter);
876         if (ret != PMINFO_R_OK)
877                 return ret;
878
879         ret = pkgmgrinfo_appinfo_filter_add_string(filter,
880                         PMINFO_APPINFO_PROP_APP_ID, appid);
881         if (ret != PMINFO_R_OK) {
882                 pkgmgrinfo_appinfo_filter_destroy(filter);
883                 return PMINFO_R_ERROR;
884         }
885
886         ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
887                         PMINFO_APPINFO_PROP_APP_DISABLE, true);
888         if (ret != PMINFO_R_OK) {
889                 pkgmgrinfo_appinfo_filter_destroy(filter);
890                 return PMINFO_R_ERROR;
891         }
892
893         ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
894         pkgmgrinfo_appinfo_filter_destroy(filter);
895
896         return ret;
897 }
898
899 API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
900 {
901         return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, _getuid(), handle);
902 }
903
904 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
905                 pkgmgrinfo_appinfo_h *handle)
906 {
907         int ret;
908         pkgmgrinfo_appinfo_filter_h filter;
909
910         if (appid == NULL || handle == NULL) {
911                 LOGE("invalid parameter");
912                 return PMINFO_R_EINVAL;
913         }
914
915         ret = pkgmgrinfo_appinfo_filter_create(&filter);
916         if (ret != PMINFO_R_OK)
917                 return ret;
918
919         ret = pkgmgrinfo_appinfo_filter_add_string(filter,
920                         PMINFO_APPINFO_PROP_APP_ID, appid);
921         if (ret != PMINFO_R_OK) {
922                 pkgmgrinfo_appinfo_filter_destroy(filter);
923                 return PMINFO_R_ERROR;
924         }
925
926         ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
927                         PMINFO_APPINFO_PROP_APP_DISABLE, false);
928         if (ret != PMINFO_R_OK) {
929                 pkgmgrinfo_appinfo_filter_destroy(filter);
930                 return PMINFO_R_ERROR;
931         }
932
933         ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
934         pkgmgrinfo_appinfo_filter_destroy(filter);
935         return ret;
936 }
937
938 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
939 {
940         return pkgmgrinfo_appinfo_get_usr_appinfo(appid, _getuid(), handle);
941 }
942
943 API int pkgmgrinfo_appinfo_get_usr_all_appinfo(const char *appid, uid_t uid,
944                 pkgmgrinfo_appinfo_h *handle)
945 {
946         int ret;
947         pkgmgrinfo_appinfo_filter_h filter;
948
949         if (appid == NULL || handle == NULL) {
950                 LOGE("invalid parameter");
951                 return PMINFO_R_EINVAL;
952         }
953
954         ret = pkgmgrinfo_appinfo_filter_create(&filter);
955         if (ret != PMINFO_R_OK)
956                 return ret;
957
958         ret = pkgmgrinfo_appinfo_filter_add_string(filter,
959                         PMINFO_APPINFO_PROP_APP_ID, appid);
960         if (ret != PMINFO_R_OK) {
961                 pkgmgrinfo_appinfo_filter_destroy(filter);
962                 return PMINFO_R_ERROR;
963         }
964
965         ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
966                         PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false);
967         if (ret != PMINFO_R_OK) {
968                 pkgmgrinfo_appinfo_filter_destroy(filter);
969                 return PMINFO_R_ERROR;
970         }
971
972         ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
973         pkgmgrinfo_appinfo_filter_destroy(filter);
974
975         return ret;
976 }
977
978 API int pkgmgrinfo_appinfo_get_all_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
979 {
980         return pkgmgrinfo_appinfo_get_usr_all_appinfo(appid, _getuid(), handle);
981 }
982
983 static gpointer __copy_str(gconstpointer src, gpointer data)
984 {
985         const char *tmp = (const char *)src;
986         char *buffer;
987
988         buffer = strdup(tmp);
989         if (buffer == NULL) {
990                 LOGE("memory alloc failed");
991                 *(int *)data = -1;
992                 return NULL;
993         }
994
995         return buffer;
996 }
997
998 static gpointer __copy_label(gconstpointer src, gpointer data)
999 {
1000         label_x *tmp = (label_x *)src;
1001         label_x *label;
1002
1003         label = calloc(1, sizeof(label_x));
1004         if (label == NULL) {
1005                 LOGE("memory alloc failed");
1006                 *(int *)data = -1;
1007                 return NULL;
1008         }
1009
1010         if (tmp->name)
1011                 label->name = strdup(tmp->name);
1012         if (tmp->text)
1013                 label->text = strdup(tmp->text);
1014         if (tmp->lang)
1015                 label->lang = strdup(tmp->lang);
1016
1017         return label;
1018 }
1019
1020 static gpointer __copy_icon(gconstpointer src, gpointer data)
1021 {
1022         icon_x *tmp = (icon_x *)src;
1023         icon_x *icon;
1024
1025         icon = calloc(1, sizeof(icon_x));
1026         if (icon == NULL) {
1027                 LOGE("memory alloc failed");
1028                 *(int *)data = -1;
1029                 return NULL;
1030         }
1031
1032         if (tmp->text)
1033                 icon->text = strdup(tmp->text);
1034         if (tmp->lang)
1035                 icon->lang = strdup(tmp->lang);
1036         if (tmp->section)
1037                 icon->section = strdup(tmp->section);
1038         if (tmp->size)
1039                 icon->size = strdup(tmp->size);
1040         if (tmp->resolution)
1041                 icon->resolution = strdup(tmp->resolution);
1042
1043         return icon;
1044 }
1045
1046 static gpointer __copy_metadata(gconstpointer src, gpointer data)
1047 {
1048         metadata_x *tmp = (metadata_x *)src;
1049         metadata_x *metadata;
1050
1051         metadata = calloc(1, sizeof(metadata_x));
1052         if (metadata == NULL) {
1053                 LOGE("memory alloc failed");
1054                 *(int *)data = -1;
1055                 return NULL;
1056         }
1057
1058         if (tmp->key)
1059                 metadata->key = strdup(tmp->key);
1060         if (tmp->value)
1061                 metadata->value = strdup(tmp->value);
1062
1063         return metadata;
1064 }
1065
1066 static gpointer __copy_datacontrol(gconstpointer src, gpointer data)
1067 {
1068         datacontrol_x *tmp = (datacontrol_x *)src;
1069         datacontrol_x *datacontrol;
1070
1071         datacontrol = calloc(1, sizeof(datacontrol_x));
1072         if (datacontrol == NULL) {
1073                 LOGE("memory alloc failed");
1074                 *(int *)data = -1;
1075                 return NULL;
1076         }
1077
1078         if (tmp->providerid)
1079                 datacontrol->providerid = strdup(tmp->providerid);
1080         if (tmp->access)
1081                 datacontrol->access = strdup(tmp->access);
1082         if (tmp->type)
1083                 datacontrol->type = strdup(tmp->type);
1084
1085         return datacontrol;
1086 }
1087
1088 static gpointer __copy_appcontrol(gconstpointer src, gpointer data)
1089 {
1090         appcontrol_x *tmp = (appcontrol_x *)src;
1091         appcontrol_x *appcontrol;
1092
1093         appcontrol = calloc(1, sizeof(appcontrol_x));
1094         if (appcontrol == NULL) {
1095                 LOGE("memory alloc failed");
1096                 *(int *)data = -1;
1097                 return NULL;
1098         }
1099
1100         if (tmp->operation)
1101                 appcontrol->operation = strdup(tmp->operation);
1102         if (tmp->uri)
1103                 appcontrol->uri = strdup(tmp->uri);
1104         if (tmp->mime)
1105                 appcontrol->mime = strdup(tmp->mime);
1106
1107         return appcontrol;
1108 }
1109
1110 static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
1111 {
1112         splashscreen_x *tmp = (splashscreen_x *)src;
1113         splashscreen_x *splashscreen;
1114
1115         splashscreen = (splashscreen_x *)calloc(1, sizeof(splashscreen_x));
1116         if (splashscreen == NULL) {
1117                 LOGE("memory alloc failed");
1118                 *(int *)data = -1;
1119                 return NULL;
1120         }
1121
1122         if (tmp->src)
1123                 splashscreen->src = strdup(tmp->src);
1124         if (tmp->type)
1125                 splashscreen->type = strdup(tmp->type);
1126         if (tmp->orientation)
1127                 splashscreen->orientation = strdup(tmp->orientation);
1128         if (tmp->indicatordisplay)
1129                 splashscreen->indicatordisplay = strdup(tmp->indicatordisplay);
1130         if (tmp->operation)
1131                 splashscreen->operation = strdup(tmp->operation);
1132         if (tmp->color_depth)
1133                 splashscreen->color_depth = strdup(tmp->color_depth);
1134
1135         return splashscreen;
1136 }
1137
1138 static int _appinfo_copy_appinfo(application_x **application, application_x *data)
1139 {
1140         application_x *app_info;
1141         int ret;
1142
1143         app_info = calloc(1, sizeof(application_x));
1144         if (app_info == NULL) {
1145                 LOGE("memory alloc failed");
1146                 return PMINFO_R_ERROR;
1147         }
1148
1149         if (data->appid != NULL)
1150                 app_info->appid = strdup(data->appid);
1151         if (data->exec != NULL)
1152                 app_info->exec = strdup(data->exec);
1153         if (data->nodisplay != NULL)
1154                 app_info->nodisplay = strdup(data->nodisplay);
1155         if (data->multiple != NULL)
1156                 app_info->multiple = strdup(data->multiple);
1157         if (data->taskmanage != NULL)
1158                 app_info->taskmanage = strdup(data->taskmanage);
1159         if (data->type != NULL)
1160                 app_info->type = strdup(data->type);
1161         if (data->categories != NULL)
1162                 app_info->categories = strdup(data->categories);
1163         if (data->hwacceleration != NULL)
1164                 app_info->hwacceleration = strdup(data->hwacceleration);
1165         if (data->screenreader != NULL)
1166                 app_info->screenreader = strdup(data->screenreader);
1167         if (data->mainapp != NULL)
1168                 app_info->mainapp = strdup(data->mainapp);
1169         if (data->package != NULL)
1170                 app_info->package = strdup(data->package);
1171         if (data->recentimage != NULL)
1172                 app_info->recentimage = strdup(data->recentimage);
1173         if (data->launchcondition != NULL)
1174                 app_info->launchcondition = strdup(data->launchcondition);
1175         if (data->indicatordisplay != NULL)
1176                 app_info->indicatordisplay = strdup(data->indicatordisplay);
1177         if (data->portraitimg != NULL)
1178                 app_info->portraitimg = strdup(data->portraitimg);
1179         if (data->landscapeimg != NULL)
1180                 app_info->landscapeimg = strdup(data->landscapeimg);
1181         if (data->guestmode_visibility != NULL)
1182                 app_info->guestmode_visibility = strdup(data->guestmode_visibility);
1183         if (data->component != NULL)
1184                 app_info->component = strdup(data->component);
1185         if (data->permission_type != NULL)
1186                 app_info->permission_type = strdup(data->permission_type);
1187         if (data->component_type != NULL)
1188                 app_info->component_type = strdup(data->component_type);
1189         if (data->preload != NULL)
1190                 app_info->preload = strdup(data->preload);
1191         if (data->submode != NULL)
1192                 app_info->submode = strdup(data->submode);
1193         if (data->submode_mainid != NULL)
1194                 app_info->submode_mainid = strdup(data->submode_mainid);
1195         if (data->process_pool != NULL)
1196                 app_info->process_pool = strdup(data->process_pool);
1197         if (data->installed_storage != NULL)
1198                 app_info->installed_storage = strdup(data->installed_storage);
1199         if (data->autorestart != NULL)
1200                 app_info->autorestart = strdup(data->autorestart);
1201         if (data->onboot != NULL)
1202                 app_info->onboot = strdup(data->onboot);
1203         if (data->support_disable != NULL)
1204                 app_info->support_disable = strdup(data->support_disable);
1205         if (data->ui_gadget != NULL)
1206                 app_info->ui_gadget = strdup(data->ui_gadget);
1207         if (data->launch_mode != NULL)
1208                 app_info->launch_mode = strdup(data->launch_mode);
1209         if (data->package_type != NULL)
1210                 app_info->package_type = strdup(data->package_type);
1211         if (data->effective_appid != NULL)
1212                 app_info->effective_appid = strdup(data->effective_appid);
1213         if (data->splash_screen_display != NULL)
1214                 app_info->splash_screen_display = strdup(data->splash_screen_display);
1215
1216         /* GList */
1217         ret = 0;
1218         app_info->label = g_list_copy_deep(data->label, __copy_label, &ret);
1219         if (ret < 0) {
1220                 LOGE("memory alloc failed");
1221                 pkgmgrinfo_basic_free_application(app_info);
1222                 return PMINFO_R_ERROR;
1223         }
1224
1225         ret = 0;
1226         app_info->icon = g_list_copy_deep(data->icon, __copy_icon, &ret);
1227         if (ret < 0) {
1228                 LOGE("memory alloc failed");
1229                 pkgmgrinfo_basic_free_application(app_info);
1230                 return PMINFO_R_ERROR;
1231         }
1232
1233         ret = 0;
1234         app_info->category = g_list_copy_deep(data->category, __copy_str, &ret);
1235         if (ret < 0) {
1236                 LOGE("memory alloc failed");
1237                 pkgmgrinfo_basic_free_application(app_info);
1238                 return PMINFO_R_ERROR;
1239         }
1240
1241         ret = 0;
1242         app_info->metadata = g_list_copy_deep(data->metadata, __copy_metadata, &ret);
1243         if (ret < 0) {
1244                 LOGE("memory alloc failed");
1245                 pkgmgrinfo_basic_free_application(app_info);
1246                 return PMINFO_R_ERROR;
1247         }
1248
1249         ret = 0;
1250         app_info->datacontrol = g_list_copy_deep(data->datacontrol, __copy_datacontrol, &ret);
1251         if (ret < 0) {
1252                 LOGE("memory alloc failed");
1253                 pkgmgrinfo_basic_free_application(app_info);
1254                 return PMINFO_R_ERROR;
1255         }
1256
1257         ret = 0;
1258         app_info->appcontrol = g_list_copy_deep(data->appcontrol, __copy_appcontrol, &ret);
1259         if (ret < 0) {
1260                 LOGE("memory alloc failed");
1261                 pkgmgrinfo_basic_free_application(app_info);
1262                 return PMINFO_R_ERROR;
1263         }
1264
1265         ret = 0;
1266         app_info->background_category = g_list_copy_deep(data->background_category, __copy_str, &ret);
1267         if (ret < 0) {
1268                 LOGE("memory alloc failed");
1269                 pkgmgrinfo_basic_free_application(app_info);
1270                 return PMINFO_R_ERROR;
1271         }
1272
1273         ret = 0;
1274         app_info->splashscreens = g_list_copy_deep(data->splashscreens, __copy_splashscreens, &ret);
1275         if (ret < 0) {
1276                 LOGE("memory alloc failed");
1277                 pkgmgrinfo_basic_free_application(app_info);
1278                 return PMINFO_R_ERROR;
1279         }
1280
1281         *application = app_info;
1282
1283         return PMINFO_R_OK;
1284 }
1285
1286 API int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h handle,
1287                 pkgmgrinfo_appinfo_h *clone)
1288 {
1289         pkgmgr_appinfo_x *info;
1290         pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
1291
1292         if (handle == NULL)
1293                 return PMINFO_R_EINVAL;
1294
1295         info = calloc(1, sizeof(pkgmgr_appinfo_x));
1296         if (info == NULL) {
1297                 LOGE("memory alloc failed");
1298                 return PMINFO_R_ERROR;
1299         }
1300
1301         if (temp->package != NULL)
1302                 info->package = strdup(temp->package);
1303         if (temp->locale != NULL)
1304                 info->locale = strdup(temp->locale);
1305
1306         info->app_component = temp->app_component;
1307
1308         if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
1309                 LOGE("appinfo copy failed");
1310                 if (info->package)
1311                         free((void *)info->package);
1312                 if (info->locale)
1313                         free(info->locale);
1314                 free(info);
1315                 return PMINFO_R_ERROR;
1316         }
1317
1318         *clone = info;
1319
1320         return PMINFO_R_OK;
1321 }
1322
1323 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
1324                 pkgmgrinfo_filter_x *filter, int flag, pkgmgrinfo_app_list_cb app_list_cb,
1325                 void *user_data)
1326 {
1327         int ret;
1328         char *locale;
1329         application_x *app;
1330         pkgmgr_appinfo_x info;
1331         GHashTable *list;
1332         GHashTableIter iter;
1333         gpointer value;
1334
1335         locale = _get_system_locale();
1336         if (locale == NULL)
1337                 return PMINFO_R_ERROR;
1338
1339         list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1340                         __free_applications);
1341         if (list == NULL) {
1342                 free(locale);
1343                 return PMINFO_R_ERROR;
1344         }
1345
1346         if (__check_disable_filter_exist(filter) == false) {
1347                 pkgmgrinfo_appinfo_filter_add_bool(filter,
1348                                 PMINFO_APPINFO_PROP_APP_DISABLE, false);
1349         }
1350
1351         ret = _appinfo_get_applications(uid, uid, locale, filter, flag, list);
1352         if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1353                 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
1354                                 filter, flag, list);
1355
1356         if (ret != PMINFO_R_OK) {
1357                 g_hash_table_destroy(list);
1358                 free(locale);
1359                 return ret;
1360         }
1361
1362         g_hash_table_iter_init(&iter, list);
1363         while (g_hash_table_iter_next(&iter, NULL, &value)) {
1364                 app = (application_x *)value;
1365                 info.app_info = app;
1366                 info.locale = locale;
1367                 info.package = app->package;
1368                 if (app_list_cb(&info, user_data) < 0)
1369                         break;
1370         }
1371         g_hash_table_destroy(list);
1372         free(locale);
1373
1374         return PMINFO_R_OK;
1375 }
1376
1377 static const char *__appcomponent_str(pkgmgrinfo_app_component comp);
1378
1379 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
1380                 pkgmgrinfo_app_component component,
1381                 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
1382 {
1383         int ret;
1384         pkgmgrinfo_appinfo_filter_h filter;
1385         char *pkgid;
1386         const char *comp_str = NULL;
1387
1388         if (handle == NULL || app_func == NULL) {
1389                 LOGE("invalid parameter");
1390                 return PMINFO_R_EINVAL;
1391         }
1392
1393         if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
1394                 LOGE("invalid parameter");
1395                 return PMINFO_R_EINVAL;
1396         }
1397
1398         if (pkgmgrinfo_appinfo_filter_create(&filter))
1399                 return PMINFO_R_ERROR;
1400
1401         if (pkgmgrinfo_appinfo_filter_add_string(filter,
1402                                 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
1403                 pkgmgrinfo_appinfo_filter_destroy(filter);
1404                 return PMINFO_R_ERROR;
1405         }
1406
1407         comp_str = __appcomponent_str(component);
1408
1409         if (comp_str) {
1410                 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1411                                         PMINFO_APPINFO_PROP_APP_COMPONENT,
1412                                         comp_str)) {
1413                         pkgmgrinfo_appinfo_filter_destroy(filter);
1414                         return PMINFO_R_ERROR;
1415                 }
1416         }
1417
1418         ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1419                         PMINFO_APPINFO_GET_ALL, app_func, user_data);
1420
1421         pkgmgrinfo_appinfo_filter_destroy(filter);
1422
1423         return ret;
1424 }
1425
1426 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle,
1427                 pkgmgrinfo_app_component component,
1428                 pkgmgrinfo_app_list_cb app_func, void *user_data)
1429 {
1430         return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, _getuid());
1431 }
1432
1433 API int pkgmgrinfo_appinfo_get_usr_installed_list_full(
1434                 pkgmgrinfo_app_list_cb app_func, uid_t uid, int flag,
1435                 void *user_data)
1436 {
1437         int ret;
1438         pkgmgrinfo_appinfo_filter_h filter;
1439
1440         if (app_func == NULL) {
1441                 LOGE("invalid parameter");
1442                 return PMINFO_R_EINVAL;
1443         }
1444
1445         if (pkgmgrinfo_appinfo_filter_create(&filter))
1446                 return PMINFO_R_ERROR;
1447
1448         if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1449                                 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1450                 pkgmgrinfo_appinfo_filter_destroy(filter);
1451                 return PMINFO_R_ERROR;
1452         }
1453
1454         if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1455                         PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false)) {
1456                 pkgmgrinfo_appinfo_filter_destroy(filter);
1457                 return PMINFO_R_ERROR;
1458         }
1459
1460         ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, flag, app_func,
1461                         user_data);
1462
1463         pkgmgrinfo_appinfo_filter_destroy(filter);
1464
1465         return ret;
1466 }
1467
1468 API int pkgmgrinfo_appinfo_get_installed_list_full(
1469                 pkgmgrinfo_app_list_cb app_func, int flag, void *user_data)
1470 {
1471         return pkgmgrinfo_appinfo_get_usr_installed_list_full(app_func,
1472                         _getuid(), flag, user_data);
1473 }
1474
1475 API int pkgmgrinfo_appinfo_get_usr_installed_list(
1476                 pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1477 {
1478         int ret;
1479         pkgmgrinfo_appinfo_filter_h filter;
1480
1481         if (app_func == NULL) {
1482                 LOGE("invalid parameter");
1483                 return PMINFO_R_EINVAL;
1484         }
1485
1486         /* create an empty filter */
1487         ret = pkgmgrinfo_appinfo_filter_create(&filter);
1488         if (ret != PMINFO_R_OK)
1489                 return ret;
1490
1491         ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1492                         PMINFO_APPINFO_GET_ALL, app_func, user_data);
1493
1494         pkgmgrinfo_appinfo_filter_destroy(filter);
1495
1496         return ret;
1497 }
1498
1499 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func,
1500                 void *user_data)
1501 {
1502         return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, _getuid(),
1503                         user_data);
1504 }
1505
1506 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
1507 {
1508         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1509
1510         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1511         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1512
1513         if (info->app_info == NULL || info->app_info->appid == NULL)
1514                 return PMINFO_R_ERROR;
1515         *appid = (char *)info->app_info->appid;
1516
1517         return PMINFO_R_OK;
1518 }
1519
1520 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
1521 {
1522         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1523
1524         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1525         retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1526
1527         if (info->package == NULL)
1528                 return PMINFO_R_ERROR;
1529
1530         *pkg_name = (char *)info->package;
1531
1532         return PMINFO_R_OK;
1533 }
1534
1535 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
1536 {
1537         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1538
1539         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1540         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1541
1542         if (info->package == NULL)
1543                 return PMINFO_R_ERROR;
1544
1545         *pkgid = (char *)info->package;
1546
1547         return PMINFO_R_OK;
1548 }
1549
1550 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h  handle, char **pkgtype)
1551 {
1552         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1553         retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1554         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1555
1556         *pkgtype = (char *)info->app_info->package_type;
1557
1558         return PMINFO_R_OK;
1559 }
1560
1561 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
1562 {
1563         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1564
1565         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1566         retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1567
1568         if (info->app_info == NULL || info->app_info->exec == NULL)
1569                 return PMINFO_R_ERROR;
1570         *exec = (char *)info->app_info->exec;
1571
1572         return PMINFO_R_OK;
1573 }
1574
1575
1576 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1577 {
1578         icon_x *ptr;
1579         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1580
1581         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1582         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1583
1584         if (info->app_info == NULL)
1585                 return PMINFO_R_ERROR;
1586
1587         if (info->app_info->icon == NULL) {
1588                 *icon = "";
1589                 return PMINFO_R_OK;
1590         }
1591
1592         ptr = (icon_x *)info->app_info->icon->data;
1593         if (ptr == NULL)
1594                 return PMINFO_R_ERROR;
1595
1596         if (ptr->text == NULL)
1597                 return PMINFO_R_ERROR;
1598                 else
1599                         *icon = ptr->text;
1600
1601         return PMINFO_R_OK;
1602 }
1603
1604
1605 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
1606 {
1607         label_x *ptr;
1608         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1609
1610         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1611         retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1612
1613         if (info->app_info == NULL || info->app_info->label == NULL)
1614                 return PMINFO_R_ERROR;
1615
1616         ptr = (label_x *)info->app_info->label->data;
1617         if (ptr == NULL)
1618                 return PMINFO_R_ERROR;
1619
1620         if (ptr->text == NULL)
1621                 return PMINFO_R_ERROR;
1622         else
1623                 *label = ptr->text;
1624
1625         return PMINFO_R_OK;
1626 }
1627
1628 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1629 {
1630         char *result = NULL;
1631         char *query = NULL;
1632         sqlite3_stmt *stmt = NULL;
1633         sqlite3 *db = NULL;
1634         char *val;
1635         char *parser_db;
1636
1637         parser_db = getUserPkgParserDBPathUID(uid);
1638         if (parser_db == NULL) {
1639                 _LOGE("Failed to get parser db path");
1640                 goto err;
1641         }
1642
1643         if (__open_db(parser_db, &db, SQLITE_OPEN_READONLY) != SQLITE_OK) {
1644                 _LOGE("DB open fail\n");
1645                 free(parser_db);
1646                 goto err;
1647         }
1648         free(parser_db);
1649
1650         query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1651         if (query == NULL) {
1652                 _LOGE("Out of memory");
1653                 goto err;
1654         }
1655
1656         if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1657                 _LOGE("prepare_v2 fail\n");
1658                 goto err;
1659         }
1660
1661         if (sqlite3_step(stmt) == SQLITE_ROW) {
1662                 val = (char *)sqlite3_column_text(stmt, 0);
1663                 if (val != NULL)
1664                         result = strdup(val);
1665         }
1666
1667 err:
1668         sqlite3_finalize(stmt);
1669         sqlite3_free(query);
1670         sqlite3_close(db);
1671
1672         return result;
1673 }
1674
1675 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1676 {
1677         char *val;
1678
1679         retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1680
1681         val = _get_localed_label(appid, locale, uid);
1682         if (val == NULL)
1683                 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1684
1685         if (val == NULL) {
1686                 val = _get_localed_label(appid, locale, GLOBAL_USER);
1687                 if (val == NULL)
1688                         val = _get_localed_label(appid, DEFAULT_LOCALE, GLOBAL_USER);
1689         }
1690
1691         if (val == NULL)
1692                 return PMINFO_R_ERROR;
1693
1694         *label = val;
1695
1696         return PMINFO_R_OK;
1697 }
1698
1699 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1700 {
1701         return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, _getuid(), label);
1702 }
1703
1704 API int pkgmgrinfo_appinfo_get_metadata_value(pkgmgrinfo_appinfo_h handle, const char *metadata_key, char **metadata_value)
1705 {
1706         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1707         retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL");
1708         retvm_if(metadata_value == NULL, PMINFO_R_EINVAL, "metadata_value is NULL");
1709
1710         GList *list_md = NULL;
1711         metadata_x *metadata = NULL;
1712         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1713
1714         list_md = info->app_info->metadata;
1715
1716         for (; list_md; list_md = list_md->next) {
1717                 metadata = (metadata_x *)list_md->data;
1718                 if (metadata && metadata->key) {
1719                         if (strcasecmp(metadata->key, metadata_key) == 0) {
1720                                 if (metadata->value == NULL)
1721                                         *metadata_value = "";
1722                                 else
1723                                         *metadata_value = (char *)metadata->value;
1724                                 return PMINFO_R_OK;
1725                         }
1726                 }
1727         }
1728
1729         return PMINFO_R_EINVAL;
1730 }
1731
1732 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1733 {
1734         if (strcasecmp(comp, "uiapp") == 0)
1735                 return PMINFO_UI_APP;
1736         else if (strcasecmp(comp, "svcapp") == 0)
1737                 return PMINFO_SVC_APP;
1738         else if (strcasecmp(comp, "widgetapp") == 0)
1739                 return PMINFO_WIDGET_APP;
1740         else if (strcasecmp(comp, "watchapp") == 0)
1741                 return PMINFO_WATCH_APP;
1742         else
1743                 return -1;
1744 }
1745
1746 static const char *__appcomponent_str(pkgmgrinfo_app_component comp)
1747 {
1748         switch (comp) {
1749         case PMINFO_UI_APP:
1750                 return "uiapp";
1751         case PMINFO_SVC_APP:
1752                 return "svcapp";
1753         case PMINFO_WIDGET_APP:
1754                 return "widgetapp";
1755         case PMINFO_WATCH_APP:
1756                 return "watchapp";
1757         default:
1758                 return NULL;
1759         }
1760 }
1761
1762 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1763 {
1764         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1765         int comp;
1766
1767         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1768         retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1769
1770         if (info->app_info == NULL)
1771                 return PMINFO_R_ERROR;
1772
1773         comp = __appcomponent_convert(info->app_info->component);
1774         if (comp < 0)
1775                 return PMINFO_R_ERROR;
1776
1777         *component = comp;
1778
1779         return PMINFO_R_OK;
1780 }
1781
1782 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1783 {
1784         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1785
1786         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1787         retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1788
1789         if (info->app_info == NULL || info->app_info->type == NULL)
1790                 return PMINFO_R_ERROR;
1791         *app_type = (char *)info->app_info->type;
1792
1793         return PMINFO_R_OK;
1794 }
1795
1796 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h  handle,
1797                                         int *operation_count, char ***operation)
1798 {
1799         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1800         retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1801         retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1802         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1803         *operation_count = data->operation_count;
1804         *operation = data->operation;
1805         return PMINFO_R_OK;
1806 }
1807
1808 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h  handle,
1809                                         int *uri_count, char ***uri)
1810 {
1811         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1812         retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1813         retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1814         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1815         *uri_count = data->uri_count;
1816         *uri = data->uri;
1817         return PMINFO_R_OK;
1818 }
1819
1820 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h  handle,
1821                                         int *mime_count, char ***mime)
1822 {
1823         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1824         retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1825         retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1826         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1827         *mime_count = data->mime_count;
1828         *mime = data->mime;
1829         return PMINFO_R_OK;
1830 }
1831
1832 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h  handle,
1833                                         int *subapp_count, char ***subapp)
1834 {
1835         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1836         retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1837         retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1838         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1839         *subapp_count = data->subapp_count;
1840         *subapp = data->subapp;
1841         return PMINFO_R_OK;
1842 }
1843
1844 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1845 {
1846         char *val;
1847         icon_x *ptr;
1848         GList *tmp;
1849         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1850
1851         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1852         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1853
1854         if (info->app_info == NULL)
1855                 return PMINFO_R_ERROR;
1856
1857         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1858                 ptr = (icon_x *)tmp->data;
1859                 if (ptr == NULL || ptr->section == NULL)
1860                         continue;
1861
1862                 val = (char *)ptr->section;
1863                 if (val && strcmp(val, "setting") == 0) {
1864                         *icon = (char *)ptr->text;
1865                         return PMINFO_R_OK;
1866                 }
1867         }
1868
1869         return PMINFO_R_ERROR;
1870 }
1871
1872
1873 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1874 {
1875         char *val;
1876         icon_x *ptr;
1877         GList *tmp;
1878         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1879
1880         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1881         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1882
1883         if (info->app_info == NULL)
1884                 return PMINFO_R_ERROR;
1885
1886         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1887                 ptr = (icon_x *)tmp->data;
1888                 if (ptr == NULL || ptr->section == NULL)
1889                         continue;
1890
1891                 val = (char *)ptr->section;
1892                 if (val && strcmp(val, "notification") == 0) {
1893                         *icon = (char *)ptr->text;
1894                         return PMINFO_R_OK;
1895                 }
1896         }
1897
1898         return PMINFO_R_ERROR;
1899 }
1900
1901 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1902 {
1903         char *val;
1904         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1905
1906         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1907         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1908
1909         if (info->app_info == NULL || info->app_info->recentimage == NULL)
1910                 return PMINFO_R_ERROR;
1911
1912         val = (char *)info->app_info->recentimage;
1913         if (strcasecmp(val, "capture") == 0)
1914                 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1915         else if (strcasecmp(val, "icon") == 0)
1916                 *type = PMINFO_RECENTIMAGE_USE_ICON;
1917         else
1918                 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1919
1920         return PMINFO_R_OK;
1921 }
1922
1923 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1924 {
1925         char *val;
1926         image_x *ptr;
1927         GList *tmp;
1928         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1929
1930         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1931         retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1932
1933         if (info->app_info == NULL)
1934                 return PMINFO_R_ERROR;
1935
1936         for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1937                 ptr = (image_x *)tmp->data;
1938                 if (ptr == NULL || ptr->section == NULL)
1939                         continue;
1940
1941                 val = (char *)ptr->section;
1942                 if (val && strcmp(val, "preview") == 0) {
1943                         *preview_img = (char *)ptr->text;
1944                         return PMINFO_R_OK;
1945                 }
1946         }
1947
1948         return PMINFO_R_ERROR;
1949 }
1950
1951 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1952 {
1953         const char *val;
1954         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1955
1956         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1957         retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1958
1959         val = info->app_info->permission_type;
1960         if (val == NULL)
1961                 return PMINFO_R_ERROR;
1962
1963         if (strcmp(val, "signature") == 0)
1964                 *permission = PMINFO_PERMISSION_SIGNATURE;
1965         else if (strcmp(val, "privilege") == 0)
1966                 *permission = PMINFO_PERMISSION_PRIVILEGE;
1967         else
1968                 *permission = PMINFO_PERMISSION_NORMAL;
1969
1970         return PMINFO_R_OK;
1971 }
1972
1973 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1974 {
1975         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1976
1977         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1978         retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1979
1980         if (info->app_info == NULL || info->app_info->component_type == NULL)
1981                 return PMINFO_R_ERROR;
1982
1983         *component_type = (char *)info->app_info->component_type;
1984
1985         return PMINFO_R_OK;
1986 }
1987
1988 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1989 {
1990         char *val;
1991         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1992
1993         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1994         retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1995
1996         if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1997                 return PMINFO_R_ERROR;
1998
1999         val = (char *)info->app_info->hwacceleration;
2000         if (strcasecmp(val, "off") == 0)
2001                 *hwacceleration = PMINFO_HWACCELERATION_OFF;
2002         else if (strcasecmp(val, "on") == 0)
2003                 *hwacceleration = PMINFO_HWACCELERATION_ON;
2004         else
2005                 *hwacceleration = PMINFO_HWACCELERATION_DEFAULT;
2006
2007         return PMINFO_R_OK;
2008 }
2009
2010 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
2011 {
2012         char *val;
2013         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2014
2015         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2016         retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2017
2018         if (info->app_info == NULL || info->app_info->screenreader == NULL)
2019                 return PMINFO_R_ERROR;
2020
2021         val = (char *)info->app_info->screenreader;
2022         if (strcasecmp(val, "screenreader-off") == 0)
2023                 *screenreader = PMINFO_SCREENREADER_OFF;
2024         else if (strcasecmp(val, "screenreader-on") == 0)
2025                 *screenreader = PMINFO_SCREENREADER_ON;
2026         else
2027                 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
2028
2029         return PMINFO_R_OK;
2030 }
2031
2032 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
2033 {
2034         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2035
2036         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2037         retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2038         retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2039
2040         if (info->app_info == NULL)
2041                 return PMINFO_R_ERROR;
2042
2043         if (info->app_info->portraitimg == NULL)
2044                 *portrait_img = "";
2045         else
2046                 *portrait_img = (char *)info->app_info->portraitimg;
2047
2048         if (info->app_info->landscapeimg == NULL)
2049                 *landscape_img = "";
2050         else
2051                 *landscape_img = (char *)info->app_info->landscapeimg;
2052
2053         return PMINFO_R_OK;
2054 }
2055
2056 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
2057 {
2058         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2059
2060         if (handle == NULL || effectimage_type == NULL) {
2061                 LOGE("invalid parameter");
2062                 return PMINFO_R_EINVAL;
2063         }
2064
2065         if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
2066                 return PMINFO_R_ERROR;
2067
2068         *effectimage_type = (char *)info->app_info->effectimage_type;
2069
2070         return PMINFO_R_OK;
2071 }
2072
2073 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h  handle, char **submode_mainid)
2074 {
2075         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2076
2077         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2078         retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2079
2080         if (info->app_info == NULL)
2081                 return PMINFO_R_ERROR;
2082
2083         if (info->app_info->submode_mainid == NULL)
2084                 *submode_mainid = "";
2085         else
2086                 *submode_mainid = (char *)info->app_info->submode_mainid;
2087
2088         return PMINFO_R_OK;
2089 }
2090
2091 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
2092 {
2093         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2094         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2095
2096         if (info->app_info && info->app_info->installed_storage) {
2097                  if (strcmp(info->app_info->installed_storage, "installed_internal") == 0)
2098                         *storage = PMINFO_INTERNAL_STORAGE;
2099                  else if (strcmp(info->app_info->installed_storage, "installed_external") == 0)
2100                          *storage = PMINFO_EXTERNAL_STORAGE;
2101                  else
2102                          return PMINFO_R_ERROR;
2103         } else {
2104                 return PMINFO_R_ERROR;
2105         }
2106
2107         return PMINFO_R_OK;
2108 }
2109
2110 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
2111 {
2112         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2113
2114         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2115         retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2116
2117         if (info->app_info->launch_mode == NULL)
2118                 return PMINFO_R_ERROR;
2119
2120         *mode = (char *)(info->app_info->launch_mode);
2121
2122         return PMINFO_R_OK;
2123 }
2124
2125 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
2126 {
2127         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2128
2129         if (handle == NULL || alias_appid == NULL) {
2130                 LOGE("invalid parameter");
2131                 return PMINFO_R_EINVAL;
2132         }
2133
2134         if (info->app_info == NULL || info->app_info->alias_appid == NULL)
2135                 return PMINFO_R_ERROR;
2136
2137         *alias_appid = (char *)info->app_info->alias_appid;
2138
2139         return PMINFO_R_OK;
2140 }
2141
2142 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
2143 {
2144         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2145
2146         if (handle == NULL || effective_appid == NULL) {
2147                 LOGE("invalid parameter");
2148                 return PMINFO_R_EINVAL;
2149         }
2150
2151         if (info->app_info == NULL)
2152                 return PMINFO_R_ERROR;
2153
2154         if (info->app_info->effective_appid == NULL)
2155                 *effective_appid = "";
2156         else
2157                 *effective_appid = (char *)info->app_info->effective_appid;
2158
2159         return PMINFO_R_OK;
2160 }
2161
2162 API int pkgmgrinfo_appinfo_get_tep_name(pkgmgrinfo_appinfo_h handle, char **tep_name)
2163 {
2164         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2165
2166         if (handle == NULL || tep_name == NULL) {
2167                 LOGE("invalid parameter");
2168                 return PMINFO_R_EINVAL;
2169         }
2170
2171         if (info->app_info == NULL)
2172                 return PMINFO_R_ERROR;
2173
2174         if (info->app_info->tep_name == NULL)
2175                 *tep_name = "";
2176         else
2177                 *tep_name = (char *)info->app_info->tep_name;
2178
2179         return PMINFO_R_OK;
2180 }
2181
2182 API int pkgmgrinfo_appinfo_get_zip_mount_file(pkgmgrinfo_appinfo_h handle, char **zip_mount_file)
2183 {
2184         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2185
2186         if (handle == NULL || zip_mount_file == NULL) {
2187                 LOGE("invalid parameter");
2188                 return PMINFO_R_EINVAL;
2189         }
2190
2191         if (info->app_info == NULL)
2192                 return PMINFO_R_ERROR;
2193
2194         if (info->app_info->zip_mount_file == NULL)
2195                 *zip_mount_file = "";
2196         else
2197                 *zip_mount_file = (char *)info->app_info->zip_mount_file;
2198
2199         return PMINFO_R_OK;
2200 }
2201
2202 API int pkgmgrinfo_appinfo_get_root_path(pkgmgrinfo_appinfo_h handle, char **root_path)
2203 {
2204         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2205
2206         if (handle == NULL || root_path == NULL) {
2207                 LOGE("invalid parameter");
2208                 return PMINFO_R_EINVAL;
2209         }
2210
2211         if (info->app_info == NULL || info->app_info->root_path == NULL)
2212                 return PMINFO_R_ERROR;
2213
2214         *root_path = (char *)info->app_info->root_path;
2215
2216         return PMINFO_R_OK;
2217 }
2218
2219 API int pkgmgrinfo_appinfo_get_api_version(pkgmgrinfo_appinfo_h handle, char **api_version)
2220 {
2221         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2222
2223         if (handle == NULL || api_version == NULL) {
2224                 LOGE("invalid parameter");
2225                 return PMINFO_R_EINVAL;
2226         }
2227
2228         if (info->app_info == NULL || info->app_info->api_version == NULL)
2229                 return PMINFO_R_ERROR;
2230
2231         *api_version = (char *)info->app_info->api_version;
2232
2233         return PMINFO_R_OK;
2234 }
2235
2236 API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int *installed_time)
2237 {
2238         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2239
2240         if (handle == NULL || installed_time == NULL) {
2241                 LOGE("invalid parameter");
2242                 return PMINFO_R_EINVAL;
2243         }
2244
2245         if (info->app_info == NULL || info->app_info->package_installed_time == NULL)
2246                 return PMINFO_R_ERROR;
2247
2248         *installed_time = atoi(info->app_info->package_installed_time);
2249
2250         return PMINFO_R_OK;
2251 }
2252
2253 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
2254 {
2255         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2256         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2257         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2258         retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2259
2260         int ret = PMINFO_R_OK;
2261         char *query = NULL;
2262         sqlite3_stmt *stmt = NULL;
2263
2264         /*open db*/
2265         ret = __open_manifest_db(uid, true);
2266         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2267
2268         /*Start constructing query*/
2269         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
2270         tryvm_if(query == NULL, ret = PMINFO_R_ERROR, "Out of memory");
2271
2272         /*prepare query*/
2273         ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
2274         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
2275
2276         /*step query*/
2277         ret = sqlite3_step(stmt);
2278         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
2279
2280         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2281         *access = strdup((char *)sqlite3_column_text(stmt, 2));
2282
2283         ret = PMINFO_R_OK;
2284
2285 catch:
2286         sqlite3_free(query);
2287         sqlite3_finalize(stmt);
2288         __close_manifest_db();
2289         return ret;
2290 }
2291
2292 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
2293 {
2294         return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, _getuid(), appid, access);
2295 }
2296
2297 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
2298 {
2299         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2300         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2301
2302         int ret = PMINFO_R_OK;
2303         char *query = NULL;
2304         sqlite3_stmt *stmt = NULL;
2305
2306         /*open db*/
2307         ret = __open_manifest_db(uid, true);
2308         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2309
2310         /*Start constructing query*/
2311         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
2312         tryvm_if(query == NULL, ret = PMINFO_R_ERROR, "Out of memory");
2313
2314         /*prepare query*/
2315         ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
2316         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
2317
2318         /*step query*/
2319         ret = sqlite3_step(stmt);
2320         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
2321
2322         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2323
2324         ret = PMINFO_R_OK;
2325
2326 catch:
2327         sqlite3_free(query);
2328         sqlite3_finalize(stmt);
2329         __close_manifest_db();
2330         return ret;
2331 }
2332
2333 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
2334 {
2335         return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
2336 }
2337
2338 API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h  handle, int *support_mode)
2339 {
2340         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2341         retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2342
2343         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2344         if (info->app_info->support_mode)
2345                 *support_mode = atoi(info->app_info->support_mode);
2346         else
2347                 *support_mode = 0;
2348
2349         return PMINFO_R_OK;
2350 }
2351
2352 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
2353                         pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
2354 {
2355         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2356         retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2357         int ret = -1;
2358         permission_x *ptr;
2359         GList *tmp;
2360         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2361
2362         if (info->app_info == NULL)
2363                 return PMINFO_R_ERROR;
2364
2365         for (tmp = info->app_info->permission; tmp; tmp = tmp->next) {
2366                 ptr = (permission_x *)tmp->data;
2367                 if (ptr == NULL)
2368                         continue;
2369                 if (ptr->value) {
2370                         ret = permission_func(ptr->value, user_data);
2371                         if (ret < 0)
2372                                 break;
2373                 }
2374         }
2375         return PMINFO_R_OK;
2376 }
2377
2378 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
2379                         pkgmgrinfo_app_category_list_cb category_func, void *user_data)
2380 {
2381         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2382         retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2383         int ret = -1;
2384         const char *category;
2385         GList *tmp;
2386         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2387
2388         if (info->app_info == NULL)
2389                 return PMINFO_R_ERROR;
2390
2391         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2392                 category = (const char *)tmp->data;
2393                 if (category) {
2394                         ret = category_func(category, user_data);
2395                         if (ret < 0)
2396                                 break;
2397                 }
2398         }
2399         return PMINFO_R_OK;
2400 }
2401
2402 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
2403                         pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
2404 {
2405         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2406         retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2407         int ret = -1;
2408         metadata_x *ptr;
2409         GList *tmp;
2410         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2411
2412         if (info->app_info == NULL)
2413                 return PMINFO_R_ERROR;
2414
2415         for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
2416                 ptr = (metadata_x *)tmp->data;
2417                 if (ptr == NULL)
2418                         continue;
2419                 if (ptr->key) {
2420                         ret = metadata_func(ptr->key, ptr->value ? ptr->value : "", user_data);
2421                         if (ret < 0)
2422                                 break;
2423                 }
2424         }
2425         return PMINFO_R_OK;
2426 }
2427
2428 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
2429                         pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
2430 {
2431         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2432         retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2433         int ret;
2434         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2435         appcontrol_x *appcontrol;
2436         GList *tmp;
2437
2438         if (info->app_info == NULL)
2439                 return PMINFO_R_ERROR;
2440
2441         for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2442                 appcontrol = (appcontrol_x *)tmp->data;
2443                 if (appcontrol == NULL)
2444                         continue;
2445                 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
2446                 if (ret < 0)
2447                         break;
2448         }
2449
2450         return PMINFO_R_OK;
2451 }
2452
2453 API int pkgmgrinfo_appinfo_foreach_background_category(
2454                 pkgmgrinfo_appinfo_h handle,
2455                 pkgmgrinfo_app_background_category_list_cb category_func,
2456                 void *user_data)
2457 {
2458         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2459         GList *tmp;
2460         char *category;
2461
2462         if (handle == NULL || category_func == NULL || info->app_info == NULL) {
2463                 LOGE("invalid parameter");
2464                 return PMINFO_R_EINVAL;
2465         }
2466
2467         for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
2468                 category = (char *)tmp->data;
2469                 if (category == NULL)
2470                         continue;
2471
2472                 if (category_func(category, user_data) < 0)
2473                         break;
2474         }
2475
2476         return PMINFO_R_OK;
2477 }
2478
2479 API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
2480                 pkgmgrinfo_app_splash_screen_list_cb splash_screen_func,
2481                 void *user_data)
2482 {
2483         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2484         splashscreen_x *splashscreen;
2485         GList *tmp;
2486         int ret;
2487
2488         if (info == NULL || info->app_info == NULL
2489                         || splash_screen_func == NULL) {
2490                 LOGE("invalid parameter");
2491                 return PMINFO_R_EINVAL;
2492         }
2493
2494         for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) {
2495                 splashscreen = (splashscreen_x *)tmp->data;
2496                 if (splashscreen == NULL)
2497                         continue;
2498                 ret = splash_screen_func(splashscreen->src,
2499                                 splashscreen->type,
2500                                 splashscreen->orientation,
2501                                 splashscreen->indicatordisplay,
2502                                 splashscreen->operation,
2503                                 splashscreen->color_depth,
2504                                 user_data);
2505                 if (ret < 0)
2506                         break;
2507         }
2508
2509         return PMINFO_R_OK;
2510 }
2511
2512 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
2513 {
2514         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2515         retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2516         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2517
2518         if (info->app_info == NULL || info->app_info->nodisplay == NULL)
2519                 return PMINFO_R_ERROR;
2520
2521         *nodisplay = _get_bool_value(info->app_info->nodisplay);
2522
2523         return PMINFO_R_OK;
2524 }
2525
2526 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
2527 {
2528         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2529         retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2530         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2531
2532         if (info->app_info == NULL || info->app_info->multiple == NULL)
2533                 return PMINFO_R_ERROR;
2534
2535         *multiple = _get_bool_value(info->app_info->multiple);
2536
2537         return PMINFO_R_OK;
2538 }
2539
2540 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
2541 {
2542         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2543         retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2544         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2545
2546         if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
2547                 return PMINFO_R_ERROR;
2548
2549         *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
2550
2551         return PMINFO_R_OK;
2552 }
2553
2554 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h  handle, bool *taskmanage)
2555 {
2556         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2557         retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2558         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2559
2560         if (info->app_info == NULL || info->app_info->taskmanage == NULL)
2561                 return PMINFO_R_ERROR;
2562
2563         *taskmanage = _get_bool_value(info->app_info->taskmanage);
2564
2565         return PMINFO_R_OK;
2566 }
2567
2568 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h  handle, bool *enabled)
2569 {
2570         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2571         retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2572         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2573
2574         if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2575                 return PMINFO_R_ERROR;
2576
2577         *enabled = !_get_bool_value(info->app_info->is_disabled);
2578
2579         return PMINFO_R_OK;
2580 }
2581
2582 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h  handle, bool *onboot)
2583 {
2584         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2585         retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2586         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2587
2588         if (info->app_info == NULL || info->app_info->onboot == NULL)
2589                 return PMINFO_R_ERROR;
2590
2591         *onboot = _get_bool_value(info->app_info->onboot);
2592
2593         return PMINFO_R_OK;
2594 }
2595
2596 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h  handle, bool *autorestart)
2597 {
2598         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2599         retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2600         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2601
2602         if (info->app_info == NULL || info->app_info->autorestart == NULL)
2603                 return PMINFO_R_ERROR;
2604
2605         *autorestart = _get_bool_value(info->app_info->autorestart);
2606
2607         return PMINFO_R_OK;
2608 }
2609
2610 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h  handle, bool *mainapp)
2611 {
2612         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2613         retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2614         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2615
2616         if (info->app_info == NULL || info->app_info->mainapp == NULL)
2617                 return PMINFO_R_ERROR;
2618
2619         *mainapp = _get_bool_value(info->app_info->mainapp);
2620
2621         return PMINFO_R_OK;
2622 }
2623
2624 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
2625 {
2626         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2627         retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2628         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2629
2630         if (info->app_info == NULL || info->app_info->preload == NULL)
2631                 return PMINFO_R_ERROR;
2632
2633         *preload = _get_bool_value(info->app_info->preload);
2634
2635         return PMINFO_R_OK;
2636 }
2637
2638 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
2639 {
2640         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2641         retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2642         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2643
2644         if (info->app_info == NULL || info->app_info->submode == NULL)
2645                 return PMINFO_R_ERROR;
2646
2647         *submode = _get_bool_value(info->app_info->submode);
2648
2649         return PMINFO_R_OK;
2650 }
2651
2652 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
2653 {
2654         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2655
2656         if (handle == NULL || process_pool == NULL) {
2657                 LOGE("invalid parameter");
2658                 return PMINFO_R_EINVAL;
2659         }
2660
2661         if (info->app_info == NULL)
2662                 return PMINFO_R_ERROR;
2663
2664         *process_pool = _get_bool_value(info->app_info->process_pool);
2665
2666         return PMINFO_R_OK;
2667 }
2668
2669 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
2670 {
2671         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2672         retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
2673         retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
2674
2675         const char *val;
2676         GList *tmp;
2677         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2678
2679         if (info->app_info == NULL)
2680                 return PMINFO_R_ERROR;
2681
2682         *exist = 0;
2683         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2684                 val = (const char *)tmp->data;
2685                 if (val == NULL)
2686                         continue;
2687                 if (strcasecmp(val, category) == 0) {
2688                         *exist = 1;
2689                         break;
2690                 }
2691         }
2692
2693         return PMINFO_R_OK;
2694 }
2695
2696 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
2697                 bool *ui_gadget)
2698 {
2699         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2700
2701         if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
2702                 _LOGE("invalid parameter");
2703                 return PMINFO_R_EINVAL;
2704         }
2705         if (info->app_info->ui_gadget == NULL)
2706                 info->app_info->ui_gadget = strdup("false");
2707
2708         *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
2709
2710         return PMINFO_R_OK;
2711 }
2712
2713 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
2714                 bool *support_disable)
2715 {
2716         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2717
2718         if (info == NULL || info->app_info == NULL || support_disable == NULL) {
2719                 _LOGE("invalid parameter");
2720                 return PMINFO_R_EINVAL;
2721         }
2722
2723         *support_disable = _get_bool_value(info->app_info->support_disable);
2724
2725         return PMINFO_R_OK;
2726 }
2727
2728 API int pkgmgrinfo_appinfo_is_removable(pkgmgrinfo_appinfo_h handle,
2729                 bool *removable)
2730 {
2731         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2732
2733         if (info == NULL || info->app_info == NULL || removable == NULL) {
2734                 _LOGE("invalid parameter");
2735                 return PMINFO_R_EINVAL;
2736         }
2737
2738         *removable = _get_bool_value(info->app_info->removable);
2739
2740         return PMINFO_R_OK;
2741 }
2742
2743 API int pkgmgrinfo_appinfo_is_system(pkgmgrinfo_appinfo_h handle, bool *system)
2744 {
2745         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2746
2747         if (info == NULL || info->app_info == NULL || system == NULL) {
2748                 _LOGE("invalid parameter");
2749                 return PMINFO_R_EINVAL;
2750         }
2751
2752         *system = _get_bool_value(info->app_info->package_system);
2753
2754         return PMINFO_R_OK;
2755 }
2756
2757 API int pkgmgrinfo_appinfo_is_disabled(pkgmgrinfo_appinfo_h handle, bool *disabled)
2758 {
2759         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2760         retvm_if(disabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2761         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2762
2763         if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2764                 return PMINFO_R_ERROR;
2765
2766         *disabled = _get_bool_value(info->app_info->is_disabled);
2767
2768         return PMINFO_R_OK;
2769 }
2770
2771 API int pkgmgrinfo_appinfo_is_global(pkgmgrinfo_appinfo_h handle, bool *global)
2772 {
2773         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2774
2775         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2776         retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2777
2778         if (info->app_info == NULL || info->app_info->for_all_users == NULL)
2779                 return PMINFO_R_ERROR;
2780
2781         *global = _get_bool_value(info->app_info->for_all_users);
2782
2783         return PMINFO_R_OK;
2784 }
2785
2786 API int pkgmgrinfo_appinfo_get_splash_screen_display(pkgmgrinfo_appinfo_h handle, bool *splash_screen_display)
2787 {
2788         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2789
2790         if (info == NULL || splash_screen_display == NULL) {
2791                 _LOGE("Invalid parameter");
2792                 return PMINFO_R_EINVAL;
2793         }
2794
2795         if (info->app_info == NULL || info->app_info->splash_screen_display == NULL)
2796                 return PMINFO_R_ERROR;
2797
2798         *splash_screen_display = _get_bool_value(info->app_info->splash_screen_display);
2799
2800         return PMINFO_R_OK;
2801 }
2802
2803 API int pkgmgrinfo_appinfo_get_setup_appid(pkgmgrinfo_appinfo_h handle, char **setup_appid)
2804 {
2805         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2806
2807         if (info == NULL || setup_appid == NULL) {
2808                 _LOGE("Invalid parameter");
2809                 return PMINFO_R_EINVAL;
2810         }
2811
2812         if (info->app_info == NULL || info->app_info->setup_appid == NULL)
2813                 return PMINFO_R_ERROR;
2814
2815         *setup_appid = info->app_info->setup_appid;
2816         return PMINFO_R_OK;
2817 }
2818
2819 API int pkgmgrinfo_appinfo_is_support_ambient(pkgmgrinfo_appinfo_h handle,
2820                 bool *support_ambient)
2821 {
2822         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2823
2824         if (info == NULL || support_ambient == NULL) {
2825                 _LOGE("Invalid parameter");
2826                 return PMINFO_R_EINVAL;
2827         }
2828
2829         if (info->app_info == NULL || info->app_info->support_ambient == NULL)
2830                 return PMINFO_R_ERROR;
2831
2832         *support_ambient = _get_bool_value(info->app_info->support_ambient);
2833
2834         return PMINFO_R_OK;
2835 }
2836
2837 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
2838 {
2839         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2840         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2841         __cleanup_appinfo(info);
2842         return PMINFO_R_OK;
2843 }
2844
2845 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
2846 {
2847         return (pkgmgrinfo_pkginfo_filter_create(handle));
2848 }
2849
2850 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
2851 {
2852         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2853 }
2854
2855 static gint __compare_func(gconstpointer data1, gconstpointer data2)
2856 {
2857         pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
2858         pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
2859         if (node1->prop == node2->prop)
2860                 return 0;
2861         else if (node1->prop > node2->prop)
2862                 return 1;
2863         else
2864                 return -1;
2865 }
2866
2867 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
2868                                 const char *property, const int value)
2869 {
2870         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2871         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2872         char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
2873         char *val = NULL;
2874         GSList *link = NULL;
2875         int prop = -1;
2876         prop = _pminfo_appinfo_convert_to_prop_int(property);
2877         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
2878                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
2879                 _LOGE("Invalid Integer Property\n");
2880                 return PMINFO_R_EINVAL;
2881         }
2882         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2883         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2884         if (node == NULL) {
2885                 _LOGE("Out of Memory!!!\n");
2886                 return PMINFO_R_ERROR;
2887         }
2888         snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
2889         val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
2890         if (val == NULL) {
2891                 _LOGE("Out of Memory\n");
2892                 free(node);
2893                 node = NULL;
2894                 return PMINFO_R_ERROR;
2895         }
2896         node->prop = prop;
2897         node->value = val;
2898         /*If API is called multiple times for same property, we should override the previous values.
2899         Last value set will be used for filtering.*/
2900         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2901         if (link)
2902                 filter->list = g_slist_delete_link(filter->list, link);
2903         filter->list = g_slist_append(filter->list, (gpointer)node);
2904         return PMINFO_R_OK;
2905
2906 }
2907
2908 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
2909                                 const char *property, const bool value)
2910 {
2911         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2912         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2913         char *val = NULL;
2914         GSList *link = NULL;
2915         int prop = -1;
2916         prop = _pminfo_appinfo_convert_to_prop_bool(property);
2917         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
2918                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
2919                 _LOGE("Invalid Boolean Property\n");
2920                 return PMINFO_R_EINVAL;
2921         }
2922         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2923         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2924         if (node == NULL) {
2925                 _LOGE("Out of Memory!!!\n");
2926                 return PMINFO_R_ERROR;
2927         }
2928         if (value)
2929                 val = strndup("true", 4);
2930         else
2931                 val = strndup("false", 5);
2932         if (val == NULL) {
2933                 _LOGE("Out of Memory\n");
2934                 free(node);
2935                 node = NULL;
2936                 return PMINFO_R_ERROR;
2937         }
2938         node->prop = prop;
2939         node->value = val;
2940         /*If API is called multiple times for same property, we should override the previous values.
2941         Last value set will be used for filtering.*/
2942         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2943         if (link)
2944                 filter->list = g_slist_delete_link(filter->list, link);
2945         filter->list = g_slist_append(filter->list, (gpointer)node);
2946         return PMINFO_R_OK;
2947
2948 }
2949
2950 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
2951                                 const char *property, const char *value)
2952 {
2953         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2954         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2955         retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2956         char *val = NULL;
2957         pkgmgrinfo_node_x *ptr = NULL;
2958         char prev[PKG_STRING_LEN_MAX] = {'\0'};
2959         char temp[PKG_STRING_LEN_MAX] = {'\0'};
2960         GSList *link = NULL;
2961         int prop = -1;
2962         prop = _pminfo_appinfo_convert_to_prop_str(property);
2963         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
2964                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
2965                 _LOGE("Invalid String Property\n");
2966                 return PMINFO_R_EINVAL;
2967         }
2968         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2969         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2970         if (node == NULL) {
2971                 _LOGE("Out of Memory!!!\n");
2972                 return PMINFO_R_ERROR;
2973         }
2974         node->prop = prop;
2975         switch (prop) {
2976         case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
2977                 node->value = strdup(value);
2978                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2979                 if (link)
2980                         filter->list = g_slist_delete_link(filter->list, link);
2981                 filter->list = g_slist_append(filter->list, (gpointer)node);
2982                 break;
2983         case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
2984                 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
2985                 if (val == NULL) {
2986                         _LOGE("Out of Memory\n");
2987                         free(node);
2988                         node = NULL;
2989                         return PMINFO_R_ERROR;
2990                 }
2991                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2992                 if (link) {
2993                         ptr = (pkgmgrinfo_node_x *)link->data;
2994                         strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
2995                         _LOGI("Previous value is %s\n", prev);
2996                         filter->list = g_slist_delete_link(filter->list, link);
2997                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value);
2998                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2999                         _LOGI("New value is %s\n", val);
3000                         node->value = val;
3001                         filter->list = g_slist_append(filter->list, (gpointer)node);
3002                         memset(temp, '\0', PKG_STRING_LEN_MAX);
3003                 } else {
3004                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s", value);
3005                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
3006                         _LOGI("First value is %s\n", val);
3007                         node->value = val;
3008                         filter->list = g_slist_append(filter->list, (gpointer)node);
3009                         memset(temp, '\0', PKG_STRING_LEN_MAX);
3010                 }
3011                 break;
3012         default:
3013                 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
3014                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3015                 if (link)
3016                         filter->list = g_slist_delete_link(filter->list, link);
3017                 filter->list = g_slist_append(filter->list, (gpointer)node);
3018                 break;
3019         }
3020         return PMINFO_R_OK;
3021 }
3022
3023 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
3024 {
3025         int ret;
3026         char *locale;
3027         GHashTable *list;
3028
3029         if (handle == NULL || count == NULL) {
3030                 _LOGE("invalid parameter");
3031                 return PMINFO_R_EINVAL;
3032         }
3033
3034         locale = _get_system_locale();
3035         if (locale == NULL)
3036                 return PMINFO_R_ERROR;
3037
3038         list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
3039                         __free_applications);
3040         if (list == NULL) {
3041                 free(locale);
3042                 return PMINFO_R_ERROR;
3043         }
3044
3045         ret = _appinfo_get_applications(uid, uid, locale, handle, 0, list);
3046         if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
3047                 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
3048                                 handle, 0, list);
3049
3050         if (ret != PMINFO_R_OK) {
3051                 g_hash_table_destroy(list);
3052                 free(locale);
3053                 return PMINFO_R_ERROR;
3054         }
3055
3056         *count = g_hash_table_size(list);
3057         g_hash_table_destroy(list);
3058         free(locale);
3059
3060         return PMINFO_R_OK;
3061 }
3062
3063 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
3064 {
3065         return pkgmgrinfo_appinfo_usr_filter_count(handle, count, _getuid());
3066 }
3067
3068 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
3069                 pkgmgrinfo_appinfo_filter_h handle,
3070                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3071 {
3072         if (handle == NULL || app_cb == NULL) {
3073                 LOGE("invalid parameter");
3074                 return PMINFO_R_EINVAL;
3075         }
3076
3077         return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3078                         user_data);
3079 }
3080
3081 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
3082                                 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3083 {
3084         return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, _getuid());
3085 }
3086
3087 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
3088 {
3089         return (pkgmgrinfo_pkginfo_filter_create(handle));
3090 }
3091
3092 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
3093 {
3094         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3095 }
3096
3097 API int pkgmgrinfo_appinfo_metadata_filter_add(
3098                 pkgmgrinfo_appinfo_metadata_filter_h handle,
3099                 const char *key, const char *value)
3100 {
3101         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3102         pkgmgrinfo_metadata_node_x *node;
3103
3104         /* value can be NULL.
3105          * In that case all apps with specified key should be displayed
3106          */
3107         if (key == NULL) {
3108                 LOGE("invalid parameter");
3109                 return PMINFO_R_EINVAL;
3110         }
3111
3112         node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x));
3113         if (node == NULL) {
3114                 LOGE("out of memory");
3115                 return PMINFO_R_ERROR;
3116         }
3117
3118         node->key = strdup(key);
3119         if (value && strlen(value))
3120                 node->value = strdup(value);
3121
3122         filter->list_metadata = g_slist_append(filter->list_metadata,
3123                         (gpointer)node);
3124
3125         return PMINFO_R_OK;
3126 }
3127
3128 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
3129                 pkgmgrinfo_appinfo_metadata_filter_h handle,
3130                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3131 {
3132         if (handle == NULL || app_cb == NULL) {
3133                 LOGE("invalid parameter");
3134                 return PMINFO_R_EINVAL;
3135         }
3136
3137         return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3138                         user_data);
3139 }
3140
3141 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
3142                 pkgmgrinfo_appinfo_metadata_filter_h handle,
3143                 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3144 {
3145         return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
3146                         user_data, _getuid());
3147 }
3148
3149 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
3150 {
3151         const char *val;
3152         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3153
3154         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3155         retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3156
3157         val = info->app_info->guestmode_visibility;
3158         *status = _get_bool_value(val);
3159         return PMINFO_R_OK;
3160 }