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