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