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