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