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