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