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