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