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