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