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