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