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