Use GList instead of custom linked list
[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
18 static bool _get_bool_value(const char *str)
19 {
20         if (str == NULL)
21                 return false;
22         else if (!strcasecmp(str, "true"))
23                 return true;
24         else
25                 return false;
26 }
27
28 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
29 {
30         pkgmgr_appinfo_x *info = data;
31         pkgmgr_appinfo_x *tmp;
32
33         while (info != NULL) {
34                 tmp = info->next;
35                 if (info->package)
36                         free((void *)info->package);
37                 if (info->locale)
38                         free((void *)info->locale);
39
40                 pkgmgrinfo_basic_free_application(info->app_info);
41                 free((void *)info);
42                 info = tmp;
43         }
44         return;
45 }
46
47 static char *_get_filtered_query(const char *query_raw,
48                 pkgmgrinfo_filter_x *filter)
49 {
50         char buf[MAX_QUERY_LEN] = { 0, };
51         char *condition;
52         size_t len;
53         GSList *list;
54         GSList *head = NULL;
55
56         if (filter)
57                 head = filter->list;
58
59         strncat(buf, query_raw, MAX_QUERY_LEN - 1);
60         len = strlen(buf);
61         for (list = head; list; list = list->next) {
62                 /* TODO: revise condition getter function */
63                 __get_filter_condition(list->data, &condition);
64                 if (condition == NULL)
65                         continue;
66                 if (buf[strlen(query_raw)] == '\0') {
67                         len += strlen(" WHERE ");
68                         strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1);
69                 } else {
70                         len += strlen(" AND ");
71                         strncat(buf, " AND ", MAX_QUERY_LEN -len - 1);
72                 }
73                 len += strlen(condition);
74                 strncat(buf, condition, sizeof(buf) - len - 1);
75                 free(condition);
76                 condition = NULL;
77         }
78
79         return strdup(buf);
80 }
81
82 static gint __list_strcmp(gconstpointer a, gconstpointer b)
83 {
84         return strcmp((char *)a, (char *)b);
85 }
86
87 static gint _appinfo_get_list(sqlite3 *db, const char *locale,
88                 pkgmgrinfo_filter_x *filter, GList **list)
89 {
90         static const char query_raw[] =
91                 "SELECT DISTINCT package_app_info.app_id FROM package_app_info"
92                 " LEFT OUTER JOIN package_app_localized_info"
93                 "  ON package_app_info.app_id=package_app_localized_info.app_id"
94                 "  AND package_app_localized_info.app_locale=%Q"
95                 " LEFT OUTER JOIN package_app_app_category"
96                 "  ON package_app_info.app_id=package_app_app_category.app_id"
97                 " LEFT OUTER JOIN package_app_app_svc"
98                 "  ON package_app_info.app_id=package_app_app_svc.app_id "
99                 " LEFT OUTER JOIN package_app_app_metadata"
100                 "  ON package_app_info.app_id=package_app_app_metadata.app_id ";
101         int ret;
102         char *query;
103         char *query_localized;
104         sqlite3_stmt *stmt;
105         char *appid = NULL;
106
107         query = _get_filtered_query(query_raw, filter);
108         if (query == NULL)
109                 return PMINFO_R_ERROR;
110         query_localized = sqlite3_mprintf(query, locale);
111         free(query);
112         if (query_localized == NULL)
113                 return PMINFO_R_ERROR;
114
115         ret = sqlite3_prepare_v2(db, query_localized,
116                         strlen(query_localized), &stmt, NULL);
117         sqlite3_free(query_localized);
118         if (ret != SQLITE_OK) {
119                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
120                 return PMINFO_R_ERROR;
121         }
122
123         while (sqlite3_step(stmt) == SQLITE_ROW) {
124                 _save_column_str(stmt, 0, (const char **)&appid);
125                 if (appid != NULL)
126                         *list = g_list_insert_sorted(*list, appid,
127                                         __list_strcmp);
128         }
129
130         sqlite3_finalize(stmt);
131
132         return PMINFO_R_OK;
133 }
134
135 static int _appinfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid,
136                 GList **list)
137 {
138         int ret;
139         sqlite3 *db;
140         const char *dbpath;
141         char *locale;
142         GList *tmp;
143         GList *tmp2;
144
145         locale = _get_system_locale();
146         if (locale == NULL)
147                 return PMINFO_R_ERROR;
148
149         dbpath = getUserPkgParserDBPathUID(uid);
150         if (dbpath == NULL) {
151                 free(locale);
152                 return PMINFO_R_ERROR;
153         }
154
155         ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
156         if (ret != SQLITE_OK) {
157                 _LOGE("failed to open db: %d", ret);
158                 free(locale);
159                 return PMINFO_R_ERROR;
160         }
161
162         if (_appinfo_get_list(db, locale, filter, list)) {
163                 free(locale);
164                 sqlite3_close_v2(db);
165                 return PMINFO_R_ERROR;
166         }
167         sqlite3_close_v2(db);
168
169         if (uid == GLOBAL_USER) {
170                 free(locale);
171                 return PMINFO_R_OK;
172         }
173
174         /* search again from global */
175         dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
176         if (dbpath == NULL) {
177                 free(locale);
178                 return PMINFO_R_ERROR;
179         }
180
181         ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
182         if (ret != SQLITE_OK) {
183                 _LOGE("failed to open db: %d", ret);
184                 free(locale);
185                 return PMINFO_R_ERROR;
186         }
187
188         if (_appinfo_get_list(db, locale, filter, list)) {
189                 free(locale);
190                 sqlite3_close_v2(db);
191                 return PMINFO_R_ERROR;
192         }
193         sqlite3_close_v2(db);
194
195         /* remove duplicate element:
196          * since the list is sorted, we can remove duplicates in linear time
197          */
198         for (tmp = *list, tmp2 = g_list_next(tmp); tmp;
199                         tmp = tmp2, tmp2 = g_list_next(tmp)) {
200                 if (tmp->prev == NULL || tmp->data == NULL)
201                         continue;
202                 if (strcmp((const char *)tmp->prev->data,
203                                         (const char *)tmp->data) == 0)
204                         *list = g_list_delete_link(*list, tmp);
205         }
206
207         free(locale);
208
209         return PMINFO_R_OK;
210 }
211
212 static int _appinfo_get_label(sqlite3 *db, const char *appid,
213                 const char *locale, GList **label)
214 {
215         static const char query_raw[] =
216                 "SELECT app_label, app_locale "
217                 "FROM package_app_localized_info "
218                 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
219         int ret;
220         char *query;
221         sqlite3_stmt *stmt;
222         int idx;
223         label_x *info;
224
225         query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
226         if (query == NULL) {
227                 LOGE("out of memory");
228                 return PMINFO_R_ERROR;
229         }
230
231         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
232         sqlite3_free(query);
233         if (ret != SQLITE_OK) {
234                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
235                 return PMINFO_R_ERROR;
236         }
237
238         while (sqlite3_step(stmt) == SQLITE_ROW) {
239                 info = calloc(1, sizeof(label_x));
240                 if (info == NULL) {
241                         LOGE("out of memory");
242                         sqlite3_finalize(stmt);
243                         return PMINFO_R_ERROR;
244                 }
245                 idx = 0;
246                 _save_column_str(stmt, idx++, &info->text);
247                 _save_column_str(stmt, idx++, &info->lang);
248                 *label = g_list_append(*label, info);
249         }
250
251         sqlite3_finalize(stmt);
252
253         return PMINFO_R_OK;
254 }
255
256 static int _appinfo_get_icon(sqlite3 *db, const char *appid, const char *locale,
257                 GList **icon)
258 {
259         static const char query_raw[] =
260                 "SELECT app_icon, app_locale "
261                 "FROM package_app_localized_info "
262                 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
263         int ret;
264         char *query;
265         sqlite3_stmt *stmt;
266         int idx;
267         icon_x *info;
268
269         query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
270         if (query == NULL) {
271                 LOGE("out of memory");
272                 return PMINFO_R_ERROR;
273         }
274
275         ret = sqlite3_prepare_v2(db, query, strlen(query),
276                         &stmt, NULL);
277         sqlite3_free(query);
278         if (ret != SQLITE_OK) {
279                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
280                 return PMINFO_R_ERROR;
281         }
282
283         while (sqlite3_step(stmt) == SQLITE_ROW) {
284                 info = calloc(1, sizeof(icon_x));
285                 if (info == NULL) {
286                         LOGE("out of memory");
287                         sqlite3_finalize(stmt);
288                         return PMINFO_R_ERROR;
289                 }
290                 idx = 0;
291                 _save_column_str(stmt, idx++, &info->text);
292                 _save_column_str(stmt, idx++, &info->lang);
293                 *icon = g_list_append(*icon, info);
294         }
295
296         sqlite3_finalize(stmt);
297
298         return PMINFO_R_OK;
299 }
300
301 static int _appinfo_get_category(sqlite3 *db, const char *appid,
302                 GList **category)
303 {
304         static const char query_raw[] =
305                 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
306         int ret;
307         char *query;
308         sqlite3_stmt *stmt;
309         const char *val;
310
311         query = sqlite3_mprintf(query_raw, appid);
312         if (query == NULL) {
313                 LOGE("out of memory");
314                 return PMINFO_R_ERROR;
315         }
316
317         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
318         sqlite3_free(query);
319         if (ret != SQLITE_OK) {
320                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
321                 return PMINFO_R_ERROR;
322         }
323
324         while (sqlite3_step(stmt) == SQLITE_ROW) {
325                 val = NULL;
326                 _save_column_str(stmt, 0, &val);
327                 if (val)
328                         *category = g_list_append(*category, (gpointer)val);
329         }
330
331         sqlite3_finalize(stmt);
332
333         return PMINFO_R_OK;
334 }
335
336 static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str)
337 {
338         char *dup;
339         char *token;
340         char *ptr = NULL;
341         appcontrol_x *ac;
342
343         if (appcontrol_str == NULL)
344                 return;
345
346         dup = strdup(appcontrol_str);
347         do {
348                 ac = calloc(1, sizeof(appcontrol_x));
349                 if (ac == NULL) {
350                         _LOGE("out of memory");
351                         break;
352                 }
353                 token = strtok_r(dup, "|", &ptr);
354                 if (token && strcmp(token, "NULL"))
355                         ac->operation = strdup(token);
356                 token = strtok_r(NULL, "|", &ptr);
357                 if (token && strcmp(token, "NULL"))
358                         ac->uri = strdup(token);
359                 token = strtok_r(NULL, "|", &ptr);
360                 if (token && strcmp(token, "NULL"))
361                         ac->mime = strdup(token);
362                 *appcontrol = g_list_append(*appcontrol, ac);
363         } while ((token = strtok_r(NULL, ";", &ptr)));
364
365         free(dup);
366 }
367
368 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
369                 GList **appcontrol)
370 {
371         static const char query_raw[] =
372                 "SELECT app_control FROM package_app_app_control "
373                 "WHERE app_id=%Q";
374         int ret;
375         char *query;
376         sqlite3_stmt *stmt;
377         char *str;
378
379         query = sqlite3_mprintf(query_raw, appid);
380         if (query == NULL) {
381                 LOGE("out of memory");
382                 return PMINFO_R_ERROR;
383         }
384
385         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
386         sqlite3_free(query);
387         if (ret != SQLITE_OK) {
388                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
389                 return PMINFO_R_ERROR;
390         }
391
392         while (sqlite3_step(stmt) == SQLITE_ROW) {
393                 str = NULL;
394                 _save_column_str(stmt, 0, (const char **)&str);
395                 /* TODO: revise */
396                 __parse_appcontrol(appcontrol, str);
397                 free(str);
398         }
399
400         sqlite3_finalize(stmt);
401
402         return PMINFO_R_OK;
403 }
404
405 static int _appinfo_get_data_control(sqlite3 *db, const char *appid,
406                 GList **datacontrol)
407 {
408         static const char query_raw[] =
409                 "SELECT providerid, access, type "
410                 "FROM package_app_data_control WHERE app_id=%Q";
411         int ret;
412         char *query;
413         sqlite3_stmt *stmt;
414         int idx;
415         datacontrol_x *info;
416
417         query = sqlite3_mprintf(query_raw, appid);
418         if (query == NULL) {
419                 LOGE("out of memory");
420                 return PMINFO_R_ERROR;
421         }
422
423         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
424         sqlite3_free(query);
425         if (ret != SQLITE_OK) {
426                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
427                 return PMINFO_R_ERROR;
428         }
429
430         while (sqlite3_step(stmt) == SQLITE_ROW) {
431                 info = calloc(1, sizeof(datacontrol_x));
432                 if (info == NULL) {
433                         LOGE("out of memory");
434                         sqlite3_finalize(stmt);
435                         return PMINFO_R_ERROR;
436                 }
437                 idx = 0;
438                 _save_column_str(stmt, idx++, &info->providerid);
439                 _save_column_str(stmt, idx++, &info->access);
440                 _save_column_str(stmt, idx++, &info->type);
441                 *datacontrol = g_list_append(*datacontrol, info);
442         }
443
444         sqlite3_finalize(stmt);
445
446         return PMINFO_R_OK;
447 }
448
449 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
450                 GList **metadata)
451 {
452         static const char query_raw[] =
453                 "SELECT md_key, md_value "
454                 "FROM package_app_app_metadata WHERE app_id=%Q";
455         int ret;
456         char *query;
457         sqlite3_stmt *stmt;
458         int idx;
459         metadata_x *info;
460
461         query = sqlite3_mprintf(query_raw, appid);
462         if (query == NULL) {
463                 LOGE("out of memory");
464                 return PMINFO_R_ERROR;
465         }
466
467         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
468         sqlite3_free(query);
469         if (ret != SQLITE_OK) {
470                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
471                 return PMINFO_R_ERROR;
472         }
473
474         while (sqlite3_step(stmt) == SQLITE_ROW) {
475                 info = calloc(1, sizeof(metadata_x));
476                 if (info == NULL) {
477                         LOGE("out of memory");
478                         sqlite3_finalize(stmt);
479                         return PMINFO_R_ERROR;
480                 }
481                 idx = 0;
482                 _save_column_str(stmt, idx++, &info->key);
483                 _save_column_str(stmt, idx++, &info->value);
484                 *metadata = g_list_append(*metadata, info);
485         }
486
487         sqlite3_finalize(stmt);
488
489         return PMINFO_R_OK;
490
491 }
492
493 static int _appinfo_get_application(sqlite3 *db, const char *appid,
494                 const char *locale, application_x **application)
495 {
496         static const char query_raw[] =
497                 "SELECT app_id, app_component, app_exec, app_nodisplay, "
498                 "app_type, app_onboot, app_multiple, app_autorestart, "
499                 "app_taskmanage, app_enabled, app_hwacceleration, "
500                 "app_screenreader, app_mainapp, app_recentimage, "
501                 "app_launchcondition, app_indicatordisplay, app_portraitimg, "
502                 "app_landscapeimg, app_guestmodevisibility, "
503                 "app_permissiontype, app_preload, app_submode, "
504                 "app_submode_mainid, app_launch_mode, app_ui_gadget, "
505                 "app_support_disable, "
506                 "component_type, package "
507                 "FROM package_app_info WHERE app_id=%Q";
508         int ret;
509         char *query;
510         sqlite3_stmt *stmt;
511         int idx;
512         application_x *info;
513
514         query = sqlite3_mprintf(query_raw, appid);
515         if (query == NULL) {
516                 LOGE("out of memory");
517                 return PMINFO_R_ERROR;
518         }
519
520         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
521         sqlite3_free(query);
522         if (ret != SQLITE_OK) {
523                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
524                 return PMINFO_R_ERROR;
525         }
526
527         ret = sqlite3_step(stmt);
528         if (ret == SQLITE_DONE) {
529                 sqlite3_finalize(stmt);
530                 return PMINFO_R_ENOENT;
531         } else if (ret != SQLITE_ROW) {
532                 LOGE("step failed: %s", sqlite3_errmsg(db));
533                 sqlite3_finalize(stmt);
534                 return PMINFO_R_ERROR;
535         }
536
537         info = calloc(1, sizeof(application_x));
538         if (info == NULL) {
539                 LOGE("out of memory");
540                 sqlite3_finalize(stmt);
541                 return PMINFO_R_ERROR;
542         }
543         idx = 0;
544         _save_column_str(stmt, idx++, &info->appid);
545         _save_column_str(stmt, idx++, &info->component);
546         _save_column_str(stmt, idx++, &info->exec);
547         _save_column_str(stmt, idx++, &info->nodisplay);
548         _save_column_str(stmt, idx++, &info->type);
549         _save_column_str(stmt, idx++, &info->onboot);
550         _save_column_str(stmt, idx++, &info->multiple);
551         _save_column_str(stmt, idx++, &info->autorestart);
552         _save_column_str(stmt, idx++, &info->taskmanage);
553         _save_column_str(stmt, idx++, &info->enabled);
554         _save_column_str(stmt, idx++, &info->hwacceleration);
555         _save_column_str(stmt, idx++, &info->screenreader);
556         _save_column_str(stmt, idx++, &info->mainapp);
557         _save_column_str(stmt, idx++, &info->recentimage);
558         _save_column_str(stmt, idx++, &info->launchcondition);
559         _save_column_str(stmt, idx++, &info->indicatordisplay);
560         _save_column_str(stmt, idx++, &info->portraitimg);
561         _save_column_str(stmt, idx++, &info->landscapeimg);
562         _save_column_str(stmt, idx++, &info->guestmode_visibility);
563         _save_column_str(stmt, idx++, &info->permission_type);
564         _save_column_str(stmt, idx++, &info->preload);
565         _save_column_str(stmt, idx++, &info->submode);
566         _save_column_str(stmt, idx++, &info->submode_mainid);
567         _save_column_str(stmt, idx++, &info->launch_mode);
568         _save_column_str(stmt, idx++, &info->ui_gadget);
569         _save_column_str(stmt, idx++, &info->support_disable);
570         _save_column_str(stmt, idx++, &info->component_type);
571         _save_column_str(stmt, idx++, &info->package);
572
573         if (_appinfo_get_label(db, info->appid, locale, &info->label)) {
574                 pkgmgrinfo_basic_free_application(info);
575                 sqlite3_finalize(stmt);
576                 return PMINFO_R_ERROR;
577         }
578
579         if (_appinfo_get_icon(db, info->appid, locale, &info->icon)) {
580                 pkgmgrinfo_basic_free_application(info);
581                 sqlite3_finalize(stmt);
582                 return PMINFO_R_ERROR;
583         }
584
585         if (_appinfo_get_category(db, info->appid, &info->category)) {
586                 pkgmgrinfo_basic_free_application(info);
587                 sqlite3_finalize(stmt);
588                 return PMINFO_R_ERROR;
589         }
590
591         if (_appinfo_get_app_control(db, info->appid, &info->appcontrol)) {
592                 pkgmgrinfo_basic_free_application(info);
593                 sqlite3_finalize(stmt);
594                 return PMINFO_R_ERROR;
595         }
596
597         if (_appinfo_get_data_control(db, info->appid, &info->datacontrol)) {
598                 pkgmgrinfo_basic_free_application(info);
599                 sqlite3_finalize(stmt);
600                 return PMINFO_R_ERROR;
601         }
602
603         if (_appinfo_get_metadata(db, info->appid, &info->metadata)) {
604                 pkgmgrinfo_basic_free_application(info);
605                 sqlite3_finalize(stmt);
606                 return PMINFO_R_ERROR;
607         }
608
609         *application = info;
610
611         sqlite3_finalize(stmt);
612
613         return PMINFO_R_OK;
614 }
615
616 static int _appinfo_get_appinfo(const char *appid, uid_t uid,
617                 pkgmgr_appinfo_x **appinfo)
618 {
619         int ret;
620         sqlite3 *db;
621         const char *dbpath;
622         char *locale;
623         pkgmgr_appinfo_x *info;
624
625         dbpath = getUserPkgParserDBPathUID(uid);
626         if (dbpath == NULL)
627                 return PMINFO_R_ERROR;
628
629         locale = _get_system_locale();
630         if (locale == NULL)
631                 return PMINFO_R_ERROR;
632
633         ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
634         if (ret != SQLITE_OK) {
635                 _LOGE("failed to open db: %d", ret);
636                 free(locale);
637                 return PMINFO_R_ERROR;
638         }
639
640         info = calloc(1, sizeof(pkgmgr_appinfo_x));
641         if (info == NULL) {
642                 _LOGE("out of memory");
643                 free(locale);
644                 sqlite3_close_v2(db);
645                 return PMINFO_R_ERROR;
646         }
647
648         ret = _appinfo_get_application(db, appid, locale, &info->app_info);
649         if (ret != PMINFO_R_OK) {
650                 free(info);
651                 free(locale);
652                 sqlite3_close_v2(db);
653                 return ret;
654         }
655
656         info->locale = locale;
657         info->package = strdup(info->app_info->package);
658
659         *appinfo = info;
660
661         sqlite3_close_v2(db);
662
663         return ret;
664 }
665
666 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
667                 pkgmgrinfo_appinfo_h *handle)
668 {
669         int ret;
670
671         if (appid == NULL || handle == NULL) {
672                 LOGE("invalid parameter");
673                 return PMINFO_R_EINVAL;
674         }
675
676         ret = _appinfo_get_appinfo(appid, uid, (pkgmgr_appinfo_x **)handle);
677         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
678                 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
679                                 (pkgmgr_appinfo_x **)handle);
680
681         if (ret != PMINFO_R_OK)
682                 _LOGE("failed to get appinfo of %s for user %d", appid, uid);
683
684         return ret;
685 }
686
687 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
688 {
689         return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
690 }
691
692 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
693                 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
694                 void *user_data)
695 {
696         int ret;
697         pkgmgr_appinfo_x *info;
698         GList *list = NULL;
699         GList *tmp;
700         char *appid;
701         int stop = 0;
702
703         ret = _appinfo_get_filtered_list(filter, uid, &list);
704         if (ret != PMINFO_R_OK)
705                 return PMINFO_R_ERROR;
706
707         for (tmp = list; tmp; tmp = tmp->next) {
708                 appid = (char *)tmp->data;
709                 if (stop == 0) {
710                         ret = _appinfo_get_appinfo(appid, uid, &info);
711                         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
712                                 ret = _appinfo_get_appinfo(appid, GLOBAL_USER,
713                                                 &info);
714                         if (ret != PMINFO_R_OK) {
715                                 free(appid);
716                                 continue;
717                         }
718                         if (app_list_cb(info, user_data) < 0)
719                                 stop = 1;
720                         pkgmgrinfo_appinfo_destroy_appinfo(info);
721                 }
722                 free(appid);
723         }
724
725         g_list_free(list);
726
727         return PMINFO_R_OK;
728 }
729
730 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
731                 pkgmgrinfo_app_component component,
732                 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
733 {
734         int ret;
735         pkgmgrinfo_appinfo_filter_h filter;
736         char *pkgid;
737         const char *comp_str = NULL;
738
739         if (handle == NULL || app_func == NULL) {
740                 LOGE("invalied parameter");
741                 return PMINFO_R_EINVAL;
742         }
743
744         if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
745                 LOGE("invalid parameter");
746                 return PMINFO_R_EINVAL;
747         }
748
749         if (pkgmgrinfo_appinfo_filter_create(&filter))
750                 return PMINFO_R_ERROR;
751
752         if (pkgmgrinfo_appinfo_filter_add_string(filter,
753                                 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
754                 pkgmgrinfo_appinfo_filter_destroy(filter);
755                 return PMINFO_R_ERROR;
756         }
757
758
759         switch (component) {
760         case PMINFO_UI_APP:
761                 comp_str = PMINFO_APPINFO_UI_APP;
762                 break;
763         case PMINFO_SVC_APP:
764                 comp_str = PMINFO_APPINFO_SVC_APP;
765                 break;
766         default:
767                 break;
768         }
769
770         if (comp_str) {
771                 if (pkgmgrinfo_appinfo_filter_add_string(filter,
772                                         PMINFO_APPINFO_PROP_APP_COMPONENT,
773                                         comp_str)) {
774                         pkgmgrinfo_appinfo_filter_destroy(filter);
775                         return PMINFO_R_ERROR;
776                 }
777         }
778
779         ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
780                         user_data);
781
782         pkgmgrinfo_appinfo_filter_destroy(filter);
783
784         return ret;
785 }
786
787 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
788                                                 pkgmgrinfo_app_list_cb app_func, void *user_data)
789 {
790         return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
791 }
792
793 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
794 {
795         if (app_func == NULL) {
796                 LOGE("invalid parameter");
797                 return PMINFO_R_EINVAL;
798         }
799
800         return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
801                         user_data);
802 }
803
804 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
805 {
806         return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
807 }
808
809 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
810 {
811         if (app_func == NULL) {
812                 LOGE("invalid parameter");
813                 return PMINFO_R_EINVAL;
814         }
815
816         return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
817                         user_data);
818 }
819
820 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
821 {
822         return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
823 }
824
825 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
826 {
827         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
828
829         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
830         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
831
832         if (info->app_info == NULL || info->app_info->appid == NULL)
833                 return PMINFO_R_ERROR;
834         *appid = (char *)info->app_info->appid;
835
836         return PMINFO_R_OK;
837 }
838
839 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
840 {
841         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
842
843         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
844         retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
845
846         if (info->package == NULL)
847                 return PMINFO_R_ERROR;
848
849         *pkg_name = (char *)info->package;
850
851         return PMINFO_R_OK;
852 }
853
854 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
855 {
856         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
857
858         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
859         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
860
861         if (info->package == NULL)
862                 return PMINFO_R_ERROR;
863
864         *pkgid = (char *)info->package;
865
866         return PMINFO_R_OK;
867 }
868
869 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
870 {
871         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
872
873         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
874         retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
875
876         if (info->app_info == NULL || info->app_info->exec == NULL)
877                 return PMINFO_R_ERROR;
878         *exec = (char *)info->app_info->exec;
879
880         return PMINFO_R_OK;
881 }
882
883
884 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
885 {
886         const char *locale;
887         icon_x *ptr;
888         GList *tmp;
889         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
890
891         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
892         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
893
894         locale = info->locale;
895         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
896
897         if (info->app_info == NULL)
898                 return PMINFO_R_ERROR;
899
900         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
901                 ptr = (icon_x *)tmp->data;
902                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
903                                 strcmp(ptr->lang, locale))
904                         continue;
905                 *icon = (char *)ptr->text;
906                 return PMINFO_R_OK;
907         }
908
909         locale = DEFAULT_LOCALE;
910         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
911                 ptr = (icon_x *)tmp->data;
912                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
913                                 strcmp(ptr->lang, locale))
914                         continue;
915                 *icon = (char *)ptr->text;
916                 return PMINFO_R_OK;
917         }
918
919         return PMINFO_R_ERROR;
920 }
921
922
923 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
924 {
925         const char *locale;
926         label_x *ptr;
927         GList *tmp;
928         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
929
930         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
931         retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
932
933         locale = info->locale;
934         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
935
936         if (info->app_info == NULL)
937                 return PMINFO_R_ERROR;
938
939         for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
940                 ptr = (label_x *)tmp->data;
941                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
942                                 strcmp(ptr->lang, locale))
943                         continue;
944                 *label = (char *)ptr->text;
945                 return PMINFO_R_OK;
946         }
947
948         locale = DEFAULT_LOCALE;
949         for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
950                 ptr = (label_x *)tmp->data;
951                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
952                                 strcmp(ptr->lang, locale))
953                         continue;
954                 *label = (char *)ptr->text;
955                 return PMINFO_R_OK;
956         }
957
958         return PMINFO_R_ERROR;
959 }
960
961 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
962 {
963         char *result = NULL;
964         char *query = NULL;
965         sqlite3_stmt *stmt = NULL;
966         sqlite3 *db = NULL;
967         char *val;
968         const char *manifest_db;
969
970         manifest_db = getUserPkgParserDBPathUID(uid);
971         if (manifest_db == NULL) {
972                 _LOGE("Failed to get manifest db path");
973                 goto err;
974         }
975
976         if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
977                 _LOGE("DB open fail\n");
978                 goto err;
979         }
980
981         query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
982         if (query == NULL) {
983                 _LOGE("Out of memory");
984                 goto err;
985         }
986
987         if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
988                 _LOGE("prepare_v2 fail\n");
989                 goto err;
990         }
991
992         if (sqlite3_step(stmt) == SQLITE_ROW) {
993                 val = (char *)sqlite3_column_text(stmt, 0);
994                 if (val != NULL)
995                         result = strdup(val);
996         }
997
998 err:
999         sqlite3_finalize(stmt);
1000         sqlite3_free(query);
1001         sqlite3_close(db);
1002
1003         return result;
1004 }
1005
1006 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1007 {
1008         char *val;
1009
1010         retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1011
1012         val = _get_localed_label(appid, locale, uid);
1013         if (val == NULL)
1014                 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1015
1016         if (val == NULL)
1017                 return PMINFO_R_ERROR;
1018
1019         *label = val;
1020
1021         return PMINFO_R_OK;
1022 }
1023
1024 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1025 {
1026         return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, GLOBAL_USER, label);
1027 }
1028
1029 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1030 {
1031         if ( strcasecmp(comp, "uiapp") == 0)
1032                 return PMINFO_UI_APP;
1033         else if ( strcasecmp(comp, "svcapp") == 0)
1034                 return PMINFO_SVC_APP;
1035         else
1036                 return -1;
1037 }
1038
1039 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1040 {
1041         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1042         int comp;
1043
1044         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1045         retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1046
1047         if (info->app_info == NULL)
1048                 return PMINFO_R_ERROR;
1049
1050         comp = __appcomponent_convert(info->app_info->component);
1051         if (comp < 0)
1052                 return PMINFO_R_ERROR;
1053
1054         *component = comp;
1055
1056         return PMINFO_R_OK;
1057 }
1058
1059 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1060 {
1061         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1062
1063         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1064         retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1065
1066         if (info->app_info == NULL || info->app_info->type == NULL)
1067                 return PMINFO_R_ERROR;
1068         *app_type = (char *)info->app_info->type;
1069
1070         return PMINFO_R_OK;
1071 }
1072
1073 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h  handle,
1074                                         int *operation_count, char ***operation)
1075 {
1076         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1077         retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1078         retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1079         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1080         *operation_count = data->operation_count;
1081         *operation = data->operation;
1082         return PMINFO_R_OK;
1083 }
1084
1085 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h  handle,
1086                                         int *uri_count, char ***uri)
1087 {
1088         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1089         retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1090         retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1091         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1092         *uri_count = data->uri_count;
1093         *uri = data->uri;
1094         return PMINFO_R_OK;
1095 }
1096
1097 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h  handle,
1098                                         int *mime_count, char ***mime)
1099 {
1100         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1101         retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1102         retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1103         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1104         *mime_count = data->mime_count;
1105         *mime = data->mime;
1106         return PMINFO_R_OK;
1107 }
1108
1109 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h  handle,
1110                                         int *subapp_count, char ***subapp)
1111 {
1112         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1113         retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1114         retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1115         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1116         *subapp_count = data->subapp_count;
1117         *subapp = data->subapp;
1118         return PMINFO_R_OK;
1119 }
1120
1121 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1122 {
1123         char *val;
1124         icon_x *ptr;
1125         GList *tmp;
1126         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1127
1128         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1129         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1130
1131         if (info->app_info == NULL)
1132                 return PMINFO_R_ERROR;
1133
1134         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1135                 ptr = (icon_x *)tmp->data;
1136                 if (ptr == NULL || ptr->section == NULL)
1137                         continue;
1138
1139                 val = (char *)ptr->section;
1140                 if (val && strcmp(val, "setting") == 0) {
1141                         *icon = (char *)ptr->text;
1142                         return PMINFO_R_OK;
1143                 }
1144         }
1145
1146         return PMINFO_R_ERROR;
1147 }
1148
1149
1150 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1151 {
1152         char *val;
1153         icon_x *ptr;
1154         GList *tmp;
1155         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1156
1157         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1158         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1159
1160         if (info->app_info == NULL)
1161                 return PMINFO_R_ERROR;
1162
1163         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1164                 ptr = (icon_x *)tmp->data;
1165                 if (ptr == NULL || ptr->section == NULL)
1166                         continue;
1167
1168                 val = (char *)ptr->section;
1169                 if (val && strcmp(val, "notification") == 0){
1170                         *icon = (char *)ptr->text;
1171                         return PMINFO_R_OK;
1172                 }
1173         }
1174
1175         return PMINFO_R_ERROR;
1176 }
1177
1178 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1179 {
1180         char *val;
1181         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1182
1183         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1184         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1185
1186         if (info->app_info == NULL || info->app_info->recentimage == NULL)
1187                 return PMINFO_R_ERROR;
1188
1189         val = (char *)info->app_info->recentimage;
1190         if (strcasecmp(val, "capture") == 0)
1191                 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1192         else if (strcasecmp(val, "icon") == 0)
1193                 *type = PMINFO_RECENTIMAGE_USE_ICON;
1194         else
1195                 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1196
1197         return PMINFO_R_OK;
1198 }
1199
1200 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1201 {
1202         char *val;
1203         image_x *ptr;
1204         GList *tmp;
1205         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1206
1207         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1208         retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1209
1210         if (info->app_info == NULL)
1211                 return PMINFO_R_ERROR;
1212
1213         for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1214                 ptr = (image_x *)tmp->data;
1215                 if (ptr == NULL || ptr->section == NULL)
1216                         continue;
1217
1218                 val = (char *)ptr->section;
1219                 if (val && strcmp(val, "preview") == 0) {
1220                         *preview_img = (char *)ptr->text;
1221                         return PMINFO_R_OK;
1222                 }
1223         }
1224
1225         return PMINFO_R_ERROR;
1226 }
1227
1228 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1229 {
1230         const char *val;
1231         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1232
1233         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1234         retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1235
1236         val = info->app_info->permission_type;
1237         if (val == NULL)
1238                 return PMINFO_R_ERROR;
1239
1240         if (strcmp(val, "signature") == 0)
1241                 *permission = PMINFO_PERMISSION_SIGNATURE;
1242         else if (strcmp(val, "privilege") == 0)
1243                 *permission = PMINFO_PERMISSION_PRIVILEGE;
1244         else
1245                 *permission = PMINFO_PERMISSION_NORMAL;
1246
1247         return PMINFO_R_OK;
1248 }
1249
1250 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1251 {
1252         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1253
1254         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1255         retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1256
1257         if (info->app_info == NULL || info->app_info->component_type == NULL)
1258                 return PMINFO_R_ERROR;
1259
1260         *component_type = (char *)info->app_info->component_type;
1261
1262         return PMINFO_R_OK;
1263 }
1264
1265 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1266 {
1267         char *val;
1268         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1269
1270         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1271         retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1272
1273         if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1274                 return PMINFO_R_ERROR;
1275
1276         val = (char *)info->app_info->hwacceleration;
1277         if (strcasecmp(val, "not-use-GL") == 0)
1278                 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
1279         else if (strcasecmp(val, "use-GL") == 0)
1280                 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
1281         else
1282                 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
1283
1284         return PMINFO_R_OK;
1285 }
1286
1287 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1288 {
1289         char *val;
1290         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1291
1292         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1293         retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1294
1295         if (info->app_info == NULL || info->app_info->screenreader == NULL)
1296                 return PMINFO_R_ERROR;
1297
1298         val = (char *)info->app_info->screenreader;
1299         if (strcasecmp(val, "screenreader-off") == 0)
1300                 *screenreader = PMINFO_SCREENREADER_OFF;
1301         else if (strcasecmp(val, "screenreader-on") == 0)
1302                 *screenreader = PMINFO_SCREENREADER_ON;
1303         else
1304                 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1305
1306         return PMINFO_R_OK;
1307 }
1308
1309 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1310 {
1311         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1312
1313         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1314         retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1315         retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1316
1317         if (info->app_info == NULL || info->app_info->portraitimg ||
1318                         info->app_info->landscapeimg == NULL)
1319                 return PMINFO_R_ERROR;
1320
1321         *portrait_img = (char *)info->app_info->portraitimg;
1322         *landscape_img = (char *)info->app_info->landscapeimg;
1323
1324         return PMINFO_R_OK;
1325 }
1326
1327 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h  handle, char **submode_mainid)
1328 {
1329         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1330
1331         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1332         retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1333
1334         if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
1335                 return PMINFO_R_ERROR;
1336
1337         *submode_mainid = (char *)info->app_info->submode_mainid;
1338
1339         return PMINFO_R_OK;
1340 }
1341
1342 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
1343 {
1344         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1345
1346         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1347         retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1348
1349         if (info->app_info->launch_mode == NULL)
1350                 return PMINFO_R_ERROR;
1351
1352         *mode = (char *)(info->app_info->launch_mode);
1353
1354         return PMINFO_R_OK;
1355 }
1356
1357 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
1358 {
1359         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1360         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1361         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1362         retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1363
1364         int ret = PMINFO_R_OK;
1365         char *query = NULL;
1366         sqlite3_stmt *stmt = NULL;
1367
1368         /*open db*/
1369         ret = __open_manifest_db(uid, true);
1370         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1371
1372         /*Start constructing query*/
1373         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
1374
1375         /*prepare query*/
1376         ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1377         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1378
1379         /*step query*/
1380         ret = sqlite3_step(stmt);
1381         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1382
1383         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1384         *access = strdup((char *)sqlite3_column_text(stmt, 2));
1385
1386         ret = PMINFO_R_OK;
1387
1388 catch:
1389         sqlite3_free(query);
1390         sqlite3_finalize(stmt);
1391         __close_manifest_db();
1392         return ret;
1393 }
1394
1395 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
1396 {
1397         return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, GLOBAL_USER, appid, access);
1398 }
1399
1400 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
1401 {
1402         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
1403         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1404
1405         int ret = PMINFO_R_OK;
1406         char *query = NULL;
1407         sqlite3_stmt *stmt = NULL;
1408
1409         /*open db*/
1410         ret = __open_manifest_db(uid, true);
1411         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1412
1413         /*Start constructing query*/
1414         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
1415
1416         /*prepare query*/
1417         ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
1418         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1419
1420         /*step query*/
1421         ret = sqlite3_step(stmt);
1422         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
1423
1424         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
1425
1426         ret = PMINFO_R_OK;
1427
1428 catch:
1429         sqlite3_free(query);
1430         sqlite3_finalize(stmt);
1431         __close_manifest_db();
1432         return ret;
1433 }
1434
1435 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
1436 {
1437         return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, GLOBAL_USER, appid);
1438 }
1439
1440 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
1441                         pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
1442 {
1443         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1444         retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1445         int ret = -1;
1446         permission_x *ptr;
1447         GList *tmp;
1448         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1449
1450         if (info->app_info == NULL)
1451                 return PMINFO_R_ERROR;
1452
1453         for (tmp = info->app_info->permission; tmp; tmp = tmp->next) {
1454                 ptr = (permission_x *)tmp->data;
1455                 if (ptr == NULL)
1456                         continue;
1457                 if (ptr->value) {
1458                         ret = permission_func(ptr->value, user_data);
1459                         if (ret < 0)
1460                                 break;
1461                 }
1462         }
1463         return PMINFO_R_OK;
1464 }
1465
1466 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
1467                         pkgmgrinfo_app_category_list_cb category_func, void *user_data)
1468 {
1469         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1470         retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1471         int ret = -1;
1472         const char *category;
1473         GList *tmp;
1474         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1475
1476         if (info->app_info == NULL)
1477                 return PMINFO_R_ERROR;
1478
1479         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
1480                 category = (const char *)tmp->data;
1481                 if (category) {
1482                         ret = category_func(category, user_data);
1483                         if (ret < 0)
1484                                 break;
1485                 }
1486         }
1487         return PMINFO_R_OK;
1488 }
1489
1490 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
1491                         pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
1492 {
1493         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1494         retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1495         int ret = -1;
1496         metadata_x *ptr;
1497         GList *tmp;
1498         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1499
1500         if (info->app_info == NULL)
1501                 return PMINFO_R_ERROR;
1502
1503         for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
1504                 ptr = (metadata_x *)tmp->data;
1505                 if (ptr == NULL)
1506                         continue;
1507                 if (ptr->key) {
1508                         ret = metadata_func(ptr->key, ptr->value, user_data);
1509                         if (ret < 0)
1510                                 break;
1511                 }
1512         }
1513         return PMINFO_R_OK;
1514 }
1515
1516 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
1517                         pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
1518 {
1519         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1520         retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1521         int ret;
1522         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1523         appcontrol_x *appcontrol;
1524         GList *tmp;
1525
1526         if (info->app_info == NULL)
1527                 return PMINFO_R_ERROR;
1528
1529         for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
1530                 appcontrol = (appcontrol_x *)tmp->data;
1531                 if (appcontrol == NULL)
1532                         continue;
1533                 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
1534                 if (ret < 0)
1535                         break;
1536         }
1537
1538         return PMINFO_R_OK;
1539 }
1540
1541 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
1542 {
1543         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1544         retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1545         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1546
1547         if (info->app_info == NULL || info->app_info->nodisplay == NULL)
1548                 return PMINFO_R_ERROR;
1549
1550         *nodisplay = _get_bool_value(info->app_info->nodisplay);
1551
1552         return PMINFO_R_OK;
1553 }
1554
1555 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
1556 {
1557         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1558         retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1559         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1560
1561         if (info->app_info == NULL || info->app_info->multiple == NULL)
1562                 return PMINFO_R_ERROR;
1563
1564         *multiple = _get_bool_value(info->app_info->multiple);
1565
1566         return PMINFO_R_OK;
1567 }
1568
1569 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
1570 {
1571         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1572         retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1573         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1574
1575         if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
1576                 return PMINFO_R_ERROR;
1577
1578         *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
1579
1580         return PMINFO_R_OK;
1581 }
1582
1583 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h  handle, bool *taskmanage)
1584 {
1585         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1586         retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1587         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1588
1589         if (info->app_info == NULL || info->app_info->taskmanage == NULL)
1590                 return PMINFO_R_ERROR;
1591
1592         *taskmanage = _get_bool_value(info->app_info->taskmanage);
1593
1594         return PMINFO_R_OK;
1595 }
1596
1597 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h  handle, bool *enabled)
1598 {
1599         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1600         retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1601         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1602
1603         if (info->app_info == NULL || info->app_info->enabled == NULL)
1604                 return PMINFO_R_ERROR;
1605
1606         *enabled = _get_bool_value(info->app_info->enabled);
1607
1608         return PMINFO_R_OK;
1609 }
1610
1611 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h  handle, bool *onboot)
1612 {
1613         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1614         retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1615         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1616
1617         if (info->app_info == NULL || info->app_info->onboot == NULL)
1618                 return PMINFO_R_ERROR;
1619
1620         *onboot = _get_bool_value(info->app_info->onboot);
1621
1622         return PMINFO_R_OK;
1623 }
1624
1625 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h  handle, bool *autorestart)
1626 {
1627         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1628         retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1629         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1630
1631         if (info->app_info == NULL || info->app_info->autorestart == NULL)
1632                 return PMINFO_R_ERROR;
1633
1634         *autorestart = _get_bool_value(info->app_info->autorestart);
1635
1636         return PMINFO_R_OK;
1637 }
1638
1639 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h  handle, bool *mainapp)
1640 {
1641         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1642         retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1643         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1644
1645         if (info->app_info == NULL || info->app_info->mainapp == NULL)
1646                 return PMINFO_R_ERROR;
1647
1648         *mainapp = _get_bool_value(info->app_info->mainapp);
1649
1650         return PMINFO_R_OK;
1651 }
1652
1653 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
1654 {
1655         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1656         retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1657         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1658
1659         if (info->app_info == NULL || info->app_info->preload == NULL)
1660                 return PMINFO_R_ERROR;
1661
1662         *preload = _get_bool_value(info->app_info->preload);
1663
1664         return PMINFO_R_OK;
1665 }
1666
1667 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
1668 {
1669         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1670         retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1671         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1672
1673         if (info->app_info == NULL || info->app_info->submode == NULL)
1674                 return PMINFO_R_ERROR;
1675
1676         *submode = _get_bool_value(info->app_info->submode);
1677
1678         return PMINFO_R_OK;
1679 }
1680
1681 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
1682 {
1683         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1684         retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
1685         retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
1686
1687         const char *val;
1688         GList *tmp;
1689         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1690
1691         if (info->app_info == NULL)
1692                 return PMINFO_R_ERROR;
1693
1694         *exist = 0;
1695         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
1696                 val = (const char *)tmp->data;
1697                 if (val == NULL)
1698                         continue;
1699                 if (strcasecmp(val, category) == 0) {
1700                         *exist = 1;
1701                         break;
1702                 }
1703         }
1704
1705         return PMINFO_R_OK;
1706 }
1707
1708 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
1709                 bool *ui_gadget)
1710 {
1711         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1712
1713         if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
1714                 _LOGE("invalid parameter");
1715                 return PMINFO_R_EINVAL;
1716         }
1717
1718         *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
1719
1720         return PMINFO_R_OK;
1721 }
1722
1723 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
1724                 bool *support_disable)
1725 {
1726         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1727
1728         if (info == NULL || info->app_info == NULL || support_disable == NULL) {
1729                 _LOGE("invalid parameter");
1730                 return PMINFO_R_EINVAL;
1731         }
1732
1733         *support_disable = _get_bool_value(info->app_info->support_disable);
1734
1735         return PMINFO_R_OK;
1736 }
1737
1738 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
1739 {
1740         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1741         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1742         __cleanup_appinfo(info);
1743         return PMINFO_R_OK;
1744 }
1745
1746 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
1747 {
1748         return (pkgmgrinfo_pkginfo_filter_create(handle));
1749 }
1750
1751 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
1752 {
1753         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1754 }
1755
1756 static gint __compare_func(gconstpointer data1, gconstpointer data2)
1757 {
1758         pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
1759         pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
1760         if (node1->prop == node2->prop)
1761                 return 0;
1762         else if (node1->prop > node2->prop)
1763                 return 1;
1764         else
1765                 return -1;
1766 }
1767
1768 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
1769                                 const char *property, const int value)
1770 {
1771         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1772         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1773         char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1774         char *val = NULL;
1775         GSList *link = NULL;
1776         int prop = -1;
1777         prop = _pminfo_appinfo_convert_to_prop_int(property);
1778         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
1779                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
1780                 _LOGE("Invalid Integer Property\n");
1781                 return PMINFO_R_EINVAL;
1782         }
1783         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1784         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1785         if (node == NULL) {
1786                 _LOGE("Out of Memory!!!\n");
1787                 return PMINFO_R_ERROR;
1788         }
1789         snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1790         val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1791         if (val == NULL) {
1792                 _LOGE("Out of Memory\n");
1793                 free(node);
1794                 node = NULL;
1795                 return PMINFO_R_ERROR;
1796         }
1797         node->prop = prop;
1798         node->value = val;
1799         /*If API is called multiple times for same property, we should override the previous values.
1800         Last value set will be used for filtering.*/
1801         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1802         if (link)
1803                 filter->list = g_slist_delete_link(filter->list, link);
1804         filter->list = g_slist_append(filter->list, (gpointer)node);
1805         return PMINFO_R_OK;
1806
1807 }
1808
1809 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
1810                                 const char *property, const bool value)
1811 {
1812         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1813         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1814         char *val = NULL;
1815         GSList *link = NULL;
1816         int prop = -1;
1817         prop = _pminfo_appinfo_convert_to_prop_bool(property);
1818         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
1819                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
1820                 _LOGE("Invalid Boolean Property\n");
1821                 return PMINFO_R_EINVAL;
1822         }
1823         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1824         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1825         if (node == NULL) {
1826                 _LOGE("Out of Memory!!!\n");
1827                 return PMINFO_R_ERROR;
1828         }
1829         if (value)
1830                 val = strndup("('true','True')", 15);
1831         else
1832                 val = strndup("('false','False')", 17);
1833         if (val == NULL) {
1834                 _LOGE("Out of Memory\n");
1835                 free(node);
1836                 node = NULL;
1837                 return PMINFO_R_ERROR;
1838         }
1839         node->prop = prop;
1840         node->value = val;
1841         /*If API is called multiple times for same property, we should override the previous values.
1842         Last value set will be used for filtering.*/
1843         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1844         if (link)
1845                 filter->list = g_slist_delete_link(filter->list, link);
1846         filter->list = g_slist_append(filter->list, (gpointer)node);
1847         return PMINFO_R_OK;
1848
1849 }
1850
1851 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
1852                                 const char *property, const char *value)
1853 {
1854         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1855         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1856         retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1857         char *val = NULL;
1858         pkgmgrinfo_node_x *ptr = NULL;
1859         char prev[PKG_STRING_LEN_MAX] = {'\0'};
1860         char temp[PKG_STRING_LEN_MAX] = {'\0'};
1861         GSList *link = NULL;
1862         int prop = -1;
1863         prop = _pminfo_appinfo_convert_to_prop_str(property);
1864         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
1865                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
1866                 _LOGE("Invalid String Property\n");
1867                 return PMINFO_R_EINVAL;
1868         }
1869         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1870         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1871         if (node == NULL) {
1872                 _LOGE("Out of Memory!!!\n");
1873                 return PMINFO_R_ERROR;
1874         }
1875         node->prop = prop;
1876         switch (prop) {
1877         case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
1878                 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
1879                         val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
1880                 else
1881                         val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
1882                 node->value = val;
1883                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1884                 if (link)
1885                         filter->list = g_slist_delete_link(filter->list, link);
1886                 filter->list = g_slist_append(filter->list, (gpointer)node);
1887                 break;
1888         case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
1889         case E_PMINFO_APPINFO_PROP_APP_OPERATION:
1890         case E_PMINFO_APPINFO_PROP_APP_URI:
1891         case E_PMINFO_APPINFO_PROP_APP_MIME:
1892                 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
1893                 if (val == NULL) {
1894                         _LOGE("Out of Memory\n");
1895                         free(node);
1896                         node = NULL;
1897                         return PMINFO_R_ERROR;
1898                 }
1899                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1900                 if (link) {
1901                         ptr = (pkgmgrinfo_node_x *)link->data;
1902                         strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
1903                         _LOGE("Previous value is %s\n", prev);
1904                         filter->list = g_slist_delete_link(filter->list, link);
1905                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
1906                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1907                         _LOGE("New value is %s\n", val);
1908                         node->value = val;
1909                         filter->list = g_slist_append(filter->list, (gpointer)node);
1910                         memset(temp, '\0', PKG_STRING_LEN_MAX);
1911                 } else {
1912                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
1913                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
1914                         _LOGE("First value is %s\n", val);
1915                         node->value = val;
1916                         filter->list = g_slist_append(filter->list, (gpointer)node);
1917                         memset(temp, '\0', PKG_STRING_LEN_MAX);
1918                 }
1919                 break;
1920         default:
1921                 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
1922                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1923                 if (link)
1924                         filter->list = g_slist_delete_link(filter->list, link);
1925                 filter->list = g_slist_append(filter->list, (gpointer)node);
1926                 break;
1927         }
1928         return PMINFO_R_OK;
1929 }
1930
1931 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
1932 {
1933         int ret;
1934         GList *list = NULL;
1935
1936         if (handle == NULL || count == NULL) {
1937                 _LOGE("invalid parameter");
1938                 return PMINFO_R_EINVAL;
1939         }
1940
1941         ret = _appinfo_get_filtered_list(handle, uid, &list);
1942         if (ret != PMINFO_R_OK)
1943                 return PMINFO_R_ERROR;
1944
1945         *count = g_list_length(list);
1946
1947         g_list_free_full(list, free);
1948
1949         return PMINFO_R_OK;
1950 }
1951
1952 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
1953 {
1954         return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
1955 }
1956
1957 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
1958                 pkgmgrinfo_appinfo_filter_h handle,
1959                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
1960 {
1961         if (handle == NULL || app_cb == NULL) {
1962                 LOGE("invalid parameter");
1963                 return PMINFO_R_EINVAL;
1964         }
1965
1966         return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
1967                         user_data);
1968 }
1969
1970 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
1971                                 pkgmgrinfo_app_list_cb app_cb, void * user_data)
1972 {
1973         return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
1974 }
1975
1976 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
1977 {
1978         return (pkgmgrinfo_pkginfo_filter_create(handle));
1979 }
1980
1981 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
1982 {
1983         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
1984 }
1985
1986 API int pkgmgrinfo_appinfo_metadata_filter_add(
1987                 pkgmgrinfo_appinfo_metadata_filter_h handle,
1988                 const char *key, const char *value)
1989 {
1990         int ret;
1991
1992         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
1993                         PMINFO_APPINFO_PROP_APP_METADATA_KEY, key);
1994         if (ret != PMINFO_R_OK)
1995                 return ret;
1996
1997         /* value can be NULL.
1998          * In that case all apps with specified key should be displayed
1999          */
2000         if (value) {
2001                 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2002                                 PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value);
2003                 if (ret != PMINFO_R_OK)
2004                         return ret;
2005         }
2006
2007         return PMINFO_R_OK;
2008 }
2009
2010 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2011                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2012                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2013 {
2014         if (handle == NULL || app_cb == NULL) {
2015                 LOGE("invalid parameter");
2016                 return PMINFO_R_EINVAL;
2017         }
2018
2019         return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2020                         user_data);
2021 }
2022
2023 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
2024                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2025                 pkgmgrinfo_app_list_cb app_cb, void *user_data)
2026 {
2027         return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
2028                         user_data, GLOBAL_USER);
2029 }
2030
2031 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
2032 {
2033         const char *val;
2034         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2035
2036         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2037         retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2038
2039         val = info->app_info->guestmode_visibility;
2040         *status = _get_bool_value(val);
2041         return PMINFO_R_OK;
2042 }