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