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