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