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