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