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