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