Use %license macro to copy license file
[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         len += strlen(" WHERE 1=1");
72         strncat(buf, " WHERE 1=1", MAX_QUERY_LEN - len - 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                 len += strlen(" AND ");
86                 strncat(buf, " AND ", MAX_QUERY_LEN - len - 1);
87
88                 len += strlen(condition);
89                 strncat(buf, condition, sizeof(buf) - len - 1);
90                 free(condition);
91                 condition = NULL;
92         }
93
94         if (filter->list_metadata) {
95                 len += strlen(" AND (");
96                 strncat(buf, " AND (", MAX_QUERY_LEN - len - 1);
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                 len += strlen(condition);
104                 strncat(buf, condition, sizeof(buf) - len - 1);
105                 free(condition);
106                 condition = NULL;
107
108                 len += strlen(" OR ");
109                 strncat(buf, " OR ", MAX_QUERY_LEN - len - 1);
110         }
111         if (filter->list_metadata) {
112                 len += strlen("1=0)");
113                 strncat(buf, "1=0)", MAX_QUERY_LEN - len - 1);
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
139         len += strlen(buf);
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";
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
703                 info->for_all_users =
704                         strdup((db_uid != GLOBAL_USER) ? "false" : "true");
705
706                 if (db_uid == GLOBAL_USER) {
707                         ret = __get_appinfo_for_uid(db, info, uid);
708                         if (ret != PMINFO_R_OK) {
709                                 LOGI("Failed to get appinfo for given uid[%d]", (int)uid);
710                                 pkgmgrinfo_basic_free_application(info);
711                                 info = NULL;
712                                 continue;
713                         }
714                 }
715
716                 info->background_category = __get_background_category(
717                                 bg_category_str);
718                 free(bg_category_str);
719
720                 if (flag & PMINFO_APPINFO_GET_LABEL) {
721                         tmp_record = NULL;
722                         _save_column_str(stmt, idx++, &tmp_record);
723                         if (_add_label_info_into_list(locale, tmp_record, &info->label)) {
724                                 ret = PMINFO_R_ERROR;
725                                 goto catch;
726                         }
727                 }
728
729                 if (flag & PMINFO_APPINFO_GET_ICON) {
730                         tmp_record = NULL;
731                         _save_column_str(stmt, idx++, &tmp_record);
732                         if (_add_icon_info_into_list(locale, tmp_record, &info->icon)) {
733                                 ret = PMINFO_R_ERROR;
734                                 goto catch;
735                         }
736                 }
737
738                 if (flag & PMINFO_APPINFO_GET_CATEGORY) {
739                         if (_appinfo_get_category(db, info->appid,
740                                                 &info->category)) {
741                                 ret = PMINFO_R_ERROR;
742                                 goto catch;
743                         }
744                 }
745
746                 if (flag & PMINFO_APPINFO_GET_APP_CONTROL) {
747                         if (_appinfo_get_app_control(db, info->appid,
748                                                 &info->appcontrol)) {
749                                 ret = PMINFO_R_ERROR;
750                                 goto catch;
751                         }
752                 }
753
754                 if (flag & PMINFO_APPINFO_GET_DATA_CONTROL) {
755                         if (_appinfo_get_data_control(db, info->appid,
756                                                 &info->datacontrol)) {
757                                 ret = PMINFO_R_ERROR;
758                                 goto catch;
759                         }
760                 }
761
762                 if (flag & PMINFO_APPINFO_GET_METADATA) {
763                         if (_appinfo_get_metadata(db, info->appid,
764                                                 &info->metadata)) {
765                                 ret = PMINFO_R_ERROR;
766                                 goto catch;
767                         }
768                 }
769
770                 if (flag & PMINFO_APPINFO_GET_SPLASH_SCREEN) {
771                         if (_appinfo_get_splashscreens(db, info->appid,
772                                                 &info->splashscreens)) {
773                                 ret = PMINFO_R_ERROR;
774                                 goto catch;
775                         }
776                 }
777
778                 if (is_check_storage &&
779                                 __appinfo_check_installed_storage(info) != PMINFO_R_OK) {
780                         ret = PMINFO_R_ERROR;
781                         pkgmgrinfo_basic_free_application(info);
782                         info = NULL;
783                         continue;
784                 }
785
786                 g_hash_table_insert(applications, (gpointer)info->appid,
787                                 (gpointer)info);
788         }
789
790         ret = PMINFO_R_OK;
791
792 catch:
793         if (constraint)
794                 free(constraint);
795
796         if (ret != PMINFO_R_OK && info != NULL)
797                 pkgmgrinfo_basic_free_application(info);
798
799         g_list_free_full(bind_params, free);
800         sqlite3_close_v2(db);
801         sqlite3_finalize(stmt);
802
803         return ret;
804 }
805
806 static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
807         pkgmgrinfo_appinfo_filter_h filter, pkgmgrinfo_appinfo_h *handle)
808 {
809         int ret;
810         char *locale;
811         GHashTable *list;
812         pkgmgr_appinfo_x *info;
813
814         if (appid == NULL || filter == NULL || handle == NULL) {
815                         LOGE("invalid parameter");
816                         return PMINFO_R_EINVAL;
817         }
818
819         locale = _get_system_locale();
820         if (locale == NULL)
821                 return PMINFO_R_ERROR;
822
823         list = g_hash_table_new(g_str_hash, g_str_equal);
824         if (list == NULL) {
825                 free(locale);
826                 return PMINFO_R_ERROR;
827         }
828
829         ret = _appinfo_get_applications(uid, uid, locale, filter,
830                         PMINFO_APPINFO_GET_ALL, list);
831         if (!g_hash_table_size(list) && uid != GLOBAL_USER)
832                 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, filter,
833                                 PMINFO_APPINFO_GET_ALL, list);
834
835         if (!g_hash_table_size(list)) {
836                 _LOGI("appinfo for [%s] is not existed for user [%d]",
837                                 appid, uid);
838                 g_hash_table_destroy(list);
839                 free(locale);
840                 return PMINFO_R_ENOENT;
841         }
842
843         info = calloc(1, sizeof(pkgmgr_appinfo_x));
844         if (info == NULL) {
845                 _LOGE("out of memory");
846                 g_hash_table_destroy(list);
847                 free(locale);
848                 return PMINFO_R_ERROR;
849         }
850
851         info->app_info = (application_x *)g_hash_table_lookup(list, appid);
852         info->locale = locale;
853         info->package = strdup(info->app_info->package);
854
855         /* just free list only */
856         g_hash_table_destroy(list);
857
858         *handle = info;
859
860         return ret;
861 }
862
863 API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid,
864                 pkgmgrinfo_appinfo_h *handle)
865 {
866         int ret;
867         pkgmgrinfo_appinfo_filter_h filter;
868
869         if (appid == NULL || handle == NULL) {
870                 LOGE("invalid parameter");
871                 return PMINFO_R_EINVAL;
872         }
873
874         ret = pkgmgrinfo_appinfo_filter_create(&filter);
875         if (ret != PMINFO_R_OK)
876                 return ret;
877
878         ret = pkgmgrinfo_appinfo_filter_add_string(filter,
879                         PMINFO_APPINFO_PROP_APP_ID, appid);
880         if (ret != PMINFO_R_OK) {
881                 pkgmgrinfo_appinfo_filter_destroy(filter);
882                 return PMINFO_R_ERROR;
883         }
884
885         ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
886                         PMINFO_APPINFO_PROP_APP_DISABLE, true);
887         if (ret != PMINFO_R_OK) {
888                 pkgmgrinfo_appinfo_filter_destroy(filter);
889                 return PMINFO_R_ERROR;
890         }
891
892         ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
893         pkgmgrinfo_appinfo_filter_destroy(filter);
894
895         return ret;
896 }
897
898 API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
899 {
900         return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, _getuid(), handle);
901 }
902
903 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
904                 pkgmgrinfo_appinfo_h *handle)
905 {
906         int ret;
907         pkgmgrinfo_appinfo_filter_h filter;
908
909         if (appid == NULL || handle == NULL) {
910                 LOGE("invalid parameter");
911                 return PMINFO_R_EINVAL;
912         }
913
914         ret = pkgmgrinfo_appinfo_filter_create(&filter);
915         if (ret != PMINFO_R_OK)
916                 return ret;
917
918         ret = pkgmgrinfo_appinfo_filter_add_string(filter,
919                         PMINFO_APPINFO_PROP_APP_ID, appid);
920         if (ret != PMINFO_R_OK) {
921                 pkgmgrinfo_appinfo_filter_destroy(filter);
922                 return PMINFO_R_ERROR;
923         }
924
925         ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
926                         PMINFO_APPINFO_PROP_APP_DISABLE, false);
927         if (ret != PMINFO_R_OK) {
928                 pkgmgrinfo_appinfo_filter_destroy(filter);
929                 return PMINFO_R_ERROR;
930         }
931
932         ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
933         pkgmgrinfo_appinfo_filter_destroy(filter);
934         return ret;
935 }
936
937 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
938 {
939         return pkgmgrinfo_appinfo_get_usr_appinfo(appid, _getuid(), handle);
940 }
941
942 API int pkgmgrinfo_appinfo_get_usr_all_appinfo(const char *appid, uid_t uid,
943                 pkgmgrinfo_appinfo_h *handle)
944 {
945         int ret;
946         pkgmgrinfo_appinfo_filter_h filter;
947
948         if (appid == NULL || handle == NULL) {
949                 LOGE("invalid parameter");
950                 return PMINFO_R_EINVAL;
951         }
952
953         ret = pkgmgrinfo_appinfo_filter_create(&filter);
954         if (ret != PMINFO_R_OK)
955                 return ret;
956
957         ret = pkgmgrinfo_appinfo_filter_add_string(filter,
958                         PMINFO_APPINFO_PROP_APP_ID, appid);
959         if (ret != PMINFO_R_OK) {
960                 pkgmgrinfo_appinfo_filter_destroy(filter);
961                 return PMINFO_R_ERROR;
962         }
963
964         ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
965                         PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false);
966         if (ret != PMINFO_R_OK) {
967                 pkgmgrinfo_appinfo_filter_destroy(filter);
968                 return PMINFO_R_ERROR;
969         }
970
971         ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
972         pkgmgrinfo_appinfo_filter_destroy(filter);
973
974         return ret;
975 }
976
977 API int pkgmgrinfo_appinfo_get_all_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
978 {
979         return pkgmgrinfo_appinfo_get_usr_all_appinfo(appid, _getuid(), handle);
980 }
981
982 static gpointer __copy_str(gconstpointer src, gpointer data)
983 {
984         const char *tmp = (const char *)src;
985         char *buffer;
986
987         buffer = strdup(tmp);
988         if (buffer == NULL) {
989                 LOGE("memory alloc failed");
990                 *(int *)data = -1;
991                 return NULL;
992         }
993
994         return buffer;
995 }
996
997 static gpointer __copy_label(gconstpointer src, gpointer data)
998 {
999         label_x *tmp = (label_x *)src;
1000         label_x *label;
1001
1002         label = calloc(1, sizeof(label_x));
1003         if (label == NULL) {
1004                 LOGE("memory alloc failed");
1005                 *(int *)data = -1;
1006                 return NULL;
1007         }
1008
1009         if (tmp->name)
1010                 label->name = strdup(tmp->name);
1011         if (tmp->text)
1012                 label->text = strdup(tmp->text);
1013         if (tmp->lang)
1014                 label->lang = strdup(tmp->lang);
1015
1016         return label;
1017 }
1018
1019 static gpointer __copy_icon(gconstpointer src, gpointer data)
1020 {
1021         icon_x *tmp = (icon_x *)src;
1022         icon_x *icon;
1023
1024         icon = calloc(1, sizeof(icon_x));
1025         if (icon == NULL) {
1026                 LOGE("memory alloc failed");
1027                 *(int *)data = -1;
1028                 return NULL;
1029         }
1030
1031         if (tmp->text)
1032                 icon->text = strdup(tmp->text);
1033         if (tmp->lang)
1034                 icon->lang = strdup(tmp->lang);
1035         if (tmp->section)
1036                 icon->section = strdup(tmp->section);
1037         if (tmp->size)
1038                 icon->size = strdup(tmp->size);
1039         if (tmp->resolution)
1040                 icon->resolution = strdup(tmp->resolution);
1041
1042         return icon;
1043 }
1044
1045 static gpointer __copy_metadata(gconstpointer src, gpointer data)
1046 {
1047         metadata_x *tmp = (metadata_x *)src;
1048         metadata_x *metadata;
1049
1050         metadata = calloc(1, sizeof(metadata_x));
1051         if (metadata == NULL) {
1052                 LOGE("memory alloc failed");
1053                 *(int *)data = -1;
1054                 return NULL;
1055         }
1056
1057         if (tmp->key)
1058                 metadata->key = strdup(tmp->key);
1059         if (tmp->value)
1060                 metadata->value = strdup(tmp->value);
1061
1062         return metadata;
1063 }
1064
1065 static gpointer __copy_datacontrol(gconstpointer src, gpointer data)
1066 {
1067         datacontrol_x *tmp = (datacontrol_x *)src;
1068         datacontrol_x *datacontrol;
1069
1070         datacontrol = calloc(1, sizeof(datacontrol_x));
1071         if (datacontrol == NULL) {
1072                 LOGE("memory alloc failed");
1073                 *(int *)data = -1;
1074                 return NULL;
1075         }
1076
1077         if (tmp->providerid)
1078                 datacontrol->providerid = strdup(tmp->providerid);
1079         if (tmp->access)
1080                 datacontrol->access = strdup(tmp->access);
1081         if (tmp->type)
1082                 datacontrol->type = strdup(tmp->type);
1083
1084         return datacontrol;
1085 }
1086
1087 static gpointer __copy_appcontrol(gconstpointer src, gpointer data)
1088 {
1089         appcontrol_x *tmp = (appcontrol_x *)src;
1090         appcontrol_x *appcontrol;
1091
1092         appcontrol = calloc(1, sizeof(appcontrol_x));
1093         if (appcontrol == NULL) {
1094                 LOGE("memory alloc failed");
1095                 *(int *)data = -1;
1096                 return NULL;
1097         }
1098
1099         if (tmp->operation)
1100                 appcontrol->operation = strdup(tmp->operation);
1101         if (tmp->uri)
1102                 appcontrol->uri = strdup(tmp->uri);
1103         if (tmp->mime)
1104                 appcontrol->mime = strdup(tmp->mime);
1105
1106         return appcontrol;
1107 }
1108
1109 static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
1110 {
1111         splashscreen_x *tmp = (splashscreen_x *)src;
1112         splashscreen_x *splashscreen;
1113
1114         splashscreen = (splashscreen_x *)calloc(1, sizeof(splashscreen_x));
1115         if (splashscreen == NULL) {
1116                 LOGE("memory alloc failed");
1117                 *(int *)data = -1;
1118                 return NULL;
1119         }
1120
1121         if (tmp->src)
1122                 splashscreen->src = strdup(tmp->src);
1123         if (tmp->type)
1124                 splashscreen->type = strdup(tmp->type);
1125         if (tmp->orientation)
1126                 splashscreen->orientation = strdup(tmp->orientation);
1127         if (tmp->indicatordisplay)
1128                 splashscreen->indicatordisplay = strdup(tmp->indicatordisplay);
1129         if (tmp->operation)
1130                 splashscreen->operation = strdup(tmp->operation);
1131         if (tmp->color_depth)
1132                 splashscreen->color_depth = strdup(tmp->color_depth);
1133
1134         return splashscreen;
1135 }
1136
1137 static int _appinfo_copy_appinfo(application_x **application, application_x *data)
1138 {
1139         application_x *app_info;
1140         int ret;
1141
1142         app_info = calloc(1, sizeof(application_x));
1143         if (app_info == NULL) {
1144                 LOGE("memory alloc failed");
1145                 return PMINFO_R_ERROR;
1146         }
1147
1148         if (data->appid != NULL)
1149                 app_info->appid = strdup(data->appid);
1150         if (data->exec != NULL)
1151                 app_info->exec = strdup(data->exec);
1152         if (data->nodisplay != NULL)
1153                 app_info->nodisplay = strdup(data->nodisplay);
1154         if (data->multiple != NULL)
1155                 app_info->multiple = strdup(data->multiple);
1156         if (data->taskmanage != NULL)
1157                 app_info->taskmanage = strdup(data->taskmanage);
1158         if (data->type != NULL)
1159                 app_info->type = strdup(data->type);
1160         if (data->categories != NULL)
1161                 app_info->categories = strdup(data->categories);
1162         if (data->hwacceleration != NULL)
1163                 app_info->hwacceleration = strdup(data->hwacceleration);
1164         if (data->screenreader != NULL)
1165                 app_info->screenreader = strdup(data->screenreader);
1166         if (data->mainapp != NULL)
1167                 app_info->mainapp = strdup(data->mainapp);
1168         if (data->package != NULL)
1169                 app_info->package = strdup(data->package);
1170         if (data->recentimage != NULL)
1171                 app_info->recentimage = strdup(data->recentimage);
1172         if (data->launchcondition != NULL)
1173                 app_info->launchcondition = strdup(data->launchcondition);
1174         if (data->indicatordisplay != NULL)
1175                 app_info->indicatordisplay = strdup(data->indicatordisplay);
1176         if (data->portraitimg != NULL)
1177                 app_info->portraitimg = strdup(data->portraitimg);
1178         if (data->landscapeimg != NULL)
1179                 app_info->landscapeimg = strdup(data->landscapeimg);
1180         if (data->guestmode_visibility != NULL)
1181                 app_info->guestmode_visibility = strdup(data->guestmode_visibility);
1182         if (data->component != NULL)
1183                 app_info->component = strdup(data->component);
1184         if (data->permission_type != NULL)
1185                 app_info->permission_type = strdup(data->permission_type);
1186         if (data->component_type != NULL)
1187                 app_info->component_type = strdup(data->component_type);
1188         if (data->preload != NULL)
1189                 app_info->preload = strdup(data->preload);
1190         if (data->submode != NULL)
1191                 app_info->submode = strdup(data->submode);
1192         if (data->submode_mainid != NULL)
1193                 app_info->submode_mainid = strdup(data->submode_mainid);
1194         if (data->process_pool != NULL)
1195                 app_info->process_pool = strdup(data->process_pool);
1196         if (data->installed_storage != NULL)
1197                 app_info->installed_storage = strdup(data->installed_storage);
1198         if (data->autorestart != NULL)
1199                 app_info->autorestart = strdup(data->autorestart);
1200         if (data->onboot != NULL)
1201                 app_info->onboot = strdup(data->onboot);
1202         if (data->support_disable != NULL)
1203                 app_info->support_disable = strdup(data->support_disable);
1204         if (data->ui_gadget != NULL)
1205                 app_info->ui_gadget = strdup(data->ui_gadget);
1206         if (data->launch_mode != NULL)
1207                 app_info->launch_mode = strdup(data->launch_mode);
1208         if (data->package_type != NULL)
1209                 app_info->package_type = strdup(data->package_type);
1210         if (data->effective_appid != NULL)
1211                 app_info->effective_appid = strdup(data->effective_appid);
1212         if (data->splash_screen_display != NULL)
1213                 app_info->splash_screen_display = strdup(data->splash_screen_display);
1214
1215         /* GList */
1216         ret = 0;
1217         app_info->label = g_list_copy_deep(data->label, __copy_label, &ret);
1218         if (ret < 0) {
1219                 LOGE("memory alloc failed");
1220                 pkgmgrinfo_basic_free_application(app_info);
1221                 return PMINFO_R_ERROR;
1222         }
1223
1224         ret = 0;
1225         app_info->icon = g_list_copy_deep(data->icon, __copy_icon, &ret);
1226         if (ret < 0) {
1227                 LOGE("memory alloc failed");
1228                 pkgmgrinfo_basic_free_application(app_info);
1229                 return PMINFO_R_ERROR;
1230         }
1231
1232         ret = 0;
1233         app_info->category = g_list_copy_deep(data->category, __copy_str, &ret);
1234         if (ret < 0) {
1235                 LOGE("memory alloc failed");
1236                 pkgmgrinfo_basic_free_application(app_info);
1237                 return PMINFO_R_ERROR;
1238         }
1239
1240         ret = 0;
1241         app_info->metadata = g_list_copy_deep(data->metadata, __copy_metadata, &ret);
1242         if (ret < 0) {
1243                 LOGE("memory alloc failed");
1244                 pkgmgrinfo_basic_free_application(app_info);
1245                 return PMINFO_R_ERROR;
1246         }
1247
1248         ret = 0;
1249         app_info->datacontrol = g_list_copy_deep(data->datacontrol, __copy_datacontrol, &ret);
1250         if (ret < 0) {
1251                 LOGE("memory alloc failed");
1252                 pkgmgrinfo_basic_free_application(app_info);
1253                 return PMINFO_R_ERROR;
1254         }
1255
1256         ret = 0;
1257         app_info->appcontrol = g_list_copy_deep(data->appcontrol, __copy_appcontrol, &ret);
1258         if (ret < 0) {
1259                 LOGE("memory alloc failed");
1260                 pkgmgrinfo_basic_free_application(app_info);
1261                 return PMINFO_R_ERROR;
1262         }
1263
1264         ret = 0;
1265         app_info->background_category = g_list_copy_deep(data->background_category, __copy_str, &ret);
1266         if (ret < 0) {
1267                 LOGE("memory alloc failed");
1268                 pkgmgrinfo_basic_free_application(app_info);
1269                 return PMINFO_R_ERROR;
1270         }
1271
1272         ret = 0;
1273         app_info->splashscreens = g_list_copy_deep(data->splashscreens, __copy_splashscreens, &ret);
1274         if (ret < 0) {
1275                 LOGE("memory alloc failed");
1276                 pkgmgrinfo_basic_free_application(app_info);
1277                 return PMINFO_R_ERROR;
1278         }
1279
1280         *application = app_info;
1281
1282         return PMINFO_R_OK;
1283 }
1284
1285 API int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h handle,
1286                 pkgmgrinfo_appinfo_h *clone)
1287 {
1288         pkgmgr_appinfo_x *info;
1289         pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
1290
1291         if (handle == NULL)
1292                 return PMINFO_R_EINVAL;
1293
1294         info = calloc(1, sizeof(pkgmgr_appinfo_x));
1295         if (info == NULL) {
1296                 LOGE("memory alloc failed");
1297                 return PMINFO_R_ERROR;
1298         }
1299
1300         if (temp->package != NULL)
1301                 info->package = strdup(temp->package);
1302         if (temp->locale != NULL)
1303                 info->locale = strdup(temp->locale);
1304
1305         info->app_component = temp->app_component;
1306
1307         if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
1308                 LOGE("appinfo copy failed");
1309                 if (info->package)
1310                         free((void *)info->package);
1311                 if (info->locale)
1312                         free(info->locale);
1313                 free(info);
1314                 return PMINFO_R_ERROR;
1315         }
1316
1317         *clone = info;
1318
1319         return PMINFO_R_OK;
1320 }
1321
1322 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
1323                 pkgmgrinfo_filter_x *filter, int flag, pkgmgrinfo_app_list_cb app_list_cb,
1324                 void *user_data)
1325 {
1326         int ret;
1327         char *locale;
1328         application_x *app;
1329         pkgmgr_appinfo_x info;
1330         GHashTable *list;
1331         GHashTableIter iter;
1332         gpointer value;
1333
1334         locale = _get_system_locale();
1335         if (locale == NULL)
1336                 return PMINFO_R_ERROR;
1337
1338         list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1339                         __free_applications);
1340         if (list == NULL) {
1341                 free(locale);
1342                 return PMINFO_R_ERROR;
1343         }
1344
1345         if (__check_disable_filter_exist(filter) == false) {
1346                 pkgmgrinfo_appinfo_filter_add_bool(filter,
1347                                 PMINFO_APPINFO_PROP_APP_DISABLE, false);
1348         }
1349
1350         ret = _appinfo_get_applications(uid, uid, locale, filter, flag, list);
1351         if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1352                 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
1353                                 filter, flag, list);
1354
1355         if (ret != PMINFO_R_OK) {
1356                 g_hash_table_destroy(list);
1357                 free(locale);
1358                 return ret;
1359         }
1360
1361         g_hash_table_iter_init(&iter, list);
1362         while (g_hash_table_iter_next(&iter, NULL, &value)) {
1363                 app = (application_x *)value;
1364                 info.app_info = app;
1365                 info.locale = locale;
1366                 info.package = app->package;
1367                 if (app_list_cb(&info, user_data) < 0)
1368                         break;
1369         }
1370         g_hash_table_destroy(list);
1371         free(locale);
1372
1373         return PMINFO_R_OK;
1374 }
1375
1376 static const char *__appcomponent_str(pkgmgrinfo_app_component comp);
1377
1378 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
1379                 pkgmgrinfo_app_component component,
1380                 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
1381 {
1382         int ret;
1383         pkgmgrinfo_appinfo_filter_h filter;
1384         char *pkgid;
1385         const char *comp_str = NULL;
1386
1387         if (handle == NULL || app_func == NULL) {
1388                 LOGE("invalid parameter");
1389                 return PMINFO_R_EINVAL;
1390         }
1391
1392         if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
1393                 LOGE("invalid parameter");
1394                 return PMINFO_R_EINVAL;
1395         }
1396
1397         if (pkgmgrinfo_appinfo_filter_create(&filter))
1398                 return PMINFO_R_ERROR;
1399
1400         if (pkgmgrinfo_appinfo_filter_add_string(filter,
1401                                 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
1402                 pkgmgrinfo_appinfo_filter_destroy(filter);
1403                 return PMINFO_R_ERROR;
1404         }
1405
1406         comp_str = __appcomponent_str(component);
1407
1408         if (comp_str) {
1409                 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1410                                         PMINFO_APPINFO_PROP_APP_COMPONENT,
1411                                         comp_str)) {
1412                         pkgmgrinfo_appinfo_filter_destroy(filter);
1413                         return PMINFO_R_ERROR;
1414                 }
1415         }
1416
1417         ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1418                         PMINFO_APPINFO_GET_ALL, app_func, user_data);
1419
1420         pkgmgrinfo_appinfo_filter_destroy(filter);
1421
1422         return ret;
1423 }
1424
1425 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle,
1426                 pkgmgrinfo_app_component component,
1427                 pkgmgrinfo_app_list_cb app_func, void *user_data)
1428 {
1429         return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, _getuid());
1430 }
1431
1432 API int pkgmgrinfo_appinfo_get_usr_installed_list_full(
1433                 pkgmgrinfo_app_list_cb app_func, uid_t uid, int flag,
1434                 void *user_data)
1435 {
1436         int ret;
1437         pkgmgrinfo_appinfo_filter_h filter;
1438
1439         if (app_func == NULL) {
1440                 LOGE("invalid parameter");
1441                 return PMINFO_R_EINVAL;
1442         }
1443
1444         if (pkgmgrinfo_appinfo_filter_create(&filter))
1445                 return PMINFO_R_ERROR;
1446
1447         if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1448                                 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1449                 pkgmgrinfo_appinfo_filter_destroy(filter);
1450                 return PMINFO_R_ERROR;
1451         }
1452
1453         if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1454                         PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false)) {
1455                 pkgmgrinfo_appinfo_filter_destroy(filter);
1456                 return PMINFO_R_ERROR;
1457         }
1458
1459         ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, flag, app_func,
1460                         user_data);
1461
1462         pkgmgrinfo_appinfo_filter_destroy(filter);
1463
1464         return ret;
1465 }
1466
1467 API int pkgmgrinfo_appinfo_get_installed_list_full(
1468                 pkgmgrinfo_app_list_cb app_func, int flag, void *user_data)
1469 {
1470         return pkgmgrinfo_appinfo_get_usr_installed_list_full(app_func,
1471                         _getuid(), flag, user_data);
1472 }
1473
1474 API int pkgmgrinfo_appinfo_get_usr_installed_list(
1475                 pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1476 {
1477         int ret;
1478         pkgmgrinfo_appinfo_filter_h filter;
1479
1480         if (app_func == NULL) {
1481                 LOGE("invalid parameter");
1482                 return PMINFO_R_EINVAL;
1483         }
1484
1485         /* create an empty filter */
1486         ret = pkgmgrinfo_appinfo_filter_create(&filter);
1487         if (ret != PMINFO_R_OK)
1488                 return ret;
1489
1490         ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1491                         PMINFO_APPINFO_GET_ALL, app_func, user_data);
1492
1493         pkgmgrinfo_appinfo_filter_destroy(filter);
1494
1495         return ret;
1496 }
1497
1498 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func,
1499                 void *user_data)
1500 {
1501         return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, _getuid(),
1502                         user_data);
1503 }
1504
1505 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
1506 {
1507         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1508
1509         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1510         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1511
1512         if (info->app_info == NULL || info->app_info->appid == NULL)
1513                 return PMINFO_R_ERROR;
1514         *appid = (char *)info->app_info->appid;
1515
1516         return PMINFO_R_OK;
1517 }
1518
1519 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
1520 {
1521         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1522
1523         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1524         retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1525
1526         if (info->package == NULL)
1527                 return PMINFO_R_ERROR;
1528
1529         *pkg_name = (char *)info->package;
1530
1531         return PMINFO_R_OK;
1532 }
1533
1534 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
1535 {
1536         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1537
1538         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1539         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1540
1541         if (info->package == NULL)
1542                 return PMINFO_R_ERROR;
1543
1544         *pkgid = (char *)info->package;
1545
1546         return PMINFO_R_OK;
1547 }
1548
1549 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h  handle, char **pkgtype)
1550 {
1551         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1552         retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1553         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1554
1555         *pkgtype = (char *)info->app_info->package_type;
1556
1557         return PMINFO_R_OK;
1558 }
1559
1560 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
1561 {
1562         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1563
1564         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1565         retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1566
1567         if (info->app_info == NULL || info->app_info->exec == NULL)
1568                 return PMINFO_R_ERROR;
1569         *exec = (char *)info->app_info->exec;
1570
1571         return PMINFO_R_OK;
1572 }
1573
1574
1575 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1576 {
1577         icon_x *ptr;
1578         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1579
1580         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1581         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1582
1583         if (info->app_info == NULL)
1584                 return PMINFO_R_ERROR;
1585
1586         if (info->app_info->icon == NULL) {
1587                 *icon = "";
1588                 return PMINFO_R_OK;
1589         }
1590
1591         ptr = (icon_x *)info->app_info->icon->data;
1592         if (ptr == NULL)
1593                 return PMINFO_R_ERROR;
1594
1595         if (ptr->text == NULL)
1596                 return PMINFO_R_ERROR;
1597                 else
1598                         *icon = ptr->text;
1599
1600         return PMINFO_R_OK;
1601 }
1602
1603
1604 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
1605 {
1606         label_x *ptr;
1607         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1608
1609         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1610         retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1611
1612         if (info->app_info == NULL || info->app_info->label == NULL)
1613                 return PMINFO_R_ERROR;
1614
1615         ptr = (label_x *)info->app_info->label->data;
1616         if (ptr == NULL)
1617                 return PMINFO_R_ERROR;
1618
1619         if (ptr->text == NULL)
1620                 return PMINFO_R_ERROR;
1621         else
1622                 *label = ptr->text;
1623
1624         return PMINFO_R_OK;
1625 }
1626
1627 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1628 {
1629         char *result = NULL;
1630         char *query = NULL;
1631         sqlite3_stmt *stmt = NULL;
1632         sqlite3 *db = NULL;
1633         char *val;
1634         char *parser_db;
1635
1636         parser_db = getUserPkgParserDBPathUID(uid);
1637         if (parser_db == NULL) {
1638                 _LOGE("Failed to get parser db path");
1639                 goto err;
1640         }
1641
1642         if (__open_db(parser_db, &db, SQLITE_OPEN_READONLY) != SQLITE_OK) {
1643                 _LOGE("DB open fail\n");
1644                 free(parser_db);
1645                 goto err;
1646         }
1647         free(parser_db);
1648
1649         query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1650         if (query == NULL) {
1651                 _LOGE("Out of memory");
1652                 goto err;
1653         }
1654
1655         if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1656                 _LOGE("prepare_v2 fail\n");
1657                 goto err;
1658         }
1659
1660         if (sqlite3_step(stmt) == SQLITE_ROW) {
1661                 val = (char *)sqlite3_column_text(stmt, 0);
1662                 if (val != NULL)
1663                         result = strdup(val);
1664         }
1665
1666 err:
1667         sqlite3_finalize(stmt);
1668         sqlite3_free(query);
1669         sqlite3_close(db);
1670
1671         return result;
1672 }
1673
1674 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1675 {
1676         char *val;
1677
1678         retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1679
1680         val = _get_localed_label(appid, locale, uid);
1681         if (val == NULL)
1682                 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1683
1684         if (val == NULL) {
1685                 val = _get_localed_label(appid, locale, GLOBAL_USER);
1686                 if (val == NULL)
1687                         val = _get_localed_label(appid, DEFAULT_LOCALE, GLOBAL_USER);
1688         }
1689
1690         if (val == NULL)
1691                 return PMINFO_R_ERROR;
1692
1693         *label = val;
1694
1695         return PMINFO_R_OK;
1696 }
1697
1698 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1699 {
1700         return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, _getuid(), label);
1701 }
1702
1703 API int pkgmgrinfo_appinfo_get_metadata_value(pkgmgrinfo_appinfo_h handle, const char *metadata_key, char **metadata_value)
1704 {
1705         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1706         retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL");
1707         retvm_if(metadata_value == NULL, PMINFO_R_EINVAL, "metadata_value is NULL");
1708
1709         GList *list_md = NULL;
1710         metadata_x *metadata = NULL;
1711         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1712
1713         list_md = info->app_info->metadata;
1714
1715         for (; list_md; list_md = list_md->next) {
1716                 metadata = (metadata_x *)list_md->data;
1717                 if (metadata && metadata->key) {
1718                         if (strcasecmp(metadata->key, metadata_key) == 0) {
1719                                 if (metadata->value == NULL)
1720                                         *metadata_value = "";
1721                                 else
1722                                         *metadata_value = (char *)metadata->value;
1723                                 return PMINFO_R_OK;
1724                         }
1725                 }
1726         }
1727
1728         return PMINFO_R_EINVAL;
1729 }
1730
1731 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1732 {
1733         if (strcasecmp(comp, "uiapp") == 0)
1734                 return PMINFO_UI_APP;
1735         else if (strcasecmp(comp, "svcapp") == 0)
1736                 return PMINFO_SVC_APP;
1737         else if (strcasecmp(comp, "widgetapp") == 0)
1738                 return PMINFO_WIDGET_APP;
1739         else if (strcasecmp(comp, "watchapp") == 0)
1740                 return PMINFO_WATCH_APP;
1741         else
1742                 return -1;
1743 }
1744
1745 static const char *__appcomponent_str(pkgmgrinfo_app_component comp)
1746 {
1747         switch (comp) {
1748         case PMINFO_UI_APP:
1749                 return "uiapp";
1750         case PMINFO_SVC_APP:
1751                 return "svcapp";
1752         case PMINFO_WIDGET_APP:
1753                 return "widgetapp";
1754         case PMINFO_WATCH_APP:
1755                 return "watchapp";
1756         default:
1757                 return NULL;
1758         }
1759 }
1760
1761 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1762 {
1763         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1764         int comp;
1765
1766         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1767         retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1768
1769         if (info->app_info == NULL)
1770                 return PMINFO_R_ERROR;
1771
1772         comp = __appcomponent_convert(info->app_info->component);
1773         if (comp < 0)
1774                 return PMINFO_R_ERROR;
1775
1776         *component = comp;
1777
1778         return PMINFO_R_OK;
1779 }
1780
1781 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1782 {
1783         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1784
1785         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1786         retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1787
1788         if (info->app_info == NULL || info->app_info->type == NULL)
1789                 return PMINFO_R_ERROR;
1790         *app_type = (char *)info->app_info->type;
1791
1792         return PMINFO_R_OK;
1793 }
1794
1795 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h  handle,
1796                                         int *operation_count, char ***operation)
1797 {
1798         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1799         retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1800         retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1801         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1802         *operation_count = data->operation_count;
1803         *operation = data->operation;
1804         return PMINFO_R_OK;
1805 }
1806
1807 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h  handle,
1808                                         int *uri_count, char ***uri)
1809 {
1810         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1811         retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1812         retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1813         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1814         *uri_count = data->uri_count;
1815         *uri = data->uri;
1816         return PMINFO_R_OK;
1817 }
1818
1819 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h  handle,
1820                                         int *mime_count, char ***mime)
1821 {
1822         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1823         retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1824         retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1825         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1826         *mime_count = data->mime_count;
1827         *mime = data->mime;
1828         return PMINFO_R_OK;
1829 }
1830
1831 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h  handle,
1832                                         int *subapp_count, char ***subapp)
1833 {
1834         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1835         retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1836         retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1837         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1838         *subapp_count = data->subapp_count;
1839         *subapp = data->subapp;
1840         return PMINFO_R_OK;
1841 }
1842
1843 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1844 {
1845         char *val;
1846         icon_x *ptr;
1847         GList *tmp;
1848         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1849
1850         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1851         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1852
1853         if (info->app_info == NULL)
1854                 return PMINFO_R_ERROR;
1855
1856         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1857                 ptr = (icon_x *)tmp->data;
1858                 if (ptr == NULL || ptr->section == NULL)
1859                         continue;
1860
1861                 val = (char *)ptr->section;
1862                 if (val && strcmp(val, "setting") == 0) {
1863                         *icon = (char *)ptr->text;
1864                         return PMINFO_R_OK;
1865                 }
1866         }
1867
1868         return PMINFO_R_ERROR;
1869 }
1870
1871
1872 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1873 {
1874         char *val;
1875         icon_x *ptr;
1876         GList *tmp;
1877         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1878
1879         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1880         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1881
1882         if (info->app_info == NULL)
1883                 return PMINFO_R_ERROR;
1884
1885         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1886                 ptr = (icon_x *)tmp->data;
1887                 if (ptr == NULL || ptr->section == NULL)
1888                         continue;
1889
1890                 val = (char *)ptr->section;
1891                 if (val && strcmp(val, "notification") == 0) {
1892                         *icon = (char *)ptr->text;
1893                         return PMINFO_R_OK;
1894                 }
1895         }
1896
1897         return PMINFO_R_ERROR;
1898 }
1899
1900 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1901 {
1902         char *val;
1903         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1904
1905         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1906         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1907
1908         if (info->app_info == NULL || info->app_info->recentimage == NULL)
1909                 return PMINFO_R_ERROR;
1910
1911         val = (char *)info->app_info->recentimage;
1912         if (strcasecmp(val, "capture") == 0)
1913                 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1914         else if (strcasecmp(val, "icon") == 0)
1915                 *type = PMINFO_RECENTIMAGE_USE_ICON;
1916         else
1917                 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1918
1919         return PMINFO_R_OK;
1920 }
1921
1922 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1923 {
1924         char *val;
1925         image_x *ptr;
1926         GList *tmp;
1927         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1928
1929         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1930         retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1931
1932         if (info->app_info == NULL)
1933                 return PMINFO_R_ERROR;
1934
1935         for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1936                 ptr = (image_x *)tmp->data;
1937                 if (ptr == NULL || ptr->section == NULL)
1938                         continue;
1939
1940                 val = (char *)ptr->section;
1941                 if (val && strcmp(val, "preview") == 0) {
1942                         *preview_img = (char *)ptr->text;
1943                         return PMINFO_R_OK;
1944                 }
1945         }
1946
1947         return PMINFO_R_ERROR;
1948 }
1949
1950 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1951 {
1952         const char *val;
1953         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1954
1955         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1956         retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1957
1958         val = info->app_info->permission_type;
1959         if (val == NULL)
1960                 return PMINFO_R_ERROR;
1961
1962         if (strcmp(val, "signature") == 0)
1963                 *permission = PMINFO_PERMISSION_SIGNATURE;
1964         else if (strcmp(val, "privilege") == 0)
1965                 *permission = PMINFO_PERMISSION_PRIVILEGE;
1966         else
1967                 *permission = PMINFO_PERMISSION_NORMAL;
1968
1969         return PMINFO_R_OK;
1970 }
1971
1972 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1973 {
1974         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1975
1976         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1977         retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1978
1979         if (info->app_info == NULL || info->app_info->component_type == NULL)
1980                 return PMINFO_R_ERROR;
1981
1982         *component_type = (char *)info->app_info->component_type;
1983
1984         return PMINFO_R_OK;
1985 }
1986
1987 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1988 {
1989         char *val;
1990         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1991
1992         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1993         retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1994
1995         if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1996                 return PMINFO_R_ERROR;
1997
1998         val = (char *)info->app_info->hwacceleration;
1999         if (strcasecmp(val, "off") == 0)
2000                 *hwacceleration = PMINFO_HWACCELERATION_OFF;
2001         else if (strcasecmp(val, "on") == 0)
2002                 *hwacceleration = PMINFO_HWACCELERATION_ON;
2003         else
2004                 *hwacceleration = PMINFO_HWACCELERATION_DEFAULT;
2005
2006         return PMINFO_R_OK;
2007 }
2008
2009 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
2010 {
2011         char *val;
2012         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2013
2014         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2015         retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2016
2017         if (info->app_info == NULL || info->app_info->screenreader == NULL)
2018                 return PMINFO_R_ERROR;
2019
2020         val = (char *)info->app_info->screenreader;
2021         if (strcasecmp(val, "screenreader-off") == 0)
2022                 *screenreader = PMINFO_SCREENREADER_OFF;
2023         else if (strcasecmp(val, "screenreader-on") == 0)
2024                 *screenreader = PMINFO_SCREENREADER_ON;
2025         else
2026                 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
2027
2028         return PMINFO_R_OK;
2029 }
2030
2031 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
2032 {
2033         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2034
2035         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2036         retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2037         retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2038
2039         if (info->app_info == NULL)
2040                 return PMINFO_R_ERROR;
2041
2042         if (info->app_info->portraitimg == NULL)
2043                 *portrait_img = "";
2044         else
2045                 *portrait_img = (char *)info->app_info->portraitimg;
2046
2047         if (info->app_info->landscapeimg == NULL)
2048                 *landscape_img = "";
2049         else
2050                 *landscape_img = (char *)info->app_info->landscapeimg;
2051
2052         return PMINFO_R_OK;
2053 }
2054
2055 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
2056 {
2057         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2058
2059         if (handle == NULL || effectimage_type == NULL) {
2060                 LOGE("invalid parameter");
2061                 return PMINFO_R_EINVAL;
2062         }
2063
2064         if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
2065                 return PMINFO_R_ERROR;
2066
2067         *effectimage_type = (char *)info->app_info->effectimage_type;
2068
2069         return PMINFO_R_OK;
2070 }
2071
2072 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h  handle, char **submode_mainid)
2073 {
2074         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2075
2076         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2077         retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2078
2079         if (info->app_info == NULL)
2080                 return PMINFO_R_ERROR;
2081
2082         if (info->app_info->submode_mainid == NULL)
2083                 *submode_mainid = "";
2084         else
2085                 *submode_mainid = (char *)info->app_info->submode_mainid;
2086
2087         return PMINFO_R_OK;
2088 }
2089
2090 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
2091 {
2092         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2093         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2094
2095         if (info->app_info && info->app_info->installed_storage) {
2096                  if (strcmp(info->app_info->installed_storage, "installed_internal") == 0)
2097                         *storage = PMINFO_INTERNAL_STORAGE;
2098                  else if (strcmp(info->app_info->installed_storage, "installed_external") == 0)
2099                          *storage = PMINFO_EXTERNAL_STORAGE;
2100                  else
2101                          return PMINFO_R_ERROR;
2102         } else {
2103                 return PMINFO_R_ERROR;
2104         }
2105
2106         return PMINFO_R_OK;
2107 }
2108
2109 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
2110 {
2111         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2112
2113         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2114         retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2115
2116         if (info->app_info->launch_mode == NULL)
2117                 return PMINFO_R_ERROR;
2118
2119         *mode = (char *)(info->app_info->launch_mode);
2120
2121         return PMINFO_R_OK;
2122 }
2123
2124 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
2125 {
2126         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2127
2128         if (handle == NULL || alias_appid == NULL) {
2129                 LOGE("invalid parameter");
2130                 return PMINFO_R_EINVAL;
2131         }
2132
2133         if (info->app_info == NULL || info->app_info->alias_appid == NULL)
2134                 return PMINFO_R_ERROR;
2135
2136         *alias_appid = (char *)info->app_info->alias_appid;
2137
2138         return PMINFO_R_OK;
2139 }
2140
2141 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
2142 {
2143         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2144
2145         if (handle == NULL || effective_appid == NULL) {
2146                 LOGE("invalid parameter");
2147                 return PMINFO_R_EINVAL;
2148         }
2149
2150         if (info->app_info == NULL)
2151                 return PMINFO_R_ERROR;
2152
2153         if (info->app_info->effective_appid == NULL)
2154                 *effective_appid = "";
2155         else
2156                 *effective_appid = (char *)info->app_info->effective_appid;
2157
2158         return PMINFO_R_OK;
2159 }
2160
2161 API int pkgmgrinfo_appinfo_get_tep_name(pkgmgrinfo_appinfo_h handle, char **tep_name)
2162 {
2163         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2164
2165         if (handle == NULL || tep_name == NULL) {
2166                 LOGE("invalid parameter");
2167                 return PMINFO_R_EINVAL;
2168         }
2169
2170         if (info->app_info == NULL)
2171                 return PMINFO_R_ERROR;
2172
2173         if (info->app_info->tep_name == NULL)
2174                 *tep_name = "";
2175         else
2176                 *tep_name = (char *)info->app_info->tep_name;
2177
2178         return PMINFO_R_OK;
2179 }
2180
2181 API int pkgmgrinfo_appinfo_get_zip_mount_file(pkgmgrinfo_appinfo_h handle, char **zip_mount_file)
2182 {
2183         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2184
2185         if (handle == NULL || zip_mount_file == NULL) {
2186                 LOGE("invalid parameter");
2187                 return PMINFO_R_EINVAL;
2188         }
2189
2190         if (info->app_info == NULL)
2191                 return PMINFO_R_ERROR;
2192
2193         if (info->app_info->zip_mount_file == NULL)
2194                 *zip_mount_file = "";
2195         else
2196                 *zip_mount_file = (char *)info->app_info->zip_mount_file;
2197
2198         return PMINFO_R_OK;
2199 }
2200
2201 API int pkgmgrinfo_appinfo_get_root_path(pkgmgrinfo_appinfo_h handle, char **root_path)
2202 {
2203         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2204
2205         if (handle == NULL || root_path == NULL) {
2206                 LOGE("invalid parameter");
2207                 return PMINFO_R_EINVAL;
2208         }
2209
2210         if (info->app_info == NULL || info->app_info->root_path == NULL)
2211                 return PMINFO_R_ERROR;
2212
2213         *root_path = (char *)info->app_info->root_path;
2214
2215         return PMINFO_R_OK;
2216 }
2217
2218 API int pkgmgrinfo_appinfo_get_api_version(pkgmgrinfo_appinfo_h handle, char **api_version)
2219 {
2220         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2221
2222         if (handle == NULL || api_version == NULL) {
2223                 LOGE("invalid parameter");
2224                 return PMINFO_R_EINVAL;
2225         }
2226
2227         if (info->app_info == NULL || info->app_info->api_version == NULL)
2228                 return PMINFO_R_ERROR;
2229
2230         *api_version = (char *)info->app_info->api_version;
2231
2232         return PMINFO_R_OK;
2233 }
2234
2235 API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int *installed_time)
2236 {
2237         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2238
2239         if (handle == NULL || installed_time == NULL) {
2240                 LOGE("invalid parameter");
2241                 return PMINFO_R_EINVAL;
2242         }
2243
2244         if (info->app_info == NULL || info->app_info->package_installed_time == NULL)
2245                 return PMINFO_R_ERROR;
2246
2247         *installed_time = atoi(info->app_info->package_installed_time);
2248
2249         return PMINFO_R_OK;
2250 }
2251
2252 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
2253 {
2254         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2255         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2256         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2257         retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2258
2259         int ret = PMINFO_R_OK;
2260         char *query = NULL;
2261         sqlite3_stmt *stmt = NULL;
2262
2263         /*open db*/
2264         ret = __open_manifest_db(uid, true);
2265         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2266
2267         /*Start constructing query*/
2268         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
2269         tryvm_if(query == NULL, ret = PMINFO_R_ERROR, "Out of memory");
2270
2271         /*prepare query*/
2272         ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
2273         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
2274
2275         /*step query*/
2276         ret = sqlite3_step(stmt);
2277         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
2278
2279         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2280         *access = strdup((char *)sqlite3_column_text(stmt, 2));
2281
2282         ret = PMINFO_R_OK;
2283
2284 catch:
2285         sqlite3_free(query);
2286         sqlite3_finalize(stmt);
2287         __close_manifest_db();
2288         return ret;
2289 }
2290
2291 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
2292 {
2293         return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, _getuid(), appid, access);
2294 }
2295
2296 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
2297 {
2298         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2299         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2300
2301         int ret = PMINFO_R_OK;
2302         char *query = NULL;
2303         sqlite3_stmt *stmt = NULL;
2304
2305         /*open db*/
2306         ret = __open_manifest_db(uid, true);
2307         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2308
2309         /*Start constructing query*/
2310         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
2311         tryvm_if(query == NULL, ret = PMINFO_R_ERROR, "Out of memory");
2312
2313         /*prepare query*/
2314         ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
2315         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
2316
2317         /*step query*/
2318         ret = sqlite3_step(stmt);
2319         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
2320
2321         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2322
2323         ret = PMINFO_R_OK;
2324
2325 catch:
2326         sqlite3_free(query);
2327         sqlite3_finalize(stmt);
2328         __close_manifest_db();
2329         return ret;
2330 }
2331
2332 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
2333 {
2334         return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
2335 }
2336
2337 API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h  handle, int *support_mode)
2338 {
2339         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2340         retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2341
2342         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2343         if (info->app_info->support_mode)
2344                 *support_mode = atoi(info->app_info->support_mode);
2345         else
2346                 *support_mode = 0;
2347
2348         return PMINFO_R_OK;
2349 }
2350
2351 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
2352                         pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
2353 {
2354         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2355         retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2356         int ret = -1;
2357         permission_x *ptr;
2358         GList *tmp;
2359         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2360
2361         if (info->app_info == NULL)
2362                 return PMINFO_R_ERROR;
2363
2364         for (tmp = info->app_info->permission; tmp; tmp = tmp->next) {
2365                 ptr = (permission_x *)tmp->data;
2366                 if (ptr == NULL)
2367                         continue;
2368                 if (ptr->value) {
2369                         ret = permission_func(ptr->value, user_data);
2370                         if (ret < 0)
2371                                 break;
2372                 }
2373         }
2374         return PMINFO_R_OK;
2375 }
2376
2377 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
2378                         pkgmgrinfo_app_category_list_cb category_func, void *user_data)
2379 {
2380         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2381         retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2382         int ret = -1;
2383         const char *category;
2384         GList *tmp;
2385         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2386
2387         if (info->app_info == NULL)
2388                 return PMINFO_R_ERROR;
2389
2390         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2391                 category = (const char *)tmp->data;
2392                 if (category) {
2393                         ret = category_func(category, user_data);
2394                         if (ret < 0)
2395                                 break;
2396                 }
2397         }
2398         return PMINFO_R_OK;
2399 }
2400
2401 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
2402                         pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
2403 {
2404         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2405         retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2406         int ret = -1;
2407         metadata_x *ptr;
2408         GList *tmp;
2409         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2410
2411         if (info->app_info == NULL)
2412                 return PMINFO_R_ERROR;
2413
2414         for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
2415                 ptr = (metadata_x *)tmp->data;
2416                 if (ptr == NULL)
2417                         continue;
2418                 if (ptr->key) {
2419                         ret = metadata_func(ptr->key, ptr->value ? ptr->value : "", user_data);
2420                         if (ret < 0)
2421                                 break;
2422                 }
2423         }
2424         return PMINFO_R_OK;
2425 }
2426
2427 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
2428                         pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
2429 {
2430         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2431         retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2432         int ret;
2433         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2434         appcontrol_x *appcontrol;
2435         GList *tmp;
2436
2437         if (info->app_info == NULL)
2438                 return PMINFO_R_ERROR;
2439
2440         for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2441                 appcontrol = (appcontrol_x *)tmp->data;
2442                 if (appcontrol == NULL)
2443                         continue;
2444                 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
2445                 if (ret < 0)
2446                         break;
2447         }
2448
2449         return PMINFO_R_OK;
2450 }
2451
2452 API int pkgmgrinfo_appinfo_foreach_background_category(
2453                 pkgmgrinfo_appinfo_h handle,
2454                 pkgmgrinfo_app_background_category_list_cb category_func,
2455                 void *user_data)
2456 {
2457         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2458         GList *tmp;
2459         char *category;
2460
2461         if (handle == NULL || category_func == NULL || info->app_info == NULL) {
2462                 LOGE("invalid parameter");
2463                 return PMINFO_R_EINVAL;
2464         }
2465
2466         for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
2467                 category = (char *)tmp->data;
2468                 if (category == NULL)
2469                         continue;
2470
2471                 if (category_func(category, user_data) < 0)
2472                         break;
2473         }
2474
2475         return PMINFO_R_OK;
2476 }
2477
2478 API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
2479                 pkgmgrinfo_app_splash_screen_list_cb splash_screen_func,
2480                 void *user_data)
2481 {
2482         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2483         splashscreen_x *splashscreen;
2484         GList *tmp;
2485         int ret;
2486
2487         if (info == NULL || info->app_info == NULL
2488                         || splash_screen_func == NULL) {
2489                 LOGE("invalid parameter");
2490                 return PMINFO_R_EINVAL;
2491         }
2492
2493         for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) {
2494                 splashscreen = (splashscreen_x *)tmp->data;
2495                 if (splashscreen == NULL)
2496                         continue;
2497                 ret = splash_screen_func(splashscreen->src,
2498                                 splashscreen->type,
2499                                 splashscreen->orientation,
2500                                 splashscreen->indicatordisplay,
2501                                 splashscreen->operation,
2502                                 splashscreen->color_depth,
2503                                 user_data);
2504                 if (ret < 0)
2505                         break;
2506         }
2507
2508         return PMINFO_R_OK;
2509 }
2510
2511 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
2512 {
2513         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2514         retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2515         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2516
2517         if (info->app_info == NULL || info->app_info->nodisplay == NULL)
2518                 return PMINFO_R_ERROR;
2519
2520         *nodisplay = _get_bool_value(info->app_info->nodisplay);
2521
2522         return PMINFO_R_OK;
2523 }
2524
2525 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
2526 {
2527         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2528         retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2529         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2530
2531         if (info->app_info == NULL || info->app_info->multiple == NULL)
2532                 return PMINFO_R_ERROR;
2533
2534         *multiple = _get_bool_value(info->app_info->multiple);
2535
2536         return PMINFO_R_OK;
2537 }
2538
2539 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
2540 {
2541         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2542         retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2543         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2544
2545         if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
2546                 return PMINFO_R_ERROR;
2547
2548         *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
2549
2550         return PMINFO_R_OK;
2551 }
2552
2553 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h  handle, bool *taskmanage)
2554 {
2555         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2556         retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2557         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2558
2559         if (info->app_info == NULL || info->app_info->taskmanage == NULL)
2560                 return PMINFO_R_ERROR;
2561
2562         *taskmanage = _get_bool_value(info->app_info->taskmanage);
2563
2564         return PMINFO_R_OK;
2565 }
2566
2567 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h  handle, bool *enabled)
2568 {
2569         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2570         retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2571         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2572
2573         if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2574                 return PMINFO_R_ERROR;
2575
2576         *enabled = !_get_bool_value(info->app_info->is_disabled);
2577
2578         return PMINFO_R_OK;
2579 }
2580
2581 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h  handle, bool *onboot)
2582 {
2583         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2584         retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2585         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2586
2587         if (info->app_info == NULL || info->app_info->onboot == NULL)
2588                 return PMINFO_R_ERROR;
2589
2590         *onboot = _get_bool_value(info->app_info->onboot);
2591
2592         return PMINFO_R_OK;
2593 }
2594
2595 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h  handle, bool *autorestart)
2596 {
2597         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2598         retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2599         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2600
2601         if (info->app_info == NULL || info->app_info->autorestart == NULL)
2602                 return PMINFO_R_ERROR;
2603
2604         *autorestart = _get_bool_value(info->app_info->autorestart);
2605
2606         return PMINFO_R_OK;
2607 }
2608
2609 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h  handle, bool *mainapp)
2610 {
2611         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2612         retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2613         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2614
2615         if (info->app_info == NULL || info->app_info->mainapp == NULL)
2616                 return PMINFO_R_ERROR;
2617
2618         *mainapp = _get_bool_value(info->app_info->mainapp);
2619
2620         return PMINFO_R_OK;
2621 }
2622
2623 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
2624 {
2625         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2626         retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2627         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2628
2629         if (info->app_info == NULL || info->app_info->preload == NULL)
2630                 return PMINFO_R_ERROR;
2631
2632         *preload = _get_bool_value(info->app_info->preload);
2633
2634         return PMINFO_R_OK;
2635 }
2636
2637 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
2638 {
2639         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2640         retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2641         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2642
2643         if (info->app_info == NULL || info->app_info->submode == NULL)
2644                 return PMINFO_R_ERROR;
2645
2646         *submode = _get_bool_value(info->app_info->submode);
2647
2648         return PMINFO_R_OK;
2649 }
2650
2651 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
2652 {
2653         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2654
2655         if (handle == NULL || process_pool == NULL) {
2656                 LOGE("invalid parameter");
2657                 return PMINFO_R_EINVAL;
2658         }
2659
2660         if (info->app_info == NULL)
2661                 return PMINFO_R_ERROR;
2662
2663         *process_pool = _get_bool_value(info->app_info->process_pool);
2664
2665         return PMINFO_R_OK;
2666 }
2667
2668 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
2669 {
2670         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2671         retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
2672         retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
2673
2674         const char *val;
2675         GList *tmp;
2676         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2677
2678         if (info->app_info == NULL)
2679                 return PMINFO_R_ERROR;
2680
2681         *exist = 0;
2682         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2683                 val = (const char *)tmp->data;
2684                 if (val == NULL)
2685                         continue;
2686                 if (strcasecmp(val, category) == 0) {
2687                         *exist = 1;
2688                         break;
2689                 }
2690         }
2691
2692         return PMINFO_R_OK;
2693 }
2694
2695 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
2696                 bool *ui_gadget)
2697 {
2698         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2699
2700         if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
2701                 _LOGE("invalid parameter");
2702                 return PMINFO_R_EINVAL;
2703         }
2704         if (info->app_info->ui_gadget == NULL)
2705                 info->app_info->ui_gadget = strdup("false");
2706
2707         *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
2708
2709         return PMINFO_R_OK;
2710 }
2711
2712 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
2713                 bool *support_disable)
2714 {
2715         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2716
2717         if (info == NULL || info->app_info == NULL || support_disable == NULL) {
2718                 _LOGE("invalid parameter");
2719                 return PMINFO_R_EINVAL;
2720         }
2721
2722         *support_disable = _get_bool_value(info->app_info->support_disable);
2723
2724         return PMINFO_R_OK;
2725 }
2726
2727 API int pkgmgrinfo_appinfo_is_removable(pkgmgrinfo_appinfo_h handle,
2728                 bool *removable)
2729 {
2730         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2731
2732         if (info == NULL || info->app_info == NULL || removable == NULL) {
2733                 _LOGE("invalid parameter");
2734                 return PMINFO_R_EINVAL;
2735         }
2736
2737         *removable = _get_bool_value(info->app_info->removable);
2738
2739         return PMINFO_R_OK;
2740 }
2741
2742 API int pkgmgrinfo_appinfo_is_system(pkgmgrinfo_appinfo_h handle, bool *system)
2743 {
2744         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2745
2746         if (info == NULL || info->app_info == NULL || system == NULL) {
2747                 _LOGE("invalid parameter");
2748                 return PMINFO_R_EINVAL;
2749         }
2750
2751         *system = _get_bool_value(info->app_info->package_system);
2752
2753         return PMINFO_R_OK;
2754 }
2755
2756 API int pkgmgrinfo_appinfo_is_disabled(pkgmgrinfo_appinfo_h handle, bool *disabled)
2757 {
2758         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2759         retvm_if(disabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2760         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2761
2762         if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2763                 return PMINFO_R_ERROR;
2764
2765         *disabled = _get_bool_value(info->app_info->is_disabled);
2766
2767         return PMINFO_R_OK;
2768 }
2769
2770 API int pkgmgrinfo_appinfo_is_global(pkgmgrinfo_appinfo_h handle, bool *global)
2771 {
2772         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2773
2774         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2775         retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2776
2777         if (info->app_info == NULL || info->app_info->for_all_users == NULL)
2778                 return PMINFO_R_ERROR;
2779
2780         *global = _get_bool_value(info->app_info->for_all_users);
2781
2782         return PMINFO_R_OK;
2783 }
2784
2785 API int pkgmgrinfo_appinfo_get_splash_screen_display(pkgmgrinfo_appinfo_h handle, bool *splash_screen_display)
2786 {
2787         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2788
2789         if (info == NULL || splash_screen_display == NULL) {
2790                 _LOGE("Invalid parameter");
2791                 return PMINFO_R_EINVAL;
2792         }
2793
2794         if (info->app_info == NULL || info->app_info->splash_screen_display == NULL)
2795                 return PMINFO_R_ERROR;
2796
2797         *splash_screen_display = _get_bool_value(info->app_info->splash_screen_display);
2798
2799         return PMINFO_R_OK;
2800 }
2801
2802 API int pkgmgrinfo_appinfo_is_support_ambient(pkgmgrinfo_appinfo_h handle,
2803                 bool *support_ambient)
2804 {
2805         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2806
2807         if (info == NULL || support_ambient == NULL) {
2808                 _LOGE("Invalid parameter");
2809                 return PMINFO_R_EINVAL;
2810         }
2811
2812         if (info->app_info == NULL || info->app_info->support_ambient == NULL)
2813                 return PMINFO_R_ERROR;
2814
2815         *support_ambient = _get_bool_value(info->app_info->support_ambient);
2816
2817         return PMINFO_R_OK;
2818 }
2819
2820 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
2821 {
2822         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2823         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2824         __cleanup_appinfo(info);
2825         return PMINFO_R_OK;
2826 }
2827
2828 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
2829 {
2830         return (pkgmgrinfo_pkginfo_filter_create(handle));
2831 }
2832
2833 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
2834 {
2835         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2836 }
2837
2838 static gint __compare_func(gconstpointer data1, gconstpointer data2)
2839 {
2840         pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
2841         pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
2842         if (node1->prop == node2->prop)
2843                 return 0;
2844         else if (node1->prop > node2->prop)
2845                 return 1;
2846         else
2847                 return -1;
2848 }
2849
2850 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
2851                                 const char *property, const int value)
2852 {
2853         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2854         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2855         char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
2856         char *val = NULL;
2857         GSList *link = NULL;
2858         int prop = -1;
2859         prop = _pminfo_appinfo_convert_to_prop_int(property);
2860         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
2861                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
2862                 _LOGE("Invalid Integer Property\n");
2863                 return PMINFO_R_EINVAL;
2864         }
2865         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2866         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2867         if (node == NULL) {
2868                 _LOGE("Out of Memory!!!\n");
2869                 return PMINFO_R_ERROR;
2870         }
2871         snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
2872         val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
2873         if (val == NULL) {
2874                 _LOGE("Out of Memory\n");
2875                 free(node);
2876                 node = NULL;
2877                 return PMINFO_R_ERROR;
2878         }
2879         node->prop = prop;
2880         node->value = val;
2881         /*If API is called multiple times for same property, we should override the previous values.
2882         Last value set will be used for filtering.*/
2883         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2884         if (link)
2885                 filter->list = g_slist_delete_link(filter->list, link);
2886         filter->list = g_slist_append(filter->list, (gpointer)node);
2887         return PMINFO_R_OK;
2888
2889 }
2890
2891 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
2892                                 const char *property, const bool value)
2893 {
2894         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2895         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2896         char *val = NULL;
2897         GSList *link = NULL;
2898         int prop = -1;
2899         prop = _pminfo_appinfo_convert_to_prop_bool(property);
2900         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
2901                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
2902                 _LOGE("Invalid Boolean Property\n");
2903                 return PMINFO_R_EINVAL;
2904         }
2905         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2906         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2907         if (node == NULL) {
2908                 _LOGE("Out of Memory!!!\n");
2909                 return PMINFO_R_ERROR;
2910         }
2911         if (value)
2912                 val = strndup("true", 4);
2913         else
2914                 val = strndup("false", 5);
2915         if (val == NULL) {
2916                 _LOGE("Out of Memory\n");
2917                 free(node);
2918                 node = NULL;
2919                 return PMINFO_R_ERROR;
2920         }
2921         node->prop = prop;
2922         node->value = val;
2923         /*If API is called multiple times for same property, we should override the previous values.
2924         Last value set will be used for filtering.*/
2925         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2926         if (link)
2927                 filter->list = g_slist_delete_link(filter->list, link);
2928         filter->list = g_slist_append(filter->list, (gpointer)node);
2929         return PMINFO_R_OK;
2930
2931 }
2932
2933 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
2934                                 const char *property, const char *value)
2935 {
2936         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2937         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2938         retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2939         char *val = NULL;
2940         pkgmgrinfo_node_x *ptr = NULL;
2941         char prev[PKG_STRING_LEN_MAX] = {'\0'};
2942         char temp[PKG_STRING_LEN_MAX] = {'\0'};
2943         GSList *link = NULL;
2944         int prop = -1;
2945         prop = _pminfo_appinfo_convert_to_prop_str(property);
2946         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
2947                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
2948                 _LOGE("Invalid String Property\n");
2949                 return PMINFO_R_EINVAL;
2950         }
2951         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
2952         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
2953         if (node == NULL) {
2954                 _LOGE("Out of Memory!!!\n");
2955                 return PMINFO_R_ERROR;
2956         }
2957         node->prop = prop;
2958         switch (prop) {
2959         case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
2960                 node->value = strdup(value);
2961                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2962                 if (link)
2963                         filter->list = g_slist_delete_link(filter->list, link);
2964                 filter->list = g_slist_append(filter->list, (gpointer)node);
2965                 break;
2966         case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
2967                 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
2968                 if (val == NULL) {
2969                         _LOGE("Out of Memory\n");
2970                         free(node);
2971                         node = NULL;
2972                         return PMINFO_R_ERROR;
2973                 }
2974                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2975                 if (link) {
2976                         ptr = (pkgmgrinfo_node_x *)link->data;
2977                         strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
2978                         _LOGI("Previous value is %s\n", prev);
2979                         filter->list = g_slist_delete_link(filter->list, link);
2980                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value);
2981                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2982                         _LOGI("New value is %s\n", val);
2983                         node->value = val;
2984                         filter->list = g_slist_append(filter->list, (gpointer)node);
2985                         memset(temp, '\0', PKG_STRING_LEN_MAX);
2986                 } else {
2987                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s", value);
2988                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2989                         _LOGI("First value is %s\n", val);
2990                         node->value = val;
2991                         filter->list = g_slist_append(filter->list, (gpointer)node);
2992                         memset(temp, '\0', PKG_STRING_LEN_MAX);
2993                 }
2994                 break;
2995         default:
2996                 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
2997                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2998                 if (link)
2999                         filter->list = g_slist_delete_link(filter->list, link);
3000                 filter->list = g_slist_append(filter->list, (gpointer)node);
3001                 break;
3002         }
3003         return PMINFO_R_OK;
3004 }
3005
3006 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
3007 {
3008         int ret;
3009         char *locale;
3010         GHashTable *list;
3011
3012         if (handle == NULL || count == NULL) {
3013                 _LOGE("invalid parameter");
3014                 return PMINFO_R_EINVAL;
3015         }
3016
3017         locale = _get_system_locale();
3018         if (locale == NULL)
3019                 return PMINFO_R_ERROR;
3020
3021         list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
3022                         __free_applications);
3023         if (list == NULL) {
3024                 free(locale);
3025                 return PMINFO_R_ERROR;
3026         }
3027
3028         ret = _appinfo_get_applications(uid, uid, locale, handle, 0, list);
3029         if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
3030                 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
3031                                 handle, 0, list);
3032
3033         if (ret != PMINFO_R_OK) {
3034                 g_hash_table_destroy(list);
3035                 free(locale);
3036                 return PMINFO_R_ERROR;
3037         }
3038
3039         *count = g_hash_table_size(list);
3040         g_hash_table_destroy(list);
3041         free(locale);
3042
3043         return PMINFO_R_OK;
3044 }
3045
3046 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
3047 {
3048         return pkgmgrinfo_appinfo_usr_filter_count(handle, count, _getuid());
3049 }
3050
3051 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
3052                 pkgmgrinfo_appinfo_filter_h handle,
3053                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3054 {
3055         if (handle == NULL || app_cb == NULL) {
3056                 LOGE("invalid parameter");
3057                 return PMINFO_R_EINVAL;
3058         }
3059
3060         return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3061                         user_data);
3062 }
3063
3064 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
3065                                 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3066 {
3067         return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, _getuid());
3068 }
3069
3070 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
3071 {
3072         return (pkgmgrinfo_pkginfo_filter_create(handle));
3073 }
3074
3075 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
3076 {
3077         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3078 }
3079
3080 API int pkgmgrinfo_appinfo_metadata_filter_add(
3081                 pkgmgrinfo_appinfo_metadata_filter_h handle,
3082                 const char *key, const char *value)
3083 {
3084         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3085         pkgmgrinfo_metadata_node_x *node;
3086
3087         /* value can be NULL.
3088          * In that case all apps with specified key should be displayed
3089          */
3090         if (key == NULL) {
3091                 LOGE("invalid parameter");
3092                 return PMINFO_R_EINVAL;
3093         }
3094
3095         node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x));
3096         if (node == NULL) {
3097                 LOGE("out of memory");
3098                 return PMINFO_R_ERROR;
3099         }
3100
3101         node->key = strdup(key);
3102         if (value && strlen(value))
3103                 node->value = strdup(value);
3104
3105         filter->list_metadata = g_slist_append(filter->list_metadata,
3106                         (gpointer)node);
3107
3108         return PMINFO_R_OK;
3109 }
3110
3111 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
3112                 pkgmgrinfo_appinfo_metadata_filter_h handle,
3113                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3114 {
3115         if (handle == NULL || app_cb == NULL) {
3116                 LOGE("invalid parameter");
3117                 return PMINFO_R_EINVAL;
3118         }
3119
3120         return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3121                         user_data);
3122 }
3123
3124 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
3125                 pkgmgrinfo_appinfo_metadata_filter_h handle,
3126                 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3127 {
3128         return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
3129                         user_data, _getuid());
3130 }
3131
3132 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
3133 {
3134         const char *val;
3135         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3136
3137         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3138         retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3139
3140         val = info->app_info->guestmode_visibility;
3141         *status = _get_bool_value(val);
3142         return PMINFO_R_OK;
3143 }