Fix memory leak
[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_full(g_str_hash, g_str_equal, NULL,
725                         __free_applications);
726         if (list == NULL) {
727                 free(locale);
728                 return PMINFO_R_ERROR;
729         }
730
731         ret = _appinfo_get_applications(uid, uid, locale, filter,
732                         PMINFO_APPINFO_GET_ALL, list);
733         if (!g_hash_table_size(list) && uid != GLOBAL_USER)
734                 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale, filter,
735                                 PMINFO_APPINFO_GET_ALL, list);
736
737         if (ret != PMINFO_R_OK) {
738                 g_hash_table_destroy(list);
739                 free(locale);
740                 return ret;
741         }
742
743         if (!g_hash_table_size(list)) {
744                 _LOGD("appinfo for [%s] is not existed for user [%d]",
745                                 appid, uid);
746                 g_hash_table_destroy(list);
747                 free(locale);
748                 return PMINFO_R_ENOENT;
749         }
750
751         info = calloc(1, sizeof(pkgmgr_appinfo_x));
752         if (info == NULL) {
753                 _LOGE("out of memory");
754                 g_hash_table_destroy(list);
755                 free(locale);
756                 return PMINFO_R_ERROR;
757         }
758
759         info->app_info = (application_x *)g_hash_table_lookup(list, appid);
760         info->locale = locale;
761         info->package = strdup(info->app_info->package);
762
763         /* just free list only */
764         g_hash_table_steal(list, (gconstpointer)appid);
765         g_hash_table_destroy(list);
766
767         *handle = info;
768
769         return ret;
770 }
771
772 API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid,
773                 pkgmgrinfo_appinfo_h *handle)
774 {
775         int ret;
776         pkgmgrinfo_appinfo_filter_h filter;
777
778         if (appid == NULL || handle == NULL) {
779                 LOGE("invalid parameter");
780                 return PMINFO_R_EINVAL;
781         }
782
783         ret = pkgmgrinfo_appinfo_filter_create(&filter);
784         if (ret != PMINFO_R_OK)
785                 return ret;
786
787         ret = pkgmgrinfo_appinfo_filter_add_string(filter,
788                         PMINFO_APPINFO_PROP_APP_ID, appid);
789         if (ret != PMINFO_R_OK) {
790                 pkgmgrinfo_appinfo_filter_destroy(filter);
791                 return PMINFO_R_ERROR;
792         }
793
794         ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
795                         PMINFO_APPINFO_PROP_APP_DISABLE, true);
796         if (ret != PMINFO_R_OK) {
797                 pkgmgrinfo_appinfo_filter_destroy(filter);
798                 return PMINFO_R_ERROR;
799         }
800
801         ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
802         pkgmgrinfo_appinfo_filter_destroy(filter);
803
804         return ret;
805 }
806
807 API int pkgmgrinfo_appinfo_get_disabled_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
808 {
809         return pkgmgrinfo_appinfo_get_usr_disabled_appinfo(appid, _getuid(), handle);
810 }
811
812 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid,
813                 pkgmgrinfo_appinfo_h *handle)
814 {
815         int ret;
816         pkgmgrinfo_appinfo_filter_h filter;
817
818         if (appid == NULL || handle == NULL) {
819                 LOGE("invalid parameter");
820                 return PMINFO_R_EINVAL;
821         }
822
823         ret = pkgmgrinfo_appinfo_filter_create(&filter);
824         if (ret != PMINFO_R_OK)
825                 return ret;
826
827         ret = pkgmgrinfo_appinfo_filter_add_string(filter,
828                         PMINFO_APPINFO_PROP_APP_ID, appid);
829         if (ret != PMINFO_R_OK) {
830                 pkgmgrinfo_appinfo_filter_destroy(filter);
831                 return PMINFO_R_ERROR;
832         }
833
834         ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
835                         PMINFO_APPINFO_PROP_APP_DISABLE, false);
836         if (ret != PMINFO_R_OK) {
837                 pkgmgrinfo_appinfo_filter_destroy(filter);
838                 return PMINFO_R_ERROR;
839         }
840
841         ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
842                         PMINFO_APPINFO_PROP_PKG_DISABLE, false);
843         if (ret != PMINFO_R_OK) {
844                 pkgmgrinfo_appinfo_filter_destroy(filter);
845                 return PMINFO_R_ERROR;
846         }
847
848         ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
849         pkgmgrinfo_appinfo_filter_destroy(filter);
850         return ret;
851 }
852
853 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
854 {
855         return pkgmgrinfo_appinfo_get_usr_appinfo(appid, _getuid(), handle);
856 }
857
858 API int pkgmgrinfo_appinfo_get_usr_all_appinfo(const char *appid, uid_t uid,
859                 pkgmgrinfo_appinfo_h *handle)
860 {
861         int ret;
862         pkgmgrinfo_appinfo_filter_h filter;
863
864         if (appid == NULL || handle == NULL) {
865                 LOGE("invalid parameter");
866                 return PMINFO_R_EINVAL;
867         }
868
869         ret = pkgmgrinfo_appinfo_filter_create(&filter);
870         if (ret != PMINFO_R_OK)
871                 return ret;
872
873         ret = pkgmgrinfo_appinfo_filter_add_string(filter,
874                         PMINFO_APPINFO_PROP_APP_ID, appid);
875         if (ret != PMINFO_R_OK) {
876                 pkgmgrinfo_appinfo_filter_destroy(filter);
877                 return PMINFO_R_ERROR;
878         }
879
880         ret = pkgmgrinfo_appinfo_filter_add_bool(filter,
881                         PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false);
882         if (ret != PMINFO_R_OK) {
883                 pkgmgrinfo_appinfo_filter_destroy(filter);
884                 return PMINFO_R_ERROR;
885         }
886
887         ret = _pkgmgrinfo_get_appinfo(appid, uid, filter, handle);
888         pkgmgrinfo_appinfo_filter_destroy(filter);
889
890         return ret;
891 }
892
893 API int pkgmgrinfo_appinfo_get_all_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
894 {
895         return pkgmgrinfo_appinfo_get_usr_all_appinfo(appid, _getuid(), handle);
896 }
897
898 static gpointer __copy_str(gconstpointer src, gpointer data)
899 {
900         const char *tmp = (const char *)src;
901         char *buffer;
902
903         buffer = strdup(tmp);
904         if (buffer == NULL) {
905                 LOGE("memory alloc failed");
906                 *(int *)data = -1;
907                 return NULL;
908         }
909
910         return buffer;
911 }
912
913 static gpointer __copy_label(gconstpointer src, gpointer data)
914 {
915         label_x *tmp = (label_x *)src;
916         label_x *label;
917
918         label = calloc(1, sizeof(label_x));
919         if (label == NULL) {
920                 LOGE("memory alloc failed");
921                 *(int *)data = -1;
922                 return NULL;
923         }
924
925         if (tmp->name)
926                 label->name = strdup(tmp->name);
927         if (tmp->text)
928                 label->text = strdup(tmp->text);
929         if (tmp->lang)
930                 label->lang = strdup(tmp->lang);
931
932         return label;
933 }
934
935 static gpointer __copy_icon(gconstpointer src, gpointer data)
936 {
937         icon_x *tmp = (icon_x *)src;
938         icon_x *icon;
939
940         icon = calloc(1, sizeof(icon_x));
941         if (icon == NULL) {
942                 LOGE("memory alloc failed");
943                 *(int *)data = -1;
944                 return NULL;
945         }
946
947         if (tmp->text)
948                 icon->text = strdup(tmp->text);
949         if (tmp->lang)
950                 icon->lang = strdup(tmp->lang);
951         if (tmp->section)
952                 icon->section = strdup(tmp->section);
953         if (tmp->size)
954                 icon->size = strdup(tmp->size);
955         if (tmp->resolution)
956                 icon->resolution = strdup(tmp->resolution);
957
958         return icon;
959 }
960
961 static gpointer __copy_metadata(gconstpointer src, gpointer data)
962 {
963         metadata_x *tmp = (metadata_x *)src;
964         metadata_x *metadata;
965
966         metadata = calloc(1, sizeof(metadata_x));
967         if (metadata == NULL) {
968                 LOGE("memory alloc failed");
969                 *(int *)data = -1;
970                 return NULL;
971         }
972
973         if (tmp->key)
974                 metadata->key = strdup(tmp->key);
975         if (tmp->value)
976                 metadata->value = strdup(tmp->value);
977
978         return metadata;
979 }
980
981 static gpointer __copy_datacontrol(gconstpointer src, gpointer data)
982 {
983         datacontrol_x *tmp = (datacontrol_x *)src;
984         datacontrol_x *datacontrol;
985
986         datacontrol = calloc(1, sizeof(datacontrol_x));
987         if (datacontrol == NULL) {
988                 LOGE("memory alloc failed");
989                 *(int *)data = -1;
990                 return NULL;
991         }
992
993         if (tmp->providerid)
994                 datacontrol->providerid = strdup(tmp->providerid);
995         if (tmp->access)
996                 datacontrol->access = strdup(tmp->access);
997         if (tmp->type)
998                 datacontrol->type = strdup(tmp->type);
999         if (tmp->trusted)
1000                 datacontrol->trusted = strdup(tmp->trusted);
1001
1002         return datacontrol;
1003 }
1004
1005 static gpointer __copy_appcontrol(gconstpointer src, gpointer data)
1006 {
1007         appcontrol_x *tmp = (appcontrol_x *)src;
1008         appcontrol_x *appcontrol;
1009
1010         appcontrol = calloc(1, sizeof(appcontrol_x));
1011         if (appcontrol == NULL) {
1012                 LOGE("memory alloc failed");
1013                 *(int *)data = -1;
1014                 return NULL;
1015         }
1016
1017         if (tmp->operation)
1018                 appcontrol->operation = strdup(tmp->operation);
1019         if (tmp->uri)
1020                 appcontrol->uri = strdup(tmp->uri);
1021         if (tmp->mime)
1022                 appcontrol->mime = strdup(tmp->mime);
1023
1024         return appcontrol;
1025 }
1026
1027 static gpointer __copy_splashscreens(gconstpointer src, gpointer data)
1028 {
1029         splashscreen_x *tmp = (splashscreen_x *)src;
1030         splashscreen_x *splashscreen;
1031
1032         splashscreen = (splashscreen_x *)calloc(1, sizeof(splashscreen_x));
1033         if (splashscreen == NULL) {
1034                 LOGE("memory alloc failed");
1035                 *(int *)data = -1;
1036                 return NULL;
1037         }
1038
1039         if (tmp->src)
1040                 splashscreen->src = strdup(tmp->src);
1041         if (tmp->type)
1042                 splashscreen->type = strdup(tmp->type);
1043         if (tmp->orientation)
1044                 splashscreen->orientation = strdup(tmp->orientation);
1045         if (tmp->indicatordisplay)
1046                 splashscreen->indicatordisplay = strdup(tmp->indicatordisplay);
1047         if (tmp->operation)
1048                 splashscreen->operation = strdup(tmp->operation);
1049         if (tmp->color_depth)
1050                 splashscreen->color_depth = strdup(tmp->color_depth);
1051
1052         return splashscreen;
1053 }
1054
1055 static int _appinfo_copy_appinfo(application_x **application, application_x *data)
1056 {
1057         application_x *app_info;
1058         int ret;
1059
1060         app_info = calloc(1, sizeof(application_x));
1061         if (app_info == NULL) {
1062                 LOGE("memory alloc failed");
1063                 return PMINFO_R_ERROR;
1064         }
1065
1066         if (data->appid != NULL)
1067                 app_info->appid = strdup(data->appid);
1068         if (data->exec != NULL)
1069                 app_info->exec = strdup(data->exec);
1070         if (data->nodisplay != NULL)
1071                 app_info->nodisplay = strdup(data->nodisplay);
1072         if (data->multiple != NULL)
1073                 app_info->multiple = strdup(data->multiple);
1074         if (data->taskmanage != NULL)
1075                 app_info->taskmanage = strdup(data->taskmanage);
1076         if (data->type != NULL)
1077                 app_info->type = strdup(data->type);
1078         if (data->categories != NULL)
1079                 app_info->categories = strdup(data->categories);
1080         if (data->hwacceleration != NULL)
1081                 app_info->hwacceleration = strdup(data->hwacceleration);
1082         if (data->screenreader != NULL)
1083                 app_info->screenreader = strdup(data->screenreader);
1084         if (data->mainapp != NULL)
1085                 app_info->mainapp = strdup(data->mainapp);
1086         if (data->package != NULL)
1087                 app_info->package = strdup(data->package);
1088         if (data->recentimage != NULL)
1089                 app_info->recentimage = strdup(data->recentimage);
1090         if (data->launchcondition != NULL)
1091                 app_info->launchcondition = strdup(data->launchcondition);
1092         if (data->indicatordisplay != NULL)
1093                 app_info->indicatordisplay = strdup(data->indicatordisplay);
1094         if (data->portraitimg != NULL)
1095                 app_info->portraitimg = strdup(data->portraitimg);
1096         if (data->landscapeimg != NULL)
1097                 app_info->landscapeimg = strdup(data->landscapeimg);
1098         if (data->guestmode_visibility != NULL)
1099                 app_info->guestmode_visibility = strdup(data->guestmode_visibility);
1100         if (data->component != NULL)
1101                 app_info->component = strdup(data->component);
1102         if (data->permission_type != NULL)
1103                 app_info->permission_type = strdup(data->permission_type);
1104         if (data->component_type != NULL)
1105                 app_info->component_type = strdup(data->component_type);
1106         if (data->preload != NULL)
1107                 app_info->preload = strdup(data->preload);
1108         if (data->submode != NULL)
1109                 app_info->submode = strdup(data->submode);
1110         if (data->submode_mainid != NULL)
1111                 app_info->submode_mainid = strdup(data->submode_mainid);
1112         if (data->process_pool != NULL)
1113                 app_info->process_pool = strdup(data->process_pool);
1114         if (data->installed_storage != NULL)
1115                 app_info->installed_storage = strdup(data->installed_storage);
1116         if (data->autorestart != NULL)
1117                 app_info->autorestart = strdup(data->autorestart);
1118         if (data->onboot != NULL)
1119                 app_info->onboot = strdup(data->onboot);
1120         if (data->support_disable != NULL)
1121                 app_info->support_disable = strdup(data->support_disable);
1122         if (data->ui_gadget != NULL)
1123                 app_info->ui_gadget = strdup(data->ui_gadget);
1124         if (data->launch_mode != NULL)
1125                 app_info->launch_mode = strdup(data->launch_mode);
1126         if (data->package_type != NULL)
1127                 app_info->package_type = strdup(data->package_type);
1128         if (data->effective_appid != NULL)
1129                 app_info->effective_appid = strdup(data->effective_appid);
1130         if (data->splash_screen_display != NULL)
1131                 app_info->splash_screen_display = strdup(data->splash_screen_display);
1132
1133         /* GList */
1134         ret = 0;
1135         app_info->label = g_list_copy_deep(data->label, __copy_label, &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->icon = g_list_copy_deep(data->icon, __copy_icon, &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->category = g_list_copy_deep(data->category, __copy_str, &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->metadata = g_list_copy_deep(data->metadata, __copy_metadata, &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->datacontrol = g_list_copy_deep(data->datacontrol, __copy_datacontrol, &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->appcontrol = g_list_copy_deep(data->appcontrol, __copy_appcontrol, &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->background_category = g_list_copy_deep(data->background_category, __copy_str, &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         ret = 0;
1191         app_info->splashscreens = g_list_copy_deep(data->splashscreens, __copy_splashscreens, &ret);
1192         if (ret < 0) {
1193                 LOGE("memory alloc failed");
1194                 pkgmgrinfo_basic_free_application(app_info);
1195                 return PMINFO_R_ERROR;
1196         }
1197
1198         *application = app_info;
1199
1200         return PMINFO_R_OK;
1201 }
1202
1203 API int pkgmgrinfo_appinfo_clone_appinfo(pkgmgrinfo_appinfo_h handle,
1204                 pkgmgrinfo_appinfo_h *clone)
1205 {
1206         pkgmgr_appinfo_x *info;
1207         pkgmgr_appinfo_x *temp = (pkgmgr_appinfo_x *)handle;
1208
1209         if (handle == NULL)
1210                 return PMINFO_R_EINVAL;
1211
1212         info = calloc(1, sizeof(pkgmgr_appinfo_x));
1213         if (info == NULL) {
1214                 LOGE("memory alloc failed");
1215                 return PMINFO_R_ERROR;
1216         }
1217
1218         if (temp->package != NULL)
1219                 info->package = strdup(temp->package);
1220         if (temp->locale != NULL)
1221                 info->locale = strdup(temp->locale);
1222
1223         info->app_component = temp->app_component;
1224
1225         if (_appinfo_copy_appinfo(&info->app_info, temp->app_info) < 0) {
1226                 LOGE("appinfo copy failed");
1227                 if (info->package)
1228                         free((void *)info->package);
1229                 if (info->locale)
1230                         free(info->locale);
1231                 free(info);
1232                 return PMINFO_R_ERROR;
1233         }
1234
1235         *clone = info;
1236
1237         return PMINFO_R_OK;
1238 }
1239
1240 static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
1241                 pkgmgrinfo_filter_x *filter, int flag, pkgmgrinfo_app_list_cb app_list_cb,
1242                 void *user_data)
1243 {
1244         int ret;
1245         char *locale;
1246         application_x *app;
1247         pkgmgr_appinfo_x info;
1248         GHashTable *list;
1249         GHashTableIter iter;
1250         gpointer value;
1251
1252         locale = _get_system_locale();
1253         if (locale == NULL)
1254                 return PMINFO_R_ERROR;
1255
1256         list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
1257                         __free_applications);
1258         if (list == NULL) {
1259                 free(locale);
1260                 return PMINFO_R_ERROR;
1261         }
1262
1263         ret = _appinfo_get_applications(uid, uid, locale, filter,
1264                         flag | PMINFO_APPINFO_GET_BASICINFO, list);
1265         if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
1266                 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
1267                                 filter, flag | PMINFO_APPINFO_GET_BASICINFO, list);
1268
1269         if (ret != PMINFO_R_OK) {
1270                 g_hash_table_destroy(list);
1271                 free(locale);
1272                 return ret;
1273         }
1274
1275         g_hash_table_iter_init(&iter, list);
1276         while (g_hash_table_iter_next(&iter, NULL, &value)) {
1277                 app = (application_x *)value;
1278                 info.app_info = app;
1279                 info.locale = locale;
1280                 info.package = app->package;
1281                 if (app_list_cb(&info, user_data) < 0)
1282                         break;
1283         }
1284         g_hash_table_destroy(list);
1285         free(locale);
1286
1287         return PMINFO_R_OK;
1288 }
1289
1290 static const char *__appcomponent_str(pkgmgrinfo_app_component comp);
1291
1292 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle,
1293                 pkgmgrinfo_app_component component,
1294                 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
1295 {
1296         int ret;
1297         pkgmgrinfo_appinfo_filter_h filter;
1298         char *pkgid;
1299         const char *comp_str = NULL;
1300
1301         if (handle == NULL || app_func == NULL) {
1302                 LOGE("invalid parameter");
1303                 return PMINFO_R_EINVAL;
1304         }
1305
1306         if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid)) {
1307                 LOGE("invalid parameter");
1308                 return PMINFO_R_EINVAL;
1309         }
1310
1311         if (pkgmgrinfo_appinfo_filter_create(&filter))
1312                 return PMINFO_R_ERROR;
1313
1314         if (pkgmgrinfo_appinfo_filter_add_string(filter,
1315                                 PMINFO_APPINFO_PROP_APP_PACKAGE, pkgid)) {
1316                 pkgmgrinfo_appinfo_filter_destroy(filter);
1317                 return PMINFO_R_ERROR;
1318         }
1319
1320         if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1321                         PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1322                 pkgmgrinfo_appinfo_filter_destroy(filter);
1323                 return PMINFO_R_ERROR;
1324         }
1325
1326         comp_str = __appcomponent_str(component);
1327
1328         if (comp_str) {
1329                 if (pkgmgrinfo_appinfo_filter_add_string(filter,
1330                                         PMINFO_APPINFO_PROP_APP_COMPONENT,
1331                                         comp_str)) {
1332                         pkgmgrinfo_appinfo_filter_destroy(filter);
1333                         return PMINFO_R_ERROR;
1334                 }
1335         }
1336
1337         ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1338                         PMINFO_APPINFO_GET_ALL, app_func, user_data);
1339
1340         pkgmgrinfo_appinfo_filter_destroy(filter);
1341
1342         return ret;
1343 }
1344
1345 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle,
1346                 pkgmgrinfo_app_component component,
1347                 pkgmgrinfo_app_list_cb app_func, void *user_data)
1348 {
1349         return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, _getuid());
1350 }
1351
1352 API int pkgmgrinfo_appinfo_get_usr_installed_list_full(
1353                 pkgmgrinfo_app_list_cb app_func, uid_t uid, int flag,
1354                 void *user_data)
1355 {
1356         int ret;
1357         pkgmgrinfo_appinfo_filter_h filter;
1358
1359         if (app_func == NULL) {
1360                 LOGE("invalid parameter");
1361                 return PMINFO_R_EINVAL;
1362         }
1363
1364         if (pkgmgrinfo_appinfo_filter_create(&filter))
1365                 return PMINFO_R_ERROR;
1366
1367         if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1368                         PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1369                 pkgmgrinfo_appinfo_filter_destroy(filter);
1370                 return PMINFO_R_ERROR;
1371         }
1372
1373         if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1374                         PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
1375                 pkgmgrinfo_appinfo_filter_destroy(filter);
1376                 return PMINFO_R_ERROR;
1377         }
1378
1379         if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1380                         PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, false)) {
1381                 pkgmgrinfo_appinfo_filter_destroy(filter);
1382                 return PMINFO_R_ERROR;
1383         }
1384
1385         ret = _appinfo_get_filtered_foreach_appinfo(uid, filter, flag, app_func,
1386                         user_data);
1387
1388         pkgmgrinfo_appinfo_filter_destroy(filter);
1389
1390         return ret;
1391 }
1392
1393 API int pkgmgrinfo_appinfo_get_installed_list_full(
1394                 pkgmgrinfo_app_list_cb app_func, int flag, void *user_data)
1395 {
1396         return pkgmgrinfo_appinfo_get_usr_installed_list_full(app_func,
1397                         _getuid(), flag, user_data);
1398 }
1399
1400 API int pkgmgrinfo_appinfo_get_usr_installed_list(
1401                 pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
1402 {
1403         int ret;
1404         pkgmgrinfo_appinfo_filter_h filter;
1405
1406         if (app_func == NULL) {
1407                 LOGE("invalid parameter");
1408                 return PMINFO_R_EINVAL;
1409         }
1410
1411         /* create an empty filter */
1412         ret = pkgmgrinfo_appinfo_filter_create(&filter);
1413         if (ret != PMINFO_R_OK)
1414                 return ret;
1415
1416         if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1417                         PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
1418                 pkgmgrinfo_appinfo_filter_destroy(filter);
1419                 return PMINFO_R_ERROR;
1420         }
1421
1422         if (pkgmgrinfo_appinfo_filter_add_bool(filter,
1423                         PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
1424                 pkgmgrinfo_appinfo_filter_destroy(filter);
1425                 return PMINFO_R_ERROR;
1426         }
1427
1428         ret = _appinfo_get_filtered_foreach_appinfo(uid, filter,
1429                         PMINFO_APPINFO_GET_ALL, app_func, user_data);
1430
1431         pkgmgrinfo_appinfo_filter_destroy(filter);
1432
1433         return ret;
1434 }
1435
1436 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func,
1437                 void *user_data)
1438 {
1439         return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, _getuid(),
1440                         user_data);
1441 }
1442
1443 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
1444 {
1445         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1446
1447         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1448         retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1449
1450         if (info->app_info == NULL || info->app_info->appid == NULL)
1451                 return PMINFO_R_ERROR;
1452         *appid = (char *)info->app_info->appid;
1453
1454         return PMINFO_R_OK;
1455 }
1456
1457 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
1458 {
1459         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1460
1461         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1462         retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1463
1464         if (info->package == NULL)
1465                 return PMINFO_R_ERROR;
1466
1467         *pkg_name = (char *)info->package;
1468
1469         return PMINFO_R_OK;
1470 }
1471
1472 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
1473 {
1474         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1475
1476         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1477         retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1478
1479         if (info->package == NULL)
1480                 return PMINFO_R_ERROR;
1481
1482         *pkgid = (char *)info->package;
1483
1484         return PMINFO_R_OK;
1485 }
1486
1487 API int pkgmgrinfo_appinfo_get_pkgtype(pkgmgrinfo_appinfo_h  handle, char **pkgtype)
1488 {
1489         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1490         retvm_if(pkgtype == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1491         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1492
1493         *pkgtype = (char *)info->app_info->package_type;
1494
1495         return PMINFO_R_OK;
1496 }
1497
1498 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
1499 {
1500         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1501
1502         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1503         retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1504
1505         if (info->app_info == NULL || info->app_info->exec == NULL)
1506                 return PMINFO_R_ERROR;
1507         *exec = (char *)info->app_info->exec;
1508
1509         return PMINFO_R_OK;
1510 }
1511
1512
1513 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1514 {
1515         icon_x *ptr;
1516         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1517
1518         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1519         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1520
1521         if (info->app_info == NULL)
1522                 return PMINFO_R_ERROR;
1523
1524         if (info->app_info->icon == NULL) {
1525                 *icon = "";
1526                 return PMINFO_R_OK;
1527         }
1528
1529         ptr = (icon_x *)info->app_info->icon->data;
1530         if (ptr == NULL)
1531                 return PMINFO_R_ERROR;
1532
1533         if (ptr->text == NULL)
1534                 return PMINFO_R_ERROR;
1535                 else
1536                         *icon = ptr->text;
1537
1538         return PMINFO_R_OK;
1539 }
1540
1541
1542 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
1543 {
1544         label_x *ptr;
1545         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1546         char *lbl = NULL;
1547         const char *locale;
1548         GList *tmp;
1549
1550         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1551         retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1552
1553         if (info->app_info == NULL)
1554                 return PMINFO_R_ERROR;
1555
1556         locale = info->locale;
1557         if (locale == NULL)
1558                 locale = DEFAULT_LOCALE;
1559
1560         for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1561                 ptr = (label_x *)tmp->data;
1562                 if (ptr == NULL || strcmp(locale, ptr->lang) != 0)
1563                         continue;
1564                 lbl = ptr->text;
1565                 break;
1566         }
1567
1568         if (lbl != NULL) {
1569                 *label = lbl;
1570                 return PMINFO_R_OK;
1571         }
1572
1573         for (tmp = info->app_info->label; tmp; tmp = tmp->next) {
1574                 ptr = (label_x *)tmp->data;
1575                 if (ptr == NULL || strcmp(DEFAULT_LOCALE, ptr->lang) != 0)
1576                         continue;
1577                 lbl = ptr->text;
1578                 break;
1579         }
1580
1581         *label = lbl ? lbl : "";
1582
1583         return PMINFO_R_OK;
1584 }
1585
1586 static char *_get_localed_label(const char *appid, const char *locale, uid_t uid)
1587 {
1588         char *result = NULL;
1589         char *query = NULL;
1590         sqlite3_stmt *stmt = NULL;
1591         sqlite3 *db = NULL;
1592         char *val;
1593         char *parser_db;
1594
1595         parser_db = getUserPkgParserDBPathUID(uid);
1596         if (parser_db == NULL) {
1597                 _LOGE("Failed to get parser db path");
1598                 goto err;
1599         }
1600
1601         if (__open_db(parser_db, &db, SQLITE_OPEN_READONLY) != SQLITE_OK) {
1602                 _LOGE("DB open fail\n");
1603                 free(parser_db);
1604                 goto err;
1605         }
1606         free(parser_db);
1607
1608         query = sqlite3_mprintf("select app_label from package_app_localized_info where app_id=%Q and app_locale=%Q", appid, locale);
1609         if (query == NULL) {
1610                 _LOGE("Out of memory");
1611                 goto err;
1612         }
1613
1614         if (sqlite3_prepare_v2(db, query, -1, &stmt, NULL) != SQLITE_OK) {
1615                 _LOGE("prepare_v2 fail\n");
1616                 goto err;
1617         }
1618
1619         if (sqlite3_step(stmt) == SQLITE_ROW) {
1620                 val = (char *)sqlite3_column_text(stmt, 0);
1621                 if (val != NULL)
1622                         result = strdup(val);
1623         }
1624
1625 err:
1626         sqlite3_finalize(stmt);
1627         sqlite3_free(query);
1628         sqlite3_close(db);
1629
1630         return result;
1631 }
1632
1633 API int pkgmgrinfo_appinfo_usr_get_localed_label(const char *appid, const char *locale, uid_t uid, char **label)
1634 {
1635         char *val;
1636
1637         retvm_if(appid == NULL || locale == NULL || label == NULL, PMINFO_R_EINVAL, "Argument is NULL");
1638
1639         val = _get_localed_label(appid, locale, uid);
1640         if (val == NULL)
1641                 val = _get_localed_label(appid, DEFAULT_LOCALE, uid);
1642
1643         if (val == NULL) {
1644                 val = _get_localed_label(appid, locale, GLOBAL_USER);
1645                 if (val == NULL)
1646                         val = _get_localed_label(appid, DEFAULT_LOCALE, GLOBAL_USER);
1647         }
1648
1649         if (val == NULL)
1650                 return PMINFO_R_ERROR;
1651
1652         *label = val;
1653
1654         return PMINFO_R_OK;
1655 }
1656
1657 API int pkgmgrinfo_appinfo_get_localed_label(const char *appid, const char *locale, char **label)
1658 {
1659         return pkgmgrinfo_appinfo_usr_get_localed_label(appid, locale, _getuid(), label);
1660 }
1661
1662 API int pkgmgrinfo_appinfo_get_metadata_value(pkgmgrinfo_appinfo_h handle, const char *metadata_key, char **metadata_value)
1663 {
1664         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1665         retvm_if(metadata_key == NULL, PMINFO_R_EINVAL, "metadata_key is NULL");
1666         retvm_if(metadata_value == NULL, PMINFO_R_EINVAL, "metadata_value is NULL");
1667
1668         GList *list_md = NULL;
1669         metadata_x *metadata = NULL;
1670         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1671
1672         list_md = info->app_info->metadata;
1673
1674         for (; list_md; list_md = list_md->next) {
1675                 metadata = (metadata_x *)list_md->data;
1676                 if (metadata && metadata->key) {
1677                         if (strcasecmp(metadata->key, metadata_key) == 0) {
1678                                 if (metadata->value == NULL)
1679                                         *metadata_value = "";
1680                                 else
1681                                         *metadata_value = (char *)metadata->value;
1682                                 return PMINFO_R_OK;
1683                         }
1684                 }
1685         }
1686
1687         return PMINFO_R_EINVAL;
1688 }
1689
1690 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1691 {
1692         if (strcasecmp(comp, "uiapp") == 0)
1693                 return PMINFO_UI_APP;
1694         else if (strcasecmp(comp, "svcapp") == 0)
1695                 return PMINFO_SVC_APP;
1696         else if (strcasecmp(comp, "widgetapp") == 0)
1697                 return PMINFO_WIDGET_APP;
1698         else if (strcasecmp(comp, "watchapp") == 0)
1699                 return PMINFO_WATCH_APP;
1700         else
1701                 return -1;
1702 }
1703
1704 static const char *__appcomponent_str(pkgmgrinfo_app_component comp)
1705 {
1706         switch (comp) {
1707         case PMINFO_UI_APP:
1708                 return "uiapp";
1709         case PMINFO_SVC_APP:
1710                 return "svcapp";
1711         case PMINFO_WIDGET_APP:
1712                 return "widgetapp";
1713         case PMINFO_WATCH_APP:
1714                 return "watchapp";
1715         default:
1716                 return NULL;
1717         }
1718 }
1719
1720 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
1721 {
1722         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1723         int comp;
1724
1725         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1726         retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1727
1728         if (info->app_info == NULL)
1729                 return PMINFO_R_ERROR;
1730
1731         comp = __appcomponent_convert(info->app_info->component);
1732         if (comp < 0)
1733                 return PMINFO_R_ERROR;
1734
1735         *component = comp;
1736
1737         return PMINFO_R_OK;
1738 }
1739
1740 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
1741 {
1742         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1743
1744         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1745         retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1746
1747         if (info->app_info == NULL || info->app_info->type == NULL)
1748                 return PMINFO_R_ERROR;
1749         *app_type = (char *)info->app_info->type;
1750
1751         return PMINFO_R_OK;
1752 }
1753
1754 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h  handle,
1755                                         int *operation_count, char ***operation)
1756 {
1757         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1758         retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1759         retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1760         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1761         *operation_count = data->operation_count;
1762         *operation = data->operation;
1763         return PMINFO_R_OK;
1764 }
1765
1766 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h  handle,
1767                                         int *uri_count, char ***uri)
1768 {
1769         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1770         retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1771         retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1772         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1773         *uri_count = data->uri_count;
1774         *uri = data->uri;
1775         return PMINFO_R_OK;
1776 }
1777
1778 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h  handle,
1779                                         int *mime_count, char ***mime)
1780 {
1781         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1782         retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1783         retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1784         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1785         *mime_count = data->mime_count;
1786         *mime = data->mime;
1787         return PMINFO_R_OK;
1788 }
1789
1790 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h  handle,
1791                                         int *subapp_count, char ***subapp)
1792 {
1793         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1794         retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1795         retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1796         pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
1797         *subapp_count = data->subapp_count;
1798         *subapp = data->subapp;
1799         return PMINFO_R_OK;
1800 }
1801
1802 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
1803 {
1804         char *val;
1805         icon_x *ptr;
1806         GList *tmp;
1807         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1808
1809         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1810         retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1811
1812         if (info->app_info == NULL)
1813                 return PMINFO_R_ERROR;
1814
1815         for (tmp = info->app_info->icon; tmp; tmp = tmp->next) {
1816                 ptr = (icon_x *)tmp->data;
1817                 if (ptr == NULL || ptr->section == NULL)
1818                         continue;
1819
1820                 val = (char *)ptr->section;
1821                 if (val && strcmp(val, "notification") == 0) {
1822                         *icon = (char *)ptr->text;
1823                         return PMINFO_R_OK;
1824                 }
1825         }
1826
1827         return PMINFO_R_ERROR;
1828 }
1829
1830 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
1831 {
1832         char *val;
1833         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1834
1835         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1836         retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1837
1838         if (info->app_info == NULL || info->app_info->recentimage == NULL)
1839                 return PMINFO_R_ERROR;
1840
1841         val = (char *)info->app_info->recentimage;
1842         if (strcasecmp(val, "capture") == 0)
1843                 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
1844         else if (strcasecmp(val, "icon") == 0)
1845                 *type = PMINFO_RECENTIMAGE_USE_ICON;
1846         else
1847                 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
1848
1849         return PMINFO_R_OK;
1850 }
1851
1852 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
1853 {
1854         char *val;
1855         image_x *ptr;
1856         GList *tmp;
1857         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1858
1859         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1860         retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1861
1862         if (info->app_info == NULL)
1863                 return PMINFO_R_ERROR;
1864
1865         for (tmp = info->app_info->image; tmp; tmp = tmp->next) {
1866                 ptr = (image_x *)tmp->data;
1867                 if (ptr == NULL || ptr->section == NULL)
1868                         continue;
1869
1870                 val = (char *)ptr->section;
1871                 if (val && strcmp(val, "preview") == 0) {
1872                         *preview_img = (char *)ptr->text;
1873                         return PMINFO_R_OK;
1874                 }
1875         }
1876
1877         return PMINFO_R_ERROR;
1878 }
1879
1880 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
1881 {
1882         const char *val;
1883         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1884
1885         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
1886         retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1887
1888         val = info->app_info->permission_type;
1889         if (val == NULL)
1890                 return PMINFO_R_ERROR;
1891
1892         if (strcmp(val, "signature") == 0)
1893                 *permission = PMINFO_PERMISSION_SIGNATURE;
1894         else if (strcmp(val, "privilege") == 0)
1895                 *permission = PMINFO_PERMISSION_PRIVILEGE;
1896         else
1897                 *permission = PMINFO_PERMISSION_NORMAL;
1898
1899         return PMINFO_R_OK;
1900 }
1901
1902 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
1903 {
1904         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1905
1906         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1907         retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1908
1909         if (info->app_info == NULL || info->app_info->component_type == NULL)
1910                 return PMINFO_R_ERROR;
1911
1912         *component_type = (char *)info->app_info->component_type;
1913
1914         return PMINFO_R_OK;
1915 }
1916
1917 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
1918 {
1919         char *val;
1920         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1921
1922         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1923         retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1924
1925         if (info->app_info == NULL || info->app_info->hwacceleration == NULL)
1926                 return PMINFO_R_ERROR;
1927
1928         val = (char *)info->app_info->hwacceleration;
1929         if (strcasecmp(val, "off") == 0)
1930                 *hwacceleration = PMINFO_HWACCELERATION_OFF;
1931         else if (strcasecmp(val, "on") == 0)
1932                 *hwacceleration = PMINFO_HWACCELERATION_ON;
1933         else
1934                 *hwacceleration = PMINFO_HWACCELERATION_DEFAULT;
1935
1936         return PMINFO_R_OK;
1937 }
1938
1939 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
1940 {
1941         char *val;
1942         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1943
1944         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1945         retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1946
1947         if (info->app_info == NULL || info->app_info->screenreader == NULL)
1948                 return PMINFO_R_ERROR;
1949
1950         val = (char *)info->app_info->screenreader;
1951         if (strcasecmp(val, "screenreader-off") == 0)
1952                 *screenreader = PMINFO_SCREENREADER_OFF;
1953         else if (strcasecmp(val, "screenreader-on") == 0)
1954                 *screenreader = PMINFO_SCREENREADER_ON;
1955         else
1956                 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
1957
1958         return PMINFO_R_OK;
1959 }
1960
1961 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
1962 {
1963         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1964
1965         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
1966         retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1967         retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1968
1969         if (info->app_info == NULL)
1970                 return PMINFO_R_ERROR;
1971
1972         if (info->app_info->portraitimg == NULL)
1973                 *portrait_img = "";
1974         else
1975                 *portrait_img = (char *)info->app_info->portraitimg;
1976
1977         if (info->app_info->landscapeimg == NULL)
1978                 *landscape_img = "";
1979         else
1980                 *landscape_img = (char *)info->app_info->landscapeimg;
1981
1982         return PMINFO_R_OK;
1983 }
1984
1985 API int pkgmgrinfo_appinfo_get_effectimage_type(pkgmgrinfo_appinfo_h handle, char **effectimage_type)
1986 {
1987         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
1988
1989         if (handle == NULL || effectimage_type == NULL) {
1990                 LOGE("invalid parameter");
1991                 return PMINFO_R_EINVAL;
1992         }
1993
1994         if (info->app_info == NULL || info->app_info->effectimage_type == NULL)
1995                 return PMINFO_R_ERROR;
1996
1997         *effectimage_type = (char *)info->app_info->effectimage_type;
1998
1999         return PMINFO_R_OK;
2000 }
2001
2002 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h  handle, char **submode_mainid)
2003 {
2004         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2005
2006         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2007         retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2008
2009         if (info->app_info == NULL)
2010                 return PMINFO_R_ERROR;
2011
2012         if (info->app_info->submode_mainid == NULL)
2013                 *submode_mainid = "";
2014         else
2015                 *submode_mainid = (char *)info->app_info->submode_mainid;
2016
2017         return PMINFO_R_OK;
2018 }
2019
2020 API int pkgmgrinfo_appinfo_get_installed_storage_location(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_installed_storage *storage)
2021 {
2022         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2023         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2024
2025         if (info->app_info && info->app_info->installed_storage) {
2026                  if (strcmp(info->app_info->installed_storage, "installed_internal") == 0)
2027                         *storage = PMINFO_INTERNAL_STORAGE;
2028                  else if (strcmp(info->app_info->installed_storage, "installed_external") == 0)
2029                          *storage = PMINFO_EXTERNAL_STORAGE;
2030                  else
2031                          return PMINFO_R_ERROR;
2032         } else {
2033                 return PMINFO_R_ERROR;
2034         }
2035
2036         return PMINFO_R_OK;
2037 }
2038
2039 API int pkgmgrinfo_appinfo_get_launch_mode(pkgmgrinfo_appinfo_h handle, char **mode)
2040 {
2041         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2042
2043         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2044         retvm_if(mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2045
2046         if (info->app_info->launch_mode == NULL)
2047                 return PMINFO_R_ERROR;
2048
2049         *mode = (char *)(info->app_info->launch_mode);
2050
2051         return PMINFO_R_OK;
2052 }
2053
2054 API int pkgmgrinfo_appinfo_get_alias_appid(pkgmgrinfo_appinfo_h handle, char **alias_appid)
2055 {
2056         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2057
2058         if (handle == NULL || alias_appid == NULL) {
2059                 LOGE("invalid parameter");
2060                 return PMINFO_R_EINVAL;
2061         }
2062
2063         if (info->app_info == NULL || info->app_info->alias_appid == NULL)
2064                 return PMINFO_R_ERROR;
2065
2066         *alias_appid = (char *)info->app_info->alias_appid;
2067
2068         return PMINFO_R_OK;
2069 }
2070
2071 API int pkgmgrinfo_appinfo_get_effective_appid(pkgmgrinfo_appinfo_h handle, char **effective_appid)
2072 {
2073         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2074
2075         if (handle == NULL || effective_appid == NULL) {
2076                 LOGE("invalid parameter");
2077                 return PMINFO_R_EINVAL;
2078         }
2079
2080         if (info->app_info == NULL)
2081                 return PMINFO_R_ERROR;
2082
2083         if (info->app_info->effective_appid == NULL)
2084                 *effective_appid = "";
2085         else
2086                 *effective_appid = (char *)info->app_info->effective_appid;
2087
2088         return PMINFO_R_OK;
2089 }
2090
2091 API int pkgmgrinfo_appinfo_get_tep_name(pkgmgrinfo_appinfo_h handle, char **tep_name)
2092 {
2093         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2094
2095         if (handle == NULL || tep_name == NULL) {
2096                 LOGE("invalid parameter");
2097                 return PMINFO_R_EINVAL;
2098         }
2099
2100         if (info->app_info == NULL)
2101                 return PMINFO_R_ERROR;
2102
2103         if (info->app_info->tep_name == NULL)
2104                 *tep_name = "";
2105         else
2106                 *tep_name = (char *)info->app_info->tep_name;
2107
2108         return PMINFO_R_OK;
2109 }
2110
2111 API int pkgmgrinfo_appinfo_get_zip_mount_file(pkgmgrinfo_appinfo_h handle, char **zip_mount_file)
2112 {
2113         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2114
2115         if (handle == NULL || zip_mount_file == NULL) {
2116                 LOGE("invalid parameter");
2117                 return PMINFO_R_EINVAL;
2118         }
2119
2120         if (info->app_info == NULL)
2121                 return PMINFO_R_ERROR;
2122
2123         if (info->app_info->zip_mount_file == NULL)
2124                 *zip_mount_file = "";
2125         else
2126                 *zip_mount_file = (char *)info->app_info->zip_mount_file;
2127
2128         return PMINFO_R_OK;
2129 }
2130
2131 API int pkgmgrinfo_appinfo_get_root_path(pkgmgrinfo_appinfo_h handle, char **root_path)
2132 {
2133         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2134
2135         if (handle == NULL || root_path == NULL) {
2136                 LOGE("invalid parameter");
2137                 return PMINFO_R_EINVAL;
2138         }
2139
2140         if (info->app_info == NULL || info->app_info->root_path == NULL)
2141                 return PMINFO_R_ERROR;
2142
2143         *root_path = (char *)info->app_info->root_path;
2144
2145         return PMINFO_R_OK;
2146 }
2147
2148 API int pkgmgrinfo_appinfo_get_api_version(pkgmgrinfo_appinfo_h handle, char **api_version)
2149 {
2150         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2151
2152         if (handle == NULL || api_version == NULL) {
2153                 LOGE("invalid parameter");
2154                 return PMINFO_R_EINVAL;
2155         }
2156
2157         if (info->app_info == NULL || info->app_info->api_version == NULL)
2158                 return PMINFO_R_ERROR;
2159
2160         *api_version = (char *)info->app_info->api_version;
2161
2162         return PMINFO_R_OK;
2163 }
2164
2165 API int pkgmgrinfo_appinfo_get_installed_time(pkgmgrinfo_appinfo_h handle, int *installed_time)
2166 {
2167         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2168
2169         if (handle == NULL || installed_time == NULL) {
2170                 LOGE("invalid parameter");
2171                 return PMINFO_R_EINVAL;
2172         }
2173
2174         if (info->app_info == NULL || info->app_info->package_installed_time == NULL)
2175                 return PMINFO_R_ERROR;
2176
2177         *installed_time = atoi(info->app_info->package_installed_time);
2178
2179         return PMINFO_R_OK;
2180 }
2181
2182 static int _appinfo_get_datacontrol_info(sqlite3 *db, const char *providerid,
2183                 const char *type, char **appid, char **access)
2184 {
2185         static const char query[] =
2186                 "SELECT app_id, access FROM package_app_data_control "
2187                 "WHERE providerid=? AND type=?";
2188         int ret;
2189         sqlite3_stmt *stmt;
2190
2191         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2192         if (ret != SQLITE_OK) {
2193                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2194                 return PMINFO_R_ERROR;
2195         }
2196
2197         ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2198         if (ret != SQLITE_OK) {
2199                 LOGE("bind failed: %s", sqlite3_errmsg(db));
2200                 sqlite3_finalize(stmt);
2201                 return PMINFO_R_ERROR;
2202         }
2203
2204         ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2205         if (ret != SQLITE_OK) {
2206                 LOGE("bind failed: %s", sqlite3_errmsg(db));
2207                 sqlite3_finalize(stmt);
2208                 return PMINFO_R_ERROR;
2209         }
2210
2211         ret = sqlite3_step(stmt);
2212         if (ret != SQLITE_ROW) {
2213                 sqlite3_finalize(stmt);
2214                 if (ret == SQLITE_DONE) {
2215                         return PMINFO_R_ENOENT;
2216                 } else {
2217                         LOGE("step error: %s", sqlite3_errmsg(db));
2218                         return PMINFO_R_ERROR;
2219                 }
2220         }
2221
2222         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2223         if (*appid == NULL) {
2224                 LOGE("out of memory");
2225                 sqlite3_finalize(stmt);
2226                 return PMINFO_R_ERROR;
2227         }
2228         *access = strdup((char *)sqlite3_column_text(stmt, 1));
2229         if (*access == NULL) {
2230                 LOGE("out of memory");
2231                 free(*appid);
2232                 sqlite3_finalize(stmt);
2233                 return PMINFO_R_ERROR;
2234         }
2235
2236         sqlite3_finalize(stmt);
2237
2238         return PMINFO_R_OK;
2239 }
2240
2241 static int _pkgmgrinfo_appinfo_get_datacontrol_info(uid_t uid,
2242                 const char *providerid, const char *type,
2243                 char **appid, char **access)
2244 {
2245         int ret;
2246         char *dbpath;
2247         sqlite3 *db;
2248
2249         dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2250         if (dbpath == NULL)
2251                 return PMINFO_R_ERROR;
2252
2253         ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2254         free(dbpath);
2255         if (ret != SQLITE_OK) {
2256                 LOGE("open db failed: %s", sqlite3_errmsg(db));
2257                 return PMINFO_R_ERROR;
2258         }
2259
2260         ret = _appinfo_get_datacontrol_info(db, providerid, type, appid,
2261                         access);
2262         sqlite3_close_v2(db);
2263
2264         return ret;
2265 }
2266
2267 API int pkgmgrinfo_appinfo_usr_get_datacontrol_info(const char *providerid,
2268                 const char *type, uid_t uid, char **appid, char **access)
2269 {
2270         int ret;
2271
2272         if (providerid == NULL || type == NULL || appid == NULL ||
2273                         access == NULL) {
2274                 LOGE("invalid parameter");
2275                 return PMINFO_R_EINVAL;
2276         }
2277
2278         ret = _pkgmgrinfo_appinfo_get_datacontrol_info(GLOBAL_USER, providerid,
2279                         type, appid, access);
2280         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2281                 ret = _pkgmgrinfo_appinfo_get_datacontrol_info(uid, providerid,
2282                                 type, appid, access);
2283
2284         /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2285          * implementation, return PMINFO_R_ERROR. This should be
2286          * modified later...
2287          */
2288         if (ret == PMINFO_R_ENOENT) {
2289                 LOGE("no datacontrol info of %s", providerid);
2290                 ret = PMINFO_R_ERROR;
2291         }
2292
2293         return ret;
2294 }
2295
2296 API int pkgmgrinfo_appinfo_get_datacontrol_info(const char *providerid,
2297                 const char *type, char **appid, char **access)
2298 {
2299         return pkgmgrinfo_appinfo_usr_get_datacontrol_info(providerid,
2300                         type, _getuid(), appid, access);
2301 }
2302
2303 static int _appinfo_get_datacontrol_appid(sqlite3 *db, const char *providerid,
2304                 char **appid)
2305 {
2306         static const char query[] =
2307                 "SELECT app_id FROM package_app_data_control "
2308                 "WHERE providerid=?";
2309         int ret;
2310         sqlite3_stmt *stmt;
2311
2312         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2313         if (ret != SQLITE_OK) {
2314                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2315                 return PMINFO_R_ERROR;
2316         }
2317
2318         ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2319         if (ret != SQLITE_OK) {
2320                 LOGE("bind failed: %s", sqlite3_errmsg(db));
2321                 sqlite3_finalize(stmt);
2322                 return PMINFO_R_ERROR;
2323         }
2324
2325         ret = sqlite3_step(stmt);
2326         if (ret != SQLITE_ROW) {
2327                 sqlite3_finalize(stmt);
2328                 if (ret == SQLITE_DONE) {
2329                         return PMINFO_R_ENOENT;
2330                 } else {
2331                         LOGE("step error: %s", sqlite3_errmsg(db));
2332                         return PMINFO_R_ERROR;
2333                 }
2334         }
2335
2336         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2337
2338         sqlite3_finalize(stmt);
2339
2340         if (*appid == NULL) {
2341                 LOGE("out of memory");
2342                 return PMINFO_R_ERROR;
2343         }
2344
2345         return PMINFO_R_OK;
2346 }
2347
2348 static int _pkgmgrinfo_appinfo_get_datacontrol_appid(uid_t uid,
2349                 const char *providerid, char **appid)
2350 {
2351         int ret;
2352         char *dbpath;
2353         sqlite3 *db;
2354
2355         dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2356         if (dbpath == NULL)
2357                 return PMINFO_R_ERROR;
2358
2359         ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2360         free(dbpath);
2361         if (ret != SQLITE_OK) {
2362                 LOGE("open db failed: %s", sqlite3_errmsg(db));
2363                 return PMINFO_R_ERROR;
2364         }
2365
2366         ret = _appinfo_get_datacontrol_appid(db, providerid, appid);
2367         sqlite3_close_v2(db);
2368
2369         return ret;
2370 }
2371
2372 API int pkgmgrinfo_appinfo_usr_get_datacontrol_appid(const char *providerid,
2373                 uid_t uid, char **appid)
2374 {
2375         int ret;
2376
2377         if (providerid == NULL || appid == NULL) {
2378                 LOGE("invalid parameter");
2379                 return PMINFO_R_EINVAL;
2380         }
2381
2382         ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(GLOBAL_USER, providerid,
2383                         appid);
2384         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2385                 ret = _pkgmgrinfo_appinfo_get_datacontrol_appid(uid, providerid,
2386                                 appid);
2387
2388         /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2389          * implementation, return PMINFO_R_ERROR. This should be
2390          * modified later...
2391          */
2392         if (ret == PMINFO_R_ENOENT) {
2393                 LOGE("no datacontrol appid of %s", providerid);
2394                 ret = PMINFO_R_ERROR;
2395         }
2396
2397         return ret;
2398 }
2399
2400 API int pkgmgrinfo_appinfo_get_datacontrol_appid(const char *providerid, char **appid)
2401 {
2402         return pkgmgrinfo_appinfo_usr_get_datacontrol_appid(providerid, _getuid(), appid);
2403 }
2404
2405 static int _appinfo_get_datacontrol_trusted_info(sqlite3 *db,
2406                 const char *providerid, const char *type, char **appid,
2407                 bool *is_trusted)
2408 {
2409         static const char query[] =
2410                 "SELECT app_id, trusted FROM package_app_data_control "
2411                 "WHERE providerid=? AND type=?";
2412         int ret;
2413         sqlite3_stmt *stmt;
2414
2415         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2416         if (ret != SQLITE_OK) {
2417                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2418                 return PMINFO_R_ERROR;
2419         }
2420
2421         ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2422         if (ret != SQLITE_OK) {
2423                 LOGE("bind failed: %s", sqlite3_errmsg(db));
2424                 sqlite3_finalize(stmt);
2425                 return PMINFO_R_ERROR;
2426         }
2427
2428         ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2429         if (ret != SQLITE_OK) {
2430                 LOGE("bind failed: %s", sqlite3_errmsg(db));
2431                 sqlite3_finalize(stmt);
2432                 return PMINFO_R_ERROR;
2433         }
2434
2435         ret = sqlite3_step(stmt);
2436         if (ret != SQLITE_ROW) {
2437                 sqlite3_finalize(stmt);
2438                 if (ret == SQLITE_DONE) {
2439                         return PMINFO_R_ENOENT;
2440                 } else {
2441                         LOGE("step error: %s", sqlite3_errmsg(db));
2442                         return PMINFO_R_ERROR;
2443                 }
2444         }
2445
2446         *appid = strdup((char *)sqlite3_column_text(stmt, 0));
2447         *is_trusted = _get_bool_value((char *)sqlite3_column_text(stmt, 1));
2448
2449         sqlite3_finalize(stmt);
2450
2451         if (*appid == NULL) {
2452                 LOGE("out of memory");
2453                 return PMINFO_R_ERROR;
2454         }
2455
2456         return PMINFO_R_OK;
2457 }
2458
2459 static int _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid_t uid,
2460                 const char *providerid, const char *type, char **appid,
2461                 bool *is_trusted)
2462 {
2463         int ret;
2464         char *dbpath;
2465         sqlite3 *db;
2466
2467         dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2468         if (dbpath == NULL)
2469                 return PMINFO_R_ERROR;
2470
2471         ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2472         free(dbpath);
2473         if (ret != SQLITE_OK) {
2474                 LOGE("open db failed: %s", sqlite3_errmsg(db));
2475                 return PMINFO_R_ERROR;
2476         }
2477
2478         ret = _appinfo_get_datacontrol_trusted_info(db, providerid, type, appid,
2479                         is_trusted);
2480         sqlite3_close_v2(db);
2481
2482         return ret;
2483 }
2484
2485 API int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(
2486                 const char *providerid, const char *type, uid_t uid,
2487                 char **appid, bool *is_trusted)
2488 {
2489         int ret;
2490
2491         if (providerid == NULL || type == NULL || appid == NULL ||
2492                         is_trusted == NULL) {
2493                 LOGE("invalid parameter");
2494                 return PMINFO_R_EINVAL;
2495         }
2496
2497         ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(GLOBAL_USER,
2498                         providerid, type, appid, is_trusted);
2499         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2500                 ret = _pkgmgrinfo_appinfo_get_datacontrol_trusted_info(uid,
2501                                 providerid, type, appid, is_trusted);
2502
2503         /* FIXME: It should return PMINFO_R_ENOENT but to keep previous
2504          * implementation, return PMINFO_R_ERROR. This should be
2505          * modified later...
2506          */
2507         if (ret == PMINFO_R_ENOENT) {
2508                 LOGE("no datacontrol trusted info of %s", providerid);
2509                 ret = PMINFO_R_ERROR;
2510         }
2511
2512         return ret;
2513 }
2514
2515 API int pkgmgrinfo_appinfo_get_datacontrol_trsuted_info(const char *providerid,
2516                 const char *type, char **appid, bool *is_trusted)
2517 {
2518         return pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(providerid,
2519                         type, _getuid(), appid, is_trusted);
2520 }
2521
2522 static int _appinfo_foreach_datacontrol_privileges(sqlite3 *db,
2523                 const char *providerid, const char *type,
2524                 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2525 {
2526         static const char query[] =
2527                 "SELECT privilege FROM package_app_data_control_privilege "
2528                 "WHERE providerid=? AND type=?";
2529         int ret;
2530         sqlite3_stmt *stmt;
2531         int count = 0;
2532
2533         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2534         if (ret != SQLITE_OK) {
2535                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2536                 return PMINFO_R_ERROR;
2537         }
2538
2539         ret = sqlite3_bind_text(stmt, 1, providerid, -1, SQLITE_STATIC);
2540         if (ret != SQLITE_OK) {
2541                 LOGE("bind failed: %s", sqlite3_errmsg(db));
2542                 sqlite3_finalize(stmt);
2543                 return PMINFO_R_ERROR;
2544         }
2545
2546         ret = sqlite3_bind_text(stmt, 2, type, -1, SQLITE_STATIC);
2547         if (ret != SQLITE_OK) {
2548                 LOGE("bind failed: %s", sqlite3_errmsg(db));
2549                 sqlite3_finalize(stmt);
2550                 return PMINFO_R_ERROR;
2551         }
2552
2553         while (sqlite3_step(stmt) == SQLITE_ROW) {
2554                 count++;
2555                 ret = callback((const char *)sqlite3_column_text(stmt, 0),
2556                                 user_data);
2557                 if (ret < 0)
2558                         break;
2559         }
2560
2561         sqlite3_finalize(stmt);
2562
2563         return count ? PMINFO_R_OK : PMINFO_R_ENOENT;
2564 }
2565
2566 static int _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid_t uid,
2567                 const char *providerid, const char *type,
2568                 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2569 {
2570         int ret;
2571         char *dbpath;
2572         sqlite3 *db;
2573
2574         dbpath = getUserPkgParserDBPathUID(GLOBAL_USER);
2575         if (dbpath == NULL)
2576                 return PMINFO_R_ERROR;
2577
2578         ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2579         free(dbpath);
2580         if (ret != SQLITE_OK) {
2581                 LOGE("open db failed: %s", sqlite3_errmsg(db));
2582                 return PMINFO_R_ERROR;
2583         }
2584
2585         ret = _appinfo_foreach_datacontrol_privileges(db, providerid, type,
2586                         callback, user_data);
2587         sqlite3_close_v2(db);
2588
2589         return ret;
2590 }
2591
2592 API int pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
2593                 const char *providerid, const char *type,
2594                 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2595                 void *user_data, uid_t uid)
2596 {
2597         int ret;
2598
2599         if (providerid == NULL || type == NULL || privilege_func == NULL) {
2600                 LOGE("invalid parameter");
2601                 return PMINFO_R_EINVAL;
2602         }
2603
2604         ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(GLOBAL_USER,
2605                         providerid, type, privilege_func, user_data);
2606         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2607                 ret = _pkgmgrinfo_appinfo_foreach_datacontrol_privileges(uid,
2608                                 providerid, type, privilege_func, user_data);
2609
2610         if (ret == PMINFO_R_ENOENT)
2611                 ret = PMINFO_R_OK;
2612
2613         return ret;
2614 }
2615
2616 API int pkgmgrinfo_appinfo_foreach_datacontrol_privileges(
2617                 const char *providerid, const char *type,
2618                 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2619                 void *user_data)
2620 {
2621         return pkgmgrinfo_appinfo_usr_foreach_datacontrol_privileges(
2622                         providerid, type, privilege_func, user_data, _getuid());
2623 }
2624
2625 API int pkgmgrinfo_appinfo_get_support_mode(pkgmgrinfo_appinfo_h  handle, int *support_mode)
2626 {
2627         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2628         retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2629
2630         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2631         if (info->app_info->support_mode)
2632                 *support_mode = atoi(info->app_info->support_mode);
2633         else
2634                 *support_mode = 0;
2635
2636         return PMINFO_R_OK;
2637 }
2638
2639 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
2640                         pkgmgrinfo_app_category_list_cb category_func, void *user_data)
2641 {
2642         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2643         retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2644         int ret = -1;
2645         const char *category;
2646         GList *tmp;
2647         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2648
2649         if (info->app_info == NULL)
2650                 return PMINFO_R_ERROR;
2651
2652         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
2653                 category = (const char *)tmp->data;
2654                 if (category) {
2655                         ret = category_func(category, user_data);
2656                         if (ret < 0)
2657                                 break;
2658                 }
2659         }
2660         return PMINFO_R_OK;
2661 }
2662
2663 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
2664                         pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
2665 {
2666         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2667         retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2668         int ret = -1;
2669         metadata_x *ptr;
2670         GList *tmp;
2671         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2672
2673         if (info->app_info == NULL)
2674                 return PMINFO_R_ERROR;
2675
2676         for (tmp = info->app_info->metadata; tmp; tmp = tmp->next) {
2677                 ptr = (metadata_x *)tmp->data;
2678                 if (ptr == NULL)
2679                         continue;
2680                 if (ptr->key) {
2681                         ret = metadata_func(ptr->key, ptr->value ? ptr->value : "", user_data);
2682                         if (ret < 0)
2683                                 break;
2684                 }
2685         }
2686         return PMINFO_R_OK;
2687 }
2688
2689 static int _appinfo_foreach_appcontrol_privileges(sqlite3 *db,
2690                 const char *appid, const char *app_control,
2691                 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2692 {
2693         static const char query[] =
2694                 "SELECT privilege FROM package_app_app_control_privilege "
2695                 "WHERE app_id=? AND app_control=?";
2696         int ret;
2697         sqlite3_stmt *stmt;
2698         int count = 0;
2699
2700         ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
2701         if (ret != SQLITE_OK) {
2702                 LOGE("prepare failed: %s", sqlite3_errmsg(db));
2703                 return PMINFO_R_ERROR;
2704         }
2705
2706         ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_STATIC);
2707         if (ret != SQLITE_OK) {
2708                 LOGE("bind failed: %s", sqlite3_errmsg(db));
2709                 sqlite3_finalize(stmt);
2710                 return PMINFO_R_ERROR;
2711         }
2712
2713         ret = sqlite3_bind_text(stmt, 2, app_control, -1, SQLITE_STATIC);
2714         if (ret != SQLITE_OK) {
2715                 LOGE("bind failed: %s", sqlite3_errmsg(db));
2716                 sqlite3_finalize(stmt);
2717                 return PMINFO_R_ERROR;
2718         }
2719
2720         while (sqlite3_step(stmt) == SQLITE_ROW) {
2721                 count++;
2722                 ret = callback((const char *)sqlite3_column_text(stmt, 0),
2723                                 user_data);
2724                 if (ret < 0)
2725                         break;
2726         }
2727
2728         sqlite3_finalize(stmt);
2729
2730         return count ? PMINFO_R_OK : PMINFO_R_ENOENT;
2731 }
2732
2733 static int _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid_t uid,
2734                 const char *appid, const char *app_control,
2735                 pkgmgrinfo_pkg_privilege_list_cb callback, void *user_data)
2736 {
2737         int ret;
2738         char *dbpath;
2739         sqlite3 *db;
2740
2741         dbpath = getUserPkgParserDBPathUID(uid);
2742         if (dbpath == NULL)
2743                 return PMINFO_R_ERROR;
2744
2745         ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
2746         free(dbpath);
2747         if (ret != SQLITE_OK) {
2748                 LOGE("open db failed: %s", sqlite3_errmsg(db));
2749                 return PMINFO_R_ERROR;
2750         }
2751
2752         ret = _appinfo_foreach_appcontrol_privileges(db, appid, app_control,
2753                         callback, user_data);
2754         sqlite3_close_v2(db);
2755
2756         return ret;
2757 }
2758
2759 API int pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(const char *appid,
2760                 const char *operation, const char *uri, const char *mime,
2761                 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2762                 void *user_data, uid_t uid)
2763 {
2764         int ret;
2765         char app_control[BUFSIZE];
2766
2767         if (appid == NULL || operation == NULL || privilege_func == NULL) {
2768                 LOGE("invalid parameter");
2769                 return PMINFO_R_EINVAL;
2770         }
2771
2772         snprintf(app_control, sizeof(app_control), "%s|%s|%s", operation,
2773                         uri ? uri : "NULL", mime ? mime : "NULL");
2774
2775         ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(GLOBAL_USER,
2776                         appid, app_control, privilege_func, user_data);
2777         if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
2778                 ret = _pkgmgrinfo_appinfo_foreach_appcontrol_privileges(uid,
2779                                 appid, app_control, privilege_func, user_data);
2780
2781         if (ret == PMINFO_R_ENOENT)
2782                 ret = PMINFO_R_OK;
2783
2784         return ret;
2785 }
2786
2787 API int pkgmgrinfo_appinfo_foreach_appcontrol_privileges(const char *appid,
2788                 const char *operation, const char *uri, const char *mime,
2789                 pkgmgrinfo_pkg_privilege_list_cb privilege_func,
2790                 void *user_data)
2791 {
2792         return pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(appid,
2793                         operation, uri, mime, privilege_func, user_data,
2794                         _getuid());
2795 }
2796
2797 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
2798                         pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
2799 {
2800         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2801         retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
2802         int ret;
2803         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2804         appcontrol_x *appcontrol;
2805         GList *tmp;
2806
2807         if (info->app_info == NULL)
2808                 return PMINFO_R_ERROR;
2809
2810         for (tmp = info->app_info->appcontrol; tmp; tmp = tmp->next) {
2811                 appcontrol = (appcontrol_x *)tmp->data;
2812                 if (appcontrol == NULL)
2813                         continue;
2814                 ret = appcontrol_func(appcontrol->operation, appcontrol->uri, appcontrol->mime, user_data);
2815                 if (ret < 0)
2816                         break;
2817         }
2818
2819         return PMINFO_R_OK;
2820 }
2821
2822 API int pkgmgrinfo_appinfo_foreach_background_category(
2823                 pkgmgrinfo_appinfo_h handle,
2824                 pkgmgrinfo_app_background_category_list_cb category_func,
2825                 void *user_data)
2826 {
2827         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2828         GList *tmp;
2829         char *category;
2830
2831         if (handle == NULL || category_func == NULL || info->app_info == NULL) {
2832                 LOGE("invalid parameter");
2833                 return PMINFO_R_EINVAL;
2834         }
2835
2836         for (tmp = info->app_info->background_category; tmp; tmp = tmp->next) {
2837                 category = (char *)tmp->data;
2838                 if (category == NULL)
2839                         continue;
2840
2841                 if (category_func(category, user_data) < 0)
2842                         break;
2843         }
2844
2845         return PMINFO_R_OK;
2846 }
2847
2848 API int pkgmgrinfo_appinfo_foreach_splash_screen(pkgmgrinfo_appinfo_h handle,
2849                 pkgmgrinfo_app_splash_screen_list_cb splash_screen_func,
2850                 void *user_data)
2851 {
2852         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2853         splashscreen_x *splashscreen;
2854         GList *tmp;
2855         int ret;
2856
2857         if (info == NULL || info->app_info == NULL
2858                         || splash_screen_func == NULL) {
2859                 LOGE("invalid parameter");
2860                 return PMINFO_R_EINVAL;
2861         }
2862
2863         for (tmp = info->app_info->splashscreens; tmp; tmp = tmp->next) {
2864                 splashscreen = (splashscreen_x *)tmp->data;
2865                 if (splashscreen == NULL)
2866                         continue;
2867                 ret = splash_screen_func(splashscreen->src,
2868                                 splashscreen->type,
2869                                 splashscreen->orientation,
2870                                 splashscreen->indicatordisplay,
2871                                 splashscreen->operation,
2872                                 splashscreen->color_depth,
2873                                 user_data);
2874                 if (ret < 0)
2875                         break;
2876         }
2877
2878         return PMINFO_R_OK;
2879 }
2880
2881 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
2882 {
2883         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2884         retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2885         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2886
2887         if (info->app_info == NULL || info->app_info->nodisplay == NULL)
2888                 return PMINFO_R_ERROR;
2889
2890         *nodisplay = _get_bool_value(info->app_info->nodisplay);
2891
2892         return PMINFO_R_OK;
2893 }
2894
2895 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
2896 {
2897         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2898         retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2899         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2900
2901         if (info->app_info == NULL || info->app_info->multiple == NULL)
2902                 return PMINFO_R_ERROR;
2903
2904         *multiple = _get_bool_value(info->app_info->multiple);
2905
2906         return PMINFO_R_OK;
2907 }
2908
2909 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
2910 {
2911         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2912         retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2913         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2914
2915         if (info->app_info == NULL || info->app_info->indicatordisplay == NULL)
2916                 return PMINFO_R_ERROR;
2917
2918         *indicator_disp = _get_bool_value(info->app_info->indicatordisplay);
2919
2920         return PMINFO_R_OK;
2921 }
2922
2923 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h  handle, bool *taskmanage)
2924 {
2925         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2926         retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2927         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2928
2929         if (info->app_info == NULL || info->app_info->taskmanage == NULL)
2930                 return PMINFO_R_ERROR;
2931
2932         *taskmanage = _get_bool_value(info->app_info->taskmanage);
2933
2934         return PMINFO_R_OK;
2935 }
2936
2937 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h  handle, bool *enabled)
2938 {
2939         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2940         retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2941         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2942
2943         if (info->app_info == NULL || info->app_info->is_disabled == NULL)
2944                 return PMINFO_R_ERROR;
2945
2946         *enabled = !_get_bool_value(info->app_info->is_disabled);
2947
2948         return PMINFO_R_OK;
2949 }
2950
2951 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h  handle, bool *onboot)
2952 {
2953         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2954         retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2955         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2956
2957         if (info->app_info == NULL || info->app_info->onboot == NULL)
2958                 return PMINFO_R_ERROR;
2959
2960         *onboot = _get_bool_value(info->app_info->onboot);
2961
2962         return PMINFO_R_OK;
2963 }
2964
2965 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h  handle, bool *autorestart)
2966 {
2967         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2968         retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2969         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2970
2971         if (info->app_info == NULL || info->app_info->autorestart == NULL)
2972                 return PMINFO_R_ERROR;
2973
2974         *autorestart = _get_bool_value(info->app_info->autorestart);
2975
2976         return PMINFO_R_OK;
2977 }
2978
2979 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h  handle, bool *mainapp)
2980 {
2981         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
2982         retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
2983         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2984
2985         if (info->app_info == NULL || info->app_info->mainapp == NULL)
2986                 return PMINFO_R_ERROR;
2987
2988         *mainapp = _get_bool_value(info->app_info->mainapp);
2989
2990         return PMINFO_R_OK;
2991 }
2992
2993 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
2994 {
2995         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
2996         retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2997         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
2998
2999         if (info->app_info == NULL || info->app_info->preload == NULL)
3000                 return PMINFO_R_ERROR;
3001
3002         *preload = _get_bool_value(info->app_info->preload);
3003
3004         return PMINFO_R_OK;
3005 }
3006
3007 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
3008 {
3009         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3010         retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3011         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3012
3013         if (info->app_info == NULL || info->app_info->submode == NULL)
3014                 return PMINFO_R_ERROR;
3015
3016         *submode = _get_bool_value(info->app_info->submode);
3017
3018         return PMINFO_R_OK;
3019 }
3020
3021 API int pkgmgrinfo_appinfo_is_process_pool(pkgmgrinfo_appinfo_h handle, bool *process_pool)
3022 {
3023         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3024
3025         if (handle == NULL || process_pool == NULL) {
3026                 LOGE("invalid parameter");
3027                 return PMINFO_R_EINVAL;
3028         }
3029
3030         if (info->app_info == NULL)
3031                 return PMINFO_R_ERROR;
3032
3033         *process_pool = _get_bool_value(info->app_info->process_pool);
3034
3035         return PMINFO_R_OK;
3036 }
3037
3038 API int pkgmgrinfo_appinfo_is_category_exist(pkgmgrinfo_appinfo_h handle, const char *category, bool *exist)
3039 {
3040         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3041         retvm_if(category == NULL, PMINFO_R_EINVAL, "category is NULL");
3042         retvm_if(exist == NULL, PMINFO_R_EINVAL, "exist is NULL");
3043
3044         const char *val;
3045         GList *tmp;
3046         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3047
3048         if (info->app_info == NULL)
3049                 return PMINFO_R_ERROR;
3050
3051         *exist = 0;
3052         for (tmp = info->app_info->category; tmp; tmp = tmp->next) {
3053                 val = (const char *)tmp->data;
3054                 if (val == NULL)
3055                         continue;
3056                 if (strcasecmp(val, category) == 0) {
3057                         *exist = 1;
3058                         break;
3059                 }
3060         }
3061
3062         return PMINFO_R_OK;
3063 }
3064
3065 API int pkgmgrinfo_appinfo_is_ui_gadget(pkgmgrinfo_appinfo_h handle,
3066                 bool *ui_gadget)
3067 {
3068         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3069
3070         if (info == NULL || info->app_info == NULL || ui_gadget == NULL) {
3071                 _LOGE("invalid parameter");
3072                 return PMINFO_R_EINVAL;
3073         }
3074         if (info->app_info->ui_gadget == NULL)
3075                 info->app_info->ui_gadget = strdup("false");
3076
3077         *ui_gadget = _get_bool_value(info->app_info->ui_gadget);
3078
3079         return PMINFO_R_OK;
3080 }
3081
3082 API int pkgmgrinfo_appinfo_is_support_disable(pkgmgrinfo_appinfo_h handle,
3083                 bool *support_disable)
3084 {
3085         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3086
3087         if (info == NULL || info->app_info == NULL || support_disable == NULL) {
3088                 _LOGE("invalid parameter");
3089                 return PMINFO_R_EINVAL;
3090         }
3091
3092         *support_disable = _get_bool_value(info->app_info->support_disable);
3093
3094         return PMINFO_R_OK;
3095 }
3096
3097 API int pkgmgrinfo_appinfo_is_removable(pkgmgrinfo_appinfo_h handle,
3098                 bool *removable)
3099 {
3100         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3101
3102         if (info == NULL || info->app_info == NULL || removable == NULL) {
3103                 _LOGE("invalid parameter");
3104                 return PMINFO_R_EINVAL;
3105         }
3106
3107         *removable = _get_bool_value(info->app_info->removable);
3108
3109         return PMINFO_R_OK;
3110 }
3111
3112 API int pkgmgrinfo_appinfo_is_system(pkgmgrinfo_appinfo_h handle, bool *system)
3113 {
3114         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3115
3116         if (info == NULL || info->app_info == NULL || system == NULL) {
3117                 _LOGE("invalid parameter");
3118                 return PMINFO_R_EINVAL;
3119         }
3120
3121         *system = _get_bool_value(info->app_info->package_system);
3122
3123         return PMINFO_R_OK;
3124 }
3125
3126 API int pkgmgrinfo_appinfo_is_disabled(pkgmgrinfo_appinfo_h handle, bool *disabled)
3127 {
3128         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3129         retvm_if(disabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3130         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3131
3132         if (info->app_info == NULL || info->app_info->is_disabled == NULL)
3133                 return PMINFO_R_ERROR;
3134
3135         *disabled = _get_bool_value(info->app_info->is_disabled);
3136
3137         return PMINFO_R_OK;
3138 }
3139
3140 API int pkgmgrinfo_appinfo_is_global(pkgmgrinfo_appinfo_h handle, bool *global)
3141 {
3142         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3143
3144         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3145         retvm_if(global == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3146
3147         if (info->app_info == NULL || info->app_info->for_all_users == NULL)
3148                 return PMINFO_R_ERROR;
3149
3150         *global = _get_bool_value(info->app_info->for_all_users);
3151
3152         return PMINFO_R_OK;
3153 }
3154
3155 API int pkgmgrinfo_appinfo_get_splash_screen_display(pkgmgrinfo_appinfo_h handle, bool *splash_screen_display)
3156 {
3157         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3158
3159         if (info == NULL || splash_screen_display == NULL) {
3160                 _LOGE("Invalid parameter");
3161                 return PMINFO_R_EINVAL;
3162         }
3163
3164         if (info->app_info == NULL || info->app_info->splash_screen_display == NULL)
3165                 return PMINFO_R_ERROR;
3166
3167         *splash_screen_display = _get_bool_value(info->app_info->splash_screen_display);
3168
3169         return PMINFO_R_OK;
3170 }
3171
3172 API int pkgmgrinfo_appinfo_get_setup_appid(pkgmgrinfo_appinfo_h handle, char **setup_appid)
3173 {
3174         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3175
3176         if (info == NULL || setup_appid == NULL) {
3177                 _LOGE("Invalid parameter");
3178                 return PMINFO_R_EINVAL;
3179         }
3180
3181         if (info->app_info == NULL || info->app_info->setup_appid == NULL)
3182                 return PMINFO_R_ERROR;
3183
3184         *setup_appid = info->app_info->setup_appid;
3185         return PMINFO_R_OK;
3186 }
3187
3188 API int pkgmgrinfo_appinfo_is_support_ambient(pkgmgrinfo_appinfo_h handle,
3189                 bool *support_ambient)
3190 {
3191         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3192
3193         if (info == NULL || support_ambient == NULL) {
3194                 _LOGE("Invalid parameter");
3195                 return PMINFO_R_EINVAL;
3196         }
3197
3198         if (info->app_info == NULL || info->app_info->support_ambient == NULL)
3199                 return PMINFO_R_ERROR;
3200
3201         *support_ambient = _get_bool_value(info->app_info->support_ambient);
3202
3203         return PMINFO_R_OK;
3204 }
3205
3206 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
3207 {
3208         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
3209         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3210         __cleanup_appinfo(info);
3211         return PMINFO_R_OK;
3212 }
3213
3214 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
3215 {
3216         return (pkgmgrinfo_pkginfo_filter_create(handle));
3217 }
3218
3219 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
3220 {
3221         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3222 }
3223
3224 static gint __compare_func(gconstpointer data1, gconstpointer data2)
3225 {
3226         pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x *)data1;
3227         pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x *)data2;
3228         if (node1->prop == node2->prop)
3229                 return 0;
3230         else if (node1->prop > node2->prop)
3231                 return 1;
3232         else
3233                 return -1;
3234 }
3235
3236 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
3237                                 const char *property, const int value)
3238 {
3239         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3240         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3241         char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
3242         char *val = NULL;
3243         GSList *link = NULL;
3244         int prop = -1;
3245         prop = _pminfo_appinfo_convert_to_prop_int(property);
3246         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
3247                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
3248                 _LOGE("Invalid Integer Property\n");
3249                 return PMINFO_R_EINVAL;
3250         }
3251         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3252         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3253         if (node == NULL) {
3254                 _LOGE("Out of Memory!!!\n");
3255                 return PMINFO_R_ERROR;
3256         }
3257         snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
3258         val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
3259         if (val == NULL) {
3260                 _LOGE("Out of Memory\n");
3261                 free(node);
3262                 node = NULL;
3263                 return PMINFO_R_ERROR;
3264         }
3265         node->prop = prop;
3266         node->value = val;
3267         /*If API is called multiple times for same property, we should override the previous values.
3268         Last value set will be used for filtering.*/
3269         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3270         if (link)
3271                 filter->list = g_slist_delete_link(filter->list, link);
3272         filter->list = g_slist_append(filter->list, (gpointer)node);
3273         return PMINFO_R_OK;
3274
3275 }
3276
3277 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
3278                                 const char *property, const bool value)
3279 {
3280         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3281         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3282         char *val = NULL;
3283         GSList *link = NULL;
3284         int prop = -1;
3285         prop = _pminfo_appinfo_convert_to_prop_bool(property);
3286         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
3287                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
3288                 _LOGE("Invalid Boolean Property\n");
3289                 return PMINFO_R_EINVAL;
3290         }
3291         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3292         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3293         if (node == NULL) {
3294                 _LOGE("Out of Memory!!!\n");
3295                 return PMINFO_R_ERROR;
3296         }
3297         if (value)
3298                 val = strndup("true", 4);
3299         else
3300                 val = strndup("false", 5);
3301         if (val == NULL) {
3302                 _LOGE("Out of Memory\n");
3303                 free(node);
3304                 node = NULL;
3305                 return PMINFO_R_ERROR;
3306         }
3307         node->prop = prop;
3308         node->value = val;
3309         /*If API is called multiple times for same property, we should override the previous values.
3310         Last value set will be used for filtering.*/
3311         link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3312         if (link)
3313                 filter->list = g_slist_delete_link(filter->list, link);
3314         filter->list = g_slist_append(filter->list, (gpointer)node);
3315         return PMINFO_R_OK;
3316
3317 }
3318
3319 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
3320                                 const char *property, const char *value)
3321 {
3322         retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3323         retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3324         retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
3325         char *val = NULL;
3326         pkgmgrinfo_node_x *ptr = NULL;
3327         char prev[PKG_STRING_LEN_MAX] = {'\0'};
3328         char temp[PKG_STRING_LEN_MAX] = {'\0'};
3329         GSList *link = NULL;
3330         int prop = -1;
3331         prop = _pminfo_appinfo_convert_to_prop_str(property);
3332         if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
3333                 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
3334                 _LOGE("Invalid String Property\n");
3335                 return PMINFO_R_EINVAL;
3336         }
3337         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3338         pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)calloc(1, sizeof(pkgmgrinfo_node_x));
3339         if (node == NULL) {
3340                 _LOGE("Out of Memory!!!\n");
3341                 return PMINFO_R_ERROR;
3342         }
3343         node->prop = prop;
3344         switch (prop) {
3345         case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
3346                 node->value = strdup(value);
3347                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3348                 if (link)
3349                         filter->list = g_slist_delete_link(filter->list, link);
3350                 filter->list = g_slist_append(filter->list, (gpointer)node);
3351                 break;
3352         case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
3353                 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
3354                 if (val == NULL) {
3355                         _LOGE("Out of Memory\n");
3356                         free(node);
3357                         node = NULL;
3358                         return PMINFO_R_ERROR;
3359                 }
3360                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3361                 if (link) {
3362                         ptr = (pkgmgrinfo_node_x *)link->data;
3363                         strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
3364                         _LOGI("Previous value is %s\n", prev);
3365                         filter->list = g_slist_delete_link(filter->list, link);
3366                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value);
3367                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
3368                         _LOGI("New value is %s\n", val);
3369                         node->value = val;
3370                         filter->list = g_slist_append(filter->list, (gpointer)node);
3371                         memset(temp, '\0', PKG_STRING_LEN_MAX);
3372                 } else {
3373                         snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s", value);
3374                         strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
3375                         _LOGI("First value is %s\n", val);
3376                         node->value = val;
3377                         filter->list = g_slist_append(filter->list, (gpointer)node);
3378                         memset(temp, '\0', PKG_STRING_LEN_MAX);
3379                 }
3380                 break;
3381         default:
3382                 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
3383                 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
3384                 if (link)
3385                         filter->list = g_slist_delete_link(filter->list, link);
3386                 filter->list = g_slist_append(filter->list, (gpointer)node);
3387                 break;
3388         }
3389         return PMINFO_R_OK;
3390 }
3391
3392 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
3393 {
3394         int ret;
3395         char *locale;
3396         GHashTable *list;
3397
3398         if (handle == NULL || count == NULL) {
3399                 _LOGE("invalid parameter");
3400                 return PMINFO_R_EINVAL;
3401         }
3402
3403         locale = _get_system_locale();
3404         if (locale == NULL)
3405                 return PMINFO_R_ERROR;
3406
3407         list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
3408                         __free_applications);
3409         if (list == NULL) {
3410                 free(locale);
3411                 return PMINFO_R_ERROR;
3412         }
3413
3414         if (__check_disable_filter_exist(
3415                         handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
3416                 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3417                                 PMINFO_APPINFO_PROP_APP_DISABLE, false)) {
3418                         g_hash_table_destroy(list);
3419                         free(locale);
3420                         return PMINFO_R_ERROR;
3421                 }
3422         }
3423
3424         if (__check_disable_filter_exist(
3425                         handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
3426                 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3427                                 PMINFO_APPINFO_PROP_PKG_DISABLE, false)) {
3428                         g_hash_table_destroy(list);
3429                         free(locale);
3430                         return PMINFO_R_ERROR;
3431                 }
3432         }
3433
3434         ret = _appinfo_get_applications(uid, uid, locale, handle, 0, list);
3435         if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
3436                 ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
3437                                 handle, 0, list);
3438
3439         if (ret != PMINFO_R_OK) {
3440                 g_hash_table_destroy(list);
3441                 free(locale);
3442                 return PMINFO_R_ERROR;
3443         }
3444
3445         *count = g_hash_table_size(list);
3446         g_hash_table_destroy(list);
3447         free(locale);
3448
3449         return PMINFO_R_OK;
3450 }
3451
3452 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
3453 {
3454         return pkgmgrinfo_appinfo_usr_filter_count(handle, count, _getuid());
3455 }
3456
3457 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(
3458                 pkgmgrinfo_appinfo_filter_h handle,
3459                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3460 {
3461         if (handle == NULL || app_cb == NULL) {
3462                 LOGE("invalid parameter");
3463                 return PMINFO_R_EINVAL;
3464         }
3465
3466         if (__check_disable_filter_exist(
3467                         handle, E_APPINFO_DISABLE_TYPE_APP) == false) {
3468                 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3469                                 PMINFO_APPINFO_PROP_APP_DISABLE, false))
3470                         return PMINFO_R_ERROR;
3471         }
3472
3473         if (__check_disable_filter_exist(
3474                         handle, E_APPINFO_DISABLE_TYPE_PKG) == false) {
3475                 if (pkgmgrinfo_appinfo_filter_add_bool(handle,
3476                                 PMINFO_APPINFO_PROP_PKG_DISABLE, false))
3477                         return PMINFO_R_ERROR;
3478         }
3479
3480         return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3481                         user_data);
3482 }
3483
3484 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
3485                                 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3486 {
3487         return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, _getuid());
3488 }
3489
3490 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
3491 {
3492         return (pkgmgrinfo_pkginfo_filter_create(handle));
3493 }
3494
3495 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
3496 {
3497         return (pkgmgrinfo_pkginfo_filter_destroy(handle));
3498 }
3499
3500 API int pkgmgrinfo_appinfo_metadata_filter_add(
3501                 pkgmgrinfo_appinfo_metadata_filter_h handle,
3502                 const char *key, const char *value)
3503 {
3504         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3505         pkgmgrinfo_metadata_node_x *node;
3506
3507         /* value can be NULL.
3508          * In that case all apps with specified key should be displayed
3509          */
3510         if (key == NULL) {
3511                 LOGE("invalid parameter");
3512                 return PMINFO_R_EINVAL;
3513         }
3514
3515         node = calloc(1, sizeof(pkgmgrinfo_metadata_node_x));
3516         if (node == NULL) {
3517                 LOGE("out of memory");
3518                 return PMINFO_R_ERROR;
3519         }
3520
3521         node->key = strdup(key);
3522         if (value && strlen(value))
3523                 node->value = strdup(value);
3524
3525         filter->list_metadata = g_slist_append(filter->list_metadata,
3526                         (gpointer)node);
3527
3528         return PMINFO_R_OK;
3529 }
3530
3531 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(
3532                 pkgmgrinfo_appinfo_metadata_filter_h handle,
3533                 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
3534 {
3535         if (handle == NULL || app_cb == NULL) {
3536                 LOGE("invalid parameter");
3537                 return PMINFO_R_EINVAL;
3538         }
3539
3540         pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x *)handle;
3541         if (pkgmgrinfo_appinfo_filter_add_bool(filter,
3542                         PMINFO_APPINFO_PROP_APP_DISABLE, false))
3543                 return PMINFO_R_ERROR;
3544
3545         if (pkgmgrinfo_appinfo_filter_add_bool(filter,
3546                         PMINFO_APPINFO_PROP_PKG_DISABLE, false))
3547                 return PMINFO_R_ERROR;
3548
3549         return _appinfo_get_filtered_foreach_appinfo(uid, handle, PMINFO_APPINFO_GET_ALL, app_cb,
3550                         user_data);
3551 }
3552
3553 API int pkgmgrinfo_appinfo_metadata_filter_foreach(
3554                 pkgmgrinfo_appinfo_metadata_filter_h handle,
3555                 pkgmgrinfo_app_list_cb app_cb, void *user_data)
3556 {
3557         return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb,
3558                         user_data, _getuid());
3559 }
3560
3561 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
3562 {
3563         const char *val;
3564         pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
3565
3566         retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
3567         retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3568
3569         val = info->app_info->guestmode_visibility;
3570         *status = _get_bool_value(val);
3571         return PMINFO_R_OK;
3572 }