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