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