Add color-depth field for package_app_splash_screen table
[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
32         if (info != NULL) {
33                 if (info->package)
34                         free((void *)info->package);
35                 if (info->locale)
36                         free((void *)info->locale);
37
38                 pkgmgrinfo_basic_free_application(info->app_info);
39                 free((void *)info);
40         }
41         return;
42 }
43
44 static void __free_appinfo_list(gpointer data)
45 {
46         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
47         __cleanup_appinfo(info);
48 }
49
50 static char *_get_filtered_query(const char *query_raw,
51                 pkgmgrinfo_filter_x *filter)
52 {
53         char buf[MAX_QUERY_LEN] = { 0, };
54         char *condition;
55         size_t len;
56         GSList *list;
57         GSList *head = NULL;
58
59         if (filter)
60                 head = filter->list;
61
62         strncat(buf, query_raw, MAX_QUERY_LEN - 1);
63         len = strlen(buf);
64         for (list = head; list; list = list->next) {
65                 /* TODO: revise condition getter function */
66                 __get_filter_condition(list->data, &condition);
67                 if (condition == NULL)
68                         continue;
69                 if (buf[strlen(query_raw)] == '\0') {
70                         len += strlen(" WHERE ");
71                         strncat(buf, " WHERE ", MAX_QUERY_LEN - len - 1);
72                 } else {
73                         len += strlen(" AND ");
74                         strncat(buf, " AND ", MAX_QUERY_LEN -len - 1);
75                 }
76                 len += strlen(condition);
77                 strncat(buf, condition, sizeof(buf) - len - 1);
78                 free(condition);
79                 condition = NULL;
80         }
81
82         return strdup(buf);
83 }
84
85 static gint __list_strcmp(gconstpointer a, gconstpointer b)
86 {
87         return strcmp((char *)a, (char *)b);
88 }
89
90 static gint _appinfo_get_list(sqlite3 *db, const char *locale,
91                 pkgmgrinfo_filter_x *filter, GList **list)
92 {
93         static const char query_raw[] =
94                 "SELECT DISTINCT package_app_info.app_id FROM package_app_info"
95                 " LEFT OUTER JOIN package_app_localized_info"
96                 "  ON package_app_info.app_id=package_app_localized_info.app_id"
97                 "  AND package_app_localized_info.app_locale=%Q"
98                 " LEFT OUTER JOIN package_app_app_category"
99                 "  ON package_app_info.app_id=package_app_app_category.app_id"
100                 " LEFT OUTER JOIN package_app_app_control"
101                 "  ON package_app_info.app_id=package_app_app_control.app_id"
102                 " LEFT OUTER JOIN package_app_app_metadata"
103                 "  ON package_app_info.app_id=package_app_app_metadata.app_id ";
104         int ret;
105         char *query;
106         char *query_localized;
107         sqlite3_stmt *stmt;
108         char *appid = NULL;
109
110         query = _get_filtered_query(query_raw, filter);
111         if (query == NULL)
112                 return PMINFO_R_ERROR;
113         query_localized = sqlite3_mprintf(query, locale);
114         free(query);
115         if (query_localized == NULL)
116                 return PMINFO_R_ERROR;
117
118         ret = sqlite3_prepare_v2(db, query_localized,
119                         strlen(query_localized), &stmt, NULL);
120         sqlite3_free(query_localized);
121         if (ret != SQLITE_OK) {
122                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
123                 return PMINFO_R_ERROR;
124         }
125
126         while (sqlite3_step(stmt) == SQLITE_ROW) {
127                 _save_column_str(stmt, 0, &appid);
128                 if (appid != NULL)
129                         *list = g_list_insert_sorted(*list, appid,
130                                         __list_strcmp);
131         }
132
133         sqlite3_finalize(stmt);
134
135         return PMINFO_R_OK;
136 }
137
138 static int _appinfo_get_filtered_list(pkgmgrinfo_filter_x *filter, uid_t uid,
139                 GList **list)
140 {
141         int ret;
142         sqlite3 *db;
143         const char *dbpath;
144         char *locale;
145         GList *tmp;
146         GList *tmp2;
147
148         locale = _get_system_locale();
149         if (locale == NULL)
150                 return PMINFO_R_ERROR;
151
152         dbpath = getUserPkgParserDBPathUID(uid);
153         if (dbpath == NULL) {
154                 free(locale);
155                 return PMINFO_R_ERROR;
156         }
157
158         ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
159         if (ret != SQLITE_OK) {
160                 _LOGE("failed to open db: %d", ret);
161                 free(locale);
162                 return PMINFO_R_ERROR;
163         }
164
165         if (_appinfo_get_list(db, locale, filter, list)) {
166                 free(locale);
167                 sqlite3_close_v2(db);
168                 return PMINFO_R_ERROR;
169         }
170         sqlite3_close_v2(db);
171
172         if (uid == GLOBAL_USER) {
173                 free(locale);
174                 return PMINFO_R_OK;
175         }
176
177         /* search again from global */
178         dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
179         if (dbpath == NULL) {
180                 free(locale);
181                 return PMINFO_R_ERROR;
182         }
183
184         ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
185         if (ret != SQLITE_OK) {
186                 _LOGE("failed to open db: %d", ret);
187                 free(locale);
188                 return PMINFO_R_ERROR;
189         }
190
191         if (_appinfo_get_list(db, locale, filter, list)) {
192                 free(locale);
193                 sqlite3_close_v2(db);
194                 return PMINFO_R_ERROR;
195         }
196         sqlite3_close_v2(db);
197
198         /* remove duplicate element:
199          * since the list is sorted, we can remove duplicates in linear time
200          */
201         for (tmp = *list, tmp2 = g_list_next(tmp); tmp;
202                         tmp = tmp2, tmp2 = g_list_next(tmp)) {
203                 if (tmp->prev == NULL || tmp->data == NULL)
204                         continue;
205                 if (strcmp((const char *)tmp->prev->data,
206                                         (const char *)tmp->data) == 0)
207                         *list = g_list_delete_link(*list, tmp);
208         }
209
210         free(locale);
211
212         return PMINFO_R_OK;
213 }
214
215 static int _appinfo_get_label(sqlite3 *db, const char *appid,
216                 const char *locale, GList **label)
217 {
218         static const char query_raw[] =
219                 "SELECT app_label, app_locale "
220                 "FROM package_app_localized_info "
221                 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
222         int ret;
223         char *query;
224         sqlite3_stmt *stmt;
225         int idx;
226         label_x *info;
227
228         query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
229         if (query == NULL) {
230                 LOGE("out of memory");
231                 return PMINFO_R_ERROR;
232         }
233
234         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
235         sqlite3_free(query);
236         if (ret != SQLITE_OK) {
237                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
238                 return PMINFO_R_ERROR;
239         }
240
241         while (sqlite3_step(stmt) == SQLITE_ROW) {
242                 info = calloc(1, sizeof(label_x));
243                 if (info == NULL) {
244                         LOGE("out of memory");
245                         sqlite3_finalize(stmt);
246                         return PMINFO_R_ERROR;
247                 }
248                 idx = 0;
249                 _save_column_str(stmt, idx++, &info->text);
250                 _save_column_str(stmt, idx++, &info->lang);
251                 *label = g_list_append(*label, info);
252         }
253
254         sqlite3_finalize(stmt);
255
256         return PMINFO_R_OK;
257 }
258
259 static int _appinfo_get_icon(sqlite3 *db, const char *appid, const char *locale,
260                 GList **icon)
261 {
262         static const char query_raw[] =
263                 "SELECT app_icon, app_locale "
264                 "FROM package_app_localized_info "
265                 "WHERE app_id=%Q AND app_locale IN (%Q, %Q)";
266         int ret;
267         char *query;
268         sqlite3_stmt *stmt;
269         int idx;
270         icon_x *info;
271
272         query = sqlite3_mprintf(query_raw, appid, locale, DEFAULT_LOCALE);
273         if (query == NULL) {
274                 LOGE("out of memory");
275                 return PMINFO_R_ERROR;
276         }
277
278         ret = sqlite3_prepare_v2(db, query, strlen(query),
279                         &stmt, NULL);
280         sqlite3_free(query);
281         if (ret != SQLITE_OK) {
282                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
283                 return PMINFO_R_ERROR;
284         }
285
286         while (sqlite3_step(stmt) == SQLITE_ROW) {
287                 info = calloc(1, sizeof(icon_x));
288                 if (info == NULL) {
289                         LOGE("out of memory");
290                         sqlite3_finalize(stmt);
291                         return PMINFO_R_ERROR;
292                 }
293                 idx = 0;
294                 _save_column_str(stmt, idx++, &info->text);
295                 _save_column_str(stmt, idx++, &info->lang);
296                 *icon = g_list_append(*icon, info);
297         }
298
299         sqlite3_finalize(stmt);
300
301         return PMINFO_R_OK;
302 }
303
304 static int _appinfo_get_category(sqlite3 *db, const char *appid,
305                 GList **category)
306 {
307         static const char query_raw[] =
308                 "SELECT category FROM package_app_app_category WHERE app_id=%Q";
309         int ret;
310         char *query;
311         sqlite3_stmt *stmt;
312         char *val;
313
314         query = sqlite3_mprintf(query_raw, appid);
315         if (query == NULL) {
316                 LOGE("out of memory");
317                 return PMINFO_R_ERROR;
318         }
319
320         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
321         sqlite3_free(query);
322         if (ret != SQLITE_OK) {
323                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
324                 return PMINFO_R_ERROR;
325         }
326
327         while (sqlite3_step(stmt) == SQLITE_ROW) {
328                 val = NULL;
329                 _save_column_str(stmt, 0, &val);
330                 if (val)
331                         *category = g_list_append(*category, (gpointer)val);
332         }
333
334         sqlite3_finalize(stmt);
335
336         return PMINFO_R_OK;
337 }
338
339 static void __parse_appcontrol(GList **appcontrol, char *appcontrol_str)
340 {
341         char *dup;
342         char *token;
343         char *ptr = NULL;
344         appcontrol_x *ac;
345
346         if (appcontrol_str == NULL)
347                 return;
348
349         dup = strdup(appcontrol_str);
350         do {
351                 ac = calloc(1, sizeof(appcontrol_x));
352                 if (ac == NULL) {
353                         _LOGE("out of memory");
354                         break;
355                 }
356                 token = strtok_r(dup, "|", &ptr);
357                 if (token && strcmp(token, "NULL"))
358                         ac->operation = strdup(token);
359                 token = strtok_r(NULL, "|", &ptr);
360                 if (token && strcmp(token, "NULL"))
361                         ac->uri = strdup(token);
362                 token = strtok_r(NULL, "|", &ptr);
363                 if (token && strcmp(token, "NULL"))
364                         ac->mime = strdup(token);
365                 *appcontrol = g_list_append(*appcontrol, ac);
366         } while ((token = strtok_r(NULL, ";", &ptr)));
367
368         free(dup);
369 }
370
371 static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
372                 GList **appcontrol)
373 {
374         static const char query_raw[] =
375                 "SELECT app_control FROM package_app_app_control "
376                 "WHERE app_id=%Q";
377         int ret;
378         char *query;
379         sqlite3_stmt *stmt;
380         char *str;
381
382         query = sqlite3_mprintf(query_raw, appid);
383         if (query == NULL) {
384                 LOGE("out of memory");
385                 return PMINFO_R_ERROR;
386         }
387
388         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
389         sqlite3_free(query);
390         if (ret != SQLITE_OK) {
391                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
392                 return PMINFO_R_ERROR;
393         }
394
395         while (sqlite3_step(stmt) == SQLITE_ROW) {
396                 str = NULL;
397                 _save_column_str(stmt, 0, &str);
398                 /* TODO: revise */
399                 __parse_appcontrol(appcontrol, str);
400                 free(str);
401         }
402
403         sqlite3_finalize(stmt);
404
405         return PMINFO_R_OK;
406 }
407
408 static int _appinfo_get_data_control(sqlite3 *db, const char *appid,
409                 GList **datacontrol)
410 {
411         static const char query_raw[] =
412                 "SELECT providerid, access, type "
413                 "FROM package_app_data_control WHERE app_id=%Q";
414         int ret;
415         char *query;
416         sqlite3_stmt *stmt;
417         int idx;
418         datacontrol_x *info;
419
420         query = sqlite3_mprintf(query_raw, appid);
421         if (query == NULL) {
422                 LOGE("out of memory");
423                 return PMINFO_R_ERROR;
424         }
425
426         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
427         sqlite3_free(query);
428         if (ret != SQLITE_OK) {
429                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
430                 return PMINFO_R_ERROR;
431         }
432
433         while (sqlite3_step(stmt) == SQLITE_ROW) {
434                 info = calloc(1, sizeof(datacontrol_x));
435                 if (info == NULL) {
436                         LOGE("out of memory");
437                         sqlite3_finalize(stmt);
438                         return PMINFO_R_ERROR;
439                 }
440                 idx = 0;
441                 _save_column_str(stmt, idx++, &info->providerid);
442                 _save_column_str(stmt, idx++, &info->access);
443                 _save_column_str(stmt, idx++, &info->type);
444                 *datacontrol = g_list_append(*datacontrol, info);
445         }
446
447         sqlite3_finalize(stmt);
448
449         return PMINFO_R_OK;
450 }
451
452 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
453                 GList **metadata)
454 {
455         static const char query_raw[] =
456                 "SELECT md_key, md_value "
457                 "FROM package_app_app_metadata WHERE app_id=%Q";
458         int ret;
459         char *query;
460         sqlite3_stmt *stmt;
461         int idx;
462         metadata_x *info;
463
464         query = sqlite3_mprintf(query_raw, appid);
465         if (query == NULL) {
466                 LOGE("out of memory");
467                 return PMINFO_R_ERROR;
468         }
469
470         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
471         sqlite3_free(query);
472         if (ret != SQLITE_OK) {
473                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
474                 return PMINFO_R_ERROR;
475         }
476
477         while (sqlite3_step(stmt) == SQLITE_ROW) {
478                 info = calloc(1, sizeof(metadata_x));
479                 if (info == NULL) {
480                         LOGE("out of memory");
481                         sqlite3_finalize(stmt);
482                         return PMINFO_R_ERROR;
483                 }
484                 idx = 0;
485                 _save_column_str(stmt, idx++, &info->key);
486                 _save_column_str(stmt, idx++, &info->value);
487                 *metadata = g_list_append(*metadata, info);
488         }
489
490         sqlite3_finalize(stmt);
491
492         return PMINFO_R_OK;
493
494 }
495
496 static int _appinfo_get_splashscreens(sqlite3 *db, const char *appid,
497                 GList **splashscreens)
498 {
499         static const char query_raw[] =
500                 "SELECT src, type, orientation, indicatordisplay, operation, color_depth "
501                 "FROM package_app_splash_screen WHERE app_id=%Q";
502         int ret;
503         char *query;
504         sqlite3_stmt *stmt;
505         int idx;
506         splashscreen_x *info;
507
508         query = sqlite3_mprintf(query_raw, appid);
509         if (query == NULL) {
510                 LOGE("out of memory");
511                 return PMINFO_R_ERROR;
512         }
513
514         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
515         sqlite3_free(query);
516         if (ret != SQLITE_OK) {
517                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
518                 return PMINFO_R_ERROR;
519         }
520
521         while (sqlite3_step(stmt) == SQLITE_ROW) {
522                 info = calloc(1, sizeof(splashscreen_x));
523                 if (info == NULL) {
524                         LOGE("out of memory");
525                         sqlite3_finalize(stmt);
526                         return PMINFO_R_ERROR;
527                 }
528                 idx = 0;
529                 _save_column_str(stmt, idx++, &info->src);
530                 _save_column_str(stmt, idx++, &info->type);
531                 _save_column_str(stmt, idx++, &info->orientation);
532                 _save_column_str(stmt, idx++, &info->indicatordisplay);
533                 _save_column_str(stmt, idx++, &info->operation);
534                 _save_column_str(stmt, idx++, &info->color_depth);
535                 *splashscreens = g_list_append(*splashscreens, info);
536         }
537
538         sqlite3_finalize(stmt);
539
540         return PMINFO_R_OK;
541 }
542
543 static GList *__get_background_category(const char *value)
544 {
545         GList *category_list = NULL;
546         int convert_value = 0;
547         if (!value || strlen(value) == 0)
548                 return NULL;
549
550         convert_value = atoi(value);
551         if (convert_value < 0)
552                 return NULL;
553
554         if (convert_value & APP_BG_CATEGORY_USER_DISABLE_TRUE_VAL)
555                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_TRUE_STR));
556         else
557                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_USER_DISABLE_FALSE_STR));
558
559         if (convert_value & APP_BG_CATEGORY_MEDIA_VAL)
560                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_MEDIA_STR));
561
562         if (convert_value & APP_BG_CATEGORY_DOWNLOAD_VAL)
563                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_DOWNLOAD_STR));
564
565         if (convert_value & APP_BG_CATEGORY_BGNETWORK_VAL)
566                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_BGNETWORK_STR));
567
568         if (convert_value & APP_BG_CATEGORY_LOCATION_VAL)
569                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_LOCATION_STR));
570
571         if (convert_value & APP_BG_CATEGORY_SENSOR_VAL)
572                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SENSOR_STR));
573
574         if (convert_value & APP_BG_CATEGORY_IOTCOMM_VAL)
575                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_IOTCOMM_STR));
576
577         if (convert_value & APP_BG_CATEGORY_SYSTEM_VAL)
578                 category_list = g_list_append(category_list, strdup(APP_BG_CATEGORY_SYSTEM));
579
580         return category_list;
581
582 }
583
584 static void __get_splash_screen_display(sqlite3 *db, const char *appid, uid_t uid, char **value)
585 {
586         static const char query_raw[] =
587                 "SELECT is_splash_screen_enabled FROM package_app_info_for_uid "
588                 "WHERE app_id='%s' AND uid='%d'";
589         int ret;
590         char *query;
591         sqlite3_stmt *stmt;
592
593         query = sqlite3_mprintf(query_raw, appid, uid);
594         if (query == NULL) {
595                 LOGE("out of memory");
596                 return;
597         }
598
599         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
600         sqlite3_free(query);
601         if (ret != SQLITE_OK) {
602                 LOGE("sqlite3_prepare_v2() failed: %s", sqlite3_errmsg(db));
603                 return;
604         }
605
606         while (sqlite3_step(stmt) == SQLITE_ROW) {
607                 if (*value)
608                         free(*value);
609                 _save_column_str(stmt, 0, value);
610         }
611
612         sqlite3_finalize(stmt);
613 }
614
615 static int _appinfo_get_application(sqlite3 *db, const char *appid,
616                 const char *locale, application_x **application, bool is_disabled, uid_t db_uid, uid_t target_uid)
617 {
618         static const char query_raw[] =
619                 "SELECT app_id, app_component, app_exec, app_nodisplay, "
620                 "app_type, app_onboot, app_multiple, app_autorestart, "
621                 "app_taskmanage, app_enabled, app_hwacceleration, "
622                 "app_screenreader, app_mainapp, app_recentimage, "
623                 "app_launchcondition, app_indicatordisplay, app_portraitimg, "
624                 "app_landscapeimg, app_guestmodevisibility, "
625                 "app_permissiontype, app_preload, app_submode, "
626                 "app_submode_mainid, app_launch_mode, app_ui_gadget, "
627                 "app_support_disable, "
628                 "component_type, package, app_tep_name, app_process_pool, "
629                 "app_installed_storage, app_background_category, "
630                 "app_package_type, app_root_path, app_api_version, "
631                 "app_effective_appid, app_disable, app_splash_screen_display "
632                 "FROM package_app_info WHERE app_id='%s' "
633                 "AND (app_disable='%s' "
634                 "%s app_id %s IN "
635                 "(SELECT app_id from package_app_info_for_uid WHERE uid='%d' AND is_disabled='true'))";
636         int ret;
637         char query[MAX_QUERY_LEN] = { '\0' };
638         sqlite3_stmt *stmt;
639         int idx;
640         application_x *info;
641         char *bg_category_str = NULL;
642         snprintf(query, MAX_QUERY_LEN - 1, query_raw,
643                         appid,
644                         is_disabled ? "true" : "false",
645                         is_disabled ? "OR" : "AND",
646                         is_disabled ? "" : "NOT",
647                         (int)target_uid);
648
649         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
650         if (ret != SQLITE_OK) {
651                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
652                 return PMINFO_R_ERROR;
653         }
654
655         ret = sqlite3_step(stmt);
656         if (ret == SQLITE_DONE) {
657                 sqlite3_finalize(stmt);
658                 return PMINFO_R_ENOENT;
659         } else if (ret != SQLITE_ROW) {
660                 LOGE("step failed: %s", sqlite3_errmsg(db));
661                 sqlite3_finalize(stmt);
662                 return PMINFO_R_ERROR;
663         }
664
665         info = calloc(1, sizeof(application_x));
666         if (info == NULL) {
667                 LOGE("out of memory");
668                 sqlite3_finalize(stmt);
669                 return PMINFO_R_ERROR;
670         }
671         idx = 0;
672         _save_column_str(stmt, idx++, &info->appid);
673         _save_column_str(stmt, idx++, &info->component);
674         _save_column_str(stmt, idx++, &info->exec);
675         _save_column_str(stmt, idx++, &info->nodisplay);
676         _save_column_str(stmt, idx++, &info->type);
677         _save_column_str(stmt, idx++, &info->onboot);
678         _save_column_str(stmt, idx++, &info->multiple);
679         _save_column_str(stmt, idx++, &info->autorestart);
680         _save_column_str(stmt, idx++, &info->taskmanage);
681         _save_column_str(stmt, idx++, &info->enabled);
682         _save_column_str(stmt, idx++, &info->hwacceleration);
683         _save_column_str(stmt, idx++, &info->screenreader);
684         _save_column_str(stmt, idx++, &info->mainapp);
685         _save_column_str(stmt, idx++, &info->recentimage);
686         _save_column_str(stmt, idx++, &info->launchcondition);
687         _save_column_str(stmt, idx++, &info->indicatordisplay);
688         _save_column_str(stmt, idx++, &info->portraitimg);
689         _save_column_str(stmt, idx++, &info->landscapeimg);
690         _save_column_str(stmt, idx++, &info->guestmode_visibility);
691         _save_column_str(stmt, idx++, &info->permission_type);
692         _save_column_str(stmt, idx++, &info->preload);
693         _save_column_str(stmt, idx++, &info->submode);
694         _save_column_str(stmt, idx++, &info->submode_mainid);
695         _save_column_str(stmt, idx++, &info->launch_mode);
696         _save_column_str(stmt, idx++, &info->ui_gadget);
697         _save_column_str(stmt, idx++, &info->support_disable);
698         _save_column_str(stmt, idx++, &info->component_type);
699         _save_column_str(stmt, idx++, &info->package);
700         _save_column_str(stmt, idx++, &info->tep_name);
701         _save_column_str(stmt, idx++, &info->process_pool);
702         _save_column_str(stmt, idx++, &info->installed_storage);
703         _save_column_str(stmt, idx++, &bg_category_str);
704         _save_column_str(stmt, idx++, &info->package_type);
705         _save_column_str(stmt, idx++, &info->root_path);
706         _save_column_str(stmt, idx++, &info->api_version);
707         _save_column_str(stmt, idx++, &info->effective_appid);
708         _save_column_str(stmt, idx++, &info->is_disabled);
709         _save_column_str(stmt, idx++, &info->splash_screen_display);
710
711         if (db_uid == GLOBAL_USER)
712                 __get_splash_screen_display(db, info->appid, db_uid,
713                                 &info->splash_screen_display);
714
715         info->background_category = __get_background_category(bg_category_str);
716         free(bg_category_str);
717
718         if (_appinfo_get_label(db, info->appid, locale, &info->label)) {
719                 pkgmgrinfo_basic_free_application(info);
720                 sqlite3_finalize(stmt);
721                 return PMINFO_R_ERROR;
722         }
723
724         if (_appinfo_get_icon(db, info->appid, locale, &info->icon)) {
725                 pkgmgrinfo_basic_free_application(info);
726                 sqlite3_finalize(stmt);
727                 return PMINFO_R_ERROR;
728         }
729
730         if (_appinfo_get_category(db, info->appid, &info->category)) {
731                 pkgmgrinfo_basic_free_application(info);
732                 sqlite3_finalize(stmt);
733                 return PMINFO_R_ERROR;
734         }
735
736         if (_appinfo_get_app_control(db, info->appid, &info->appcontrol)) {
737                 pkgmgrinfo_basic_free_application(info);
738                 sqlite3_finalize(stmt);
739                 return PMINFO_R_ERROR;
740         }
741
742         if (_appinfo_get_data_control(db, info->appid, &info->datacontrol)) {
743                 pkgmgrinfo_basic_free_application(info);
744                 sqlite3_finalize(stmt);
745                 return PMINFO_R_ERROR;
746         }
747
748         if (_appinfo_get_metadata(db, info->appid, &info->metadata)) {
749                 pkgmgrinfo_basic_free_application(info);
750                 sqlite3_finalize(stmt);
751                 return PMINFO_R_ERROR;
752         }
753
754         if (_appinfo_get_splashscreens(db, info->appid, &info->splashscreens)) {
755                 pkgmgrinfo_basic_free_application(info);
756                 sqlite3_finalize(stmt);
757                 return PMINFO_R_ERROR;
758         }
759
760         info->for_all_users = strdup((db_uid != GLOBAL_USER) ? "false" : "true");
761
762         *application = info;
763
764         sqlite3_finalize(stmt);
765
766         return PMINFO_R_OK;
767 }
768
769 static int _appinfo_get_appinfo(const char *appid, uid_t db_uid,
770                 uid_t target_uid, bool is_disabled, pkgmgr_appinfo_x **appinfo)
771 {
772         int ret;
773         sqlite3 *db;
774         const char *dbpath;
775         char *locale;
776         pkgmgr_appinfo_x *info;
777
778         dbpath = getUserPkgParserDBPathUID(db_uid);
779         if (dbpath == NULL)
780                 return PMINFO_R_ERROR;
781
782         locale = _get_system_locale();
783         if (locale == NULL)
784                 return PMINFO_R_ERROR;
785
786         ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
787         if (ret != SQLITE_OK) {
788                 _LOGE("failed to open db: %d", ret);
789                 free(locale);
790                 return PMINFO_R_ERROR;
791         }
792
793         info = calloc(1, sizeof(pkgmgr_appinfo_x));
794         if (info == NULL) {
795                 _LOGE("out of memory");
796                 free(locale);
797                 sqlite3_close_v2(db);
798                 return PMINFO_R_ERROR;
799         }
800
801         ret = _appinfo_get_application(db, appid, locale, &info->app_info, is_disabled, db_uid, target_uid);
802         if (ret != PMINFO_R_OK) {
803                 free(info);
804                 free(locale);
805                 sqlite3_close_v2(db);
806                 return ret;
807         }
808
809         info->locale = locale;
810         info->package = strdup(info->app_info->package);
811
812         *appinfo = info;
813
814         sqlite3_close_v2(db);
815
816         return ret;
817 }
818
819 int _appinfo_get_applist(uid_t uid, const char *locale, GHashTable **appinfo_table)
820 {
821         int ret = PMINFO_R_ERROR;
822         int idx = 0;
823         const char *dbpath;
824         char *query = NULL;
825         char *bg_category_str = NULL;
826         char *key = NULL;
827         sqlite3 *db;
828         sqlite3_stmt *stmt = NULL;
829         pkgmgr_appinfo_x *info = NULL;
830         application_x *appinfo = NULL;
831
832         dbpath = getUserPkgParserDBPathUID(uid);
833         if (dbpath == NULL)
834                 return PMINFO_R_ERROR;
835
836         ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
837         if (ret != SQLITE_OK) {
838                 _LOGE("failed to open db: %d", ret);
839                 ret = PMINFO_R_ERROR;
840                 goto catch;
841         }
842
843         query = sqlite3_mprintf("SELECT app_id, app_exec, app_type, "
844                         "app_onboot, app_multiple, app_autorestart, app_taskmanage, "
845                         "app_hwacceleration, app_permissiontype, app_preload, "
846                         "app_installed_storage, app_process_pool, app_launch_mode, "
847                         "app_package_type, component_type, package, app_tep_name, "
848                         "app_background_category, app_root_path, app_api_version, "
849                         "app_effective_appid, app_disable, app_splash_screen_display, "
850                         "(CASE WHEN A.app_disable='true' THEN 'true' "
851                         "ELSE (CASE WHEN (SELECT app_id FROM package_app_info_for_uid "
852                         "WHERE app_id=A.app_id AND uid='%d' AND is_disabled='true') IS NULL "
853                         "THEN 'false' ELSE 'true' END) END) AS app_disable "
854                         "FROM package_app_info A", (int)getuid());
855
856         if (query == NULL) {
857                 _LOGE("Out of memory");
858                 goto catch;
859         }
860
861         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
862         if (ret != SQLITE_OK) {
863                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
864                 ret = PMINFO_R_ERROR;
865                 goto catch;
866         }
867
868         while (sqlite3_step(stmt) == SQLITE_ROW) {
869                 info = calloc(1, sizeof(pkgmgr_appinfo_x));
870                 appinfo = calloc(1, sizeof(application_x));
871                 if (info == NULL || appinfo == NULL) {
872                         LOGE("calloc failed");
873                         ret = PMINFO_R_ERROR;
874                         goto catch;
875                 }
876
877                 idx = 0;
878                 _save_column_str(stmt, idx++, &appinfo->appid);
879                 _save_column_str(stmt, idx++, &appinfo->exec);
880                 _save_column_str(stmt, idx++, &appinfo->type);
881
882                 _save_column_str(stmt, idx++, &appinfo->onboot);
883                 _save_column_str(stmt, idx++, &appinfo->multiple);
884                 _save_column_str(stmt, idx++, &appinfo->autorestart);
885                 _save_column_str(stmt, idx++, &appinfo->taskmanage);
886
887                 _save_column_str(stmt, idx++, &appinfo->hwacceleration);
888                 _save_column_str(stmt, idx++, &appinfo->permission_type);
889                 _save_column_str(stmt, idx++, &appinfo->preload);
890
891                 _save_column_str(stmt, idx++, &appinfo->installed_storage);
892                 _save_column_str(stmt, idx++, &appinfo->process_pool);
893                 _save_column_str(stmt, idx++, &appinfo->launch_mode);
894
895                 _save_column_str(stmt, idx++, &appinfo->package_type);
896                 _save_column_str(stmt, idx++, &appinfo->component_type);
897                 _save_column_str(stmt, idx++, &appinfo->package);
898                 _save_column_str(stmt, idx++, &appinfo->tep_name);
899
900                 _save_column_str(stmt, idx++, &bg_category_str);
901                 _save_column_str(stmt, idx++, &appinfo->root_path);
902                 _save_column_str(stmt, idx++, &appinfo->api_version);
903
904                 _save_column_str(stmt, idx++, &appinfo->effective_appid);
905                 _save_column_str(stmt, idx++, &appinfo->is_disabled);
906                 _save_column_str(stmt, idx++, &appinfo->splash_screen_display);
907
908                 if (uid == GLOBAL_USER)
909                         __get_splash_screen_display(db, appinfo->appid, uid,
910                                         &appinfo->splash_screen_display);
911
912                 appinfo->background_category = __get_background_category(bg_category_str);
913                 free(bg_category_str);
914
915                 if (_appinfo_get_splashscreens(db, appinfo->appid, &appinfo->splashscreens)) {
916                         pkgmgrinfo_basic_free_application(appinfo);
917                         ret = PMINFO_R_ERROR;
918                         goto catch;
919                 }
920
921                 info->locale = strdup(locale);
922                 info->package = strdup(appinfo->package);
923                 appinfo->for_all_users = strdup((uid != GLOBAL_USER) ? "false" : "true");
924                 info->app_info = appinfo;
925                 key = strdup(info->app_info->appid);
926
927                 if (!g_hash_table_contains(*appinfo_table, (gconstpointer)key))
928                         g_hash_table_insert(*appinfo_table, (gpointer)key, (gpointer)info);
929                 else
930                         __cleanup_appinfo(info);
931         }
932
933         ret = PMINFO_R_OK;
934
935 catch:
936
937         sqlite3_finalize(stmt);
938         sqlite3_free(query);
939         sqlite3_close(db);
940
941         return ret;
942 }
943
944 API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid,
945                 pkgmgrinfo_appinfo_h *handle)
946 {
947         int ret;
948
949         if (appid == NULL || handle == NULL) {
950                 LOGE("invalid parameter");
951                 return PMINFO_R_EINVAL;
952         }
953
954         ret = _appinfo_get_appinfo(appid, uid, uid, true, (pkgmgr_appinfo_x **)handle);
955         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
956                 ret = _appinfo_get_appinfo(appid, GLOBAL_USER, uid, true,
957                                 (pkgmgr_appinfo_x **)handle);
958
959         if (ret != PMINFO_R_OK)
960                 _LOGI("Appinfo for [%s] is not existed for user [%d]", appid, uid);
961
962         return ret;
963 }
964
965 API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
966 {
967         return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, _getuid(), handle);
968 }
969
970 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
971                 pkgmgrinfo_appinfo_h *handle)
972 {
973         int ret;
974
975         if (appid == NULL || handle == NULL) {
976                 LOGE("invalid parameter");
977                 return PMINFO_R_EINVAL;
978         }
979
980         ret = _appinfo_get_appinfo(appid, uid, uid, false, (pkgmgr_appinfo_x **)handle);
981         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
982                 ret = _appinfo_get_appinfo(appid, GLOBAL_USER, uid, false,
983                                 (pkgmgr_appinfo_x **)handle);
984         if (ret != PMINFO_R_OK)
985                 _LOGI("Appinfo for [%s] is not existed for user [%d]", appid, uid);
986
987         return ret;
988 }
989
990 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
991 {
992         return pkgmgrinfo_appinfo_get_usr_appinfo(appid, _getuid(), handle);
993 }
994
995 static gpointer __copy_str(gconstpointer src, gpointer data)
996 {
997         const char *tmp = (const char *)src;
998         char *buffer;
999
1000         buffer = strdup(tmp);
1001         if (buffer == NULL) {
1002                 LOGE("memory alloc failed");
1003                 *(int *)data = -1;
1004                 return NULL;
1005         }
1006
1007         return buffer;
1008 }
1009
1010 static gpointer __copy_label(gconstpointer src, gpointer data)
1011 {
1012         label_x *tmp = (label_x *)src;
1013         label_x *label;
1014
1015         label = calloc(1, sizeof(label_x));
1016         if (label == NULL) {
1017                 LOGE("memory alloc failed");
1018                 *(int *)data = -1;
1019                 return NULL;
1020         }
1021
1022         if (tmp->name)
1023                 label->name = strdup(tmp->name);
1024         if (tmp->text)
1025                 label->text = strdup(tmp->text);
1026         if (tmp->lang)
1027                 label->lang = strdup(tmp->lang);
1028
1029         return label;
1030 }
1031
1032 static gpointer __copy_icon(gconstpointer src, gpointer data)
1033 {
1034         icon_x *tmp = (icon_x *)src;
1035         icon_x *icon;
1036
1037         icon = calloc(1, sizeof(icon_x));
1038         if (icon== NULL) {
1039                 LOGE("memory alloc failed");
1040                 *(int *)data = -1;
1041                 return NULL;
1042         }
1043
1044         if (tmp->text)
1045                 icon->text = strdup(tmp->text);
1046         if (tmp->lang)
1047                 icon->lang = strdup(tmp->lang);
1048         if (tmp->section)
1049                 icon->section = strdup(tmp->section);
1050         if (tmp->size)
1051                 icon->size = strdup(tmp->size);
1052         if (tmp->resolution)
1053                 icon->resolution = strdup(tmp->resolution);
1054
1055         return icon;
1056 }
1057
1058 static gpointer __copy_metadata(gconstpointer src, gpointer data)
1059 {
1060         metadata_x *tmp = (metadata_x *)src;
1061         metadata_x *metadata;
1062
1063         metadata = calloc(1, sizeof(metadata_x));
1064         if (metadata == NULL) {
1065                 LOGE("memory alloc failed");
1066                 *(int *)data = -1;
1067                 return NULL;
1068         }
1069
1070         if (tmp->key)
1071                 metadata->key = strdup(tmp->key);
1072         if (tmp->value)
1073                 metadata->value = strdup(tmp->value);
1074
1075         return metadata;
1076 }
1077
1078 static gpointer __copy_datacontrol(gconstpointer src, gpointer data)
1079 {
1080         datacontrol_x *tmp = (datacontrol_x *)src;
1081         datacontrol_x *datacontrol;
1082
1083         datacontrol = calloc(1, sizeof(datacontrol_x));
1084         if (datacontrol == NULL) {
1085                 LOGE("memory alloc failed");
1086                 *(int *)data = -1;
1087                 return NULL;
1088         }
1089
1090         if (tmp->providerid)
1091                 datacontrol->providerid = strdup(tmp->providerid);
1092         if (tmp->access)
1093                 datacontrol->access = strdup(tmp->access);
1094         if (tmp->type)
1095                 datacontrol->type = strdup(tmp->type);
1096
1097         return datacontrol;
1098 }
1099
1100 static gpointer __copy_appcontrol(gconstpointer src, gpointer data)
1101 {
1102         appcontrol_x *tmp = (appcontrol_x *)src;
1103         appcontrol_x *appcontrol;
1104
1105         appcontrol = calloc(1, sizeof(appcontrol_x));
1106         if (appcontrol ==NULL) {
1107                 LOGE("memory alloc failed");
1108                 *(int *)data = -1;
1109                 return NULL;
1110         }
1111
1112         if (tmp->operation)
1113                 appcontrol->operation = strdup(tmp->operation);
1114         if (tmp->uri)
1115                 appcontrol->uri = strdup(tmp->uri);
1116         if (tmp->mime)
1117                 appcontrol->mime = strdup(tmp->mime);
1118
1119         return appcontrol;
1120 }
1121
1122 static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
1123 {
1124         splashscreen_x *tmp = (splashscreen_x *)src;
1125         splashscreen_x *splashscreen;
1126
1127         splashscreen = (splashscreen_x *)calloc(1, sizeof(splashscreen_x));
1128         if (splashscreen == NULL) {
1129                 LOGE("memory alloc failed");
1130                 *(int *)data = -1;
1131                 return NULL;
1132         }
1133
1134         if (tmp->src)
1135                 splashscreen->src = strdup(tmp->src);
1136         if (tmp->type)
1137                 splashscreen->type = strdup(tmp->type);
1138         if (tmp->orientation)
1139                 splashscreen->orientation = strdup(tmp->orientation);
1140         if (tmp->indicatordisplay)
1141                 splashscreen->indicatordisplay = strdup(tmp->indicatordisplay);
1142         if (tmp->operation)
1143                 splashscreen->operation = strdup(tmp->operation);
1144         if (tmp->color_depth)
1145                 splashscreen->color_depth = strdup(tmp->color_depth);
1146
1147         return splashscreen;
1148 }
1149
1150 static int _appinfo_copy_appinfo(application_x **application, application_x *data)
1151 {
1152         application_x *app_info;
1153         int ret;
1154
1155         app_info = calloc(1, sizeof(application_x));
1156         if (app_info == NULL) {
1157                 LOGE("memory alloc failed");
1158                 return PMINFO_R_ERROR;
1159         }
1160
1161         if (data->appid != NULL)
1162                 app_info->appid = strdup(data->appid);
1163         if (data->exec != NULL)
1164                 app_info->exec = strdup(data->exec);
1165         if (data->nodisplay != NULL)
1166                 app_info->nodisplay = strdup(data->nodisplay);
1167         if (data->multiple != NULL)
1168                 app_info->multiple = strdup(data->multiple);
1169         if (data->taskmanage != NULL)
1170                 app_info->taskmanage = strdup(data->taskmanage);
1171         if (data->enabled != NULL)
1172                 app_info->enabled = strdup(data->enabled);
1173         if (data->type != NULL)
1174                 app_info->type = strdup(data->type);
1175         if (data->categories != NULL)
1176                 app_info->categories = strdup(data->categories);
1177         if (data->hwacceleration != NULL)
1178                 app_info->hwacceleration = strdup(data->hwacceleration);
1179         if (data->screenreader != NULL)
1180                 app_info->screenreader = strdup(data->screenreader);
1181         if (data->mainapp != NULL)
1182                 app_info->mainapp = strdup(data->mainapp);
1183         if (data->package != NULL)
1184                 app_info->package = strdup(data->package);
1185         if (data->recentimage != NULL)
1186                 app_info->recentimage = strdup(data->recentimage);
1187         if (data->launchcondition != NULL)
1188                 app_info->launchcondition = strdup(data->launchcondition);
1189         if (data->indicatordisplay != NULL)
1190                 app_info->indicatordisplay = strdup(data->indicatordisplay);
1191         if (data->portraitimg != NULL)
1192                 app_info->portraitimg = strdup(data->portraitimg);
1193         if (data->landscapeimg != NULL)
1194                 app_info->landscapeimg = strdup(data->landscapeimg);
1195         if (data->guestmode_visibility != NULL)
1196                 app_info->guestmode_visibility = strdup(data->guestmode_visibility);
1197         if (data->component != NULL)
1198                 app_info->component = strdup(data->component);
1199         if (data->permission_type != NULL)
1200                 app_info->permission_type = strdup(data->permission_type);
1201         if (data->component_type != NULL)
1202                 app_info->component_type = strdup(data->component_type);
1203         if (data->preload != NULL)
1204                 app_info->preload = strdup(data->preload);
1205         if (data->submode != NULL)
1206                 app_info->submode = strdup(data->submode);
1207         if (data->submode_mainid != NULL)
1208                 app_info->submode_mainid = strdup(data->submode_mainid);
1209         if (data->process_pool != NULL)
1210                 app_info->process_pool = strdup(data->process_pool);
1211         if (data->installed_storage != NULL)
1212                 app_info->installed_storage = strdup(data->installed_storage);
1213         if (data->autorestart != NULL)
1214                 app_info->autorestart = strdup(data->autorestart);
1215         if (data->onboot != NULL)
1216                 app_info->onboot = strdup(data->onboot);
1217         if (data->support_disable != NULL)
1218                 app_info->support_disable = strdup(data->support_disable);
1219         if (data->ui_gadget != NULL)
1220                 app_info->ui_gadget = strdup(data->ui_gadget);
1221         if (data->launch_mode != NULL)
1222                 app_info->launch_mode = strdup(data->launch_mode);
1223         if (data->package_type != NULL)
1224                 app_info->package_type = strdup(data->package_type);
1225         if (data->effective_appid != NULL)
1226                 app_info->effective_appid = strdup(data->effective_appid);
1227         if (data->splash_screen_display != NULL)
1228                 app_info->splash_screen_display = strdup(data->splash_screen_display);
1229
1230         /* GList */
1231         ret = 0;
1232         app_info->label = g_list_copy_deep(data->label, __copy_label, &ret);
1233         if (ret < 0) {
1234                 LOGE("memory alloc failed");
1235                 pkgmgrinfo_basic_free_application(app_info);
1236                 return PMINFO_R_ERROR;
1237         }
1238
1239         ret = 0;
1240         app_info->icon = g_list_copy_deep(data->icon, __copy_icon, &ret);
1241         if (ret < 0) {
1242                 LOGE("memory alloc failed");
1243                 pkgmgrinfo_basic_free_application(app_info);
1244                 return PMINFO_R_ERROR;
1245         }
1246
1247         ret = 0;
1248         app_info->category = g_list_copy_deep(data->category, __copy_str, &ret);
1249         if (ret < 0) {
1250                 LOGE("memory alloc failed");
1251                 pkgmgrinfo_basic_free_application(app_info);
1252                 return PMINFO_R_ERROR;
1253         }
1254
1255         ret = 0;
1256         app_info->metadata = g_list_copy_deep(data->metadata, __copy_metadata, &ret);
1257         if (ret < 0) {
1258                 LOGE("memory alloc failed");
1259                 pkgmgrinfo_basic_free_application(app_info);
1260                 return PMINFO_R_ERROR;
1261         }
1262
1263         ret = 0;
1264         app_info->datacontrol = g_list_copy_deep(data->datacontrol, __copy_datacontrol, &ret);
1265         if (ret < 0) {
1266                 LOGE("memory alloc failed");
1267                 pkgmgrinfo_basic_free_application(app_info);
1268                 return PMINFO_R_ERROR;
1269         }
1270
1271         ret = 0;
1272         app_info->appcontrol = g_list_copy_deep(data->appcontrol, __copy_appcontrol, &ret);
1273         if (ret < 0) {
1274                 LOGE("memory alloc failed");
1275                 pkgmgrinfo_basic_free_application(app_info);
1276                 return PMINFO_R_ERROR;
1277         }
1278
1279         ret = 0;
1280         app_info->background_category = g_list_copy_deep(data->background_category, __copy_str, &ret);
1281         if (ret < 0) {
1282                 LOGE("memory alloc failed");
1283                 pkgmgrinfo_basic_free_application(app_info);
1284                 return PMINFO_R_ERROR;
1285         }
1286
1287         ret = 0;
1288         app_info->splashscreens = g_list_copy_deep(data->splashscreens, __copy_splashscreens, &ret);
1289         if (ret < 0) {
1290                 LOGE("memory alloc failed");
1291                 pkgmgrinfo_basic_free_application(app_info);
1292                 return PMINFO_R_ERROR;
1293         }
1294
1295         *application = app_info;
1296
1297         return PMINFO_R_OK;
1298 }
1299
1300 API int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h handle,
1301                 pkgmgrinfo_appinfo_h *clone)
1302 {
1303         pkgmgr_appinfo_x *info;
1304         pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
1305
1306         if (handle == NULL)
1307                 return PMINFO_R_EINVAL;
1308
1309         info = calloc(1, sizeof(pkgmgr_appinfo_x));
1310         if (info == NULL) {
1311                 LOGE("memory alloc failed");
1312                 return PMINFO_R_ERROR;
1313         }
1314
1315         if (temp->package != NULL)
1316                 info->package = strdup(temp->package);
1317         if (temp->locale != NULL)
1318                 info->locale = strdup(temp->locale);
1319
1320         info->app_component = temp->app_component;
1321
1322         if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
1323                 LOGE("appinfo copy failed");
1324                 if (info->package)
1325                         free((void *)info->package);
1326                 if (info->locale)
1327                         free(info->locale);
1328                 free(info);
1329                 return PMINFO_R_ERROR;
1330         }
1331
1332         *clone = info;
1333
1334         return PMINFO_R_OK;
1335 }
1336
1337 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
1338                 pkgmgrinfo_filter_x *filter, pkgmgrinfo_app_list_cb app_list_cb,
1339                 void *user_data)
1340 {
1341         int ret;
1342         pkgmgr_appinfo_x *info;
1343         GList *list = NULL;
1344         GList *tmp;
1345         char *appid;
1346         int stop = 0;
1347
1348         ret = _appinfo_get_filtered_list(filter, uid, &list);
1349         if (ret != PMINFO_R_OK)
1350                 return PMINFO_R_ERROR;
1351
1352         for (tmp = list; tmp; tmp = tmp->next) {
1353                 appid = (char *)tmp->data;
1354                 if (stop == 0) {
1355                         ret = _appinfo_get_appinfo(appid, uid, uid, false, &info);
1356                         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
1357                                 ret = _appinfo_get_appinfo(appid, GLOBAL_USER, uid, false,
1358                                                 &info);
1359                         if (ret != PMINFO_R_OK) {
1360                                 free(appid);
1361                                 continue;
1362                         }
1363                         if (app_list_cb(info, user_data) < 0)
1364                                 stop = 1;
1365                         pkgmgrinfo_appinfo_destroy_appinfo(info);
1366                 }
1367                 free(appid);
1368         }
1369
1370         g_list_free(list);
1371
1372         return PMINFO_R_OK;
1373 }
1374
1375 static const char *__appcomponent_str(pkgmgrinfo_app_component comp);
1376
1377 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
1378                 pkgmgrinfo_app_component component,
1379                 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
1380 {
1381         int ret;
1382         pkgmgrinfo_appinfo_filter_h filter;
1383         char *pkgid;
1384         const char *comp_str = NULL;
1385
1386         if (handle == NULL || app_func == NULL) {
1387                 LOGE("invalid parameter");
1388                 return PMINFO_R_EINVAL;
1389         }
1390
1391         if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
1392                 LOGE("invalid parameter");
1393                 return PMINFO_R_EINVAL;
1394         }
1395
1396         if (pkgmgrinfo_appinfo_filter_create(&filter))
1397                 return PMINFO_R_ERROR;
1398
1399         if (pkgmgrinfo_appinfo_filter_add_string(filter,
1400                                 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
1401                 pkgmgrinfo_appinfo_filter_destroy(filter);
1402                 return PMINFO_R_ERROR;
1403         }
1404
1405         if (uid == GLOBAL_USER) {
1406                 if (pkgmgrinfo_appinfo_filter_add_int(filter,
1407                                         PMINFO_APPINFO_PROP_APP_DISABLE_FOR_USER, (int)getuid())) {
1408                         pkgmgrinfo_appinfo_filter_destroy(filter);
1409                         return PMINFO_R_ERROR;
1410                 }
1411         }
1412
1413         comp_str = __appcomponent_str(component);
1414
1415         if (comp_str) {
1416                 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1417                                         PMINFO_APPINFO_PROP_APP_COMPONENT,
1418                                         comp_str)) {
1419                         pkgmgrinfo_appinfo_filter_destroy(filter);
1420                         return PMINFO_R_ERROR;
1421                 }
1422         }
1423
1424         ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, app_func,
1425                         user_data);
1426
1427         pkgmgrinfo_appinfo_filter_destroy(filter);
1428
1429         return ret;
1430 }
1431
1432 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
1433                                                 pkgmgrinfo_app_list_cb app_func, void *user_data)
1434 {
1435         return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, _getuid());
1436 }
1437
1438 API int pkgmgrinfo_appinfo_get_usr_applist_for_amd(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1439 {
1440         int ret = PMINFO_R_ERROR;
1441         char *locale = NULL;
1442         GHashTable *appinfo_table;
1443         GHashTableIter iter;
1444         char *key;
1445         pkgmgr_appinfo_x *val;
1446
1447         locale = _get_system_locale();
1448         if (locale == NULL)
1449                 return PMINFO_R_ERROR;
1450
1451         appinfo_table = g_hash_table_new_full(g_str_hash, g_str_equal,
1452                         free, __free_appinfo_list);
1453         if (appinfo_table == NULL) {
1454                 ret = -1;
1455                 goto catch;
1456         }
1457
1458         ret = _appinfo_get_applist(uid, locale, &appinfo_table);
1459         if (ret != PMINFO_R_OK) {
1460                 LOGE("failed get applist[%d]", (int)uid);
1461                 goto catch;
1462         }
1463
1464         if (uid != GLOBAL_USER) {
1465                 ret = _appinfo_get_applist(GLOBAL_USER, locale, &appinfo_table);
1466                 if (ret != PMINFO_R_OK) {
1467                         LOGE("failed get applist[%d]", GLOBAL_USER);
1468                         goto catch;
1469                 }
1470         }
1471
1472         g_hash_table_iter_init(&iter, appinfo_table);
1473         while (g_hash_table_iter_next(&iter, (gpointer)&key, (gpointer)&val)) {
1474                 ret = app_func((void *)val, user_data);
1475                 if (ret != PMINFO_R_OK) {
1476                         LOGE("callback is stopped");
1477                         goto catch;
1478                 }
1479         }
1480
1481 catch:
1482         if (locale)
1483                 free(locale);
1484
1485         if (appinfo_table)
1486                 g_hash_table_destroy(appinfo_table);
1487
1488         return ret;
1489 }
1490
1491 API int pkgmgrinfo_appinfo_get_applist_for_amd(pkgmgrinfo_app_list_cb app_func, void *user_data)
1492 {
1493         return pkgmgrinfo_appinfo_get_usr_applist_for_amd(app_func, _getuid(), user_data);
1494 }
1495
1496 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1497 {
1498         if (app_func == NULL) {
1499                 LOGE("invalid parameter");
1500                 return PMINFO_R_EINVAL;
1501         }
1502
1503         return _appinfo_get_filtered_foreach_appinfo(uid, NULL, app_func,
1504                         user_data);
1505 }
1506
1507 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
1508 {
1509         return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, _getuid(), user_data);
1510 }
1511
1512 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
1513 {
1514         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1515
1516         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1517         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1518
1519         if (info->app_info == NULL || info->app_info->appid == NULL)
1520                 return PMINFO_R_ERROR;
1521         *appid = (char *)info->app_info->appid;
1522
1523         return PMINFO_R_OK;
1524 }
1525
1526 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
1527 {
1528         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1529
1530         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1531         retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1532
1533         if (info->package == NULL)
1534                 return PMINFO_R_ERROR;
1535
1536         *pkg_name = (char *)info->package;
1537
1538         return PMINFO_R_OK;
1539 }
1540
1541 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
1542 {
1543         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1544
1545         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1546         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1547
1548         if (info->package == NULL)
1549                 return PMINFO_R_ERROR;
1550
1551         *pkgid = (char *)info->package;
1552
1553         return PMINFO_R_OK;
1554 }
1555
1556 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h  handle, char **pkgtype)
1557 {
1558         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1559         retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1560         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1561
1562         *pkgtype = (char *)info->app_info->package_type;
1563
1564         return PMINFO_R_OK;
1565 }
1566
1567 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
1568 {
1569         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1570
1571         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1572         retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1573
1574         if (info->app_info == NULL || info->app_info->exec == NULL)
1575                 return PMINFO_R_ERROR;
1576         *exec = (char *)info->app_info->exec;
1577
1578         return PMINFO_R_OK;
1579 }
1580
1581
1582 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1583 {
1584         const char *locale;
1585         icon_x *ptr;
1586         GList *tmp;
1587         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1588
1589         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1590         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1591
1592         locale = info->locale;
1593         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1594
1595         if (info->app_info == NULL)
1596                 return PMINFO_R_ERROR;
1597
1598         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1599                 ptr = (icon_x *)tmp->data;
1600                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1601                                 !strcasecmp(ptr->text, "") ||
1602                                 strcmp(ptr->lang, locale))
1603                         continue;
1604                 *icon = (char *)ptr->text;
1605                 return PMINFO_R_OK;
1606         }
1607
1608         locale = DEFAULT_LOCALE;
1609         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1610                 ptr = (icon_x *)tmp->data;
1611                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1612                                 strcmp(ptr->lang, locale))
1613                         continue;
1614                 *icon = (char *)ptr->text;
1615                 return PMINFO_R_OK;
1616         }
1617
1618         return PMINFO_R_ERROR;
1619 }
1620
1621
1622 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
1623 {
1624         const char *locale;
1625         label_x *ptr;
1626         GList *tmp;
1627         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1628
1629         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1630         retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1631
1632         locale = info->locale;
1633         retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1634
1635         if (info->app_info == NULL)
1636                 return PMINFO_R_ERROR;
1637
1638         for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1639                 ptr = (label_x *)tmp->data;
1640                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1641                                 strcmp(ptr->lang, locale))
1642                         continue;
1643                 *label = (char *)ptr->text;
1644                 return PMINFO_R_OK;
1645         }
1646
1647         locale = DEFAULT_LOCALE;
1648         for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1649                 ptr = (label_x *)tmp->data;
1650                 if (ptr == NULL || ptr->text == NULL || ptr->lang == NULL ||
1651                                 strcmp(ptr->lang, locale))
1652                         continue;
1653                 *label = (char *)ptr->text;
1654                 return PMINFO_R_OK;
1655         }
1656
1657         return PMINFO_R_ERROR;
1658 }
1659
1660 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1661 {
1662         char *result = NULL;
1663         char *query = NULL;
1664         sqlite3_stmt *stmt = NULL;
1665         sqlite3 *db = NULL;
1666         char *val;
1667         const char *manifest_db;
1668
1669         manifest_db = getUserPkgParserDBPathUID(uid);
1670         if (manifest_db == NULL) {
1671                 _LOGE("Failed to get manifest db path");
1672                 goto err;
1673         }
1674
1675         if (sqlite3_open_v2(manifest_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
1676                 _LOGE("DB open fail\n");
1677                 goto err;
1678         }
1679
1680         query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1681         if (query == NULL) {
1682                 _LOGE("Out of memory");
1683                 goto err;
1684         }
1685
1686         if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1687                 _LOGE("prepare_v2 fail\n");
1688                 goto err;
1689         }
1690
1691         if (sqlite3_step(stmt) == SQLITE_ROW) {
1692                 val = (char *)sqlite3_column_text(stmt, 0);
1693                 if (val != NULL)
1694                         result = strdup(val);
1695         }
1696
1697 err:
1698         sqlite3_finalize(stmt);
1699         sqlite3_free(query);
1700         sqlite3_close(db);
1701
1702         return result;
1703 }
1704
1705 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1706 {
1707         char *val;
1708
1709         retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1710
1711         val = _get_localed_label(appid, locale, uid);
1712         if (val == NULL)
1713                 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1714
1715         if (val == NULL)
1716                 return PMINFO_R_ERROR;
1717
1718         *label = val;
1719
1720         return PMINFO_R_OK;
1721 }
1722
1723 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1724 {
1725         return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, _getuid(), label);
1726 }
1727
1728 API int pkgmgrinfo_appinfo_get_metadata_value(pkgmgrinfo_appinfo_h handle, const char *metadata_key, char **metadata_value)
1729 {
1730         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1731         retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL");
1732         retvm_if(metadata_value == NULL, PMINFO_R_EINVAL, "metadata_value is NULL");
1733
1734         GList *list_md = NULL;
1735         metadata_x *metadata = NULL;
1736         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1737
1738         list_md = info->app_info->metadata;
1739
1740         for (; list_md; list_md = list_md->next) {
1741                 metadata = (metadata_x *)list_md->data;
1742                 if (metadata && metadata->key) {
1743                         if (strcasecmp(metadata->key, metadata_key) == 0) {
1744                                 *metadata_value = (char*)metadata->value;
1745                                 return PMINFO_R_OK;
1746                         }
1747                 }
1748         }
1749
1750         return PMINFO_R_EINVAL;
1751 }
1752
1753 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1754 {
1755         if (strcasecmp(comp, "uiapp") == 0)
1756                 return PMINFO_UI_APP;
1757         else if (strcasecmp(comp, "svcapp") == 0)
1758                 return PMINFO_SVC_APP;
1759         else if (strcasecmp(comp, "widgetapp") == 0)
1760                 return PMINFO_WIDGET_APP;
1761         else if (strcasecmp(comp, "watchapp") == 0)
1762                 return PMINFO_WATCH_APP;
1763         else
1764                 return -1;
1765 }
1766
1767 static const char *__appcomponent_str(pkgmgrinfo_app_component comp)
1768 {
1769         switch (comp) {
1770         case PMINFO_UI_APP:
1771                 return "uiapp";
1772         case PMINFO_SVC_APP:
1773                 return "svcapp";
1774         case PMINFO_WIDGET_APP:
1775                 return "widgetapp";
1776         case PMINFO_WATCH_APP:
1777                 return "watchapp";
1778         default:
1779                 return NULL;
1780         }
1781 }
1782
1783 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1784 {
1785         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1786         int comp;
1787
1788         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1789         retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1790
1791         if (info->app_info == NULL)
1792                 return PMINFO_R_ERROR;
1793
1794         comp = __appcomponent_convert(info->app_info->component);
1795         if (comp < 0)
1796                 return PMINFO_R_ERROR;
1797
1798         *component = comp;
1799
1800         return PMINFO_R_OK;
1801 }
1802
1803 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1804 {
1805         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1806
1807         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1808         retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1809
1810         if (info->app_info == NULL || info->app_info->type == NULL)
1811                 return PMINFO_R_ERROR;
1812         *app_type = (char *)info->app_info->type;
1813
1814         return PMINFO_R_OK;
1815 }
1816
1817 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h  handle,
1818                                         int *operation_count, char ***operation)
1819 {
1820         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1821         retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1822         retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1823         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1824         *operation_count = data->operation_count;
1825         *operation = data->operation;
1826         return PMINFO_R_OK;
1827 }
1828
1829 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h  handle,
1830                                         int *uri_count, char ***uri)
1831 {
1832         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1833         retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1834         retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1835         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1836         *uri_count = data->uri_count;
1837         *uri = data->uri;
1838         return PMINFO_R_OK;
1839 }
1840
1841 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h  handle,
1842                                         int *mime_count, char ***mime)
1843 {
1844         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1845         retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1846         retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1847         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1848         *mime_count = data->mime_count;
1849         *mime = data->mime;
1850         return PMINFO_R_OK;
1851 }
1852
1853 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h  handle,
1854                                         int *subapp_count, char ***subapp)
1855 {
1856         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1857         retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1858         retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1859         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1860         *subapp_count = data->subapp_count;
1861         *subapp = data->subapp;
1862         return PMINFO_R_OK;
1863 }
1864
1865 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1866 {
1867         char *val;
1868         icon_x *ptr;
1869         GList *tmp;
1870         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1871
1872         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1873         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1874
1875         if (info->app_info == NULL)
1876                 return PMINFO_R_ERROR;
1877
1878         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1879                 ptr = (icon_x *)tmp->data;
1880                 if (ptr == NULL || ptr->section == NULL)
1881                         continue;
1882
1883                 val = (char *)ptr->section;
1884                 if (val && strcmp(val, "setting") == 0) {
1885                         *icon = (char *)ptr->text;
1886                         return PMINFO_R_OK;
1887                 }
1888         }
1889
1890         return PMINFO_R_ERROR;
1891 }
1892
1893
1894 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1895 {
1896         char *val;
1897         icon_x *ptr;
1898         GList *tmp;
1899         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1900
1901         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1902         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1903
1904         if (info->app_info == NULL)
1905                 return PMINFO_R_ERROR;
1906
1907         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1908                 ptr = (icon_x *)tmp->data;
1909                 if (ptr == NULL || ptr->section == NULL)
1910                         continue;
1911
1912                 val = (char *)ptr->section;
1913                 if (val && strcmp(val, "notification") == 0){
1914                         *icon = (char *)ptr->text;
1915                         return PMINFO_R_OK;
1916                 }
1917         }
1918
1919         return PMINFO_R_ERROR;
1920 }
1921
1922 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1923 {
1924         char *val;
1925         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1926
1927         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1928         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1929
1930         if (info->app_info == NULL || info->app_info->recentimage == NULL)
1931                 return PMINFO_R_ERROR;
1932
1933         val = (char *)info->app_info->recentimage;
1934         if (strcasecmp(val, "capture") == 0)
1935                 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1936         else if (strcasecmp(val, "icon") == 0)
1937                 *type = PMINFO_RECENTIMAGE_USE_ICON;
1938         else
1939                 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1940
1941         return PMINFO_R_OK;
1942 }
1943
1944 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1945 {
1946         char *val;
1947         image_x *ptr;
1948         GList *tmp;
1949         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1950
1951         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1952         retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1953
1954         if (info->app_info == NULL)
1955                 return PMINFO_R_ERROR;
1956
1957         for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1958                 ptr = (image_x *)tmp->data;
1959                 if (ptr == NULL || ptr->section == NULL)
1960                         continue;
1961
1962                 val = (char *)ptr->section;
1963                 if (val && strcmp(val, "preview") == 0) {
1964                         *preview_img = (char *)ptr->text;
1965                         return PMINFO_R_OK;
1966                 }
1967         }
1968
1969         return PMINFO_R_ERROR;
1970 }
1971
1972 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1973 {
1974         const char *val;
1975         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1976
1977         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1978         retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1979
1980         val = info->app_info->permission_type;
1981         if (val == NULL)
1982                 return PMINFO_R_ERROR;
1983
1984         if (strcmp(val, "signature") == 0)
1985                 *permission = PMINFO_PERMISSION_SIGNATURE;
1986         else if (strcmp(val, "privilege") == 0)
1987                 *permission = PMINFO_PERMISSION_PRIVILEGE;
1988         else
1989                 *permission = PMINFO_PERMISSION_NORMAL;
1990
1991         return PMINFO_R_OK;
1992 }
1993
1994 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1995 {
1996         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1997
1998         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1999         retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2000
2001         if (info->app_info == NULL || info->app_info->component_type == NULL)
2002                 return PMINFO_R_ERROR;
2003
2004         *component_type = (char *)info->app_info->component_type;
2005
2006         return PMINFO_R_OK;
2007 }
2008
2009 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
2010 {
2011         char *val;
2012         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2013
2014         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2015         retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2016
2017         if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
2018                 return PMINFO_R_ERROR;
2019
2020         val = (char *)info->app_info->hwacceleration;
2021         if (strcasecmp(val, "not-use-GL") == 0)
2022                 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
2023         else if (strcasecmp(val, "use-GL") == 0)
2024                 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
2025         else
2026                 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
2027
2028         return PMINFO_R_OK;
2029 }
2030
2031 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
2032 {
2033         char *val;
2034         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2035
2036         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2037         retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2038
2039         if (info->app_info == NULL || info->app_info->screenreader == NULL)
2040                 return PMINFO_R_ERROR;
2041
2042         val = (char *)info->app_info->screenreader;
2043         if (strcasecmp(val, "screenreader-off") == 0)
2044                 *screenreader = PMINFO_SCREENREADER_OFF;
2045         else if (strcasecmp(val, "screenreader-on") == 0)
2046                 *screenreader = PMINFO_SCREENREADER_ON;
2047         else
2048                 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
2049
2050         return PMINFO_R_OK;
2051 }
2052
2053 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
2054 {
2055         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2056
2057         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2058         retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2059         retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2060
2061         if (info->app_info == NULL || (info->app_info->portraitimg == NULL
2062                         && info->app_info->landscapeimg == NULL))
2063                 return PMINFO_R_ERROR;
2064
2065         *portrait_img = (char *)info->app_info->portraitimg;
2066         *landscape_img = (char *)info->app_info->landscapeimg;
2067
2068         return PMINFO_R_OK;
2069 }
2070
2071 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
2072 {
2073         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2074
2075         if (handle == NULL || effectimage_type == NULL) {
2076                 LOGE("invalid parameter");
2077                 return PMINFO_R_EINVAL;
2078         }
2079
2080         if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
2081                 return PMINFO_R_ERROR;
2082
2083         *effectimage_type = (char *)info->app_info->effectimage_type;
2084
2085         return PMINFO_R_OK;
2086 }
2087
2088 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h  handle, char **submode_mainid)
2089 {
2090         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2091
2092         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2093         retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2094
2095         if (info->app_info == NULL || info->app_info->submode_mainid == NULL)
2096                 return PMINFO_R_ERROR;
2097
2098         *submode_mainid = (char *)info->app_info->submode_mainid;
2099
2100         return PMINFO_R_OK;
2101 }
2102
2103 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
2104 {
2105         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2106         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2107
2108         if (info->app_info && info->app_info->installed_storage){
2109                  if (strcmp(info->app_info->installed_storage,"installed_internal") == 0)
2110                         *storage = PMINFO_INTERNAL_STORAGE;
2111                  else if (strcmp(info->app_info->installed_storage,"installed_external") == 0)
2112                          *storage = PMINFO_EXTERNAL_STORAGE;
2113                  else
2114                          return PMINFO_R_ERROR;
2115         }else
2116                 return PMINFO_R_ERROR;
2117
2118         return PMINFO_R_OK;
2119 }
2120
2121 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
2122 {
2123         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2124
2125         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2126         retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2127
2128         if (info->app_info->launch_mode == NULL)
2129                 return PMINFO_R_ERROR;
2130
2131         *mode = (char *)(info->app_info->launch_mode);
2132
2133         return PMINFO_R_OK;
2134 }
2135
2136 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
2137 {
2138         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2139
2140         if (handle == NULL || alias_appid == NULL) {
2141                 LOGE("invalid parameter");
2142                 return PMINFO_R_EINVAL;
2143         }
2144
2145         if (info->app_info == NULL || info->app_info->alias_appid == NULL)
2146                 return PMINFO_R_ERROR;
2147
2148         *alias_appid = (char *)info->app_info->alias_appid;
2149
2150         return PMINFO_R_OK;
2151 }
2152
2153 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
2154 {
2155         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2156
2157         if (handle == NULL || effective_appid == NULL) {
2158                 LOGE("invalid parameter");
2159                 return PMINFO_R_EINVAL;
2160         }
2161
2162         if (info->app_info == NULL || info->app_info->effective_appid == NULL)
2163                 return PMINFO_R_ERROR;
2164
2165         *effective_appid = (char *)info->app_info->effective_appid;
2166
2167         return PMINFO_R_OK;
2168 }
2169
2170 API int pkgmgrinfo_appinfo_get_tep_name(pkgmgrinfo_appinfo_h handle, char **tep_name)
2171 {
2172         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2173
2174         if (handle == NULL || tep_name == NULL) {
2175                 LOGE("invalid parameter");
2176                 return PMINFO_R_EINVAL;
2177         }
2178
2179         if (info->app_info == NULL || info->app_info->tep_name == NULL)
2180                 return PMINFO_R_ERROR;
2181
2182         *tep_name = (char *)info->app_info->tep_name;
2183
2184         return PMINFO_R_OK;
2185 }
2186
2187 API int pkgmgrinfo_appinfo_get_root_path(pkgmgrinfo_appinfo_h handle, char **root_path)
2188 {
2189         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2190
2191         if (handle == NULL || root_path == NULL) {
2192                 LOGE("invalid parameter");
2193                 return PMINFO_R_EINVAL;
2194         }
2195
2196         if (info->app_info == NULL || info->app_info->root_path == NULL)
2197                 return PMINFO_R_ERROR;
2198
2199         *root_path = (char *)info->app_info->root_path;
2200
2201         return PMINFO_R_OK;
2202 }
2203
2204 API int pkgmgrinfo_appinfo_get_api_version(pkgmgrinfo_appinfo_h handle, char **api_version)
2205 {
2206         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2207
2208         if (handle == NULL || api_version == NULL) {
2209                 LOGE("invalid parameter");
2210                 return PMINFO_R_EINVAL;
2211         }
2212
2213         if (info->app_info == NULL || info->app_info->api_version == NULL)
2214                 return PMINFO_R_ERROR;
2215
2216         *api_version = (char *)info->app_info->api_version;
2217
2218         return PMINFO_R_OK;
2219 }
2220
2221 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid, const char *type, uid_t uid, char **appid, char **access)
2222 {
2223         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2224         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2225         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2226         retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2227
2228         int ret = PMINFO_R_OK;
2229         char *query = NULL;
2230         sqlite3_stmt *stmt = NULL;
2231
2232         /*open db*/
2233         ret = __open_manifest_db(uid, true);
2234         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2235
2236         /*Start constructing query*/
2237         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q and type=%Q", providerid, type);
2238
2239         /*prepare query*/
2240         ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
2241         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
2242
2243         /*step query*/
2244         ret = sqlite3_step(stmt);
2245         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
2246
2247         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2248         *access = strdup((char *)sqlite3_column_text(stmt, 2));
2249
2250         ret = PMINFO_R_OK;
2251
2252 catch:
2253         sqlite3_free(query);
2254         sqlite3_finalize(stmt);
2255         __close_manifest_db();
2256         return ret;
2257 }
2258
2259 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid, const char *type, char **appid, char **access)
2260 {
2261         return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid, type, _getuid(), appid, access);
2262 }
2263
2264 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid, uid_t uid, char **appid)
2265 {
2266         retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
2267         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2268
2269         int ret = PMINFO_R_OK;
2270         char *query = NULL;
2271         sqlite3_stmt *stmt = NULL;
2272
2273         /*open db*/
2274         ret = __open_manifest_db(uid, true);
2275         retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
2276
2277         /*Start constructing query*/
2278         query = sqlite3_mprintf("select * from package_app_data_control where providerid=%Q", providerid);
2279
2280         /*prepare query*/
2281         ret = sqlite3_prepare_v2(GET_DB(manifest_db), query, strlen(query), &stmt, NULL);
2282         tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
2283
2284         /*step query*/
2285         ret = sqlite3_step(stmt);
2286         tryvm_if((ret != SQLITE_ROW) || (ret == SQLITE_DONE), ret = PMINFO_R_ERROR, "No records found");
2287
2288         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2289
2290         ret = PMINFO_R_OK;
2291
2292 catch:
2293         sqlite3_free(query);
2294         sqlite3_finalize(stmt);
2295         __close_manifest_db();
2296         return ret;
2297 }
2298
2299 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
2300 {
2301         return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
2302 }
2303
2304 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
2305                         pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
2306 {
2307         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2308         retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2309         int ret = -1;
2310         permission_x *ptr;
2311         GList *tmp;
2312         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2313
2314         if (info->app_info == NULL)
2315                 return PMINFO_R_ERROR;
2316
2317         for (tmp = info->app_info->permission; tmp; tmp = tmp->next) {
2318                 ptr = (permission_x *)tmp->data;
2319                 if (ptr == NULL)
2320                         continue;
2321                 if (ptr->value) {
2322                         ret = permission_func(ptr->value, user_data);
2323                         if (ret < 0)
2324                                 break;
2325                 }
2326         }
2327         return PMINFO_R_OK;
2328 }
2329
2330 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
2331                         pkgmgrinfo_app_category_list_cb category_func, void *user_data)
2332 {
2333         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2334         retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2335         int ret = -1;
2336         const char *category;
2337         GList *tmp;
2338         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2339
2340         if (info->app_info == NULL)
2341                 return PMINFO_R_ERROR;
2342
2343         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2344                 category = (const char *)tmp->data;
2345                 if (category) {
2346                         ret = category_func(category, user_data);
2347                         if (ret < 0)
2348                                 break;
2349                 }
2350         }
2351         return PMINFO_R_OK;
2352 }
2353
2354 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
2355                         pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
2356 {
2357         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2358         retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2359         int ret = -1;
2360         metadata_x *ptr;
2361         GList *tmp;
2362         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2363
2364         if (info->app_info == NULL)
2365                 return PMINFO_R_ERROR;
2366
2367         for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
2368                 ptr = (metadata_x *)tmp->data;
2369                 if (ptr == NULL)
2370                         continue;
2371                 if (ptr->key) {
2372                         ret = metadata_func(ptr->key, ptr->value, user_data);
2373                         if (ret < 0)
2374                                 break;
2375                 }
2376         }
2377         return PMINFO_R_OK;
2378 }
2379
2380 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
2381                         pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
2382 {
2383         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2384         retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2385         int ret;
2386         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2387         appcontrol_x *appcontrol;
2388         GList *tmp;
2389
2390         if (info->app_info == NULL)
2391                 return PMINFO_R_ERROR;
2392
2393         for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2394                 appcontrol = (appcontrol_x *)tmp->data;
2395                 if (appcontrol == NULL)
2396                         continue;
2397                 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
2398                 if (ret < 0)
2399                         break;
2400         }
2401
2402         return PMINFO_R_OK;
2403 }
2404
2405 API int pkgmgrinfo_appinfo_foreach_background_category(
2406                 pkgmgrinfo_appinfo_h handle,
2407                 pkgmgrinfo_app_background_category_list_cb category_func,
2408                 void *user_data)
2409 {
2410         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2411         GList *tmp;
2412         char *category;
2413
2414         if (handle == NULL || category_func == NULL || info->app_info == NULL) {
2415                 LOGE("invalid parameter");
2416                 return PMINFO_R_EINVAL;
2417         }
2418
2419         for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
2420                 category = (char *)tmp->data;
2421                 if (category == NULL)
2422                         continue;
2423
2424                 if (category_func(category, user_data) < 0)
2425                         break;
2426         }
2427
2428         return PMINFO_R_OK;
2429 }
2430
2431 API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
2432                 pkgmgrinfo_app_splash_screen_list_cb splash_screen_func,
2433                 void *user_data)
2434 {
2435         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2436         splashscreen_x *splashscreen;
2437         GList *tmp;
2438         int ret;
2439
2440         if (info == NULL || info->app_info == NULL
2441                         || splash_screen_func == NULL) {
2442                 LOGE("invalid parameter");
2443                 return PMINFO_R_EINVAL;
2444         }
2445
2446         for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) {
2447                 splashscreen = (splashscreen_x *)tmp->data;
2448                 if (splashscreen == NULL)
2449                         continue;
2450                 ret = splash_screen_func(splashscreen->src,
2451                                 splashscreen->type,
2452                                 splashscreen->orientation,
2453                                 splashscreen->indicatordisplay,
2454                                 splashscreen->operation,
2455                                 splashscreen->color_depth,
2456                                 user_data);
2457                 if (ret < 0)
2458                         break;
2459         }
2460
2461         return PMINFO_R_OK;
2462 }
2463
2464 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
2465 {
2466         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2467         retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2468         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2469
2470         if (info->app_info == NULL || info->app_info->nodisplay == NULL)
2471                 return PMINFO_R_ERROR;
2472
2473         *nodisplay = _get_bool_value(info->app_info->nodisplay);
2474
2475         return PMINFO_R_OK;
2476 }
2477
2478 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
2479 {
2480         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2481         retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2482         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2483
2484         if (info->app_info == NULL || info->app_info->multiple == NULL)
2485                 return PMINFO_R_ERROR;
2486
2487         *multiple = _get_bool_value(info->app_info->multiple);
2488
2489         return PMINFO_R_OK;
2490 }
2491
2492 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
2493 {
2494         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2495         retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2496         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2497
2498         if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
2499                 return PMINFO_R_ERROR;
2500
2501         *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
2502
2503         return PMINFO_R_OK;
2504 }
2505
2506 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h  handle, bool *taskmanage)
2507 {
2508         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2509         retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2510         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2511
2512         if (info->app_info == NULL || info->app_info->taskmanage == NULL)
2513                 return PMINFO_R_ERROR;
2514
2515         *taskmanage = _get_bool_value(info->app_info->taskmanage);
2516
2517         return PMINFO_R_OK;
2518 }
2519
2520 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h  handle, bool *enabled)
2521 {
2522         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2523         retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2524         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2525
2526         if (info->app_info == NULL || info->app_info->enabled == NULL)
2527                 return PMINFO_R_ERROR;
2528
2529         *enabled = _get_bool_value(info->app_info->enabled);
2530
2531         return PMINFO_R_OK;
2532 }
2533
2534 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h  handle, bool *onboot)
2535 {
2536         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2537         retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2538         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2539
2540         if (info->app_info == NULL || info->app_info->onboot == NULL)
2541                 return PMINFO_R_ERROR;
2542
2543         *onboot = _get_bool_value(info->app_info->onboot);
2544
2545         return PMINFO_R_OK;
2546 }
2547
2548 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h  handle, bool *autorestart)
2549 {
2550         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2551         retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2552         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2553
2554         if (info->app_info == NULL || info->app_info->autorestart == NULL)
2555                 return PMINFO_R_ERROR;
2556
2557         *autorestart = _get_bool_value(info->app_info->autorestart);
2558
2559         return PMINFO_R_OK;
2560 }
2561
2562 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h  handle, bool *mainapp)
2563 {
2564         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2565         retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2566         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2567
2568         if (info->app_info == NULL || info->app_info->mainapp == NULL)
2569                 return PMINFO_R_ERROR;
2570
2571         *mainapp = _get_bool_value(info->app_info->mainapp);
2572
2573         return PMINFO_R_OK;
2574 }
2575
2576 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
2577 {
2578         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2579         retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2580         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2581
2582         if (info->app_info == NULL || info->app_info->preload == NULL)
2583                 return PMINFO_R_ERROR;
2584
2585         *preload = _get_bool_value(info->app_info->preload);
2586
2587         return PMINFO_R_OK;
2588 }
2589
2590 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
2591 {
2592         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2593         retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2594         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2595
2596         if (info->app_info == NULL || info->app_info->submode == NULL)
2597                 return PMINFO_R_ERROR;
2598
2599         *submode = _get_bool_value(info->app_info->submode);
2600
2601         return PMINFO_R_OK;
2602 }
2603
2604 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
2605 {
2606         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2607
2608         if (handle == NULL || process_pool == NULL) {
2609                 LOGE("invalid parameter");
2610                 return PMINFO_R_EINVAL;
2611         }
2612
2613         if (info->app_info == NULL)
2614                 return PMINFO_R_ERROR;
2615
2616         *process_pool = _get_bool_value(info->app_info->process_pool);
2617
2618         return PMINFO_R_OK;
2619 }
2620
2621 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
2622 {
2623         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2624         retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
2625         retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
2626
2627         const char *val;
2628         GList *tmp;
2629         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2630
2631         if (info->app_info == NULL)
2632                 return PMINFO_R_ERROR;
2633
2634         *exist = 0;
2635         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2636                 val = (const char *)tmp->data;
2637                 if (val == NULL)
2638                         continue;
2639                 if (strcasecmp(val, category) == 0) {
2640                         *exist = 1;
2641                         break;
2642                 }
2643         }
2644
2645         return PMINFO_R_OK;
2646 }
2647
2648 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
2649                 bool *ui_gadget)
2650 {
2651         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2652
2653         if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
2654                 _LOGE("invalid parameter");
2655                 return PMINFO_R_EINVAL;
2656         }
2657
2658         *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
2659
2660         return PMINFO_R_OK;
2661 }
2662
2663 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
2664                 bool *support_disable)
2665 {
2666         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2667
2668         if (info == NULL || info->app_info == NULL || support_disable == NULL) {
2669                 _LOGE("invalid parameter");
2670                 return PMINFO_R_EINVAL;
2671         }
2672
2673         *support_disable = _get_bool_value(info->app_info->support_disable);
2674
2675         return PMINFO_R_OK;
2676 }
2677
2678 API int pkgmgrinfo_appinfo_is_disabled(pkgmgrinfo_appinfo_h handle, bool *disabled)
2679 {
2680         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2681         retvm_if(disabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2682         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2683
2684         if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2685                 return PMINFO_R_ERROR;
2686
2687         *disabled = _get_bool_value(info->app_info->is_disabled);
2688
2689         return PMINFO_R_OK;
2690 }
2691
2692 API int pkgmgrinfo_appinfo_is_global(pkgmgrinfo_appinfo_h handle, bool *global)
2693 {
2694         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2695
2696         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2697         retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2698
2699         if (info->app_info == NULL || info->app_info->for_all_users == NULL)
2700                 return PMINFO_R_ERROR;
2701
2702         *global = _get_bool_value(info->app_info->for_all_users);
2703
2704         return PMINFO_R_OK;
2705 }
2706
2707 API int pkgmgrinfo_appinfo_get_splash_screen_display(pkgmgrinfo_appinfo_h handle, bool *splash_screen_display)
2708 {
2709         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2710
2711         if (info == NULL || splash_screen_display == NULL) {
2712                 _LOGE("Invalid parameter");
2713                 return PMINFO_R_EINVAL;
2714         }
2715
2716         if (info->app_info == NULL || info->app_info->splash_screen_display == NULL)
2717                 return PMINFO_R_ERROR;
2718
2719         *splash_screen_display = _get_bool_value(info->app_info->splash_screen_display);
2720
2721         return PMINFO_R_OK;
2722 }
2723
2724 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
2725 {
2726         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2727         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2728         __cleanup_appinfo(info);
2729         return PMINFO_R_OK;
2730 }
2731
2732 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
2733 {
2734         return (pkgmgrinfo_pkginfo_filter_create(handle));
2735 }
2736
2737 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
2738 {
2739         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2740 }
2741
2742 static gint __compare_func(gconstpointer data1, gconstpointer data2)
2743 {
2744         pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
2745         pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
2746         if (node1->prop == node2->prop)
2747                 return 0;
2748         else if (node1->prop > node2->prop)
2749                 return 1;
2750         else
2751                 return -1;
2752 }
2753
2754 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
2755                                 const char *property, const int value)
2756 {
2757         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2758         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2759         char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
2760         char *val = NULL;
2761         GSList *link = NULL;
2762         int prop = -1;
2763         prop = _pminfo_appinfo_convert_to_prop_int(property);
2764         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
2765                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
2766                 _LOGE("Invalid Integer Property\n");
2767                 return PMINFO_R_EINVAL;
2768         }
2769         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2770         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2771         if (node == NULL) {
2772                 _LOGE("Out of Memory!!!\n");
2773                 return PMINFO_R_ERROR;
2774         }
2775         snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
2776         val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
2777         if (val == NULL) {
2778                 _LOGE("Out of Memory\n");
2779                 free(node);
2780                 node = NULL;
2781                 return PMINFO_R_ERROR;
2782         }
2783         node->prop = prop;
2784         node->value = val;
2785         /*If API is called multiple times for same property, we should override the previous values.
2786         Last value set will be used for filtering.*/
2787         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2788         if (link)
2789                 filter->list = g_slist_delete_link(filter->list, link);
2790         filter->list = g_slist_append(filter->list, (gpointer)node);
2791         return PMINFO_R_OK;
2792
2793 }
2794
2795 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
2796                                 const char *property, const bool value)
2797 {
2798         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2799         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2800         char *val = NULL;
2801         GSList *link = NULL;
2802         int prop = -1;
2803         prop = _pminfo_appinfo_convert_to_prop_bool(property);
2804         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
2805                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
2806                 _LOGE("Invalid Boolean Property\n");
2807                 return PMINFO_R_EINVAL;
2808         }
2809         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2810         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2811         if (node == NULL) {
2812                 _LOGE("Out of Memory!!!\n");
2813                 return PMINFO_R_ERROR;
2814         }
2815         if (value)
2816                 val = strndup("('true','True')", 15);
2817         else
2818                 val = strndup("('false','False')", 17);
2819         if (val == NULL) {
2820                 _LOGE("Out of Memory\n");
2821                 free(node);
2822                 node = NULL;
2823                 return PMINFO_R_ERROR;
2824         }
2825         node->prop = prop;
2826         node->value = val;
2827         /*If API is called multiple times for same property, we should override the previous values.
2828         Last value set will be used for filtering.*/
2829         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2830         if (link)
2831                 filter->list = g_slist_delete_link(filter->list, link);
2832         filter->list = g_slist_append(filter->list, (gpointer)node);
2833         return PMINFO_R_OK;
2834
2835 }
2836
2837 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
2838                                 const char *property, const char *value)
2839 {
2840         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2841         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2842         retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
2843         char *val = NULL;
2844         pkgmgrinfo_node_x *ptr = NULL;
2845         char prev[PKG_STRING_LEN_MAX] = {'\0'};
2846         char temp[PKG_STRING_LEN_MAX] = {'\0'};
2847         GSList *link = NULL;
2848         int prop = -1;
2849         prop = _pminfo_appinfo_convert_to_prop_str(property);
2850         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
2851                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
2852                 _LOGE("Invalid String Property\n");
2853                 return PMINFO_R_EINVAL;
2854         }
2855         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
2856         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
2857         if (node == NULL) {
2858                 _LOGE("Out of Memory!!!\n");
2859                 return PMINFO_R_ERROR;
2860         }
2861         node->prop = prop;
2862         switch (prop) {
2863         case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
2864                 node->value = strdup(value);
2865                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2866                 if (link)
2867                         filter->list = g_slist_delete_link(filter->list, link);
2868                 filter->list = g_slist_append(filter->list, (gpointer)node);
2869                 break;
2870         case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
2871                 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
2872                 if (val == NULL) {
2873                         _LOGE("Out of Memory\n");
2874                         free(node);
2875                         node = NULL;
2876                         return PMINFO_R_ERROR;
2877                 }
2878                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2879                 if (link) {
2880                         ptr = (pkgmgrinfo_node_x *)link->data;
2881                         strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
2882                         _LOGI("Previous value is %s\n", prev);
2883                         filter->list = g_slist_delete_link(filter->list, link);
2884                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
2885                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2886                         _LOGI("New value is %s\n", val);
2887                         node->value = val;
2888                         filter->list = g_slist_append(filter->list, (gpointer)node);
2889                         memset(temp, '\0', PKG_STRING_LEN_MAX);
2890                 } else {
2891                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
2892                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
2893                         _LOGI("First value is %s\n", val);
2894                         node->value = val;
2895                         filter->list = g_slist_append(filter->list, (gpointer)node);
2896                         memset(temp, '\0', PKG_STRING_LEN_MAX);
2897                 }
2898                 break;
2899         default:
2900                 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
2901                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
2902                 if (link)
2903                         filter->list = g_slist_delete_link(filter->list, link);
2904                 filter->list = g_slist_append(filter->list, (gpointer)node);
2905                 break;
2906         }
2907         return PMINFO_R_OK;
2908 }
2909
2910 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
2911 {
2912         int ret;
2913         GList *list = NULL;
2914
2915         if (handle == NULL || count == NULL) {
2916                 _LOGE("invalid parameter");
2917                 return PMINFO_R_EINVAL;
2918         }
2919
2920         ret = _appinfo_get_filtered_list(handle, uid, &list);
2921         if (ret != PMINFO_R_OK)
2922                 return PMINFO_R_ERROR;
2923
2924         *count = g_list_length(list);
2925
2926         g_list_free_full(list, free);
2927
2928         return PMINFO_R_OK;
2929 }
2930
2931 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
2932 {
2933         return pkgmgrinfo_appinfo_usr_filter_count(handle, count, _getuid());
2934 }
2935
2936 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
2937                 pkgmgrinfo_appinfo_filter_h handle,
2938                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2939 {
2940         if (handle == NULL || app_cb == NULL) {
2941                 LOGE("invalid parameter");
2942                 return PMINFO_R_EINVAL;
2943         }
2944
2945         return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2946                         user_data);
2947 }
2948
2949 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
2950                                 pkgmgrinfo_app_list_cb app_cb, void * user_data)
2951 {
2952         return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, _getuid());
2953 }
2954
2955 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
2956 {
2957         return (pkgmgrinfo_pkginfo_filter_create(handle));
2958 }
2959
2960 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
2961 {
2962         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
2963 }
2964
2965 API int pkgmgrinfo_appinfo_metadata_filter_add(
2966                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2967                 const char *key, const char *value)
2968 {
2969         int ret;
2970
2971         ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2972                         PMINFO_APPINFO_PROP_APP_METADATA_KEY, key);
2973         if (ret != PMINFO_R_OK)
2974                 return ret;
2975
2976         /* value can be NULL.
2977          * In that case all apps with specified key should be displayed
2978          */
2979         if (value) {
2980                 ret = pkgmgrinfo_appinfo_filter_add_string(handle,
2981                                 PMINFO_APPINFO_PROP_APP_METADATA_VALUE, value);
2982                 if (ret != PMINFO_R_OK)
2983                         return ret;
2984         }
2985
2986         return PMINFO_R_OK;
2987 }
2988
2989 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
2990                 pkgmgrinfo_appinfo_metadata_filter_h handle,
2991                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
2992 {
2993         if (handle == NULL || app_cb == NULL) {
2994                 LOGE("invalid parameter");
2995                 return PMINFO_R_EINVAL;
2996         }
2997
2998         return _appinfo_get_filtered_foreach_appinfo(uid, handle, app_cb,
2999                         user_data);
3000 }
3001
3002 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
3003                 pkgmgrinfo_appinfo_metadata_filter_h handle,
3004                 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3005 {
3006         return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
3007                         user_data, _getuid());
3008 }
3009
3010 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
3011 {
3012         const char *val;
3013         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3014
3015         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3016         retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3017
3018         val = info->app_info->guestmode_visibility;
3019         *status = _get_bool_value(val);
3020         return PMINFO_R_OK;
3021 }