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