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