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