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