6e5db43bfce4c6e3b535b1ce0c5387e28702c304
[platform/core/api/app-manager.git] / src / app_info.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <unistd.h>
22
23 #include <pkgmgr-info.h>
24 #include <package-manager.h>
25 #include <dlog.h>
26
27 #include "app_info.h"
28 #include "app_manager.h"
29 #include "app_manager_internal.h"
30
31 #ifdef LOG_TAG
32 #undef LOG_TAG
33 #endif
34
35 #define LOG_TAG "TIZEN_N_APP_MANAGER"
36
37 struct app_info_s {
38         char *app_id;
39         pkgmgrinfo_appinfo_h pkg_app_info;
40 };
41
42 struct app_info_filter_s {
43         pkgmgrinfo_appinfo_filter_h pkg_app_info_filter;
44 };
45
46 struct app_info_metadata_filter_s {
47         pkgmgrinfo_appinfo_metadata_filter_h pkg_app_info_metadata_filter;
48 };
49
50 typedef struct _foreach_context_{
51         app_manager_app_info_cb callback;
52         void *user_data;
53 } foreach_context_s;
54
55 typedef struct _foreach_metada_context_{
56         app_info_metadata_cb callback;
57         void *user_data;
58 } foreach_metadata_context_s;
59
60 static int app_info_convert_str_property(const char *property, char **converted_property)
61 {
62         if (property == NULL)
63                 return -1;
64
65         if (strcmp(property, PACKAGE_INFO_PROP_APP_ID)==0)
66                 *converted_property = PMINFO_APPINFO_PROP_APP_ID;
67
68         else if (strcmp(property, PACKAGE_INFO_PROP_APP_TYPE)==0)
69                 *converted_property = PMINFO_APPINFO_PROP_APP_TYPE;
70
71         else if (strcmp(property, PACKAGE_INFO_PROP_APP_CATEGORY)==0)
72                 *converted_property = PMINFO_APPINFO_PROP_APP_CATEGORY;
73
74         else
75                 return -1;
76
77         return 0;
78 }
79
80 static int app_info_convert_bool_property(const char *property, char **converted_property)
81 {
82         if (property == NULL)
83                 return -1;
84
85         if (strcmp(property, PACKAGE_INFO_PROP_APP_NODISPLAY)==0)
86                 *converted_property = PMINFO_APPINFO_PROP_APP_NODISPLAY;
87
88         else if (strcmp(property, PACKAGE_INFO_PROP_APP_TASKMANAGE)==0)
89                 *converted_property = PMINFO_APPINFO_PROP_APP_TASKMANAGE;
90
91         else
92                 return -1;
93
94         return 0;
95 }
96
97 static int app_info_foreach_app_filter_cb(pkgmgrinfo_appinfo_h handle, void *user_data)
98 {
99         int retval = 0;
100         char *appid = NULL;
101         app_info_h info = NULL;
102         info = calloc(1, sizeof(struct app_info_s));
103         if (info == NULL) {
104                 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
105         }
106
107         foreach_context_s *foreach_context = user_data;
108         if (handle == NULL || foreach_context == NULL)
109         {
110                 free(info);
111                 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
112         }
113
114         retval = pkgmgrinfo_appinfo_get_appid(handle, &appid);
115         if (retval < 0)
116         {
117                 free(info);
118                 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
119         }
120
121         info->app_id = strdup(appid);
122         info->pkg_app_info = handle;
123
124         foreach_context->callback(info, foreach_context->user_data);
125
126         return APP_MANAGER_ERROR_NONE;
127 }
128
129 static int app_info_foreach_app_metadata_cb(const char *metadata_key, const char *metadata_value, void *user_data)
130 {
131         foreach_metadata_context_s *foreach_context = user_data;
132
133         if (metadata_value == NULL || foreach_context == NULL)
134         {
135                 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
136         }
137
138         foreach_context->callback(metadata_key, metadata_value, foreach_context->user_data);
139
140         return APP_MANAGER_ERROR_NONE;
141 }
142
143 static int app_info_foreach_app_info_cb(pkgmgrinfo_appinfo_h handle, void *cb_data)
144 {
145         foreach_context_s *foreach_context = cb_data;
146         app_info_h app_info = NULL;
147         char *appid = NULL;
148         int ret = 0;
149         bool iteration_next = true;
150
151         if (handle == NULL || foreach_context == NULL)
152         {
153                 app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
154                 return PMINFO_R_ERROR;
155         }
156
157         ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
158         if (ret != PMINFO_R_OK) {
159                 app_manager_error(APP_MANAGER_ERROR_NO_SUCH_APP, __FUNCTION__, NULL);
160                 return PMINFO_R_ERROR;
161         }
162
163         if (app_info_create(appid, &app_info) == APP_MANAGER_ERROR_NONE)
164         {
165                 iteration_next = foreach_context->callback(app_info, foreach_context->user_data);
166                 app_info_destroy(app_info);
167         }
168
169         if (iteration_next == true)
170         {
171                 return PMINFO_R_OK;
172         }
173         else
174         {
175                 return PMINFO_R_ERROR;
176         }
177 }
178
179 int app_info_foreach_app_info(app_manager_app_info_cb callback, void *user_data)
180 {
181         foreach_context_s foreach_context = {
182                 .callback = callback,
183                 .user_data = user_data,
184         };
185
186         if (callback == NULL)
187         {
188                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
189         }
190
191         pkgmgrinfo_appinfo_get_usr_installed_list(app_info_foreach_app_info_cb, getuid(), &foreach_context);
192
193         return APP_MANAGER_ERROR_NONE;
194 }
195
196 API int app_info_create(const char *app_id, app_info_h *app_info)
197 {
198         pkgmgrinfo_pkginfo_h pkginfo = NULL;
199         pkgmgrinfo_appinfo_h appinfo = NULL;
200         app_info_h info = NULL;
201         int retval = 0;
202         char *main_appid = NULL;
203
204         if (app_id == NULL || app_info == NULL) {
205                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
206         }
207         info = calloc(1, sizeof(struct app_info_s));
208         if (info == NULL) {
209                 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
210         }
211
212         retval = pkgmgrinfo_pkginfo_get_usr_pkginfo(app_id, getuid(), &pkginfo);
213         if (retval < 0) {
214                 if (pkgmgrinfo_appinfo_get_usr_appinfo(app_id, getuid(), &appinfo)) {
215                         free(info);
216                         return app_manager_error(APP_MANAGER_ERROR_NO_SUCH_APP, __FUNCTION__, NULL);
217                 }
218
219                 info->app_id = strdup(app_id);
220                 info->pkg_app_info = appinfo;
221                 *app_info = info;
222                 return APP_MANAGER_ERROR_NONE;
223         }
224
225         retval = pkgmgrinfo_pkginfo_get_mainappid(pkginfo, &main_appid);
226         if (retval < 0) {
227                 app_manager_error(APP_MANAGER_ERROR_NO_SUCH_APP, __FUNCTION__, NULL);
228         }
229
230         if (pkgmgrinfo_appinfo_get_usr_appinfo(main_appid, getuid(), &appinfo)) {
231                 free(info);
232                 return app_manager_error(APP_MANAGER_ERROR_NO_SUCH_APP, __FUNCTION__, NULL);
233         }
234
235         info->app_id = strdup(main_appid);
236         info->pkg_app_info = appinfo;
237         *app_info = info;
238
239         pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
240
241         return APP_MANAGER_ERROR_NONE;
242 }
243
244 API int app_info_destroy(app_info_h app_info)
245 {
246         if (app_info == NULL)
247         {
248                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
249         }
250         if (app_info->app_id) {
251                 free(app_info->app_id);
252                 app_info->app_id = NULL;
253         }
254         pkgmgrinfo_appinfo_destroy_appinfo(app_info->pkg_app_info);
255         free(app_info);
256         return APP_MANAGER_ERROR_NONE;
257 }
258
259 API int app_info_get_app_id(app_info_h app_info, char **app_id)
260 {
261         char *app_id_dup;
262
263         if (app_info == NULL || app_id == NULL)
264         {
265                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
266         }
267
268         app_id_dup = strdup(app_info->app_id);
269
270         if (app_id_dup == NULL)
271         {
272                 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
273         }
274
275         *app_id = app_id_dup;
276
277         return APP_MANAGER_ERROR_NONE;
278 }
279
280 API int app_info_get_exec(app_info_h app_info, char **exec)
281 {
282         char *val;
283         char *app_exec_dup;
284
285         if (app_info == NULL || exec == NULL)
286         {
287                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
288         }
289
290         pkgmgrinfo_appinfo_get_exec(app_info->pkg_app_info, &val);
291         if (val == NULL)
292         {
293                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
294         }
295
296         app_exec_dup = strdup(val);
297         if (app_exec_dup == NULL)
298         {
299                 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
300         }
301
302         *exec = app_exec_dup;
303
304         return APP_MANAGER_ERROR_NONE;
305 }
306
307 API int app_info_get_label(app_info_h app_info, char **label)
308 {
309         char *val;
310         char *app_label_dup;
311
312         if (app_info == NULL || label == NULL)
313         {
314                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
315         }
316
317         pkgmgrinfo_appinfo_get_label(app_info->pkg_app_info, &val);
318         if (val == NULL)
319         {
320                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
321         }
322
323         app_label_dup = strdup(val);
324         if (app_label_dup == NULL)
325         {
326                 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
327         }
328
329         *label = app_label_dup;
330
331         return APP_MANAGER_ERROR_NONE;
332 }
333
334 API int app_info_get_localed_label(const char *app_id, const char *locale, char **label)
335 {
336         char *val;
337         char *app_label_dup;
338
339         if (app_id == NULL || locale == NULL || label == NULL)
340         {
341                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
342         }
343
344         if (pkgmgrinfo_appinfo_usr_get_localed_label(app_id, locale, getuid(), &val))
345         {
346                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
347         }
348
349         app_label_dup = strdup(val);
350         if (app_label_dup == NULL)
351         {
352                 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
353         }
354
355         *label = app_label_dup;
356         free(val);
357
358         return APP_MANAGER_ERROR_NONE;
359 }
360
361 API int app_info_get_icon(app_info_h app_info, char **path)
362 {
363         char *val;
364         char *app_icon_dup;
365
366         if (app_info == NULL || path == NULL)
367         {
368                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
369         }
370
371         pkgmgrinfo_appinfo_get_icon(app_info->pkg_app_info, &val);
372         if (val == NULL)
373         {
374                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
375         }
376
377         app_icon_dup = strdup(val);
378         if (app_icon_dup == NULL)
379         {
380                 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
381         }
382
383         *path = app_icon_dup;
384
385         return APP_MANAGER_ERROR_NONE;
386 }
387
388 API int app_info_get_package(app_info_h app_info, char **package)
389 {
390         char *val;
391         char *app_package_dup;
392
393         if (app_info == NULL || package == NULL)
394         {
395                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
396         }
397
398         pkgmgrinfo_appinfo_get_pkgname(app_info->pkg_app_info, &val);
399
400         app_package_dup = strdup(val);
401         if (app_package_dup == NULL)
402         {
403                 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
404         }
405
406         *package = app_package_dup;
407
408         return APP_MANAGER_ERROR_NONE;
409 }
410
411 API int app_info_get_type(app_info_h app_info, char **type)
412 {
413         char *val;
414         char *app_type_dup;
415
416         if (app_info == NULL || type == NULL)
417         {
418                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
419         }
420
421         pkgmgrinfo_appinfo_get_apptype(app_info->pkg_app_info, &val);
422
423         app_type_dup = strdup(val);
424         if (app_type_dup == NULL)
425         {
426                 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
427         }
428
429         *type = app_type_dup;
430
431         return APP_MANAGER_ERROR_NONE;
432 }
433
434 API int app_info_foreach_metadata(app_info_h app_info, app_info_metadata_cb callback, void *user_data)
435 {
436         int retval = 0;
437
438         if (app_info == NULL || callback == NULL)
439         {
440                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
441         }
442
443         foreach_metadata_context_s foreach_context = {
444                 .callback = callback,
445                 .user_data = user_data,
446         };
447
448         retval = pkgmgrinfo_appinfo_foreach_metadata(app_info->pkg_app_info, app_info_foreach_app_metadata_cb, &foreach_context);
449         if (retval < 0)
450         {
451                 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
452         }
453
454         return APP_MANAGER_ERROR_NONE;
455 }
456
457 API int app_info_is_nodisplay(app_info_h app_info, bool *nodisplay)
458 {
459         bool val;
460
461         if (app_info == NULL || nodisplay == NULL)
462         {
463                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
464         }
465
466         if (pkgmgrinfo_appinfo_is_nodisplay(app_info->pkg_app_info, &val) < 0)
467                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
468
469         *nodisplay = val;
470         return APP_MANAGER_ERROR_NONE;
471 }
472
473 API int app_info_is_enabled(app_info_h app_info, bool *enabled)
474 {
475         bool val;
476
477         if (app_info == NULL || enabled == NULL)
478         {
479                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
480         }
481
482         if (pkgmgrinfo_appinfo_is_enabled(app_info->pkg_app_info, &val) < 0)
483                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
484
485         *enabled = val;
486         return APP_MANAGER_ERROR_NONE;
487
488 }
489
490 API int app_info_is_equal(app_info_h lhs, app_info_h rhs, bool *equal)
491 {
492         if (lhs == NULL || rhs == NULL || equal == NULL)
493         {
494                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
495         }
496
497         if (!strcmp(lhs->app_id, rhs->app_id))
498         {
499                 *equal = true;
500         }
501         else
502         {
503                 *equal = false;
504         }
505
506         return APP_MANAGER_ERROR_NONE;
507 }
508
509 API int app_info_is_onboot(app_info_h app_info, bool *onboot)
510 {
511         bool val;
512
513         if (app_info == NULL || onboot == NULL)
514         {
515                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
516         }
517
518         if (pkgmgrinfo_appinfo_is_onboot(app_info->pkg_app_info, &val) < 0)
519         {
520                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
521         }
522
523         *onboot = val;
524         return APP_MANAGER_ERROR_NONE;
525 }
526
527 API int app_info_is_preload(app_info_h app_info, bool *preload)
528 {
529         bool val;
530
531         if (app_info == NULL || preload == NULL)
532         {
533                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
534         }
535
536         if (pkgmgrinfo_appinfo_is_preload(app_info->pkg_app_info, &val) < 0)
537         {
538                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
539         }
540
541         *preload = val;
542         return APP_MANAGER_ERROR_NONE;
543 }
544
545 API int app_info_clone(app_info_h *clone, app_info_h app_info)
546 {
547         int retval;
548
549         if (clone == NULL || app_info == NULL)
550         {
551                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
552         }
553
554         retval = app_info_create(app_info->app_id, clone);
555
556         if (retval != APP_MANAGER_ERROR_NONE)
557         {
558                 return app_manager_error(retval, __FUNCTION__, NULL);
559         }
560
561         return APP_MANAGER_ERROR_NONE;
562 }
563
564 API int app_info_filter_create(app_info_filter_h *handle)
565 {
566         int retval = 0;
567         app_info_filter_h filter_created = NULL;
568         pkgmgrinfo_appinfo_filter_h filter_h = NULL;
569
570         if (handle == NULL)
571         {
572                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
573         }
574
575         retval = pkgmgrinfo_appinfo_filter_create(&filter_h);
576         if (retval < 0) {
577                 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
578         }
579
580         filter_created = calloc(1, sizeof(struct app_info_filter_s));
581         if (filter_created == NULL)
582         {
583                 free(filter_h);
584                 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
585         }
586
587         filter_created->pkg_app_info_filter = filter_h;
588
589         *handle = filter_created;
590
591         return APP_MANAGER_ERROR_NONE;
592 }
593
594 API int app_info_filter_destroy(app_info_filter_h handle)
595 {
596         int retval = 0;
597
598         if (handle == NULL)
599         {
600                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
601         }
602
603         retval = pkgmgrinfo_appinfo_filter_destroy(handle->pkg_app_info_filter);
604         if (retval < 0)
605         {
606                 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
607         }
608
609         free(handle);
610         return APP_MANAGER_ERROR_NONE;
611 }
612
613 API int app_info_filter_add_bool(app_info_filter_h handle, const char *property, const bool value)
614 {
615         int retval = 0;
616         char *converted_property = NULL;
617
618         if ((handle == NULL) || (property == NULL))
619         {
620                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
621         }
622
623         retval = app_info_convert_bool_property(property, &converted_property);
624         if (retval < 0)
625         {
626                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
627         }
628
629         retval = pkgmgrinfo_appinfo_filter_add_bool(handle->pkg_app_info_filter, converted_property, value);
630         if (retval < 0)
631         {
632                 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
633         }
634
635         return APP_MANAGER_ERROR_NONE;
636 }
637
638 API int app_info_filter_add_string(app_info_filter_h handle, const char *property, const char *value)
639 {
640         int retval = 0;
641         char *converted_property = NULL;
642
643         if ((handle == NULL) || (property == NULL))
644         {
645                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
646         }
647
648         retval = app_info_convert_str_property(property, &converted_property);
649         if (retval < 0)
650         {
651                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
652         }
653
654         retval = pkgmgrinfo_appinfo_filter_add_string(handle->pkg_app_info_filter, converted_property, value);
655         if (retval < 0)
656         {
657                 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
658         }
659
660         return APP_MANAGER_ERROR_NONE;
661 }
662
663 API int app_info_filter_count_appinfo(app_info_filter_h handle, int *count)
664 {
665         int retval = 0;
666
667         if ((handle == NULL) || (count == NULL))
668         {
669                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
670         }
671
672         retval = pkgmgrinfo_appinfo_filter_count(handle->pkg_app_info_filter, count);
673         if (retval < 0)
674         {
675                 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
676         }
677
678         return APP_MANAGER_ERROR_NONE;
679 }
680
681 API int app_info_filter_foreach_appinfo(app_info_filter_h handle, app_info_filter_cb callback, void * user_data)
682 {
683         int retval = 0;
684
685         foreach_context_s foreach_context = {
686                 .callback = callback,
687                 .user_data = user_data,
688         };
689
690         if ((handle == NULL) || (callback == NULL))
691         {
692                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
693         }
694
695         retval = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle->pkg_app_info_filter, app_info_foreach_app_filter_cb, &foreach_context);
696         if (retval < 0)
697         {
698                 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
699         }
700
701         return APP_MANAGER_ERROR_NONE;
702 }
703
704 API int app_info_metadata_filter_create(app_info_metadata_filter_h *handle)
705 {
706         int retval = 0;
707         app_info_metadata_filter_h filter_created = NULL;
708         pkgmgrinfo_appinfo_metadata_filter_h filter_h = NULL;
709
710         if (handle == NULL)
711         {
712                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
713         }
714
715         filter_created = calloc(1, sizeof(struct app_info_metadata_filter_s));
716         if (filter_created == NULL)
717         {
718                 return app_manager_error(APP_MANAGER_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
719         }
720
721         retval = pkgmgrinfo_appinfo_metadata_filter_create(&filter_h);
722         if (retval < 0) {
723                 free(filter_created);
724                 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
725         }
726
727         filter_created->pkg_app_info_metadata_filter = filter_h;
728
729         *handle = filter_created;
730
731         return APP_MANAGER_ERROR_NONE;
732 }
733
734 API int app_info_metadata_filter_destroy(app_info_metadata_filter_h handle)
735 {
736         int retval = 0;
737
738         if (handle == NULL)
739         {
740                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
741         }
742
743         retval = pkgmgrinfo_appinfo_metadata_filter_destroy(handle->pkg_app_info_metadata_filter);
744         if (retval < 0)
745         {
746                 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
747         }
748
749         free(handle);
750         return APP_MANAGER_ERROR_NONE;
751 }
752
753 API int app_info_metadata_filter_add(app_info_metadata_filter_h handle, const char *key, const char *value)
754 {
755         int retval = 0;
756
757         if ((handle == NULL) || (key == NULL))
758         {
759                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
760         }
761
762         retval = pkgmgrinfo_appinfo_metadata_filter_add(handle->pkg_app_info_metadata_filter, key, value);
763         if (retval < 0)
764         {
765                 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
766         }
767
768         return APP_MANAGER_ERROR_NONE;
769 }
770
771 API int app_info_metadata_filter_foreach(app_info_metadata_filter_h handle, app_info_filter_cb callback, void *user_data)
772 {
773         int retval = 0;
774
775         foreach_context_s foreach_context = {
776                 .callback = callback,
777                 .user_data = user_data,
778         };
779
780         if (handle == NULL)
781         {
782                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
783         }
784
785         if (callback == NULL)
786         {
787                 return app_manager_error(APP_MANAGER_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
788         }
789
790         retval = pkgmgrinfo_appinfo_metadata_filter_foreach(handle->pkg_app_info_metadata_filter, app_info_foreach_app_filter_cb, &foreach_context);
791         if (retval < 0)
792         {
793                 return app_manager_error(APP_MANAGER_ERROR_IO_ERROR, __FUNCTION__, NULL);
794         }
795
796         return APP_MANAGER_ERROR_NONE;
797 }