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