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