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