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