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