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