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